55from apps .authorization .permissions import DataAccessGrantPermission
66# FIXME: removed for local testing
77# from apps.capabilities.permissions import TokenHasProtectedCapability
8- from django .http import JsonResponse
8+ # from django.http import JsonResponse
9+ from apps .fhir .bluebutton .models import Crosswalk
910
1011from rest_framework import permissions # pyright: ignore[reportMissingImports]
1112
1213from apps .versions import noisy_has_permission
1314
1415
15- def _is_not_empty (s : set ) -> bool :
16- if len (s ) > 0 :
17- return True
18- else :
19- return False
20-
21-
2216class HasDigitalInsuranceCardScope (permissions .BasePermission ):
2317
2418 required_coverage_search_scopes = ['patient/Coverage.rs' , 'patient/Coverage.s' , 'patient/Coverage.read' ]
2519 required_patient_read_scopes = ['patient/Patient.r' , 'patient/Patient.rs' , 'patient/Patient.read' ]
2620
21+ def _is_not_empty (s : set ) -> bool :
22+ return len (s ) > 0
23+
2724 def has_permission (self , request , view ) -> bool : # type: ignore
2825 print ("HasDigitalInsuranceCardScope has_permission" )
2926
@@ -50,8 +47,8 @@ def has_permission(self, request, view) -> bool: # type: ignore
5047 print ("PS" , patient_set )
5148 print ("TS" , token_set )
5249
53- return (_is_not_empty (coverage_set .intersection (token_set ))
54- and _is_not_empty (patient_set .intersection (token_set )))
50+ return (HasDigitalInsuranceCardScope . _is_not_empty (coverage_set .intersection (token_set ))
51+ and HasDigitalInsuranceCardScope . _is_not_empty (patient_set .intersection (token_set )))
5552
5653
5754class DigitalInsuranceCardView (FhirDataView ):
@@ -83,8 +80,8 @@ def get(self, request, *args, **kwargs):
8380 print ("GET OF INSURANCE CARD" )
8481 print ("request: " , request .__dict__ )
8582 print ("self.resource_type: " , self .resource_type )
86- # return super().get(request, self.resource_type, *args, **kwargs)
87- return JsonResponse (status = 200 , data = {"ok " : "go " })
83+ return super ().get (request , self .resource_type , * args , ** kwargs )
84+ # return JsonResponse(status=200, data={"consternation ": "vorciferous "})
8885
8986 # How do the has_permission herre and the has_permission in the permission classes
9087 # play together? If they pass, can this fail? Visa-versa?
@@ -116,13 +113,14 @@ def build_parameters(self, request):
116113 }
117114
118115 def build_url (self , fhir_settings , resource_type , resource_id = None , * args , ** kwargs ):
119- print ("BUILD_URL IN DIGITALINSURANCECARD" )
120116 if fhir_settings .fhir_url .endswith ('v1/fhir/' ):
121117 # only if called by tests
122118 return f"{ fhir_settings .fhir_url } { resource_type } /"
123119 else :
120+ # TODO - is this preferred (explicit), or should we keep using the implicit model APIS that Django creates?
121+ fhir_id = Crosswalk .objects .get (user = self .request .user ).fhir_id (self .version )
124122 if self .version == 3 and getattr (fhir_settings , 'fhir_url_v3' , None ):
125123 fhir_url = fhir_settings .fhir_url_v3
126124 else :
127125 fhir_url = fhir_settings .fhir_url
128- return f"{ fhir_url } /v{ self .version } /fhir/Patient/{ resource_id } /$generate-insurance-card"
126+ return f"{ fhir_url } /v{ self .version } /fhir/Patient/{ fhir_id } /$generate-insurance-card"
0 commit comments