Search in sources :

Example 26 with UnusedTracker

use of org.hl7.fhir.r4b.conformance.ProfileUtilities.UnusedTracker in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method genCardinality.

private void genCardinality(HierarchicalTableGenerator gen, ElementDefinition definition, Row row, boolean hasDef, UnusedTracker tracker, ElementDefinition fallback) {
    IntegerType min = !hasDef ? new IntegerType() : definition.hasMinElement() ? definition.getMinElement() : new IntegerType();
    StringType max = !hasDef ? new StringType() : definition.hasMaxElement() ? definition.getMaxElement() : new StringType();
    if (min.isEmpty() && definition.getUserData(DERIVATION_POINTER) != null) {
        ElementDefinition base = (ElementDefinition) definition.getUserData(DERIVATION_POINTER);
        if (base.hasMinElement()) {
            min = base.getMinElement().copy();
            min.setUserData(DERIVATION_EQUALS, true);
        }
    }
    if (max.isEmpty() && definition.getUserData(DERIVATION_POINTER) != null) {
        ElementDefinition base = (ElementDefinition) definition.getUserData(DERIVATION_POINTER);
        if (base.hasMaxElement()) {
            max = base.getMaxElement().copy();
            max.setUserData(DERIVATION_EQUALS, true);
        }
    }
    if (min.isEmpty() && fallback != null)
        min = fallback.getMinElement();
    if (max.isEmpty() && fallback != null)
        max = fallback.getMaxElement();
    if (!max.isEmpty())
        tracker.used = !max.getValue().equals("0");
    Cell cell = gen.new Cell(null, null, null, null, null);
    row.getCells().add(cell);
    if (!min.isEmpty() || !max.isEmpty()) {
        cell.addPiece(checkForNoChange(min, gen.new Piece(null, !min.hasValue() ? "" : Integer.toString(min.getValue()), null)));
        cell.addPiece(checkForNoChange(min, max, gen.new Piece(null, "..", null)));
        cell.addPiece(checkForNoChange(min, gen.new Piece(null, !max.hasValue() ? "" : max.getValue(), null)));
    }
}
Also used : IntegerType(org.hl7.fhir.r4.model.IntegerType) StringType(org.hl7.fhir.r4.model.StringType) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

Example 27 with UnusedTracker

use of org.hl7.fhir.r4b.conformance.ProfileUtilities.UnusedTracker in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method genElementCells.

public List<Cell> genElementCells(HierarchicalTableGenerator gen, ElementDefinition element, String profileBaseFileName, boolean snapshot, String corePath, String imagePath, boolean root, boolean logicalModel, boolean allInvariants, StructureDefinition profile, Row typesRow, Row row, boolean hasDef, boolean ext, UnusedTracker used, String ref, String sName, Cell nameCell, boolean mustSupport, boolean allowSubRows, RenderingContext rc) throws IOException {
    List<Cell> res = new ArrayList<>();
    Cell gc = gen.new Cell();
    row.getCells().add(gc);
    res.add(gc);
    if (element != null && element.getIsModifier()) {
        checkForNoChange(element.getIsModifierElement(), gc.addStyledText(translate("sd.table", "This element is a modifier element"), "?!", null, null, null, false));
    }
    if (element != null && element.getMustSupport()) {
        checkForNoChange(element.getMustSupportElement(), gc.addStyledText(translate("sd.table", "This element must be supported"), "S", "white", "red", null, false));
    }
    if (element != null && element.getIsSummary()) {
        checkForNoChange(element.getIsSummaryElement(), gc.addStyledText(translate("sd.table", "This element is included in summaries"), "\u03A3", null, null, null, false));
    }
    if (element != null && (hasNonBaseConstraints(element.getConstraint()) || hasNonBaseConditions(element.getCondition()))) {
        gc.addStyledText(translate("sd.table", "This element has or is affected by some invariants (" + listConstraintsAndConditions(element) + ")"), "I", null, null, null, false);
    }
    ExtensionContext extDefn = null;
    if (ext) {
        if (element != null && element.getType().size() == 1 && element.getType().get(0).hasProfile()) {
            String eurl = element.getType().get(0).getProfile().get(0).getValue();
            extDefn = locateExtension(StructureDefinition.class, eurl);
            if (extDefn == null) {
                res.add(genCardinality(gen, element, row, hasDef, used, null));
                res.add(addCell(row, gen.new Cell(null, null, "?gen-e1? " + element.getType().get(0).getProfile(), null, null)));
                res.add(generateDescription(gen, row, element, (ElementDefinition) element.getUserData(DERIVATION_POINTER), used.used, profile == null ? "" : profile.getUrl(), eurl, profile, corePath, imagePath, root, logicalModel, allInvariants, snapshot, mustSupport, allowSubRows, rc));
            } else {
                String name = urltail(eurl);
                nameCell.getPieces().get(0).setText(name);
                // left.getPieces().get(0).setReference((String) extDefn.getExtensionStructure().getTag("filename"));
                nameCell.getPieces().get(0).setHint(translate("sd.table", "Extension URL") + " = " + extDefn.getUrl());
                res.add(genCardinality(gen, element, row, hasDef, used, extDefn.getElement()));
                ElementDefinition valueDefn = extDefn.getExtensionValueDefinition();
                if (valueDefn != null && !"0".equals(valueDefn.getMax()))
                    res.add(genTypes(gen, row, valueDefn, profileBaseFileName, profile, corePath, imagePath, root, mustSupport));
                else
                    // if it's complex, we just call it nothing
                    // genTypes(gen, row, extDefn.getSnapshot().getElement().get(0), profileBaseFileName, profile);
                    res.add(addCell(row, gen.new Cell(null, null, "(" + translate("sd.table", "Complex") + ")", null, null)));
                res.add(generateDescription(gen, row, element, extDefn.getElement(), used.used, null, extDefn.getUrl(), profile, corePath, imagePath, root, logicalModel, allInvariants, valueDefn, snapshot, mustSupport, allowSubRows, rc));
            }
        } else {
            res.add(genCardinality(gen, element, row, hasDef, used, null));
            if ("0".equals(element.getMax()))
                res.add(addCell(row, gen.new Cell()));
            else
                res.add(genTypes(gen, row, element, profileBaseFileName, profile, corePath, imagePath, root, mustSupport));
            res.add(generateDescription(gen, row, element, (ElementDefinition) element.getUserData(DERIVATION_POINTER), used.used, null, null, profile, corePath, imagePath, root, logicalModel, allInvariants, snapshot, mustSupport, allowSubRows, rc));
        }
    } else {
        res.add(genCardinality(gen, element, row, hasDef, used, null));
        if (hasDef && !"0".equals(element.getMax()) && typesRow == null)
            res.add(genTypes(gen, row, element, profileBaseFileName, profile, corePath, imagePath, root, mustSupport));
        else
            res.add(addCell(row, gen.new Cell()));
        res.add(generateDescription(gen, row, element, (ElementDefinition) element.getUserData(DERIVATION_POINTER), used.used, null, null, profile, corePath, imagePath, root, logicalModel, allInvariants, snapshot, mustSupport, allowSubRows, rc));
    }
    return res;
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

Example 28 with UnusedTracker

use of org.hl7.fhir.r4b.conformance.ProfileUtilities.UnusedTracker 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 29 with UnusedTracker

use of org.hl7.fhir.r4b.conformance.ProfileUtilities.UnusedTracker in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method describeCardinality.

private String describeCardinality(ElementDefinition definition, ElementDefinition fallback, UnusedTracker tracker) {
    IntegerType min = definition.hasMinElement() ? definition.getMinElement() : new IntegerType();
    StringType max = definition.hasMaxElement() ? definition.getMaxElement() : new StringType();
    if (min.isEmpty() && fallback != null)
        min = fallback.getMinElement();
    if (max.isEmpty() && fallback != null)
        max = fallback.getMaxElement();
    tracker.used = !max.isEmpty() && !max.getValue().equals("0");
    if (min.isEmpty() && max.isEmpty())
        return null;
    else
        return (!min.hasValue() ? "" : Integer.toString(min.getValue())) + ".." + (!max.hasValue() ? "" : max.getValue());
}
Also used : IntegerType(org.hl7.fhir.r4b.model.IntegerType) StringType(org.hl7.fhir.r4b.model.StringType)

Example 30 with UnusedTracker

use of org.hl7.fhir.r4b.conformance.ProfileUtilities.UnusedTracker in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method genGridElement.

private void genGridElement(String defPath, HierarchicalTableGenerator gen, List<Row> rows, ElementDefinition element, List<ElementDefinition> all, List<StructureDefinition> profiles, boolean showMissing, String profileBaseFileName, Boolean extensions, String corePath, String imagePath, boolean root, boolean isConstraintMode) throws IOException, FHIRException {
    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 (!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;
        String ref = defPath == null ? null : defPath + element.getId();
        UnusedTracker used = new UnusedTracker();
        used.used = true;
        Cell left = gen.new Cell();
        if (element.getType().size() == 1 && element.getType().get(0).isPrimitive())
            left.getPieces().add(gen.new Piece(ref, "\u00A0\u00A0" + s, !hasDef ? null : gt(element.getDefinitionElement())).addStyle("font-weight:bold"));
        else
            left.getPieces().add(gen.new Piece(ref, "\u00A0\u00A0" + s, !hasDef ? null : gt(element.getDefinitionElement())));
        if (element.hasSliceName()) {
            left.getPieces().add(gen.new Piece("br"));
            String indent = StringUtils.repeat('\u00A0', 1 + 2 * (element.getPath().split("\\.").length));
            left.getPieces().add(gen.new Piece(null, indent + "(" + element.getSliceName() + ")", null));
        }
        row.getCells().add(left);
        ExtensionContext extDefn = null;
        genCardinality(gen, element, row, hasDef, used, null);
        if (hasDef && !"0".equals(element.getMax()))
            genTypes(gen, row, element, profileBaseFileName, profile, corePath, imagePath, root, false);
        else
            row.getCells().add(gen.new Cell());
        generateGridDescription(gen, row, element, null, used.used, null, null, profile, corePath, imagePath, root, null);
        /*      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");
            }
        }
      }*/
        rows.add(row);
        for (ElementDefinition child : children) if (child.getMustSupport())
            genGridElement(defPath, gen, row.getSubRows(), child, all, profiles, showMissing, profileBaseFileName, isExtension, corePath, imagePath, false, isConstraintMode);
    }
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

Aggregations

Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)28 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)22 Row (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)18 ArrayList (java.util.ArrayList)8 List (java.util.List)6 HierarchicalTableGenerator (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator)6 TableModel (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)6 FHIRException (org.hl7.fhir.exceptions.FHIRException)5 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)5 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)5 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)4 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)4 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)3 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)3 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)3 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)3 IntegerType (org.hl7.fhir.dstu2.model.IntegerType)2 StringType (org.hl7.fhir.dstu2.model.StringType)2 IntegerType (org.hl7.fhir.dstu2016may.model.IntegerType)2 StringType (org.hl7.fhir.dstu2016may.model.StringType)2