use of com.ibm.cohort.cql.evaluation.parameters.IntegerParameter in project quality-measure-and-cohort-service by Alvearie.
the class CqlEvaluatorIntegrationTest method testMissingRequiredCQLParameterSomeSpecified.
@Test
public void testMissingRequiredCQLParameterSomeSpecified() throws Exception {
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1978-05-06");
CqlEvaluator evaluator = setupTestFor(patient, "cql.parameters");
String expression = "Female";
Map<String, Parameter> parameters = new HashMap<>();
parameters.put("Unused", new IntegerParameter(100));
CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("TestWithParams", "1.0.0"), parameters, newPatientContext("123"), Collections.singleton(expression));
Map<String, Object> expected = new HashMap<>();
expected.put(expression, null);
Assert.assertEquals(expected, actual.getExpressionResults());
}
use of com.ibm.cohort.cql.evaluation.parameters.IntegerParameter in project quality-measure-and-cohort-service by Alvearie.
the class SparkCqlEvaluatorTest method testParameterMatrixOutputSimpleSuccess.
@Test
public void testParameterMatrixOutputSimpleSuccess() throws Exception {
String outputLocation = "target/output/param-matrix/patient_cohort";
CqlEvaluationRequest template = new CqlEvaluationRequest();
template.setDescriptor(new CqlLibraryDescriptor().setLibraryId("SampleLibrary").setVersion("1.0.0"));
template.setExpressionsByNames(Collections.singleton("IsFemale"));
template.setContextKey("Patient");
template.setContextValue("NA");
CqlEvaluationRequests requests = new CqlEvaluationRequests();
requests.setEvaluations(new ArrayList<>());
List<Integer> ages = Arrays.asList(15, 17, 18);
for (Integer age : ages) {
Map<String, Parameter> parameters = new HashMap<>();
parameters.put("MinimumAge", new IntegerParameter(age));
CqlEvaluationRequest request = new CqlEvaluationRequest(template);
request.setParameters(parameters);
requests.getEvaluations().add(request);
}
ObjectMapper om = new ObjectMapper();
File jobsFile = new File("target/output/param-matrix-simple/cql-jobs.json");
if (!jobsFile.exists()) {
jobsFile.getParentFile().mkdirs();
}
FileUtils.write(jobsFile, om.writeValueAsString(requests), StandardCharsets.UTF_8);
try {
String[] args = new String[] { "-d", "src/test/resources/simple-job/context-definitions.json", "-j", jobsFile.getPath(), "-m", "src/test/resources/simple-job/modelinfo/simple-modelinfo-1.0.0.xml", "-c", "src/test/resources/simple-job/cql", "-i", "Patient=" + new File("src/test/resources/simple-job/testdata/patient").toURI().toString(), "-o", "Patient=" + new File(outputLocation).toURI().toString(), "--output-format", "delta", "--overwrite-output-for-contexts", "--metadata-output-path", outputLocation };
SparkCqlEvaluator.main(args);
validateOutputCountsAndColumns(outputLocation, new HashSet<>(Arrays.asList("id", "parameters", "SampleLibrary|IsFemale")), 10 * ages.size(), "delta");
} finally {
jobsFile.delete();
}
}
use of com.ibm.cohort.cql.evaluation.parameters.IntegerParameter in project quality-measure-and-cohort-service by Alvearie.
the class SparkCqlEvaluatorTest method testParameterMatrixOutputDisabledRowsGroupingSuccess.
@Test
public void testParameterMatrixOutputDisabledRowsGroupingSuccess() throws Exception {
String outputLocation = "target/output/param-matrix-group-disabled/patient_cohort";
CqlEvaluationRequest template = new CqlEvaluationRequest();
template.setDescriptor(new CqlLibraryDescriptor().setLibraryId("SampleLibrary").setVersion("1.0.0"));
template.setExpressionsByNames(Collections.singleton("IsFemale"));
template.setContextKey("Patient");
template.setContextValue("NA");
CqlEvaluationRequests requests = new CqlEvaluationRequests();
requests.setEvaluations(new ArrayList<>());
List<Integer> ages = Arrays.asList(15, 17, 18);
for (Integer age : ages) {
Map<String, Parameter> parameters = new HashMap<>();
parameters.put("MinimumAge", new IntegerParameter(age));
CqlExpressionConfiguration renamed = new CqlExpressionConfiguration();
renamed.setName("IsFemale");
renamed.setOutputColumn("IsFemale" + age);
CqlEvaluationRequest request = new CqlEvaluationRequest(template);
request.setExpressions(Collections.singleton(renamed));
request.setParameters(parameters);
requests.getEvaluations().add(request);
}
ObjectMapper om = new ObjectMapper();
File jobsFile = new File("target/output/param-matrix-simple/cql-jobs.json");
if (!jobsFile.exists()) {
jobsFile.getParentFile().mkdirs();
}
FileUtils.write(jobsFile, om.writeValueAsString(requests), StandardCharsets.UTF_8);
try {
String[] args = new String[] { "-d", "src/test/resources/simple-job/context-definitions.json", "-j", jobsFile.getPath(), "-m", "src/test/resources/simple-job/modelinfo/simple-modelinfo-1.0.0.xml", "-c", "src/test/resources/simple-job/cql", "-i", "Patient=" + new File("src/test/resources/simple-job/testdata/patient").toURI().toString(), "-o", "Patient=" + new File(outputLocation).toURI().toString(), "--output-format", "delta", "--overwrite-output-for-contexts", "--metadata-output-path", outputLocation, "--disable-result-grouping" };
SparkCqlEvaluator.main(args);
validateOutputCountsAndColumns(outputLocation, new HashSet<>(Arrays.asList("id", "parameters", "IsFemale15", "IsFemale17", "IsFemale18")), 10, "delta");
} finally {
jobsFile.delete();
}
}
use of com.ibm.cohort.cql.evaluation.parameters.IntegerParameter in project quality-measure-and-cohort-service by Alvearie.
the class R4ParameterDefinitionWithDefaultToCohortParameterConverter method toCohortParameter.
public static Parameter toCohortParameter(Extension extension) {
Parameter parameter;
Type extensionValue = extension.getValue();
if (extensionValue instanceof Base64BinaryType) {
parameter = new StringParameter(((Base64BinaryType) extensionValue).asStringValue());
} else if (extensionValue instanceof BooleanType) {
parameter = new BooleanParameter(((BooleanType) extensionValue).booleanValue());
} else if (extensionValue instanceof DateType) {
parameter = new DateParameter(((DateType) extensionValue).asStringValue());
} else if (extensionValue instanceof DateTimeType) {
parameter = convertDateTimeType((DateTimeType) extensionValue);
} else if (extensionValue instanceof DecimalType) {
parameter = new DecimalParameter(((DecimalType) extensionValue).getValueAsString());
} else if (extensionValue instanceof InstantType) {
parameter = new DatetimeParameter(((InstantType) extensionValue).getValueAsString());
} else if (extensionValue instanceof IntegerType) {
parameter = new IntegerParameter(((IntegerType) extensionValue).getValue());
} else if (extensionValue instanceof StringType) {
parameter = new StringParameter(((StringType) extensionValue).getValue());
} else if (extensionValue instanceof TimeType) {
parameter = new TimeParameter(((TimeType) extensionValue).asStringValue());
} else if (extensionValue instanceof UriType) {
parameter = new StringParameter(((UriType) extensionValue).getValue());
} else if (extensionValue instanceof Coding) {
parameter = convertCoding((Coding) extensionValue);
} else if (extensionValue instanceof CodeableConcept) {
parameter = convertCodeableConcept((CodeableConcept) extensionValue);
} else if (extensionValue instanceof Period) {
Period castValue = (Period) extensionValue;
parameter = new IntervalParameter(convertDateTimeType(castValue.getStartElement()), true, convertDateTimeType(castValue.getEndElement()), true);
} else if (extensionValue instanceof Quantity) {
parameter = convertQuantity((Quantity) extensionValue);
} else if (extensionValue instanceof Range) {
Range castValue = (Range) extensionValue;
parameter = new IntervalParameter(convertQuantity(castValue.getLow()), true, convertQuantity(castValue.getHigh()), true);
} else if (extensionValue instanceof Ratio) {
Ratio castValue = (Ratio) extensionValue;
parameter = new RatioParameter().setDenominator(convertQuantity(castValue.getDenominator())).setNumerator(convertQuantity(castValue.getNumerator()));
} else {
throw new UnsupportedFhirTypeException(extensionValue);
}
return parameter;
}
use of com.ibm.cohort.cql.evaluation.parameters.IntegerParameter in project quality-measure-and-cohort-service by Alvearie.
the class MeasureEvaluatorTest method measure_report_generated___named_parameters_on_measure_report.
@Test
public void measure_report_generated___named_parameters_on_measure_report() throws Exception {
CapabilityStatement metadata = getCapabilityStatement();
mockFhirResourceRetrieval("/metadata?_format=json", metadata);
Patient patient = getPatient("123", AdministrativeGender.MALE, "1970-10-10");
mockFhirResourceRetrieval(patient);
Library library = mockLibraryRetrieval("TestDummyPopulations", DEFAULT_VERSION, "cql/fhir-measure/test-dummy-populations.xml", ELM_MIME_TYPE);
Measure measure = getCohortMeasure("CohortMeasureName", library, INITIAL_POPULATION);
mockFhirResourceRetrieval(measure);
Map<String, Parameter> parameterMap = new HashMap<>();
parameterMap.put("integerParam", new IntegerParameter(1));
parameterMap.put("decimalParam", new DecimalParameter("1.0"));
parameterMap.put("stringParam", new StringParameter("1"));
parameterMap.put("booleanParam", new BooleanParameter(false));
parameterMap.put("datetimeParam", new DatetimeParameter("2020-01-01"));
parameterMap.put("dateParam", new DateParameter("2020-01-01"));
parameterMap.put("timeParam", new TimeParameter("01:00:00"));
parameterMap.put("quantityParam", new QuantityParameter("1.0", "ml"));
parameterMap.put("ratioParam", new RatioParameter(new QuantityParameter("1.0", "ml"), new QuantityParameter("2.0", "ml")));
parameterMap.put("codeParam", new CodeParameter("1", "2", "3", "4"));
parameterMap.put("conceptParam", new ConceptParameter("1", new CodeParameter("1", "2", "3", "4")));
parameterMap.put("datetimeIntervalParam", new IntervalParameter(new DatetimeParameter("2020-01-01"), true, new DatetimeParameter("2021-01-01"), true));
parameterMap.put("quantityIntervalParam", new IntervalParameter(new QuantityParameter("1.0", "ml"), true, new QuantityParameter("2.0", "ml"), true));
MeasureReport report = evaluator.evaluatePatientMeasure(measure.getId(), patient.getId(), parameterMap);
assertNotNull(report);
List<String> parameterNames = report.getExtension().stream().filter(x -> x.getUrl().equals(MEASURE_PARAMETER_VALUE_URL)).map(x -> (ParameterDefinition) x.getValue()).map(ParameterDefinition::getName).collect(Collectors.toList());
// Expected parameters are the ones listed above, plus the special parameters
// measurement period and product line
assertEquals(parameterMap.size() + 2, parameterNames.size());
assertTrue(parameterNames.containsAll(parameterMap.keySet()));
assertTrue(parameterNames.contains(CDMConstants.MEASUREMENT_PERIOD));
assertTrue(parameterNames.contains(CDMConstants.PRODUCT_LINE));
}
Aggregations