use of com.ibm.cohort.cql.evaluation.parameters.Parameter in project quality-measure-and-cohort-service by Alvearie.
the class DefaultMeasurementPeriodStrategyTest method parameter_not_null_datetime_with_ampersand___value_used.
@Test
public void parameter_not_null_datetime_with_ampersand___value_used() {
Measure measure = new Measure();
Map<String, Parameter> parameterOverrides = Collections.singletonMap(DefaultMeasurementPeriodStrategy.DEFAULT_MEASUREMENT_PERIOD_PARAMETER, new IntervalParameter(new DatetimeParameter("@2020-01-01T00:00:00.0"), true, new DatetimeParameter("@2021-01-01T00:00:00.0"), true));
Pair<String, String> result = new DefaultMeasurementPeriodStrategy().getMeasurementPeriod(measure, parameterOverrides);
assertEquals("Unexpected start", "2020-01-01", result.getLeft());
assertEquals("Unexpected end", "2021-01-01", result.getRight());
}
use of com.ibm.cohort.cql.evaluation.parameters.Parameter in project quality-measure-and-cohort-service by Alvearie.
the class SparkCqlEvaluatorTest method testGetFilteredRequestsGlobalParametersApplied.
@Test
public void testGetFilteredRequestsGlobalParametersApplied() {
CqlEvaluationRequests requests = new CqlEvaluationRequests();
requests.setGlobalParameters(new HashMap<String, Parameter>() {
{
put("param1", new IntegerParameter(10));
put("param2", new StringParameter("10"));
put("globalParam", new DecimalParameter("10.0"));
}
});
CqlEvaluationRequest request = makeEvaluationRequest("context", "lib1", "1.0.0");
request.setExpressionsByNames(new HashSet<>(Collections.singletonList("cohortOrig")));
request.setParameters(new HashMap<String, Parameter>() {
{
put("param1", new IntegerParameter(1));
put("param2", new StringParameter("1"));
put("param3", new DecimalParameter("1.0"));
}
});
CqlEvaluationRequest request2 = makeEvaluationRequest("context", "lib2", "1.0.0");
request2.setExpressionsByNames(new HashSet<>(Collections.singletonList("cohortOrig")));
List<CqlEvaluationRequest> evaluations = Arrays.asList(request, request2);
requests.setEvaluations(evaluations);
CqlEvaluationRequests actual = evaluator.getFilteredRequests(requests, null, null);
for (CqlEvaluationRequest evaluation : actual.getEvaluations()) {
if (evaluation.getDescriptor().getLibraryId().equals("lib1")) {
assertEquals(4, evaluation.getParameters().size());
assertEquals(new IntegerParameter(1), evaluation.getParameters().get("param1"));
assertEquals(new StringParameter("1"), evaluation.getParameters().get("param2"));
assertEquals(new DecimalParameter("1.0"), evaluation.getParameters().get("param3"));
assertEquals(new DecimalParameter("10.0"), evaluation.getParameters().get("globalParam"));
} else if (evaluation.getDescriptor().getLibraryId().equals("lib2")) {
assertEquals(3, evaluation.getParameters().size());
assertEquals(new IntegerParameter(10), evaluation.getParameters().get("param1"));
assertEquals(new StringParameter("10"), evaluation.getParameters().get("param2"));
assertEquals(new DecimalParameter("10.0"), evaluation.getParameters().get("globalParam"));
} else {
fail("Unexpected library encountered. Expected only lib1 and lib2.");
}
}
}
use of com.ibm.cohort.cql.evaluation.parameters.Parameter in project quality-measure-and-cohort-service by Alvearie.
the class SparkCqlEvaluatorTest method testParameterMatrixOutputWithKeyParametersSpecifiedSuccess.
@Test
public void testParameterMatrixOutputWithKeyParametersSpecifiedSuccess() throws Exception {
String outputLocation = "target/output/param-matrix-key-params/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);
CqlExpressionConfiguration renamed = new CqlExpressionConfiguration();
renamed.setName("IsFemale");
renamed.setOutputColumn("Renamed");
Map<String, Parameter> parametersWithExtraneous = new HashMap<>(parameters);
parametersWithExtraneous.put("Extraneous", new IntegerParameter(0));
request = new CqlEvaluationRequest(template);
request.setExpressions(Collections.singleton(renamed));
request.setParameters(parametersWithExtraneous);
requests.getEvaluations().add(request);
}
ObjectMapper om = new ObjectMapper();
File jobsFile = new File("target/param-matrix/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, "--key-parameters", "MinimumAge" };
SparkCqlEvaluator.main(args);
validateOutputCountsAndColumns(outputLocation, new HashSet<>(Arrays.asList("id", "parameters", "SampleLibrary|IsFemale", "Renamed")), 10 * ages.size(), "delta");
} finally {
jobsFile.delete();
}
}
use of com.ibm.cohort.cql.evaluation.parameters.Parameter in project quality-measure-and-cohort-service by Alvearie.
the class SparkCqlEvaluatorTest method testParameterMatrixOutputNonOverlappingParamsSuccess.
@Test
public void testParameterMatrixOutputNonOverlappingParamsSuccess() throws Exception {
String outputLocation = "target/output/param-matrix-non-overlap/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);
CqlExpressionConfiguration renamed = new CqlExpressionConfiguration();
renamed.setName("IsFemale");
renamed.setOutputColumn("Renamed");
Map<String, Parameter> parametersWithExtraneous = new HashMap<>(parameters);
parametersWithExtraneous.put("Extraneous", new IntegerParameter(0));
request = new CqlEvaluationRequest(template);
request.setExpressions(Collections.singleton(renamed));
request.setParameters(parametersWithExtraneous);
requests.getEvaluations().add(request);
}
ObjectMapper om = new ObjectMapper();
File jobsFile = new File("target/output/param-matrix/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);
// Because we've got a mismatch in the parameters in the first and second columns, each context
// has a set of rows for the first parameter set where one column is populated and the other is null
// and another set of rows where the first column is null and the second is populated.
validateOutputCountsAndColumns(outputLocation, new HashSet<>(Arrays.asList("id", "parameters", "SampleLibrary|IsFemale", "Renamed")), 10 * ages.size() * /*outputColumns=*/
2, "delta");
} finally {
jobsFile.delete();
}
}
use of com.ibm.cohort.cql.evaluation.parameters.Parameter in project quality-measure-and-cohort-service by Alvearie.
the class CqlContextFactory method createContext.
/**
* Initialize a CQL context from the values associated with the provided
* CQL Context Key. This encapsulates the set of initializations that are
* static from run to run.
*
* @param contextKey container for stable context settings
* @return initialized CQL Context object
* @throws CqlLibraryDeserializationException if the specified library cannot be loaded
*/
protected Context createContext(ContextCacheKey contextKey) throws CqlLibraryDeserializationException {
LibraryLoader libraryLoader = new ProviderBasedLibraryLoader(contextKey.libraryProvider);
VersionedIdentifier vid = new VersionedIdentifier().withId(contextKey.topLevelLibraryIdentifier.getId()).withVersion(contextKey.topLevelLibraryIdentifier.getVersion());
Library entryPoint = libraryLoader.load(vid);
Context cqlContext;
if (contextKey.evaluationDateTime != null) {
cqlContext = new Context(entryPoint, contextKey.evaluationDateTime, new CqlSystemDataProvider());
} else {
cqlContext = new Context(entryPoint, new CqlSystemDataProvider());
}
cqlContext.registerExternalFunctionProvider(vid, this.externalFunctionProvider);
registerExternalIncludes(cqlContext, cqlContext.getCurrentLibrary());
cqlContext.registerLibraryLoader(libraryLoader);
cqlContext.registerTerminologyProvider(contextKey.terminologyProvider);
if (contextKey.parameters != null) {
Library library = cqlContext.getCurrentLibrary();
for (Map.Entry<String, Parameter> entry : contextKey.parameters.entrySet()) {
Object cqlValue = entry.getValue().toCqlType();
cqlContext.setParameter(library.getLocalId(), entry.getKey(), cqlValue);
}
if (library.getIncludes() != null && library.getIncludes().getDef() != null) {
for (IncludeDef def : library.getIncludes().getDef()) {
String name = def.getLocalIdentifier();
for (Map.Entry<String, Parameter> parameterValue : contextKey.parameters.entrySet()) {
Object cqlValue = parameterValue.getValue().toCqlType();
cqlContext.setParameter(name, parameterValue.getKey(), cqlValue);
}
}
}
}
return cqlContext;
}
Aggregations