Skip to content

Commit

Permalink
MDEV-189: Switch LESMIS vitals to using new vitals reports (#5009)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-bes authored Sep 24, 2023
1 parent d3792d9 commit 808396e
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions packages/lesmis/src/api/queries/useVitalsData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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,
Expand All @@ -134,6 +122,6 @@ export const useVitalsData = entityCode => {

return {
data: { ...vitalsData, partners },
isLoading: schoolVitalsLoading || entityVitalsLoading || parentVitalsLoading,
isLoading: entityVitalsLoading || parentVitalsLoading,
};
};

0 comments on commit 808396e

Please sign in to comment.