Search in sources :

Example 6 with PropertyWrapper

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

the class NarrativeGenerator method generateResourceSummary.

private void generateResourceSummary(XhtmlNode x, ResourceWrapper res, boolean textAlready, boolean showCodeDetails) 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) || last;
                }
            }
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 7 with PropertyWrapper

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

the class ProfileDrivenRenderer 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 : PropertyWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition)

Example 8 with PropertyWrapper

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

the class ProfileDrivenRenderer 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 = getContext().getWorker().fetchResource(StructureDefinition.class, url);
                if (ed == null) {
                    if (xverManager == null) {
                        xverManager = new XVerExtensionManager(context.getWorker());
                    }
                    if (xverManager.matchingUrl(url) && xverManager.status(url) == XVerExtensionStatus.Valid) {
                        ed = xverManager.makeDefinition(url);
                        getContext().getWorker().generateSnapshot(ed);
                        getContext().getWorker().cacheResource(ed);
                    }
                }
                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") && !url.startsWith("http://hl7.org/fhir/us")) {
                            throw new DefinitionException("unknown extension " + url);
                        }
                        // System.out.println("unknown extension "+url);
                        pe = new PropertyWrapperDirect(this.context, new Property(p.getName() + "[" + url + "]", p.getTypeCode(), p.getDefinition(), p.getMinCardinality(), p.getMaxCardinality(), ex), null);
                    } else {
                        ElementDefinition def = ed.getSnapshot().getElement().get(0);
                        pe = new PropertyWrapperDirect(this.context, new Property(p.getName() + "[" + url + "]", "Extension", def.getDefinition(), def.getMin(), def.getMax().equals("*") ? Integer.MAX_VALUE : Integer.parseInt(def.getMax()), ex), ed.getSnapshot().getElementFirstRep());
                        ((PropertyWrapperDirect) pe).getWrapped().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) PropertyWrapperDirect(org.hl7.fhir.r4b.renderers.utils.DirectWrappers.PropertyWrapperDirect) PropertyWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper) Extension(org.hl7.fhir.r4b.model.Extension) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) XVerExtensionManager(org.hl7.fhir.r4b.utils.XVerExtensionManager) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) Property(org.hl7.fhir.r4b.model.Property)

Example 9 with PropertyWrapper

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

the class ProfileDrivenRenderer method generateElementByProfile.

public void generateElementByProfile(ResourceWrapper res, StructureDefinition profile, List<ElementDefinition> allElements, XhtmlNode x, String path, boolean showCodeDetails, int indent, PropertyWrapper p, ElementDefinition child) throws UnsupportedEncodingException, IOException, EOperationOutcome {
    Map<String, String> displayHints = readDisplayHints(child);
    if ("DomainResource.contained".equals(child.getBase().getPath())) {
    // if (p.getValues().size() > 0 && child != null) {
    // for (BaseWrapper v : p.getValues()) {
    // x.an(v.get("id").primitiveValue());
    // }
    // }
    } else if (!exemptFromRendering(child)) {
        if (isExtension(p)) {
            hasExtensions = true;
        }
        List<ElementDefinition> grandChildren = getChildrenForPath(allElements, path + "." + p.getName());
        filterGrandChildren(grandChildren, path + "." + p.getName(), p);
        if (p.getValues().size() > 0) {
            if (isPrimitive(child)) {
                XhtmlNode para = x.isPara() ? para = x : 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, x, list.li(), false, showCodeDetails, displayHints, path, indent);
                    } else {
                        boolean first = true;
                        for (BaseWrapper v : p.getValues()) {
                            if (first) {
                                first = false;
                            } else {
                                para.tx(", ");
                            }
                            renderLeaf(res, v, child, x, para, false, showCodeDetails, displayHints, path, indent);
                        }
                    }
                }
            } else if (canDoTable(path, p, grandChildren, x)) {
                XhtmlNode xn = new XhtmlNode(NodeType.Element, getHeader());
                xn.addText(Utilities.capitalize(Utilities.camelCase(Utilities.pluralizeMe(p.getName()))));
                XhtmlNode tbl = new XhtmlNode(NodeType.Element, "table");
                tbl.setAttribute("class", "grid");
                XhtmlNode tr = tbl.tr();
                // work around problem with empty table rows
                tr.td().tx("-");
                boolean add = addColumnHeadings(tr, grandChildren);
                for (BaseWrapper v : p.getValues()) {
                    if (v != null) {
                        tr = tbl.tr();
                        // work around problem with empty table rows
                        tr.td().tx("*");
                        add = addColumnValues(res, tr, grandChildren, v, showCodeDetails, displayHints, path, indent) || add;
                    }
                }
                if (add) {
                    x.add(xn);
                    x.add(tbl);
                }
            } else if (isExtension(p)) {
                for (BaseWrapper v : p.getValues()) {
                    if (v != null) {
                        PropertyWrapper vp = v.getChildByName("value");
                        PropertyWrapper ev = v.getChildByName("extension");
                        if (vp.hasValues()) {
                            BaseWrapper vv = vp.value();
                            XhtmlNode para = x.para();
                            para.b().addText(p.getStructure().present());
                            para.tx(": ");
                            renderLeaf(res, vv, child, x, para, false, showCodeDetails, displayHints, path, indent);
                        } else if (ev.hasValues()) {
                            XhtmlNode bq = x.addTag("blockquote");
                            bq.para().b().addText(isExtension(p) ? p.getStructure().present() : p.getName());
                            for (BaseWrapper vv : ev.getValues()) {
                                StructureDefinition ex = context.getWorker().fetchTypeDefinition("Extension");
                                List<ElementDefinition> children = getChildrenForPath(ex.getSnapshot().getElement(), "Extension");
                                generateByProfile(res, ex, vv, allElements, child, children, bq, "Extension", showCodeDetails, indent + 1);
                            }
                        }
                    }
                }
            } else {
                for (BaseWrapper v : p.getValues()) {
                    if (v != null) {
                        XhtmlNode bq = x.addTag("blockquote");
                        bq.para().b().addText(isExtension(p) ? p.getStructure().present() : p.getName());
                        generateByProfile(res, profile, v, allElements, child, grandChildren, bq, path + "." + p.getName(), showCodeDetails, indent + 1);
                    }
                }
            }
        }
    }
}
Also used : PropertyWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) List(java.util.List) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 10 with PropertyWrapper

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

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