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;
}
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());
}
}
}
Aggregations