use of com.ibm.cohort.cql.evaluation.parameters.Parameter 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.Parameter 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.Parameter in project quality-measure-and-cohort-service by Alvearie.
the class CqlEvaluator method evaluate.
public List<Pair<CqlEvaluationRequest, CqlEvaluationResult>> evaluate(CqlEvaluationRequests requests, CqlDebug debug) {
List<Pair<CqlEvaluationRequest, CqlEvaluationResult>> results = new ArrayList<>(requests.getEvaluations().size());
ZonedDateTime batchDateTime = ZonedDateTime.now();
for (CqlEvaluationRequest request : requests.getEvaluations()) {
Map<String, Parameter> parameters = new HashMap<>();
if (requests.getGlobalParameters() != null) {
parameters.putAll(requests.getGlobalParameters());
}
if (request.getParameters() != null) {
parameters.putAll(request.getParameters());
}
CqlEvaluationRequest withGlobals = new CqlEvaluationRequest(request);
withGlobals.setParameters(parameters);
results.add(Pair.of(request, evaluate(withGlobals, debug, batchDateTime)));
}
return results;
}
use of com.ibm.cohort.cql.evaluation.parameters.Parameter in project quality-measure-and-cohort-service by Alvearie.
the class ParameterHelperTest method testResolveCodeParameter.
@Test
public void testResolveCodeParameter() {
Map<String, Parameter> params = ParameterHelper.parseParameterArguments(Arrays.asList("test:code:1.2.3:SNOMEDCT:Hernia"));
assertEquals(1, params.size());
CodeParameter p = (CodeParameter) params.get("test");
assertNotNull("Parameter with expected name not found", p);
assertEquals("Unexpected value", "1.2.3", p.getValue());
assertEquals("Unexpected value", "SNOMEDCT", p.getSystem());
assertEquals("Unexpected value", "Hernia", p.getDisplay());
}
use of com.ibm.cohort.cql.evaluation.parameters.Parameter in project quality-measure-and-cohort-service by Alvearie.
the class ParameterHelper method parseParameterArguments.
/**
* Conversion routine for CQL parameter values encoded for command line
* interaction.
*
* @param arguments list of CQL parameter values encoded as strings
* @return decoded parameter values formatted for consumption by the CQL engine
*/
public static Map<String, Parameter> parseParameterArguments(List<String> arguments) {
Map<String, Parameter> result = new HashMap<>();
Pattern p = Pattern.compile("(?<name>[^:]+):(?<type>[^:]+):(?<value>.*)");
for (String arg : arguments) {
Matcher m = p.matcher(arg);
if (m.matches()) {
String name = m.group("name");
String type = m.group("type");
String value = m.group("value");
String subType = null;
String start = null;
String end = null;
if (type.equals("interval")) {
String[] parts = value.split(",");
if (parts.length != 3) {
throw new IllegalArgumentException("Invalid interval format. Must contain exactly 3 fields separated by commas");
}
subType = parts[0];
start = parts[1];
end = parts[2];
}
Map.Entry<String, Parameter> stringObjectEntry = convertParameter(name, type, value, subType, start, end);
result.put(stringObjectEntry.getKey(), stringObjectEntry.getValue());
} else {
throw new IllegalArgumentException(String.format("Invalid parameter string %s", arg));
}
}
return result;
}
Aggregations