Search in sources :

Example 1 with CompositeCqlDataProvider

use of com.ibm.cohort.cql.data.CompositeCqlDataProvider 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)

Aggregations

CompositeCqlDataProvider (com.ibm.cohort.cql.data.CompositeCqlDataProvider)1 CqlDataProvider (com.ibm.cohort.cql.data.CqlDataProvider)1 CqlEvaluationResult (com.ibm.cohort.cql.evaluation.CqlEvaluationResult)1 CqlEvaluator (com.ibm.cohort.cql.evaluation.CqlEvaluator)1 ClasspathCqlLibraryProvider (com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider)1 CqlLibraryProvider (com.ibm.cohort.cql.library.CqlLibraryProvider)1 CqlVersionedIdentifier (com.ibm.cohort.cql.library.CqlVersionedIdentifier)1 CqlTerminologyProvider (com.ibm.cohort.cql.terminology.CqlTerminologyProvider)1 UnsupportedTerminologyProvider (com.ibm.cohort.cql.terminology.UnsupportedTerminologyProvider)1 CqlToElmTranslator (com.ibm.cohort.cql.translation.CqlToElmTranslator)1 TranslatingCqlLibraryProvider (com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider)1 SimpleDataRow (com.ibm.cohort.datarow.model.SimpleDataRow)1 File (java.io.File)1 FileReader (java.io.FileReader)1 Reader (java.io.Reader)1 OffsetDateTime (java.time.OffsetDateTime)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 DateTime (org.opencds.cqf.cql.engine.runtime.DateTime)1