use of com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider in project quality-measure-and-cohort-service by Alvearie.
the class CqlTranslationIntegrationTest method singleFile_withOptions__translatedSuccessfully.
@Test
public void singleFile_withOptions__translatedSuccessfully() {
CqlLibraryProvider backingLibraryProvider = new ClasspathCqlLibraryProvider("cql.basic");
CqlToElmTranslator translator = new CqlToElmTranslator();
Path modelInfo = Paths.get("src/test/resources/modelinfo/ig-with-target-modelinfo-0.0.1.xml");
translator.registerModelInfo(modelInfo.toFile());
CqlLibraryProvider translatingLibraryProvider = new TranslatingCqlLibraryProvider(backingLibraryProvider, translator, true);
LibraryLoader libraryLoader = new ProviderBasedLibraryLoader(translatingLibraryProvider);
VersionedIdentifier identifier = new VersionedIdentifier().withId("Test").withVersion("1.0.0");
Library library = libraryLoader.load(identifier);
Assert.assertEquals(identifier, library.getIdentifier());
Assert.assertEquals(2, library.getAnnotation().size());
Assert.assertEquals(4, library.getStatements().getDef().size());
}
use of com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider 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.ClasspathCqlLibraryProvider in project quality-measure-and-cohort-service by Alvearie.
the class DataRowDataProviderTest method testEvaluateSuccess.
@Test
public void testEvaluateSuccess() throws Exception {
CqlLibraryProvider backingProvider = new ClasspathCqlLibraryProvider("cql");
CqlToElmTranslator translator = new CqlToElmTranslator();
try (Reader r = new FileReader(new File("src/test/resources/modelinfo/mock-modelinfo-1.0.0.xml"))) {
translator.registerModelInfo(r);
}
CqlLibraryProvider libraryProvider = new TranslatingCqlLibraryProvider(backingProvider, translator);
CqlVersionedIdentifier topLevelLibraryIdentifier = new CqlVersionedIdentifier("SampleLibrary", "1.0.0");
CqlTerminologyProvider terminologyProvider = new UnsupportedTerminologyProvider();
Map<String, Object> row = new HashMap<>();
row.put("id", "123");
row.put("gender", "female");
row.put("birthDate", new DateTime(OffsetDateTime.now()));
Map<String, Iterable<Object>> data = new HashMap<>();
data.put("Patient", Arrays.asList(new SimpleDataRow(row)));
DataRowRetrieveProvider retrieveProvider = new DataRowRetrieveProvider(data, terminologyProvider);
CqlDataProvider dataProvider = new CompositeCqlDataProvider(new DataRowModelResolver(SimpleDataRow.class), retrieveProvider);
CqlEvaluator evaluator = new CqlEvaluator().setLibraryProvider(libraryProvider).setTerminologyProvider(terminologyProvider).setDataProvider(dataProvider).setCacheContexts(false);
CqlEvaluationResult result = evaluator.evaluate(topLevelLibraryIdentifier);
assertEquals(2, result.getExpressionResults().size());
Object perDefineResult = result.getExpressionResults().get("IsFemale");
assertEquals(Boolean.TRUE, perDefineResult);
}
use of com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider in project quality-measure-and-cohort-service by Alvearie.
the class SparkSchemaCreatorTest method setup.
@Before
public void setup() {
cqlTranslator = new CqlToElmTranslator();
cqlTranslator.registerModelInfo(new File("src/test/resources/output-validation/modelinfo/simple-all-types-model-info.xml"));
CqlLibraryProvider backingProvider = new ClasspathCqlLibraryProvider("output-validation.cql");
cqlLibraryProvider = new TranslatingCqlLibraryProvider(backingProvider, cqlTranslator);
outputColumnNameFactory = new DefaultSparkOutputColumnEncoder(".");
}
use of com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider in project quality-measure-and-cohort-service by Alvearie.
the class ColumnRuleCreatorTest method testGetFiltersForContextOnlyJoinColumns.
@Test
public void testGetFiltersForContextOnlyJoinColumns() throws Exception {
CqlToElmTranslator cqlTranslator = new CqlToElmTranslator();
cqlTranslator.registerModelInfo(new File("src/test/resources/alltypes/modelinfo/alltypes-modelinfo-1.0.0.xml"));
ObjectMapper mapper = new ObjectMapper();
CqlEvaluationRequests requests = mapper.readValue(new File("src/test/resources/alltypes/metadata/join-only.json"), CqlEvaluationRequests.class);
CqlLibraryProvider backingProvider = new ClasspathCqlLibraryProvider("alltypes.cql");
TranslatingCqlLibraryProvider cqlLibraryProvider = new TranslatingCqlLibraryProvider(backingProvider, cqlTranslator);
ColumnRuleCreator columnRuleCreator = new ColumnRuleCreator(requests.getEvaluations(), cqlTranslator, cqlLibraryProvider);
ContextDefinitions definitions = mapper.readValue(new File("src/test/resources/alltypes/metadata/context-definitions-related-column.json"), ContextDefinitions.class);
ContextDefinition context = definitions.getContextDefinitionByName("Patient");
Map<String, Set<StringMatcher>> actual = columnRuleCreator.getDataRequirementsForContext(context);
Map<String, Set<StringMatcher>> expected = new HashMap<>();
expected.put("A", new HashSet<>(Arrays.asList(new EqualsStringMatcher(ContextRetriever.SOURCE_FACT_IDX), new EqualsStringMatcher("id_col"), new EqualsStringMatcher("pat_id"))));
expected.put("B", new HashSet<>(Arrays.asList(new EqualsStringMatcher(ContextRetriever.SOURCE_FACT_IDX), new EqualsStringMatcher("string"), new EqualsStringMatcher(ContextRetriever.JOIN_CONTEXT_VALUE_IDX))));
expected.put("C", new HashSet<>(Arrays.asList(new EqualsStringMatcher(ContextRetriever.SOURCE_FACT_IDX), new EqualsStringMatcher("pat_id"), new EqualsStringMatcher(ContextRetriever.JOIN_CONTEXT_VALUE_IDX))));
assertEquals(expected, actual);
}
Aggregations