Skip to content

Commit

Permalink
(fix): O3-1112: Offline actions don't display offline registered pati…
Browse files Browse the repository at this point in the history
…ents correctly (#331)

* Consider offline patients in the offline actions table.

* Remove unnecessary null check.
  • Loading branch information
manuelroemer authored Feb 17, 2022
1 parent 5bd3f88 commit 324eb32
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 188 deletions.
22 changes: 16 additions & 6 deletions packages/apps/esm-offline-tools-app/src/hooks/offline-actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
fetchCurrentPatient,
getOfflineDb,
getSynchronizationItems,
SyncItem,
} from "@openmrs/esm-framework";
import uniq from "lodash-es/uniq";
Expand All @@ -26,11 +27,20 @@ export function useSyncItemPatients(syncItems?: Array<SyncItem>) {

return useSWR(
() => ["patients", ...patientUuids],
async () => {
const results: Array<{ data: fhir.Patient }> = await Promise.all(
patientUuids.map((id) => fetchCurrentPatient(id))
);
return results.map((res) => res.data);
}
() => Promise.all(patientUuids.map((id) => getFhirPatient(id)))
);
}

async function getFhirPatient(patientUuid: string) {
const syncItems = await getSynchronizationItems<{
fhirPatient?: fhir.Patient;
}>("patient-registration");
const offlineRegisteredPatient = syncItems.find(
(syncItem) => syncItem.fhirPatient?.id === patientUuid
)?.fhirPatient;

return (
offlineRegisteredPatient ??
(await fetchCurrentPatient(patientUuid).then((res) => res.data))
);
}
Loading

0 comments on commit 324eb32

Please sign in to comment.