From d86d85b0da27f87325b3d3a37a39833a6054b548 Mon Sep 17 00:00:00 2001 From: bradsawadye Date: Fri, 3 May 2024 13:29:48 +0200 Subject: [PATCH 1/3] Enable updating of patients --- src/utils/kafkaFhir.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/utils/kafkaFhir.ts b/src/utils/kafkaFhir.ts index c14a89b..1ff1a8e 100644 --- a/src/utils/kafkaFhir.ts +++ b/src/utils/kafkaFhir.ts @@ -144,8 +144,7 @@ const fhirDatastoreRequestDetailsOrg: RequestDetails = { port: config.fhirDatastorePort, headers: { 'Content-Type': 'application/fhir+json' }, method: 'POST', - path: '/fhir', - data: '', + path: '/fhir' }; export const processBundle = async (bundle: Bundle): Promise => { @@ -177,10 +176,26 @@ export const processBundle = async (bundle: Bundle): Promise { if (patientEntry.fullUrl) { + // Check if patient already exists and perform update + const guttedPatient = await sendRequest({ + ...fhirDatastoreRequestDetails, + method: 'GET', + path: `/fhir/Patient/${patientEntry.fullUrl.split('/').pop()}`, + }); + if (isHttpStatusOk(guttedPatient.status)) { + const mpiPatient = await sendRequest({ + ...clientRegistryRequestDetails, + method: 'GET', + path: `/fhir/links/Patient/${Object.assign(guttedPatient.body).link[0].other.reference}`, + }); + clientRegistryRequestDetails.method = 'PUT'; + clientRegistryRequestDetails.path = `/fhir/Patient/${ + Object.assign(mpiPatient.body).id + }`; + } newPatientMap[patientEntry.fullUrl] = { mpiTransformResult: transformPatientResourceForMPI(patientEntry.resource as Patient), }; From 1bc2af71085ec7631ab6d8ba353303d1672f3cb4 Mon Sep 17 00:00:00 2001 From: bradsawadye Date: Fri, 3 May 2024 13:30:41 +0200 Subject: [PATCH 2/3] Fix tests --- tests/unit/matchPatientSync.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/matchPatientSync.ts b/tests/unit/matchPatientSync.ts index 1105f4a..316a16a 100644 --- a/tests/unit/matchPatientSync.ts +++ b/tests/unit/matchPatientSync.ts @@ -28,7 +28,6 @@ describe('Match Patient Synchronously', (): void => { headers: { 'Content-Type': 'application/fhir+json' }, method: 'POST', path: '/fhir', - data: '', }; it('should return error when validation fails', async (): Promise => { From 6b154ef3ac0da565a872ebf14447b96bbb55c7cb Mon Sep 17 00:00:00 2001 From: bradsawadye Date: Fri, 3 May 2024 15:15:10 +0200 Subject: [PATCH 3/3] Cater for sante mpi --- src/utils/kafkaFhir.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/utils/kafkaFhir.ts b/src/utils/kafkaFhir.ts index 1ff1a8e..2763329 100644 --- a/src/utils/kafkaFhir.ts +++ b/src/utils/kafkaFhir.ts @@ -185,12 +185,24 @@ export const processBundle = async (bundle: Bundle): Promise