Skip to content

Commit

Permalink
Merge pull request #42 from jembi/Enable-patient-update
Browse files Browse the repository at this point in the history
Enable patient update
  • Loading branch information
MatthewErispe authored May 6, 2024
2 parents 715186d + 6b154ef commit 9cc1e01
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
33 changes: 30 additions & 3 deletions src/utils/kafkaFhir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,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<MpiMediatorResponseObject> => {
Expand Down Expand Up @@ -185,10 +184,38 @@ export const processBundle = async (bundle: Bundle): Promise<MpiMediatorResponse
}

const newPatientMap: NewPatientMap = {};

// transform and send each patient resource and submit to MPI
const promises = patientEntries.map(async (patientEntry) => {
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 id: string = Object.assign(guttedPatient.body).link[0].other.reference.split('/').pop();

let mpiPatient = await sendRequest({
...clientRegistryRequestDetails,
method: 'GET',
path: `/fhir/links/Patient/${id}`,
});

if (!isHttpStatusOk(mpiPatient.status)) {
mpiPatient = await sendRequest({
...clientRegistryRequestDetails,
method: 'GET',
path: `/fhir/Patient/${id}`,
});
}

clientRegistryRequestDetails.method = 'PUT';
clientRegistryRequestDetails.path = `/fhir/Patient/${
Object.assign(mpiPatient.body).id
}`;
}
newPatientMap[patientEntry.fullUrl] = {
mpiTransformResult: transformPatientResourceForMPI(patientEntry.resource as Patient),
};
Expand Down
1 change: 0 additions & 1 deletion tests/unit/matchPatientSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
Expand Down

0 comments on commit 9cc1e01

Please sign in to comment.