Search in sources :

Example 1 with BindingResolution

use of org.hl7.fhir.r4.conformance.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution in project kindling by HL7.

the class PageProcessor method resolveBinding.

public BindingResolution resolveBinding(StructureDefinition profile, String ref, String description, String path) throws FHIRException {
    BindingResolution br = new BindingResolution();
    if (ref.contains("|"))
        ref = ref.substring(0, ref.indexOf("|"));
    if (ref.startsWith("http://terminology.hl7.org/ValueSet/v3-") || ref.startsWith("http://terminology.hl7.org/ValueSet/v2-")) {
        ValueSet vs = workerContext.fetchResource(ValueSet.class, ref);
        if (vs == null) {
            br.url = "v3/" + ref.substring(39) + "/vs.html";
            br.display = ref.substring(39);
        } else {
            br.url = vs.getUserString("path");
            br.display = vs.present();
        }
    } else if (definitions.getValuesets().has(ref)) {
        ValueSet vs = definitions.getValuesets().get(ref);
        br.url = vs.getUserString("path");
        br.display = vs.present();
    } else if (ref.startsWith("ValueSet/")) {
        ValueSet vs = definitions.getValuesets().get(ref.substring(8));
        if (vs == null) {
            br.url = ref.substring(9) + ".html";
            br.display = ref.substring(9);
        } else {
            br.url = vs.getUserString("path");
            br.display = vs.present();
        }
    } else if (ref.startsWith("http://hl7.org/fhir/ValueSet/")) {
        ValueSet vs = definitions.getValuesets().get(ref);
        if (vs == null)
            vs = definitions.getExtraValuesets().get(ref);
        if (vs != null) {
            br.url = vs.getUserString("path");
            if (Utilities.noString(br.url))
                br.url = ref.substring(23) + ".html";
            br.display = vs.present();
        } else if (ref.substring(23).equals("use-context")) {
            // special case because this happens before the value set is created
            br.url = "valueset-" + ref.substring(23) + ".html";
            br.display = "Context of Use ValueSet";
        } else if (ref.startsWith("http://terminology.hl7.org/ValueSet/v3-")) {
            br.url = "v3/" + ref.substring(26) + "/index.html";
            br.display = ref.substring(26);
        } else if (ref.startsWith("http://terminology.hl7.org/ValueSet/v2-")) {
            br.url = "v2/" + ref.substring(26) + "/index.html";
            br.display = ref.substring(26);
        } else if (ref.startsWith("#")) {
            br.url = null;
            br.display = ref;
        } else {
            br.url = ref;
            br.display = "????";
            getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.NOTFOUND, -1, -1, path, "Unresolved Value set " + ref, IssueSeverity.WARNING));
        }
    } else {
        br.url = ref;
        if (ref.equals("http://tools.ietf.org/html/bcp47"))
            br.display = "IETF BCP-47";
        else if (ref.equals("http://www.rfc-editor.org/bcp/bcp13.txt"))
            br.display = "IETF BCP-13";
        else if (ref.equals("http://www.ncbi.nlm.nih.gov/nuccore?db=nuccore"))
            br.display = "NucCore";
        else if (ref.equals("https://rtmms.nist.gov/rtmms/index.htm#!rosetta"))
            br.display = "Rosetta";
        else if (ref.equals("http://www.iso.org/iso/country_codes.htm"))
            br.display = "ISO Country Codes";
        else if (ref.equals("http://www.ncbi.nlm.nih.gov/clinvar/variation"))
            br.display = "ClinVar";
        else if (!Utilities.noString(description))
            br.display = description;
        else
            br.display = "????";
    }
    return br;
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 2 with BindingResolution

use of org.hl7.fhir.r4.conformance.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution 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 3 with BindingResolution

use of org.hl7.fhir.r4.conformance.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution 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 4 with BindingResolution

use of org.hl7.fhir.r4.conformance.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution 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) throws IOException {
    Cell c = gen.new Cell();
    row.getCells().add(c);
    if (used) {
        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, definition.getShort(), null)));
            } else if (fallback != null && fallback != null && fallback.hasShort()) {
                if (!c.getPieces().isEmpty())
                    c.addPiece(gen.new Piece("br"));
                c.addPiece(checkForNoChange(fallback.getShortElement(), gen.new Piece(null, fallback.getShort(), 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 = ed == null ? null : (String) corePath + ed.getUserData("path");
                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) {
                if (definition.hasBinding()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    BindingResolution br = pkp.resolveBinding(definition.getBinding());
                    c.getPieces().add(checkForNoChange(definition.getBinding(), gen.new Piece(null, "Binding: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getBinding(), gen.new Piece(br.url == null ? null : Utilities.isAbsoluteUrl(br.url) ? br.url : corePath + br.url, br.display, null)));
                    if (definition.getBinding().hasStrength()) {
                        c.getPieces().add(checkForNoChange(definition.getBinding(), gen.new Piece(null, " (", null)));
                        c.getPieces().add(checkForNoChange(definition.getBinding(), gen.new Piece(corePath + "terminologies.html#" + definition.getBinding().getStrength().toCode(), definition.getBinding().getStrength().toCode(), definition.getBinding().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()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    c.getPieces().add(checkForNoChange(definition.getExample(), gen.new Piece(null, "Example: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getExample(), gen.new Piece(null, buildJson(definition.getExample()), null).addStyle("color: darkgreen")));
                }
            }
        }
    }
    return c;
}
Also used : StructureDefinition(org.hl7.fhir.dstu2.model.StructureDefinition) BindingResolution(org.hl7.fhir.dstu2.utils.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) ElementDefinitionConstraintComponent(org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionConstraintComponent)

Example 5 with BindingResolution

use of org.hl7.fhir.r4.conformance.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution 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, boolean root, boolean logicalModel) throws IOException {
    Cell c = gen.new Cell();
    row.getCells().add(c);
    if (used) {
        if (logicalModel && ToolingExtensions.hasExtension(profile, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace")) {
            if (root) {
                c.getPieces().add(gen.new Piece(null, "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, "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, "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 (definition != null && definition.hasShort()) {
                if (!c.getPieces().isEmpty())
                    c.addPiece(gen.new Piece("br"));
                c.addPiece(checkForNoChange(definition.getShortElement(), gen.new Piece(null, definition.getShort(), null)));
            } else if (fallback != null && fallback != null && fallback.hasShort()) {
                if (!c.getPieces().isEmpty())
                    c.addPiece(gen.new Piece("br"));
                c.addPiece(checkForNoChange(fallback.getShortElement(), gen.new Piece(null, fallback.getShort(), 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 = ed == null ? null : (String) corePath + ed.getUserData("path");
                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) {
                if (definition.hasBinding()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    BindingResolution br = pkp.resolveBinding(definition.getBinding());
                    c.getPieces().add(checkForNoChange(definition.getBinding(), gen.new Piece(null, "Binding: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getBinding(), gen.new Piece(br.url == null ? null : Utilities.isAbsoluteUrl(br.url) ? br.url : corePath + br.url, br.display, null)));
                    if (definition.getBinding().hasStrength()) {
                        c.getPieces().add(checkForNoChange(definition.getBinding(), gen.new Piece(null, " (", null)));
                        c.getPieces().add(checkForNoChange(definition.getBinding(), gen.new Piece(corePath + "terminologies.html#" + definition.getBinding().getStrength().toCode(), definition.getBinding().getStrength().toCode(), definition.getBinding().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()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    c.getPieces().add(checkForNoChange(definition.getExample(), gen.new Piece(null, "Example: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getExample(), gen.new Piece(null, buildJson(definition.getExample()), null).addStyle("color: darkgreen")));
                }
            }
        }
    }
    return c;
}
Also used : StructureDefinition(org.hl7.fhir.dstu2016may.model.StructureDefinition) BindingResolution(org.hl7.fhir.dstu2016may.utils.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) ElementDefinition(org.hl7.fhir.dstu2016may.model.ElementDefinition) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) ElementDefinitionConstraintComponent(org.hl7.fhir.dstu2016may.model.ElementDefinition.ElementDefinitionConstraintComponent)

Aggregations

Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)14 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)14 BindingResolution (org.hl7.fhir.r4b.conformance.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution)6 BindingResolution (org.hl7.fhir.r5.conformance.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 HierarchicalTableGenerator (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator)4 Row (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)4 TableModel (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)4 BindingResolution (org.hl7.fhir.dstu3.conformance.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution)3 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)3 BindingResolution (org.hl7.fhir.r4.conformance.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution)3 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)3 ElementDefinitionBindingComponent (org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionBindingComponent)2 ElementDefinitionConstraintComponent (org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionConstraintComponent)2 ElementDefinitionExampleComponent (org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionExampleComponent)2 ElementDefinitionMappingComponent (org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionMappingComponent)2 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)2 StructureDefinitionMappingComponent (org.hl7.fhir.dstu3.model.StructureDefinition.StructureDefinitionMappingComponent)2