Search in sources :

Example 41 with PropertyWrapper

use of org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generateByProfile.

private void generateByProfile(ResourceWrapper res, StructureDefinition profile, BaseWrapper e, List<ElementDefinition> allElements, ElementDefinition defn, List<ElementDefinition> children, XhtmlNode x, String path, boolean showCodeDetails) throws FHIRException, UnsupportedEncodingException, IOException {
    if (children.isEmpty()) {
        renderLeaf(res, e, defn, x, false, showCodeDetails, readDisplayHints(defn));
    } else {
        for (PropertyWrapper p : splitExtensions(profile, e.children())) {
            if (p.hasValues()) {
                ElementDefinition child = getElementDefinition(children, path + "." + p.getName(), p);
                if (child != null) {
                    Map<String, String> displayHints = readDisplayHints(child);
                    if (!exemptFromRendering(child)) {
                        List<ElementDefinition> grandChildren = getChildrenForPath(allElements, path + "." + p.getName());
                        filterGrandChildren(grandChildren, path + "." + p.getName(), p);
                        if (p.getValues().size() > 0 && child != null) {
                            if (isPrimitive(child)) {
                                XhtmlNode para = x.addTag("p");
                                String name = p.getName();
                                if (name.endsWith("[x]"))
                                    name = name.substring(0, name.length() - 3);
                                if (showCodeDetails || !isDefaultValue(displayHints, p.getValues())) {
                                    para.addTag("b").addText(name);
                                    para.addText(": ");
                                    if (renderAsList(child) && p.getValues().size() > 1) {
                                        XhtmlNode list = x.addTag("ul");
                                        for (BaseWrapper v : p.getValues()) renderLeaf(res, v, child, list.addTag("li"), false, showCodeDetails, displayHints);
                                    } else {
                                        boolean first = true;
                                        for (BaseWrapper v : p.getValues()) {
                                            if (first)
                                                first = false;
                                            else
                                                para.addText(", ");
                                            renderLeaf(res, v, child, para, false, showCodeDetails, displayHints);
                                        }
                                    }
                                }
                            } else if (canDoTable(path, p, grandChildren)) {
                                x.addTag("h3").addText(Utilities.capitalize(Utilities.camelCase(Utilities.pluralizeMe(p.getName()))));
                                XhtmlNode tbl = x.addTag("table").setAttribute("class", "grid");
                                XhtmlNode tr = tbl.addTag("tr");
                                // work around problem with empty table rows
                                tr.addTag("td").addText("-");
                                addColumnHeadings(tr, grandChildren);
                                for (BaseWrapper v : p.getValues()) {
                                    if (v != null) {
                                        tr = tbl.addTag("tr");
                                        // work around problem with empty table rows
                                        tr.addTag("td").addText("*");
                                        addColumnValues(res, tr, grandChildren, v, showCodeDetails, displayHints);
                                    }
                                }
                            } else {
                                for (BaseWrapper v : p.getValues()) {
                                    if (v != null) {
                                        XhtmlNode bq = x.addTag("blockquote");
                                        bq.addTag("p").addTag("b").addText(p.getName());
                                        generateByProfile(res, profile, v, allElements, child, grandChildren, bq, path + "." + p.getName(), showCodeDetails);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : ElementDefinition(org.hl7.fhir.dstu2016may.model.ElementDefinition) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 42 with PropertyWrapper

use of org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generateResourceSummary.

private void generateResourceSummary(XhtmlNode x, ResourceWrapper res, boolean textAlready, boolean showCodeDetails) throws FHIRException, UnsupportedEncodingException, IOException {
    if (!textAlready) {
        XhtmlNode div = res.getNarrative();
        if (div != null) {
            if (div.allChildrenAreText())
                x.getChildNodes().addAll(div.getChildNodes());
            if (div.getChildNodes().size() == 1 && div.getChildNodes().get(0).allChildrenAreText())
                x.getChildNodes().addAll(div.getChildNodes().get(0).getChildNodes());
        }
        x.addText("Generated Summary: ");
    }
    String path = res.getName();
    StructureDefinition profile = context.fetchResource(StructureDefinition.class, path);
    if (profile == null)
        x.addText("unknown resource " + path);
    else {
        boolean firstElement = true;
        boolean last = false;
        for (PropertyWrapper p : res.children()) {
            ElementDefinition child = getElementDefinition(profile.getSnapshot().getElement(), path + "." + p.getName(), p);
            if (p.getValues().size() > 0 && p.getValues().get(0) != null && child != null && isPrimitive(child) && includeInSummary(child)) {
                if (firstElement)
                    firstElement = false;
                else if (last)
                    x.addText("; ");
                boolean first = true;
                last = false;
                for (BaseWrapper v : p.getValues()) {
                    if (first)
                        first = false;
                    else if (last)
                        x.addText(", ");
                    last = displayLeaf(res, v, child, x, p.getName(), showCodeDetails) || last;
                }
            }
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.dstu2016may.model.StructureDefinition) ElementDefinition(org.hl7.fhir.dstu2016may.model.ElementDefinition) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 43 with PropertyWrapper

use of org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper in project org.hl7.fhir.core by hapifhir.

the class PatientRenderer method display.

@Override
public String display(ResourceWrapper pat) throws UnsupportedEncodingException, IOException {
    Identifier id = null;
    PropertyWrapper pw = getProperty(pat, "identifier");
    for (BaseWrapper t : pw.getValues()) {
        id = chooseId(id, (Identifier) t.getBase());
    }
    pw = getProperty(pat, "name");
    HumanName n = null;
    for (BaseWrapper t : pw.getValues()) {
        n = chooseName(n, (HumanName) t);
    }
    String gender = null;
    pw = getProperty(pat, "gender");
    if (valued(pw)) {
        pw.value().getBase().primitiveValue();
    }
    DateType dt = null;
    pw = getProperty(pat, "birthDate");
    if (valued(pw)) {
        dt = (DateType) pw.value().getBase();
    }
    return display(n, gender, dt, id);
}
Also used : PropertyWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper) HumanName(org.hl7.fhir.r4b.model.HumanName) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) Identifier(org.hl7.fhir.r4b.model.Identifier) DateType(org.hl7.fhir.r4b.model.DateType)

Example 44 with PropertyWrapper

use of org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper in project org.hl7.fhir.core by hapifhir.

the class ProfileDrivenRenderer method addColumnValues.

private boolean addColumnValues(ResourceWrapper res, XhtmlNode tr, List<ElementDefinition> grandChildren, BaseWrapper v, boolean showCodeDetails, Map<String, String> displayHints, String path, int indent) throws FHIRException, UnsupportedEncodingException, IOException, EOperationOutcome {
    boolean b = false;
    for (ElementDefinition e : grandChildren) {
        PropertyWrapper p = v.getChildByName(e.getPath().substring(e.getPath().lastIndexOf(".") + 1));
        XhtmlNode td = tr.td();
        if (p == null || p.getValues().size() == 0 || p.getValues().get(0) == null) {
            b = true;
            td.tx(" ");
        } else {
            for (BaseWrapper vv : p.getValues()) {
                b = true;
                td.sep(", ");
                renderLeaf(res, vv, e, td, td, false, showCodeDetails, displayHints, path, indent);
            }
        }
    }
    return b;
}
Also used : PropertyWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 45 with PropertyWrapper

use of org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper in project org.hl7.fhir.core by hapifhir.

the class ProfileDrivenRenderer method generateResourceSummary.

// 
// public void inject(Element er, XhtmlNode x, NarrativeStatus status, boolean pretty) {
// if (!x.hasAttribute("xmlns"))
// x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
// Element le = XMLUtil.getNamedChild(er, "language");
// String l = le == null ? null : le.getAttribute("value");
// if (!Utilities.noString(l)) {
// // use both - see https://www.w3.org/TR/i18n-html-tech-lang/#langvalues
// x.setAttribute("lang", l);
// x.setAttribute("xml:lang", l);
// }
// Element txt = XMLUtil.getNamedChild(er, "text");
// if (txt == null) {
// txt = er.getOwnerDocument().createElementNS(FormatUtilities.FHIR_NS, "text");
// Element n = XMLUtil.getFirstChild(er);
// while (n != null && (n.getNodeName().equals("id") || n.getNodeName().equals("meta") || n.getNodeName().equals("implicitRules") || n.getNodeName().equals("language")))
// n = XMLUtil.getNextSibling(n);
// if (n == null)
// er.appendChild(txt);
// else
// er.insertBefore(txt, n);
// }
// Element st = XMLUtil.getNamedChild(txt, "status");
// if (st == null) {
// st = er.getOwnerDocument().createElementNS(FormatUtilities.FHIR_NS, "status");
// Element n = XMLUtil.getFirstChild(txt);
// if (n == null)
// txt.appendChild(st);
// else
// txt.insertBefore(st, n);
// }
// st.setAttribute("value", status.toCode());
// Element div = XMLUtil.getNamedChild(txt, "div");
// if (div == null) {
// div = er.getOwnerDocument().createElementNS(FormatUtilities.XHTML_NS, "div");
// div.setAttribute("xmlns", FormatUtilities.XHTML_NS);
// txt.appendChild(div);
// }
// if (div.hasChildNodes())
// div.appendChild(er.getOwnerDocument().createElementNS(FormatUtilities.XHTML_NS, "hr"));
// new XhtmlComposer(XhtmlComposer.XML, pretty).compose(div, x);
// }
// 
// public void inject(org.hl7.fhir.r4b.elementmodel.Element er, XhtmlNode x, NarrativeStatus status, boolean pretty) throws IOException, FHIRException {
// if (!x.hasAttribute("xmlns"))
// x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
// String l = er.getChildValue("language");
// if (!Utilities.noString(l)) {
// // use both - see https://www.w3.org/TR/i18n-html-tech-lang/#langvalues
// x.setAttribute("lang", l);
// x.setAttribute("xml:lang", l);
// }
// org.hl7.fhir.r4b.elementmodel.Element txt = er.getNamedChild("text");
// if (txt == null) {
// txt = new org.hl7.fhir.r4b.elementmodel.Element("text", er.getProperty().getChild(null, "text"));
// int i = 0;
// while (i < er.getChildren().size() && (er.getChildren().get(i).getName().equals("id") || er.getChildren().get(i).getName().equals("meta") || er.getChildren().get(i).getName().equals("implicitRules") || er.getChildren().get(i).getName().equals("language")))
// i++;
// if (i >= er.getChildren().size())
// er.getChildren().add(txt);
// else
// er.getChildren().add(i, txt);
// }
// org.hl7.fhir.r4b.elementmodel.Element st = txt.getNamedChild("status");
// if (st == null) {
// st = new org.hl7.fhir.r4b.elementmodel.Element("status", txt.getProperty().getChild(null, "status"));
// txt.getChildren().add(0, st);
// }
// st.setValue(status.toCode());
// org.hl7.fhir.r4b.elementmodel.Element div = txt.getNamedChild("div");
// if (div == null) {
// div = new org.hl7.fhir.r4b.elementmodel.Element("div", txt.getProperty().getChild(null, "div"));
// txt.getChildren().add(div);
// div.setValue(new XhtmlComposer(XhtmlComposer.XML, pretty).compose(x));
// }
// div.setValue(x.toString());
// div.setXhtml(x);
// }
// 
public void generateResourceSummary(XhtmlNode x, ResourceWrapper res, boolean textAlready, boolean showCodeDetails, boolean canLink) throws FHIRException, UnsupportedEncodingException, IOException {
    if (!textAlready) {
        XhtmlNode div = res.getNarrative();
        if (div != null) {
            if (div.allChildrenAreText())
                x.getChildNodes().addAll(div.getChildNodes());
            if (div.getChildNodes().size() == 1 && div.getChildNodes().get(0).allChildrenAreText())
                x.getChildNodes().addAll(div.getChildNodes().get(0).getChildNodes());
        }
        x.tx("Generated Summary: ");
    }
    String path = res.fhirType();
    StructureDefinition profile = getContext().getWorker().fetchResource(StructureDefinition.class, path);
    if (profile == null)
        x.tx("unknown resource " + path);
    else {
        boolean firstElement = true;
        boolean last = false;
        for (PropertyWrapper p : res.children()) {
            if (!ignoreProperty(p) && !p.getElementDefinition().getBase().getPath().startsWith("Resource.")) {
                ElementDefinition child = getElementDefinition(profile.getSnapshot().getElement(), path + "." + p.getName(), p);
                if (p.getValues().size() > 0 && p.getValues().get(0) != null && child != null && isPrimitive(child) && includeInSummary(child, p.getValues())) {
                    if (firstElement)
                        firstElement = false;
                    else if (last)
                        x.tx("; ");
                    boolean first = true;
                    last = false;
                    for (BaseWrapper v : p.getValues()) {
                        if (first)
                            first = false;
                        else if (last)
                            x.tx(", ");
                        last = displayLeaf(res, v, child, x, p.getName(), showCodeDetails, canLink) || last;
                    }
                }
            }
        }
    }
}
Also used : PropertyWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)32 PropertyWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper)17 PropertyWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper)17 ArrayList (java.util.ArrayList)14 BaseWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper)13 BaseWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper)13 HashMap (java.util.HashMap)5 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)5 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)5 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)5 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)4 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)4 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)4 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)3 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)3 List (java.util.List)2 StructureDefinition (org.hl7.fhir.dstu2.model.StructureDefinition)2 StructureDefinition (org.hl7.fhir.dstu2016may.model.StructureDefinition)2 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)2 DateType (org.hl7.fhir.r4b.model.DateType)2