Skip to content

Commit

Permalink
Fixup FHIR compliance; add missing resource nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-c committed Nov 19, 2024
1 parent 513a1d8 commit 69f27ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion patientsearch/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def external_search(resource_type):
audit_entry("multiple patients returned from PDMP", extra=extra, level="warn")

if external_match_count:
external_search_bundle["entry"][0].setdefault("id", local_fhir_patient["id"])
external_search_bundle["entry"][0]["resource"].setdefault("id", local_fhir_patient["id"])

message = "PDMP found match" if external_match_count else "fEMR found match"
audit_entry(message, extra=extra)
Expand Down
12 changes: 6 additions & 6 deletions patientsearch/models/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def add_identifier_to_resource_type(bundle, resource_type, identifier):
return result

for resource in result["entry"]:
if resource.get("resourceType") != resource_type:
if resource["resource"].get("resourceType") != resource_type:
continue
identifiers = resource.get("identifier", [])
identifiers = resource["resource"].get("identifier", [])
found = False
for i in identifiers:
if (
Expand All @@ -30,7 +30,7 @@ def add_identifier_to_resource_type(bundle, resource_type, identifier):
break
if not found:
identifiers.append(identifier)
resource["identifier"] = identifiers
resource["resource"]["identifier"] = identifiers
return result


Expand Down Expand Up @@ -165,10 +165,10 @@ def sync_bundle(token, bundle, consider_active=False):

for entry in bundle.get("entry"):
# Restrict to what is expected for now
if entry["resourceType"] != "Patient":
raise ValueError(f"Can't sync resourceType {entry['resourceType']}")
if entry["resource"]["resourceType"] != "Patient":
raise ValueError(f"Can't sync resourceType {entry['resource']['resourceType']}")

patient = sync_patient(token, entry, consider_active)
patient = sync_patient(token, entry["resource"], consider_active)
# TODO handle multiple external matches (if it ever happens!)
# currently returning first
return patient
Expand Down

0 comments on commit 69f27ec

Please sign in to comment.