diff --git a/mediator/src/utils/fhir.ts b/mediator/src/utils/fhir.ts index f56260f2..28fad9b6 100644 --- a/mediator/src/utils/fhir.ts +++ b/mediator/src/utils/fhir.ts @@ -187,7 +187,7 @@ export async function getFhirResourcesSince(lastUpdated: Date, resourceType: str */ function getNextUrl(url: string, pagination: any) { let nextUrl = ''; - const nextLink = pagination.link && pagination.link.find((link: any) => link.relation === 'next'); + const nextLink = pagination.link?.find((link: any) => link.relation === 'next'); if (nextLink?.url) { const qs = nextLink.url.split('?')[1]; nextUrl = `${url}/?${qs}`; diff --git a/mediator/src/utils/openmrs_sync.ts b/mediator/src/utils/openmrs_sync.ts index 0836adfe..585b3e03 100644 --- a/mediator/src/utils/openmrs_sync.ts +++ b/mediator/src/utils/openmrs_sync.ts @@ -313,16 +313,26 @@ export async function sendEncounterToFhir( observations.forEach(o => sendObservationToFhir(o, existingPatient)); + sendEncounterToCht(encounter, existingPatient, observations); +} + +/* + Send an Encounter from OpenMRS to CHT +*/ +export async function sendEncounterToCht( + encounter: fhir4.Encounter, + patient: fhir4.Patient, + observations: fhir4.Observation[] +) { logger.info(`Sending Encounter ${encounter.id} to CHT`); - const chtResponse = await chtRecordFromObservations(existingPatient.id, observations); + const chtResponse = await chtRecordFromObservations(patient, observations); if (chtResponse.status != 200) { logger.error(`Error saving encounter to cht ${encounter.id}: ${chtResponse.status}`); return } const chtId = chtResponse.data.id; - addId(encounter, chtDocumentIdentifierType, chtId) - + addId(encounter, chtDocumentIdentifierType, chtId); await updateFhirResource(encounter); }