Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes rare issue with weight management regression #1050

Merged
merged 1 commit into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/main/java/org/mitre/synthea/modules/WeightLossModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,16 @@ public double transitionRegression(Person person, long time) {
double targetWeight = BMI.weightForHeightAndBMI(height, bmiForPercentileAtTwenty);
int ageTwenty = 20;
int lossAndRegressionTotalYears = 7;
double weightAtTwenty = BMI.weightForHeightAndBMI(height, pgt.tail().bmi);
int regressionEndAge = (startAgeInMonths / 12) + lossAndRegressionTotalYears;
double percentageElapsed = (person.ageInDecimalYears(time) - ageTwenty)
/ (regressionEndAge - ageTwenty);
int denominator = regressionEndAge - ageTwenty;
// This can happen when regression ends at age 20
if (denominator == 0) {
denominator = 1;
}

double percentageElapsed = (person.ageInDecimalYears(time) - ageTwenty) / denominator;

double weightAtTwenty = BMI.weightForHeightAndBMI(height, pgt.tail().bmi);
return weightAtTwenty + (percentageElapsed * (targetWeight - weightAtTwenty));
}

Expand Down Expand Up @@ -417,4 +423,4 @@ public boolean meetsWeightManagementThresholds(Person person, long time) {
|| (age < 20 && bmi >= bmiAtPercentile)));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,34 @@ public void adjustBMIVectorForSuccessfulManagementRunOnce() {
assertEquals(expectedTailAge, pgt.tail().ageInMonths);
assertEquals(expectedBMI, pgt.tail().bmi, 0.001);
}
}

@Test
public void transitionRegression() {
long birthDay = TestHelper.timestamp(1990, 1, 1, 0, 0, 0);
long weightLossStart = TestHelper.timestamp(2003, 12, 2, 0, 0, 0);
long transitionRegressionTime = TestHelper.timestamp(2010, 1, 1, 0, 0, 0);
Person person = new Person(0L);
String gender = "M";
double bmiPercentileChange = 0.01;
person.attributes.put(Person.BIRTHDATE, birthDay);
person.attributes.put(Person.GENDER, gender);
person.attributes.put(WeightLossModule.WEIGHT_MANAGEMENT_START, weightLossStart);
person.attributes.put(WeightLossModule.WEIGHT_LOSS_BMI_PERCENTILE_CHANGE, bmiPercentileChange);
person.setVitalSign(VitalSign.HEIGHT_PERCENTILE, 0.75);
PediatricGrowthTrajectory pgt = new PediatricGrowthTrajectory(0L, birthDay);
int yearToCheck = 1993;
for (int i = 0; i < 17; i++) {
long timeToCheck = TestHelper.timestamp(yearToCheck + i, 1, 1, 0, 0, 0);
pgt.currentBMI(person, timeToCheck);
}

person.attributes.put(Person.GROWTH_TRAJECTORY, pgt);

double weight = mod.transitionRegression(person, transitionRegressionTime);
// The seeded pgt will target a BMI around 24.9 at age 20
// The person is in the 75th percentile for height which would make them ~181.65 cm
// Therefore, the weight should be about 82.14 kg, since this is the end of the transition
// back to the original weight trajectory
assertEquals(82.14, weight, 0.01);
}
}