Skip to content

Commit 7579701

Browse files
Address PR feedback: use parse_qs, remove parse_string function/tests
1 parent 4f35128 commit 7579701

File tree

2 files changed

+7
-28
lines changed

2 files changed

+7
-28
lines changed

apps/fhir/bluebutton/tests/test_utils.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
crosswalk_patient_id,
1919
get_resourcerouter,
2020
build_oauth_resource,
21-
parse_string,
2221
valid_patient_read_or_search_call,
2322
)
2423

@@ -71,16 +70,6 @@ def test_notNone(self):
7170
response = notNone(listing, "number")
7271
self.assertEqual(response, listing)
7372

74-
def test_parse_string(self):
75-
result = parse_string('PatientId:-20140000008326', ':')
76-
assert result == '-20140000008326'
77-
78-
result = parse_string('?_lastUpdated=lt2024-06-15&startIndex=0&cursor=0&_id=-99000010256546', '_id=')
79-
assert result == '-99000010256546'
80-
81-
result = parse_string('?_lastUpdated=lt2024-06-15&startIndex=0&cursor=0&_id=-99000010256546', '_id==')
82-
assert result is None
83-
8473
def test_valid_patient_read_or_search_call_valid_read_calls(self):
8574
result = valid_patient_read_or_search_call('PatientId:-20140000008329', '-20140000008329', '')
8675
assert result is True

apps/fhir/bluebutton/utils.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from datetime import datetime
1212
from pytz import timezone
1313
from typing import Optional
14+
from urllib.parse import parse_qs
1415

1516
from django.conf import settings
1617
from 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-
762750
def 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

Comments
 (0)