use of org.hl7.fhir.r4b.model.Quantity in project quality-measure-and-cohort-service by Alvearie.
the class CQLToFHIRMeasureReportHelper method getFhirTypeForInterval.
private static IBaseDatatype getFhirTypeForInterval(Interval interval) {
Object low = interval.getLow();
Object high = interval.getHigh();
if (low instanceof DateTime) {
// Handle DateTime conversion to force UTC timezone
Period period = new Period();
period.setStartElement(createDateTimeType((DateTime) low));
period.setEndElement(createDateTimeType((DateTime) high));
return period;
} else if (low instanceof Quantity) {
return converter.toFhirRange(interval);
} else {
logger.warn("Support not implemented for Interval parameters of type {} on a MeasureReport", low.getClass());
return null;
}
}
use of org.hl7.fhir.r4b.model.Quantity in project quality-measure-and-cohort-service by Alvearie.
the class FHIRRestUtilsTest method testConstructAppropriateJsonRange.
@Test
public void testConstructAppropriateJsonRange() {
ParameterDefinition definition = new ParameterDefinition();
definition.setType("Range");
Extension extension = new Extension();
extension.setUrl("http://ibm.com/fhir/cdm/StructureDefinition/default-value");
Range range = new Range();
Quantity lowQuantity = new Quantity();
lowQuantity.setUnit("year");
lowQuantity.setValue(10);
Quantity highQuantity = new Quantity();
highQuantity.setUnit("year");
highQuantity.setValue(100);
range.setLow(lowQuantity);
range.setHigh(highQuantity);
extension.setValue(range);
List<Extension> extensions = new ArrayList<>();
extensions.add(extension);
definition.setExtension(extensions);
String defaultResult = FHIRRestUtils.complicatedTypeValueConstructor(definition);
assertEquals("{\"low\":{\"value\":10,\"unit\":\"year\"},\"high\":{\"value\":100,\"unit\":\"year\"}}", defaultResult);
}
use of org.hl7.fhir.r4b.model.Quantity in project quality-measure-and-cohort-service by Alvearie.
the class FHIRRestUtilsTest method testConstructAppropriateJsonQuantity.
@Test
public void testConstructAppropriateJsonQuantity() {
ParameterDefinition definition = new ParameterDefinition();
definition.setType("Quantity");
Extension extension = new Extension();
extension.setUrl("http://ibm.com/fhir/cdm/StructureDefinition/default-value");
Quantity quantity = new Quantity();
quantity.setUnit("year");
quantity.setValue(10);
extension.setValue(quantity);
List<Extension> extensions = new ArrayList<>();
extensions.add(extension);
definition.setExtension(extensions);
String defaultResult = FHIRRestUtils.complicatedTypeValueConstructor(definition);
assertEquals("{\"value\":10,\"unit\":\"year\"}", defaultResult);
}
use of org.hl7.fhir.r4b.model.Quantity in project openmrs-module-fhir2 by openmrs.
the class ObservationComponentTranslatorImplTest method toFhirResource_shouldConvertObsValueToType.
@Test
public void toFhirResource_shouldConvertObsValueToType() {
Obs obs = new Obs();
obs.setValueNumeric(130d);
when(observationValueTranslator.toFhirResource(obs)).thenReturn(new Quantity(130d));
Observation.ObservationComponentComponent result = observationComponentTranslator.toFhirResource(obs);
assertThat(result.getValue(), notNullValue());
assertThat(result.getValue(), instanceOf(Quantity.class));
assertThat(((Quantity) result.getValue()).getValue().doubleValue(), equalTo(130d));
}
use of org.hl7.fhir.r4b.model.Quantity in project quality-measure-and-cohort-service by Alvearie.
the class ModelUtilsTest method testFHIR400Model.
@Test
public void testFHIR400Model() throws Exception {
ModelInfo modelInfo = loadFromClasspath("org/hl7/fhir/fhir-modelinfo-4.0.0.xml");
Map<QName, TypeNode> typeMap = ModelUtils.buildTypeMap(modelInfo);
assertEquals(892, typeMap.size());
TypeNode node = typeMap.get(new QName(modelInfo.getUrl(), "MoneyQuantity"));
assertNotNull(node);
assertEquals("Missing parent type", 1, node.getParentTypes().size());
assertEquals("Quantity", node.getParentTypes().iterator().next().getTypeName().getLocalPart());
node = typeMap.get(new QName(modelInfo.getUrl(), "Quantity"));
assertNotNull(node);
assertEquals(5, node.getChildTypes().size());
assertEquals(1, node.getChildTypes().stream().filter(n -> n.getTypeName().getLocalPart().equals("MoneyQuantity")).collect(Collectors.counting()).longValue());
node = typeMap.get(new QName(modelInfo.getUrl(), "Element"));
assertNotNull(node);
// The actual parent is System.Any, but we exclude included types from the type map
assertEquals(0, node.getParentTypes().size());
}
Aggregations