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