Search in sources :

Example 41 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.

the class OperationDefinitionRenderer method genOpParam.

private void genOpParam(XhtmlNode tbl, String path, OperationDefinitionParameterComponent p) throws EOperationOutcome, FHIRException, IOException {
    XhtmlNode tr;
    tr = tbl.tr();
    tr.td().addText(p.getUse().toString());
    tr.td().addText(path + p.getName());
    tr.td().addText(Integer.toString(p.getMin()) + ".." + p.getMax());
    XhtmlNode td = tr.td();
    StructureDefinition sd = p.getType() != null ? context.getWorker().fetchTypeDefinition(p.getType().toCode()) : null;
    if (sd == null)
        td.tx(p.hasType() ? p.getType().toCode() : "");
    else if (sd.getAbstract() && p.hasExtension(ToolingExtensions.EXT_ALLOWED_TYPE)) {
        boolean first = true;
        for (Extension ex : p.getExtensionsByUrl(ToolingExtensions.EXT_ALLOWED_TYPE)) {
            if (first)
                first = false;
            else
                td.tx(" | ");
            String s = ex.getValue().primitiveValue();
            StructureDefinition sdt = context.getWorker().fetchTypeDefinition(s);
            if (sdt == null)
                td.tx(p.hasType() ? p.getType().toCode() : "");
            else
                td.ah(sdt.getUserString("path")).tx(s);
        }
    } else
        td.ah(sd.getUserString("path")).tx(p.hasType() ? p.getType().toCode() : "");
    if (p.hasSearchType()) {
        td.br();
        td.tx("(");
        td.ah(context.getSpecificationLink() == null ? "search.html#" + p.getSearchType().toCode() : Utilities.pathURL(context.getSpecificationLink(), "search.html#" + p.getSearchType().toCode())).tx(p.getSearchType().toCode());
        td.tx(")");
    }
    td = tr.td();
    if (p.hasBinding() && p.getBinding().hasValueSet()) {
        AddVsRef(p.getBinding().getValueSet(), td);
        td.tx(" (" + p.getBinding().getStrength().getDisplay() + ")");
    }
    addMarkdown(tr.td(), p.getDocumentation());
    if (!p.hasType()) {
        for (OperationDefinitionParameterComponent pp : p.getPart()) {
            genOpParam(tbl, path + p.getName() + ".", pp);
        }
    }
}
Also used : Extension(org.hl7.fhir.r5.model.Extension) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) OperationDefinitionParameterComponent(org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterComponent)

Example 42 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generate.

public boolean generate(ResourceContext rcontext, OperationDefinition opd) throws EOperationOutcome, FHIRException, IOException {
    XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
    x.h2().addText(opd.getName());
    x.para().addText(Utilities.capitalize(opd.getKind().toString()) + ": " + opd.getName());
    x.para().tx("The official URL for this operation definition is: ");
    x.pre().tx(opd.getUrl());
    addMarkdown(x, opd.getDescription());
    if (opd.getSystem())
        x.para().tx("URL: [base]/$" + opd.getCode());
    for (CodeType c : opd.getResource()) {
        if (opd.getType())
            x.para().tx("URL: [base]/" + c.getValue() + "/$" + opd.getCode());
        if (opd.getInstance())
            x.para().tx("URL: [base]/" + c.getValue() + "/[id]/$" + opd.getCode());
    }
    x.para().tx("Parameters");
    XhtmlNode tbl = x.table("grid");
    XhtmlNode tr = tbl.tr();
    tr.td().b().tx("Use");
    tr.td().b().tx("Name");
    tr.td().b().tx("Cardinality");
    tr.td().b().tx("Type");
    tr.td().b().tx("Binding");
    tr.td().b().tx("Documentation");
    for (OperationDefinitionParameterComponent p : opd.getParameter()) {
        genOpParam(rcontext, tbl, "", p);
    }
    addMarkdown(x, opd.getComment());
    inject(opd, x, NarrativeStatus.GENERATED);
    return true;
}
Also used : CodeType(org.hl7.fhir.dstu3.model.CodeType) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) OperationDefinitionParameterComponent(org.hl7.fhir.dstu3.model.OperationDefinition.OperationDefinitionParameterComponent)

Example 43 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generate.

public boolean generate(ResourceContext rcontext, StructureDefinition sd, Set<String> outputTracker) throws EOperationOutcome, FHIRException, IOException {
    ProfileUtilities pu = new ProfileUtilities(context, null, pkp);
    XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
    x.getChildNodes().add(pu.generateTable(definitionsTarget, sd, true, destDir, false, sd.getId(), false, corePath, "", false, false, outputTracker));
    inject(sd, x, NarrativeStatus.GENERATED);
    return true;
}
Also used : ProfileUtilities(org.hl7.fhir.r4.conformance.ProfileUtilities) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 44 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generate.

public boolean generate(ResourceContext rcontext, OperationDefinition opd) throws EOperationOutcome, FHIRException, IOException {
    XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
    x.h2().addText(opd.getName());
    x.para().addText(Utilities.capitalize(opd.getKind().toString()) + ": " + opd.getName());
    x.para().tx("The official URL for this operation definition is: ");
    x.pre().tx(opd.getUrl());
    addMarkdown(x, opd.getDescription());
    if (opd.getSystem())
        x.para().tx("URL: [base]/$" + opd.getCode());
    for (CodeType c : opd.getResource()) {
        if (opd.getType())
            x.para().tx("URL: [base]/" + c.getValue() + "/$" + opd.getCode());
        if (opd.getInstance())
            x.para().tx("URL: [base]/" + c.getValue() + "/[id]/$" + opd.getCode());
    }
    x.para().tx("Parameters");
    XhtmlNode tbl = x.table("grid");
    XhtmlNode tr = tbl.tr();
    tr.td().b().tx("Use");
    tr.td().b().tx("Name");
    tr.td().b().tx("Cardinality");
    tr.td().b().tx("Type");
    tr.td().b().tx("Binding");
    tr.td().b().tx("Documentation");
    for (OperationDefinitionParameterComponent p : opd.getParameter()) {
        genOpParam(rcontext, tbl, "", p);
    }
    addMarkdown(x, opd.getComment());
    inject(opd, x, NarrativeStatus.GENERATED);
    return true;
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) OperationDefinitionParameterComponent(org.hl7.fhir.r4.model.OperationDefinition.OperationDefinitionParameterComponent)

Example 45 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.

the class ProfileDrivenRenderer method generateElementByProfile.

public void generateElementByProfile(ResourceWrapper res, StructureDefinition profile, List<ElementDefinition> allElements, XhtmlNode x, String path, boolean showCodeDetails, int indent, PropertyWrapper p, ElementDefinition child) throws UnsupportedEncodingException, IOException, EOperationOutcome {
    Map<String, String> displayHints = readDisplayHints(child);
    if ("DomainResource.contained".equals(child.getBase().getPath())) {
    // if (p.getValues().size() > 0 && child != null) {
    // for (BaseWrapper v : p.getValues()) {
    // x.an(v.get("id").primitiveValue());
    // }
    // }
    } else if (!exemptFromRendering(child)) {
        if (isExtension(p)) {
            hasExtensions = true;
        }
        List<ElementDefinition> grandChildren = getChildrenForPath(allElements, path + "." + p.getName());
        filterGrandChildren(grandChildren, path + "." + p.getName(), p);
        if (p.getValues().size() > 0) {
            if (isPrimitive(child)) {
                XhtmlNode para = x.isPara() ? para = x : x.para();
                String name = p.getName();
                if (name.endsWith("[x]"))
                    name = name.substring(0, name.length() - 3);
                if (showCodeDetails || !isDefaultValue(displayHints, p.getValues())) {
                    para.b().addText(name);
                    para.tx(": ");
                    if (renderAsList(child) && p.getValues().size() > 1) {
                        XhtmlNode list = x.ul();
                        for (BaseWrapper v : p.getValues()) renderLeaf(res, v, child, x, list.li(), false, showCodeDetails, displayHints, path, indent);
                    } else {
                        boolean first = true;
                        for (BaseWrapper v : p.getValues()) {
                            if (first) {
                                first = false;
                            } else {
                                para.tx(", ");
                            }
                            renderLeaf(res, v, child, x, para, false, showCodeDetails, displayHints, path, indent);
                        }
                    }
                }
            } else if (canDoTable(path, p, grandChildren, x)) {
                XhtmlNode xn = new XhtmlNode(NodeType.Element, getHeader());
                xn.addText(Utilities.capitalize(Utilities.camelCase(Utilities.pluralizeMe(p.getName()))));
                XhtmlNode tbl = new XhtmlNode(NodeType.Element, "table");
                tbl.setAttribute("class", "grid");
                XhtmlNode tr = tbl.tr();
                // work around problem with empty table rows
                tr.td().tx("-");
                boolean add = addColumnHeadings(tr, grandChildren);
                for (BaseWrapper v : p.getValues()) {
                    if (v != null) {
                        tr = tbl.tr();
                        // work around problem with empty table rows
                        tr.td().tx("*");
                        add = addColumnValues(res, tr, grandChildren, v, showCodeDetails, displayHints, path, indent) || add;
                    }
                }
                if (add) {
                    x.add(xn);
                    x.add(tbl);
                }
            } else if (isExtension(p)) {
                for (BaseWrapper v : p.getValues()) {
                    if (v != null) {
                        PropertyWrapper vp = v.getChildByName("value");
                        PropertyWrapper ev = v.getChildByName("extension");
                        if (vp.hasValues()) {
                            BaseWrapper vv = vp.value();
                            XhtmlNode para = x.para();
                            para.b().addText(p.getStructure().present());
                            para.tx(": ");
                            renderLeaf(res, vv, child, x, para, false, showCodeDetails, displayHints, path, indent);
                        } else if (ev.hasValues()) {
                            XhtmlNode bq = x.addTag("blockquote");
                            bq.para().b().addText(isExtension(p) ? p.getStructure().present() : p.getName());
                            for (BaseWrapper vv : ev.getValues()) {
                                StructureDefinition ex = context.getWorker().fetchTypeDefinition("Extension");
                                List<ElementDefinition> children = getChildrenForPath(ex.getSnapshot().getElement(), "Extension");
                                generateByProfile(res, ex, vv, allElements, child, children, bq, "Extension", showCodeDetails, indent + 1);
                            }
                        }
                    }
                }
            } else {
                for (BaseWrapper v : p.getValues()) {
                    if (v != null) {
                        XhtmlNode bq = x.addTag("blockquote");
                        bq.para().b().addText(isExtension(p) ? p.getStructure().present() : p.getName());
                        generateByProfile(res, profile, v, allElements, child, grandChildren, bq, path + "." + p.getName(), showCodeDetails, indent + 1);
                    }
                }
            }
        }
    }
}
Also used : PropertyWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper) BaseWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) List(java.util.List) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)52 FHIRException (org.hl7.fhir.exceptions.FHIRException)38 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)37 ArrayList (java.util.ArrayList)35 ProfileUtilities (org.hl7.fhir.dstu3.conformance.ProfileUtilities)14 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)13 StructureDefinition (org.hl7.fhir.dstu2.model.StructureDefinition)13 ProfileUtilities (org.hl7.fhir.dstu2.utils.ProfileUtilities)13 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)13 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)13 FileOutputStream (java.io.FileOutputStream)10 Test (org.junit.jupiter.api.Test)10 IOException (java.io.IOException)9 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)9 DomainResource (org.hl7.fhir.r5.model.DomainResource)7 DomainResource (org.hl7.fhir.r4b.model.DomainResource)6 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)6 BaseWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper)6 BaseWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper)6 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)5