Search in sources :

Example 11 with CqlLibraryDescriptor

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

the class TranslatingCqlLibraryProviderTest method testLoadWithTranslation.

@Test
public void testLoadWithTranslation() throws Exception {
    CqlToElmTranslator translator = new CqlToElmTranslator();
    try (Reader modelInfoXML = new FileReader("src/test/resources/modelinfo/mock-modelinfo-1.0.0.xml")) {
        translator.registerModelInfo(modelInfoXML);
    }
    CqlLibraryProvider backingProvider = new ClasspathCqlLibraryProvider("cql");
    CqlLibraryProvider provider = new TranslatingCqlLibraryProvider(backingProvider, translator);
    CqlLibraryDescriptor descriptor = new CqlLibraryDescriptor().setLibraryId("CohortHelpers").setVersion("1.0.0").setFormat(Format.CQL);
    CqlLibrary library = provider.getLibrary(descriptor);
    assertEquals(Format.CQL, library.getDescriptor().getFormat());
    assertTrue(library.getContent().startsWith("library"));
    descriptor.setFormat(Format.ELM);
    library = provider.getLibrary(descriptor);
    assertEquals(Format.ELM, library.getDescriptor().getFormat());
    assertTrue(library.getContent().startsWith("<?xml"));
}
Also used : CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) FileReader(java.io.FileReader) Reader(java.io.Reader) FileReader(java.io.FileReader) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) Test(org.junit.Test)

Example 12 with CqlLibraryDescriptor

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

the class ContextColumnNameEncoderTest method testMultipleRequestsColumnNames.

@Test
public void testMultipleRequestsColumnNames() {
    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)));
    ContextColumnNameEncoder contextColumnNameEncoder = ContextColumnNameEncoder.create(Arrays.asList(request, request2), "|");
    assertEquals("lib1|abcd", contextColumnNameEncoder.getColumnName(request, "abcd"));
    assertEquals("A2", contextColumnNameEncoder.getColumnName(request, "efgh"));
    assertEquals("A3", contextColumnNameEncoder.getColumnName(request2, "ijkl"));
    assertEquals("lib2|mnop", contextColumnNameEncoder.getColumnName(request2, "mnop"));
}
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 CqlLibraryDescriptor

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

the class ContextColumnNameEncoderTest method testOneDefineDefaultNaming.

@Test
public void testOneDefineDefaultNaming() {
    CqlLibraryDescriptor libraryDescriptor = new CqlLibraryDescriptor();
    libraryDescriptor.setLibraryId("lib1");
    CqlEvaluationRequest request = new CqlEvaluationRequest();
    request.setExpressionsByNames(new HashSet<>(Collections.singletonList("abcd")));
    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");
        }
    };
    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 14 with CqlLibraryDescriptor

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

the class SparkSchemaCreatorTest method testInvalidKeyColumn.

@Test(expected = IllegalArgumentException.class)
public void testInvalidKeyColumn() throws Exception {
    ContextDefinitions contextDefinitions = makeContextDefinitions(Arrays.asList(makeContextDefinition("Context1Id", "Type1", "other")));
    CqlEvaluationRequests cqlEvaluationRequests = makeEvaluationRequests(Arrays.asList(makeEvaluationRequest(new CqlLibraryDescriptor().setLibraryId("Context1Id").setVersion("1.0.0"), new HashSet<>(Collections.singletonList("define_boolean")), "Context1Id")));
    SparkSchemaCreator schemaCreator = new SparkSchemaCreator(cqlLibraryProvider, cqlEvaluationRequests, contextDefinitions, outputColumnNameFactory, cqlTranslator);
    schemaCreator.calculateSchemasForContexts(Arrays.asList("Context1Id"));
}
Also used : ContextDefinitions(com.ibm.cohort.cql.spark.aggregation.ContextDefinitions) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) Test(org.junit.Test)

Example 15 with CqlLibraryDescriptor

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

the class SparkSchemaCreatorTest method singleContextSupportedDefineTypes.

@Test
public void singleContextSupportedDefineTypes() throws Exception {
    ContextDefinitions contextDefinitions = makeContextDefinitions(Collections.singletonList(makeContextDefinition("A", "Type1", "id")));
    CqlEvaluationRequests cqlEvaluationRequests = makeEvaluationRequests(Arrays.asList(makeEvaluationRequest(new CqlLibraryDescriptor().setLibraryId("Context1Id").setVersion("1.0.0"), new HashSet<>(Arrays.asList("define_integer", "define_boolean", "define_string", "define_decimal")), "A"), makeEvaluationRequest(new CqlLibraryDescriptor().setLibraryId("Context2Id").setVersion("1.0.0"), new HashSet<>(Arrays.asList("define_date", "define_datetime")), "A")));
    SparkSchemaCreator schemaCreator = new SparkSchemaCreator(cqlLibraryProvider, cqlEvaluationRequests, contextDefinitions, outputColumnNameFactory, cqlTranslator);
    StructType actualSchema = schemaCreator.calculateSchemasForContexts(Arrays.asList("A")).get("A");
    StructType expectedSchema = new StructType().add("id", DataTypes.IntegerType, false).add("parameters", DataTypes.StringType, false).add("Context1Id.define_integer", DataTypes.IntegerType, true).add("Context1Id.define_boolean", DataTypes.BooleanType, true).add("Context1Id.define_string", DataTypes.StringType, true).add("Context1Id.define_decimal", DataTypes.createDecimalType(28, 8), true).add("Context2Id.define_date", DataTypes.DateType, true).add("Context2Id.define_datetime", DataTypes.TimestampType, true);
    validateSchemas(expectedSchema, actualSchema, "id");
}
Also used : ContextDefinitions(com.ibm.cohort.cql.spark.aggregation.ContextDefinitions) StructType(org.apache.spark.sql.types.StructType) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) Test(org.junit.Test)

Aggregations

CqlLibraryDescriptor (com.ibm.cohort.cql.library.CqlLibraryDescriptor)50 Test (org.junit.Test)34 CqlEvaluationRequest (com.ibm.cohort.cql.evaluation.CqlEvaluationRequest)19 CqlEvaluationRequests (com.ibm.cohort.cql.evaluation.CqlEvaluationRequests)18 CqlLibrary (com.ibm.cohort.cql.library.CqlLibrary)17 HashMap (java.util.HashMap)17 CqlExpressionConfiguration (com.ibm.cohort.cql.evaluation.CqlExpressionConfiguration)14 CqlLibraryProvider (com.ibm.cohort.cql.library.CqlLibraryProvider)14 ContextDefinitions (com.ibm.cohort.cql.spark.aggregation.ContextDefinitions)10 ClasspathCqlLibraryProvider (com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider)9 CqlToElmTranslator (com.ibm.cohort.cql.translation.CqlToElmTranslator)8 File (java.io.File)8 IntegerParameter (com.ibm.cohort.cql.evaluation.parameters.IntegerParameter)7 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)7 DecimalParameter (com.ibm.cohort.cql.evaluation.parameters.DecimalParameter)5 StringParameter (com.ibm.cohort.cql.evaluation.parameters.StringParameter)5 Format (com.ibm.cohort.cql.library.Format)5 TranslatingCqlLibraryProvider (com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 CqlDataProvider (com.ibm.cohort.cql.data.CqlDataProvider)4