Skip to content

Commit

Permalink
Merge pull request #234 from uwcirg/develop
Browse files Browse the repository at this point in the history
merge dev changes into main for release
  • Loading branch information
pbugni authored Dec 4, 2024
2 parents 513a1d8 + c9c8526 commit 0e33a95
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 23 deletions.
4 changes: 3 additions & 1 deletion patientsearch/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions patientsearch/models/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", [])
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions patientsearch/src/js/constants/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 3 additions & 2 deletions patientsearch/src/js/helpers/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 8 additions & 7 deletions tests/test_sync/external_patient_active_search.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"entry": [
{
"entry": [
{
"resource": {
"active": true,
"birthDate": "1977-01-12",
"gender": "male",
Expand All @@ -10,8 +11,8 @@
},
"resourceType": "Patient"
}
],
"resourceType": "Bundle",
"type": "searchset"
}
}
],
"resourceType": "Bundle",
"type": "searchset"
}
16 changes: 9 additions & 7 deletions tests/test_sync/external_patient_search.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 0e33a95

Please sign in to comment.