From 808396ef4efd2d58e197ffe3e0ba49cc2d120220 Mon Sep 17 00:00:00 2001 From: Rohan Port <59544282+rohan-bes@users.noreply.github.com> Date: Mon, 25 Sep 2023 09:44:13 +1000 Subject: [PATCH] MDEV-189: Switch LESMIS vitals to using new vitals reports (#5009) --- .../lesmis/src/api/queries/useVitalsData.js | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/packages/lesmis/src/api/queries/useVitalsData.js b/packages/lesmis/src/api/queries/useVitalsData.js index 463a07a95f..b99f39eeba 100644 --- a/packages/lesmis/src/api/queries/useVitalsData.js +++ b/packages/lesmis/src/api/queries/useVitalsData.js @@ -68,31 +68,21 @@ const useReport = (entity, reportName, options, enabled) => }, ); -const useSchoolReport = entity => - useReport( - entity, - 'LESMIS_school_vitals', - { params: { endDate: utcMoment().format(endDateFormat) } }, - entity?.type === 'school', - ); +const vitalsReports = { + country: 'lesmis_ctry_vitals', + district: 'lesmis_prov_vitals', + sub_district: 'lesmis_dist_vitals', + school: 'lesmis_sch_vitals', +}; const useEntityReport = entity => useReport( entity, - 'LESMIS_entity_vitals', + vitalsReports[entity?.type], { params: { endDate: utcMoment().format(endDateFormat) } }, - entity !== undefined && entity?.type !== 'school', + entity !== undefined, ); -const useSchoolVitals = entity => { - const { data: results, isLoading } = useSchoolReport(entity); - - return { - data: results?.[0], - isLoading, - }; -}; - const useEntityVitals = entity => { const { data: results, isLoading } = useEntityReport(entity); @@ -115,14 +105,12 @@ export const useVitalsData = entityCode => { const { data: entityData } = useEntityData(entityCode); const parentEntityData = getParentEntity(entities, entityData); - const { data: schoolVitals, isLoading: schoolVitalsLoading } = useSchoolVitals(entityData); const { data: entityVitals, isLoading: entityVitalsLoading } = useEntityVitals(entityData); const { data: parentVitals, isLoading: parentVitalsLoading } = useEntityVitals(parentEntityData); const vitalsData = { ...entitiesQuery, ...entityData, - ...schoolVitals, ...entityVitals, parentVitals: { ...parentEntityData, @@ -134,6 +122,6 @@ export const useVitalsData = entityCode => { return { data: { ...vitalsData, partners }, - isLoading: schoolVitalsLoading || entityVitalsLoading || parentVitalsLoading, + isLoading: entityVitalsLoading || parentVitalsLoading, }; };