Skip to content

Commit

Permalink
populate mamba reports
Browse files Browse the repository at this point in the history
  • Loading branch information
lucyjemutai committed May 16, 2024
1 parent c50c7a3 commit 33ebfb4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
21 changes: 21 additions & 0 deletions packages/esm-commons-lib/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,24 @@ export async function fetchMambaReportData(reportId: string) {
throw new Error(`Error fetching data for report_id=${reportId}: ${error}`);
}
}
export async function fetchMambaAncData(reportId: string, patientUuid: string) {
try {
const response = await openmrsFetch(`ws/rest/v1/mamba/report?report_id=${reportId}&person_uuid=${patientUuid}`);
const data = await response.json();

if (data && data.results && data.results.length > 0) {
const record = data.results[0].record;

for (const item of record) {
if (item.value !== '') {
return item.value;
}
}
}

return '--';
} catch (error) {
console.error(`Error fetching data for report_id=${reportId}: `, error);
throw new Error(`Error fetching data for report_id=${reportId}: ${error}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
fetchPatientLastEncounter,
SummaryCardColumn,
SummaryCard,
fetchMambaReportData,
fetchMambaAncData,
} from '@ohri/openmrs-esm-ohri-commons-lib';
import dayjs from 'dayjs';
import { moduleName } from '../../..';
Expand Down Expand Up @@ -49,13 +49,18 @@ const CurrentPregnancy: React.FC<PatientChartProps> = ({ patientUuid }) => {
const [infantOutcomes, setInfantOutcomes] = useState([]);
const { formNames, encounterTypes, obsConcepts, formUuids } = useConfig();
const [totalAncCount, setTotalAncCount] = useState(null);
const [motherStatus, setMotherStatus] = useState(null);
const [deliveryDate, setDeliveryDate] = useState(null);

useEffect(() => {
const fetchData = async () => {
try {
const [totalAncCount] = await Promise.all([fetchMambaReportData('no_of_anc_visits')]);

const [totalAncCount] = await Promise.all([fetchMambaAncData('no_of_anc_visits', patientUuid)]);
const [motherStatus] = await Promise.all([fetchMambaAncData('mother_status', patientUuid)]);
const [deliveryDate] = await Promise.all([fetchMambaAncData('estimated_date_of_delivery', patientUuid)]);
setTotalAncCount(totalAncCount);
setMotherStatus(motherStatus);
setDeliveryDate(deliveryDate);
} catch (error) {
console.error('Error fetching data:', error);
throw new Error('Error fetching data. Please try again.');
Expand Down Expand Up @@ -266,29 +271,21 @@ const CurrentPregnancy: React.FC<PatientChartProps> = ({ patientUuid }) => {
{
key: 'expectedDeliveryDate',
header: t('expectedDeliveryDate', 'Expected Delivery Date'),
encounterTypes: [encounterTypes.antenatal],
encounterTypes: [encounterTypes.labourAndDelivery],
getObsValue: async ([encounter]) => {
return getObsFromEncounter(encounter, obsConcepts.eDDConcept, true);
},
getObsSummary: ([encounter]) => {
let edd = getObsFromEncounter(encounter, obsConcepts.eDDConcept, true);
if (edd !== '--') {
const days = calculateDateDifferenceInDate(edd);
edd = edd > 0 ? `In ${days}` : '';
}
return edd;
return deliveryDate;
},
},
{
key: 'motherStatus',
header: t('motherStatus', 'Mother Status'),
encounterTypes: [encounterTypes.labourAndDelivery],
getObsValue: async ([encounter]) => {
return getObsFromEncounter(encounter, obsConcepts.motherStatusConcept);
return motherStatus;
},
},
],
[],
[motherStatus, deliveryDate],
);

const arvTherapyColumns: SummaryCardColumn[] = useMemo(
Expand Down

0 comments on commit 33ebfb4

Please sign in to comment.