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);
}
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);
}
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);
}
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;
}
}
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;
}
Aggregations