use of com.ibm.cohort.cql.evaluation.parameters.Parameter in project quality-measure-and-cohort-service by Alvearie.
the class CqlEvaluatorIntegrationTest method testRequiredCQLParameterSpecifiedPatientInRange.
@Test
public void testRequiredCQLParameterSpecifiedPatientInRange() 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("MaxAge", new IntegerParameter(50));
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, true);
Assert.assertEquals(expected, actual.getExpressionResults());
}
use of com.ibm.cohort.cql.evaluation.parameters.Parameter in project quality-measure-and-cohort-service by Alvearie.
the class CqlEvaluatorIntegrationTest method testRequiredCQLParameterSpecifiedPatientOutOfRange.
@Test
public void testRequiredCQLParameterSpecifiedPatientOutOfRange() 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("MaxAge", new IntegerParameter(40));
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, false);
Assert.assertEquals(expected, actual.getExpressionResults());
}
use of com.ibm.cohort.cql.evaluation.parameters.Parameter 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.Parameter in project quality-measure-and-cohort-service by Alvearie.
the class R4ParameterDefinitionWithDefaultToCohortParameterConverter method toCohortParameter.
public static Parameter toCohortParameter(ParameterDefinition parameterDefinition) {
Extension defaultValueExtension = parameterDefinition.getExtensionByUrl(CDMConstants.PARAMETER_DEFAULT_URL);
Parameter parameter = null;
if (defaultValueExtension != null) {
parameter = toCohortParameter(defaultValueExtension);
}
return parameter;
}
use of com.ibm.cohort.cql.evaluation.parameters.Parameter in project quality-measure-and-cohort-service by Alvearie.
the class SparkCqlEvaluator method getFilteredRequests.
/**
* @param requests Request object to filter.
* @param libraries Map of library id to version used for filtering
* down request based on library id. If this argument
* is null or empty, then no library id filtering
* is performed.
* @param expressions Used to optionally override which expressions will
* run for each individual CqlEvaluationRequest. If this
* argument is null or empty, no expressions are overwritten.
*
* @return CqlEvaluationRequests with the original requests optionally filtered
* based on the library ids the.
* Requests will optionally have their expressions overridden
* by args.expressions. if any are provided.
* Individual requests will also will also have any global
* parameters set on each individual CqlEvaluationRequest.
*/
protected CqlEvaluationRequests getFilteredRequests(CqlEvaluationRequests requests, Map<String, String> libraries, Collection<String> expressions) {
if (requests != null) {
List<CqlEvaluationRequest> evaluations = requests.getEvaluations();
if (libraries != null && !libraries.isEmpty()) {
evaluations = evaluations.stream().filter(r -> libraries.keySet().contains(r.getDescriptor().getLibraryId())).collect(Collectors.toList());
}
if (expressions != null && !expressions.isEmpty()) {
evaluations.forEach(x -> x.setExpressions(x.getExpressions().stream().filter(e -> expressions.contains(e.getName())).collect(Collectors.toSet())));
}
if (requests.getGlobalParameters() != null) {
for (CqlEvaluationRequest evaluation : evaluations) {
for (Map.Entry<String, Parameter> globalParameter : requests.getGlobalParameters().entrySet()) {
Map<String, Parameter> parameters = evaluation.getParameters();
if (parameters == null) {
evaluation.setParameters(new HashMap<>());
parameters = evaluation.getParameters();
}
parameters.putIfAbsent(globalParameter.getKey(), globalParameter.getValue());
}
}
}
requests.setEvaluations(evaluations);
jobSpecification.set(requests);
}
return requests;
}
Aggregations