Search in sources :

Example 1 with Expression

use of org.hl7.fhir.r5.model.Expression in project kindling by HL7.

the class PageProcessor method genConstraints.

private String genConstraints(String name, String prefix) throws Exception {
    Map<String, String> invs = new HashMap<String, String>();
    if (definitions.getConstraints().containsKey(name)) {
        ProfiledType cnst = definitions.getConstraints().get(name);
        generateConstraintsTable(name, cnst, invs, true, prefix);
    } else {
        ElementDefn e = definitions.getElementDefn(name);
        generateConstraintsTable(name, e, invs, true, prefix);
    }
    List<String> ids = new ArrayList<String>();
    for (String n : invs.keySet()) {
        ids.add(n);
    }
    Collections.sort(ids, new ConstraintsSorter());
    StringBuilder b = new StringBuilder();
    for (String n : ids) {
        b.append(invs.get(n));
    }
    if (b.length() > 0)
        return "<a name=\"" + name + "-inv\"> </a><table class=\"grid\"><tr><td width=\"60\"><b>id</b></td><td><b>Level</b></td><td><b>Location</b></td><td><b>Description</b></td><td><b><a href=\"" + prefix + "fhirpath.html\">Expression</a></b></td></tr>" + b + "</table>";
    else
        return "";
}
Also used : ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ArrayList(java.util.ArrayList)

Example 2 with Expression

use of org.hl7.fhir.r5.model.Expression in project kindling by HL7.

the class PageProcessor method getInvariantList.

private String getInvariantList(StructureDefinition profile) throws FHIRException, Exception {
    List<String> txlist = new ArrayList<String>();
    Map<String, List<ElementDefinitionConstraintComponent>> txmap = new HashMap<String, List<ElementDefinitionConstraintComponent>>();
    for (ElementDefinition ed : profile.getSnapshot().getElement()) {
        if (!"0".equals(ed.getMax())) {
            List<ElementDefinitionConstraintComponent> list = new ArrayList<ElementDefinition.ElementDefinitionConstraintComponent>();
            for (ElementDefinitionConstraintComponent t : ed.getConstraint()) {
                if (!t.hasSource() || t.getSource().equals(profile.getUrl())) {
                    list.add(t);
                }
            }
            if (!list.isEmpty()) {
                txlist.add(ed.getPath());
                txmap.put(ed.getPath(), list);
            }
        }
    }
    if (txlist.isEmpty())
        return "";
    else {
        StringBuilder b = new StringBuilder();
        b.append("<h4>Constraints</h4>\r\n");
        b.append("<table class=\"list\">\r\n");
        b.append("<tr><td width=\"60\"><b>Id</b></td><td><b>Path</b></td><td><b>Details</b></td><td><b>Requirements</b></td></tr>\r\n");
        for (String path : txlist) {
            List<ElementDefinitionConstraintComponent> invs = txmap.get(path);
            for (ElementDefinitionConstraintComponent inv : invs) {
                b.append("<tr>" + presentLevel(inv) + " <td>").append(inv.getKey()).append("</td><td>").append(path).append("</td><td>").append(Utilities.escapeXml(inv.getHuman())).append("<br/><a href=\"http://hl7.org/fhirpath\">Expression</a>: ").append(Utilities.escapeXml(inv.getExpression())).append("</td><td>").append(Utilities.escapeXml(inv.getRequirements()));
                if (inv.hasExtension(ToolingExtensions.EXT_BEST_PRACTICE_EXPLANATION))
                    b.append(". This is (only) a best practice guideline because: <blockquote>" + processMarkdown("best practice guideline", inv.getExtensionString(ToolingExtensions.EXT_BEST_PRACTICE_EXPLANATION), "") + "</blockquote>");
                b.append("</td></tr>\r\n");
            }
        }
        b.append("</table>\r\n");
        return b.toString();
    }
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)

Example 3 with Expression

use of org.hl7.fhir.r5.model.Expression in project kindling by HL7.

the class PageProcessor method generateConstraints.

private void generateConstraints(String path, ElementDefn e, Map<String, String> invs, boolean base, String prefix) throws Exception {
    for (Invariant inv : e.getInvariants().values()) {
        String s = "";
        if (base)
            s = "<li>" + presentLevel(inv) + " <b title=\"Formal Invariant Identifier\">" + inv.getId() + "</b>: " + Utilities.escapeXml(inv.getEnglish()) + " (<a href=\"http://hl7.org/fhirpath\">expression</a>: <span style=\"font-family: Courier New, monospace\">" + Utilities.escapeXml(inv.getExpression()) + "</span>)";
        else
            s = "<li>" + presentLevel(inv) + " <b title=\"Formal Invariant Identifier\">" + inv.getId() + "</b>: On " + path + ": " + Utilities.escapeXml(inv.getEnglish()) + " (<a href=\"http://hl7.org/fhirpath\">expression</a> on " + presentPath(path) + ": <span style=\"font-family: Courier New, monospace\">" + Utilities.escapeXml(inv.getExpression()) + "</span>)";
        if (!Utilities.noString(inv.getExplanation()))
            s = s + ". This is (only) a best practice guideline because: <blockquote>" + processMarkdown("best practice guideline", inv.getExplanation(), prefix) + "</blockquote>";
        invs.put(inv.getId(), s + "</li>");
    }
    for (ElementDefn c : e.getElements()) {
        generateConstraints(path + "." + c.getName(), c, invs, false, prefix);
    }
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 4 with Expression

use of org.hl7.fhir.r5.model.Expression in project kindling by HL7.

the class PageProcessor method getSearch.

/*
  private String prepWikiName(String name) {
    return Utilities.noString(name) ? "Index" : Utilities.capitalize(Utilities.fileTitle(name));
  }
  */
private String getSearch(ResourceDefn resource, String searchAdditions) {
    if (resource.getSearchParams().size() == 0)
        return "";
    else {
        StandardsStatus st = resource.getStatus();
        StringBuilder b = new StringBuilder();
        b.append("<h2>Search Parameters</h2>\r\n");
        if (resource.getName().equals("Query"))
            b.append("<p>Search parameters for this resource. The <a href=\"#all\">common parameters</a> also apply.</p>\r\n");
        else
            b.append("<p>Search parameters for this resource. The <a href=\"search.html#all\">common parameters</a> also apply. See <a href=\"search.html\">Searching</a> for more information about searching in REST, messaging, and services.</p>\r\n");
        b.append("<table class=\"list\">\r\n");
        b.append("<tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Description</b></td><td><b>Expression</b></td><td><b>In Common</b></td></tr>\r\n");
        List<String> names = new ArrayList<String>();
        names.addAll(resource.getSearchParams().keySet());
        Collections.sort(names);
        for (String name : names) {
            SearchParameterDefn p = resource.getSearchParams().get(name);
            String pp = presentPaths(p.getPaths());
            String sst = (p.getStandardsStatus() == null || p.getStandardsStatus() == st) ? "" : makeStandardsStatusRef(p.getStandardsStatus());
            b.append("<tr><td><a name=\"sp-").append(p.getCode()).append("\"> </a>").append(p.getCode()).append(sst).append("</td><td><a href=\"search.html#").append(p.getType()).append("\">").append(p.getType()).append("</a></td><td>").append(Utilities.escapeXml(p.getDescription())).append("</td><td>").append(p.getType() == SearchType.composite ? getCompositeExpression(p) : Utilities.escapeXml(p.getExpression())).append(p.getType() == SearchType.reference ? p.getTargetTypesAsText() : "").append("</td><td>").append(presentOthers(p)).append("</td></tr>\r\n");
        }
        b.append(searchAdditions);
        b.append("</table>\r\n");
        return b.toString();
    }
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) ArrayList(java.util.ArrayList) StandardsStatus(org.hl7.fhir.utilities.StandardsStatus)

Example 5 with Expression

use of org.hl7.fhir.r5.model.Expression in project kindling by HL7.

the class ExampleInspector method testSearchParameters.

private void testSearchParameters(org.w3c.dom.Element xe, String rn, boolean inBundle) throws FHIRException {
    ResourceDefn r = definitions.getResources().get(rn);
    for (SearchParameterDefn sp : r.getSearchParams().values()) {
        if (!sp.isXPathDone() && !Utilities.noString(sp.getXPath())) {
            try {
                sp.setXPathDone(true);
                NamespaceContext context = new NamespaceContextMap("f", "http://hl7.org/fhir", "h", "http://www.w3.org/1999/xhtml");
                XPathFactory factory = XPathFactory.newInstance();
                XPath xpath = factory.newXPath();
                xpath.setNamespaceContext(context);
                XPathExpression expression;
                expression = inBundle ? xpath.compile("/f:Bundle/f:entry/f:resource/" + sp.getXPath()) : xpath.compile("/" + sp.getXPath());
                NodeList resultNodes = (NodeList) expression.evaluate(xe, XPathConstants.NODESET);
                if (resultNodes.getLength() > 0)
                    sp.setWorks(true);
            } catch (Exception e1) {
                throw new FHIRException("Xpath \"" + sp.getXPath() + "\" execution failed: " + e1.getMessage(), e1);
            }
        }
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) XPathFactory(javax.xml.xpath.XPathFactory) SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) NamespaceContext(javax.xml.namespace.NamespaceContext) NamespaceContextMap(org.hl7.fhir.utilities.xml.NamespaceContextMap) NodeList(org.w3c.dom.NodeList) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) ValidationException(org.everit.json.schema.ValidationException) MalformedURLException(java.net.MalformedURLException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) 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