Search in sources :

Example 81 with ResourceWrapper

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

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

the class ParametersRenderer method render.

@Override
public boolean render(XhtmlNode x, ResourceWrapper params) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
    x.h2().tx("Parameters");
    XhtmlNode tbl = x.table("grid");
    PropertyWrapper pw = getProperty(params, "parameter");
    if (valued(pw)) {
        paramsW(tbl, pw.getValues(), 0);
    }
    return false;
}
Also used : PropertyWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 83 with ResourceWrapper

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

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

Example 85 with ResourceWrapper

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

the class LibraryRenderer method render.

public boolean render(XhtmlNode x, ResourceWrapper lib) throws FHIRFormatError, DefinitionException, IOException {
    PropertyWrapper authors = lib.getChildByName("author");
    PropertyWrapper editors = lib.getChildByName("editor");
    PropertyWrapper reviewers = lib.getChildByName("reviewer");
    PropertyWrapper endorsers = lib.getChildByName("endorser");
    if ((authors != null && authors.hasValues()) || (editors != null && editors.hasValues()) || (reviewers != null && reviewers.hasValues()) || (endorsers != null && endorsers.hasValues())) {
        boolean email = hasCT(authors, "email") || hasCT(editors, "email") || hasCT(reviewers, "email") || hasCT(endorsers, "email");
        boolean phone = hasCT(authors, "phone") || hasCT(editors, "phone") || hasCT(reviewers, "phone") || hasCT(endorsers, "phone");
        boolean url = hasCT(authors, "url") || hasCT(editors, "url") || hasCT(reviewers, "url") || hasCT(endorsers, "url");
        x.h2().tx("Participants");
        XhtmlNode t = x.table("grid");
        if (authors != null) {
            for (BaseWrapper cd : authors.getValues()) {
                participantRow(t, "Author", cd, email, phone, url);
            }
        }
        if (authors != null) {
            for (BaseWrapper cd : editors.getValues()) {
                participantRow(t, "Editor", cd, email, phone, url);
            }
        }
        if (authors != null) {
            for (BaseWrapper cd : reviewers.getValues()) {
                participantRow(t, "Reviewer", cd, email, phone, url);
            }
        }
        if (authors != null) {
            for (BaseWrapper cd : endorsers.getValues()) {
                participantRow(t, "Endorser", cd, email, phone, url);
            }
        }
    }
    PropertyWrapper artifacts = lib.getChildByName("relatedArtifact");
    if (artifacts != null && artifacts.hasValues()) {
        x.h2().tx("Related Artifacts");
        XhtmlNode t = x.table("grid");
        boolean label = false;
        boolean display = false;
        boolean citation = false;
        for (BaseWrapper ra : artifacts.getValues()) {
            label = label || ra.has("label");
            display = display || ra.has("display");
            citation = citation || ra.has("citation");
        }
        for (BaseWrapper ra : artifacts.getValues()) {
            renderArtifact(t, ra, lib, label, display, citation);
        }
    }
    PropertyWrapper parameters = lib.getChildByName("parameter");
    if (parameters != null && parameters.hasValues()) {
        x.h2().tx("Parameters");
        XhtmlNode t = x.table("grid");
        boolean doco = false;
        for (BaseWrapper p : parameters.getValues()) {
            doco = doco || p.has("documentation");
        }
        for (BaseWrapper p : parameters.getValues()) {
            renderParameter(t, p, doco);
        }
    }
    PropertyWrapper dataRequirements = lib.getChildByName("dataRequirement");
    if (dataRequirements != null && dataRequirements.hasValues()) {
        x.h2().tx("Data Requirements");
        for (BaseWrapper p : dataRequirements.getValues()) {
            renderDataRequirement(x, (DataRequirement) p.getBase());
        }
    }
    PropertyWrapper contents = lib.getChildByName("content");
    if (contents != null) {
        x.h2().tx("Contents");
        boolean isCql = false;
        int counter = 0;
        for (BaseWrapper p : contents.getValues()) {
            Attachment att = (Attachment) p.getBase();
            renderAttachment(x, att, isCql, counter, lib.getId());
            isCql = isCql || (att.hasContentType() && att.getContentType().startsWith("text/cql"));
            counter++;
        }
    }
    return false;
}
Also used : PropertyWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) Attachment(org.hl7.fhir.r4b.model.Attachment) ContactPoint(org.hl7.fhir.r4b.model.ContactPoint) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)57 BaseWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper)17 BaseWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper)17 NotImplementedException (org.apache.commons.lang3.NotImplementedException)13 PropertyWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper)13 PropertyWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper)13 ResourceWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper)9 ResourceWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.ResourceWrapper)8 IOException (java.io.IOException)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)7 Base64 (org.apache.commons.codec.binary.Base64)6 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)6 ResourceWithReference (org.hl7.fhir.r4b.renderers.utils.Resolver.ResourceWithReference)6 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)6 ResourceWithReference (org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference)6 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)6 Row (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 ArrayList (java.util.ArrayList)5 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)3