Search in sources :

Example 46 with Expression

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

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

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

Example 49 with Expression

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

the class SearchParameter method setProperty.

@Override
public Base setProperty(String name, Base value) throws FHIRException {
    if (name.equals("url")) {
        // UriType
        this.url = castToUri(value);
    } else if (name.equals("version")) {
        // StringType
        this.version = castToString(value);
    } else if (name.equals("name")) {
        // StringType
        this.name = castToString(value);
    } else if (name.equals("status")) {
        value = new PublicationStatusEnumFactory().fromType(castToCode(value));
        // Enumeration<PublicationStatus>
        this.status = (Enumeration) value;
    } else if (name.equals("experimental")) {
        // BooleanType
        this.experimental = castToBoolean(value);
    } else if (name.equals("date")) {
        // DateTimeType
        this.date = castToDateTime(value);
    } else if (name.equals("publisher")) {
        // StringType
        this.publisher = castToString(value);
    } else if (name.equals("contact")) {
        this.getContact().add(castToContactDetail(value));
    } else if (name.equals("useContext")) {
        this.getUseContext().add(castToUsageContext(value));
    } else if (name.equals("jurisdiction")) {
        this.getJurisdiction().add(castToCodeableConcept(value));
    } else if (name.equals("purpose")) {
        // MarkdownType
        this.purpose = castToMarkdown(value);
    } else if (name.equals("code")) {
        // CodeType
        this.code = castToCode(value);
    } else if (name.equals("base")) {
        this.getBase().add(castToCode(value));
    } else if (name.equals("type")) {
        value = new SearchParamTypeEnumFactory().fromType(castToCode(value));
        // Enumeration<SearchParamType>
        this.type = (Enumeration) value;
    } else if (name.equals("derivedFrom")) {
        // UriType
        this.derivedFrom = castToUri(value);
    } else if (name.equals("description")) {
        // MarkdownType
        this.description = castToMarkdown(value);
    } else if (name.equals("expression")) {
        // StringType
        this.expression = castToString(value);
    } else if (name.equals("xpath")) {
        // StringType
        this.xpath = castToString(value);
    } else if (name.equals("xpathUsage")) {
        value = new XPathUsageTypeEnumFactory().fromType(castToCode(value));
        // Enumeration<XPathUsageType>
        this.xpathUsage = (Enumeration) value;
    } else if (name.equals("target")) {
        this.getTarget().add(castToCode(value));
    } else if (name.equals("comparator")) {
        value = new SearchComparatorEnumFactory().fromType(castToCode(value));
        this.getComparator().add((Enumeration) value);
    } else if (name.equals("modifier")) {
        value = new SearchModifierCodeEnumFactory().fromType(castToCode(value));
        this.getModifier().add((Enumeration) value);
    } else if (name.equals("chain")) {
        this.getChain().add(castToString(value));
    } else if (name.equals("component")) {
        this.getComponent().add((SearchParameterComponentComponent) value);
    } else
        return super.setProperty(name, value);
    return value;
}
Also used : PublicationStatusEnumFactory(org.hl7.fhir.dstu3.model.Enumerations.PublicationStatusEnumFactory) SearchParamTypeEnumFactory(org.hl7.fhir.dstu3.model.Enumerations.SearchParamTypeEnumFactory)

Example 50 with Expression

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

the class FluentPathTests method test.

@ParameterizedTest(name = "{index}: file {0}")
@MethodSource("data")
public void test(String name, Element element) throws IOException, FHIRException {
    String input = element.getAttribute("inputfile");
    String expression = XMLUtil.getNamedChild(element, "expression").getTextContent();
    boolean fail = "true".equals(XMLUtil.getNamedChild(element, "expression").getAttribute("invalid"));
    Resource res = null;
    List<Base> outcome = new ArrayList<Base>();
    ExpressionNode node = fp.parse(expression);
    try {
        if (Utilities.noString(input))
            fp.check(null, null, node);
        else {
            res = new XmlParser().parse(new FileInputStream(Utilities.path("C:\\work\\org.hl7.fhir\\build\\publish", input)));
            fp.check(res, res.getResourceType().toString(), res.getResourceType().toString(), node);
        }
        outcome = fp.evaluate(res, node);
        Assertions.assertTrue(!fail, String.format("Expected exception parsing %s", expression));
    } catch (Exception e) {
        Assertions.assertTrue(fail, String.format("Unexpected exception parsing %s: " + e.getMessage(), expression));
    }
    if ("true".equals(element.getAttribute("predicate"))) {
        boolean ok = fp.convertToBoolean(outcome);
        outcome.clear();
        outcome.add(new BooleanType(ok));
    }
    if (fp.hasLog())
        System.out.println(fp.takeLog());
    List<Element> expected = new ArrayList<Element>();
    XMLUtil.getNamedChildren(element, "output", expected);
    Assertions.assertTrue(outcome.size() == expected.size(), String.format("Expected %d objects but found %d", expected.size(), outcome.size()));
    for (int i = 0; i < Math.min(outcome.size(), expected.size()); i++) {
        String tn = expected.get(i).getAttribute("type");
        if (!Utilities.noString(tn)) {
            Assertions.assertTrue(tn.equals(outcome.get(i).fhirType()), String.format("Outcome %d: Type should be %s but was %s", i, tn, outcome.get(i).fhirType()));
        }
        String v = expected.get(i).getTextContent();
        if (!Utilities.noString(v)) {
            Assertions.assertTrue(outcome.get(i) instanceof PrimitiveType, String.format("Outcome %d: Value should be a primitive type but was %s", i, outcome.get(i).fhirType()));
            Assertions.assertTrue(v.equals(((PrimitiveType) outcome.get(i)).asStringValue()), String.format("Outcome %d: Value should be %s but was %s", i, v, outcome.get(i).toString()));
        }
    }
}
Also used : XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) Element(org.w3c.dom.Element) Resource(org.hl7.fhir.dstu3.model.Resource) ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) Base(org.hl7.fhir.dstu3.model.Base) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ExpressionNode(org.hl7.fhir.dstu3.model.ExpressionNode) PrimitiveType(org.hl7.fhir.dstu3.model.PrimitiveType) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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