Search in sources :

Example 51 with BaseWrapper

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

the class QuestionnaireResponseRenderer method renderTree.

public boolean renderTree(XhtmlNode x, ResourceWrapper qr) throws UnsupportedEncodingException, IOException {
    HierarchicalTableGenerator gen = new HierarchicalTableGenerator(context.getDestDir(), context.isInlineGraphics(), true);
    TableModel model = gen.new TableModel("qtree=" + qr.getId(), false);
    model.setAlternating(true);
    model.setDocoImg(context.getSpecificationLink() + "help16.png");
    model.setDocoRef(context.getSpecificationLink() + "formats.html#table");
    model.getTitles().add(gen.new Title(null, model.getDocoRef(), translate("sd.head", "LinkId"), translate("sd.hint", "The linkId for the item"), null, 0));
    model.getTitles().add(gen.new Title(null, model.getDocoRef(), translate("sd.head", "Text"), translate("sd.hint", "Text for the item"), null, 0));
    model.getTitles().add(gen.new Title(null, model.getDocoRef(), translate("sd.head", "Definition"), translate("sd.hint", "Minimum and Maximum # of times the the itemcan appear in the instance"), null, 0));
    model.getTitles().add(gen.new Title(null, model.getDocoRef(), translate("sd.head", "Answer"), translate("sd.hint", "The type of the item"), null, 0));
    boolean hasExt = false;
    // first we add a root for the questionaire itself
    Row row = addTreeRoot(gen, model.getRows(), qr);
    List<BaseWrapper> items = qr.children("item");
    for (BaseWrapper i : items) {
        hasExt = renderTreeItem(gen, row.getSubRows(), qr, i) || hasExt;
    }
    XhtmlNode xn = gen.generate(model, context.getLocalPrefix(), 1, null);
    x.getChildNodes().add(xn);
    return hasExt;
}
Also used : BaseWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper) HierarchicalTableGenerator(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) TableModel(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 52 with BaseWrapper

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

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

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

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