Search in sources :

Example 11 with CqlEvaluationRequest

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

the class ConfigurableOutputColumnNameEncoderTest method testNamesForSingleContext.

@Test
public void testNamesForSingleContext() {
    CqlLibraryDescriptor libraryDescriptor1 = new CqlLibraryDescriptor();
    libraryDescriptor1.setLibraryId("lib1");
    CqlEvaluationRequest request = new CqlEvaluationRequest();
    request.setDescriptor(libraryDescriptor1);
    request.setId(1);
    CqlExpressionConfiguration expressionConfiguration1 = new CqlExpressionConfiguration();
    expressionConfiguration1.setName("abcd");
    CqlExpressionConfiguration expressionConfiguration2 = new CqlExpressionConfiguration();
    expressionConfiguration2.setName("efgh");
    expressionConfiguration2.setOutputColumn("A2");
    request.setExpressions(new HashSet<>(Arrays.asList(expressionConfiguration1, expressionConfiguration2)));
    CqlLibraryDescriptor libraryDescriptor2 = new CqlLibraryDescriptor();
    libraryDescriptor2.setLibraryId("lib2");
    CqlEvaluationRequest request2 = new CqlEvaluationRequest();
    request2.setDescriptor(libraryDescriptor2);
    request2.setId(2);
    CqlExpressionConfiguration expressionConfiguration3 = new CqlExpressionConfiguration();
    expressionConfiguration3.setName("ijkl");
    expressionConfiguration3.setOutputColumn("A3");
    CqlExpressionConfiguration expressionConfiguration4 = new CqlExpressionConfiguration();
    expressionConfiguration4.setName("mnop");
    request2.setExpressions(new HashSet<>(Arrays.asList(expressionConfiguration3, expressionConfiguration4)));
    request.setContextKey("context1");
    request2.setContextKey("context1");
    CqlEvaluationRequests evaluationRequests = new CqlEvaluationRequests();
    evaluationRequests.setEvaluations(Arrays.asList(request, request2));
    ConfigurableOutputColumnNameEncoder nameEncoder = ConfigurableOutputColumnNameEncoder.create(evaluationRequests, "|");
    assertEquals("lib1|abcd", nameEncoder.getColumnName(request, "abcd"));
    assertEquals("A2", nameEncoder.getColumnName(request, "efgh"));
    assertEquals("A3", nameEncoder.getColumnName(request2, "ijkl"));
    assertEquals("lib2|mnop", nameEncoder.getColumnName(request2, "mnop"));
}
Also used : CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) CqlExpressionConfiguration(com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) Test(org.junit.Test)

Example 12 with CqlEvaluationRequest

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

the class ContextColumnNameEncoderTest method testMultipleUniqueDefinesDefaultNaming.

@Test
public void testMultipleUniqueDefinesDefaultNaming() {
    CqlLibraryDescriptor libraryDescriptor = new CqlLibraryDescriptor();
    libraryDescriptor.setLibraryId("lib1");
    CqlEvaluationRequest request = new CqlEvaluationRequest();
    request.setExpressionsByNames(new HashSet<>(Arrays.asList("abcd", "efgh")));
    request.setDescriptor(libraryDescriptor);
    request.setId(1);
    Map<String, String> defineToOutputNameMap = ContextColumnNameEncoder.getDefineToOutputNameMap(request, "|");
    Map<String, String> expectedResult = new HashMap<String, String>() {

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

Example 13 with CqlEvaluationRequest

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

the class ContextColumnNameEncoderTest method testgetColumnNameForUnknownEvaluationRequest.

@Test
public void testgetColumnNameForUnknownEvaluationRequest() {
    ContextColumnNameEncoder contextColumnNameEncoder = ContextColumnNameEncoder.create(Collections.emptyList(), "|");
    CqlEvaluationRequest request = new CqlEvaluationRequest();
    request.setId(1);
    IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> contextColumnNameEncoder.getColumnName(request, "define1"));
    assertTrue(ex.getMessage().contains("No lookup information found for CqlEvaluationRequest with id"));
}
Also used : CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) Test(org.junit.Test)

Example 14 with CqlEvaluationRequest

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

the class ContextColumnNameEncoderTest method testMultipleDefinesSameNameThrowsError.

@Test
public void testMultipleDefinesSameNameThrowsError() {
    CqlLibraryDescriptor libraryDescriptor = new CqlLibraryDescriptor();
    libraryDescriptor.setLibraryId("lib1");
    CqlExpressionConfiguration expressionConfiguration1 = new CqlExpressionConfiguration();
    expressionConfiguration1.setName("abcd");
    expressionConfiguration1.setOutputColumn("A1");
    CqlExpressionConfiguration expressionConfiguration2 = new CqlExpressionConfiguration();
    expressionConfiguration2.setName("abcd");
    expressionConfiguration2.setOutputColumn("A2");
    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 expression abcd"));
}
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 15 with CqlEvaluationRequest

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

the class SparkCqlEvaluator method getFilteredJobSpecificationWithIds.

/**
 * Read the job specification file, apply some filtering logic for the
 * given requests, and then assign unique ids to each remaining request.
 *
 * @return CqlEvaluationRequests object containing requests with optional
 *         filtering and overrides described in {@link #getFilteredRequests(CqlEvaluationRequests, Map, Collection)}.
 *         Each remaining CqlEvaluationRequest is assigned a unique integer id.
 *
 * @throws Exception if there was an error reading the job specification.
 */
public CqlEvaluationRequests getFilteredJobSpecificationWithIds() throws Exception {
    CqlEvaluationRequests filteredRequests = getFilteredRequests(getJobSpecification(), args.libraries, args.expressions);
    List<CqlEvaluationRequest> evaluations = filteredRequests.getEvaluations();
    if (evaluations != null && !evaluations.isEmpty()) {
        int i = 1;
        for (CqlEvaluationRequest evaluation : evaluations) {
            evaluation.setId(i);
            i++;
        }
        filteredRequests.setEvaluations(evaluations);
    }
    return filteredRequests;
}
Also used : CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests)

Aggregations

CqlEvaluationRequest (com.ibm.cohort.cql.evaluation.CqlEvaluationRequest)30 Test (org.junit.Test)21 CqlLibraryDescriptor (com.ibm.cohort.cql.library.CqlLibraryDescriptor)19 HashMap (java.util.HashMap)16 CqlEvaluationRequests (com.ibm.cohort.cql.evaluation.CqlEvaluationRequests)15 CqlExpressionConfiguration (com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration)15 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 DateParameter (com.ibm.cohort.cql.evaluation.parameters.DateParameter)5 DecimalParameter (com.ibm.cohort.cql.evaluation.parameters.DecimalParameter)5 IntegerParameter (com.ibm.cohort.cql.evaluation.parameters.IntegerParameter)5 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)5 StringParameter (com.ibm.cohort.cql.evaluation.parameters.StringParameter)5 Map (java.util.Map)5 File (java.io.File)4 List (java.util.List)4 Set (java.util.Set)4 CqlLibraryProvider (com.ibm.cohort.cql.library.CqlLibraryProvider)3 CqlToElmTranslator (com.ibm.cohort.cql.translation.CqlToElmTranslator)3 ArrayList (java.util.ArrayList)3