Search in sources :

Example 26 with Quantity

use of org.hl7.fhir.dstu2016may.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;
    }
}
Also used : Period(org.hl7.fhir.r4.model.Period) Quantity(org.opencds.cqf.cql.engine.runtime.Quantity) DateTime(org.opencds.cqf.cql.engine.runtime.DateTime)

Example 27 with Quantity

use of org.hl7.fhir.dstu2016may.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);
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) ArrayList(java.util.ArrayList) Quantity(org.hl7.fhir.r4.model.Quantity) Range(org.hl7.fhir.r4.model.Range) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 28 with Quantity

use of org.hl7.fhir.dstu2016may.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);
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) ArrayList(java.util.ArrayList) Quantity(org.hl7.fhir.r4.model.Quantity) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 29 with Quantity

use of org.hl7.fhir.dstu2016may.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));
}
Also used : Obs(org.openmrs.Obs) Observation(org.hl7.fhir.r4.model.Observation) Quantity(org.hl7.fhir.r4.model.Quantity) Test(org.junit.Test)

Example 30 with Quantity

use of org.hl7.fhir.dstu2016may.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());
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) Arrays(java.util.Arrays) TypeInfo(org.hl7.elm_modelinfo.r1.TypeInfo) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertThrows(org.junit.Assert.assertThrows) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) Test(org.junit.Test) ClassInfo(org.hl7.elm_modelinfo.r1.ClassInfo) Collectors(java.util.stream.Collectors) File(java.io.File) Assert.assertThat(org.junit.Assert.assertThat) HashSet(java.util.HashSet) Assert.assertNull(org.junit.Assert.assertNull) TypeNode(com.ibm.cohort.cql.spark.optimizer.ModelUtils.TypeNode) Map(java.util.Map) QName(javax.xml.namespace.QName) JAXB(javax.xml.bind.JAXB) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) ModelSpecifier(org.hl7.elm_modelinfo.r1.ModelSpecifier) ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) QName(javax.xml.namespace.QName) TypeNode(com.ibm.cohort.cql.spark.optimizer.ModelUtils.TypeNode) Test(org.junit.Test)

Aggregations

Quantity (org.hl7.fhir.r4.model.Quantity)58 ArrayList (java.util.ArrayList)47 Test (org.junit.jupiter.api.Test)40 BigDecimal (java.math.BigDecimal)39 Quantity (org.hl7.fhir.dstu3.model.Quantity)39 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)37 Test (org.junit.Test)25 List (java.util.List)24 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)23 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)23 NotImplementedException (org.apache.commons.lang3.NotImplementedException)19 FHIRException (org.hl7.fhir.exceptions.FHIRException)18 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)18 Observation (org.hl7.fhir.r4.model.Observation)18 UcumException (org.fhir.ucum.UcumException)16 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)16 Resource (org.hl7.fhir.r4.model.Resource)16 Quantity (org.hl7.fhir.r5.model.Quantity)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 Coding (org.hl7.fhir.r4.model.Coding)13