Search in sources :

Example 81 with Expression

use of org.hl7.elm.r1.Expression in project org.hl7.fhir.core by hapifhir.

the class Expression40Test method testAdvisorExpressionConversion40_10.

@Test
@DisplayName("Test Advisor is used in Expression R4 -> DSTU3 conversion.")
public void testAdvisorExpressionConversion40_10() throws IOException {
    InputStream r4_stream = this.getClass().getResourceAsStream("/questionnaire_with_expression_40.json");
    org.hl7.fhir.r4.model.Questionnaire r4_input = (org.hl7.fhir.r4.model.Questionnaire) new org.hl7.fhir.r4.formats.JsonParser().parse(r4_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_40.convertResource(r4_input, new ExpressionAdvisor40());
    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 : InputStream(java.io.InputStream) ExpressionAdvisor40(org.hl7.fhir.convertors.advisors.support.ExpressionAdvisor40) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 82 with Expression

use of org.hl7.elm.r1.Expression in project org.hl7.fhir.core by hapifhir.

the class Expression40Test method testBaseAdvisorExpressionIgore.

@Test
@DisplayName("Ensure base advisor ignores Expression types and doesn't explode.")
public void testBaseAdvisorExpressionIgore() throws IOException {
    Expression exp = new Expression();
    exp.setExpression("x + y = z");
    Extension ext = new Extension();
    ext.setValue(exp);
    BaseAdvisor_10_40 baseAdvisor1040 = new BaseAdvisor_10_40();
    Assertions.assertTrue(baseAdvisor1040.ignoreExtension("", ext));
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Expression(org.hl7.fhir.r4.model.Expression) BaseAdvisor_10_40(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 83 with Expression

use of org.hl7.elm.r1.Expression in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeElementDefinitionElementDefinitionConstraintComponent.

protected void composeElementDefinitionElementDefinitionConstraintComponent(Complex parent, String parentType, String name, ElementDefinition.ElementDefinitionConstraintComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeElement(t, "constraint", name, element, index);
    if (element.hasKeyElement())
        composeId(t, "ElementDefinition", "key", element.getKeyElement(), -1);
    if (element.hasRequirementsElement())
        composeString(t, "ElementDefinition", "requirements", element.getRequirementsElement(), -1);
    if (element.hasSeverityElement())
        composeEnum(t, "ElementDefinition", "severity", element.getSeverityElement(), -1);
    if (element.hasHumanElement())
        composeString(t, "ElementDefinition", "human", element.getHumanElement(), -1);
    if (element.hasExpressionElement())
        composeString(t, "ElementDefinition", "expression", element.getExpressionElement(), -1);
    if (element.hasXpathElement())
        composeString(t, "ElementDefinition", "xpath", element.getXpathElement(), -1);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Example 84 with Expression

use of org.hl7.elm.r1.Expression in project org.hl7.fhir.core by hapifhir.

the class FluentPathTests method testWrong.

private void testWrong(Resource resource, String expression) throws FileNotFoundException, IOException, FHIRException {
    if (TestingUtilities.context == null)
        TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
    FHIRPathEngine fp = new FHIRPathEngine(TestingUtilities.context);
    try {
        ExpressionNode node = fp.parse(expression);
        fp.check(null, null, resource.getResourceType().toString(), node);
        fp.evaluate(null, null, resource, node);
        if (fp.hasLog())
            System.out.println(fp.takeLog());
        Assertions.fail("Fail expected");
    } catch (PathEngineException e) {
    // ok
    }
}
Also used : FHIRPathEngine(org.hl7.fhir.dstu2016may.utils.FHIRPathEngine) ExpressionNode(org.hl7.fhir.dstu2016may.model.ExpressionNode) PathEngineException(org.hl7.fhir.exceptions.PathEngineException)

Example 85 with Expression

use of org.hl7.elm.r1.Expression in project org.hl7.fhir.core by hapifhir.

the class FluentPathTests method test.

@SuppressWarnings("deprecation")
private void test(Resource resource, String expression, int count, String... types) throws FileNotFoundException, IOException, FHIRException {
    if (TestingUtilities.context == null)
        TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
    FHIRPathEngine fp = new FHIRPathEngine(TestingUtilities.context);
    ExpressionNode node = fp.parse(expression);
    fp.check(null, resource.getResourceType().toString(), resource.getResourceType().toString(), node);
    List<Base> outcome = fp.evaluate(resource, node);
    if (fp.hasLog())
        System.out.println(fp.takeLog());
    Assertions.assertTrue(outcome.size() == count, String.format("Expected %d objects but found %d", count, outcome.size()));
    CommaSeparatedStringBuilder msg = new CommaSeparatedStringBuilder();
    for (String t : types) msg.append(t);
    for (Base b : outcome) {
        boolean found = false;
        String type = b.fhirType();
        for (String t : types) if (type.equals(t))
            found = true;
        Assertions.assertTrue(found, String.format("Object type %s not ok from %s", type, msg));
    }
}
Also used : FHIRPathEngine(org.hl7.fhir.dstu2016may.utils.FHIRPathEngine) ExpressionNode(org.hl7.fhir.dstu2016may.model.ExpressionNode) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) Base(org.hl7.fhir.dstu2016may.model.Base)

Aggregations

Test (org.junit.Test)102 Expression (org.apache.commons.jexl2.Expression)98 TermWeightPosition (datawave.ingest.protobuf.TermWeightPosition)66 Zone (datawave.query.jexl.functions.TermFrequencyList.Zone)66 Test (org.junit.jupiter.api.Test)60 ArrayList (java.util.ArrayList)36 HashMap (java.util.HashMap)35 Patient (org.hl7.fhir.r4.model.Patient)29 CqlEvaluator (com.ibm.cohort.cql.evaluation.CqlEvaluator)28 CqlVersionedIdentifier (com.ibm.cohort.cql.library.CqlVersionedIdentifier)28 Expression (io.atlasmap.v2.Expression)26 JexlContext (org.apache.commons.jexl2.JexlContext)26 Expression (org.hl7.elm.r1.Expression)26 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)25 CqlEvaluationResult (com.ibm.cohort.cql.evaluation.CqlEvaluationResult)24 JexlEngine (org.apache.commons.jexl2.JexlEngine)22 MapContext (org.apache.commons.jexl2.MapContext)22 FHIRException (org.hl7.fhir.exceptions.FHIRException)19 FhirServerConfig (com.ibm.cohort.fhir.client.config.FhirServerConfig)16 Coding (org.hl7.fhir.r4.model.Coding)15