Search in sources :

Example 1 with Quantity

use of org.opencds.cqf.cql.engine.runtime.Quantity 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 Quantity

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

the class CQLToFHIRMeasureReportHelperTest method testIntervalQuantity_shouldReturnRange.

@Test
public void testIntervalQuantity_shouldReturnRange() {
    String unit = "ml";
    BigDecimal startAmount = new BigDecimal("4.0");
    BigDecimal endAmount = new BigDecimal("5.0");
    Quantity startQuantity = new Quantity().withUnit(unit).withValue(startAmount);
    Quantity endQuantity = new Quantity().withUnit(unit).withValue(endAmount);
    IBaseDatatype fhirTypeValue = CQLToFHIRMeasureReportHelper.getFhirTypeValue(new Interval(startQuantity, true, endQuantity, true));
    assertTrue(fhirTypeValue instanceof Range);
    Range castResult = (Range) fhirTypeValue;
    verifyBaseTypeAsQuantity(castResult.getLow(), startAmount, unit);
    verifyBaseTypeAsQuantity(castResult.getHigh(), endAmount, unit);
}
Also used : IBaseDatatype(org.hl7.fhir.instance.model.api.IBaseDatatype) Quantity(org.opencds.cqf.cql.engine.runtime.Quantity) Range(org.hl7.fhir.r4.model.Range) BigDecimal(java.math.BigDecimal) Interval(org.opencds.cqf.cql.engine.runtime.Interval) Test(org.junit.Test)

Example 3 with Quantity

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

the class CQLToFHIRMeasureReportHelperTest method testQuantity.

@Test
public void testQuantity() {
    String unit = "ml";
    BigDecimal amount = new BigDecimal("4.0");
    Quantity quantity = new Quantity().withUnit(unit).withValue(amount);
    verifyBaseTypeAsQuantity(CQLToFHIRMeasureReportHelper.getFhirTypeValue(quantity), amount, unit);
}
Also used : Quantity(org.opencds.cqf.cql.engine.runtime.Quantity) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 4 with Quantity

use of org.opencds.cqf.cql.engine.runtime.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 5 with Quantity

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

the class SparkTypeConverter method toSparkQuantity.

public Object toSparkQuantity(Object obj) {
    Object result = null;
    if (obj != null) {
        if (obj instanceof Quantity) {
            Quantity quantity = (Quantity) obj;
            Map<String, Object> map = new HashMap<>();
            map.put(SYSTEM_TYPE_PROPERTY, "Quantity");
            map.put("unit", quantity.getUnit());
            map.put("value", quantity.getValue());
            result = JavaConverters.mapAsScalaMap(map);
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Quantity(org.opencds.cqf.cql.engine.runtime.Quantity)

Aggregations

Quantity (org.opencds.cqf.cql.engine.runtime.Quantity)6 BigDecimal (java.math.BigDecimal)4 Test (org.junit.Test)4 IBaseDatatype (org.hl7.fhir.instance.model.api.IBaseDatatype)2 Ratio (org.opencds.cqf.cql.engine.runtime.Ratio)2 HashMap (java.util.HashMap)1 Period (org.hl7.fhir.r4.model.Period)1 Range (org.hl7.fhir.r4.model.Range)1 DateTime (org.opencds.cqf.cql.engine.runtime.DateTime)1 Interval (org.opencds.cqf.cql.engine.runtime.Interval)1