@@ -54,43 +54,38 @@ def _get_oauth2_session_with_token(request: HttpRequest) -> OAuth2Session:
5454FhirDataParams = namedtuple ("FhirDataParams" , "name,uri,version,patient" )
5555
5656
57- def _build_pagination_uri (params , request ):
58- uri = None
57+ def _build_pagination_uri (uri : str , params : FhirDataParams , request : HttpRequest ) -> str :
5958 # This sets up the navigation URI (pagination) based on whether we are handling
6059 # a patient or a beneficiary. All of this logic is essentially to add one parameter,
6160 # name correctly, to the nav URI. It is version dependent (there is no pagination in V3).
62- nav_link = request .GET .get ('nav_link' , None )
63- if nav_link is not None :
64- # for now it's either EOB or Coverage, make this more generic later
65- patient = request .GET .get ('patient' )
66- beneficiary = request .GET .get ('beneficiary' )
67- if patient is not None :
68- id_type = 'patient'
69- id = patient
70- elif beneficiary is not None :
71- id_type = 'beneficiary'
72- id = beneficiary
73- else :
74- # We should not be able to get here.
75- raise VersionNotMatched (f"Failed to set a patient id for version; given { params .version } " )
76-
77- # Extend the base URI with pagination information.
78- uri = EndpointUrl .nav_uri (uri ,
79- count = request .GET .get ('_count' , 10 ),
80- start_index = request .GET .get ('startIndex' , 0 ),
81- id_type = id_type ,
82- id = id )
61+ # for now it's either EOB or Coverage, make this more generic later
62+ patient = request .GET .get ('patient' )
63+ beneficiary = request .GET .get ('beneficiary' )
64+ if patient is not None :
65+ id_type = 'patient'
66+ id = patient
67+ elif beneficiary is not None :
68+ id_type = 'beneficiary'
69+ id = beneficiary
70+ else :
71+ # We should not be able to get here.
72+ raise ValueError ("Failed to set a patient id or beneficiary id on the pagination URI" ) # noqa: E702
73+
74+ # Extend the base URI with pagination information.
75+ uri = EndpointUrl .nav_uri (uri ,
76+ count = request .GET .get ('_count' , 10 ),
77+ start_index = request .GET .get ('startIndex' , 0 ),
78+ id_type = id_type ,
79+ id = id )
8380 return uri
8481
8582
8683def _get_fhir_data_as_json (request : HttpRequest , params : FhirDataParams ) -> Dict [str , object ]:
8784 """Make a call to the FHIR backend and return the JSON data from the call"""
8885 uri = EndpointUrl .fmt (params .name , params .uri , params .version , params .patient )
8986
90- if params .version in [Versions .V1 , Versions .V2 ]:
91- pagination_uri = _build_pagination_uri (params , request )
92- if pagination_uri is not None :
93- uri = pagination_uri
87+ if params .version in [Versions .V1 , Versions .V2 ] and request .GET .get ('nav_link' , None ):
88+ uri = _build_pagination_uri (uri , params , request )
9489
9590 oas = _get_oauth2_session_with_token (request )
9691 r = oas .get (uri )
@@ -109,7 +104,7 @@ def _convert_response_string_to_json(json_response: str) -> Dict[str, object]:
109104 try :
110105 return json .loads (json_response .content )
111106 except JSONDecodeError :
112- return {'error' : f'Could not decode JSON; status code { json_response .status_code } ' }
107+ return {'error' : f'Could not decode JSON; status code { json_response .status_code } ' } # noqa: E702
113108 else :
114109 # Same as above.
115110 return {'error' : json_response .status_code }
0 commit comments