Search in sources :

Example 31 with CqlVersionedIdentifier

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

the class CqlTemporalTests method determineIfAnEventFollows.

@Test
public void determineIfAnEventFollows() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    mockFhirResourceRetrieval("/Encounter?subject=Patient%2F123&_format=json", getFhirParser(), ENCOUNTER_3, fhirConfig);
    mockFhirResourceRetrieval("/Condition?subject=Patient%2F123&_format=json", getFhirParser(), CONDITION_IN, fhirConfig);
    CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
    String expression = "NotFollowedByCondition";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test4", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
    Map<String, Object> expected = new HashMap<>();
    expected.put(expression, true);
    Assert.assertEquals(expected, actual.getExpressionResults());
}
Also used : HashMap(java.util.HashMap) Patient(org.hl7.fhir.r4.model.Patient) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) CqlEvaluationResult(com.ibm.cohort.cql.evaluation.CqlEvaluationResult) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) Test(org.junit.Test)

Example 32 with CqlVersionedIdentifier

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

the class CqlContextFactoryTest method testContextCacheKeyEquals.

@Test
public void testContextCacheKeyEquals() {
    CqlLibraryProvider libraryProvider = mock(CqlLibraryProvider.class);
    CqlTerminologyProvider terminologyProvider = mock(CqlTerminologyProvider.class);
    CqlVersionedIdentifier topLevelLibraryIdentifier = new CqlVersionedIdentifier("Test", "1.0.0");
    Map<String, Parameter> parameters = new HashMap<>();
    ZonedDateTime evaluationDateTime = ZonedDateTime.now();
    CqlContextFactory.ContextCacheKey k1 = new CqlContextFactory.ContextCacheKey(libraryProvider, topLevelLibraryIdentifier, terminologyProvider, null, evaluationDateTime, parameters);
    assertEquals(k1, k1);
    CqlContextFactory.ContextCacheKey k2 = new CqlContextFactory.ContextCacheKey(libraryProvider, topLevelLibraryIdentifier, terminologyProvider, null, evaluationDateTime, parameters);
    assertEquals(k1, k2);
    Map<ContextCacheKey, String> map = new HashMap<>();
    map.put(k1, "Hello,World");
    assertEquals("Hello,World", map.get(k2));
}
Also used : HashMap(java.util.HashMap) 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) ContextCacheKey(com.ibm.cohort.cql.evaluation.CqlContextFactory.ContextCacheKey) PriorityCqlLibraryProvider(com.ibm.cohort.cql.library.PriorityCqlLibraryProvider) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlLibraryProvider(com.ibm.cohort.cql.library.CqlLibraryProvider) CqlTerminologyProvider(com.ibm.cohort.cql.terminology.CqlTerminologyProvider) ContextCacheKey(com.ibm.cohort.cql.evaluation.CqlContextFactory.ContextCacheKey) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) Test(org.junit.Test)

Example 33 with CqlVersionedIdentifier

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

Aggregations

CqlVersionedIdentifier (com.ibm.cohort.cql.library.CqlVersionedIdentifier)33 CqlEvaluator (com.ibm.cohort.cql.evaluation.CqlEvaluator)31 Test (org.junit.Test)31 Patient (org.hl7.fhir.r4.model.Patient)29 CqlEvaluationResult (com.ibm.cohort.cql.evaluation.CqlEvaluationResult)27 HashMap (java.util.HashMap)27 FhirServerConfig (com.ibm.cohort.fhir.client.config.FhirServerConfig)14 Date (java.util.Date)7 IntegerParameter (com.ibm.cohort.cql.evaluation.parameters.IntegerParameter)6 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)6 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)6 Observation (org.hl7.fhir.r4.model.Observation)6 DatetimeParameter (com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter)4 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)4 ClasspathCqlLibraryProvider (com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider)4 CqlTerminologyProvider (com.ibm.cohort.cql.terminology.CqlTerminologyProvider)4 TranslatingCqlLibraryProvider (com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider)4 Bundle (org.hl7.fhir.r4.model.Bundle)4 Condition (org.hl7.fhir.r4.model.Condition)4 Reference (org.hl7.fhir.r4.model.Reference)4