Search in sources :

Example 71 with BaseWrapper

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

the class QuestionnaireResponseRenderer method renderAnswer.

public void renderAnswer(HierarchicalTableGenerator gen, ResourceWrapper q, Row r, BaseWrapper ans) throws UnsupportedEncodingException, IOException {
    List<BaseWrapper> items;
    Base b = ans.get("value[x]");
    if (b == null) {
        r.getCells().add(gen.new Cell(null, null, "null!", null, null));
    } else if (b.isPrimitive()) {
        r.getCells().add(gen.new Cell(null, null, b.primitiveValue(), null, null));
    } else {
        XhtmlNode x = new XhtmlNode(NodeType.Element, "span");
        Cell cell = gen.new Cell(null, null, null, null, null);
        Piece p = gen.new Piece("span");
        p.getChildren().add(x);
        cell.addPiece(p);
        render(x, (DataType) b);
        r.getCells().add(cell);
    }
    items = ans.children("item");
    for (BaseWrapper si : items) {
        renderTreeItem(gen, r.getSubRows(), q, si);
    }
}
Also used : BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) DataType(org.hl7.fhir.r4b.model.DataType) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) Base(org.hl7.fhir.r4b.model.Base) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 72 with BaseWrapper

use of org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper 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 73 with BaseWrapper

use of org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper 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)

Example 74 with BaseWrapper

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

the class DiagnosticReportRenderer method render.

public boolean render(XhtmlNode x, ResourceWrapper dr) throws IOException, FHIRException, EOperationOutcome {
    XhtmlNode h2 = x.h2();
    render(h2, getProperty(dr, "code").value());
    h2.tx(" ");
    PropertyWrapper pw = getProperty(dr, "category");
    if (valued(pw)) {
        h2.tx("(");
        boolean first = true;
        for (BaseWrapper b : pw.getValues()) {
            if (first)
                first = false;
            else
                h2.tx(", ");
            render(h2, b);
        }
        h2.tx(") ");
    }
    XhtmlNode tbl = x.table("grid");
    XhtmlNode tr;
    if (dr.has("subject")) {
        tr = tbl.tr();
        tr.td().tx("Subject");
        populateSubjectSummary(tr.td(), getProperty(dr, "subject").value());
    }
    DataType eff = null;
    DataType iss = null;
    if (dr.has("effective[x]")) {
        tr = tbl.tr();
        tr.td().tx("When For");
        eff = (DataType) getProperty(dr, "effective[x]").value().getBase();
        render(tr.td(), eff);
    }
    if (dr.has("issued")) {
        tr = tbl.tr();
        tr.td().tx("Reported");
        eff = (DataType) getProperty(dr, "issued").value().getBase();
        render(tr.td(), getProperty(dr, "issued").value());
    }
    pw = getProperty(dr, "perfomer");
    if (valued(pw)) {
        tr = tbl.tr();
        tr.td().tx(Utilities.pluralize("Performer", pw.getValues().size()));
        XhtmlNode tdr = tr.td();
        for (BaseWrapper v : pw.getValues()) {
            tdr.tx(" ");
            render(tdr, v);
        }
    }
    pw = getProperty(dr, "identifier");
    if (valued(pw)) {
        tr = tbl.tr();
        tr.td().tx(Utilities.pluralize("Identifier", pw.getValues().size()) + ":");
        XhtmlNode tdr = tr.td();
        for (BaseWrapper v : pw.getValues()) {
            tdr.tx(" ");
            render(tdr, v);
        }
    }
    pw = getProperty(dr, "request");
    if (valued(pw)) {
        tr = tbl.tr();
        tr.td().tx(Utilities.pluralize("Request", pw.getValues().size()) + ":");
        XhtmlNode tdr = tr.td();
        for (BaseWrapper v : pw.getValues()) {
            tdr.tx(" ");
            render(tdr, v);
        }
        tdr.br();
    }
    x.para().b().tx("Report Details");
    pw = getProperty(dr, "result");
    if (valued(pw)) {
        List<ObservationNode> observations = fetchObservations(pw.getValues(), dr);
        buildObservationsTable(x, observations, eff, iss);
    }
    pw = getProperty(dr, "conclusion");
    if (valued(pw)) {
        render(x.para(), pw.value());
    }
    pw = getProperty(dr, "conclusionCode");
    if (!valued(pw)) {
        pw = getProperty(dr, "codedDiagnosis");
    }
    if (valued(pw)) {
        XhtmlNode p = x.para();
        p.b().tx("Coded Conclusions :");
        XhtmlNode ul = x.ul();
        for (BaseWrapper v : pw.getValues()) {
            render(ul.li(), v);
        }
    }
    return false;
}
Also used : PropertyWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) DataType(org.hl7.fhir.r4b.model.DataType) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 75 with BaseWrapper

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

the class DiagnosticReportRenderer method fetchObservations.

private List<ObservationNode> fetchObservations(List<BaseWrapper> list, ResourceWrapper rw) throws UnsupportedEncodingException, FHIRException, IOException {
    List<ObservationNode> res = new ArrayList<ObservationNode>();
    for (BaseWrapper b : list) {
        if (b.has("reference")) {
            ObservationNode obs = new ObservationNode();
            obs.ref = b.get("reference").primitiveValue();
            obs.obs = resolveReference(rw, obs.ref);
            if (obs.obs != null && obs.obs.getResource() != null) {
                PropertyWrapper t = getProperty(obs.obs.getResource(), "contained");
                if (t != null && t.hasValues()) {
                    obs.contained = fetchObservations(t.getValues(), rw);
                }
            }
            res.add(obs);
        }
    }
    return res;
}
Also used : PropertyWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) ArrayList(java.util.ArrayList)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)48 BaseWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper)20 BaseWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper)20 PropertyWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper)15 PropertyWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper)15 ArrayList (java.util.ArrayList)14 NotImplementedException (org.apache.commons.lang3.NotImplementedException)11 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)7 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)7 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)7 Base64 (org.apache.commons.codec.binary.Base64)6 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)6 HashMap (java.util.HashMap)5 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)5 ResourceWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.ResourceWrapper)5 ResourceWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper)5 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)4 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)3 Base (org.hl7.fhir.r4b.model.Base)3 Extension (org.hl7.fhir.r4b.model.Extension)3