diff --git a/patientsearch/api.py b/patientsearch/api.py index 2697935a..eea163fc 100644 --- a/patientsearch/api.py +++ b/patientsearch/api.py @@ -629,7 +629,9 @@ 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) diff --git a/patientsearch/models/sync.py b/patientsearch/models/sync.py index ceb53645..1a8dd486 100644 --- a/patientsearch/models/sync.py +++ b/patientsearch/models/sync.py @@ -16,7 +16,8 @@ def add_identifier_to_resource_type(bundle, resource_type, identifier): if "entry" not in result: return result - for resource in result["entry"]: + for entry in result["entry"]: + resource = entry["resource"] if resource.get("resourceType") != resource_type: continue identifiers = resource.get("identifier", []) @@ -164,11 +165,12 @@ def sync_bundle(token, bundle, consider_active=False): raise ValueError(f"Expected bundle; can't process {bundle.get('resourceType')}") for entry in bundle.get("entry"): + resource = entry["resource"] # Restrict to what is expected for now - if entry["resourceType"] != "Patient": - raise ValueError(f"Can't sync resourceType {entry['resourceType']}") + if resource["resourceType"] != "Patient": + raise ValueError(f"Can't sync resourceType {resource['resourceType']}") - patient = sync_patient(token, entry, consider_active) + patient = sync_patient(token, resource, consider_active) # TODO handle multiple external matches (if it ever happens!) # currently returning first return patient diff --git a/patientsearch/src/js/constants/consts.js b/patientsearch/src/js/constants/consts.js index 373c281c..35b4055a 100644 --- a/patientsearch/src/js/constants/consts.js +++ b/patientsearch/src/js/constants/consts.js @@ -154,3 +154,4 @@ export const ACCESS_TOKEN_KEY = "access_token"; export const REALM_ACCESS_TOKEN_KEY = "realm_access"; export const MAX_MAIN_TABLE_WIDTH = "1280px"; export const FOLLOWING_FLAG = "following"; +export const MIN_QUERY_COUNT = 500; diff --git a/patientsearch/src/js/helpers/utility.js b/patientsearch/src/js/helpers/utility.js index 5129d4ad..68311de7 100644 --- a/patientsearch/src/js/helpers/utility.js +++ b/patientsearch/src/js/helpers/utility.js @@ -2,6 +2,7 @@ import differenceInMonths from "date-fns/differenceInMonths"; import isValid from "date-fns/isValid"; import { ACCESS_TOKEN_KEY, + MIN_QUERY_COUNT, REALM_ACCESS_TOKEN_KEY, noCacheParam, } from "../constants/consts"; @@ -541,7 +542,7 @@ export async function getPatientIdsByCareTeamParticipant(practitionerId) { if (!practitionerId) return null; const results = await Promise.allSettled([ fetchData( - `/fhir/Patient?general-practitioner=Practitioner/${practitionerId}&_count=200`, + `/fhir/Patient?general-practitioner=Practitioner/${practitionerId}&_count=${MIN_QUERY_COUNT}`, noCacheParam, (error) => { if (error) { @@ -554,7 +555,7 @@ export async function getPatientIdsByCareTeamParticipant(practitionerId) { } ), fetchData( - `/fhir/CareTeam?participant=Practitioner/${practitionerId}&_count=200`, + `/fhir/CareTeam?participant=Practitioner/${practitionerId}&_count=${MIN_QUERY_COUNT}`, noCacheParam, (error) => { if (error) { diff --git a/tests/test_sync.py b/tests/test_sync.py index 7eb484e6..d1fd540c 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -150,8 +150,8 @@ def test_adding_identifier(external_patient_search): result = add_identifier_to_resource_type(external_patient_search, "Patient", ident) assert result != external_patient_search for entry in result["entry"]: - assert len(entry["identifier"]) == 1 - assert entry["identifier"][0] == ident + assert len(entry["resource"]["identifier"]) == 1 + assert entry["resource"]["identifier"][0] == ident def test_existing( diff --git a/tests/test_sync/external_patient_active_search.json b/tests/test_sync/external_patient_active_search.json index 77584bfe..503f0888 100644 --- a/tests/test_sync/external_patient_active_search.json +++ b/tests/test_sync/external_patient_active_search.json @@ -1,6 +1,7 @@ { - "entry": [ - { + "entry": [ + { + "resource": { "active": true, "birthDate": "1977-01-12", "gender": "male", @@ -10,8 +11,8 @@ }, "resourceType": "Patient" } - ], - "resourceType": "Bundle", - "type": "searchset" - } - \ No newline at end of file + } + ], + "resourceType": "Bundle", + "type": "searchset" +} diff --git a/tests/test_sync/external_patient_search.json b/tests/test_sync/external_patient_search.json index 93b8ff80..67301369 100644 --- a/tests/test_sync/external_patient_search.json +++ b/tests/test_sync/external_patient_search.json @@ -1,13 +1,15 @@ { "entry": [ { - "birthDate": "1977-01-12", - "gender": "male", - "name": { - "family": "skywalker", - "given": ["luke"] - }, - "resourceType": "Patient" + "resource": { + "birthDate": "1977-01-12", + "gender": "male", + "name": { + "family": "skywalker", + "given": ["luke"] + }, + "resourceType": "Patient" + } } ], "resourceType": "Bundle",