Search in sources :

Example 26 with LogicalModel

use of org.hl7.fhir.definitions.model.LogicalModel in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method genElement.

private Row 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, String imagePath, boolean root, boolean logicalModel, boolean isConstraintMode, boolean allInvariants, Row slicingRow, boolean mustSupport, RenderingContext rc) throws IOException, FHIRException {
    Row originalRow = slicingRow;
    StructureDefinition profile = profiles == null ? null : profiles.get(profiles.size() - 1);
    Row typesRow = null;
    List<ElementDefinition> children = getChildren(all, element);
    if (!onlyInformationIsMapping(all, element)) {
        Row row = gen.new Row();
        row.setAnchor(element.getPath());
        row.setColor(getRowColor(element, isConstraintMode));
        if (element.hasSlicing())
            row.setLineColor(1);
        else if (element.hasSliceName())
            row.setLineColor(2);
        else
            row.setLineColor(0);
        boolean hasDef = element != null;
        boolean ext = false;
        if (tail(element.getPath()).equals("extension")) {
            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 (tail(element.getPath()).equals("modifierExtension")) {
            if (element.hasType() && element.getType().get(0).hasProfile() && extensionIsComplex(element.getType().get(0).getProfile().get(0).getValue()))
                row.setIcon("icon_modifier_extension_complex.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX);
            else
                row.setIcon("icon_modifier_extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
        } else if (!hasDef || element.getType().size() == 0) {
            if (root && context.getResourceNames().contains(profile.getType())) {
                row.setIcon("icon_resource.png", HierarchicalTableGenerator.TEXT_ICON_RESOURCE);
            } else {
                row.setIcon("icon_element.gif", HierarchicalTableGenerator.TEXT_ICON_ELEMENT);
            }
        } else if (hasDef && element.getType().size() > 1) {
            if (allAreReference(element.getType())) {
                row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
            } else {
                row.setIcon("icon_choice.gif", HierarchicalTableGenerator.TEXT_ICON_CHOICE);
                typesRow = row;
            }
        } else if (hasDef && element.getType().get(0).getWorkingCode() != null && element.getType().get(0).getWorkingCode().startsWith("@")) {
            row.setIcon("icon_reuse.png", HierarchicalTableGenerator.TEXT_ICON_REUSE);
        } else if (hasDef && isPrimitive(element.getType().get(0).getWorkingCode())) {
            row.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
        } else if (hasDef && element.getType().get(0).hasTarget()) {
            row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
        } else if (hasDef && isDataType(element.getType().get(0).getWorkingCode())) {
            row.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
        } else if (hasDef && Utilities.existsInList(element.getType().get(0).getWorkingCode(), "Element", "BackboneElement")) {
            row.setIcon("icon_element.gif", HierarchicalTableGenerator.TEXT_ICON_ELEMENT);
        } else {
            row.setIcon("icon_resource.png", HierarchicalTableGenerator.TEXT_ICON_RESOURCE);
        }
        if (element.hasUserData("render.opaque")) {
            row.setOpacity("0.5");
        }
        UnusedTracker used = new UnusedTracker();
        String ref = defPath == null ? null : defPath + element.getId();
        String sName = tail(element.getPath());
        if (element.hasSliceName())
            sName = sName + ":" + element.getSliceName();
        used.used = true;
        if (logicalModel && element.hasRepresentation(PropertyRepresentation.XMLATTR))
            sName = "@" + sName;
        Cell nc = genElementNameCell(gen, element, profileBaseFileName, snapshot, corePath, imagePath, root, logicalModel, allInvariants, profile, typesRow, row, hasDef, ext, used, ref, sName, all);
        genElementCells(gen, element, profileBaseFileName, snapshot, corePath, imagePath, root, logicalModel, allInvariants, profile, typesRow, row, hasDef, ext, used, ref, sName, nc, mustSupport, true, rc);
        if (element.hasSlicing()) {
            if (standardExtensionSlicing(element)) {
                // doesn't matter whether we have a type, we're used if we're setting up slicing ... element.hasType() && element.getType().get(0).hasProfile();
                used.used = true;
                // ?
                showMissing = false;
            } else {
                row.setIcon("icon_slice.png", HierarchicalTableGenerator.TEXT_ICON_SLICE);
                slicingRow = row;
                for (Cell cell : row.getCells()) for (Piece p : cell.getPieces()) {
                    p.addStyle("font-style: italic");
                }
            }
        } else if (element.hasSliceName()) {
            row.setIcon("icon_slice_item.png", HierarchicalTableGenerator.TEXT_ICON_SLICE_ITEM);
        }
        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 {
            if (slicingRow != originalRow && !children.isEmpty()) {
                // we've entered a slice; we're going to create a holder row for the slice children
                Row hrow = gen.new Row();
                hrow.setAnchor(element.getPath());
                hrow.setColor(getRowColor(element, isConstraintMode));
                hrow.setLineColor(1);
                hrow.setIcon("icon_element.gif", HierarchicalTableGenerator.TEXT_ICON_ELEMENT);
                hrow.getCells().add(gen.new Cell(null, null, sName + ":All Slices", "", null));
                hrow.getCells().add(gen.new Cell());
                hrow.getCells().add(gen.new Cell());
                hrow.getCells().add(gen.new Cell());
                hrow.getCells().add(gen.new Cell(null, null, "Content/Rules for all slices", "", null));
                row.getSubRows().add(hrow);
                row = hrow;
            }
            if (typesRow != null && !children.isEmpty()) {
                // we've entered a typing slice; we're going to create a holder row for the all types children
                Row hrow = gen.new Row();
                hrow.setAnchor(element.getPath());
                hrow.setColor(getRowColor(element, isConstraintMode));
                hrow.setLineColor(1);
                hrow.setIcon("icon_element.gif", HierarchicalTableGenerator.TEXT_ICON_ELEMENT);
                hrow.getCells().add(gen.new Cell(null, null, sName + ":All Types", "", null));
                hrow.getCells().add(gen.new Cell());
                hrow.getCells().add(gen.new Cell());
                hrow.getCells().add(gen.new Cell());
                hrow.getCells().add(gen.new Cell(null, null, "Content/Rules for all Types", "", null));
                row.getSubRows().add(hrow);
                row = hrow;
            }
            Row currRow = row;
            List<ElementChoiceGroup> groups = readChoices(element, children);
            boolean isExtension = Utilities.existsInList(tail(element.getPath()), "extension", "modifierExtension");
            for (ElementDefinition child : children) {
                if (!child.hasSliceName()) {
                    currRow = row;
                }
                Row childRow = chooseChildRowByGroup(gen, currRow, groups, child, element, isConstraintMode);
                if (logicalModel || !child.getPath().endsWith(".id") || (child.getPath().endsWith(".id") && (profile != null) && (profile.getDerivation() == TypeDerivationRule.CONSTRAINT))) {
                    currRow = genElement(defPath, gen, childRow.getSubRows(), child, all, profiles, showMissing, profileBaseFileName, isExtension, snapshot, corePath, imagePath, false, logicalModel, isConstraintMode, allInvariants, currRow, mustSupport, rc);
                }
            }
        // if (!snapshot && (extensions == null || !extensions))
        // for (ElementDefinition child : children)
        // if (child.getPath().endsWith(".extension") || child.getPath().endsWith(".modifierExtension"))
        // genElement(defPath, gen, row.getSubRows(), child, all, profiles, showMissing, profileBaseFileName, true, false, corePath, imagePath, false, logicalModel, isConstraintMode, allInvariants);
        }
        if (typesRow != null) {
            makeChoiceRows(typesRow.getSubRows(), element, gen, corePath, profileBaseFileName, mustSupport);
        }
    }
    return slicingRow;
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

Example 27 with LogicalModel

use of org.hl7.fhir.definitions.model.LogicalModel 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) 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, 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 (definition.hasContentReference()) {
            ElementDefinition ed = getElementByName(profile.getSnapshot().getElement(), definition.getContentReference());
            if (ed == null)
                c.getPieces().add(gen.new Piece(null, translate("sd.table", "Unknown reference to %s", definition.getContentReference()), null));
            else
                c.getPieces().add(gen.new Piece("#" + ed.getPath(), translate("sd.table", "See %s", 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, gt(definition.getShortElement()), null)));
            } else if (fallback != null && fallback.hasShort()) {
                if (!c.getPieces().isEmpty())
                    c.addPiece(gen.new Piece("br"));
                c.addPiece(checkForNoChange(fallback.getShortElement(), gen.new Piece(null, gt(fallback.getShortElement()), 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 = null;
                if (ed != null) {
                    String p = ed.getUserString("path");
                    if (p != null) {
                        ref = p.startsWith("http:") || igmode ? p : Utilities.pathURL(corePath, p);
                    }
                }
                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));
            }
            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 != null) {
                ElementDefinitionBindingComponent binding = null;
                if (valueDefn != null && valueDefn.hasBinding() && !valueDefn.getBinding().isEmpty())
                    binding = valueDefn.getBinding();
                else if (definition.hasBinding())
                    binding = definition.getBinding();
                if (binding != null && !binding.isEmpty()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    BindingResolution br = 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, 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, gen.new Piece(null, " (", null)));
                        c.getPieces().add(checkForNoChange(binding, gen.new Piece(corePath + "terminologies.html#" + binding.getStrength().toCode(), egt(binding.getStrengthElement()), binding.getStrength().getDefinition())));
                        c.getPieces().add(gen.new Piece(null, ")", null));
                    }
                }
                for (ElementDefinitionConstraintComponent inv : definition.getConstraint()) {
                    if (!inv.hasSource() || 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() && definition.getBase().getMax().equals("*")) || (definition.hasMax() && definition.getMax().equals("*"))) {
                    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")));
                    c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, buildJson(definition.getFixed()), null).addStyle("color: darkgreen")));
                    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")));
                    c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, buildJson(definition.getPattern()), null).addStyle("color: darkgreen")));
                } 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.dstu3.model.ElementDefinition.ElementDefinitionExampleComponent) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) BindingResolution(org.hl7.fhir.dstu3.conformance.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution) StructureDefinitionMappingComponent(org.hl7.fhir.dstu3.model.StructureDefinition.StructureDefinitionMappingComponent) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) ElementDefinitionBindingComponent(org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionBindingComponent) ElementDefinitionConstraintComponent(org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionConstraintComponent) ElementDefinitionMappingComponent(org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionMappingComponent)

Example 28 with LogicalModel

use of org.hl7.fhir.definitions.model.LogicalModel in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method genElement.

private Row 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, String imagePath, boolean root, boolean logicalModel, boolean isConstraintMode, boolean allInvariants, Row slicingRow, boolean mustSupport, RenderingContext rc) throws IOException, FHIRException {
    Row originalRow = slicingRow;
    StructureDefinition profile = profiles == null ? null : profiles.get(profiles.size() - 1);
    Row typesRow = null;
    List<ElementDefinition> children = getChildren(all, element);
    if (!onlyInformationIsMapping(all, element)) {
        Row row = gen.new Row();
        row.setAnchor(element.getPath());
        row.setColor(getRowColor(element, isConstraintMode));
        if (element.hasSlicing())
            row.setLineColor(1);
        else if (element.hasSliceName())
            row.setLineColor(2);
        else
            row.setLineColor(0);
        boolean hasDef = element != null;
        boolean ext = false;
        if (tail(element.getPath()).equals("extension")) {
            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 (tail(element.getPath()).equals("modifierExtension")) {
            if (element.hasType() && element.getType().get(0).hasProfile() && extensionIsComplex(element.getType().get(0).getProfile().get(0).getValue()))
                row.setIcon("icon_modifier_extension_complex.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX);
            else
                row.setIcon("icon_modifier_extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
        } else if (!hasDef || element.getType().size() == 0) {
            if (root && context.getResourceNames().contains(profile.getType())) {
                row.setIcon("icon_resource.png", HierarchicalTableGenerator.TEXT_ICON_RESOURCE);
            } else {
                row.setIcon("icon_element.gif", HierarchicalTableGenerator.TEXT_ICON_ELEMENT);
            }
        } else if (hasDef && element.getType().size() > 1) {
            if (allAreReference(element.getType())) {
                row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
            } else {
                row.setIcon("icon_choice.gif", HierarchicalTableGenerator.TEXT_ICON_CHOICE);
                typesRow = row;
            }
        } else if (hasDef && element.getType().get(0).getWorkingCode() != null && element.getType().get(0).getWorkingCode().startsWith("@")) {
            row.setIcon("icon_reuse.png", HierarchicalTableGenerator.TEXT_ICON_REUSE);
        } else if (hasDef && isPrimitive(element.getType().get(0).getWorkingCode())) {
            row.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
        } else if (hasDef && element.getType().get(0).hasTarget()) {
            row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
        } else if (hasDef && isDataType(element.getType().get(0).getWorkingCode())) {
            row.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
        } else if (hasDef && Utilities.existsInList(element.getType().get(0).getWorkingCode(), "Element", "BackboneElement")) {
            row.setIcon("icon_element.gif", HierarchicalTableGenerator.TEXT_ICON_ELEMENT);
        } else {
            row.setIcon("icon_resource.png", HierarchicalTableGenerator.TEXT_ICON_RESOURCE);
        }
        if (element.hasUserData("render.opaque")) {
            row.setOpacity("0.5");
        }
        UnusedTracker used = new UnusedTracker();
        String ref = defPath == null ? null : defPath + element.getId();
        String sName = tail(element.getPath());
        if (element.hasSliceName())
            sName = sName + ":" + element.getSliceName();
        used.used = true;
        if (logicalModel && element.hasRepresentation(PropertyRepresentation.XMLATTR))
            sName = "@" + sName;
        Cell nc = genElementNameCell(gen, element, profileBaseFileName, snapshot, corePath, imagePath, root, logicalModel, allInvariants, profile, typesRow, row, hasDef, ext, used, ref, sName, all);
        genElementCells(gen, element, profileBaseFileName, snapshot, corePath, imagePath, root, logicalModel, allInvariants, profile, typesRow, row, hasDef, ext, used, ref, sName, nc, mustSupport, true, rc);
        if (element.hasSlicing()) {
            if (standardExtensionSlicing(element)) {
                // doesn't matter whether we have a type, we're used if we're setting up slicing ... element.hasType() && element.getType().get(0).hasProfile();
                used.used = true;
                // ?
                showMissing = false;
            } else {
                row.setIcon("icon_slice.png", HierarchicalTableGenerator.TEXT_ICON_SLICE);
                slicingRow = row;
                for (Cell cell : row.getCells()) for (Piece p : cell.getPieces()) {
                    p.addStyle("font-style: italic");
                }
            }
        } else if (element.hasSliceName()) {
            row.setIcon("icon_slice_item.png", HierarchicalTableGenerator.TEXT_ICON_SLICE_ITEM);
        }
        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 {
            if (slicingRow != originalRow && !children.isEmpty()) {
                // we've entered a slice; we're going to create a holder row for the slice children
                Row hrow = gen.new Row();
                hrow.setAnchor(element.getPath());
                hrow.setColor(getRowColor(element, isConstraintMode));
                hrow.setLineColor(1);
                hrow.setIcon("icon_element.gif", HierarchicalTableGenerator.TEXT_ICON_ELEMENT);
                hrow.getCells().add(gen.new Cell(null, null, sName + ":All Slices", "", null));
                hrow.getCells().add(gen.new Cell());
                hrow.getCells().add(gen.new Cell());
                hrow.getCells().add(gen.new Cell());
                hrow.getCells().add(gen.new Cell(null, null, "Content/Rules for all slices", "", null));
                row.getSubRows().add(hrow);
                row = hrow;
            }
            if (typesRow != null && !children.isEmpty()) {
                // we've entered a typing slice; we're going to create a holder row for the all types children
                Row hrow = gen.new Row();
                hrow.setAnchor(element.getPath());
                hrow.setColor(getRowColor(element, isConstraintMode));
                hrow.setLineColor(1);
                hrow.setIcon("icon_element.gif", HierarchicalTableGenerator.TEXT_ICON_ELEMENT);
                hrow.getCells().add(gen.new Cell(null, null, sName + ":All Types", "", null));
                hrow.getCells().add(gen.new Cell());
                hrow.getCells().add(gen.new Cell());
                hrow.getCells().add(gen.new Cell());
                hrow.getCells().add(gen.new Cell(null, null, "Content/Rules for all Types", "", null));
                row.getSubRows().add(hrow);
                row = hrow;
            }
            Row currRow = row;
            List<ElementChoiceGroup> groups = readChoices(element, children);
            boolean isExtension = Utilities.existsInList(tail(element.getPath()), "extension", "modifierExtension");
            for (ElementDefinition child : children) {
                if (!child.hasSliceName()) {
                    currRow = row;
                }
                Row childRow = chooseChildRowByGroup(gen, currRow, groups, child, element, isConstraintMode);
                if (logicalModel || !child.getPath().endsWith(".id") || (child.getPath().endsWith(".id") && (profile != null) && (profile.getDerivation() == TypeDerivationRule.CONSTRAINT))) {
                    currRow = genElement(defPath, gen, childRow.getSubRows(), child, all, profiles, showMissing, profileBaseFileName, isExtension, snapshot, corePath, imagePath, false, logicalModel, isConstraintMode, allInvariants, currRow, mustSupport, rc);
                }
            }
        // if (!snapshot && (extensions == null || !extensions))
        // for (ElementDefinition child : children)
        // if (child.getPath().endsWith(".extension") || child.getPath().endsWith(".modifierExtension"))
        // genElement(defPath, gen, row.getSubRows(), child, all, profiles, showMissing, profileBaseFileName, true, false, corePath, imagePath, false, logicalModel, isConstraintMode, allInvariants);
        }
        if (typesRow != null) {
            makeChoiceRows(typesRow.getSubRows(), element, gen, corePath, profileBaseFileName, mustSupport);
        }
    }
    return slicingRow;
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

Example 29 with LogicalModel

use of org.hl7.fhir.definitions.model.LogicalModel in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method generateTable.

public XhtmlNode generateTable(String defFile, StructureDefinition profile, boolean diff, String imageFolder, boolean inlineGraphics, String profileBaseFileName, boolean snapshot, String corePath, String imagePath, boolean logicalModel, boolean allInvariants, Set<String> outputTracker, boolean active, boolean mustSupport, RenderingContext rc) throws IOException, FHIRException {
    // check it's ok to get rid of one of these
    assert (diff != snapshot);
    HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics, true);
    gen.setTranslator(getTranslator());
    TableModel model = gen.initNormalTable(corePath, false, true, profile.getId() + (diff ? "d" : "s"), active);
    List<ElementDefinition> list = new ArrayList<>();
    if (diff)
        list.addAll(profile.getDifferential().getElement());
    else
        list.addAll(profile.getSnapshot().getElement());
    List<StructureDefinition> profiles = new ArrayList<StructureDefinition>();
    profiles.add(profile);
    if (list.isEmpty()) {
        ElementDefinition root = new ElementDefinition().setPath(profile.getType());
        root.setId(profile.getType());
        list.add(root);
    } else {
        if (list.get(0).getPath().contains(".")) {
            ElementDefinition root = new ElementDefinition().setPath(profile.getType());
            root.setId(profile.getType());
            list.add(0, root);
        }
    }
    if (diff) {
        insertMissingSparseElements(list);
    }
    genElement(defFile == null ? null : defFile + "#", gen, model.getRows(), list.get(0), list, profiles, diff, profileBaseFileName, null, snapshot, corePath, imagePath, true, logicalModel, profile.getDerivation() == TypeDerivationRule.CONSTRAINT && usesMustSupport(list), allInvariants, null, mustSupport, rc);
    try {
        return gen.generate(model, imagePath, 0, outputTracker);
    } catch (org.hl7.fhir.exceptions.FHIRException e) {
        throw new FHIRException(context.formatMessage(I18nConstants.ERROR_GENERATING_TABLE_FOR_PROFILE__, profile.getUrl(), e.getMessage()), e);
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ArrayList(java.util.ArrayList) HierarchicalTableGenerator(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator) FHIRException(org.hl7.fhir.exceptions.FHIRException) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException) TableModel(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)

Aggregations

Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)14 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)10 ArrayList (java.util.ArrayList)9 LogicalModel (org.hl7.fhir.definitions.model.LogicalModel)9 FHIRException (org.hl7.fhir.exceptions.FHIRException)7 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)7 HierarchicalTableGenerator (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator)5 Row (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)5 TableModel (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)5 File (java.io.File)4 ImplementationGuideDefn (org.hl7.fhir.definitions.model.ImplementationGuideDefn)4 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)4 CSFile (org.hl7.fhir.utilities.CSFile)4 Profile (org.hl7.fhir.definitions.model.Profile)3 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)3 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)3 StructureDefinition (org.hl7.fhir.dstu2016may.model.StructureDefinition)3 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)3 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)3 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)3