Search in sources :

Example 6 with Slice

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

the class ProfileUtilities method genElement.

private void genElement(String defPath, HierarchicalTableGenerator gen, List<Row> rows, ElementDefinition element, List<ElementDefinition> all, List<StructureDefinition> profiles, boolean showMissing, String profileBaseFileName, Boolean extensions, boolean snapshot, String corePath, String imagePath, boolean root, boolean logicalModel, boolean isConstraintMode, boolean allInvariants) throws IOException {
    StructureDefinition profile = profiles == null ? null : profiles.get(profiles.size() - 1);
    String s = tail(element.getPath());
    List<ElementDefinition> children = getChildren(all, element);
    boolean isExtension = (s.equals("extension") || s.equals("modifierExtension"));
    if (!snapshot && isExtension && extensions != null && extensions != isExtension)
        return;
    if (!onlyInformationIsMapping(all, element)) {
        Row row = gen.new Row();
        row.setAnchor(element.getPath());
        row.setColor(getRowColor(element, isConstraintMode));
        boolean hasDef = element != null;
        boolean ext = false;
        if (s.equals("extension")) {
            if (element.hasType() && element.getType().get(0).hasProfile() && extensionIsComplex(element.getType().get(0).getProfile()))
                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 (s.equals("modifierExtension")) {
            if (element.hasType() && element.getType().get(0).hasProfile() && extensionIsComplex(element.getType().get(0).getProfile()))
                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 (allTypesAre(element.getType(), "Reference"))
                row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
            else
                row.setIcon("icon_choice.gif", HierarchicalTableGenerator.TEXT_ICON_CHOICE);
        } else if (hasDef && element.getType().get(0).getCode() != null && element.getType().get(0).getCode().startsWith("@"))
            row.setIcon("icon_reuse.png", HierarchicalTableGenerator.TEXT_ICON_REUSE);
        else if (hasDef && isPrimitive(element.getType().get(0).getCode()))
            row.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
        else if (hasDef && isReference(element.getType().get(0).getCode()))
            row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
        else if (hasDef && isDataType(element.getType().get(0).getCode()))
            row.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
        else
            row.setIcon("icon_resource.png", HierarchicalTableGenerator.TEXT_ICON_RESOURCE);
        String ref = defPath == null ? null : defPath + element.getId();
        UnusedTracker used = new UnusedTracker();
        used.used = true;
        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()) {
                extDefn = locateExtension(StructureDefinition.class, element.getType().get(0).getProfile());
                if (extDefn == null) {
                    genCardinality(gen, element, row, hasDef, used, null);
                    row.getCells().add(gen.new Cell(null, null, "?? " + element.getType().get(0).getProfile(), null, null));
                    generateDescription(gen, row, element, null, used.used, profile.getUrl(), element.getType().get(0).getProfile(), profile, corePath, imagePath, root, logicalModel, allInvariants);
                } else {
                    String name = urltail(element.getType().get(0).getProfile());
                    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);
                }
            } 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);
            }
        } else {
            genCardinality(gen, element, row, hasDef, used, null);
            if (hasDef && !"0".equals(element.getMax()))
                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);
        }
        if (element.hasSlicing()) {
            if (standardExtensionSlicing(element)) {
                used.used = element.hasType() && element.getType().get(0).hasProfile();
                showMissing = false;
            } else {
                row.setIcon("icon_slice.png", HierarchicalTableGenerator.TEXT_ICON_SLICE);
                row.getCells().get(2).getPieces().clear();
                for (Cell cell : row.getCells()) for (Piece p : cell.getPieces()) {
                    p.addStyle("font-style: italic");
                }
            }
        }
        if (used.used || showMissing)
            rows.add(row);
        if (!used.used && !element.hasSlicing()) {
            for (Cell cell : row.getCells()) for (Piece p : cell.getPieces()) {
                p.setStyle("text-decoration:line-through");
                p.setReference(null);
            }
        } else {
            for (ElementDefinition child : children) if (logicalModel || !child.getPath().endsWith(".id") || (child.getPath().endsWith(".id") && (profile != null) && (profile.getDerivation() == TypeDerivationRule.CONSTRAINT)))
                genElement(defPath, gen, row.getSubRows(), child, all, profiles, showMissing, profileBaseFileName, isExtension, snapshot, corePath, imagePath, false, logicalModel, isConstraintMode, allInvariants);
            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);
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

Example 7 with Slice

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

the class ProfileUtilities method makeExtensionSlicing.

private ElementDefinitionSlicingComponent makeExtensionSlicing() {
    ElementDefinitionSlicingComponent slice = new ElementDefinitionSlicingComponent();
    nextSliceId++;
    slice.setId(Integer.toString(nextSliceId));
    slice.addDiscriminator().setPath("url").setType(DiscriminatorType.VALUE);
    slice.setOrdered(false);
    slice.setRules(SlicingRules.OPEN);
    return slice;
}
Also used : ElementDefinitionSlicingComponent(org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionSlicingComponent)

Example 8 with Slice

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

the class ProfileUtilities method summariseSlicing.

private String summariseSlicing(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.dstu3.model.ElementDefinition.ElementDefinitionSlicingDiscriminatorComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 9 with Slice

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

the class ProfileUtilities method generateGridDescription.

private Cell generateGridDescription(HierarchicalTableGenerator gen, Row row, ElementDefinition definition, ElementDefinition fallback, boolean used, String baseURL, String url, StructureDefinition profile, String corePath, String imagePath, boolean root, ElementDefinition valueDefn) throws IOException {
    Cell c = gen.new Cell();
    row.getCells().add(c);
    if (used) {
        if (definition.hasContentReference()) {
            ElementDefinition ed = getElementByName(profile.getSnapshot().getElement(), definition.getContentReference());
            if (ed == null)
                c.getPieces().add(gen.new Piece(null, "Unknown reference to " + definition.getContentReference(), null));
            else
                c.getPieces().add(gen.new Piece("#" + ed.getPath(), "See " + ed.getPath(), null));
        }
        if (definition.getPath().endsWith("url") && definition.hasFixed()) {
            c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "\"" + buildJson(definition.getFixed()) + "\"", null).addStyle("color: darkgreen")));
        } else {
            if (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, "URL: ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(ref, fullUrl, null));
            }
            if (definition.hasSlicing()) {
                if (!c.getPieces().isEmpty())
                    c.addPiece(gen.new Piece("br"));
                c.getPieces().add(gen.new Piece(null, "Slice: ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(null, describeSlice(definition.getSlicing()), null));
            }
            if (definition != null) {
                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, "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(), binding.getStrength().toCode(), binding.getStrength().getDefinition())));
                        c.getPieces().add(gen.new Piece(null, ")", null));
                    }
                }
                for (ElementDefinitionConstraintComponent inv : definition.getConstraint()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, inv.getKey() + ": ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, inv.getHuman(), null)));
                }
                if (definition.hasFixed()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "Fixed Value: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, buildJson(definition.getFixed()), null).addStyle("color: darkgreen")));
                } else if (definition.hasPattern()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, "Required Pattern: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, buildJson(definition.getPattern()), null).addStyle("color: darkgreen")));
                } else if (definition.hasExample()) {
                    for (ElementDefinitionExampleComponent ex : definition.getExample()) {
                        if (!c.getPieces().isEmpty())
                            c.addPiece(gen.new Piece("br"));
                        c.getPieces().add(checkForNoChange(ex, gen.new Piece(null, "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));
                                }
                            }
                        }
                    }
                }
                if (definition.getComment() != null) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    c.getPieces().add(gen.new Piece(null, "Comments: ", null).addStyle("font-weight:bold"));
                    c.addPiece(gen.new Piece("br"));
                    c.addMarkdown(definition.getComment());
                // c.getPieces().add(checkForNoChange(definition.getCommentElement(), gen.new Piece(null, definition.getComment(), 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 10 with Slice

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

the class ProfileUtilities method determineSlicing.

private void determineSlicing(ElementDefinition slicer, List<ElementDefinition> slices) {
    // first, name them
    int i = 0;
    for (ElementDefinition ed : slices) {
        if (ed.hasUserData("slice-name")) {
            ed.setSliceName(ed.getUserString("slice-name"));
        } else {
            i++;
            ed.setSliceName("slice-" + Integer.toString(i));
        }
    }
    // right now, we hard code this...
    if (slicer.getPath().endsWith(".extension") || slicer.getPath().endsWith(".modifierExtension"))
        slicer.getSlicing().addDiscriminator().setType(DiscriminatorType.VALUE).setPath("url");
    else if (slicer.getPath().equals("DiagnosticReport.result"))
        slicer.getSlicing().addDiscriminator().setType(DiscriminatorType.VALUE).setPath("reference.code");
    else if (slicer.getPath().equals("Observation.related"))
        slicer.getSlicing().addDiscriminator().setType(DiscriminatorType.VALUE).setPath("target.reference.code");
    else if (slicer.getPath().equals("Bundle.entry"))
        slicer.getSlicing().addDiscriminator().setType(DiscriminatorType.VALUE).setPath("resource.@profile");
    else
        throw new Error("No slicing for " + slicer.getPath());
}
Also used : FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition)

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