Search in sources :

Example 6 with ClasspathCqlLibraryProvider

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());
}
Also used : Path(java.nio.file.Path) VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) ProviderBasedLibraryLoader(com.ibm.cohort.cql.library.ProviderBasedLibraryLoader) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) Library(org.cqframework.cql.elm.execution.Library) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) LibraryLoader(org.opencds.cqf.cql.engine.execution.LibraryLoader) ProviderBasedLibraryLoader(com.ibm.cohort.cql.library.ProviderBasedLibraryLoader) Test(org.junit.Test)

Example 7 with ClasspathCqlLibraryProvider

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"));
}
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 8 with ClasspathCqlLibraryProvider

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);
}
Also used : UnsupportedTerminologyProvider(com.ibm.cohort.cql.terminology.UnsupportedTerminologyProvider) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) HashMap(java.util.HashMap) Reader(java.io.Reader) FileReader(java.io.FileReader) CompositeCqlDataProvider(com.ibm.cohort.cql.data.CompositeCqlDataProvider) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) CqlEvaluationResult(com.ibm.cohort.cql.evaluation.CqlEvaluationResult) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) OffsetDateTime(java.time.OffsetDateTime) DateTime(org.opencds.cqf.cql.engine.runtime.DateTime) SimpleDataRow(com.ibm.cohort.datarow.model.SimpleDataRow) FileReader(java.io.FileReader) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlTerminologyProvider(com.ibm.cohort.cql.terminology.CqlTerminologyProvider) File(java.io.File) CqlDataProvider(com.ibm.cohort.cql.data.CqlDataProvider) CompositeCqlDataProvider(com.ibm.cohort.cql.data.CompositeCqlDataProvider) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) Test(org.junit.Test)

Example 9 with ClasspathCqlLibraryProvider

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(".");
}
Also used : TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) File(java.io.File) Before(org.junit.Before)

Example 10 with ClasspathCqlLibraryProvider

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);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) HashMap(java.util.HashMap) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) EqualsStringMatcher(com.ibm.cohort.cql.util.EqualsStringMatcher) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ClasspathCqlLibraryProvider (com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider)16 CqlLibraryProvider (com.ibm.cohort.cql.library.CqlLibraryProvider)14 TranslatingCqlLibraryProvider (com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider)11 CqlToElmTranslator (com.ibm.cohort.cql.translation.CqlToElmTranslator)10 Test (org.junit.Test)9 PriorityCqlLibraryProvider (com.ibm.cohort.cql.library.PriorityCqlLibraryProvider)6 File (java.io.File)6 HashMap (java.util.HashMap)6 CqlTerminologyProvider (com.ibm.cohort.cql.terminology.CqlTerminologyProvider)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 CqlDataProvider (com.ibm.cohort.cql.data.CqlDataProvider)4 CqlLibrary (com.ibm.cohort.cql.library.CqlLibrary)4 CqlLibraryDescriptor (com.ibm.cohort.cql.library.CqlLibraryDescriptor)4 MapCqlLibraryProviderFactory (com.ibm.cohort.cql.library.MapCqlLibraryProviderFactory)4 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)3 CqlEvaluationRequests (com.ibm.cohort.cql.evaluation.CqlEvaluationRequests)3 CqlEvaluator (com.ibm.cohort.cql.evaluation.CqlEvaluator)3 CqlVersionedIdentifier (com.ibm.cohort.cql.library.CqlVersionedIdentifier)3 EqualsStringMatcher (com.ibm.cohort.cql.util.EqualsStringMatcher)3 R4RestFhirTerminologyProvider (com.ibm.cohort.engine.terminology.R4RestFhirTerminologyProvider)3