Search in sources :

Example 11 with CqlExpressionConfiguration

use of com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration in project quality-measure-and-cohort-service by Alvearie.

the class ContextColumnNameEncoderTest method testDefinesWithOutputColumns.

@Test
public void testDefinesWithOutputColumns() {
    CqlLibraryDescriptor libraryDescriptor = new CqlLibraryDescriptor();
    libraryDescriptor.setLibraryId("lib1");
    CqlEvaluationRequest request = new CqlEvaluationRequest();
    CqlExpressionConfiguration expressionConfiguration1 = new CqlExpressionConfiguration();
    expressionConfiguration1.setName("abcd");
    expressionConfiguration1.setOutputColumn("A1");
    CqlExpressionConfiguration expressionConfiguration2 = new CqlExpressionConfiguration();
    expressionConfiguration2.setName("efgh");
    expressionConfiguration2.setOutputColumn("A2");
    request.setExpressions(new HashSet<>(Arrays.asList(expressionConfiguration1, expressionConfiguration2)));
    request.setDescriptor(libraryDescriptor);
    request.setId(1);
    Map<String, String> defineToOutputNameMap = ContextColumnNameEncoder.getDefineToOutputNameMap(request, "|");
    Map<String, String> expectedResult = new HashMap<String, String>() {

        {
            put("abcd", "A1");
            put("efgh", "A2");
        }
    };
    TestCase.assertEquals(expectedResult, defineToOutputNameMap);
}
Also used : HashMap(java.util.HashMap) CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) CqlExpressionConfiguration(com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) Test(org.junit.Test)

Example 12 with CqlExpressionConfiguration

use of com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration in project quality-measure-and-cohort-service by Alvearie.

the class ContextColumnNameEncoderTest method testMultipleDefinesSameOutputColumnThrowsError.

@Test
public void testMultipleDefinesSameOutputColumnThrowsError() {
    CqlLibraryDescriptor libraryDescriptor = new CqlLibraryDescriptor();
    libraryDescriptor.setLibraryId("lib1");
    CqlExpressionConfiguration expressionConfiguration1 = new CqlExpressionConfiguration();
    expressionConfiguration1.setName("abcd");
    expressionConfiguration1.setOutputColumn("NAME");
    CqlExpressionConfiguration expressionConfiguration2 = new CqlExpressionConfiguration();
    expressionConfiguration2.setName("efgh");
    expressionConfiguration2.setOutputColumn("NAME");
    CqlEvaluationRequest request = new CqlEvaluationRequest();
    request.setExpressions(new HashSet<>(Arrays.asList(expressionConfiguration1, expressionConfiguration2)));
    request.setDescriptor(libraryDescriptor);
    request.setId(1);
    IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> ContextColumnNameEncoder.getDefineToOutputNameMap(request, "|"));
    assertTrue(ex.getMessage().contains("Evaluation request contains duplicate outputColumn"));
}
Also used : CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) CqlExpressionConfiguration(com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) Test(org.junit.Test)

Example 13 with CqlExpressionConfiguration

use of com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration in project quality-measure-and-cohort-service by Alvearie.

the class ContextColumnNameEncoderTest method testMultipleRequestsSameDefineDifferentOutputColumn.

@Test
public void testMultipleRequestsSameDefineDifferentOutputColumn() {
    String commonLibrary = "lib1";
    String commonDefine = "abcd";
    CqlLibraryDescriptor libraryDescriptor1 = new CqlLibraryDescriptor();
    libraryDescriptor1.setLibraryId(commonLibrary);
    CqlEvaluationRequest request = new CqlEvaluationRequest();
    request.setDescriptor(libraryDescriptor1);
    request.setId(1);
    CqlExpressionConfiguration expressionConfiguration1 = new CqlExpressionConfiguration();
    expressionConfiguration1.setName(commonDefine);
    expressionConfiguration1.setOutputColumn("col1");
    request.setExpressions(new HashSet<>(Collections.singletonList(expressionConfiguration1)));
    CqlLibraryDescriptor libraryDescriptor2 = new CqlLibraryDescriptor();
    libraryDescriptor2.setLibraryId(commonLibrary);
    CqlEvaluationRequest request2 = new CqlEvaluationRequest();
    request2.setDescriptor(libraryDescriptor2);
    request2.setId(2);
    CqlExpressionConfiguration expressionConfiguration2 = new CqlExpressionConfiguration();
    expressionConfiguration2.setName(commonDefine);
    expressionConfiguration2.setOutputColumn("col2");
    request2.setExpressions(new HashSet<>(Collections.singletonList(expressionConfiguration2)));
    ContextColumnNameEncoder contextColumnNameEncoder = ContextColumnNameEncoder.create(Arrays.asList(request, request2), "|");
    assertEquals("col1", contextColumnNameEncoder.getColumnName(request, commonDefine));
    assertEquals("col2", contextColumnNameEncoder.getColumnName(request2, commonDefine));
}
Also used : CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) CqlExpressionConfiguration(com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) Test(org.junit.Test)

Example 14 with CqlExpressionConfiguration

use of com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration 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();
    }
}
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 15 with CqlExpressionConfiguration

use of com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration 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();
    }
}
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)

Aggregations

CqlExpressionConfiguration (com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration)15 CqlEvaluationRequest (com.ibm.cohort.cql.evaluation.CqlEvaluationRequest)14 CqlLibraryDescriptor (com.ibm.cohort.cql.library.CqlLibraryDescriptor)14 Test (org.junit.Test)13 CqlEvaluationRequests (com.ibm.cohort.cql.evaluation.CqlEvaluationRequests)7 HashMap (java.util.HashMap)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 DateParameter (com.ibm.cohort.cql.evaluation.parameters.DateParameter)3 DecimalParameter (com.ibm.cohort.cql.evaluation.parameters.DecimalParameter)3 IntegerParameter (com.ibm.cohort.cql.evaluation.parameters.IntegerParameter)3 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)3 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)3 StringParameter (com.ibm.cohort.cql.evaluation.parameters.StringParameter)3 File (java.io.File)3 CqlEvaluationResult (com.ibm.cohort.cql.evaluation.CqlEvaluationResult)1 SparkDataRow (com.ibm.cohort.cql.spark.data.SparkDataRow)1 EvaluationError (com.ibm.cohort.cql.spark.errors.EvaluationError)1 DataRow (com.ibm.cohort.datarow.model.DataRow)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1