Search in sources :

Example 56 with Slice

use of org.hl7.elm.r1.Slice in project kindling by HL7.

the class PageProcessor method describeSlice.

private String describeSlice(String path, ElementDefinitionSlicingComponent slicing) {
    if (!slicing.hasDiscriminator())
        return "<li>There is a slice with no discriminator at " + path + "</li>\r\n";
    String s = "";
    if (slicing.getOrdered())
        s = "ordered";
    if (slicing.getRules() != SlicingRules.OPEN)
        s = Utilities.noString(s) ? slicing.getRules().getDisplay() : s + ", " + slicing.getRules().getDisplay();
    if (!Utilities.noString(s))
        s = " (" + s + ")";
    CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
    for (ElementDefinitionSlicingDiscriminatorComponent d : slicing.getDiscriminator()) b.append(d.getType().toCode() + ":" + d.getPath());
    if (slicing.getDiscriminator().size() == 1)
        return "<li>The element " + path + " is sliced based on the value of " + b.toString() + s + "</li>\r\n";
    else
        return "<li>The element " + path + " is sliced based on the values of " + b.toString() + s + "</li>\r\n";
}
Also used : ElementDefinitionSlicingDiscriminatorComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingDiscriminatorComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 57 with Slice

use of org.hl7.elm.r1.Slice in project kindling by HL7.

the class OldSpreadsheetParser method processLine.

private ElementDefn processLine(ResourceDefn root, Sheet sheet, int row, Map<String, Invariant> invariants, boolean profile, Profile pack, boolean firstTime) throws Exception {
    ElementDefn e;
    String path = sheet.getColumn(row, "Element");
    if (path.startsWith("!"))
        return null;
    if (Utilities.noString(path))
        throw new Exception("Error reading definitions - no path found @ " + getLocation(row));
    if (path.contains("#"))
        throw new Exception("Old path style @ " + getLocation(row));
    String profileName = isProfile ? sheet.getColumn(row, "Profile Name") : "";
    String discriminator = isProfile ? sheet.getColumn(row, "Discriminator") : "";
    boolean isRoot = !path.contains(".");
    if (isRoot) {
        if (root.getRoot() != null)
            throw new Exception("Definitions in " + getLocation(row) + " contain two roots: " + path + " in " + root.getName());
        root.setName(path);
        e = new TypeDefn();
        e.setName(path);
        root.setRoot((TypeDefn) e);
        if (template != null)
            e.copyFrom(template.getRoot(), root.getName(), templateTitle);
    } else {
        e = makeFromPath(root.getRoot(), path, row, profileName, true);
        if (template != null) {
            ElementDefn ted = getTemplateDefinition(path);
            if (ted != null) {
                e.copyFrom(ted, root.getName(), templateTitle);
            }
        }
    }
    e.setStandardsStatus(StandardsStatus.fromCode(sheet.getColumn(row, "Standards-Status")));
    e.setNormativeVersion(sheet.getColumn(row, "Normative-Version"));
    if (e.getName().startsWith("@")) {
        e.setName(e.getName().substring(1));
        e.setXmlAttribute(true);
    }
    String c = sheet.getColumn(row, "Card.");
    if (c == null || c.equals("") || c.startsWith("!")) {
        if (!isRoot && !profile && (template == null))
            throw new Exception("Missing cardinality at " + getLocation(row) + " on " + path);
        if (isRoot && (template == null)) {
            e.setMinCardinality(0);
            e.setMaxCardinality(Integer.MAX_VALUE);
        }
    } else {
        String[] card = c.split("\\.\\.");
        if (card.length != 2 || !Utilities.isInteger(card[0]) || (!"*".equals(card[1]) && !Utilities.isInteger(card[1])))
            throw new Exception("Unable to parse Cardinality '" + c + "' " + c + " in " + getLocation(row) + " on " + path);
        e.setMinCardinality(Integer.parseInt(card[0]));
        e.setMaxCardinality("*".equals(card[1]) ? Integer.MAX_VALUE : Integer.parseInt(card[1]));
    }
    if (profileName.startsWith("#"))
        throw new Exception("blah: " + profileName);
    e.setProfileName(profileName);
    e.setSliceDescription(isProfile ? sheet.getColumn(row, "Slice Description") : "");
    for (String d : discriminator.split("\\,")) if (!Utilities.noString(d))
        e.getDiscriminator().add(d);
    doAliases(sheet, row, e);
    if (sheet.hasColumn(row, "Must Understand"))
        throw new Exception("Column 'Must Understand' has been renamed to 'Is Modifier'");
    if (sheet.hasColumn(row, "Is Modifier")) {
        e.setIsModifier(parseBoolean(sheet.getColumn(row, "Is Modifier"), row, null));
        String reason = sheet.getColumn(row, "Modifier Reason");
        if (Utilities.noString(reason) && e.getName().toLowerCase().contains("status") && sheet.getColumn(row, "Short Name").contains("error"))
            reason = "This element is labelled as a modifier because it is a status element that contains status entered-in-error which means that the resource should not be treated as valid";
        if (Utilities.noString(reason) && e.getName().equals("active"))
            reason = "This element is labelled as a modifier because it is a status element that can indicate that a record should not be treated as valid";
        if (Utilities.noString(reason)) {
            System.out.println("Missing IsModifierReason on " + path);
            reason = "Not known why this is labelled a modifier";
        }
        e.setModifierReason(reason);
    }
    if (isProfile) {
        // later, this will get hooked in from the underlying definitions, but we need to know this now to validate the extension modifier matching
        if (e.getName().equals("modifierExtension"))
            e.setIsModifier(true);
        e.setMustSupport(parseBoolean(sheet.getColumn(row, "Must Support"), row, null));
    }
    if (sheet.hasColumn(row, "Summary"))
        e.setSummaryItem(parseBoolean(sheet.getColumn(row, "Summary"), row, null));
    e.setRegex(sheet.getColumn(row, "Regex"));
    String uml = sheet.getColumn(row, "UML");
    if (uml != null) {
        if (uml.contains(";")) {
            String[] parts = uml.split("\\;");
            e.setSvgLeft(Integer.parseInt(parts[0]));
            e.setSvgTop(Integer.parseInt(parts[1]));
            if (parts.length > 2)
                e.setSvgWidth(Integer.parseInt(parts[2]));
            e.setUmlDir("");
        } else if (uml.startsWith("break:")) {
            e.setUmlBreak(true);
            e.setUmlDir(uml.substring(6));
        } else {
            e.setUmlDir(uml);
        }
    }
    String s = sheet.getColumn(row, "Condition");
    if (s != null && !s.equals(""))
        throw new Exception("Found Condition in spreadsheet " + getLocation(row));
    s = sheet.getColumn(row, "Inv.");
    if (s != null && !s.equals("")) {
        for (String sn : s.split(",")) {
            if (!sn.startsWith("!")) {
                Invariant inv = invariants.get(sn);
                if (inv == null)
                    throw new Exception("unable to find Invariant '" + sn + "' " + getLocation(row));
                e.getStatedInvariants().add(inv);
            }
        }
    }
    TypeParser tp = new TypeParser(version.toCode());
    e.getTypes().addAll(tp.parse(sheet.getColumn(row, "Type"), isProfile, profileExtensionBase, context, !path.contains("."), this.name));
    if (isRoot && e.getTypes().size() == 1 && definitions != null) {
        String t = e.getTypes().get(0).getName();
        if (definitions.getResourceTemplates().containsKey(t)) {
            // we've got a template in play.
            template = definitions.getResourceTemplates().get(t);
            templateTitle = Utilities.unCamelCase(e.getName());
            e.getTypes().get(0).setName(template.getRoot().getTypes().get(0).getName());
        } else if (definitions.getBaseResources().containsKey(t) && definitions.getBaseResources().get(t).isInterface()) {
            // we've got a template in play.
            template = definitions.getBaseResources().get(t);
            templateTitle = Utilities.unCamelCase(e.getName());
        }
    }
    if (isProfile && ((path.endsWith(".extension") || path.endsWith(".modifierExtension")) && (e.getTypes().size() == 1) && e.getTypes().get(0).hasProfile()) && Utilities.noString(profileName))
        throw new Exception("need to have a profile name if a profiled extension is referenced for " + e.getTypes().get(0).getProfile());
    if (sheet.hasColumn(row, "Concept Domain"))
        throw new Exception("Column 'Concept Domain' has been retired in " + path);
    String bindingName = sheet.getColumn(row, "Binding");
    if (!Utilities.noString(bindingName)) {
        BindingSpecification binding = bindings.get(bindingName);
        if (binding == null && definitions != null)
            binding = definitions.getCommonBindings().get(bindingName);
        if (binding == null) {
            if (bindingName.startsWith("!"))
                e.setNoBindingAllowed(true);
            else
                throw new Exception("Binding name " + bindingName + " could not be resolved in local spreadsheet");
        }
        e.setBinding(binding);
        if (binding != null && !binding.getUseContexts().contains(name))
            binding.getUseContexts().add(name);
    } else if (e.getBinding() != null) {
        if (!e.getBinding().getUseContexts().contains(name))
            e.getBinding().getUseContexts().add(name);
    }
    if (!Utilities.noString(sheet.getColumn(row, "Short Label")))
        throw new Exception("Short Label is no longer used");
    if (// todo: make this a warning when a fair chunk of the spreadsheets have been converted
    sheet.hasColumn(row, "Short Name"))
        if (sheet.getColumn(row, "Short Name").startsWith("&"))
            e.setShortDefn(e.getShortDefn() + sheet.getColumn(row, "Short Name").substring(1));
        else
            e.setShortDefn(sheet.getColumn(row, "Short Name"));
    if (!isProfile && e.getShortDefn() == null)
        throw new Exception("A short definition is required for " + e.getName() + " at " + getLocation(row));
    if (sheet.hasColumn(row, "Definition"))
        if (sheet.getColumn(row, "Definition").startsWith("&"))
            e.setDefinition(Utilities.appendPeriod(e.getDefinition() + processDefinition(sheet.getColumn(row, "Definition")).substring(1)));
        else
            e.setDefinition(Utilities.appendPeriod(processDefinition(sheet.getColumn(row, "Definition"))));
    if (isRoot) {
        root.setDefinition(e.getDefinition());
    }
    if (isProfile || isLogicalModel)
        e.setMaxLength(sheet.getColumn(row, "Max Length"));
    if (sheet.hasColumn(row, "Requirements"))
        if (sheet.getColumn(row, "Requirements").startsWith("&"))
            e.setRequirements(Utilities.appendPeriod(e.getRequirements() + sheet.getColumn(row, "Requirements").substring(1)));
        else
            e.setRequirements(Utilities.appendPeriod(sheet.getColumn(row, "Requirements")));
    if (sheet.hasColumn(row, "Comments"))
        if (sheet.getColumn(row, "Comments").startsWith("&"))
            e.setComments(Utilities.appendPeriod(e.getComments() + Utilities.appendPeriod(sheet.getColumn(row, "Comments").substring(1))));
        else
            e.setComments(Utilities.appendPeriod(Utilities.appendPeriod(sheet.getColumn(row, "Comments"))));
    for (String n : mappings.keySet()) {
        String ms = sheet.getColumn(row, mappings.get(n).getColumnName());
        if (mappings.get(n).getColumnName().equals("Snomed Code") && !Utilities.noString(ms))
            System.out.println("!!");
        e.addMapping(n, ms.trim());
    }
    if (pack != null) {
        for (String n : pack.getMappingSpaces().keySet()) {
            e.addMapping(n, sheet.getColumn(row, pack.getMappingSpaces().get(n).getColumnName()).trim());
        }
    }
    if (sheet.hasColumn("Hierarchy"))
        e.setHierarchy(parseBoolean(sheet.getColumn(row, "Hierarchy"), row, null));
    if (sheet.hasColumn(row, "To Do"))
        e.setTodo(Utilities.appendPeriod(sheet.getColumn(row, "To Do")));
    if (sheet.hasColumn(row, "Example"))
        e.setExample(processValue(sheet, row, "Example", sheet.getColumn(row, "Example"), e));
    processOtherExamples(e, sheet, row);
    if (sheet.hasColumn(row, "Committee Notes"))
        e.setCommitteeNotes(Utilities.appendPeriod(sheet.getColumn(row, "Committee Notes")));
    if (sheet.hasColumn(row, "Display Hint"))
        e.setDisplayHint(sheet.getColumn(row, "Display Hint"));
    if (isProfile) {
        e.setFixed(processValue(sheet, row, "Value", sheet.getColumn(row, "Value"), e));
        e.setPattern(processValue(sheet, row, "Pattern", sheet.getColumn(row, "Pattern"), e));
    } else {
        if (sheet.hasColumn(row, "Default Value"))
            errors.add(path + ": Default value '" + sheet.getColumn(row, "Default Value") + "' found @ " + getLocation(row));
        if (sheet.hasColumn(row, "Missing Meaning"))
            e.setMeaningWhenMissing(sheet.getColumn(row, "Missing Meaning"));
    }
    if (sheet.hasColumn(row, "w5"))
        e.setW5(checkW5(sheet.getColumn(row, "w5"), path));
    if (sheet.hasColumn(row, "Translatable"))
        e.setTranslatable(parseBoolean(sheet.getColumn(row, "Translatable"), row, false));
    if (sheet.hasColumn(row, "Order Meaning"))
        e.setOrderMeaning(sheet.getColumn(row, "Order Meaning"));
    return e;
}
Also used : TypeDefn(org.hl7.fhir.definitions.model.TypeDefn) Invariant(org.hl7.fhir.definitions.model.Invariant) TypeParser(org.hl7.fhir.definitions.parsers.TypeParser) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 58 with Slice

use of org.hl7.elm.r1.Slice 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) 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 (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;
                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 != 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));
                    }
                    if (binding.hasExtension(ToolingExtensions.EXT_MAX_VALUESET)) {
                        br = pkp.resolveBinding(profile, ToolingExtensions.readStringExtension(binding, ToolingExtensions.EXT_MAX_VALUESET), definition.getPath());
                        c.addPiece(gen.new Piece("br"));
                        c.getPieces().add(checkForNoChange(binding, gen.new Piece(corePath + "extension-elementdefinition-maxvalueset.html", translate("sd.table", "Max Binding") + ": ", "Max Value Set Extension").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.hasExtension(ToolingExtensions.EXT_MIN_VALUESET)) {
                        br = pkp.resolveBinding(profile, ToolingExtensions.readStringExtension(binding, ToolingExtensions.EXT_MIN_VALUESET), definition.getPath());
                        c.addPiece(gen.new Piece("br"));
                        c.getPieces().add(checkForNoChange(binding, gen.new Piece(corePath + "extension-elementdefinition-minvalueset.html", translate("sd.table", "Min Binding") + ": ", "Min Value Set Extension").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)));
                    }
                }
                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")));
                    if (!useTableForFixedValues || 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);
                    }
                    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 || 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);
                    }
                } 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.r4.model.ElementDefinition.ElementDefinitionExampleComponent) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) BindingResolution(org.hl7.fhir.r4.conformance.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution) StructureDefinitionMappingComponent(org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionMappingComponent) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) ElementDefinitionBindingComponent(org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionBindingComponent) ElementDefinitionConstraintComponent(org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionConstraintComponent) ElementDefinitionMappingComponent(org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionMappingComponent)

Example 59 with Slice

use of org.hl7.elm.r1.Slice 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) throws IOException, FHIRException {
    Row originalRow = slicingRow;
    StructureDefinition profile = profiles == null ? null : profiles.get(profiles.size() - 1);
    String s = tail(element.getPath());
    if (element.hasSliceName())
        s = s + ":" + element.getSliceName();
    Row typesRow = null;
    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;
        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)
            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
            row.setIcon("icon_resource.png", HierarchicalTableGenerator.TEXT_ICON_RESOURCE);
        String ref = defPath == null ? null : defPath + element.getId();
        UnusedTracker used = new UnusedTracker();
        used.used = true;
        if (logicalModel && element.hasRepresentation(PropertyRepresentation.XMLATTR))
            s = "@" + s;
        Cell left = gen.new Cell(null, ref, s, (element.hasSliceName() ? translate("sd.table", "Slice") + " " + element.getSliceName() : "") + (hasDef && element.hasSliceName() ? ": " : "") + (!hasDef ? null : gt(element.getDefinitionElement())), null);
        row.getCells().add(left);
        Cell gc = gen.new Cell();
        row.getCells().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 && (!element.getConstraint().isEmpty() || !element.getCondition().isEmpty()))
            gc.addStyledText(translate("sd.table", "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()) {
                String eurl = element.getType().get(0).getProfile().get(0).getValue();
                extDefn = locateExtension(StructureDefinition.class, eurl);
                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(), eurl, profile, corePath, imagePath, root, logicalModel, allInvariants, snapshot);
                } else {
                    String name = urltail(eurl);
                    left.getPieces().get(0).setText(name);
                    // left.getPieces().get(0).setReference((String) extDefn.getExtensionStructure().getTag("filename"));
                    left.getPieces().get(0).setHint(translate("sd.table", "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, imagePath);
                    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, "(" + translate("sd.table", "Complex") + ")", null, null));
                    generateDescription(gen, row, element, extDefn.getElement(), used.used, null, extDefn.getUrl(), profile, corePath, imagePath, root, logicalModel, allInvariants, valueDefn, snapshot);
                }
            } 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, imagePath);
                generateDescription(gen, row, element, null, used.used, null, null, profile, corePath, imagePath, root, logicalModel, allInvariants, snapshot);
            }
        } else {
            genCardinality(gen, element, row, hasDef, used, null);
            if (element.hasSlicing())
                row.getCells().add(gen.new Cell(null, corePath + "profiling.html#slicing", "(Slice Definition)", null, null));
            else if (hasDef && !"0".equals(element.getMax()) && typesRow == null)
                genTypes(gen, row, element, profileBaseFileName, profile, corePath, imagePath);
            else
                row.getCells().add(gen.new Cell());
            generateDescription(gen, row, element, null, used.used, null, null, profile, corePath, imagePath, root, logicalModel, allInvariants, snapshot);
        }
        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, "(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, "(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;
            for (ElementDefinition child : children) {
                if (!child.hasSliceName())
                    currRow = row;
                if (logicalModel || !child.getPath().endsWith(".id") || (child.getPath().endsWith(".id") && (profile != null) && (profile.getDerivation() == TypeDerivationRule.CONSTRAINT)))
                    currRow = genElement(defPath, gen, currRow.getSubRows(), child, all, profiles, showMissing, profileBaseFileName, isExtension, snapshot, corePath, imagePath, false, logicalModel, isConstraintMode, allInvariants, currRow);
            }
        // 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);
        }
    }
    return slicingRow;
}
Also used : StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

Example 60 with Slice

use of org.hl7.elm.r1.Slice in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method summarizeSlicing.

private String summarizeSlicing(ElementDefinitionSlicingComponent slice) {
    StringBuilder b = new StringBuilder();
    boolean first = true;
    for (ElementDefinitionSlicingDiscriminatorComponent d : slice.getDiscriminator()) {
        if (first)
            first = false;
        else
            b.append(", ");
        b.append(d);
    }
    b.append("(");
    if (slice.hasOrdered())
        b.append(slice.getOrderedElement().asStringValue());
    b.append("/");
    if (slice.hasRules())
        b.append(slice.getRules().toCode());
    b.append(")");
    if (slice.hasDescription()) {
        b.append(" \"");
        b.append(slice.getDescription());
        b.append("\"");
    }
    return b.toString();
}
Also used : ElementDefinitionSlicingDiscriminatorComponent(org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionSlicingDiscriminatorComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Aggregations

ArrayList (java.util.ArrayList)21 FHIRException (org.hl7.fhir.exceptions.FHIRException)19 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)16 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)16 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)15 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)14 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)10 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)10 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)10 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)9 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)9 List (java.util.List)8 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)8 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)8 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)7 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)7 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)6 StructureDefinition (org.hl7.fhir.dstu2.model.StructureDefinition)5 Color (com.livinglogic.ul4.Color)3 MonthDelta (com.livinglogic.ul4.MonthDelta)3