Skip to content

Commit

Permalink
OLMIS-7903: updated buq data, based on edited request
Browse files Browse the repository at this point in the history
  • Loading branch information
mdulko committed Apr 10, 2024
1 parent 878f401 commit 0dc7be1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 172 deletions.
4 changes: 2 additions & 2 deletions src/buq/components/MOHApproval/MOHFinalApprovalTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ const MOHApprovalTable = ({ data, redirectUrl, handleSetData }) => {
},
{
Header: "Facility Name",
accessor: "calculatedGroupsCosts.facilityName",
accessor: "facilityName",
},
{
Header: "Facility Type",
accessor: "calculatedGroupsCosts.facilityType",
accessor: "facilityType",
},
{
Header: "Pharmaceuticals",
Expand Down
49 changes: 25 additions & 24 deletions src/buq/components/MOHApproval/MohForFinalApproval.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import useGeographicZoneGroup from '../../../react-hooks/useGeographicZoneGroup'
import useServerService from '../../../react-hooks/useServerService';
import useCostCalculationRegion from '../../../react-hooks/useCostCalculationRegion';
import MOHFinalApprovalTable from "./MOHFinalApprovalTable";
import useCostCalculationsForFourLevels from "../../../react-hooks/useCostCalculationsForFourLevels";
import DetailsBlock from '../../../react-components/DetailsBlock';
import MOHSearchBuq from "./MOHSearchBuq";
import MOHActionBarFinalApprove from "./MOHActionBarFinalApprove";
Expand All @@ -25,14 +24,6 @@ const MohForFinalApproval = ({ loadingModalService, facilityService }) => {

const { programId } = useCostCalculationRegion();

const { fetchedData, fetchDataByRegion } = useCostCalculationsForFourLevels(
group,
facilityService,
loadingModalService,
programId,
forecastingPeriodId
);

useEffect(() => {
const groupValues = geographicZoneParams[0];
if (group === undefined) {
Expand All @@ -44,7 +35,7 @@ const MohForFinalApproval = ({ loadingModalService, facilityService }) => {
if (buqsData.length) {
combineData();
}
}, [fetchedData, buqsData]);
}, [buqsData]);

const fetchBuqForFinalApproval = () => {
loadingModalService.open();
Expand All @@ -53,7 +44,6 @@ const MohForFinalApproval = ({ loadingModalService, facilityService }) => {
buqService.forFinalApproval(programId, forecastingPeriodId, group.value).then(function (response) {
if (response.content.length) {
setBuqsData(response.content);
fetchDataByRegion();
} else {
loadingModalService.close();
}
Expand All @@ -62,16 +52,27 @@ const MohForFinalApproval = ({ loadingModalService, facilityService }) => {

const combineData = () => {
let items = [];
buqsData.map((buq, index) => {
const item = fetchedData?.filter(function (data) {
return data.buqIdsToBeApproved.includes(buq.id)
})
buqsData.map(async (buq, index) => {
const facilityData = await facilityService.get(buq.bottomUpQuantification.facilityId);

const calc = buq.calculatedGroupsCosts;

const calculatedGroups = {
pharmaceuticals: calc.Pharmaceuticals,
medicalSupplies: calc['Medical supplies'],
radiology: calc['Radiology (X-rays consumables)'],
dentalSupplies: calc['Dental supplies'],
diagnosticsSupplies: calc['Diagnostics supplies'],
others: calc.Others,
};

items.push({
buq,
calculatedGroupsCosts: item[0],
idCheckbox: `${buq.id}${buq.facilityId}`,
key: index + buq.id
calculatedGroupsCosts: calculatedGroups,
idCheckbox: `${buq.bottomUpQuantification.id}${buq.bottomUpQuantification.facilityId}`,
facilityName: facilityData.name,
facilityType: facilityData.type.name,
key: index + buq.bottomUpQuantification.id,
})

setData(items);
Expand Down Expand Up @@ -108,7 +109,7 @@ const MohForFinalApproval = ({ loadingModalService, facilityService }) => {
topic: 'Others',
value: data.length > 1
? data?.reduce((total, buq) => {
if (buq.calculatedGroupsCosts !== undefined) {
if (buq.calculatedGroupsCosts !== undefined && total?.calculatedGroupsCosts !== undefined) {
return (parseInt(total.calculatedGroupsCosts.others) + parseInt(buq.calculatedGroupsCosts.others)).toFixed(2) + " USD"
}
})
Expand All @@ -118,7 +119,7 @@ const MohForFinalApproval = ({ loadingModalService, facilityService }) => {
topic: 'Pharmaceuticals',
value: data.length > 1
? data?.reduce((total, buq) => {
if (buq.calculatedGroupsCosts !== undefined) {
if (buq.calculatedGroupsCosts !== undefined && total?.calculatedGroupsCosts !== undefined) {
return (parseInt(total.calculatedGroupsCosts.pharmaceuticals) + parseInt(buq?.calculatedGroupsCosts?.pharmaceuticals)).toFixed(2) + " USD"
}
})
Expand All @@ -128,7 +129,7 @@ const MohForFinalApproval = ({ loadingModalService, facilityService }) => {
topic: 'Medical supplies & Equipment',
value: data.length > 1
? data?.reduce((total, buq) => {
if (buq.calculatedGroupsCosts !== undefined) {
if (buq.calculatedGroupsCosts !== undefined && total?.calculatedGroupsCosts !== undefined) {
return (parseInt(total.calculatedGroupsCosts.medicalSupplies) + parseInt(buq?.calculatedGroupsCosts?.medicalSupplies)).toFixed(2) + " USD"
}
})
Expand All @@ -140,7 +141,7 @@ const MohForFinalApproval = ({ loadingModalService, facilityService }) => {
topic: 'Radiology (x-rays consumables)',
value: data.length > 1
? data?.reduce((total, buq) => {
if (buq.calculatedGroupsCosts !== undefined) {
if (buq.calculatedGroupsCosts !== undefined && total?.calculatedGroupsCosts !== undefined) {
return (parseInt(total.calculatedGroupsCosts.radiology) + parseInt(buq?.calculatedGroupsCosts?.radiology)).toFixed(2) + " USD"
}
})
Expand All @@ -150,7 +151,7 @@ const MohForFinalApproval = ({ loadingModalService, facilityService }) => {
topic: 'Diagnostics supplies & Equipment',
value: data.length > 1
? data?.reduce((total, buq) => {
if (buq.calculatedGroupsCosts !== undefined) {
if (buq.calculatedGroupsCosts !== undefined && total?.calculatedGroupsCosts !== undefined) {
return (parseInt(total.calculatedGroupsCosts.diagnosticsSupplies) + parseInt(buq?.calculatedGroupsCosts?.diagnosticsSupplies)).toFixed(2) + " USD"
}
})
Expand All @@ -160,7 +161,7 @@ const MohForFinalApproval = ({ loadingModalService, facilityService }) => {
topic: 'Quantification Period',
value: data.length > 1
? data?.reduce((total, buq) => {
if (buq.calculatedGroupsCosts !== undefined) {
if (buq.calculatedGroupsCosts !== undefined && total?.calculatedGroupsCosts !== undefined) {
return (parseInt(total.calculatedGroupsCosts.dentalSupplies) + parseInt(buq.calculatedGroupsCosts?.dentalSupplies)).toFixed(2) + " USD"
}
})
Expand Down
146 changes: 0 additions & 146 deletions src/react-hooks/useCostCalculationsForFourLevels.jsx

This file was deleted.

0 comments on commit 0dc7be1

Please sign in to comment.