Search in sources :

Example 1 with SampledDataDt

use of ca.uhn.fhir.model.dstu2.composite.SampledDataDt in project synthea by synthetichealth.

the class FhirDstu2 method mapValueToSampledData.

/**
 * Maps a Synthea internal SampledData object to the FHIR standard SampledData
 * representation.
 *
 * @param value Synthea internal SampledData instance
 * @param unit Observation unit value
 * @return
 */
static SampledDataDt mapValueToSampledData(Components.SampledData value, String unit) {
    SampledDataDt recordData = new SampledDataDt();
    SimpleQuantityDt origin = new SimpleQuantityDt();
    origin.setValue(new BigDecimal(value.originValue)).setCode(unit).setSystem(UNITSOFMEASURE_URI).setUnit(unit);
    recordData.setOrigin(origin);
    // Use the period from the first series. They should all be the same.
    // FHIR output is milliseconds so we need to convert from TimeSeriesData seconds.
    recordData.setPeriod(value.series.get(0).getPeriod() * 1000);
    // Set optional fields if they were provided
    if (value.factor != null) {
        recordData.setFactor(value.factor);
    }
    if (value.lowerLimit != null) {
        recordData.setLowerLimit(value.lowerLimit);
    }
    if (value.upperLimit != null) {
        recordData.setUpperLimit(value.upperLimit);
    }
    recordData.setDimensions(value.series.size());
    recordData.setData(ExportHelper.sampledDataToValueString(value));
    return recordData;
}
Also used : SampledDataDt(ca.uhn.fhir.model.dstu2.composite.SampledDataDt) SimpleQuantityDt(ca.uhn.fhir.model.dstu2.composite.SimpleQuantityDt) BigDecimal(java.math.BigDecimal)

Example 2 with SampledDataDt

use of ca.uhn.fhir.model.dstu2.composite.SampledDataDt in project synthea by synthetichealth.

the class FHIRDSTU2ExporterTest method testSampledDataExport.

@Test
public void testSampledDataExport() throws Exception {
    Person person = new Person(0L);
    person.attributes.put(Person.GENDER, "F");
    person.attributes.put(Person.FIRST_LANGUAGE, "spanish");
    person.attributes.put(Person.RACE, "other");
    person.attributes.put(Person.ETHNICITY, "hispanic");
    person.attributes.put(Person.INCOME, Integer.parseInt(Config.get("generate.demographics.socioeconomic.income.poverty")) * 2);
    person.attributes.put(Person.OCCUPATION_LEVEL, 1.0);
    person.history = new LinkedList<>();
    Provider mock = Mockito.mock(Provider.class);
    Mockito.when(mock.getResourceID()).thenReturn("Mock-UUID");
    person.setProvider(EncounterType.AMBULATORY, mock);
    person.setProvider(EncounterType.WELLNESS, mock);
    person.setProvider(EncounterType.EMERGENCY, mock);
    person.setProvider(EncounterType.INPATIENT, mock);
    Long time = System.currentTimeMillis();
    int age = 35;
    long birthTime = time - Utilities.convertTime("years", age);
    person.attributes.put(Person.BIRTHDATE, birthTime);
    Payer.loadNoInsurance();
    for (int i = 0; i < age; i++) {
        long yearTime = time - Utilities.convertTime("years", i);
        person.coverage.setPayerAtTime(yearTime, Payer.noInsurance);
    }
    Module module = TestHelper.getFixture("observation.json");
    State encounter = module.getState("SomeEncounter");
    assertTrue(encounter.process(person, time));
    person.history.add(encounter);
    State physiology = module.getState("Simulate_CVS");
    assertTrue(physiology.process(person, time));
    person.history.add(physiology);
    State sampleObs = module.getState("SampledDataObservation");
    assertTrue(sampleObs.process(person, time));
    person.history.add(sampleObs);
    FhirContext ctx = FhirDstu2.getContext();
    IParser parser = ctx.newJsonParser().setPrettyPrint(true);
    String fhirJson = FhirDstu2.convertToFHIRJson(person, System.currentTimeMillis());
    Bundle bundle = parser.parseResource(Bundle.class, fhirJson);
    for (Entry entry : bundle.getEntry()) {
        if (entry.getResource() instanceof Observation) {
            Observation obs = (Observation) entry.getResource();
            assertTrue(obs.getValue() instanceof SampledDataDt);
            SampledDataDt data = (SampledDataDt) obs.getValue();
            // 0.01s == 10ms
            assertEquals(10, data.getPeriod().doubleValue(), 0.001);
            assertEquals(3, (int) data.getDimensions());
        }
    }
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) Bundle(ca.uhn.fhir.model.dstu2.resource.Bundle) Provider(org.mitre.synthea.world.agents.Provider) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) SampledDataDt(ca.uhn.fhir.model.dstu2.composite.SampledDataDt) State(org.mitre.synthea.engine.State) Observation(ca.uhn.fhir.model.dstu2.resource.Observation) Module(org.mitre.synthea.engine.Module) Person(org.mitre.synthea.world.agents.Person) IParser(ca.uhn.fhir.parser.IParser) Test(org.junit.Test)

Aggregations

SampledDataDt (ca.uhn.fhir.model.dstu2.composite.SampledDataDt)2 FhirContext (ca.uhn.fhir.context.FhirContext)1 SimpleQuantityDt (ca.uhn.fhir.model.dstu2.composite.SimpleQuantityDt)1 Bundle (ca.uhn.fhir.model.dstu2.resource.Bundle)1 Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)1 Observation (ca.uhn.fhir.model.dstu2.resource.Observation)1 IParser (ca.uhn.fhir.parser.IParser)1 BigDecimal (java.math.BigDecimal)1 Test (org.junit.Test)1 Module (org.mitre.synthea.engine.Module)1 State (org.mitre.synthea.engine.State)1 Person (org.mitre.synthea.world.agents.Person)1 Provider (org.mitre.synthea.world.agents.Provider)1