Skip to content

Commit

Permalink
parent targets fix (#1361)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitSharmaEquidhi authored Jan 28, 2025
1 parent 3cdfc2f commit ddb801e
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions health-services/project-factory/src/server/utils/campaignUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1696,15 +1696,15 @@ function mapBoundariesParent(boundaryResponse: any, request: any, parent: any) {
function mapTargets(boundaryResponses: any, codesTargetMapping: any) {
if (!boundaryResponses || !codesTargetMapping) return;

// Helper function to map individual boundaries
const mapBoundary = (boundary: any) => {
if (!boundary.children || boundary.children.length === 0) {
// If no children, simply return the target value object or default to empty object
const targetValue = codesTargetMapping[boundary.code];
return targetValue || {};
}
// Helper function to map individual boundaries
const mapBoundary = (boundary: any) => {
if (!boundary.children || boundary.children.length === 0) {
// If no children, simply return the target value object or default to empty object
const targetValue = codesTargetMapping[boundary.code];
return targetValue || {};
}

// Initialize a new object to accumulate total target values from children
// Initialize a new object to accumulate total target values from children
let totalTargetValue: any = {};

// Iterate through each child and accumulate their target values
Expand All @@ -1718,19 +1718,20 @@ function mapTargets(boundaryResponses: any, codesTargetMapping: any) {
totalTargetValue[key] = (totalTargetValue[key] || 0) + childTargetValue[key];
}
}
}

// Store the accumulated total target value for the current boundary
codesTargetMapping[boundary.code] = totalTargetValue;
return totalTargetValue;
};
// Map each boundary response
for (const boundaryResponse of boundaryResponses) {
// Store the accumulated total target value for the current boundary
codesTargetMapping[boundary.code] = totalTargetValue;
return totalTargetValue;
};

// Map each boundary response
for (const boundaryResponse of boundaryResponses) {
mapBoundary(boundaryResponse);
}
}
}


async function processBoundary(
boundaryResponse: any,
boundaries: any,
Expand Down

0 comments on commit ddb801e

Please sign in to comment.