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

Fix issue where vital signs were sometimes being set to NaN #1381

Merged
merged 2 commits into from
Nov 9, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
* Represents the LMS parameters on the CDC growth chart for a particular sex and age in months.
*/
public class GrowthChartEntry implements Serializable {

/**
* The highest percentile to use when attempting to calculate a value. Tests with the BMI growth
* charts for females at 240 months show that values greater than 0.99739 cause a term in the
* equation to go negative causing the code to return NaN. Values slightly less than that can
* return unrealistic values. This provides a limit to the maximum percentile that will be looked
* up.
*/
public static double MAX_PERCENTILE = 0.995;

private double lboxCox;
private double median;
private double scov;
Expand Down Expand Up @@ -51,11 +61,16 @@ public double percentileForValue(double value) {
* @return The value for the given percentile
*/
public double lookUp(double percentile) {
double z = GrowthChart.calculateZScore(percentile);
double percentileToUse = percentile;
if (percentile > MAX_PERCENTILE) {
percentileToUse = MAX_PERCENTILE;
}
double z = GrowthChart.calculateZScore(percentileToUse);
if (this.lboxCox == 0) {
return this.median * Math.exp((this.scov * z));
} else {
return this.median * Math.pow((1 + (this.lboxCox * this.scov * z)), (1.0 / this.lboxCox));
double expressionTerm = this.lboxCox * this.scov * z;
return this.median * Math.pow((1 + expressionTerm), (1.0 / this.lboxCox));
}
}
}
3 changes: 2 additions & 1 deletion src/test/java/org/mitre/synthea/modules/GrowthChartTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public void testGrowthChartLookupHigh() throws Exception {
@Test
public void testGrowthChartLookupMax() throws Exception {
double height = LifecycleModule.lookupGrowthChart("height", "M", 20, 1.0);
assertEquals(94.95447906, height, 0.01);
// Max value is now capped to the 99.5th percentile.
assertEquals(93.1240785326071, height, 0.01);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.mitre.synthea.world.concepts;

import java.util.Map;

import junit.framework.TestCase;

public class GrowthChartTest extends TestCase {

/**
* Test the look up of BMI values at the high end of the range.
*/
public void testLookUp() {
Map<GrowthChart.ChartType, GrowthChart> growthChart =
GrowthChart.loadCharts();
double bmi = growthChart.get(GrowthChart.ChartType.BMI).lookUp(240, "F", 0.997394309960757);
assertFalse(Double.isNaN(bmi));
bmi = growthChart.get(GrowthChart.ChartType.BMI).lookUp(240, "F", 0.5);
assertEquals(21.71699934, bmi, 0.01);
}
}