diff --git a/src/utils/kafkaFhir.ts b/src/utils/kafkaFhir.ts index 2763329..47e147d 100644 --- a/src/utils/kafkaFhir.ts +++ b/src/utils/kafkaFhir.ts @@ -178,16 +178,19 @@ export const processBundle = async (bundle: Bundle): Promise { + let guttedPatient: ResponseObject; + let id: string; + if (patientEntry.fullUrl) { // Check if patient already exists and perform update - const guttedPatient = await sendRequest({ + guttedPatient = await sendRequest({ ...fhirDatastoreRequestDetails, method: 'GET', path: `/fhir/Patient/${patientEntry.fullUrl.split('/').pop()}`, }); if (isHttpStatusOk(guttedPatient.status)) { - const id: string = Object.assign(guttedPatient.body).link[0].other.reference.split('/').pop(); + id = Object.assign(guttedPatient.body).link[0].other.reference.split('/').pop(); let mpiPatient = await sendRequest({ ...clientRegistryRequestDetails, @@ -224,7 +227,12 @@ export const processBundle = async (bundle: Bundle): Promise { + if (isHttpStatusOk(guttedPatient.status)) { + return {status: response.status, body: {...response.body, id}} + } + return response; + }); }); const clientRegistryResponses = await Promise.all(promises);