1111from datetime import datetime
1212from pytz import timezone
1313from typing import Optional
14+ from urllib .parse import parse_qs
1415
1516from django .conf import settings
1617from django .contrib import messages
@@ -746,19 +747,6 @@ def get_patient_by_mbi_hash(mbi_hash, request):
746747 return response .json ()
747748
748749
749- def parse_string (string_to_parse : str , split_char : str ) -> str :
750- """_summary_
751- Args:
752- string_to_parse (str): _description_
753- split_char (str): _description_
754- Returns:
755- str: _description_
756- """
757- parts = string_to_parse .split (split_char , 1 )
758- parsed_string = parts [1 ] if len (parts ) > 1 else None
759- return parsed_string
760-
761-
762750def valid_patient_read_or_search_call (beneficiary_id : str , resource_id : Optional [str ], query_param : str ) -> bool :
763751 """Determine if a read or search Patient call is valid, based on what was passed for the resource_id (read call)
764752 or the query_parameter (search call)
@@ -772,16 +760,18 @@ def valid_patient_read_or_search_call(beneficiary_id: str, resource_id: Optional
772760 Returns:
773761 bool: Whether or not the call is valid
774762 """
775- beneficiary_id = parse_string (beneficiary_id , ':' )
763+ bene_split = beneficiary_id .split (':' , 1 )
764+ beneficiary_id = bene_split [1 ] if len (bene_split ) > 1 else None
776765 # Handles the case where it is a read call, but what is passed does not match the beneficiary_id
777766 # which is constructed using the patient id for the current session in generate_info_headers.
778- if resource_id and resource_id != beneficiary_id :
767+ if resource_id and beneficiary_id and resource_id != beneficiary_id :
779768 return False
780769
781770 # Handles the case where it is a search call, but what is passed does not match the beneficiary_id
782771 # so a 404 Not found will be thrown before reaching out to BFD
783- patient_id = parse_string (query_param , '_id=' )
784- if patient_id and patient_id != beneficiary_id :
772+ query_dict = parse_qs (query_param )
773+ passed_identifier = query_dict .get ('_id' , [None ])
774+ if passed_identifier [0 ] and passed_identifier [0 ] != beneficiary_id :
785775 return False
786776
787777 return True
0 commit comments