Skip to content

Commit 4be5dd4

Browse files
authored
Merge pull request #1050 from synthetichealth/fix-transition-regression
Fixes rare issue with weight management regression
2 parents 271aa6e + d331e71 commit 4be5dd4

2 files changed

Lines changed: 41 additions & 5 deletions

File tree

src/main/java/org/mitre/synthea/modules/WeightLossModule.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,16 @@ public double transitionRegression(Person person, long time) {
277277
double targetWeight = BMI.weightForHeightAndBMI(height, bmiForPercentileAtTwenty);
278278
int ageTwenty = 20;
279279
int lossAndRegressionTotalYears = 7;
280-
double weightAtTwenty = BMI.weightForHeightAndBMI(height, pgt.tail().bmi);
281280
int regressionEndAge = (startAgeInMonths / 12) + lossAndRegressionTotalYears;
282-
double percentageElapsed = (person.ageInDecimalYears(time) - ageTwenty)
283-
/ (regressionEndAge - ageTwenty);
281+
int denominator = regressionEndAge - ageTwenty;
282+
// This can happen when regression ends at age 20
283+
if (denominator == 0) {
284+
denominator = 1;
285+
}
286+
287+
double percentageElapsed = (person.ageInDecimalYears(time) - ageTwenty) / denominator;
288+
289+
double weightAtTwenty = BMI.weightForHeightAndBMI(height, pgt.tail().bmi);
284290
return weightAtTwenty + (percentageElapsed * (targetWeight - weightAtTwenty));
285291
}
286292

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

420-
}
426+
}

src/test/java/org/mitre/synthea/modules/WeightLossModuleTest.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,34 @@ public void adjustBMIVectorForSuccessfulManagementRunOnce() {
292292
assertEquals(expectedTailAge, pgt.tail().ageInMonths);
293293
assertEquals(expectedBMI, pgt.tail().bmi, 0.001);
294294
}
295-
}
295+
296+
@Test
297+
public void transitionRegression() {
298+
long birthDay = TestHelper.timestamp(1990, 1, 1, 0, 0, 0);
299+
long weightLossStart = TestHelper.timestamp(2003, 12, 2, 0, 0, 0);
300+
long transitionRegressionTime = TestHelper.timestamp(2010, 1, 1, 0, 0, 0);
301+
Person person = new Person(0L);
302+
String gender = "M";
303+
double bmiPercentileChange = 0.01;
304+
person.attributes.put(Person.BIRTHDATE, birthDay);
305+
person.attributes.put(Person.GENDER, gender);
306+
person.attributes.put(WeightLossModule.WEIGHT_MANAGEMENT_START, weightLossStart);
307+
person.attributes.put(WeightLossModule.WEIGHT_LOSS_BMI_PERCENTILE_CHANGE, bmiPercentileChange);
308+
person.setVitalSign(VitalSign.HEIGHT_PERCENTILE, 0.75);
309+
PediatricGrowthTrajectory pgt = new PediatricGrowthTrajectory(0L, birthDay);
310+
int yearToCheck = 1993;
311+
for (int i = 0; i < 17; i++) {
312+
long timeToCheck = TestHelper.timestamp(yearToCheck + i, 1, 1, 0, 0, 0);
313+
pgt.currentBMI(person, timeToCheck);
314+
}
315+
316+
person.attributes.put(Person.GROWTH_TRAJECTORY, pgt);
317+
318+
double weight = mod.transitionRegression(person, transitionRegressionTime);
319+
// The seeded pgt will target a BMI around 24.9 at age 20
320+
// The person is in the 75th percentile for height which would make them ~181.65 cm
321+
// Therefore, the weight should be about 82.14 kg, since this is the end of the transition
322+
// back to the original weight trajectory
323+
assertEquals(82.14, weight, 0.01);
324+
}
325+
}

0 commit comments

Comments
 (0)