Search in sources :

Example 6 with CqlExpressionConfiguration

use of com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration 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 7 with CqlExpressionConfiguration

use of com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration 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 8 with CqlExpressionConfiguration

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

the class ConfigurableOutputColumnNameEncoderTest method testNamesForMultipleContexts.

@Test
public void testNamesForMultipleContexts() {
    CqlLibraryDescriptor libraryDescriptor1 = new CqlLibraryDescriptor();
    libraryDescriptor1.setLibraryId("lib1");
    CqlEvaluationRequest request = new CqlEvaluationRequest();
    request.setDescriptor(libraryDescriptor1);
    request.setId(1);
    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)));
    CqlLibraryDescriptor libraryDescriptor2 = new CqlLibraryDescriptor();
    libraryDescriptor2.setLibraryId("lib1");
    CqlEvaluationRequest request2 = new CqlEvaluationRequest();
    request2.setDescriptor(libraryDescriptor2);
    request2.setId(2);
    CqlExpressionConfiguration expressionConfiguration3 = new CqlExpressionConfiguration();
    expressionConfiguration3.setName("abcd");
    expressionConfiguration3.setOutputColumn("A3");
    CqlExpressionConfiguration expressionConfiguration4 = new CqlExpressionConfiguration();
    expressionConfiguration4.setName("efgh");
    expressionConfiguration4.setOutputColumn("A4");
    request2.setExpressions(new HashSet<>(Arrays.asList(expressionConfiguration3, expressionConfiguration4)));
    request.setContextKey("context1");
    request2.setContextKey("context2");
    CqlEvaluationRequests evaluationRequests = new CqlEvaluationRequests();
    evaluationRequests.setEvaluations(Arrays.asList(request, request2));
    ConfigurableOutputColumnNameEncoder nameEncoder = ConfigurableOutputColumnNameEncoder.create(evaluationRequests, "|");
    assertEquals("A1", nameEncoder.getColumnName(request, "abcd"));
    assertEquals("A2", nameEncoder.getColumnName(request, "efgh"));
    assertEquals("A3", nameEncoder.getColumnName(request2, "abcd"));
    assertEquals("A4", nameEncoder.getColumnName(request2, "efgh"));
}
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 9 with CqlExpressionConfiguration

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

the class ConfigurableOutputColumnNameEncoderTest method testOutputColumnsRepeatedAcrossContexts.

@Test
public void testOutputColumnsRepeatedAcrossContexts() {
    CqlLibraryDescriptor libraryDescriptor1 = new CqlLibraryDescriptor();
    libraryDescriptor1.setLibraryId("lib1");
    CqlEvaluationRequest request = new CqlEvaluationRequest();
    request.setDescriptor(libraryDescriptor1);
    request.setId(1);
    CqlExpressionConfiguration expressionConfiguration1 = new CqlExpressionConfiguration();
    expressionConfiguration1.setName("abcd");
    expressionConfiguration1.setOutputColumn("A1");
    request.setExpressions(new HashSet<>(Collections.singletonList(expressionConfiguration1)));
    CqlLibraryDescriptor libraryDescriptor2 = new CqlLibraryDescriptor();
    libraryDescriptor2.setLibraryId("lib2");
    CqlEvaluationRequest request2 = new CqlEvaluationRequest();
    request2.setDescriptor(libraryDescriptor2);
    request2.setId(2);
    CqlExpressionConfiguration expressionConfiguration2 = new CqlExpressionConfiguration();
    expressionConfiguration2.setName("abcd");
    expressionConfiguration2.setOutputColumn("A1");
    request2.setExpressions(new HashSet<>(Collections.singletonList(expressionConfiguration2)));
    request.setContextKey("context1");
    request2.setContextKey("context2");
    CqlEvaluationRequests evaluationRequests = new CqlEvaluationRequests();
    evaluationRequests.setEvaluations(Arrays.asList(request, request2));
    ConfigurableOutputColumnNameEncoder nameEncoder = ConfigurableOutputColumnNameEncoder.create(evaluationRequests, "|");
    assertEquals("A1", nameEncoder.getColumnName(request, "abcd"));
    assertEquals("A1", nameEncoder.getColumnName(request2, "abcd"));
}
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 10 with CqlExpressionConfiguration

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

the class ContextColumnNameEncoderTest method testMultipleRequestsSameDefineSameDefaultOutputColumn.

@Test
public void testMultipleRequestsSameDefineSameDefaultOutputColumn() {
    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);
    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);
    request2.setExpressions(new HashSet<>(Collections.singletonList(expressionConfiguration2)));
    IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> ContextColumnNameEncoder.create(Arrays.asList(request, request2), "|"));
    assertTrue(ex.getMessage().contains("Duplicate outputColumn lib1|abcd defined"));
}
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)

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