Search in sources :

Example 16 with PropertyWrapper

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

the class LibraryRenderer method render.

public boolean render(XhtmlNode x, ResourceWrapper lib) throws FHIRFormatError, DefinitionException, IOException {
    PropertyWrapper authors = lib.getChildByName("author");
    PropertyWrapper editors = lib.getChildByName("editor");
    PropertyWrapper reviewers = lib.getChildByName("reviewer");
    PropertyWrapper endorsers = lib.getChildByName("endorser");
    if ((authors != null && authors.hasValues()) || (editors != null && editors.hasValues()) || (reviewers != null && reviewers.hasValues()) || (endorsers != null && endorsers.hasValues())) {
        boolean email = hasCT(authors, "email") || hasCT(editors, "email") || hasCT(reviewers, "email") || hasCT(endorsers, "email");
        boolean phone = hasCT(authors, "phone") || hasCT(editors, "phone") || hasCT(reviewers, "phone") || hasCT(endorsers, "phone");
        boolean url = hasCT(authors, "url") || hasCT(editors, "url") || hasCT(reviewers, "url") || hasCT(endorsers, "url");
        x.h2().tx("Participants");
        XhtmlNode t = x.table("grid");
        if (authors != null) {
            for (BaseWrapper cd : authors.getValues()) {
                participantRow(t, "Author", cd, email, phone, url);
            }
        }
        if (authors != null) {
            for (BaseWrapper cd : editors.getValues()) {
                participantRow(t, "Editor", cd, email, phone, url);
            }
        }
        if (authors != null) {
            for (BaseWrapper cd : reviewers.getValues()) {
                participantRow(t, "Reviewer", cd, email, phone, url);
            }
        }
        if (authors != null) {
            for (BaseWrapper cd : endorsers.getValues()) {
                participantRow(t, "Endorser", cd, email, phone, url);
            }
        }
    }
    PropertyWrapper artifacts = lib.getChildByName("relatedArtifact");
    if (artifacts != null && artifacts.hasValues()) {
        x.h2().tx("Related Artifacts");
        XhtmlNode t = x.table("grid");
        boolean label = false;
        boolean display = false;
        boolean citation = false;
        for (BaseWrapper ra : artifacts.getValues()) {
            label = label || ra.has("label");
            display = display || ra.has("display");
            citation = citation || ra.has("citation");
        }
        for (BaseWrapper ra : artifacts.getValues()) {
            renderArtifact(t, ra, lib, label, display, citation);
        }
    }
    PropertyWrapper parameters = lib.getChildByName("parameter");
    if (parameters != null && parameters.hasValues()) {
        x.h2().tx("Parameters");
        XhtmlNode t = x.table("grid");
        boolean doco = false;
        for (BaseWrapper p : parameters.getValues()) {
            doco = doco || p.has("documentation");
        }
        for (BaseWrapper p : parameters.getValues()) {
            renderParameter(t, p, doco);
        }
    }
    PropertyWrapper dataRequirements = lib.getChildByName("dataRequirement");
    if (dataRequirements != null && dataRequirements.hasValues()) {
        x.h2().tx("Data Requirements");
        for (BaseWrapper p : dataRequirements.getValues()) {
            renderDataRequirement(x, (DataRequirement) p.getBase());
        }
    }
    PropertyWrapper contents = lib.getChildByName("content");
    if (contents != null) {
        x.h2().tx("Contents");
        boolean isCql = false;
        int counter = 0;
        for (BaseWrapper p : contents.getValues()) {
            Attachment att = (Attachment) p.getBase();
            renderAttachment(x, att, isCql, counter, lib.getId());
            isCql = isCql || (att.hasContentType() && att.getContentType().startsWith("text/cql"));
            counter++;
        }
    }
    return false;
}
Also used : PropertyWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper) BaseWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper) Attachment(org.hl7.fhir.r5.model.Attachment) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 17 with PropertyWrapper

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

the class NarrativeGenerator method splitExtensions.

private List<PropertyWrapper> splitExtensions(StructureDefinition profile, List<PropertyWrapper> children) throws UnsupportedEncodingException, IOException, FHIRException {
    List<PropertyWrapper> results = new ArrayList<PropertyWrapper>();
    Map<String, PropertyWrapper> map = new HashMap<String, PropertyWrapper>();
    for (PropertyWrapper p : children) if (p.getName().equals("extension") || p.getName().equals("modifierExtension")) {
        // we're going to split these up, and create a property for each url
        if (p.hasValues()) {
            for (BaseWrapper v : p.getValues()) {
                Extension ex = (Extension) v.getBase();
                String url = ex.getUrl();
                StructureDefinition ed = context.fetchResource(StructureDefinition.class, url);
                if (p.getName().equals("modifierExtension") && ed == null)
                    throw new DefinitionException("Unknown modifier extension " + url);
                PropertyWrapper pe = map.get(p.getName() + "[" + url + "]");
                if (pe == null) {
                    if (ed == null) {
                        if (url.startsWith("http://hl7.org/fhir"))
                            throw new DefinitionException("unknown extension " + url);
                        // System.out.println("unknown extension "+url);
                        pe = new PropertyWrapperDirect(new Property(p.getName() + "[" + url + "]", p.getTypeCode(), p.getDefinition(), p.getMinCardinality(), p.getMaxCardinality(), ex));
                    } else {
                        ElementDefinition def = ed.getSnapshot().getElement().get(0);
                        pe = new PropertyWrapperDirect(new Property(p.getName() + "[" + url + "]", "Extension", def.getDefinition(), def.getMin(), def.getMax().equals("*") ? Integer.MAX_VALUE : Integer.parseInt(def.getMax()), ex));
                        ((PropertyWrapperDirect) pe).wrapped.setStructure(ed);
                    }
                    results.add(pe);
                } else
                    pe.getValues().add(v);
            }
        }
    } else
        results.add(p);
    return results;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Extension(org.hl7.fhir.dstu3.model.Extension) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) Property(org.hl7.fhir.dstu3.model.Property)

Example 18 with PropertyWrapper

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

use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper 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, int indent, ResourceContext rc) throws FHIRException, UnsupportedEncodingException, IOException {
    if (children.isEmpty()) {
        renderLeaf(res, e, defn, x, false, showCodeDetails, readDisplayHints(defn), path, indent, rc);
    } 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.para();
                                String name = p.getName();
                                if (name.endsWith("[x]"))
                                    name = name.substring(0, name.length() - 3);
                                if (showCodeDetails || !isDefaultValue(displayHints, p.getValues())) {
                                    para.b().addText(name);
                                    para.tx(": ");
                                    if (renderAsList(child) && p.getValues().size() > 1) {
                                        XhtmlNode list = x.ul();
                                        for (BaseWrapper v : p.getValues()) renderLeaf(res, v, child, list.li(), false, showCodeDetails, displayHints, path, indent, rc);
                                    } else {
                                        boolean first = true;
                                        for (BaseWrapper v : p.getValues()) {
                                            if (first)
                                                first = false;
                                            else
                                                para.tx(", ");
                                            renderLeaf(res, v, child, para, false, showCodeDetails, displayHints, path, indent, rc);
                                        }
                                    }
                                }
                            } else if (canDoTable(path, p, grandChildren)) {
                                x.addTag(getHeader()).addText(Utilities.capitalize(Utilities.camelCase(Utilities.pluralizeMe(p.getName()))));
                                XhtmlNode tbl = x.table("grid");
                                XhtmlNode tr = tbl.tr();
                                // work around problem with empty table rows
                                tr.td().tx("-");
                                addColumnHeadings(tr, grandChildren);
                                for (BaseWrapper v : p.getValues()) {
                                    if (v != null) {
                                        tr = tbl.tr();
                                        // work around problem with empty table rows
                                        tr.td().tx("*");
                                        addColumnValues(res, tr, grandChildren, v, showCodeDetails, displayHints, path, indent, rc);
                                    }
                                }
                            } else {
                                for (BaseWrapper v : p.getValues()) {
                                    if (v != null) {
                                        XhtmlNode bq = x.addTag("blockquote");
                                        bq.para().b().addText(p.getName());
                                        generateByProfile(res, profile, v, allElements, child, grandChildren, bq, path + "." + p.getName(), showCodeDetails, indent + 1, rc);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 20 with PropertyWrapper

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

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)32 PropertyWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper)17 PropertyWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper)17 ArrayList (java.util.ArrayList)14 BaseWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper)13 BaseWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper)13 HashMap (java.util.HashMap)5 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)5 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)5 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)5 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)4 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)4 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)4 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)3 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)3 List (java.util.List)2 StructureDefinition (org.hl7.fhir.dstu2.model.StructureDefinition)2 StructureDefinition (org.hl7.fhir.dstu2016may.model.StructureDefinition)2 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)2 DateType (org.hl7.fhir.r4b.model.DateType)2