Search in sources :

Example 1 with StructureDefinitionContextComponent

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

the class PageProcessor method presentContext.

private Object presentContext(StructureDefinition cs, String resource) {
    StringBuilder b = new StringBuilder();
    boolean first = true;
    for (StructureDefinitionContextComponent c : cs.getContext()) {
        if (appliesTo(c, resource)) {
            if (first)
                first = false;
            else
                b.append(", ");
            if (c.getType() != ExtensionContextType.ELEMENT)
                b.append("<a href=\"codesystem-extension-context-type.html#" + c.getType().toCode() + "\">" + c.getType().toCode() + "</a>: ");
            b.append("<code>" + c.getExpression() + "</code>");
        }
    }
    return b.toString();
}
Also used : StructureDefinitionContextComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 2 with StructureDefinitionContextComponent

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

the class PageProcessor method produceExtensions.

private String produceExtensions(ResourceDefn resource) {
    int count = 0;
    Map<String, StructureDefinition> map = new HashMap<String, StructureDefinition>();
    for (StructureDefinition sd : workerContext.getExtensionDefinitions()) {
        boolean inc = false;
        for (StructureDefinitionContextComponent ec : sd.getContext()) {
            if (ec.getType() == ExtensionContextType.ELEMENT) {
                inc = inc || (ec.getExpression().equals(resource.getName()) || ec.getExpression().startsWith(resource.getName() + "."));
            }
            if (inc)
                map.put(sd.getId(), sd);
        }
    }
    StringBuilder b = new StringBuilder();
    for (String s : sorted(map.keySet())) {
        StructureDefinition cs = map.get(s);
        count++;
        b.append("  <tr>\r\n");
        String ref = cs.getUserString("path");
        b.append("    <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.getId())).append("</a></td>\r\n");
        b.append("    <td>").append(presentContext(cs, resource.getName())).append("</td>\r\n");
        b.append("    <td>").append(Utilities.escapeXml(cs.getName())).append("</td>\r\n");
        Profile ap = (Profile) cs.getUserData("profile");
        if (ap == null)
            b.append("    <td></td>\r\n");
        else {
            ImplementationGuideDefn ig = definitions.getIgs().get(ap.getCategory());
            b.append("    <td>for <a href=\"" + ig.getPrefix() + ap.getId().toLowerCase() + ".html\">" + Utilities.escapeXml(ap.getTitle()) + "</a></td>\r\n");
        }
        b.append(" </tr>\r\n");
    }
    if (count == 0)
        b.append("<tr><td>No Extensions defined for this resource</td></tr>");
    map.clear();
    for (StructureDefinition sd : workerContext.getExtensionDefinitions()) {
        boolean inc = false;
        for (StructureDefinitionContextComponent ec : sd.getContext()) inc = inc || (ec.getExpression().equals("Resource") || ec.getExpression().equals("DomainResource") || ec.getExpression().equals("Any"));
        if (inc)
            map.put(sd.getId(), sd);
    }
    b.append("<tr><td colspan=\"4\">Extensions for all resources or elements</td></tr>");
    for (String s : sorted(map.keySet())) {
        StructureDefinition cs = map.get(s);
        count++;
        b.append("  <tr>\r\n");
        String ref = cs.getUserString("path");
        b.append("    <td colspan=\"2\"><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.getId())).append("</a></td>\r\n");
        b.append("    <td>").append(Utilities.escapeXml(cs.getName())).append("</td>\r\n");
        Profile ap = (Profile) cs.getUserData("profile");
        if (ap == null)
            b.append("    <td></td>\r\n");
        else {
            ImplementationGuideDefn ig = definitions.getIgs().get(ap.getCategory());
            b.append("    <td>for <a href=\"" + ig.getPrefix() + ap.getId() + ".html\">" + Utilities.escapeXml(ap.getTitle()) + "</a></td>\r\n");
        }
        b.append(" </tr>\r\n");
    }
    return b.toString();
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) StructureDefinitionContextComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) Profile(org.hl7.fhir.definitions.model.Profile)

Example 3 with StructureDefinitionContextComponent

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

the class PageProcessor method produceDataTypeExtras.

private String produceDataTypeExtras(String tn, boolean profiles) {
    int count = 0;
    Map<String, StructureDefinition> map = new HashMap<String, StructureDefinition>();
    for (StructureDefinition sd : workerContext.getExtensionDefinitions()) {
        boolean inc = false;
        for (StructureDefinitionContextComponent ec : sd.getContext()) {
            if (ec.getType() == ExtensionContextType.ELEMENT) {
                inc = inc || matchesType(tn, ec.getExpression());
            }
        }
        if (inc)
            map.put(sd.getId(), sd);
    }
    StringBuilder b = new StringBuilder();
    b.append("  <tr><td colspan=\"3\"><b>Extensions</b> (+ see <a href=\"" + definitions.getElementExtrasLink() + "\">extensions on all Elements</a>)</td></tr>\r\n");
    for (String s : sorted(map.keySet())) {
        StructureDefinition cs = map.get(s);
        count++;
        b.append("  <tr>\r\n");
        String ref = cs.getUserString("path");
        b.append("    <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.getId())).append("</a></td>\r\n");
        b.append("    <td>").append(Utilities.escapeXml(cs.getName())).append("</td>\r\n");
        Profile ap = (Profile) cs.getUserData("profile");
        if (ap == null)
            b.append("    <td></td>\r\n");
        else {
            ImplementationGuideDefn ig = definitions.getIgs().get(ap.getCategory());
            b.append("    <td>for <a href=\"" + ig.getPrefix() + ap.getId().toLowerCase() + ".html\">" + Utilities.escapeXml(ap.getTitle()) + "</a></td>\r\n");
        }
        b.append(" </tr>\r\n");
    }
    if (count == 0)
        b.append("<tr><td>No Extensions defined for " + (tn.equals("primitives") ? "primitive types" : "this type") + " (though see <a href=\"element-extensions.html\">extensions on all Elements</a>)</td></tr>");
    if (profiles) {
        count = 0;
        Map<String, CSPair> pmap = new HashMap<String, CSPair>();
        for (Profile ap : definitions.getPackList()) {
            for (ConstraintStructure cs : ap.getProfiles()) {
                if (coversType(cs, tn))
                    pmap.put(cs.getTitle(), new CSPair(ap, cs));
            }
        }
        b.append("  <tr><td colspan=\"3\"><b>Profiles</b></td></tr>\r\n");
        for (String s : sorted(pmap.keySet())) {
            CSPair cs = pmap.get(s);
            ImplementationGuideDefn ig = definitions.getIgs().get(cs.p.getCategory());
            count++;
            b.append("  <tr>\r\n");
            String ref = (ig.isCore() ? "" : ig.getCode() + File.separator) + cs.cs.getId() + ".html";
            b.append("    <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.cs.getTitle())).append("</a></td>\r\n");
            b.append("    <td>").append(Utilities.escapeXml(cs.p.getDescription())).append("</td>\r\n");
            ref = (ig.isCore() ? "" : ig.getCode() + File.separator) + cs.p.getId().toLowerCase() + ".html";
            b.append("    <td>for <a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.p.getTitle())).append("</a></td>\r\n");
            b.append(" </tr>\r\n");
        }
        if (count == 0)
            b.append("<tr><td>No Profiles defined for for " + (tn.equals("primitives") ? "primitive types" : "this type") + "</td></tr>");
    }
    return b.toString();
}
Also used : StructureDefinitionContextComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) Profile(org.hl7.fhir.definitions.model.Profile) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure)

Example 4 with StructureDefinitionContextComponent

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

the class PageProcessor method genExtensionRow.

private void genExtensionRow(ImplementationGuideDefn ig, StringBuilder s, StructureDefinition ed) throws Exception {
    s.append("<tr>");
    s.append("<td><a href=\"" + ed.getUserString("path") + "\" title=\"" + Utilities.escapeXml(ed.getDescription()) + "\">" + ed.getId() + "</a></td>");
    s.append("<td>" + displayExtensionCardinality(ed) + "</td>");
    s.append("<td>" + determineExtensionType(ed) + "</td>");
    s.append("<td>");
    boolean first = true;
    for (StructureDefinitionContextComponent ec : ed.getContext()) {
        if (first)
            first = false;
        else
            s.append(",<br/> ");
        if (ec.getType() == ExtensionContextType.ELEMENT) {
            String ref = Utilities.oidRoot(ec.getExpression());
            if (ref.startsWith("@"))
                ref = ref.substring(1);
            if (definitions.hasElementDefn(ref))
                s.append("<a href=\"" + definitions.getSrcFile(ref) + ".html#" + Utilities.oidRoot(ec.getExpression()) + "\">" + ec.getExpression() + "</a>");
            else if (definitions.hasResource(ref))
                s.append("<a href=\"" + ref.toLowerCase() + ".html\">" + ec.getExpression() + "</a>");
            else
                s.append(ec.getExpression());
        } else if (ec.getType() == ExtensionContextType.FHIRPATH) {
            s.append(Utilities.escapeXml(ec.getExpression()));
        } else
            throw new Error("Not done yet");
    }
    s.append("</td>");
    String fmm = ToolingExtensions.readStringExtension(ed, ToolingExtensions.EXT_FMM_LEVEL);
    s.append("<td>" + (Utilities.noString(fmm) ? "0" : fmm) + "</td>");
    // s.append("<td><a href=\"extension-"+ed.getId().toLowerCase()+ ".xml.html\">XML</a></td>");
    // s.append("<td><a href=\"extension-"+ed.getId().toLowerCase()+ ".json.html\">JSON</a></td>");
    s.append("</tr>");
}
Also used : StructureDefinitionContextComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError)

Example 5 with StructureDefinitionContextComponent

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

the class StructureDefinitionSpreadsheetGenerator method addStructureDefinitionMetadata.

private void addStructureDefinitionMetadata(Sheet sheet, StructureDefinition sd) {
    for (Coding k : sd.getKeyword()) {
        addMetadataRow(sheet, "Keyword", dr.display(k));
    }
    addMetadataRow(sheet, "FHIR Version", sd.getFhirVersionElement().asStringValue());
    addMetadataRow(sheet, "Kind", sd.getKindElement().asStringValue());
    addMetadataRow(sheet, "Type", sd.getType());
    addMetadataRow(sheet, "Base Definition", sd.getBaseDefinition());
    addMetadataRow(sheet, "Abstract", sd.getAbstractElement().asStringValue());
    addMetadataRow(sheet, "Derivation", sd.getDerivationElement().asStringValue());
    for (StructureDefinitionContextComponent k : sd.getContext()) {
        addMetadataRow(sheet, "Context", k.getTypeElement().asStringValue() + ":" + k.getExpression());
    }
    for (StringType k : sd.getContextInvariant()) {
        addMetadataRow(sheet, "Context Inv.", k.getValue());
    }
}
Also used : StructureDefinitionContextComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent) Coding(org.hl7.fhir.r5.model.Coding) StringType(org.hl7.fhir.r5.model.StringType)

Aggregations

StructureDefinitionContextComponent (org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent)11 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)8 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)6 ArrayList (java.util.ArrayList)3 StringType (org.hl7.fhir.r5.model.StringType)3 HashMap (java.util.HashMap)2 ConstraintStructure (org.hl7.fhir.definitions.model.ConstraintStructure)2 ImplementationGuideDefn (org.hl7.fhir.definitions.model.ImplementationGuideDefn)2 Profile (org.hl7.fhir.definitions.model.Profile)2 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 StringType (org.hl7.fhir.r4b.model.StringType)2 StructureDefinitionContextComponent (org.hl7.fhir.r4b.model.StructureDefinition.StructureDefinitionContextComponent)2 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerFactoryConfigurationError (javax.xml.transform.TransformerFactoryConfigurationError)1 ProfileGenerator (org.hl7.fhir.definitions.generators.specification.ProfileGenerator)1 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)1 Invariant (org.hl7.fhir.definitions.model.Invariant)1