Search in sources :

Example 21 with CqlEvaluator

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

the class CqlEvaluatorIntegrationTest method testUOMEquivalence_demonstrateConversionOnOneSide.

@Test
public void testUOMEquivalence_demonstrateConversionOnOneSide() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1983-12-02");
    CqlEvaluator evaluator = setupTestFor(patient, "cql.uomequivalence");
    String expression = "AreEquivalent";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("TestUOMCompare", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
    Map<String, Object> expected = new HashMap<>();
    // you can use the *convert* function to change the
    // units of a quantity to a known value
    expected.put(expression, true);
    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 22 with CqlEvaluator

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

the class CqlEvaluatorIntegrationTest method testMissingRequiredCQLParameterNoneSpecified.

@Test
public void testMissingRequiredCQLParameterNoneSpecified() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1978-05-06");
    CqlEvaluator evaluator = setupTestFor(patient, "cql.parameters");
    String expression = "Female";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("TestWithParams", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
    Map<String, Object> expected = new HashMap<>();
    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 23 with CqlEvaluator

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

the class CqlEvaluatorIntegrationTest method testIncorrectLibraryVersionSpecified.

@Test(expected = IllegalArgumentException.class)
public void testIncorrectLibraryVersionSpecified() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.MALE, null);
    CqlEvaluator evaluator = setupTestFor(patient, "cql.basic");
    String expression = "Female";
    evaluator.evaluate(new CqlVersionedIdentifier("Test", "bad-version"), null, newPatientContext("123"), Collections.singleton(expression));
}
Also used : Patient(org.hl7.fhir.r4.model.Patient) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) Test(org.junit.Test)

Example 24 with CqlEvaluator

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

the class CqlEvaluatorIntegrationTest method testIntervalStartsInterval.

@Test
public /**
 * This test exists to validate the the engine correctly evaluates CQL
 * that includes an "interval starts interval" expression. This was
 * called out because the CQL Author's Guide documentation mentioned
 * "interval begins interval" as a supported feature and "begins"
 * isn't the correct operator name.
 *
 * @throws Exception on any error.
 */
void testIntervalStartsInterval() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1983-12-02");
    CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal");
    String expression = "LHS Starts RHS";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("IntervalStartsInterval", "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) 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 25 with CqlEvaluator

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

the class CqlEvaluatorIntegrationTest method testPatientIsFemaleTrue.

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

Aggregations

CqlEvaluator (com.ibm.cohort.cql.evaluation.CqlEvaluator)34 CqlVersionedIdentifier (com.ibm.cohort.cql.library.CqlVersionedIdentifier)31 Patient (org.hl7.fhir.r4.model.Patient)29 Test (org.junit.Test)29 CqlEvaluationResult (com.ibm.cohort.cql.evaluation.CqlEvaluationResult)28 HashMap (java.util.HashMap)26 FhirServerConfig (com.ibm.cohort.fhir.client.config.FhirServerConfig)14 Date (java.util.Date)7 CqlDataProvider (com.ibm.cohort.cql.data.CqlDataProvider)5 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)5 Observation (org.hl7.fhir.r4.model.Observation)5 DatetimeParameter (com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter)4 IntegerParameter (com.ibm.cohort.cql.evaluation.parameters.IntegerParameter)4 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)4 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)4 List (java.util.List)4 Condition (org.hl7.fhir.r4.model.Condition)4 Reference (org.hl7.fhir.r4.model.Reference)4 ClasspathCqlLibraryProvider (com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider)3 CqlLibraryProvider (com.ibm.cohort.cql.library.CqlLibraryProvider)3