Search in sources :

Example 86 with ElementDefinition

use of org.hl7.fhir.r4.model.ElementDefinition in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method generateExtensionTable.

public XhtmlNode generateExtensionTable(String defFile, StructureDefinition ed, String imageFolder, boolean inlineGraphics, boolean full, String corePath, String imagePath, Set<String> outputTracker) throws IOException, FHIRException {
    HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics);
    gen.setTranslator(getTranslator());
    TableModel model = gen.initNormalTable(corePath, false, true, ed.getId(), false);
    boolean deep = false;
    String m = "";
    boolean vdeep = false;
    if (ed.getSnapshot().getElementFirstRep().getIsModifier())
        m = "modifier_";
    for (ElementDefinition eld : ed.getSnapshot().getElement()) {
        deep = deep || eld.getPath().contains("Extension.extension.");
        vdeep = vdeep || eld.getPath().contains("Extension.extension.extension.");
    }
    Row r = gen.new Row();
    model.getRows().add(r);
    r.getCells().add(gen.new Cell(null, defFile == null ? "" : defFile + "-definitions.html#extension." + ed.getName(), ed.getSnapshot().getElement().get(0).getIsModifier() ? "modifierExtension" : "extension", null, null));
    r.getCells().add(gen.new Cell());
    r.getCells().add(gen.new Cell(null, null, describeCardinality(ed.getSnapshot().getElement().get(0), null, new UnusedTracker()), null, null));
    ElementDefinition ved = null;
    if (full || vdeep) {
        r.getCells().add(gen.new Cell("", "", "Extension", null, null));
        r.setIcon(deep ? "icon_" + m + "extension_complex.png" : "icon_extension_simple.png", deep ? HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX : HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
        List<ElementDefinition> children = getChildren(ed.getSnapshot().getElement(), ed.getSnapshot().getElement().get(0));
        for (ElementDefinition child : children) if (!child.getPath().endsWith(".id"))
            genElement(defFile == null ? "" : defFile + "-definitions.html#extension.", gen, r.getSubRows(), child, ed.getSnapshot().getElement(), null, true, defFile, true, full, corePath, imagePath, true, false, false, false);
    } else if (deep) {
        List<ElementDefinition> children = new ArrayList<ElementDefinition>();
        for (ElementDefinition ted : ed.getSnapshot().getElement()) {
            if (ted.getPath().equals("Extension.extension"))
                children.add(ted);
        }
        r.getCells().add(gen.new Cell("", "", "Extension", null, null));
        r.setIcon("icon_" + m + "extension_complex.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX);
        for (ElementDefinition c : children) {
            ved = getValueFor(ed, c);
            ElementDefinition ued = getUrlFor(ed, c);
            if (ved != null && ued != null) {
                Row r1 = gen.new Row();
                r.getSubRows().add(r1);
                r1.getCells().add(gen.new Cell(null, defFile == null ? "" : defFile + "-definitions.html#extension." + ed.getName(), ((UriType) ued.getFixed()).getValue(), null, null));
                r1.getCells().add(gen.new Cell());
                r1.getCells().add(gen.new Cell(null, null, describeCardinality(c, null, new UnusedTracker()), null, null));
                genTypes(gen, r1, ved, defFile, ed, corePath, imagePath);
                r1.getCells().add(gen.new Cell(null, null, c.getDefinition(), null, null));
                r1.setIcon("icon_" + m + "extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
            }
        }
    } else {
        for (ElementDefinition ted : ed.getSnapshot().getElement()) {
            if (ted.getPath().startsWith("Extension.value"))
                ved = ted;
        }
        genTypes(gen, r, ved, defFile, ed, corePath, imagePath);
        r.setIcon("icon_" + m + "extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
    }
    Cell c = gen.new Cell("", "", "URL = " + ed.getUrl(), null, null);
    c.addPiece(gen.new Piece("br")).addPiece(gen.new Piece(null, ed.getName() + ": " + ed.getDescription(), null));
    if (!full && !(deep || vdeep) && ved != null && ved.hasBinding()) {
        c.addPiece(gen.new Piece("br"));
        BindingResolution br = pkp.resolveBinding(ed, ved.getBinding(), ved.getPath());
        c.getPieces().add(checkForNoChange(ved.getBinding(), gen.new Piece(null, translate("sd.table", "Binding") + ": ", null).addStyle("font-weight:bold")));
        c.getPieces().add(checkForNoChange(ved.getBinding(), gen.new Piece(br.url == null ? null : Utilities.isAbsoluteUrl(br.url) || !pkp.prependLinks() ? br.url : corePath + br.url, br.display, null)));
        if (ved.getBinding().hasStrength()) {
            c.getPieces().add(checkForNoChange(ved.getBinding(), gen.new Piece(null, " (", null)));
            c.getPieces().add(checkForNoChange(ved.getBinding(), gen.new Piece(corePath + "terminologies.html#" + ved.getBinding().getStrength().toCode(), egt(ved.getBinding().getStrengthElement()), ved.getBinding().getStrength().getDefinition())));
            c.getPieces().add(gen.new Piece(null, ")", null));
        }
    }
    c.addPiece(gen.new Piece("br")).addPiece(gen.new Piece(null, describeExtensionContext(ed), null));
    r.getCells().add(c);
    try {
        return gen.generate(model, corePath, 0, outputTracker);
    } catch (org.hl7.fhir.exceptions.FHIRException e) {
        throw new FHIRException(e.getMessage(), e);
    }
}
Also used : BindingResolution(org.hl7.fhir.dstu3.conformance.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution) HierarchicalTableGenerator(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator) FHIRException(org.hl7.fhir.exceptions.FHIRException) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) List(java.util.List) ArrayList(java.util.ArrayList) FHIRException(org.hl7.fhir.exceptions.FHIRException) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) TableModel(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)

Example 87 with ElementDefinition

use of org.hl7.fhir.r4.model.ElementDefinition in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method generateCsvs.

// generate a CSV representation of the structure definition
public void generateCsvs(OutputStream dest, StructureDefinition structure, boolean asXml) throws IOException, DefinitionException, Exception {
    if (!structure.hasSnapshot())
        throw new DefinitionException("needs a snapshot");
    CSVWriter csv = new CSVWriter(dest, structure, asXml);
    for (ElementDefinition child : structure.getSnapshot().getElement()) {
        csv.processElement(child);
    }
    csv.dump();
}
Also used : CSVWriter(org.hl7.fhir.dstu3.utils.formats.CSVWriter) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition)

Example 88 with ElementDefinition

use of org.hl7.fhir.r4.model.ElementDefinition 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.dstu3.model.IntegerType) StringType(org.hl7.fhir.dstu3.model.StringType) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

Example 89 with ElementDefinition

use of org.hl7.fhir.r4.model.ElementDefinition in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method generateSlicer.

private Slicer generateSlicer(ElementDefinition child, ElementDefinitionSlicingComponent slicing, StructureDefinition structure) {
    // given a child in a structure, it's sliced. figure out the slicing xpath
    if (child.getPath().endsWith(".extension")) {
        ElementDefinition ued = getUrlFor(structure, child);
        if ((ued == null || !ued.hasFixed()) && !(child.hasType() && (child.getType().get(0).hasProfile())))
            return new Slicer(false);
        else {
            Slicer s = new Slicer(true);
            String url = (ued == null || !ued.hasFixed()) ? child.getType().get(0).getProfile() : ((UriType) ued.getFixed()).asStringValue();
            s.name = " with URL = '" + url + "'";
            s.criteria = "[@url = '" + url + "']";
            return s;
        }
    } else
        return new Slicer(false);
}
Also used : ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition)

Example 90 with ElementDefinition

use of org.hl7.fhir.r4.model.ElementDefinition in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method buildSpanEntryFromProfile.

private SpanEntry buildSpanEntryFromProfile(String name, String cardinality, StructureDefinition profile) throws IOException {
    SpanEntry res = new SpanEntry();
    res.setName(name);
    res.setCardinality(cardinality);
    res.setProfileLink(profile.getUserString("path"));
    res.setResType(profile.getType());
    StructureDefinition base = context.fetchResource(StructureDefinition.class, res.getResType());
    if (base != null)
        res.setResLink(base.getUserString("path"));
    res.setId(profile.getId());
    res.setProfile(profile.getDerivation() == TypeDerivationRule.CONSTRAINT);
    StringBuilder b = new StringBuilder();
    b.append(res.getResType());
    boolean first = true;
    boolean open = false;
    if (profile.getDerivation() == TypeDerivationRule.CONSTRAINT) {
        res.setDescription(profile.getName());
        for (ElementDefinition ed : profile.getSnapshot().getElement()) {
            if (isKeyProperty(ed.getBase().getPath()) && ed.hasFixed()) {
                if (first) {
                    open = true;
                    first = false;
                    b.append("[");
                } else {
                    b.append(", ");
                }
                b.append(tail(ed.getBase().getPath()));
                b.append("=");
                b.append(summarise(ed.getFixed()));
            }
        }
        if (open)
            b.append("]");
    } else
        res.setDescription("Base FHIR " + profile.getName());
    res.setType(b.toString());
    return res;
}
Also used : StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition)

Aggregations

ArrayList (java.util.ArrayList)226 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)199 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)120 FHIRException (org.hl7.fhir.exceptions.FHIRException)116 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)92 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)91 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)85 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)82 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)68 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)60 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)57 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)51 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)50 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)46 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)44 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)42 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)41 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)41 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)38 List (java.util.List)37