Search in sources :

Example 61 with ResourceWrapper

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

the class QuestionnaireResponseRenderer method renderTreeItem.

private boolean renderTreeItem(HierarchicalTableGenerator gen, List<Row> rows, ResourceWrapper q, BaseWrapper i) throws IOException {
    Row r = gen.new Row();
    rows.add(r);
    boolean hasExt = false;
    List<BaseWrapper> items = i.children("item");
    List<BaseWrapper> answers = i.children("answer");
    boolean hasItem = items != null && !items.isEmpty();
    if (answers != null) {
        for (BaseWrapper a : answers) {
            hasItem = a.has("item");
        }
    }
    if (hasItem) {
        r.setIcon("icon-q-group.png", "Group");
    } else {
        r.setIcon("icon-q-string.png", "Item");
    }
    String linkId = i.has("linkId") ? i.get("linkId").primitiveValue() : "??";
    String text = i.has("text") ? i.get("text").primitiveValue() : "";
    r.getCells().add(gen.new Cell(null, context.getDefinitionsTarget() == null ? "" : context.getDefinitionsTarget() + "#item." + linkId, linkId, null, null));
    r.getCells().add(gen.new Cell(null, null, text, null, null));
    r.getCells().add(gen.new Cell(null, null, null, null, null));
    if (answers == null || answers.size() == 0) {
        r.getCells().add(gen.new Cell(null, null, null, null, null));
        if (items != null) {
            for (BaseWrapper si : items) {
                renderTreeItem(gen, r.getSubRows(), q, si);
            }
        }
    } else if (answers.size() == 1) {
        BaseWrapper ans = answers.get(0);
        renderAnswer(gen, q, r, ans);
    } else {
        r.getCells().add(gen.new Cell(null, null, null, null, null));
        for (BaseWrapper ans : answers) {
            Row ar = gen.new Row();
            ar.setIcon("icon-q-string.png", "Item");
            ar.getSubRows().add(ar);
            ar.getCells().add(gen.new Cell(null, null, null, null, null));
            ar.getCells().add(gen.new Cell(null, null, text, null, null));
            ar.getCells().add(gen.new Cell(null, null, null, null, null));
            renderAnswer(gen, q, ar, ans);
        }
    }
    return hasExt;
}
Also used : BaseWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

Example 62 with ResourceWrapper

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

the class PatientRenderer method describe.

public void describe(XhtmlNode x, 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.getBase());
    }
    String gender = null;
    pw = getProperty(pat, "gender");
    if (valued(pw)) {
        gender = pw.value().getBase().primitiveValue();
    }
    DateType dt = null;
    pw = getProperty(pat, "birthDate");
    if (valued(pw)) {
        dt = (DateType) pw.value().getBase();
    }
    describe(x, n, gender, dt, id);
}
Also used : PropertyWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper) HumanName(org.hl7.fhir.r5.model.HumanName) BaseWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper) Identifier(org.hl7.fhir.r5.model.Identifier) DateType(org.hl7.fhir.r5.model.DateType)

Example 63 with ResourceWrapper

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

the class ResourceRenderer method renderResourceHeader.

protected void renderResourceHeader(ResourceWrapper r, XhtmlNode x) throws UnsupportedEncodingException, FHIRException, IOException {
    XhtmlNode div = x.div().style("display: inline-block").style("background-color: #d9e0e7").style("padding: 6px").style("margin: 4px").style("border: 1px solid #8da1b4").style("border-radius: 5px").style("line-height: 60%");
    String id = getPrimitiveValue(r, "id");
    String lang = getPrimitiveValue(r, "language");
    String ir = getPrimitiveValue(r, "implicitRules");
    BaseWrapper meta = r.getChildByName("meta").hasValues() ? r.getChildByName("meta").getValues().get(0) : null;
    String versionId = getPrimitiveValue(meta, "versionId");
    String lastUpdated = getPrimitiveValue(meta, "lastUpdated");
    String source = getPrimitiveValue(meta, "source");
    if (id != null || lang != null || versionId != null || lastUpdated != null) {
        XhtmlNode p = plateStyle(div.para());
        p.tx("Resource ");
        if (id != null) {
            p.tx("\"" + id + "\" ");
        }
        if (versionId != null) {
            p.tx("Version \"" + versionId + "\" ");
        }
        if (lastUpdated != null) {
            p.tx("Updated \"");
            renderDateTime(p, lastUpdated);
            p.tx("\" ");
        }
        if (lang != null) {
            p.tx(" (Language \"" + lang + "\") ");
        }
    }
    if (ir != null) {
        plateStyle(div.para()).b().tx("Special rules apply: " + ir + "!");
    }
    if (source != null) {
        plateStyle(div.para()).tx("Information Source: " + source + "!");
    }
    if (meta != null) {
        PropertyWrapper pl = meta.getChildByName("profile");
        if (pl.hasValues()) {
            XhtmlNode p = plateStyle(div.para());
            p.tx(Utilities.pluralize("Profile", pl.getValues().size()) + ": ");
            boolean first = true;
            for (BaseWrapper bw : pl.getValues()) {
                if (first)
                    first = false;
                else
                    p.tx(", ");
                renderCanonical(r, p, bw.getBase().primitiveValue());
            }
        }
        PropertyWrapper tl = meta.getChildByName("tag");
        if (tl.hasValues()) {
            XhtmlNode p = plateStyle(div.para());
            p.tx(Utilities.pluralize("Tag", tl.getValues().size()) + ": ");
            boolean first = true;
            for (BaseWrapper bw : tl.getValues()) {
                if (first)
                    first = false;
                else
                    p.tx(", ");
                String system = getPrimitiveValue(bw, "system");
                String version = getPrimitiveValue(bw, "version");
                String code = getPrimitiveValue(bw, "system");
                String display = getPrimitiveValue(bw, "system");
                renderCoding(p, new Coding(system, version, code, display));
            }
        }
        PropertyWrapper sl = meta.getChildByName("security");
        if (sl.hasValues()) {
            XhtmlNode p = plateStyle(div.para());
            p.tx(Utilities.pluralize("Security Label", tl.getValues().size()) + ": ");
            boolean first = true;
            for (BaseWrapper bw : sl.getValues()) {
                if (first)
                    first = false;
                else
                    p.tx(", ");
                String system = getPrimitiveValue(bw, "system");
                String version = getPrimitiveValue(bw, "version");
                String code = getPrimitiveValue(bw, "system");
                String display = getPrimitiveValue(bw, "system");
                renderCoding(p, new Coding(system, version, code, display));
            }
        }
    }
}
Also used : PropertyWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper) BaseWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper) Coding(org.hl7.fhir.r5.model.Coding) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 64 with ResourceWrapper

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

the class ResourceRenderer method render.

public XhtmlNode render(ResourceWrapper r) throws IOException, FHIRException, EOperationOutcome {
    assert r.getContext() == context;
    XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
    boolean hasExtensions = render(x, r);
    if (r.hasNarrative()) {
        r.injectNarrative(x, hasExtensions ? NarrativeStatus.EXTENSIONS : NarrativeStatus.GENERATED);
    }
    return x;
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 65 with ResourceWrapper

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

the class ResourceRenderer method renderReference.

public void renderReference(ResourceWrapper rw, XhtmlNode x, BaseWrapper r) throws UnsupportedEncodingException, IOException {
    XhtmlNode c = x;
    ResourceWithReference tr = null;
    String v;
    if (r.has("reference")) {
        v = r.get("reference").primitiveValue();
        tr = resolveReference(rw, v);
        if (!v.startsWith("#")) {
            if (tr != null && tr.getReference() != null)
                c = x.ah(tr.getReference());
            else
                c = x.ah(v);
        }
    } else {
        v = "";
    }
    // what to display: if text is provided, then that. if the reference was resolved, then show the generated narrative
    if (r.has("display")) {
        c.addText(r.get("display").primitiveValue());
        if (tr != null && tr.getResource() != null) {
            c.tx(". Generated Summary: ");
            new ProfileDrivenRenderer(context).generateResourceSummary(c, tr.getResource(), true, v.startsWith("#"), false);
        }
    } else if (tr != null && tr.getResource() != null) {
        new ProfileDrivenRenderer(context).generateResourceSummary(c, tr.getResource(), v.startsWith("#"), v.startsWith("#"), false);
    } else {
        c.addText(v);
    }
}
Also used : ResourceWithReference(org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference) 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