Search in sources :

Example 21 with HierarchicalTableGenerator

use of org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method genTypes.

private Cell genTypes(HierarchicalTableGenerator gen, Row r, ElementDefinition e, String profileBaseFileName, StructureDefinition profile, String corePath) {
    Cell c = gen.new Cell();
    r.getCells().add(c);
    List<TypeRefComponent> types = e.getType();
    if (!e.hasType()) {
        if (e.hasContentReference()) {
            return c;
        } else {
            ElementDefinition d = (ElementDefinition) e.getUserData(DERIVATION_POINTER);
            if (d != null && d.hasType()) {
                types = new ArrayList<ElementDefinition.TypeRefComponent>();
                for (TypeRefComponent tr : d.getType()) {
                    TypeRefComponent tt = tr.copy();
                    tt.setUserData(DERIVATION_EQUALS, true);
                    types.add(tt);
                }
            } else
                return c;
        }
    }
    boolean first = true;
    // either all types are the same, or we don't consider any of them the same
    Element source = types.get(0);
    boolean allReference = ADD_REFERENCE_TO_TABLE && !types.isEmpty();
    for (TypeRefComponent t : types) {
        if (!(t.getCode().equals("Reference") && t.hasProfile()))
            allReference = false;
    }
    if (allReference) {
        c.getPieces().add(gen.new Piece(corePath + "references.html", "Reference", null));
        c.getPieces().add(gen.new Piece(null, "(", null));
    }
    TypeRefComponent tl = null;
    for (TypeRefComponent t : types) {
        if (first)
            first = false;
        else if (allReference)
            c.addPiece(checkForNoChange(tl, gen.new Piece(null, " | ", null)));
        else
            c.addPiece(checkForNoChange(tl, gen.new Piece(null, ", ", null)));
        tl = t;
        if (t.getCode().equals("Reference") || (t.getCode().equals("Resource") && t.hasProfile())) {
            if (ADD_REFERENCE_TO_TABLE && !allReference) {
                c.getPieces().add(gen.new Piece(corePath + "references.html", "Reference", null));
                c.getPieces().add(gen.new Piece(null, "(", null));
            }
            if (t.hasProfile() && t.getProfile().get(0).getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
                StructureDefinition sd = context.fetchResource(StructureDefinition.class, t.getProfile().get(0).getValue());
                if (sd != null) {
                    String disp = sd.hasDisplay() ? sd.getDisplay() : sd.getName();
                    c.addPiece(checkForNoChange(t, gen.new Piece(corePath + sd.getUserString("path"), disp, null)));
                } else {
                    String rn = t.getProfile().get(0).getValue().substring(40);
                    c.addPiece(checkForNoChange(t, gen.new Piece(corePath + pkp.getLinkFor(rn), rn, null)));
                }
            } else if (t.getProfile().size() == 0) {
                c.addPiece(checkForNoChange(t, gen.new Piece(null, t.getCode(), null)));
            } else if (t.getProfile().get(0).getValue().startsWith("#"))
                c.addPiece(checkForNoChange(t, gen.new Piece(corePath + profileBaseFileName + "." + t.getProfile().get(0).getValue().substring(1).toLowerCase() + ".html", t.getProfile().get(0).getValue(), null)));
            else
                c.addPiece(checkForNoChange(t, gen.new Piece(corePath + t.getProfile().get(0).getValue(), t.getProfile().get(0).getValue(), null)));
            if (ADD_REFERENCE_TO_TABLE && !allReference) {
                c.getPieces().add(gen.new Piece(null, ")", null));
            }
        } else if (t.hasProfile()) {
            // a profiled type
            String ref;
            ref = pkp.getLinkForProfile(profile, t.getProfile().get(0).getValue());
            if (ref != null) {
                String[] parts = ref.split("\\|");
                c.addPiece(checkForNoChange(t, gen.new Piece(corePath + parts[0], parts[1], t.getCode())));
            } else
                c.addPiece(checkForNoChange(t, gen.new Piece(corePath + ref, t.getCode(), null)));
        } else if (pkp.hasLinkFor(t.getCode())) {
            c.addPiece(checkForNoChange(t, gen.new Piece(corePath + pkp.getLinkFor(t.getCode()), t.getCode(), null)));
        } else
            c.addPiece(checkForNoChange(t, gen.new Piece(null, t.getCode(), null)));
    }
    if (allReference) {
        c.getPieces().add(gen.new Piece(null, ")", null));
    }
    return c;
}
Also used : StructureDefinition(org.hl7.fhir.dstu2016may.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.dstu2016may.model.ElementDefinition.TypeRefComponent) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) Element(org.hl7.fhir.dstu2016may.model.Element) ElementDefinition(org.hl7.fhir.dstu2016may.model.ElementDefinition) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

Example 22 with HierarchicalTableGenerator

use of org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method generateDescription.

private Cell generateDescription(HierarchicalTableGenerator gen, Row row, ElementDefinition definition, ElementDefinition fallback, boolean used, String baseURL, String url, StructureDefinition profile, String corePath, boolean root, boolean logicalModel) throws IOException {
    Cell c = gen.new Cell();
    row.getCells().add(c);
    if (used) {
        if (logicalModel && ToolingExtensions.hasExtension(profile, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace")) {
            if (root) {
                c.getPieces().add(gen.new Piece(null, "XML Namespace: ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(profile, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"), null));
            } else if (!root && ToolingExtensions.hasExtension(definition, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace") && !ToolingExtensions.readStringExtension(definition, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").equals(ToolingExtensions.readStringExtension(profile, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"))) {
                c.getPieces().add(gen.new Piece(null, "XML Namespace: ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(definition, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"), null));
            }
        }
        if (definition.hasContentReference()) {
            ElementDefinition ed = getElementByName(profile.getSnapshot().getElement(), definition.getContentReference());
            if (ed == null)
                c.getPieces().add(gen.new Piece(null, "Unknown reference to " + definition.getContentReference(), null));
            else
                c.getPieces().add(gen.new Piece("#" + ed.getPath(), "See " + ed.getPath(), null));
        }
        if (definition.getPath().endsWith("url") && definition.hasFixed()) {
            c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "\"" + buildJson(definition.getFixed()) + "\"", null).addStyle("color: darkgreen")));
        } else {
            if (definition != null && definition.hasShort()) {
                if (!c.getPieces().isEmpty())
                    c.addPiece(gen.new Piece("br"));
                c.addPiece(checkForNoChange(definition.getShortElement(), gen.new Piece(null, definition.getShort(), null)));
            } else if (fallback != null && fallback != null && fallback.hasShort()) {
                if (!c.getPieces().isEmpty())
                    c.addPiece(gen.new Piece("br"));
                c.addPiece(checkForNoChange(fallback.getShortElement(), gen.new Piece(null, fallback.getShort(), null)));
            }
            if (url != null) {
                if (!c.getPieces().isEmpty())
                    c.addPiece(gen.new Piece("br"));
                String fullUrl = url.startsWith("#") ? baseURL + url : url;
                StructureDefinition ed = context.fetchResource(StructureDefinition.class, url);
                String ref = ed == null ? null : (String) corePath + ed.getUserData("path");
                c.getPieces().add(gen.new Piece(null, "URL: ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(ref, fullUrl, null));
            }
            if (definition.hasSlicing()) {
                if (!c.getPieces().isEmpty())
                    c.addPiece(gen.new Piece("br"));
                c.getPieces().add(gen.new Piece(null, "Slice: ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(null, describeSlice(definition.getSlicing()), null));
            }
            if (definition != null) {
                if (definition.hasBinding()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    BindingResolution br = pkp.resolveBinding(definition.getBinding());
                    c.getPieces().add(checkForNoChange(definition.getBinding(), gen.new Piece(null, "Binding: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getBinding(), gen.new Piece(br.url == null ? null : Utilities.isAbsoluteUrl(br.url) ? br.url : corePath + br.url, br.display, null)));
                    if (definition.getBinding().hasStrength()) {
                        c.getPieces().add(checkForNoChange(definition.getBinding(), gen.new Piece(null, " (", null)));
                        c.getPieces().add(checkForNoChange(definition.getBinding(), gen.new Piece(corePath + "terminologies.html#" + definition.getBinding().getStrength().toCode(), definition.getBinding().getStrength().toCode(), definition.getBinding().getStrength().getDefinition())));
                        c.getPieces().add(gen.new Piece(null, ")", null));
                    }
                }
                for (ElementDefinitionConstraintComponent inv : definition.getConstraint()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, inv.getKey() + ": ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, inv.getHuman(), null)));
                }
                if (definition.hasFixed()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "Fixed Value: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, buildJson(definition.getFixed()), null).addStyle("color: darkgreen")));
                } else if (definition.hasPattern()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, "Required Pattern: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, buildJson(definition.getPattern()), null).addStyle("color: darkgreen")));
                } else if (definition.hasExample()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    c.getPieces().add(checkForNoChange(definition.getExample(), gen.new Piece(null, "Example: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getExample(), gen.new Piece(null, buildJson(definition.getExample()), null).addStyle("color: darkgreen")));
                }
            }
        }
    }
    return c;
}
Also used : StructureDefinition(org.hl7.fhir.dstu2016may.model.StructureDefinition) BindingResolution(org.hl7.fhir.dstu2016may.utils.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) ElementDefinition(org.hl7.fhir.dstu2016may.model.ElementDefinition) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) ElementDefinitionConstraintComponent(org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionConstraintComponent)

Example 23 with HierarchicalTableGenerator

use of org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method generateExtensionTable.

public XhtmlNode generateExtensionTable(String defFile, StructureDefinition ed, String imageFolder, boolean inlineGraphics, boolean full, String corePath, Set<String> outputTracker) throws IOException, FHIRException {
    HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics);
    TableModel model = gen.initNormalTable(corePath, false, true, ed.getId(), false);
    boolean deep = false;
    boolean vdeep = false;
    for (ElementDefinition eld : ed.getSnapshot().getElement()) {
        deep = deep || eld.getPath().contains("Extension.extension.");
        vdeep = vdeep || eld.getPath().contains("Extension.extension.extension.");
    }
    Row r = gen.new Row();
    model.getRows().add(r);
    r.getCells().add(gen.new Cell(null, defFile == null ? "" : defFile + "-definitions.html#extension." + ed.getName(), ed.getSnapshot().getElement().get(0).getIsModifier() ? "modifierExtension" : "extension", null, null));
    r.getCells().add(gen.new Cell());
    r.getCells().add(gen.new Cell(null, null, describeCardinality(ed.getSnapshot().getElement().get(0), null, new UnusedTracker()), null, null));
    if (full || vdeep) {
        r.getCells().add(gen.new Cell("", "", "Extension", null, null));
        r.setIcon(deep ? "icon_extension_complex.png" : "icon_extension_simple.png", deep ? HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX : HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
        List<ElementDefinition> children = getChildren(ed.getSnapshot().getElement(), ed.getSnapshot().getElement().get(0));
        for (ElementDefinition child : children) if (!child.getPath().endsWith(".id"))
            genElement(defFile == null ? "" : defFile + "-definitions.html#extension.", gen, r.getSubRows(), child, ed.getSnapshot().getElement(), null, true, defFile, true, full, corePath, true, false);
    } else if (deep) {
        List<ElementDefinition> children = new ArrayList<ElementDefinition>();
        for (ElementDefinition ted : ed.getSnapshot().getElement()) {
            if (ted.getPath().equals("Extension.extension"))
                children.add(ted);
        }
        r.getCells().add(gen.new Cell("", "", "Extension", null, null));
        r.setIcon("icon_extension_complex.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX);
        for (ElementDefinition c : children) {
            ElementDefinition ved = getValueFor(ed, c);
            ElementDefinition ued = getUrlFor(ed, c);
            if (ved != null && ued != null) {
                Row r1 = gen.new Row();
                r.getSubRows().add(r1);
                r1.getCells().add(gen.new Cell(null, defFile == null ? "" : defFile + "-definitions.html#extension." + ed.getName(), ((UriType) ued.getFixed()).getValue(), null, null));
                r1.getCells().add(gen.new Cell());
                r1.getCells().add(gen.new Cell(null, null, describeCardinality(c, null, new UnusedTracker()), null, null));
                genTypes(gen, r1, ved, defFile, ed, corePath);
                r1.getCells().add(gen.new Cell(null, null, c.getDefinition(), null, null));
                r1.setIcon("icon_extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
            }
        }
    } else {
        ElementDefinition ved = null;
        for (ElementDefinition ted : ed.getSnapshot().getElement()) {
            if (ted.getPath().startsWith("Extension.value"))
                ved = ted;
        }
        genTypes(gen, r, ved, defFile, ed, corePath);
        r.setIcon("icon_extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
    }
    Cell c = gen.new Cell("", "", "URL = " + ed.getUrl(), null, null);
    c.addPiece(gen.new Piece("br")).addPiece(gen.new Piece(null, ed.getName() + ": " + ed.getDescription(), null));
    c.addPiece(gen.new Piece("br")).addPiece(gen.new Piece(null, describeExtensionContext(ed), null));
    r.getCells().add(c);
    try {
        return gen.generate(model, corePath, 0, outputTracker);
    } catch (org.hl7.fhir.exceptions.FHIRException e) {
        throw new FHIRException(e.getMessage(), e);
    }
}
Also used : HierarchicalTableGenerator(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator) FHIRException(org.hl7.fhir.exceptions.FHIRException) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) List(java.util.List) ArrayList(java.util.ArrayList) FHIRException(org.hl7.fhir.exceptions.FHIRException) ElementDefinition(org.hl7.fhir.dstu2016may.model.ElementDefinition) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) TableModel(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)

Example 24 with HierarchicalTableGenerator

use of org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method genElement.

private void genElement(String defPath, HierarchicalTableGenerator gen, List<Row> rows, ElementDefinition element, List<ElementDefinition> all, List<StructureDefinition> profiles, boolean showMissing, String profileBaseFileName, Boolean extensions, boolean snapshot, String corePath, boolean root, boolean logicalModel) throws IOException {
    StructureDefinition profile = profiles == null ? null : profiles.get(profiles.size() - 1);
    String s = tail(element.getPath());
    List<ElementDefinition> children = getChildren(all, element);
    boolean isExtension = (s.equals("extension") || s.equals("modifierExtension"));
    if (!snapshot && isExtension && extensions != null && extensions != isExtension)
        return;
    if (!onlyInformationIsMapping(all, element)) {
        Row row = gen.new Row();
        row.setAnchor(element.getPath());
        row.setColor(getRowColor(element));
        boolean hasDef = element != null;
        boolean ext = false;
        if (s.equals("extension") || s.equals("modifierExtension")) {
            if (element.hasType() && element.getType().get(0).hasProfile() && extensionIsComplex(element.getType().get(0).getProfile().get(0).getValue()))
                row.setIcon("icon_extension_complex.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX);
            else
                row.setIcon("icon_extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
            ext = true;
        } else if (!hasDef || element.getType().size() == 0)
            row.setIcon("icon_element.gif", HierarchicalTableGenerator.TEXT_ICON_ELEMENT);
        else if (hasDef && element.getType().size() > 1) {
            if (allTypesAre(element.getType(), "Reference"))
                row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
            else
                row.setIcon("icon_choice.gif", HierarchicalTableGenerator.TEXT_ICON_CHOICE);
        } else if (hasDef && element.getType().get(0).getCode() != null && element.getType().get(0).getCode().startsWith("@"))
            row.setIcon("icon_reuse.png", HierarchicalTableGenerator.TEXT_ICON_REUSE);
        else if (hasDef && isPrimitive(element.getType().get(0).getCode()))
            row.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
        else if (hasDef && isReference(element.getType().get(0).getCode()))
            row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
        else if (hasDef && isDataType(element.getType().get(0).getCode()))
            row.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
        else
            row.setIcon("icon_resource.png", HierarchicalTableGenerator.TEXT_ICON_RESOURCE);
        String ref = defPath == null ? null : defPath + makePathLink(element);
        UnusedTracker used = new UnusedTracker();
        used.used = true;
        Cell left = gen.new Cell(null, ref, s, !hasDef ? null : element.getDefinition(), null);
        row.getCells().add(left);
        Cell gc = gen.new Cell();
        row.getCells().add(gc);
        if (element != null && element.getIsModifier())
            checkForNoChange(element.getIsModifierElement(), gc.addStyledText("This element is a modifier element", "?!", null, null, null, false));
        if (element != null && element.getMustSupport())
            checkForNoChange(element.getMustSupportElement(), gc.addStyledText("This element must be supported", "S", null, null, null, false));
        if (element != null && element.getIsSummary())
            checkForNoChange(element.getIsSummaryElement(), gc.addStyledText("This element is included in summaries", "∑", null, null, null, false));
        if (element != null && (!element.getConstraint().isEmpty() || !element.getCondition().isEmpty()))
            gc.addStyledText("This element has or is affected by some invariants", "I", null, null, null, false);
        ExtensionContext extDefn = null;
        if (ext) {
            if (element != null && element.getType().size() == 1 && element.getType().get(0).hasProfile()) {
                extDefn = locateExtension(StructureDefinition.class, element.getType().get(0).getProfile().get(0).getValue());
                if (extDefn == null) {
                    genCardinality(gen, element, row, hasDef, used, null);
                    row.getCells().add(gen.new Cell(null, null, "?? " + element.getType().get(0).getProfile(), null, null));
                    generateDescription(gen, row, element, null, used.used, profile.getUrl(), element.getType().get(0).getProfile().get(0).getValue(), profile, corePath, root, logicalModel);
                } else {
                    String name = urltail(element.getType().get(0).getProfile().get(0).getValue());
                    left.getPieces().get(0).setText(name);
                    // left.getPieces().get(0).setReference((String) extDefn.getExtensionStructure().getTag("filename"));
                    left.getPieces().get(0).setHint("Extension URL = " + extDefn.getUrl());
                    genCardinality(gen, element, row, hasDef, used, extDefn.getElement());
                    ElementDefinition valueDefn = extDefn.getExtensionValueDefinition();
                    if (valueDefn != null && !"0".equals(valueDefn.getMax()))
                        genTypes(gen, row, valueDefn, profileBaseFileName, profile, corePath);
                    else
                        // if it's complex, we just call it nothing
                        // genTypes(gen, row, extDefn.getSnapshot().getElement().get(0), profileBaseFileName, profile);
                        row.getCells().add(gen.new Cell(null, null, "(Complex)", null, null));
                    generateDescription(gen, row, element, extDefn.getElement(), used.used, null, extDefn.getUrl(), profile, corePath, root, logicalModel);
                }
            } else {
                genCardinality(gen, element, row, hasDef, used, null);
                if ("0".equals(element.getMax()))
                    row.getCells().add(gen.new Cell());
                else
                    genTypes(gen, row, element, profileBaseFileName, profile, corePath);
                generateDescription(gen, row, element, null, used.used, null, null, profile, corePath, root, logicalModel);
            }
        } else {
            genCardinality(gen, element, row, hasDef, used, null);
            if (hasDef && !"0".equals(element.getMax()))
                genTypes(gen, row, element, profileBaseFileName, profile, corePath);
            else
                row.getCells().add(gen.new Cell());
            generateDescription(gen, row, element, null, used.used, null, null, profile, corePath, root, logicalModel);
        }
        if (element.hasSlicing()) {
            if (standardExtensionSlicing(element)) {
                used.used = element.hasType() && element.getType().get(0).hasProfile();
                showMissing = false;
            } else {
                row.setIcon("icon_slice.png", HierarchicalTableGenerator.TEXT_ICON_SLICE);
                row.getCells().get(2).getPieces().clear();
                for (Cell cell : row.getCells()) for (Piece p : cell.getPieces()) {
                    p.addStyle("font-style: italic");
                }
            }
        }
        if (used.used || showMissing)
            rows.add(row);
        if (!used.used && !element.hasSlicing()) {
            for (Cell cell : row.getCells()) for (Piece p : cell.getPieces()) {
                p.setStyle("text-decoration:line-through");
                p.setReference(null);
            }
        } else {
            for (ElementDefinition child : children) if (logicalModel || !child.getPath().endsWith(".id"))
                genElement(defPath, gen, row.getSubRows(), child, all, profiles, showMissing, profileBaseFileName, isExtension, snapshot, corePath, false, logicalModel);
            if (!snapshot && (extensions == null || !extensions))
                for (ElementDefinition child : children) if (child.getPath().endsWith(".extension"))
                    genElement(defPath, gen, row.getSubRows(), child, all, profiles, showMissing, profileBaseFileName, true, false, corePath, false, logicalModel);
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.dstu2016may.model.StructureDefinition) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) ElementDefinition(org.hl7.fhir.dstu2016may.model.ElementDefinition) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

Example 25 with HierarchicalTableGenerator

use of org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method generateDescription.

private Cell generateDescription(HierarchicalTableGenerator gen, Row row, ElementDefinition definition, ElementDefinition fallback, boolean used, String baseURL, String url, StructureDefinition profile, String corePath, String imagePath, boolean root, boolean logicalModel, boolean allInvariants, ElementDefinition valueDefn, boolean snapshot, boolean mustSupportOnly, boolean allowSubRows, RenderingContext rc) throws IOException, FHIRException {
    Cell c = gen.new Cell();
    row.getCells().add(c);
    if (used) {
        if (logicalModel && ToolingExtensions.hasExtension(profile, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace")) {
            if (root) {
                c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML Namespace") + ": ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(profile, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"), null));
            } else if (!root && ToolingExtensions.hasExtension(definition, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace") && !ToolingExtensions.readStringExtension(definition, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").equals(ToolingExtensions.readStringExtension(profile, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"))) {
                c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML Namespace") + ": ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(definition, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"), null));
            }
        }
        if (root) {
            if (profile != null && profile.getAbstract()) {
                if (!c.getPieces().isEmpty()) {
                    c.addPiece(gen.new Piece("br"));
                }
                c.addPiece(gen.new Piece(null, "This is an abstract profile", null));
            }
        }
        if (definition.getPath().endsWith("url") && definition.hasFixed()) {
            c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "\"" + buildJson(definition.getFixed()) + "\"", null).addStyle("color: darkgreen")));
        } else {
            if (definition != null && definition.hasShort()) {
                if (!c.getPieces().isEmpty()) {
                    c.addPiece(gen.new Piece("br"));
                }
                c.addPiece(checkForNoChange(definition.getShortElement(), gen.new Piece(null, gt(definition.getShortElement()), null)));
            } else if (fallback != null && fallback.hasShort()) {
                if (!c.getPieces().isEmpty()) {
                    c.addPiece(gen.new Piece("br"));
                }
                c.addPiece(gen.new Piece(null, gt(fallback.getShortElement()), null).addStyle("opacity: 0.5"));
            }
            if (url != null) {
                if (!c.getPieces().isEmpty())
                    c.addPiece(gen.new Piece("br"));
                String fullUrl = url.startsWith("#") ? baseURL + url : url;
                StructureDefinition ed = context.fetchResource(StructureDefinition.class, url);
                String ref = null;
                String ref2 = null;
                String fixedUrl = null;
                if (ed != null) {
                    String p = ed.getUserString("path");
                    if (p != null) {
                        ref = p.startsWith("http:") || igmode ? p : Utilities.pathURL(corePath, p);
                    }
                    fixedUrl = getFixedUrl(ed);
                    if (fixedUrl != null) {
                        // if its null, we guess that it's not a profiled extension?
                        if (fixedUrl.equals(url))
                            fixedUrl = null;
                        else {
                            StructureDefinition ed2 = context.fetchResource(StructureDefinition.class, fixedUrl);
                            if (ed2 != null) {
                                String p2 = ed2.getUserString("path");
                                if (p2 != null) {
                                    ref2 = p2.startsWith("http:") || igmode ? p2 : Utilities.pathURL(corePath, p2);
                                }
                            }
                        }
                    }
                }
                if (fixedUrl == null) {
                    c.getPieces().add(gen.new Piece(null, translate("sd.table", "URL") + ": ", null).addStyle("font-weight:bold"));
                    c.getPieces().add(gen.new Piece(ref, fullUrl, null));
                } else {
                    // reference to a profile take on the extension show the base URL
                    c.getPieces().add(gen.new Piece(null, translate("sd.table", "URL") + ": ", null).addStyle("font-weight:bold"));
                    c.getPieces().add(gen.new Piece(ref2, fixedUrl, null));
                    c.getPieces().add(gen.new Piece(null, translate("sd.table", " profiled by ") + " ", null).addStyle("font-weight:bold"));
                    c.getPieces().add(gen.new Piece(ref, fullUrl, null));
                }
            }
            if (definition.hasSlicing()) {
                if (!c.getPieces().isEmpty()) {
                    c.addPiece(gen.new Piece("br"));
                }
                c.getPieces().add(gen.new Piece(null, translate("sd.table", "Slice") + ": ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(null, describeSlice(definition.getSlicing()), null));
            }
            if (!definition.getPath().contains(".") && ToolingExtensions.hasExtension(profile, ToolingExtensions.EXT_BINDING_STYLE)) {
                if (!c.getPieces().isEmpty()) {
                    c.addPiece(gen.new Piece("br"));
                }
                c.getPieces().add(gen.new Piece(null, translate("sd.table", "Binding") + ": ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(null, "This type can be bound to a value set using the ", null));
                c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(profile, ToolingExtensions.EXT_BINDING_STYLE), null));
                c.getPieces().add(gen.new Piece(null, " binding style", null));
            }
            if (definition.hasExtension(ToolingExtensions.EXT_XML_NAME)) {
                if (!c.getPieces().isEmpty()) {
                    c.addPiece(gen.new Piece("br"));
                }
                if (definition.hasExtension(ToolingExtensions.EXT_XML_NAMESPACE)) {
                    c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML") + ": ", null).addStyle("font-weight:bold"));
                    c.getPieces().add(gen.new Piece(null, definition.getExtensionString(ToolingExtensions.EXT_XML_NAME), null));
                    c.getPieces().add(gen.new Piece(null, " (", null));
                    c.getPieces().add(gen.new Piece(null, definition.getExtensionString(ToolingExtensions.EXT_XML_NAMESPACE), null));
                    c.getPieces().add(gen.new Piece(null, ")", null));
                } else {
                    c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML Element Name") + ": ", null).addStyle("font-weight:bold"));
                    c.getPieces().add(gen.new Piece(null, definition.getExtensionString(ToolingExtensions.EXT_XML_NAME), null));
                }
            } else if (definition.hasExtension(ToolingExtensions.EXT_XML_NAMESPACE)) {
                if (!c.getPieces().isEmpty()) {
                    c.addPiece(gen.new Piece("br"));
                }
                c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML Namespace") + ": ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(null, definition.getExtensionString(ToolingExtensions.EXT_XML_NAMESPACE), null));
            }
            if (definition != null) {
                ElementDefinitionBindingComponent binding = null;
                if (valueDefn != null && valueDefn.hasBinding() && !valueDefn.getBinding().isEmpty())
                    binding = makeUnifiedBinding(valueDefn.getBinding(), valueDefn);
                else if (definition.hasBinding())
                    binding = makeUnifiedBinding(definition.getBinding(), definition);
                if (binding != null && !binding.isEmpty()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    BindingResolution br = pkp == null ? makeNullBr(binding) : pkp.resolveBinding(profile, binding, definition.getPath());
                    c.getPieces().add(checkForNoChange(binding, gen.new Piece(null, translate("sd.table", "Binding") + ": ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(binding.getValueSetElement(), gen.new Piece(br.url == null ? null : Utilities.isAbsoluteUrl(br.url) || !pkp.prependLinks() ? br.url : corePath + br.url, br.display, null)));
                    if (binding.hasStrength()) {
                        c.getPieces().add(checkForNoChange(binding.getStrengthElement(), gen.new Piece(null, " (", null)));
                        c.getPieces().add(checkForNoChange(binding.getStrengthElement(), gen.new Piece(corePath + "terminologies.html#" + binding.getStrength().toCode(), egt(binding.getStrengthElement()), binding.getStrength().getDefinition())));
                        c.getPieces().add(checkForNoChange(binding.getStrengthElement(), gen.new Piece(null, ")", null)));
                    }
                    if (binding.hasDescription() && MarkDownProcessor.isSimpleMarkdown(binding.getDescription())) {
                        c.getPieces().add(gen.new Piece(null, ": ", null));
                        c.addMarkdownNoPara(PublicationHacker.fixBindingDescriptions(context, binding.getDescriptionElement()).asStringValue(), checkForNoChange(PublicationHacker.fixBindingDescriptions(context, binding.getDescriptionElement())));
                    }
                    AdditionalBindingsRenderer abr = new AdditionalBindingsRenderer(pkp, corePath, profile, definition.getPath(), rc, null);
                    if (binding.hasExtension(ToolingExtensions.EXT_MAX_VALUESET)) {
                        abr.seeMaxBinding(ToolingExtensions.getExtension(binding, ToolingExtensions.EXT_MAX_VALUESET));
                    }
                    if (binding.hasExtension(ToolingExtensions.EXT_MIN_VALUESET)) {
                        abr.seeMinBinding(ToolingExtensions.getExtension(binding, ToolingExtensions.EXT_MIN_VALUESET));
                    }
                    if (binding.hasExtension(ToolingExtensions.EXT_BINDING_ADDITIONAL)) {
                        abr.seeAdditionalBindings(binding.getExtensionsByUrl(ToolingExtensions.EXT_BINDING_ADDITIONAL));
                    }
                    abr.render(gen, c);
                }
                for (ElementDefinitionConstraintComponent inv : definition.getConstraint()) {
                    if (!inv.hasSource() || profile == null || inv.getSource().equals(profile.getUrl()) || allInvariants) {
                        if (!c.getPieces().isEmpty())
                            c.addPiece(gen.new Piece("br"));
                        c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, inv.getKey() + ": ", null).addStyle("font-weight:bold")));
                        c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, gt(inv.getHumanElement()), null)));
                    }
                }
                if ((definition.hasBase() && "*".equals(definition.getBase().getMax())) || (definition.hasMax() && "*".equals(definition.getMax()))) {
                    if (c.getPieces().size() > 0)
                        c.addPiece(gen.new Piece("br"));
                    if (definition.hasOrderMeaning()) {
                        c.getPieces().add(gen.new Piece(null, "This repeating element order: " + definition.getOrderMeaning(), null));
                    } else {
                    // don't show this, this it's important: c.getPieces().add(gen.new Piece(null, "This repeating element has no defined order", null));
                    }
                }
                if (definition.hasFixed()) {
                    if (!c.getPieces().isEmpty()) {
                        c.addPiece(gen.new Piece("br"));
                    }
                    c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, translate("sd.table", "Fixed Value") + ": ", null).addStyle("font-weight:bold")));
                    if (!useTableForFixedValues || !allowSubRows || definition.getFixed().isPrimitive()) {
                        String s = buildJson(definition.getFixed());
                        String link = null;
                        if (Utilities.isAbsoluteUrl(s))
                            link = pkp.getLinkForUrl(corePath, s);
                        c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(link, s, null).addStyle("color: darkgreen")));
                    } else {
                        c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "As shown", null).addStyle("color: darkgreen")));
                        genFixedValue(gen, row, definition.getFixed(), snapshot, false, corePath, false);
                    }
                    if (isCoded(definition.getFixed()) && !hasDescription(definition.getFixed())) {
                        Piece p = describeCoded(gen, definition.getFixed());
                        if (p != null)
                            c.getPieces().add(p);
                    }
                } else if (definition.hasPattern()) {
                    if (!c.getPieces().isEmpty()) {
                        c.addPiece(gen.new Piece("br"));
                    }
                    c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, translate("sd.table", "Required Pattern") + ": ", null).addStyle("font-weight:bold")));
                    if (!useTableForFixedValues || !allowSubRows || definition.getPattern().isPrimitive())
                        c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, buildJson(definition.getPattern()), null).addStyle("color: darkgreen")));
                    else {
                        c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, "At least the following", null).addStyle("color: darkgreen")));
                        genFixedValue(gen, row, definition.getPattern(), snapshot, true, corePath, mustSupportOnly);
                    }
                } else if (definition.hasExample()) {
                    for (ElementDefinitionExampleComponent ex : definition.getExample()) {
                        if (!c.getPieces().isEmpty()) {
                            c.addPiece(gen.new Piece("br"));
                        }
                        c.getPieces().add(checkForNoChange(ex, gen.new Piece(null, translate("sd.table", "Example") + ("".equals("General") ? "" : " " + ex.getLabel()) + ": ", null).addStyle("font-weight:bold")));
                        c.getPieces().add(checkForNoChange(ex, gen.new Piece(null, buildJson(ex.getValue()), null).addStyle("color: darkgreen")));
                    }
                }
                if (definition.hasMaxLength() && definition.getMaxLength() != 0) {
                    if (!c.getPieces().isEmpty()) {
                        c.addPiece(gen.new Piece("br"));
                    }
                    c.getPieces().add(checkForNoChange(definition.getMaxLengthElement(), gen.new Piece(null, "Max Length: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getMaxLengthElement(), gen.new Piece(null, Integer.toString(definition.getMaxLength()), null).addStyle("color: darkgreen")));
                }
                if (profile != null) {
                    for (StructureDefinitionMappingComponent md : profile.getMapping()) {
                        if (md.hasExtension(ToolingExtensions.EXT_TABLE_NAME)) {
                            ElementDefinitionMappingComponent map = null;
                            for (ElementDefinitionMappingComponent m : definition.getMapping()) if (m.getIdentity().equals(md.getIdentity()))
                                map = m;
                            if (map != null) {
                                for (int i = 0; i < definition.getMapping().size(); i++) {
                                    c.addPiece(gen.new Piece("br"));
                                    c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(md, ToolingExtensions.EXT_TABLE_NAME) + ": " + map.getMap(), null));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return c;
}
Also used : ElementDefinitionExampleComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionExampleComponent) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) BindingResolution(org.hl7.fhir.r4b.conformance.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution) StructureDefinitionMappingComponent(org.hl7.fhir.r4b.model.StructureDefinition.StructureDefinitionMappingComponent) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) ElementDefinitionBindingComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent) ElementDefinitionConstraintComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionConstraintComponent) ElementDefinitionMappingComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionMappingComponent)

Aggregations

Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)99 Row (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)83 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)67 TableModel (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)51 HierarchicalTableGenerator (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator)45 ArrayList (java.util.ArrayList)25 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)17 FHIRException (org.hl7.fhir.exceptions.FHIRException)14 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)13 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)13 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)10 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)9 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)9 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)9 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)8 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)7 HashSet (java.util.HashSet)6 List (java.util.List)6 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)6 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)5