Search in sources :

Example 16 with CqlVersionedIdentifier

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

the class CqlEvaluatorIntegrationTest method testConditionClinicalStatusActiveIsMatched.

@Test
public void testConditionClinicalStatusActiveIsMatched() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    Condition condition = new Condition();
    condition.setId("condition");
    condition.setSubject(new Reference("Patient/123"));
    condition.setClinicalStatus(new CodeableConcept().addCoding(new Coding().setCode("active").setSystem("http://terminology.hl7.org/CodeSystem/condition-clinical")).setText("Active"));
    mockFhirResourceRetrieval("/Condition?subject=Patient%2F123&_format=json", condition);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    CqlEvaluator evaluator = setupTestFor(patient, fhirConfig, "cql.condition", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
    String expression = "HasActiveCondition";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("TestStatusActive", "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 : Condition(org.hl7.fhir.r4.model.Condition) HashMap(java.util.HashMap) Reference(org.hl7.fhir.r4.model.Reference) Patient(org.hl7.fhir.r4.model.Patient) CqlEvaluationResult(com.ibm.cohort.cql.evaluation.CqlEvaluationResult) Coding(org.hl7.fhir.r4.model.Coding) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) Test(org.junit.Test)

Example 17 with CqlVersionedIdentifier

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

the class CqlEvaluatorIntegrationTest method runUnsupportedValueSetPropertyTest.

private void runUnsupportedValueSetPropertyTest(String expression) throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1983-12-02");
    Condition condition = new Condition();
    condition.setId("Condition");
    condition.setSubject(new Reference(patient));
    condition.getCode().addCoding().setSystem("SNOMED-CT").setCode("1234");
    // This stub works for [Condition] c where c.code in "ValueSet"
    mockFhirResourceRetrieval("/Condition?subject=Patient%2F123&_format=json", condition);
    CqlEvaluator evaluator = setupTestFor(patient, "cql.valueset", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
    CqlException ex = assertThrows("Missing expected exception", CqlException.class, () -> {
        evaluator.evaluate(new CqlVersionedIdentifier("TestUnsupported", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
    });
    assertTrue("Unexpected exception message: " + ex.getMessage(), ex.getMessage().contains("version and code system bindings are not supported at this time"));
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) Reference(org.hl7.fhir.r4.model.Reference) Patient(org.hl7.fhir.r4.model.Patient) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) CqlException(org.opencds.cqf.cql.engine.exception.CqlException) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier)

Example 18 with CqlVersionedIdentifier

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

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

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

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