@@ -34,12 +34,7 @@ def get_available_scopes(self, application=None, request=None, *args, **kwargs):
3434 # Return all scopes
3535 return app_scopes_avail
3636 else :
37- # Remove personal information scopes
38- app_scopes = []
39- for s in app_scopes_avail :
40- if s not in settings .BENE_PERSONAL_INFO_SCOPES :
41- app_scopes .append (s )
42- return app_scopes
37+ return self .remove_demographic_scopes (app_scopes_avail )
4338
4439 def get_default_scopes (self , application = None , request = None , * args , ** kwargs ):
4540 """
@@ -59,9 +54,38 @@ def get_default_scopes(self, application=None, request=None, *args, **kwargs):
5954 # Return all scopes
6055 return app_scopes_default
6156 else :
62- # Remove personal information scopes
63- app_scopes = []
64- for s in app_scopes_default :
65- if s not in settings .BENE_PERSONAL_INFO_SCOPES :
66- app_scopes .append (s )
67- return app_scopes
57+ return self .remove_demographic_scopes (app_scopes_default )
58+
59+ def condense_scopes (self , scopes ):
60+ """
61+ Returns a list based on the provided list of scopes with redundant scopes consolidated
62+ """
63+ out_scopes = set (scopes )
64+
65+ # Consolidate v2 resource scopes
66+ if "patient/Patient.rs" in scopes or ("patient/Patient.r" in scopes and "patient/Patient.s" in scopes ):
67+ out_scopes .add ("patient/Patient.rs" )
68+ out_scopes .discard ("patient/Patient.r" )
69+ out_scopes .discard ("patient/Patient.s" )
70+ if "patient/Coverage.rs" in scopes or ("patient/Coverage.r" in scopes and "patient/Coverage.s" in scopes ):
71+ out_scopes .add ("patient/Coverage.rs" )
72+ out_scopes .discard ("patient/Coverage.r" )
73+ out_scopes .discard ("patient/Coverage.s" )
74+ if "patient/ExplanationOfBenefit.rs" in scopes or \
75+ ("patient/ExplanationOfBenefit.r" in scopes and "patient/ExplanationOfBenefit.s" in scopes ):
76+ out_scopes .add ("patient/ExplanationOfBenefit.rs" )
77+ out_scopes .discard ("patient/ExplanationOfBenefit.r" )
78+ out_scopes .discard ("patient/ExplanationOfBenefit.s" )
79+
80+ return list (out_scopes )
81+
82+ def remove_demographic_scopes (self , scopes ):
83+ """
84+ Returns a list of all of the provided list except with personal info scopes removed
85+ """
86+ # Remove personal information scopes
87+ out_scopes = []
88+ for s in scopes :
89+ if s not in settings .BENE_PERSONAL_INFO_SCOPES :
90+ out_scopes .append (s )
91+ return out_scopes
0 commit comments