Search in sources :

Example 61 with BaseWrapper

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

the class ListRenderer method render.

public boolean render(XhtmlNode x, ResourceWrapper list) throws FHIRFormatError, DefinitionException, IOException {
    if (list.has("title")) {
        x.h2().tx(list.get("title").primitiveValue());
    }
    XhtmlNode t = x.table("clstu");
    XhtmlNode tr = t.tr();
    XhtmlNode td = tr.td();
    if (list.has("date")) {
        td.tx("Date: " + list.get("date").dateTimeValue().toHumanDisplay());
    }
    if (list.has("mode")) {
        td.tx("Mode: " + list.get("mode").primitiveValue());
    }
    if (list.has("status")) {
        td.tx("Status: " + list.get("status").primitiveValue());
    }
    if (list.has("code")) {
        td.tx("Code: " + displayBase(list.get("code")));
    }
    tr = t.tr();
    td = tr.td();
    if (list.has("subject")) {
        td.tx("Subject: ");
        shortForRef(td, list.get("subject"));
    }
    if (list.has("encounter")) {
        td.tx("Encounter: ");
        shortForRef(td, list.get("encounter"));
    }
    if (list.has("source")) {
        td.tx("Source: ");
        shortForRef(td, list.get("encounter"));
    }
    if (list.has("orderedBy")) {
        td.tx("Order: " + displayBase(list.get("orderedBy")));
    }
    // for (Annotation a : list.getNote()) {
    // renderAnnotation(a, x);
    // }
    boolean flag = false;
    boolean deleted = false;
    boolean date = false;
    for (BaseWrapper e : list.children("entry")) {
        flag = flag || e.has("flag");
        deleted = deleted || e.has("deleted");
        date = date || e.has("date");
    }
    t = x.table("grid");
    tr = t.tr().style("backgound-color: #eeeeee");
    tr.td().b().tx("Items");
    if (date) {
        tr.td().tx("Date");
    }
    if (flag) {
        tr.td().tx("Flag");
    }
    if (deleted) {
        tr.td().tx("Deleted");
    }
    for (BaseWrapper e : list.children("entry")) {
        tr = t.tr();
        shortForRef(tr.td(), e.get("item"));
        if (date) {
            tr.td().tx(e.has("date") ? e.get("date").dateTimeValue().toHumanDisplay() : "");
        }
        if (flag) {
            tr.td().tx(e.has("flag") ? displayBase(e.get("flag")) : "");
        }
        if (deleted) {
            tr.td().tx(e.has("deleted") ? e.get("deleted").primitiveValue() : "");
        }
    }
    return false;
}
Also used : BaseWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 62 with BaseWrapper

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

the class NarrativeGenerator method displayLeaf.

private boolean displayLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, String name, boolean showCodeDetails) throws FHIRException, UnsupportedEncodingException, IOException {
    if (ew == null)
        return false;
    Base e = ew.getBase();
    if (e == null)
        return false;
    Map<String, String> displayHints = readDisplayHints(defn);
    if (name.endsWith("[x]"))
        name = name.substring(0, name.length() - 3);
    if (!showCodeDetails && e instanceof PrimitiveType && isDefault(displayHints, ((PrimitiveType) e)))
        return false;
    if (e instanceof StringType) {
        x.addText(name + ": " + ((StringType) e).getValue());
        return true;
    } else if (e instanceof CodeType) {
        x.addText(name + ": " + ((CodeType) e).getValue());
        return true;
    } else if (e instanceof IdType) {
        x.addText(name + ": " + ((IdType) e).getValue());
        return true;
    } else if (e instanceof UriType) {
        x.addText(name + ": " + ((UriType) e).getValue());
        return true;
    } else if (e instanceof DateTimeType) {
        x.addText(name + ": " + ((DateTimeType) e).toHumanDisplay());
        return true;
    } else if (e instanceof InstantType) {
        x.addText(name + ": " + ((InstantType) e).toHumanDisplay());
        return true;
    } else if (e instanceof Extension) {
        // x.tx("Extensions: todo");
        return false;
    } else if (e instanceof org.hl7.fhir.dstu3.model.DateType) {
        x.addText(name + ": " + ((org.hl7.fhir.dstu3.model.DateType) e).toHumanDisplay());
        return true;
    } else if (e instanceof Enumeration) {
        // todo: look up a display name if there is one
        x.addText(((Enumeration<?>) e).getValue().toString());
        return true;
    } else if (e instanceof BooleanType) {
        if (((BooleanType) e).getValue()) {
            x.addText(name);
            return true;
        }
    } else if (e instanceof CodeableConcept) {
        renderCodeableConcept((CodeableConcept) e, x, showCodeDetails);
        return true;
    } else if (e instanceof Coding) {
        renderCoding((Coding) e, x, showCodeDetails);
        return true;
    } else if (e instanceof Annotation) {
        renderAnnotation((Annotation) e, x, showCodeDetails);
        return true;
    } else if (e instanceof org.hl7.fhir.dstu3.model.IntegerType) {
        x.addText(Integer.toString(((org.hl7.fhir.dstu3.model.IntegerType) e).getValue()));
        return true;
    } else if (e instanceof org.hl7.fhir.dstu3.model.DecimalType) {
        x.addText(((org.hl7.fhir.dstu3.model.DecimalType) e).getValue().toString());
        return true;
    } else if (e instanceof Identifier) {
        renderIdentifier((Identifier) e, x);
        return true;
    } else if (e instanceof HumanName) {
        renderHumanName((HumanName) e, x);
        return true;
    } else if (e instanceof SampledData) {
        renderSampledData((SampledData) e, x);
        return true;
    } else if (e instanceof Address) {
        renderAddress((Address) e, x);
        return true;
    } else if (e instanceof ContactPoint) {
        renderContactPoint((ContactPoint) e, x);
        return true;
    } else if (e instanceof Timing) {
        renderTiming((Timing) e, x);
        return true;
    } else if (e instanceof Quantity) {
        renderQuantity((Quantity) e, x, showCodeDetails);
        return true;
    } else if (e instanceof Ratio) {
        renderQuantity(((Ratio) e).getNumerator(), x, showCodeDetails);
        x.tx("/");
        renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
        return true;
    } else if (e instanceof Period) {
        Period p = (Period) e;
        x.addText(name + ": ");
        x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
        x.tx(" --> ");
        x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
        return true;
    } else if (e instanceof Reference) {
        Reference r = (Reference) e;
        if (r.hasDisplayElement())
            x.addText(r.getDisplay());
        else if (r.hasReferenceElement()) {
            ResourceWithReference tr = resolveReference(res, r.getReference());
            // getDisplayForReference(tr.getReference()));
            x.addText(tr == null ? r.getReference() : "????");
        } else
            x.tx("??");
        return true;
    } else if (e instanceof Narrative) {
        return false;
    } else if (e instanceof Resource) {
        return false;
    } else if (e instanceof ContactDetail) {
        return false;
    } else if (e instanceof Range) {
        return false;
    } else if (e instanceof Meta) {
        return false;
    } else if (e instanceof Dosage) {
        return false;
    } else if (e instanceof Signature) {
        return false;
    } else if (e instanceof UsageContext) {
        return false;
    } else if (e instanceof ElementDefinition) {
        return false;
    } else if (!(e instanceof Attachment))
        throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet");
    return false;
}
Also used : Meta(org.hl7.fhir.dstu3.model.Meta) Address(org.hl7.fhir.dstu3.model.Address) StringType(org.hl7.fhir.dstu3.model.StringType) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Attachment(org.hl7.fhir.dstu3.model.Attachment) Dosage(org.hl7.fhir.dstu3.model.Dosage) UriType(org.hl7.fhir.dstu3.model.UriType) HumanName(org.hl7.fhir.dstu3.model.HumanName) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) Narrative(org.hl7.fhir.dstu3.model.Narrative) SampledData(org.hl7.fhir.dstu3.model.SampledData) PrimitiveType(org.hl7.fhir.dstu3.model.PrimitiveType) Ratio(org.hl7.fhir.dstu3.model.Ratio) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) InstantType(org.hl7.fhir.dstu3.model.InstantType) Enumeration(org.hl7.fhir.dstu3.model.Enumeration) Reference(org.hl7.fhir.dstu3.model.Reference) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) DomainResource(org.hl7.fhir.dstu3.model.DomainResource) MetadataResource(org.hl7.fhir.dstu3.model.MetadataResource) Resource(org.hl7.fhir.dstu3.model.Resource) Quantity(org.hl7.fhir.dstu3.model.Quantity) Period(org.hl7.fhir.dstu3.model.Period) Range(org.hl7.fhir.dstu3.model.Range) Base(org.hl7.fhir.dstu3.model.Base) Annotation(org.hl7.fhir.dstu3.model.Annotation) IdType(org.hl7.fhir.dstu3.model.IdType) Extension(org.hl7.fhir.dstu3.model.Extension) ContactDetail(org.hl7.fhir.dstu3.model.ContactDetail) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) UsageContext(org.hl7.fhir.dstu3.model.UsageContext) Signature(org.hl7.fhir.dstu3.model.Signature) CodeType(org.hl7.fhir.dstu3.model.CodeType) EventTiming(org.hl7.fhir.dstu3.model.Timing.EventTiming) Timing(org.hl7.fhir.dstu3.model.Timing) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 63 with BaseWrapper

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

the class NarrativeGenerator method filterGrandChildren.

private void filterGrandChildren(List<ElementDefinition> grandChildren, String string, PropertyWrapper prop) {
    List<ElementDefinition> toRemove = new ArrayList<ElementDefinition>();
    toRemove.addAll(grandChildren);
    for (BaseWrapper b : prop.getValues()) {
        List<ElementDefinition> list = new ArrayList<ElementDefinition>();
        for (ElementDefinition ed : toRemove) {
            PropertyWrapper p = b.getChildByName(tail(ed.getPath()));
            if (p != null && p.hasValues())
                list.add(ed);
        }
        toRemove.removeAll(list);
    }
    grandChildren.removeAll(toRemove);
}
Also used : ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition)

Example 64 with BaseWrapper

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

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

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