Search in sources :

Example 6 with CqlToElmTranslator

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

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

the class MapCqlLibraryProviderZipIntegrationTest method testLibraryFoundInZipWithSearchPathsMissingError.

@Test(expected = IllegalArgumentException.class)
public void testLibraryFoundInZipWithSearchPathsMissingError() throws Exception {
    MapCqlLibraryProviderFactory factory = new MapCqlLibraryProviderFactory();
    CqlLibraryProvider provider = factory.fromZipFile(Paths.get("src/test/resources/cql/zip-structured/col_colorectal_cancer_screening_v1_0_0.zip"), "deploypackage");
    CqlLibraryProvider fhirClasspathProvider = new ClasspathCqlLibraryProvider();
    provider = new PriorityCqlLibraryProvider(provider, fhirClasspathProvider);
    CqlToElmTranslator translator = new CqlToElmTranslator();
    provider = new TranslatingCqlLibraryProvider(provider, translator, false);
    LibraryLoader libraryLoader = new ProviderBasedLibraryLoader(provider);
    VersionedIdentifier id = new VersionedIdentifier().withId("COL_InitialPop").withVersion("1.0.0");
    libraryLoader.load(id);
}
Also used : VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) LibraryLoader(org.opencds.cqf.cql.engine.execution.LibraryLoader) Test(org.junit.Test)

Example 8 with CqlToElmTranslator

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

the class MapCqlLibraryProviderZipIntegrationTest method testLibraryFoundInZipWithSearchPathsSuccess.

@Test
public void testLibraryFoundInZipWithSearchPathsSuccess() throws Exception {
    MapCqlLibraryProviderFactory factory = new MapCqlLibraryProviderFactory();
    CqlLibraryProvider provider = factory.fromZipFile(Paths.get("src/test/resources/cql/zip-structured/col_colorectal_cancer_screening_v1_0_0.zip"), "CDSexport");
    CqlLibraryProvider fhirClasspathProvider = new ClasspathCqlLibraryProvider();
    provider = new PriorityCqlLibraryProvider(provider, fhirClasspathProvider);
    CqlToElmTranslator translator = new CqlToElmTranslator();
    provider = new TranslatingCqlLibraryProvider(provider, translator, false);
    LibraryLoader libraryLoader = new ProviderBasedLibraryLoader(provider);
    VersionedIdentifier id = new VersionedIdentifier().withId("COL_InitialPop").withVersion("1.0.0");
    Library library = libraryLoader.load(id);
    Assert.assertEquals("COL_InitialPop", library.getIdentifier().getId());
}
Also used : VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) Library(org.cqframework.cql.elm.execution.Library) LibraryLoader(org.opencds.cqf.cql.engine.execution.LibraryLoader) Test(org.junit.Test)

Example 9 with CqlToElmTranslator

use of com.ibm.cohort.cql.translation.CqlToElmTranslator 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 CqlToElmTranslator

use of com.ibm.cohort.cql.translation.CqlToElmTranslator 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

CqlToElmTranslator (com.ibm.cohort.cql.translation.CqlToElmTranslator)22 TranslatingCqlLibraryProvider (com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider)18 CqlLibraryProvider (com.ibm.cohort.cql.library.CqlLibraryProvider)14 ClasspathCqlLibraryProvider (com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider)13 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 CqlDataProvider (com.ibm.cohort.cql.data.CqlDataProvider)9 CqlTerminologyProvider (com.ibm.cohort.cql.terminology.CqlTerminologyProvider)9 PriorityCqlLibraryProvider (com.ibm.cohort.cql.library.PriorityCqlLibraryProvider)7 CqlLibraryDescriptor (com.ibm.cohort.cql.library.CqlLibraryDescriptor)6 Set (java.util.Set)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 File (java.io.File)5 CqlEvaluationRequests (com.ibm.cohort.cql.evaluation.CqlEvaluationRequests)4 CqlEvaluator (com.ibm.cohort.cql.evaluation.CqlEvaluator)4 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)4 CqlLibrary (com.ibm.cohort.cql.library.CqlLibrary)4 VersionedIdentifier (org.cqframework.cql.elm.execution.VersionedIdentifier)4 LibraryLoader (org.opencds.cqf.cql.engine.execution.LibraryLoader)4 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)3