Search in sources :

Example 26 with Parameter

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();
    }
}
Also used : IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) HashMap(java.util.HashMap) CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 27 with Parameter

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();
    }
}
Also used : IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) HashMap(java.util.HashMap) CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) CqlExpressionConfiguration(com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 28 with Parameter

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;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) Pair(org.apache.commons.lang3.tuple.Pair)

Example 29 with Parameter

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());
}
Also used : DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) Test(org.junit.Test)

Example 30 with Parameter

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;
}
Also used : Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) Map(java.util.Map)

Aggregations

Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)60 Test (org.junit.Test)53 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)52 IntegerParameter (com.ibm.cohort.cql.evaluation.parameters.IntegerParameter)40 HashMap (java.util.HashMap)38 DatetimeParameter (com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter)35 StringParameter (com.ibm.cohort.cql.evaluation.parameters.StringParameter)34 DateParameter (com.ibm.cohort.cql.evaluation.parameters.DateParameter)33 DecimalParameter (com.ibm.cohort.cql.evaluation.parameters.DecimalParameter)32 BooleanParameter (com.ibm.cohort.cql.evaluation.parameters.BooleanParameter)26 CodeParameter (com.ibm.cohort.cql.evaluation.parameters.CodeParameter)26 QuantityParameter (com.ibm.cohort.cql.evaluation.parameters.QuantityParameter)26 TimeParameter (com.ibm.cohort.cql.evaluation.parameters.TimeParameter)26 Measure (org.hl7.fhir.r4.model.Measure)19 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)16 Patient (org.hl7.fhir.r4.model.Patient)15 Library (org.hl7.fhir.r4.model.Library)14 ConceptParameter (com.ibm.cohort.cql.evaluation.parameters.ConceptParameter)12 RatioParameter (com.ibm.cohort.cql.evaluation.parameters.RatioParameter)12 ArrayList (java.util.ArrayList)11