@@ -221,20 +221,15 @@ def request_call(request, call_url, crosswalk=None, timeout=None, get_parameters
221221 call_url = target server URL and search parameters to be sent
222222 crosswalk = Crosswalk record. The crosswalk is keyed off Request.user
223223 timeout allows a timeout in seconds to be set.
224-
225- FhirServer is joined to Crosswalk.
226- FhirServerAuth and FhirServerVerify receive crosswalk and lookup
227- values in the linked fhir_server model.
228-
229224 """
230225
231226 logger_perf = bb2logging .getLogger (bb2logging .PERFORMANCE_LOGGER , request )
232227
233228 # Updated to receive crosswalk (Crosswalk entry for user)
234229 # call FhirServer_Auth(crosswalk) to get authentication
235- auth_state = FhirServerAuth (crosswalk )
230+ auth_state = FhirServerAuth ()
236231
237- verify_state = FhirServerVerify ( crosswalk )
232+ verify_state = fhir_settings . verify_server
238233 if auth_state ["client_auth" ]:
239234 # cert puts cert and key file together
240235 # (cert_file_path, key_file_path)
@@ -326,16 +321,21 @@ def notNone(value=None, default=None):
326321 return value
327322
328323
329- def FhirServerAuth (crosswalk = None ):
330- # Get default clientauth settings from base.py
331- # Receive a crosswalk.id or None
332- # Return a dict
324+ def FhirServerAuth () -> dict :
325+ """Helper class to modify cert paths if client_auth is true
326+ TODO - this can probably be refactored or removed, rolled into the FHIRServerSettings class
327+
328+ Returns:
329+ dict: A dictionary with the following:
330+ - client_auth (bool): if client authentication is required
331+ - cert_file (str): path to cert file
332+ - key_file (str): path to key file
333+ """
333334
334335 auth_settings = {}
335- resource_router = get_resourcerouter ()
336- auth_settings ["client_auth" ] = resource_router .client_auth
337- auth_settings ["cert_file" ] = resource_router .cert_file
338- auth_settings ["key_file" ] = resource_router .key_file
336+ auth_settings ["client_auth" ] = fhir_settings .client_auth
337+ auth_settings ["cert_file" ] = fhir_settings .cert_file
338+ auth_settings ["key_file" ] = fhir_settings .key_file
339339
340340 if auth_settings ["client_auth" ]:
341341 # join settings.FHIR_CLIENT_CERTSTORE to cert_file and key_file
@@ -351,12 +351,6 @@ def FhirServerAuth(crosswalk=None):
351351 return auth_settings
352352
353353
354- def FhirServerVerify (crosswalk = None ):
355- # Get default Server Verify Setting
356- # Return True or False (Default)
357- return get_resourcerouter ().verify_server
358-
359-
360354def mask_with_this_url (request , host_path = "" , in_text = "" , find_url = "" ):
361355 """find_url in in_text and replace with url for this server"""
362356
@@ -455,10 +449,6 @@ def get_crosswalk(user):
455449 return None
456450
457451
458- def get_resourcerouter (crosswalk = None ):
459- return fhir_settings
460-
461-
462452def handle_http_error (e ):
463453 """Handle http error from request_call
464454
@@ -605,7 +595,7 @@ def get_response_text(fhir_response=None):
605595 return text_in
606596
607597
608- def build_oauth_resource (request , version = Versions .NOT_AN_API_VERSION , format_type = "json" ):
598+ def build_oauth_resource (request , version = Versions .NOT_AN_API_VERSION , format_type = "json" ) -> dict | str :
609599 """
610600 Create a resource entry for oauth endpoint(s) for insertion
611601 into the conformance/capabilityStatement
@@ -707,17 +697,15 @@ def get_v2_patient_by_id(id, request):
707697 a helper adapted to just get patient given an id out of band of auth flow
708698 or normal data flow, use by tools such as BB2-Tools admin viewers
709699 """
710- auth_settings = FhirServerAuth (None )
700+ auth_settings = FhirServerAuth ()
711701 certs = (auth_settings ["cert_file" ], auth_settings ["key_file" ])
712702
713703 headers = generate_info_headers (request )
714704 headers ["BlueButton-Application" ] = "BB2-Tools"
715705 headers ["includeIdentifiers" ] = "true"
716706 # for now this will only work for v1/v2 patients, but we'll need to be able to
717707 # determine if the user is V3 and use those endpoints later
718- url = "{}/v2/fhir/Patient/{}?_format={}" .format (
719- get_resourcerouter ().fhir_url , id , settings .FHIR_PARAM_FORMAT
720- )
708+ url = f'{ fhir_settings .fhir_url } /v2/fhir/Patient/{ id } ?_format={ settings .FHIR_PARAM_FORMAT } '
721709 s = requests .Session ()
722710 req = requests .Request ("GET" , url , headers = headers )
723711 prepped = req .prepare ()
@@ -730,17 +718,15 @@ def get_v2_patient_by_id(id, request):
730718# of the ticket to remove the user_mbi_hash column from the crosswalk table
731719# We can remove this entire function at that point
732720def get_patient_by_mbi_hash (mbi_hash , request ):
733- auth_settings = FhirServerAuth (None )
721+ auth_settings = FhirServerAuth ()
734722 certs = (auth_settings ["cert_file" ], auth_settings ["key_file" ])
735723 headers = generate_info_headers (request )
736724 headers ["BlueButton-Application" ] = "BB2-Tools"
737725 headers ["includeIdentifiers" ] = "true"
738726
739727 search_identifier = f'https://bluebutton.cms.gov/resources/identifier/mbi-hash|{ mbi_hash } ' # noqa: E231
740728 payload = {'identifier' : search_identifier }
741- url = '{}/v2/fhir/Patient/_search' .format (
742- get_resourcerouter ().fhir_url
743- )
729+ url = f'{ fhir_settings .fhir_url } /v2/fhir/Patient/_search'
744730
745731 s = requests .Session ()
746732 req = requests .Request ("POST" , url , headers = headers , data = payload )
0 commit comments