Search in sources :

Example 1 with VitalSign

use of org.mitre.synthea.world.concepts.VitalSign in project synthea by synthetichealth.

the class Generator method writeToConsole.

/**
 * Print out the completed person to the consol.
 * @param person The person to print.
 * @param index The number person simulated.
 * @param time The time at which they died/the simulation ended.
 * @param isAlive Whether the person to print is alive.
 */
private synchronized void writeToConsole(Person person, int index, long time, boolean isAlive) {
    // this is synchronized to ensure all lines for a single person are always printed
    // consecutively
    String deceased = isAlive ? "" : "DECEASED";
    System.out.format("%d -- %s (%d y/o %s) %s, %s %s (%d)\n", index + 1, person.attributes.get(Person.NAME), person.ageInYears(time), person.attributes.get(Person.GENDER), person.attributes.get(Person.CITY), person.attributes.get(Person.STATE), deceased, person.getCount());
    if (this.logLevel.equals("detailed")) {
        System.out.println("ATTRIBUTES");
        for (String attribute : person.attributes.keySet()) {
            System.out.format("  * %s = %s\n", attribute, person.attributes.get(attribute));
        }
        System.out.format("SYMPTOMS: %d\n", person.symptomTotal());
        System.out.println(person.record.textSummary());
        System.out.println("VITAL SIGNS");
        for (VitalSign vitalSign : person.vitalSigns.keySet()) {
            System.out.format("  * %25s = %6.2f\n", vitalSign, person.getVitalSign(vitalSign, time).doubleValue());
        }
        System.out.println("-----");
    }
}
Also used : VitalSign(org.mitre.synthea.world.concepts.VitalSign)

Example 2 with VitalSign

use of org.mitre.synthea.world.concepts.VitalSign in project synthea by synthetichealth.

the class SimRunner method execute.

/**
 * Executes the simulation if any input values are beyond the variance threshold.
 * @param time simulation time
 */
public void execute(long time) {
    // Copy our input parameters for future threshold checks
    prevInputs = new HashMap<String, Double>(modelInputs);
    MultiTable results = runSim(time, modelInputs);
    firstExecution = true;
    // Set all of the results
    for (IoMapper mapper : config.getOutputs()) {
        switch(mapper.getType()) {
            default:
            case ATTRIBUTE:
                person.attributes.put(mapper.getTo(), mapper.getOutputResult(results, config.getLeadTime()));
                break;
            case VITAL_SIGN:
                VitalSign vs = mapper.getVitalSignTarget();
                Object result = mapper.getOutputResult(results, config.getLeadTime());
                if (result instanceof List) {
                    throw new IllegalArgumentException("Mapping lists to VitalSigns is currently unsupported. " + "Cannot map list to VitalSign \"" + mapper.getTo() + "\".");
                }
                vitalSignResults.put(vs, (double) result);
                break;
        }
    }
}
Also used : VitalSign(org.mitre.synthea.world.concepts.VitalSign) List(java.util.List) MultiTable(org.simulator.math.odes.MultiTable)

Example 3 with VitalSign

use of org.mitre.synthea.world.concepts.VitalSign in project synthea by synthetichealth.

the class PhysiologyValueGeneratorTest method testMultiLoad.

@Test
public void testMultiLoad() {
    // Verify that we can load all ValueGenerators defined in a configuration file
    Person person = new Person(0);
    person.attributes.put(Person.BIRTHDATE, dateToSimTime("1988-07-25"));
    person.setVitalSign(VitalSign.BMI, 22.0);
    PhysiologyGeneratorConfig config = PhysiologyValueGenerator.getConfig("circulation_hemodynamics.yml");
    List<PhysiologyValueGenerator> generators = PhysiologyValueGenerator.fromConfig(config, person);
    // Create a Set with each VitalSign in the config
    HashSet<VitalSign> cfgVitals = new HashSet<VitalSign>();
    for (IoMapper mapper : config.getOutputs()) {
        if (mapper.getType() == IoMapper.IoType.VITAL_SIGN) {
            cfgVitals.add(VitalSign.fromString(mapper.getTo()));
        }
    }
    // Create a Set with each VitalSign generator
    HashSet<VitalSign> genVitals = new HashSet<VitalSign>();
    for (PhysiologyValueGenerator generator : generators) {
        genVitals.add(generator.getVitalSign());
    }
    assertEquals(cfgVitals, genVitals);
}
Also used : VitalSign(org.mitre.synthea.world.concepts.VitalSign) PhysiologyGeneratorConfig(org.mitre.synthea.helpers.physiology.PhysiologyGeneratorConfig) Person(org.mitre.synthea.world.agents.Person) IoMapper(org.mitre.synthea.helpers.physiology.IoMapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with VitalSign

use of org.mitre.synthea.world.concepts.VitalSign in project synthea by synthetichealth.

the class ExpressionProcessor method getPersonValue.

/**
 * Retrieve the desired value from a Person model. Check for a VitalSign first and
 * then an attribute if there is no VitalSign by the provided name.
 * Throws an IllegalArgumentException if neither exists.
 * @param param name of the VitalSign or attribute to retrieve from the Person
 * @param person Person instance to get the parameter from
 * @param time current time
 * @return value
 */
public static Object getPersonValue(String param, Person person, long time, String expression) {
    // Treat "age" as a special case. In expressions, age is represented in decimal years
    if (param.equals("age")) {
        return new BigDecimal(person.ageInDecimalYears(time));
    }
    // If this param is in the cache, check if we have a VitalSign or not
    org.mitre.synthea.world.concepts.VitalSign vs = vitalSignCache.get(param);
    if (vs == null && !attributeSet.contains(param)) {
        try {
            vs = org.mitre.synthea.world.concepts.VitalSign.fromString(param);
            // Take note that this parameter is a VitalSign so we don't have to repeatedly
            // call fromString, which can get expensive
            vitalSignCache.put(param, vs);
        } catch (IllegalArgumentException ex) {
            // Take note that this parameter is an attribute so we don't have to repeatedly
            // call fromString, which can get expensive
            attributeSet.add(param);
        }
    }
    if (vs != null) {
        return new BigDecimal(person.getVitalSign(vs, time));
    }
    Object value = person.attributes.get(param);
    if (value == null) {
        if (expression != null) {
            throw new IllegalArgumentException("Unable to map \"" + param + "\" in expression \"" + expression + "\": Invalid person attribute or vital sign.");
        } else {
            throw new IllegalArgumentException("Unable to map \"" + param + "\": Invalid person attribute or vital sign.");
        }
    }
    if (value instanceof Number) {
        // If it's any numeric type, use a BigDecimal
        return new BigDecimal(value.toString());
    } else if (value instanceof String || value instanceof Boolean) {
        // Provide strings and booleans as-is
        return value;
    } else {
        if (expression != null) {
            throw new IllegalArgumentException("Unable to map person attribute \"" + param + "\" in expression \"" + expression + "\": Unsupported type: " + value.getClass().getTypeName() + ".");
        } else {
            throw new IllegalArgumentException("Unable to map person attribute \"" + param + "\": Unsupported type: " + value.getClass().getTypeName() + ".");
        }
    }
}
Also used : VitalSign(org.mitre.synthea.world.concepts.VitalSign) BigDecimal(java.math.BigDecimal)

Aggregations

VitalSign (org.mitre.synthea.world.concepts.VitalSign)4 BigDecimal (java.math.BigDecimal)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Test (org.junit.Test)1 IoMapper (org.mitre.synthea.helpers.physiology.IoMapper)1 PhysiologyGeneratorConfig (org.mitre.synthea.helpers.physiology.PhysiologyGeneratorConfig)1 Person (org.mitre.synthea.world.agents.Person)1 MultiTable (org.simulator.math.odes.MultiTable)1