From 33ebfb4a42bf9c74e75fce890a9b0e79755bf055 Mon Sep 17 00:00:00 2001 From: lucyjemutai Date: Thu, 16 May 2024 20:29:28 +0300 Subject: [PATCH 1/9] populate mamba reports --- packages/esm-commons-lib/src/api/api.ts | 21 +++++++++++++++ .../tabs/current-pregnancy.component.tsx | 27 +++++++++---------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/packages/esm-commons-lib/src/api/api.ts b/packages/esm-commons-lib/src/api/api.ts index eb0845427..3579697cb 100644 --- a/packages/esm-commons-lib/src/api/api.ts +++ b/packages/esm-commons-lib/src/api/api.ts @@ -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}`); + } +} diff --git a/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx b/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx index c1b1419a2..93d4d6604 100644 --- a/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx +++ b/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx @@ -11,7 +11,7 @@ import { fetchPatientLastEncounter, SummaryCardColumn, SummaryCard, - fetchMambaReportData, + fetchMambaAncData, } from '@ohri/openmrs-esm-ohri-commons-lib'; import dayjs from 'dayjs'; import { moduleName } from '../../..'; @@ -49,13 +49,18 @@ const CurrentPregnancy: React.FC = ({ 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.'); @@ -266,17 +271,9 @@ const CurrentPregnancy: React.FC = ({ 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; }, }, { @@ -284,11 +281,11 @@ const CurrentPregnancy: React.FC = ({ patientUuid }) => { header: t('motherStatus', 'Mother Status'), encounterTypes: [encounterTypes.labourAndDelivery], getObsValue: async ([encounter]) => { - return getObsFromEncounter(encounter, obsConcepts.motherStatusConcept); + return motherStatus; }, }, ], - [], + [motherStatus, deliveryDate], ); const arvTherapyColumns: SummaryCardColumn[] = useMemo( From 3b50cd124bdbcdbd3d603cb669a231e8e952e986 Mon Sep 17 00:00:00 2001 From: lucyjemutai Date: Mon, 20 May 2024 12:00:58 +0300 Subject: [PATCH 2/9] update for the Mother-Hiv-Status --- packages/esm-commons-lib/src/api/api.ts | 37 +++++++++++-- packages/esm-commons-lib/src/types/index.ts | 1 + .../mch-summary/mch-summary.component.tsx | 19 ++++++- .../tabs/current-pregnancy.component.tsx | 53 ++++++++----------- 4 files changed, 73 insertions(+), 37 deletions(-) diff --git a/packages/esm-commons-lib/src/api/api.ts b/packages/esm-commons-lib/src/api/api.ts index 3579697cb..63ecc1321 100644 --- a/packages/esm-commons-lib/src/api/api.ts +++ b/packages/esm-commons-lib/src/api/api.ts @@ -255,16 +255,38 @@ 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) { + +export async function fetchData( + reportType: 'fetchMambaAncData' | 'MotherHivStatus', + reportId?: string, + patientUuid?: string, + pTrackerId?: string, +) { try { - const response = await openmrsFetch(`ws/rest/v1/mamba/report?report_id=${reportId}&person_uuid=${patientUuid}`); + let endpoint = ''; + switch (reportType) { + case 'fetchMambaAncData': + endpoint = `ws/rest/v1/mamba/report?report_id=${reportId}&person_uuid=${patientUuid}`; + break; + case 'MotherHivStatus': + endpoint = `ws/rest/v1/mamba/report?report_id=${reportId}&ptracker_id=${pTrackerId}&person_uuid=${patientUuid}`; + break; + default: + throw new Error('Invalid report type'); + } + + const response = await openmrsFetch(endpoint); 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 !== '') { + if (!isNaN(item.value as any)) { + return parseInt(item.value, 10); + } else if (isInvalidValue(item.value)) { + return '--'; + } else { return item.value; } } @@ -276,3 +298,12 @@ export async function fetchMambaAncData(reportId: string, patientUuid: string) { throw new Error(`Error fetching data for report_id=${reportId}: ${error}`); } } + +function isInvalidValue(value: any): boolean { + if (typeof value === 'string') { + return value.trim() === ''; + } else if (value instanceof Date) { + return isNaN(value.getTime()); + } + return false; +} diff --git a/packages/esm-commons-lib/src/types/index.ts b/packages/esm-commons-lib/src/types/index.ts index 48f5f7d24..10d262af4 100644 --- a/packages/esm-commons-lib/src/types/index.ts +++ b/packages/esm-commons-lib/src/types/index.ts @@ -14,4 +14,5 @@ export interface DashboardConfig extends DashboardLinkConfig { export interface PatientChartProps { patientUuid: string; + pTrackerId?: string; } diff --git a/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx b/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx index 3e9a19083..d2fd4cea4 100644 --- a/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx +++ b/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx @@ -5,14 +5,29 @@ import styles from '../common.scss'; import { PatientChartProps } from '@ohri/openmrs-esm-ohri-commons-lib'; import CurrentPregnancy from './tabs/current-pregnancy.component'; import HivExposedInfant from './tabs/hiv-exposed-infant.component'; -import { usePatient } from '@openmrs/esm-framework'; +import { usePatient, useConfig } from '@openmrs/esm-framework'; import dayjs from 'dayjs'; const MaternalSummary: React.FC = ({ patientUuid }) => { const { t } = useTranslation(); + const { identifiersTypes } = useConfig(); const { patient, isLoading } = usePatient(patientUuid); const dob = patient?.birthDate; const age = useMemo(() => dayjs().diff(dayjs(patient?.birthDate), 'year'), [patient?.birthDate]); + const [pTrackerId, setPtrackerId] = useState(''); + + useEffect(() => { + if (patient) { + const lastIdentifier = patient.identifier + .slice() + .reverse() + .find((identifier) => identifier.type.id === identifiersTypes.PTrackerIdentifierType); + + if (lastIdentifier) { + setPtrackerId(lastIdentifier.value); + } + } + }, [patient]); return ( <> @@ -27,7 +42,7 @@ const MaternalSummary: React.FC = ({ patientUuid }) => { - + diff --git a/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx b/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx index 93d4d6604..224e8e947 100644 --- a/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx +++ b/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx @@ -11,7 +11,7 @@ import { fetchPatientLastEncounter, SummaryCardColumn, SummaryCard, - fetchMambaAncData, + fetchData, } from '@ohri/openmrs-esm-ohri-commons-lib'; import dayjs from 'dayjs'; import { moduleName } from '../../..'; @@ -35,7 +35,7 @@ export interface familyItemProps { hivStatus: string; finalOutcome: string; } -const CurrentPregnancy: React.FC = ({ patientUuid }) => { +const CurrentPregnancy: React.FC = ({ patientUuid, pTrackerId }) => { const { t } = useTranslation(); const currentPregnancyHeader = t('recentPregnancy', 'Recent Pregnancy'); const arvTherapyHeader = t('art', 'ART'); @@ -51,24 +51,34 @@ const CurrentPregnancy: React.FC = ({ patientUuid }) => { const [totalAncCount, setTotalAncCount] = useState(null); const [motherStatus, setMotherStatus] = useState(null); const [deliveryDate, setDeliveryDate] = useState(null); + const [motherHivStatus, setMotherHivStatus] = useState(null); + const [loading, setLoading] = useState(true); useEffect(() => { - const fetchData = async () => { + const fetchDataAndSetState = async () => { try { - 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)]); + setLoading(true); + const [totalAncCount, motherStatus, deliveryDate, motherHivStatus] = await Promise.all([ + fetchData('fetchMambaAncData', 'no_of_anc_visits', patientUuid), + fetchData('fetchMambaAncData', 'mother_status', patientUuid), + fetchData('fetchMambaAncData', 'estimated_date_of_delivery', patientUuid), + fetchData('MotherHivStatus', 'mother_hiv_status', patientUuid, pTrackerId), + ]); + setTotalAncCount(totalAncCount); setMotherStatus(motherStatus); setDeliveryDate(deliveryDate); + setMotherHivStatus(motherHivStatus); } catch (error) { console.error('Error fetching data:', error); throw new Error('Error fetching data. Please try again.'); + } finally { + setLoading(false); } }; - fetchData(); - }, []); + fetchDataAndSetState(); + }, [patientUuid, pTrackerId]); const headersFamily = [ { @@ -242,32 +252,11 @@ const CurrentPregnancy: React.FC = ({ patientUuid }) => { { key: 'motherHIVStatus', header: t('motherHIVStatus', 'Mother HIV Status'), - encounterTypes: [encounterTypes.motherPostnatal, encounterTypes.labourAndDelivery, encounterTypes.antenatal], - getObsValue: (encounters) => { - const pncArtData = { - artInitiation: getObsFromEncounter(encounters[0], obsConcepts.artInitiationConcept), - motherHIVStatus: getObsFromEncounter(encounters[0], obsConcepts.hivTestResultConcept), - pTrackerId: getObsFromEncounter(encounters[0], obsConcepts.pTrackerIdConcept), - }; - const lndArtData = { - artInitiation: getObsFromEncounter(encounters[1], obsConcepts.artInitiationConcept), - motherHIVStatus: getObsFromEncounter(encounters[1], obsConcepts.hivTestResultConcept), - pTrackerId: getObsFromEncounter(encounters[1], obsConcepts.pTrackerIdConcept), - }; - const ancArtData = { - artInitiation: getObsFromEncounter(encounters[2], obsConcepts.artInitiationConcept), - motherHIVStatus: getObsFromEncounter(encounters[2], obsConcepts.hivTestResultConcept), - pTrackerId: getObsFromEncounter(encounters[2], obsConcepts.pTrackerIdConcept), - }; - const latestArtData = getLatestArtDetails(pncArtData, lndArtData, ancArtData); - if (!latestArtData['motherHIVStatus']) { - return '--'; - } - - return latestArtData['motherHIVStatus']; + encounterTypes: [encounterTypes.labourAndDelivery], + getObsValue: async ([encounter]) => { + return motherHivStatus; }, }, - { key: 'expectedDeliveryDate', header: t('expectedDeliveryDate', 'Expected Delivery Date'), From 2e9ecc76323c2f8cfef3f79784ee765335f46d41 Mon Sep 17 00:00:00 2001 From: lucyjemutai Date: Tue, 21 May 2024 15:04:47 +0300 Subject: [PATCH 3/9] fetching patient uuid --- .../views/mch-summary/mch-summary.component.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx b/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx index d2fd4cea4..809adf959 100644 --- a/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx +++ b/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx @@ -18,16 +18,16 @@ const MaternalSummary: React.FC = ({ patientUuid }) => { useEffect(() => { if (patient) { - const lastIdentifier = patient.identifier - .slice() - .reverse() - .find((identifier) => identifier.type.id === identifiersTypes.PTrackerIdentifierType); + const reversedIdentifiers = patient.identifier.slice().reverse(); + const pTrackerIdentifier = reversedIdentifiers.find((identifier) => { + return identifier.type.coding[0].code === identifiersTypes.ptrackerIdentifierType; + }); - if (lastIdentifier) { - setPtrackerId(lastIdentifier.value); + if (pTrackerIdentifier) { + setPtrackerId(pTrackerIdentifier.value); } } - }, [patient]); + }, [identifiersTypes.PTrackerIdentifierType, identifiersTypes.ptrackerIdentifierType, patient]); return ( <> From 50091ff23c1e769023acff5ede3f0981eff2d6cb Mon Sep 17 00:00:00 2001 From: lucyjemutai Date: Tue, 21 May 2024 16:44:40 +0300 Subject: [PATCH 4/9] address the pr comments --- packages/esm-commons-lib/src/api/api.ts | 3 +-- .../views/mch-summary/mch-summary.component.tsx | 2 +- .../tabs/current-pregnancy.component.tsx | 14 +++++++------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/esm-commons-lib/src/api/api.ts b/packages/esm-commons-lib/src/api/api.ts index 63ecc1321..73d17ef67 100644 --- a/packages/esm-commons-lib/src/api/api.ts +++ b/packages/esm-commons-lib/src/api/api.ts @@ -277,8 +277,7 @@ export async function fetchData( const response = await openmrsFetch(endpoint); const data = await response.json(); - - if (data && data.results && data.results.length > 0) { + if (data && data.results && data.results?.length) { const record = data.results[0].record; for (const item of record) { diff --git a/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx b/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx index 809adf959..02da5dc63 100644 --- a/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx +++ b/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx @@ -27,7 +27,7 @@ const MaternalSummary: React.FC = ({ patientUuid }) => { setPtrackerId(pTrackerIdentifier.value); } } - }, [identifiersTypes.PTrackerIdentifierType, identifiersTypes.ptrackerIdentifierType, patient]); + }, [identifiersTypes.ptrackerIdentifierType, patient]); return ( <> diff --git a/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx b/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx index 224e8e947..facffa4f1 100644 --- a/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx +++ b/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx @@ -252,29 +252,29 @@ const CurrentPregnancy: React.FC = ({ patientUuid, pTrackerId { key: 'motherHIVStatus', header: t('motherHIVStatus', 'Mother HIV Status'), - encounterTypes: [encounterTypes.labourAndDelivery], - getObsValue: async ([encounter]) => { + encounterTypes: [], + getObsValue: async () => { return motherHivStatus; }, }, { key: 'expectedDeliveryDate', header: t('expectedDeliveryDate', 'Expected Delivery Date'), - encounterTypes: [encounterTypes.labourAndDelivery], - getObsValue: async ([encounter]) => { + encounterTypes: [], + getObsValue: async () => { return deliveryDate; }, }, { key: 'motherStatus', header: t('motherStatus', 'Mother Status'), - encounterTypes: [encounterTypes.labourAndDelivery], - getObsValue: async ([encounter]) => { + encounterTypes: [], + getObsValue: async () => { return motherStatus; }, }, ], - [motherStatus, deliveryDate], + [t, motherHivStatus, deliveryDate, motherStatus], ); const arvTherapyColumns: SummaryCardColumn[] = useMemo( From d7f6151238511391d260ec5b609421ae73d0fcc2 Mon Sep 17 00:00:00 2001 From: lucyjemutai Date: Tue, 21 May 2024 23:48:42 +0300 Subject: [PATCH 5/9] use SWR for data fetching --- packages/esm-commons-lib/src/api/api.ts | 52 +++++++++++-------- .../tabs/current-pregnancy.component.tsx | 38 +++----------- 2 files changed, 36 insertions(+), 54 deletions(-) diff --git a/packages/esm-commons-lib/src/api/api.ts b/packages/esm-commons-lib/src/api/api.ts index 73d17ef67..82af7c46e 100644 --- a/packages/esm-commons-lib/src/api/api.ts +++ b/packages/esm-commons-lib/src/api/api.ts @@ -7,6 +7,7 @@ import { encounterRepresentation, covidOutcomesCohortUUID, } from '../constants'; +import useSWR from 'swr'; const BASE_WS_API_URL = '/ws/rest/v1/'; const BASE_FHIR_API_URL = '/ws/fhir2/R4/'; @@ -256,32 +257,20 @@ export async function fetchMambaReportData(reportId: string) { } } -export async function fetchData( +export function useDataFetch( reportType: 'fetchMambaAncData' | 'MotherHivStatus', reportId?: string, patientUuid?: string, pTrackerId?: string, ) { - try { - let endpoint = ''; - switch (reportType) { - case 'fetchMambaAncData': - endpoint = `ws/rest/v1/mamba/report?report_id=${reportId}&person_uuid=${patientUuid}`; - break; - case 'MotherHivStatus': - endpoint = `ws/rest/v1/mamba/report?report_id=${reportId}&ptracker_id=${pTrackerId}&person_uuid=${patientUuid}`; - break; - default: - throw new Error('Invalid report type'); - } - - const response = await openmrsFetch(endpoint); + const fetcher = async (url) => { + const response = await openmrsFetch(url); const data = await response.json(); - if (data && data.results && data.results?.length) { + if (data && data.results && data.results.length) { const record = data.results[0].record; for (const item of record) { - if (!isNaN(item.value as any)) { + if (!isNaN(item.value)) { return parseInt(item.value, 10); } else if (isInvalidValue(item.value)) { return '--'; @@ -290,15 +279,34 @@ export async function fetchData( } } } - return '--'; - } catch (error) { - console.error(`Error fetching data for report_id=${reportId}: `, error); - throw new Error(`Error fetching data for report_id=${reportId}: ${error}`); + }; + + let endpoint = ''; + switch (reportType) { + case 'fetchMambaAncData': + endpoint = `/ws/rest/v1/mamba/report?report_id=${reportId}&person_uuid=${patientUuid}`; + break; + case 'MotherHivStatus': + endpoint = `/ws/rest/v1/mamba/report?report_id=${reportId}&ptracker_id=${pTrackerId}&person_uuid=${patientUuid}`; + break; + default: + throw new Error('Invalid report type'); } + + const { data, error } = useSWR(endpoint, fetcher, { + revalidateOnFocus: true, + revalidateOnReconnect: true, + }); + + return { + data, + isLoading: !error && !data, + isError: error, + }; } -function isInvalidValue(value: any): boolean { +function isInvalidValue(value) { if (typeof value === 'string') { return value.trim() === ''; } else if (value instanceof Date) { diff --git a/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx b/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx index facffa4f1..e197e45b9 100644 --- a/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx +++ b/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx @@ -11,7 +11,7 @@ import { fetchPatientLastEncounter, SummaryCardColumn, SummaryCard, - fetchData, + useDataFetch, } from '@ohri/openmrs-esm-ohri-commons-lib'; import dayjs from 'dayjs'; import { moduleName } from '../../..'; @@ -48,37 +48,11 @@ const CurrentPregnancy: React.FC = ({ patientUuid, pTrackerId const [pregnancyOutcomes, setPregnancyOutcomes] = useState([]); 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); - const [motherHivStatus, setMotherHivStatus] = useState(null); - const [loading, setLoading] = useState(true); - - useEffect(() => { - const fetchDataAndSetState = async () => { - try { - setLoading(true); - const [totalAncCount, motherStatus, deliveryDate, motherHivStatus] = await Promise.all([ - fetchData('fetchMambaAncData', 'no_of_anc_visits', patientUuid), - fetchData('fetchMambaAncData', 'mother_status', patientUuid), - fetchData('fetchMambaAncData', 'estimated_date_of_delivery', patientUuid), - fetchData('MotherHivStatus', 'mother_hiv_status', patientUuid, pTrackerId), - ]); - - setTotalAncCount(totalAncCount); - setMotherStatus(motherStatus); - setDeliveryDate(deliveryDate); - setMotherHivStatus(motherHivStatus); - } catch (error) { - console.error('Error fetching data:', error); - throw new Error('Error fetching data. Please try again.'); - } finally { - setLoading(false); - } - }; - - fetchDataAndSetState(); - }, [patientUuid, pTrackerId]); + console.log('pTrackerId', pTrackerId); + const { data: totalAncCount } = useDataFetch('fetchMambaAncData', 'no_of_anc_visits', patientUuid); + const { data: motherStatus } = useDataFetch('fetchMambaAncData', 'mother_status', patientUuid); + const { data: deliveryDate } = useDataFetch('fetchMambaAncData', 'estimated_date_of_delivery', patientUuid); + const { data: motherHivStatus } = useDataFetch('MotherHivStatus', 'mother_hiv_status', patientUuid, pTrackerId); const headersFamily = [ { From 2faa7bd21a05dd402638de569828e2660d11ffe4 Mon Sep 17 00:00:00 2001 From: lucyjemutai Date: Tue, 21 May 2024 23:50:38 +0300 Subject: [PATCH 6/9] remove console log --- .../src/views/mch-summary/tabs/current-pregnancy.component.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx b/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx index e197e45b9..0774fc1b5 100644 --- a/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx +++ b/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx @@ -48,7 +48,6 @@ const CurrentPregnancy: React.FC = ({ patientUuid, pTrackerId const [pregnancyOutcomes, setPregnancyOutcomes] = useState([]); const [infantOutcomes, setInfantOutcomes] = useState([]); const { formNames, encounterTypes, obsConcepts, formUuids } = useConfig(); - console.log('pTrackerId', pTrackerId); const { data: totalAncCount } = useDataFetch('fetchMambaAncData', 'no_of_anc_visits', patientUuid); const { data: motherStatus } = useDataFetch('fetchMambaAncData', 'mother_status', patientUuid); const { data: deliveryDate } = useDataFetch('fetchMambaAncData', 'estimated_date_of_delivery', patientUuid); From 3776b95be9154417c4ecb47d4ab8a1540fe73827 Mon Sep 17 00:00:00 2001 From: lucyjemutai Date: Wed, 22 May 2024 12:44:58 +0300 Subject: [PATCH 7/9] code clean-up --- .../mch-summary/tabs/current-pregnancy.component.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx b/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx index 0774fc1b5..4e5e05c6a 100644 --- a/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx +++ b/packages/esm-ohri-pmtct-app/src/views/mch-summary/tabs/current-pregnancy.component.tsx @@ -226,7 +226,7 @@ const CurrentPregnancy: React.FC = ({ patientUuid, pTrackerId key: 'motherHIVStatus', header: t('motherHIVStatus', 'Mother HIV Status'), encounterTypes: [], - getObsValue: async () => { + getObsValue: () => { return motherHivStatus; }, }, @@ -234,7 +234,7 @@ const CurrentPregnancy: React.FC = ({ patientUuid, pTrackerId key: 'expectedDeliveryDate', header: t('expectedDeliveryDate', 'Expected Delivery Date'), encounterTypes: [], - getObsValue: async () => { + getObsValue: () => { return deliveryDate; }, }, @@ -242,7 +242,7 @@ const CurrentPregnancy: React.FC = ({ patientUuid, pTrackerId key: 'motherStatus', header: t('motherStatus', 'Mother Status'), encounterTypes: [], - getObsValue: async () => { + getObsValue: () => { return motherStatus; }, }, @@ -325,8 +325,8 @@ const CurrentPregnancy: React.FC = ({ patientUuid, pTrackerId { key: 'ancVisitsAttended', header: t('ancVisitsAttended', 'ANC visits attended'), - encounterTypes: [encounterTypes.antenatal], - getObsValue: async ([encounter]) => { + encounterTypes: [], + getObsValue: () => { return totalAncCount; }, }, From b759a90c57c8aeb8266cbbdb9e92f7c17b574eb2 Mon Sep 17 00:00:00 2001 From: lucyjemutai Date: Thu, 23 May 2024 16:24:31 +0300 Subject: [PATCH 8/9] ptrackerId search --- .../src/views/mch-summary/mch-summary.component.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx b/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx index 02da5dc63..d0f0fe51d 100644 --- a/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx +++ b/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx @@ -18,10 +18,15 @@ const MaternalSummary: React.FC = ({ patientUuid }) => { useEffect(() => { if (patient) { - const reversedIdentifiers = patient.identifier.slice().reverse(); - const pTrackerIdentifier = reversedIdentifiers.find((identifier) => { - return identifier.type.coding[0].code === identifiersTypes.ptrackerIdentifierType; - }); + const identifiers = patient.identifier; + let pTrackerIdentifier; + + for (let i = identifiers.length - 1; i >= 0; i--) { + if (identifiers[i].type.coding[0].code === identifiersTypes.ptrackerIdentifierType) { + pTrackerIdentifier = identifiers[i]; + break; + } + } if (pTrackerIdentifier) { setPtrackerId(pTrackerIdentifier.value); From a993f199d87af3ac2f06590f689f0b8f9d2931ac Mon Sep 17 00:00:00 2001 From: lucyjemutai Date: Fri, 24 May 2024 15:28:30 +0300 Subject: [PATCH 9/9] latest ptrackerId search --- .../src/views/mch-summary/mch-summary.component.tsx | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx b/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx index d0f0fe51d..02da5dc63 100644 --- a/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx +++ b/packages/esm-ohri-pmtct-app/src/views/mch-summary/mch-summary.component.tsx @@ -18,15 +18,10 @@ const MaternalSummary: React.FC = ({ patientUuid }) => { useEffect(() => { if (patient) { - const identifiers = patient.identifier; - let pTrackerIdentifier; - - for (let i = identifiers.length - 1; i >= 0; i--) { - if (identifiers[i].type.coding[0].code === identifiersTypes.ptrackerIdentifierType) { - pTrackerIdentifier = identifiers[i]; - break; - } - } + const reversedIdentifiers = patient.identifier.slice().reverse(); + const pTrackerIdentifier = reversedIdentifiers.find((identifier) => { + return identifier.type.coding[0].code === identifiersTypes.ptrackerIdentifierType; + }); if (pTrackerIdentifier) { setPtrackerId(pTrackerIdentifier.value);