Skip to content

Commit

Permalink
#3 | add function to calculate the growth status for adolescent
Browse files Browse the repository at this point in the history
  • Loading branch information
sachsk committed May 15, 2024
1 parent 4a052ea commit 5328e94
Show file tree
Hide file tree
Showing 5 changed files with 2,245 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/health_modules/adolescent/growthStatusCalculator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import _ from "lodash";
import growthChartBoys from "/src/health_modules/adolescent/metadata/adolesecent_growth_chart_boys.json";
import growthChartGirls from "/src/health_modules/adolescent/metadata/adolesecent_growth_chart_girls.json";

const getStatusData = (data) => [
{value: data.severe_mn, status: -3},
{value: data.moderate_mn, status: -2},
{value: data.mild_mn, status: -1},
{value: data.normal, status: 0},
{value: data.mild_ob, status: 1},
{value: data.moderate_ob, status: 2},
{value: data.severe_ob, status: 3}
];


const getStatus = (arrayDataObj,weight) => {
for (const item of arrayDataObj) {
if (weight <= item.value) {
return item.status;
}
}
return 3; // Default status if weight exceeds all thresholds (severe_ob)
}

const calculateGrowthStatus = (individual, weight, asOnDate) => {
let ageInMonths = individual.getAgeInMonths(asOnDate);
let gender = _.get(individual, "gender.name");
let growthStatusValuesJson = gender === 'Female' ? growthChartGirls : growthChartBoys;
let values = _.find(growthStatusValuesJson, (item) => item.month == ageInMonths);

return {wfaStatus:getStatus(getStatusData(values),weight)};
}

export default calculateGrowthStatus;


Loading

0 comments on commit 5328e94

Please sign in to comment.