Search in sources :

Example 16 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)) {
        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.r4b.renderers.utils.BaseWrappers.PropertyWrapper) HumanName(org.hl7.fhir.r4b.model.HumanName) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) Identifier(org.hl7.fhir.r4b.model.Identifier) DateType(org.hl7.fhir.r4b.model.DateType)

Example 17 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.r4b.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 18 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.size() == 0) {
        r.getCells().add(gen.new Cell(null, null, null, null, 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.r4b.renderers.utils.BaseWrappers.BaseWrapper) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

Example 19 with BaseWrapper

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

the class ParametersRenderer method paramsW.

private void paramsW(XhtmlNode tbl, List<BaseWrapper> list, int indent) throws FHIRFormatError, DefinitionException, FHIRException, IOException, EOperationOutcome {
    for (BaseWrapper p : list) {
        XhtmlNode tr = tbl.tr();
        XhtmlNode td = tr.td();
        for (int i = 0; i < indent; i++) {
            td.tx(XhtmlNode.NBSP);
        }
        if (p.has("name")) {
            td.tx(p.get("name").primitiveValue());
        } else {
            td.tx("???");
        }
        if (p.has("value")) {
            renderBase(tr.td(), p.get("value"));
        } else if (p.has("resource")) {
            ResourceWrapper rw = p.getChildByName("resource").getAsResource();
            td = tr.td();
            XhtmlNode para = td.para();
            para.tx(rw.fhirType() + "/" + rw.getId());
            para.an(rw.fhirType() + "_" + rw.getId()).tx(" ");
            XhtmlNode x = rw.getNarrative();
            if (x != null) {
                td.addChildren(x);
            } else {
                ResourceRenderer rr = RendererFactory.factory(rw, context, rcontext);
                rr.render(td, rw);
            }
        } else if (p.has("part")) {
            tr.td();
            PropertyWrapper pw = getProperty(p, "part");
            paramsW(tbl, pw.getValues(), 1);
        }
    }
}
Also used : ResourceWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.ResourceWrapper) PropertyWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 20 with BaseWrapper

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

the class DiagnosticReportRenderer method addObservationToTable.

private void addObservationToTable(XhtmlNode tr, ResourceWrapper obs, int i, String ref, boolean refRange, boolean flags, boolean note, boolean effectiveTime, boolean issued, DataType eff, DataType iss) throws UnsupportedEncodingException, FHIRException, IOException {
    // code (+bodysite)
    XhtmlNode td = tr.td();
    PropertyWrapper pw = getProperty(obs, "code");
    if (valued(pw)) {
        render(td.ah(ref), pw.value());
    }
    pw = getProperty(obs, "bodySite");
    if (valued(pw)) {
        td.tx(" (");
        render(td, pw.value());
        td.tx(")");
    }
    // value / dataAbsentReason (in red)
    td = tr.td();
    pw = getProperty(obs, "value[x]");
    if (valued(pw)) {
        render(td, pw.value());
    } else {
        pw = getProperty(obs, "dataAbsentReason");
        if (valued(pw)) {
            XhtmlNode span = td.span("color: maroon", "Error");
            span.tx("Error: ");
            render(span.b(), pw.value());
        }
    }
    if (refRange) {
        // reference range
        td = tr.td();
        pw = getProperty(obs, "referenceRange");
        if (valued(pw)) {
            boolean first = true;
            for (BaseWrapper v : pw.getValues()) {
                if (first)
                    first = false;
                else
                    td.br();
                PropertyWrapper pwr = getProperty(v, "type");
                if (valued(pwr)) {
                    render(td, pwr.value());
                    td.tx(": ");
                }
                PropertyWrapper pwt = getProperty(v, "text");
                if (valued(pwt)) {
                    render(td, pwt.value());
                } else {
                    PropertyWrapper pwl = getProperty(v, "low");
                    PropertyWrapper pwh = getProperty(v, "high");
                    if (valued(pwl) && valued(pwh)) {
                        render(td, pwl.value());
                        td.tx(" - ");
                        render(td, pwh.value());
                    } else if (valued(pwl)) {
                        td.tx(">");
                        render(td, pwl.value());
                    } else if (valued(pwh)) {
                        td.tx("<");
                        render(td, pwh.value());
                    } else {
                        td.tx("??");
                    }
                }
                pwr = getProperty(v, "appliesTo");
                PropertyWrapper pwrA = getProperty(v, "age");
                if (valued(pwr) || valued(pwrA)) {
                    boolean firstA = true;
                    td.tx(" for ");
                    if (valued(pwr)) {
                        for (BaseWrapper va : pwr.getValues()) {
                            if (firstA)
                                firstA = false;
                            else
                                td.tx(", ");
                            render(td, va);
                        }
                    }
                    if (valued(pwrA)) {
                        if (firstA)
                            firstA = false;
                        else
                            td.tx(", ");
                        td.tx("Age ");
                        render(td, pwrA.value());
                    }
                }
            }
        }
    }
    if (flags) {
        // flags (status other than F, interpretation, )
        td = tr.td();
        boolean first = true;
        pw = getProperty(obs, "status");
        if (valued(pw)) {
            if (!pw.value().getBase().primitiveValue().equals("final")) {
                if (first)
                    first = false;
                else
                    td.br();
                render(td, pw.value());
            }
        }
        pw = getProperty(obs, "interpretation");
        if (valued(pw)) {
            for (BaseWrapper v : pw.getValues()) {
                if (first)
                    first = false;
                else
                    td.br();
                render(td, v);
            }
        }
    }
    if (note) {
        td = tr.td();
        pw = getProperty(obs, "note");
        if (valued(pw)) {
            render(td, pw.value());
        }
    }
    if (effectiveTime) {
        // effective if different to DR
        td = tr.td();
        pw = getProperty(obs, "effective[x]");
        if (valued(pw)) {
            if (!Base.compareDeep(pw.value().getBase(), eff, true)) {
                render(td, pw.value());
            }
        }
    }
    if (issued) {
        // issued if different to DR
        td = tr.td();
        pw = getProperty(obs, "issued");
        if (valued(pw)) {
            if (!Base.compareDeep(pw.value().getBase(), eff, true)) {
                render(td, pw.value());
            }
        }
    }
}
Also used : PropertyWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) 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