Search in sources :

Example 31 with Expression

use of org.hl7.fhir.r5.model.Expression 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)

Example 32 with Expression

use of org.hl7.fhir.r5.model.Expression in project quality-measure-and-cohort-service by Alvearie.

the class CqlTemporalTests method anEventDoesFollow.

@Test
public void anEventDoesFollow() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    mockFhirResourceRetrieval("/Encounter?subject=Patient%2F123&_format=json", getFhirParser(), ENCOUNTER_1, 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, false);
    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 33 with Expression

use of org.hl7.fhir.r5.model.Expression in project quality-measure-and-cohort-service by Alvearie.

the class PathCaptureContext method reportProperty.

public void reportProperty(Property elm) {
    // Log guarding to prevent some of the parameter resolution logic from getting called unnecessarily
    if (LOG.isTraceEnabled()) {
        LOG.trace("Property {} source {}", elm.getPath(), elm.getSource() != null ? elm.getSource().getClass().getSimpleName() : null);
    }
    Set<QName> modelTypeNames = null;
    if (elm.getScope() != null || elm.getSource() instanceof AliasRef) {
        String aliasName = (elm.getScope() != null) ? elm.getScope() : ((AliasRef) elm.getSource()).getName();
        QueryAliasContext aliasContext = getCurrentQueryContext().resolveAlias(aliasName);
        if (aliasContext == null) {
            aliasContext = getCurrentExpressionContext().resolveAlias(aliasName);
        }
        modelTypeNames = ElmUtils.getModelTypeNames(aliasContext.getAliasedQuerySource().getExpression());
    } else if (elm.getSource() instanceof QueryLetRef) {
        String letName = ((QueryLetRef) elm.getSource()).getName();
        QueryLetContext letContext = getCurrentQueryContext().resolveLet(letName);
        if (letContext == null) {
            letContext = getCurrentExpressionContext().resolveLet(letName);
        }
        modelTypeNames = ElmUtils.getModelTypeNames(letContext.getLetClause().getExpression());
    } else {
        // There are times when the scope is null. I've noticed this particularly when referencing properties
        // of another expression result
        modelTypeNames = ElmUtils.getModelTypeNames(elm.getSource());
    }
    LOG.trace("ModelTypeNames {}", modelTypeNames);
    if (modelTypeNames != null) {
        for (QName qname : modelTypeNames) {
            pathsByQName.computeIfAbsent(qname, key -> new HashSet<>()).add(elm.getPath());
        }
    }
}
Also used : Property(org.hl7.elm.r1.Property) Logger(org.slf4j.Logger) VersionedIdentifier(org.hl7.elm.r1.VersionedIdentifier) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) UsingDef(org.hl7.elm.r1.UsingDef) HashMap(java.util.HashMap) Deque(java.util.Deque) HashSet(java.util.HashSet) AliasRef(org.hl7.elm.r1.AliasRef) Retrieve(org.hl7.elm.r1.Retrieve) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) QueryLetRef(org.hl7.elm.r1.QueryLetRef) QName(javax.xml.namespace.QName) ArrayDeque(java.util.ArrayDeque) ByColumn(org.hl7.elm.r1.ByColumn) ExpressionDef(org.hl7.elm.r1.ExpressionDef) AliasRef(org.hl7.elm.r1.AliasRef) QName(javax.xml.namespace.QName) QueryLetRef(org.hl7.elm.r1.QueryLetRef) HashSet(java.util.HashSet)

Example 34 with Expression

use of org.hl7.fhir.r5.model.Expression in project org.hl7.fhir.core by hapifhir.

the class Expression50Test method testAdvisorExpressionConversion50_10.

@Test
@DisplayName("Test Advisor is used in Expression R5 -> DSTU3 conversion.")
public void testAdvisorExpressionConversion50_10() throws IOException {
    InputStream r5_stream = this.getClass().getResourceAsStream("/questionnaire_with_expression_50.json");
    org.hl7.fhir.r5.model.Questionnaire r5_input = (org.hl7.fhir.r5.model.Questionnaire) new org.hl7.fhir.r5.formats.JsonParser().parse(r5_stream);
    InputStream r2_stream = this.getClass().getResourceAsStream("/questionnaire_with_converted_expression_40_10.json");
    org.hl7.fhir.dstu2.model.Questionnaire r2_expected_output = (org.hl7.fhir.dstu2.model.Questionnaire) new org.hl7.fhir.dstu2.formats.JsonParser().parse(r2_stream);
    org.hl7.fhir.dstu2.model.Questionnaire convertedDstu2Questionnaire = (org.hl7.fhir.dstu2.model.Questionnaire) VersionConvertorFactory_10_50.convertResource(r5_input, new ExpressionAdvisor50());
    org.hl7.fhir.dstu2.formats.JsonParser dstu2_parser = new org.hl7.fhir.dstu2.formats.JsonParser();
    String composeString1 = dstu2_parser.composeString(convertedDstu2Questionnaire);
    String composeString2 = dstu2_parser.composeString(r2_expected_output);
    System.out.println("Expected out ->\n" + composeString2 + "\n\nActual out ->\n" + composeString1);
    Assertions.assertTrue(r2_expected_output.equalsDeep(convertedDstu2Questionnaire));
}
Also used : ExpressionAdvisor50(org.hl7.fhir.convertors.advisors.support.ExpressionAdvisor50) InputStream(java.io.InputStream) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 35 with Expression

use of org.hl7.fhir.r5.model.Expression in project org.hl7.fhir.core by hapifhir.

the class ExpressionAdvisor50 method handleExtension.

public void handleExtension(@Nonnull String path, @Nonnull org.hl7.fhir.r5.model.Extension src, @Nonnull org.hl7.fhir.dstu2.model.Extension tgt) {
    if (src.getValue() instanceof org.hl7.fhir.r5.model.Expression) {
        StringType type = new StringType();
        if (src.getValue() == null) {
            throw new NullPointerException("null cannot be cast to non-null type org.hl7.fhir.r5.model.Expression");
        } else {
            type.setValueAsString(((Expression) src.getValue()).getExpression());
            tgt.setValue(type);
            if (src.hasUrlElement()) {
                tgt.setUrlElement(Uri10_50.convertUri(src.getUrlElement()));
            }
        }
    } else {
        throw new FHIRException("Unknown extension type passed in to custom convertor method.");
    }
}
Also used : Expression(org.hl7.fhir.r5.model.Expression) StringType(org.hl7.fhir.dstu2.model.StringType) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

HashMap (java.util.HashMap)33 Test (org.junit.Test)30 Test (org.junit.jupiter.api.Test)30 Patient (org.hl7.fhir.r4.model.Patient)29 CqlEvaluator (com.ibm.cohort.cql.evaluation.CqlEvaluator)28 CqlVersionedIdentifier (com.ibm.cohort.cql.library.CqlVersionedIdentifier)28 ArrayList (java.util.ArrayList)27 Expression (org.hl7.elm.r1.Expression)26 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)25 CqlEvaluationResult (com.ibm.cohort.cql.evaluation.CqlEvaluationResult)24 FHIRException (org.hl7.fhir.exceptions.FHIRException)19 FhirServerConfig (com.ibm.cohort.fhir.client.config.FhirServerConfig)16 Coding (org.hl7.fhir.r4.model.Coding)15 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)14 Row (org.apache.spark.sql.Row)12 List (java.util.List)11 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)11 FhirPath (au.csiro.pathling.fhirpath.FhirPath)10 Nonnull (javax.annotation.Nonnull)10 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)9