Search in sources :

Example 6 with CqlVersionedIdentifier

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

the class CqlEvaluatorIntegrationTest method testMissingRequiredCQLParameterSomeSpecified.

@Test
public void testMissingRequiredCQLParameterSomeSpecified() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1978-05-06");
    CqlEvaluator evaluator = setupTestFor(patient, "cql.parameters");
    String expression = "Female";
    Map<String, Parameter> parameters = new HashMap<>();
    parameters.put("Unused", new IntegerParameter(100));
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("TestWithParams", "1.0.0"), parameters, newPatientContext("123"), Collections.singleton(expression));
    Map<String, Object> expected = new HashMap<>();
    expected.put(expression, null);
    Assert.assertEquals(expected, actual.getExpressionResults());
}
Also used : IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) HashMap(java.util.HashMap) Patient(org.hl7.fhir.r4.model.Patient) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) 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 7 with CqlVersionedIdentifier

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

the class CqlEvaluatorIntegrationTest method testUOMEquivalence_demonstrateEqualityIssue.

/*
     * The following `testUOMEquivalence` tests are intended to document the engine behavior
     * when an author attempts to compare quantities with different UoM values.
     */
@Test
public void testUOMEquivalence_demonstrateEqualityIssue() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1983-12-02");
    CqlEvaluator evaluator = setupTestFor(patient, "cql.uomequivalence");
    String expression = "IsEqual";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("TestUOMCompare", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
    Map<String, Object> expected = new HashMap<>();
    // when you compare two quantities with different UoM, the
    // the engine returns null.
    expected.put(expression, null);
    Assert.assertEquals(expected, actual.getExpressionResults());
}
Also used : HashMap(java.util.HashMap) Patient(org.hl7.fhir.r4.model.Patient) 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 8 with CqlVersionedIdentifier

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

the class CqlEvaluatorIntegrationTest method testSimplestHTTPRequestSettings.

@Test
public void testSimplestHTTPRequestSettings() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    CqlEvaluator evaluator = setupTestFor(patient, fhirConfig, "cql.basic");
    String expression = "Female";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test", "1.0.0"), null, new ImmutablePair<>("Patient", "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 9 with CqlVersionedIdentifier

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

the class CqlTemporalTests method canFindMultipleEncountersFollowingEachOther.

@Test
public void canFindMultipleEncountersFollowingEachOther() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    Bundle bundle = new Bundle();
    Bundle.BundleEntryComponent firstEncounter = new Bundle.BundleEntryComponent();
    firstEncounter.setResource(ENCOUNTER_1);
    Bundle.BundleEntryComponent secondEncounter = new Bundle.BundleEntryComponent();
    secondEncounter.setResource(ENCOUNTER_2);
    bundle.addEntry(firstEncounter);
    bundle.addEntry(secondEncounter);
    mockFhirResourceRetrieval("/Encounter?subject=Patient%2F123&_format=json", getFhirParser(), bundle, fhirConfig);
    CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
    String expression = "ValidEncounters2";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test3", "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) Bundle(org.hl7.fhir.r4.model.Bundle) 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 10 with CqlVersionedIdentifier

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

the class CqlTemporalTests method confirmCanFindEventWithExistenceOfThirdEvent.

@Test
public void confirmCanFindEventWithExistenceOfThirdEvent() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    Observation observation = new Observation();
    DateTimeType observationEffective = new DateTimeType(new Date());
    observationEffective.setYear(2015);
    observationEffective.setMonth(0);
    observationEffective.setDay(5);
    observation.setEffective(observationEffective);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    mockFhirResourceRetrieval("/Condition?subject=Patient%2F123&_format=json", getFhirParser(), CONDITION_IN, fhirConfig);
    mockFhirResourceRetrieval("/Encounter?subject=Patient%2F123&_format=json", getFhirParser(), ENCOUNTER_1, fhirConfig);
    mockFhirResourceRetrieval("/Observation?subject=Patient%2F123&_format=json", getFhirParser(), observation, fhirConfig);
    CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
    String expression = "ObservationWithin30DaysOfCondition";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test2", "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 : DateTimeType(org.hl7.fhir.r4.model.DateTimeType) HashMap(java.util.HashMap) Observation(org.hl7.fhir.r4.model.Observation) Patient(org.hl7.fhir.r4.model.Patient) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) CqlEvaluationResult(com.ibm.cohort.cql.evaluation.CqlEvaluationResult) Date(java.util.Date) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) 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