Search in sources :

Example 21 with CqlToElmTranslator

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

the class CqlContextFactoryTest method testCreateContextSuccess.

@Test
public void testCreateContextSuccess() {
    boolean expectedDebug = true;
    ZonedDateTime expectedEvaluationDateTime = ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 11, 12, 13), ZoneId.of("America/New_York"));
    PriorityCqlLibraryProvider libraryProvider = new PriorityCqlLibraryProvider(new ClasspathCqlLibraryProvider("cql", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH));
    CqlToElmTranslator translator = new CqlToElmTranslator();
    TranslatingCqlLibraryProvider translatingProvider = new TranslatingCqlLibraryProvider(libraryProvider, translator);
    CqlVersionedIdentifier topLevelLibraryIdentifier = new CqlVersionedIdentifier("MyCQL", "1.0.0");
    CqlTerminologyProvider terminologyProvider = new UnsupportedTerminologyProvider();
    CqlDataProvider dataProvider = mock(CqlDataProvider.class);
    Pair<String, String> contextData = Pair.of("Patient", "123");
    Map<String, Parameter> expectedParams = new HashMap<>();
    expectedParams.put("P1", new StringParameter("MyString"));
    expectedParams.put("P2", new IntegerParameter(10));
    CqlContextFactory cqlContextFactory = spy(CqlContextFactory.class);
    Context context = cqlContextFactory.createContext(translatingProvider, topLevelLibraryIdentifier, terminologyProvider, dataProvider, expectedEvaluationDateTime, contextData, expectedParams, expectedDebug ? CqlDebug.DEBUG : CqlDebug.NONE);
    assertEquals(expectedDebug, context.getDebugMap().getIsLoggingEnabled());
    assertEquals(expectedEvaluationDateTime.toInstant(), context.getEvaluationDateTime().getDateTime().toZonedDateTime().toInstant());
    context.enterContext(contextData.getKey());
    assertEquals(contextData.getValue(), context.getCurrentContextValue());
    assertEquals(topLevelLibraryIdentifier.getId(), context.getCurrentLibrary().getIdentifier().getId());
    assertEquals(topLevelLibraryIdentifier.getVersion(), context.getCurrentLibrary().getIdentifier().getVersion());
    for (Map.Entry<String, Parameter> entry : expectedParams.entrySet()) {
        Object actualValue = context.resolveParameterRef(null, entry.getKey());
        assertEquals(entry.getValue().toCqlType(), actualValue);
    }
    // Once more just to check that caching is working. Using a different data provider because that is
    // how we will actually use it at runtime.
    CqlDataProvider dataProvider2 = mock(CqlDataProvider.class);
    cqlContextFactory.createContext(translatingProvider, topLevelLibraryIdentifier, terminologyProvider, dataProvider2, expectedEvaluationDateTime, contextData, expectedParams, expectedDebug ? CqlDebug.DEBUG : CqlDebug.NONE);
    verify(cqlContextFactory, times(1)).createContext(any(ContextCacheKey.class));
}
Also used : Context(org.opencds.cqf.cql.engine.execution.Context) UnsupportedTerminologyProvider(com.ibm.cohort.cql.terminology.UnsupportedTerminologyProvider) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) HashMap(java.util.HashMap) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) PriorityCqlLibraryProvider(com.ibm.cohort.cql.library.PriorityCqlLibraryProvider) ZonedDateTime(java.time.ZonedDateTime) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlTerminologyProvider(com.ibm.cohort.cql.terminology.CqlTerminologyProvider) ContextCacheKey(com.ibm.cohort.cql.evaluation.CqlContextFactory.ContextCacheKey) CqlDataProvider(com.ibm.cohort.cql.data.CqlDataProvider) HashMap(java.util.HashMap) Map(java.util.Map) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) Test(org.junit.Test)

Example 22 with CqlToElmTranslator

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

the class MapCqlLibraryProviderZipIntegrationTest method testLibraryFoundInZipSuccess.

@Test
public void testLibraryFoundInZipSuccess() throws Exception {
    MapCqlLibraryProviderFactory factory = new MapCqlLibraryProviderFactory();
    CqlLibraryProvider provider = factory.fromZipFile(Paths.get("src/test/resources/cql/zip/breast_cancer_screening_v1_0_0_cql.zip"));
    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("BreastCancerScreening");
    Library library = libraryLoader.load(id);
    Assert.assertEquals("BreastCancerScreening", 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)

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