use of org.hl7.fhir.dstu2.model.SampledData in project org.hl7.fhir.core by hapifhir.
the class ProfileDrivenRenderer method renderLeaf.
private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode parent, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints, String path, int indent) throws FHIRException, UnsupportedEncodingException, IOException, EOperationOutcome {
if (ew == null)
return;
Base e = ew.getBase();
if (e instanceof StringType)
x.addText(((StringType) e).getValue());
else if (e instanceof CodeType)
x.addText(((CodeType) e).getValue());
else if (e instanceof IdType)
x.addText(((IdType) e).getValue());
else if (e instanceof Extension)
return;
else if (e instanceof InstantType)
x.addText(((InstantType) e).toHumanDisplay());
else if (e instanceof DateTimeType) {
renderDateTime(x, e);
} else if (e instanceof Base64BinaryType)
x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
else if (e instanceof org.hl7.fhir.r5.model.DateType) {
org.hl7.fhir.r5.model.DateType dt = ((org.hl7.fhir.r5.model.DateType) e);
renderDate(x, dt);
} else if (e instanceof Enumeration) {
Object ev = ((Enumeration<?>) e).getValue();
// todo: look up a display name if there is one
x.addText(ev == null ? "" : ev.toString());
} else if (e instanceof BooleanType) {
x.addText(((BooleanType) e).getValue().toString());
} else if (e instanceof CodeableConcept) {
renderCodeableConcept(x, (CodeableConcept) e, showCodeDetails);
} else if (e instanceof Coding) {
renderCoding(x, (Coding) e, showCodeDetails);
} else if (e instanceof CodeableReference) {
renderCodeableReference(x, (CodeableReference) e, showCodeDetails);
} else if (e instanceof Annotation) {
renderAnnotation(x, (Annotation) e);
} else if (e instanceof Identifier) {
renderIdentifier(x, (Identifier) e);
} else if (e instanceof org.hl7.fhir.r5.model.IntegerType) {
if (((org.hl7.fhir.r5.model.IntegerType) e).hasValue()) {
x.addText(Integer.toString(((org.hl7.fhir.r5.model.IntegerType) e).getValue()));
} else {
x.addText("??");
}
} else if (e instanceof org.hl7.fhir.r5.model.Integer64Type) {
if (((org.hl7.fhir.r5.model.Integer64Type) e).hasValue()) {
x.addText(Long.toString(((org.hl7.fhir.r5.model.Integer64Type) e).getValue()));
} else {
x.addText("??");
}
} else if (e instanceof org.hl7.fhir.r5.model.DecimalType) {
x.addText(((org.hl7.fhir.r5.model.DecimalType) e).getValue().toString());
} else if (e instanceof HumanName) {
renderHumanName(x, (HumanName) e);
} else if (e instanceof SampledData) {
renderSampledData(x, (SampledData) e);
} else if (e instanceof Address) {
renderAddress(x, (Address) e);
} else if (e instanceof ContactPoint) {
renderContactPoint(x, (ContactPoint) e);
} else if (e instanceof Expression) {
renderExpression(x, (Expression) e);
} else if (e instanceof Money) {
renderMoney(x, (Money) e);
} else if (e instanceof ContactDetail) {
ContactDetail cd = (ContactDetail) e;
if (cd.hasName()) {
x.tx(cd.getName() + ": ");
}
boolean first = true;
for (ContactPoint c : cd.getTelecom()) {
if (first)
first = false;
else
x.tx(",");
renderContactPoint(x, c);
}
} else if (e instanceof UriType) {
renderUri(x, (UriType) e, defn.getPath(), rcontext != null && rcontext.getResourceResource() != null ? rcontext.getResourceResource().getId() : null);
} else if (e instanceof Timing) {
renderTiming(x, (Timing) e);
} else if (e instanceof Range) {
renderRange(x, (Range) e);
} else if (e instanceof Quantity) {
renderQuantity(x, (Quantity) e, showCodeDetails);
} else if (e instanceof Ratio) {
renderQuantity(x, ((Ratio) e).getNumerator(), showCodeDetails);
x.tx("/");
renderQuantity(x, ((Ratio) e).getDenominator(), showCodeDetails);
} else if (e instanceof Period) {
Period p = (Period) e;
renderPeriod(x, p);
} else if (e instanceof Reference) {
Reference r = (Reference) e;
if (r.getReference() != null && r.getReference().contains("#")) {
if (containedIds.contains(r.getReference().substring(1))) {
x.ah(r.getReference()).tx("See " + r.getReference());
} else {
// in this case, we render the resource in line
ResourceWrapper rw = null;
for (ResourceWrapper t : res.getContained()) {
if (r.getReference().substring(1).equals(t.getId())) {
rw = t;
}
}
if (rw == null) {
renderReference(res, x, r);
} else {
x.an(rw.getId());
ResourceRenderer rr = RendererFactory.factory(rw, context.copy().setAddGeneratedNarrativeHeader(false));
rr.render(parent.blockquote(), rw);
}
}
} else {
renderReference(res, x, r);
}
} else if (e instanceof Resource) {
return;
} else if (e instanceof DataRequirement) {
DataRequirement p = (DataRequirement) e;
renderDataRequirement(x, p);
} else if (e instanceof PrimitiveType) {
x.tx(((PrimitiveType) e).primitiveValue());
} else if (e instanceof ElementDefinition) {
x.tx("todo-bundle");
} else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta)) {
throw new NotImplementedException("type " + e.getClass().getName() + " not handled - should not be here");
}
}
use of org.hl7.fhir.dstu2.model.SampledData in project synthea by synthetichealth.
the class FHIRR4ExporterTest 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.attributes.put(Person.CONTACT_EMAIL, "test@test.test");
person.attributes.put(Person.CONTACT_GIVEN_NAME, "John");
person.attributes.put(Person.CONTACT_FAMILY_NAME, "Appleseed");
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 = FhirR4.getContext();
IParser parser = ctx.newJsonParser().setPrettyPrint(true);
String fhirJson = FhirR4.convertToFHIRJson(person, System.currentTimeMillis());
Bundle bundle = parser.parseResource(Bundle.class, fhirJson);
for (BundleEntryComponent entry : bundle.getEntry()) {
if (entry.getResource() instanceof Observation) {
Observation obs = (Observation) entry.getResource();
assertTrue(obs.getValue() instanceof SampledData);
SampledData data = (SampledData) obs.getValue();
// 0.01s == 10ms
assertEquals(10, data.getPeriod().doubleValue(), 0.001);
assertEquals(3, (int) data.getDimensions());
}
}
}
use of org.hl7.fhir.dstu2.model.SampledData in project synthea by synthetichealth.
the class FHIRSTU3ExporterTest 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.attributes.put(Person.CONTACT_EMAIL, "test@test.test");
person.attributes.put(Person.CONTACT_GIVEN_NAME, "John");
person.attributes.put(Person.CONTACT_FAMILY_NAME, "Appleseed");
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 = FhirStu3.getContext();
IParser parser = ctx.newJsonParser().setPrettyPrint(true);
String fhirJson = FhirStu3.convertToFHIRJson(person, System.currentTimeMillis());
Bundle bundle = parser.parseResource(Bundle.class, fhirJson);
for (BundleEntryComponent entry : bundle.getEntry()) {
if (entry.getResource() instanceof Observation) {
Observation obs = (Observation) entry.getResource();
assertTrue(obs.getValue() instanceof SampledData);
SampledData data = (SampledData) obs.getValue();
// 0.01s == 10ms
assertEquals(10, data.getPeriod().doubleValue(), 0.001);
assertEquals(3, (int) data.getDimensions());
}
}
}
use of org.hl7.fhir.dstu2.model.SampledData in project synthea by synthetichealth.
the class FhirR4 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 org.hl7.fhir.r4.model.SampledData mapValueToSampledData(Components.SampledData value, String unit) {
org.hl7.fhir.r4.model.SampledData recordData = new org.hl7.fhir.r4.model.SampledData();
recordData.setOrigin(new Quantity().setValue(value.originValue).setCode(unit).setSystem(UNITSOFMEASURE_URI).setUnit(unit));
// 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 org.hl7.fhir.dstu2.model.SampledData in project synthea by synthetichealth.
the class FhirStu3 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 org.hl7.fhir.dstu3.model.SampledData mapValueToSampledData(Components.SampledData value, String unit) {
org.hl7.fhir.dstu3.model.SampledData recordData = new org.hl7.fhir.dstu3.model.SampledData();
SimpleQuantity origin = new SimpleQuantity();
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;
}
Aggregations