Skip to content

Commit

Permalink
Previous values are picked from old encounters
Browse files Browse the repository at this point in the history
  • Loading branch information
lucyjemutai committed Sep 14, 2023
1 parent 09d6538 commit 84eb470
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prettier/prettier */
import { openmrsFetch, openmrsObservableFetch } from '@openmrs/esm-framework';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
Expand Down Expand Up @@ -27,13 +28,6 @@ export function getLocationsByTag(tag: string): Observable<{ uuid: string; displ
);
}

export function getPreviousEncounter(patientUuid: string, encounterType) {
const query = `encounterType=${encounterType}&patient=${patientUuid}`;
return openmrsFetch(`/ws/rest/v1/encounter?${query}&limit=1&v=${encounterRepresentation}`).then(({ data }) => {
return data.results.length ? data.results[0] : null;
});
}

export function fetchConceptNameByUuid(conceptUuid: string) {
return openmrsFetch(`/ws/rest/v1/concept/${conceptUuid}/name?limit=1`).then(({ data }) => {
if (data.results.length) {
Expand Down Expand Up @@ -97,3 +91,23 @@ export async function fetchClobData(form: OpenmrsForm): Promise<any | null> {

return clobDataResponse;
}

export function getPreviousEncounter(patientUuid: string, encounterType: string) {
const query = `patient=${patientUuid}&_sort=-_lastUpdated&_count=1&type=${encounterType}`;
return openmrsFetch(`/ws/fhir2/R4/Encounter?${query}`).then(async ({ data }) => {
console.log('LUCY_FHIR', data);
if (data.total > 0) {
const latestEncounter = data.entry[0].resource;
console.log('TEST', latestEncounter.id);

const query = `encounterType=${encounterType}&patient=${patientUuid}`;
return openmrsFetch(`/ws/rest/v1/encounter/${latestEncounter.id}?${query}&limit=1&v=${encounterRepresentation}`,
).then(({ data }) => {
console.log('LUCY_REST', data);
return data.results.length ? data.results[0] : null;
});
} else {
return null;
}
});
}

0 comments on commit 84eb470

Please sign in to comment.