Search in sources :

Example 11 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.

the class PageProcessor method generateConstraintsTable.

private void generateConstraintsTable(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 = "<tr><td><b title=\"Formal Invariant Identifier\">" + inv.getId() + "</b></td><td>" + presentLevel(inv) + "</td><td>(base)</td><td>" + Utilities.escapeXml(inv.getEnglish()) + "</td><td><span style=\"font-family: Courier New, monospace\">" + Utilities.escapeXml(inv.getExpression()) + "</span>";
        else
            s = "<tr><td><b title=\"Formal Invariant Identifier\">" + inv.getId() + "</b></td><td>" + presentLevel(inv) + "</td><td>" + path + "</td><td>" + Utilities.escapeXml(inv.getEnglish()) + "</td><td><span style=\"font-family: Courier New, monospace\">" + Utilities.escapeXml(inv.getExpression()) + "</span>";
        if (!Utilities.noString(inv.getExplanation()))
            s = s + "<br/>This is (only) a best practice guideline because: <blockquote>" + processMarkdown("best practice guideline", inv.getExplanation(), prefix) + "</blockquote>";
        s = s + "</td></tr>";
        invs.put(inv.getId(), s);
    }
    for (ElementDefn c : e.getElements()) {
        generateConstraintsTable(path + "." + c.getName(), c, invs, false, prefix);
    }
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 12 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn 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 13 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.

the class PageProcessor method generateValueSetUsage.

private String generateValueSetUsage(ValueSet vs, String prefix, boolean addTitle) throws Exception {
    List<String> items = new ArrayList<>();
    if (vs.hasUrl()) {
        for (CodeSystem cs : getCodeSystems().getList()) {
            if (cs != null) {
                if (vs.getUrl().equals(cs.getValueSet())) {
                    String p = cs.getUserString("path");
                    addItem(items, "<li>CodeSystem: This value set is the designated 'entire code system' value set for <a href=\"" + (Utilities.isAbsoluteUrl(p) ? "" : prefix) + p + "\">" + cs.getName() + "</a> " + "</li>\r\n");
                }
            }
        }
    }
    for (ConceptMap cm : getConceptMaps().getList()) {
        String p = cm.getUserString("path");
        if (cm.hasSourceUriType() && cm.getSourceUriType().equals(vs.getUrl())) {
            addItem(items, "<li>ConceptMap: Translation source in <a href=\"" + (Utilities.isAbsoluteUrl(p) ? "" : prefix) + p + "\">" + cm.present() + "</a> " + "</li>\r\n");
        } else if (cm.hasSourceCanonicalType() && (cm.getSourceCanonicalType().getValue().equals(vs.getUrl()) || vs.getUrl().endsWith("/" + cm.getSourceCanonicalType().getValue()))) {
            addItem(items, "<li>ConceptMap: Translation source in <a href=\"" + (Utilities.isAbsoluteUrl(p) ? "" : prefix) + p + "\">" + cm.getName() + "</a> " + "</li>\r\n");
        }
    }
    for (ConceptMap cm : getConceptMaps().getList()) {
        String p = cm.getUserString("path");
        if (cm.hasTargetUriType() && cm.getTargetUriType().equals(vs.getUrl())) {
            addItem(items, "<li>ConceptMap: Translation target in <a href=\"" + (Utilities.isAbsoluteUrl(p) ? "" : prefix) + p + "\">" + cm.present() + "</a> " + "</li>\r\n");
        } else if (cm.hasTargetCanonicalType() && (cm.getTargetCanonicalType().getValue().equals(vs.getUrl()) || vs.getUrl().endsWith("/" + cm.getTargetCanonicalType().getValue()))) {
            addItem(items, "<li>ConceptMap: Translation target ConceptMap <a href=\"" + (Utilities.isAbsoluteUrl(p) ? "" : prefix) + p + "\">" + cm.getName() + "</a> " + "</li>\r\n");
        }
    }
    for (ResourceDefn r : definitions.getBaseResources().values()) {
        scanForUsage(items, vs, r.getRoot(), r.getName().toLowerCase() + "-definitions.html", prefix);
        scanForOperationUsage(items, vs, r, r.getName().toLowerCase() + "-operation-", prefix);
        scanForProfileUsage(items, vs, r, prefix);
    }
    for (ResourceDefn r : definitions.getResources().values()) {
        scanForUsage(items, vs, r.getRoot(), r.getName().toLowerCase() + "-definitions.html", prefix);
        scanForOperationUsage(items, vs, r, r.getName().toLowerCase() + "-operation-", prefix);
        scanForProfileUsage(items, vs, r, prefix);
    }
    for (ElementDefn e : definitions.getInfrastructure().values()) {
        scanForUsage(items, vs, e, definitions.getSrcFile(e.getName()) + "-definitions.html", prefix);
    }
    for (ElementDefn e : definitions.getTypes().values()) {
        if (!definitions.dataTypeIsSharedInfo(e.getName())) {
            scanForUsage(items, vs, e, definitions.getSrcFile(e.getName()) + "-definitions.html", prefix);
        }
    }
    for (StructureDefinition sd : workerContext.getExtensionDefinitions()) {
        scanForUsage(items, vs, sd, sd.getUserString("path"), prefix);
    }
    for (ValueSet vsi : definitions.getValuesets().getList()) {
        String path = (String) vsi.getUserData("path");
        if (vs.hasCompose()) {
            for (ConceptSetComponent t : vs.getCompose().getInclude()) {
                for (UriType uri : t.getValueSet()) {
                    if (uri.getValue().equals(vs.getUrl())) {
                        addItem(items, "<li>ValueSet: Included in <a href=\"" + prefix + path + "\">" + Utilities.escapeXml(vs.present()) + "</a></li>\r\n");
                    }
                }
            }
            for (ConceptSetComponent t : vs.getCompose().getExclude()) {
                for (UriType uri : t.getValueSet()) {
                    if (uri.getValue().equals(vs.getUrl())) {
                        addItem(items, "<li>ValueSet: Excluded from  <a href=\"" + prefix + path + "\">" + Utilities.escapeXml(vs.present()) + "</a></li>\r\n");
                    }
                }
            }
        // for (ConceptSetComponent t : vsi.getCompose().getInclude()) {
        // if (vs.hasCodeSystem() && t.getSystem().equals(vs.getCodeSystem().getSystem()))
        // b.append(" <li>Included in Valueset <a href=\""+prefix+path+"\">"+Utilities.escapeXml(vs.getName())+"</a></li>\r\n");
        // }
        // for (ConceptSetComponent t : vsi.getCompose().getExclude()) {
        // if (vs.hasCodeSystem() && t.getSystem().equals(vs.getCodeSystem().getSystem()))
        // b.append(" <li>Excluded in Valueset <a href=\""+prefix+path+"\">"+Utilities.escapeXml(vs.getName())+"</a></li>\r\n");
        // }
        }
    }
    if (ini.getPropertyNames(vs.getUrl()) != null) {
        for (String n : ini.getPropertyNames(vs.getUrl())) {
            addItem(items, "<li>" + ini.getStringProperty(vs.getUrl(), n) + "</li>\r\n");
        }
    }
    if (items.size() == 0)
        return "<p>\r\nThis value set is not currently used\r\n</p>\r\n";
    else {
        StringBuilder b = new StringBuilder();
        for (String s : items) {
            b.append(" " + s);
        }
        return (addTitle ? "<p>\r\nThis value set is used in the following places:\r\n</p>\r\n" : "") + "<ul>\r\n" + b.toString() + "</ul>\r\n";
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ArrayList(java.util.ArrayList) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) ValueSet(org.hl7.fhir.r5.model.ValueSet) UriType(org.hl7.fhir.r5.model.UriType)

Example 14 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.

the class DefinitionsUsageTracker method usage.

private void usage(org.hl7.fhir.r5.elementmodel.Element instance, ElementDefn definition, String path) throws Exception {
    definition.setCoveredByExample(true);
    for (Element c : instance.getChildren()) {
        String p = c.getProperty().getDefinition().getPath();
        ElementDefn ed = definitions.getElementByPath(p.split("\\."), "example usage", true);
        if (ed != null)
            usage(c, ed, path + "." + c.getName());
    // else if (!c.getName().equals("extension"))
    // System.out.println("error finding "+c.getName()+" at "+path);
    }
}
Also used : Element(org.hl7.fhir.r5.elementmodel.Element) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 15 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.

the class ExampleAdorner method getLink.

@Override
public String getLink(XhtmlGenerator ref, XhtmlGeneratorAdornerState state, Element node) throws Exception {
    if (state == null) {
        if (node == null || !definitions.hasResource(node.getLocalName()))
            return null;
        else {
            definitions.getResourceByName(node.getLocalName()).getRoot().setCoveredByExample(true);
            return prefix + node.getLocalName().toLowerCase() + "-definitions.html";
        }
    } else {
        ExampleAdornerState s = (ExampleAdornerState) state;
        if (s.definition == null)
            if (node.getNamespaceURI().equals("http://www.w3.org/1999/xhtml"))
                return prefix + "narrative.html";
            else
                return null;
        ElementDefn t = s.definition;
        if (t.typeCode().equals("Resource") && (s.getPath().endsWith(".entry.resource") || s.getPath().endsWith(".contained")) && definitions.isResource(node.getNodeName()))
            return null;
        ElementDefn child = t.getElementByName(node.getNodeName(), true, definitions, "adorn example", false);
        String p = child == null ? null : s.getPath() + "." + child.getName();
        while (child == null && t != null && definitions.hasElementDefn(t.typeCodeNoParams())) {
            t = definitions.getElementDefn(t.typeCodeNoParams());
            child = t.getElementByName(node.getNodeName(), true, definitions, "adorn example", false);
            if (child != null) {
                p = t.getName() + "." + child.getName();
            }
        }
        if (child == null) {
            if (node.getNamespaceURI().equals("http://www.w3.org/1999/xhtml"))
                return prefix + "narrative.html";
            else
                return null;
        } else {
            child.setCoveredByExample(true);
            String r = p.contains(".") ? p.substring(0, p.indexOf(".")) : p;
            return prefix + definitions.getSrcFile(r) + "-definitions.html#" + p;
        }
    }
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Aggregations

ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)100 TypeRef (org.hl7.fhir.definitions.model.TypeRef)35 ArrayList (java.util.ArrayList)28 FHIRException (org.hl7.fhir.exceptions.FHIRException)28 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)21 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)19 Invariant (org.hl7.fhir.definitions.model.Invariant)16 IOException (java.io.IOException)14 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)11 FileNotFoundException (java.io.FileNotFoundException)10 URISyntaxException (java.net.URISyntaxException)10 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)10 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)9 TransformerException (javax.xml.transform.TransformerException)8 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)8 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)7 NotImplementedException (org.apache.commons.lang3.NotImplementedException)7 UcumException (org.fhir.ucum.UcumException)7 TypeParser (org.hl7.fhir.definitions.parsers.TypeParser)7 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)7