Search in sources :

Example 71 with ResourceWrapper

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

the class NarrativeGenerator method generateDiagnosticReport.

public XhtmlNode generateDiagnosticReport(ResourceWrapper dr) {
    XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
    XhtmlNode h2 = root.h2();
    displayCodeableConcept(h2, getProperty(dr, "code").value());
    h2.tx(" ");
    PropertyWrapper pw = getProperty(dr, "category");
    if (valued(pw)) {
        h2.tx("(");
        displayCodeableConcept(h2, pw.value());
        h2.tx(") ");
    }
    displayDate(h2, getProperty(dr, "issued").value());
    XhtmlNode tbl = root.table("grid");
    XhtmlNode tr = tbl.tr();
    XhtmlNode tdl = tr.td();
    XhtmlNode tdr = tr.td();
    populateSubjectSummary(tdl, getProperty(dr, "subject").value());
    tdr.b().tx("Report Details");
    tdr.br();
    pw = getProperty(dr, "perfomer");
    if (valued(pw)) {
        tdr.addText(pluralise("Performer", pw.getValues().size()) + ":");
        for (BaseWrapper v : pw.getValues()) {
            tdr.tx(" ");
            displayReference(tdr, v);
        }
        tdr.br();
    }
    pw = getProperty(dr, "identifier");
    if (valued(pw)) {
        tdr.addText(pluralise("Identifier", pw.getValues().size()) + ":");
        for (BaseWrapper v : pw.getValues()) {
            tdr.tx(" ");
            displayIdentifier(tdr, v);
        }
        tdr.br();
    }
    pw = getProperty(dr, "request");
    if (valued(pw)) {
        tdr.addText(pluralise("Request", pw.getValues().size()) + ":");
        for (BaseWrapper v : pw.getValues()) {
            tdr.tx(" ");
            displayReferenceId(tdr, v);
        }
        tdr.br();
    }
    pw = getProperty(dr, "result");
    if (valued(pw)) {
        List<ObservationNode> observations = fetchObservations(pw.getValues());
        buildObservationsTable(root, observations);
    }
    pw = getProperty(dr, "conclusion");
    if (valued(pw))
        displayText(root.para(), pw.value());
    pw = getProperty(dr, "result");
    if (valued(pw)) {
        XhtmlNode p = root.para();
        p.b().tx("Coded Diagnoses :");
        for (BaseWrapper v : pw.getValues()) {
            tdr.tx(" ");
            displayCodeableConcept(tdr, v);
        }
    }
    return root;
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 72 with ResourceWrapper

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

the class NarrativeGenerator method addObservationToTable.

private void addObservationToTable(XhtmlNode tr, ResourceWrapper obs, int i) {
    // TODO Auto-generated method stub
    // code (+bodysite)
    XhtmlNode td = tr.td();
    PropertyWrapper pw = getProperty(obs, "result");
    if (valued(pw)) {
        displayCodeableConcept(td, pw.value());
    }
    pw = getProperty(obs, "bodySite");
    if (valued(pw)) {
        td.tx(" (");
        displayCodeableConcept(td, pw.value());
        td.tx(")");
    }
    // value / dataAbsentReason (in red)
    td = tr.td();
    pw = getProperty(obs, "value[x]");
    if (valued(pw)) {
        if (pw.getTypeCode().equals("CodeableConcept"))
            displayCodeableConcept(td, pw.value());
        else if (pw.getTypeCode().equals("string"))
            displayText(td, pw.value());
        else
            td.addText(pw.getTypeCode() + " not rendered yet");
    }
    // units
    td = tr.td();
    td.tx("to do");
    // reference range
    td = tr.td();
    td.tx("to do");
    // flags (status other than F, interpretation, )
    td = tr.td();
    td.tx("to do");
    // issued if different to DR
    td = tr.td();
    td.tx("to do");
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 73 with ResourceWrapper

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

the class NarrativeGenerator method generateResourceSummary.

private void generateResourceSummary(XhtmlNode x, ResourceWrapper res, boolean textAlready, boolean showCodeDetails, ResourceContext rc) 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.getName();
    StructureDefinition profile = context.fetchResource(StructureDefinition.class, path);
    if (profile == null)
        x.tx("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.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, rc) || last;
                }
            }
        }
    }
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 74 with ResourceWrapper

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

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

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