Search in sources :

Example 1 with Ratio

use of org.opencds.cqf.cql.engine.runtime.Ratio in project quality-measure-and-cohort-service by Alvearie.

the class CQLToFHIRMeasureReportHelperTest method testRatio.

@Test
public void testRatio() {
    String unit = "ml";
    BigDecimal amount1 = new BigDecimal("4.0");
    Quantity quantity1 = new Quantity().withUnit(unit).withValue(amount1);
    BigDecimal amount2 = new BigDecimal("7.0");
    Quantity quantity2 = new Quantity().withUnit(unit).withValue(amount2);
    Ratio ratio = new Ratio().setNumerator(quantity1).setDenominator(quantity2);
    IBaseDatatype fhirTypeValue = CQLToFHIRMeasureReportHelper.getFhirTypeValue(ratio);
    assertTrue(fhirTypeValue instanceof org.hl7.fhir.r4.model.Ratio);
    org.hl7.fhir.r4.model.Ratio castResult = (org.hl7.fhir.r4.model.Ratio) fhirTypeValue;
    verifyBaseTypeAsQuantity(castResult.getNumerator(), amount1, unit);
    verifyBaseTypeAsQuantity(castResult.getDenominator(), amount2, unit);
}
Also used : IBaseDatatype(org.hl7.fhir.instance.model.api.IBaseDatatype) Quantity(org.opencds.cqf.cql.engine.runtime.Quantity) Ratio(org.opencds.cqf.cql.engine.runtime.Ratio) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 2 with Ratio

use of org.opencds.cqf.cql.engine.runtime.Ratio in project quality-measure-and-cohort-service by Alvearie.

the class SparkTypeConverter method toSparkRatio.

public Object toSparkRatio(Object obj) {
    Object result = null;
    if (obj != null) {
        if (obj instanceof Ratio) {
            Ratio ratio = (Ratio) obj;
            Map<String, Object> map = new HashMap<>();
            map.put(SYSTEM_TYPE_PROPERTY, "Ratio");
            map.put("numerator", toSparkType(ratio.getNumerator()));
            map.put("denominator", toSparkType(ratio.getDenominator()));
            result = JavaConverters.mapAsScalaMap(map);
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Ratio(org.opencds.cqf.cql.engine.runtime.Ratio)

Example 3 with Ratio

use of org.opencds.cqf.cql.engine.runtime.Ratio in project quality-measure-and-cohort-service by Alvearie.

the class SparkTypeConverterTest method testToSparkRatio.

@Test
public void testToSparkRatio() {
    Ratio ratio = new Ratio().setNumerator(new Quantity().withValue(new BigDecimal(1.2)).withUnit("mg/mL")).setDenominator(new Quantity().withValue(new BigDecimal(5.9)).withUnit("mg/mL"));
    Object converted = typeConverter.toSparkRatio(ratio);
    assertTrue(converted instanceof scala.collection.Map);
}
Also used : Quantity(org.opencds.cqf.cql.engine.runtime.Quantity) Ratio(org.opencds.cqf.cql.engine.runtime.Ratio) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

Ratio (org.opencds.cqf.cql.engine.runtime.Ratio)3 BigDecimal (java.math.BigDecimal)2 Test (org.junit.Test)2 Quantity (org.opencds.cqf.cql.engine.runtime.Quantity)2 HashMap (java.util.HashMap)1 IBaseDatatype (org.hl7.fhir.instance.model.api.IBaseDatatype)1