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"));
}
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"));
}
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);
}
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"));
}
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");
}
Aggregations