Skip to content

Commit

Permalink
feat: check if OpenMRS patient exists before creating a new one
Browse files Browse the repository at this point in the history
  • Loading branch information
njogz committed Nov 5, 2024
1 parent 2162895 commit e57f9bb
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions mediator/src/utils/openmrs_sync.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
getFhirResourcesSince,
updateFhirResource,
createFhirResource,
getIdType,
addId,
addSourceMeta,
copyIdToNamedIdentifier,
getFhirResource,
replaceReference,
createFhirResource,
getFHIRPatientResource,
addSourceMeta
getFhirResourceByIdentifier,
getFhirResourcesSince,
getIdType,
replaceReference,
updateFhirResource
} from './fhir'
import { SYNC_INTERVAL } from '../../config'
import { getOpenMRSResourcesSince, createOpenMRSResource } from './openmrs'
Expand Down Expand Up @@ -126,6 +126,12 @@ export async function compare(
And forward to CHT if successful
*/
async function sendPatientToFhir(patient: fhir4.Patient) {
// check if patient already exists
const openMRSPatient = await getFhirResourceByIdentifier(getIdType(patient, openMRSIdentifierType), 'Patient');
if (openMRSPatient.data?.total > 0) {
logger.error(`Patient with the same patient_id already exists`);
return { status: 200, data: { message: `Patient with the same ${openMRSIdentifierType} already exists`} };
}
logger.info(`Sending Patient ${patient.id} to FHIR`);
copyIdToNamedIdentifier(patient, patient, openMRSIdentifierType);
addSourceMeta(patient, openMRSSource);
Expand Down

0 comments on commit e57f9bb

Please sign in to comment.