Skip to content

Commit

Permalink
chore(#142): sonar fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
witash committed Oct 22, 2024
1 parent 1a5be52 commit d6db1d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mediator/src/utils/fhir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
16 changes: 13 additions & 3 deletions mediator/src/utils/openmrs_sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit d6db1d6

Please sign in to comment.