Search in sources :

Example 1 with TimeSeriesData

use of org.mitre.synthea.helpers.TimeSeriesData in project synthea by synthetichealth.

the class ExportHelper method sampledDataToValueString.

/**
 * Helper to translate all SampledData values into string form.
 *
 * @param sampledData The SampledData object to export
 * @return stringified sampled data values
 */
public static String sampledDataToValueString(SampledData sampledData) {
    int numSamples = sampledData.series.get(0).getValues().size();
    DecimalFormat df;
    if (sampledData.decimalFormat != null) {
        df = new DecimalFormat(sampledData.decimalFormat);
    } else {
        df = new DecimalFormat();
    }
    // Build the data string from all list values
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < numSamples; i++) {
        for (TimeSeriesData series : sampledData.series) {
            double num = series.getValues().get(i);
            sb.append(df.format(num));
            sb.append(" ");
        }
    }
    return sb.toString().trim();
}
Also used : DecimalFormat(java.text.DecimalFormat) TimeSeriesData(org.mitre.synthea.helpers.TimeSeriesData)

Example 2 with TimeSeriesData

use of org.mitre.synthea.helpers.TimeSeriesData in project synthea by synthetichealth.

the class StateTest method setAttribute_with_seriesData_Module.

@Test
public void setAttribute_with_seriesData_Module() throws Exception {
    Module module = TestHelper.getFixture("series_data.json");
    assertTrue(module.process(person, time));
    TimeSeriesData data = (TimeSeriesData) person.attributes.get("series_data");
    assertEquals(12, data.getValues().size());
    assertEquals(1, data.getValues().get(0), 0.0001);
    HealthRecord.Observation obs = person.record.getLatestObservation("1234");
    assertNotNull(obs);
    assertTrue(obs.value instanceof Components.SampledData);
    Components.SampledData sampledData = (Components.SampledData) obs.value;
    String value = ExportHelper.sampledDataToValueString(sampledData);
    assertEquals("1 2 3 4 4 3 2 1 1 2 3 4", value);
}
Also used : HealthRecord(org.mitre.synthea.world.concepts.HealthRecord) SampledData(org.mitre.synthea.engine.Components.SampledData) SampledData(org.mitre.synthea.engine.Components.SampledData) QualityOfLifeModule(org.mitre.synthea.modules.QualityOfLifeModule) CardiovascularDiseaseModule(org.mitre.synthea.modules.CardiovascularDiseaseModule) EncounterModule(org.mitre.synthea.modules.EncounterModule) WeightLossModule(org.mitre.synthea.modules.WeightLossModule) LifecycleModule(org.mitre.synthea.modules.LifecycleModule) DeathModule(org.mitre.synthea.modules.DeathModule) TimeSeriesData(org.mitre.synthea.helpers.TimeSeriesData) Test(org.junit.Test)

Example 3 with TimeSeriesData

use of org.mitre.synthea.helpers.TimeSeriesData in project synthea by synthetichealth.

the class StateTest method testPhysiology.

@Test
public void testPhysiology() throws Exception {
    // BMI is an input parameter so we need to set it
    person.setVitalSign(VitalSign.BMI, 32.98);
    // Pulmonary resistance and BMI multiplier are also input parameters
    person.attributes.put("Pulmonary Resistance", 0.1552);
    person.attributes.put("BMI Multiplier", 0.055);
    Module module = TestHelper.getFixture("smith_physiology.json");
    State simulateCvs = module.getState("Simulate_CVS");
    assertTrue(simulateCvs.process(person, time));
    // The "Final Aortal Volume" attribute should have been set
    assertTrue(person.attributes.containsKey("Final Aortal Volume"));
    // The "Arterial Pressure Values" attribute should have been set to a list
    assertTrue(person.attributes.get("Arterial Pressure Values") instanceof TimeSeriesData);
    // LVEF should be diminished and BP should be elevated
    assertTrue("LVEF < 60%", (double) person.attributes.get("LVEF") < 60.0);
    assertTrue("LVEF > 50%", (double) person.attributes.get("LVEF") > 50.0);
    assertTrue("SYS BP < 150 mmhg", (double) person.attributes.get("SBP") < 150.0);
    assertTrue("SYS BP > 130 mmhg", (double) person.attributes.get("SBP") > 130.0);
    assertTrue("DIA BP < 100 mmhg", (double) person.attributes.get("DBP") < 100.0);
    assertTrue("DIA BP > 80 mmhg", (double) person.attributes.get("DBP") > 80.0);
    // test that the state can be effectively cloned
    State cvsClone = simulateCvs.clone();
    assertNotEquals(cvsClone, simulateCvs);
    assertTrue(cvsClone.process(person, time));
}
Also used : QualityOfLifeModule(org.mitre.synthea.modules.QualityOfLifeModule) CardiovascularDiseaseModule(org.mitre.synthea.modules.CardiovascularDiseaseModule) EncounterModule(org.mitre.synthea.modules.EncounterModule) WeightLossModule(org.mitre.synthea.modules.WeightLossModule) LifecycleModule(org.mitre.synthea.modules.LifecycleModule) DeathModule(org.mitre.synthea.modules.DeathModule) TimeSeriesData(org.mitre.synthea.helpers.TimeSeriesData) Test(org.junit.Test)

Example 4 with TimeSeriesData

use of org.mitre.synthea.helpers.TimeSeriesData in project synthea by synthetichealth.

the class StateTest method setAttribute_with_seriesData.

@Test
public void setAttribute_with_seriesData() throws Exception {
    Module module = TestHelper.getFixture("set_attribute.json");
    State set4 = module.getState("Set_Attribute_4");
    assertTrue(set4.process(person, time));
    TimeSeriesData data = (TimeSeriesData) person.attributes.get("ECG");
    assertEquals(10, data.getValues().size());
    assertEquals(2041, data.getValues().get(0), 0.0001);
}
Also used : QualityOfLifeModule(org.mitre.synthea.modules.QualityOfLifeModule) CardiovascularDiseaseModule(org.mitre.synthea.modules.CardiovascularDiseaseModule) EncounterModule(org.mitre.synthea.modules.EncounterModule) WeightLossModule(org.mitre.synthea.modules.WeightLossModule) LifecycleModule(org.mitre.synthea.modules.LifecycleModule) DeathModule(org.mitre.synthea.modules.DeathModule) TimeSeriesData(org.mitre.synthea.helpers.TimeSeriesData) Test(org.junit.Test)

Example 5 with TimeSeriesData

use of org.mitre.synthea.helpers.TimeSeriesData in project synthea by synthetichealth.

the class IoMapperTest method ioMapperOutputTest.

@Test
public void ioMapperOutputTest() {
    testMapper.setFrom("invalid");
    testMapper.setTo("test attribute");
    testMapper.setType(IoMapper.IoType.ATTRIBUTE);
    testMapper.setVariance(0);
    // Add some mock model output values
    double[] timePoints = { 0, 1, 2, 3 };
    double[][] mockData = new double[4][1];
    mockData[0][0] = 0.0;
    mockData[1][0] = 1.0;
    mockData[2][0] = 2.0;
    mockData[3][0] = 3.0;
    String[] params = { "model_output" };
    MultiTable mockResults = new MultiTable(timePoints, mockData, params);
    // Invalid parameter name so we should get an exception
    try {
        testMapper.getOutputResult(mockResults, 0);
    } catch (IllegalArgumentException e) {
        assertEquals("Invalid model parameter \"invalid\" cannot be mapped to " + "patient value \"test attribute\"", e.getMessage());
    }
    // set to the correct value
    testMapper.setFrom("model_output");
    // Mapper should set the final value
    assertEquals(3.0, (double) testMapper.getOutputResult(mockResults, 0), 0);
    // Test setting an entire list of values
    testMapper.setFrom(null);
    testMapper.setFromList("invalid");
    // Invalid parameter name so we should get an exception
    try {
        testMapper.getOutputResult(mockResults, 0);
    } catch (IllegalArgumentException e) {
        assertEquals("Invalid model parameter \"invalid\" cannot be mapped to " + "patient value \"test attribute\"", e.getMessage());
    }
    testMapper.setFromList("model_output");
    // Mapper should provide a list of all values
    List<Double> expectedValues = Arrays.asList(0.0, 1.0, 2.0, 3.0);
    TimeSeriesData seriesData = (TimeSeriesData) testMapper.getOutputResult(mockResults, 0);
    assertEquals(expectedValues, seriesData.getValues());
    assertEquals(1.0, seriesData.getPeriod(), 0.00001);
    // Test an expression
    testMapper.setFromList(null);
    testMapper.setFromExp("Sum(#{model_output})");
    Map<String, String> paramTypes = new HashMap<String, String>();
    paramTypes.put("model_output", "List<Decimal>");
    testMapper.initialize(paramTypes);
    // Should result in the sum of all values for 'model_output'
    assertEquals(6.0, (double) testMapper.getOutputResult(mockResults, 0), 0.0001);
}
Also used : HashMap(java.util.HashMap) MultiTable(org.simulator.math.odes.MultiTable) TimeSeriesData(org.mitre.synthea.helpers.TimeSeriesData) Test(org.junit.Test)

Aggregations

TimeSeriesData (org.mitre.synthea.helpers.TimeSeriesData)5 Test (org.junit.Test)4 CardiovascularDiseaseModule (org.mitre.synthea.modules.CardiovascularDiseaseModule)3 DeathModule (org.mitre.synthea.modules.DeathModule)3 EncounterModule (org.mitre.synthea.modules.EncounterModule)3 LifecycleModule (org.mitre.synthea.modules.LifecycleModule)3 QualityOfLifeModule (org.mitre.synthea.modules.QualityOfLifeModule)3 WeightLossModule (org.mitre.synthea.modules.WeightLossModule)3 DecimalFormat (java.text.DecimalFormat)1 HashMap (java.util.HashMap)1 SampledData (org.mitre.synthea.engine.Components.SampledData)1 HealthRecord (org.mitre.synthea.world.concepts.HealthRecord)1 MultiTable (org.simulator.math.odes.MultiTable)1