Search in sources :

Example 46 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.r5.renderers.utils.BaseWrappers.ResourceWrapper) PropertyWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper) BaseWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 47 with BaseWrapper

use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper 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.r5.renderers.utils.DirectWrappers.PropertyWrapperDirect) PropertyWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper) Extension(org.hl7.fhir.r5.model.Extension) BaseWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) XVerExtensionManager(org.hl7.fhir.r5.utils.XVerExtensionManager) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) Property(org.hl7.fhir.r5.model.Property)

Example 48 with BaseWrapper

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

the class ProfileDrivenRenderer method displayLeaf.

private boolean displayLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, String name, boolean showCodeDetails, boolean allowLinks) throws FHIRException, UnsupportedEncodingException, IOException {
    if (ew == null)
        return false;
    Base e = ew.getBase();
    if (e == null)
        return false;
    Map<String, String> displayHints = readDisplayHints(defn);
    if (name.endsWith("[x]"))
        name = name.substring(0, name.length() - 3);
    if (!showCodeDetails && e instanceof PrimitiveType && isDefault(displayHints, ((PrimitiveType) e)))
        return false;
    if (e instanceof StringType) {
        x.addText(name + ": " + ((StringType) e).getValue());
        return true;
    } else if (e instanceof CodeType) {
        x.addText(name + ": " + ((CodeType) e).getValue());
        return true;
    } else if (e instanceof IdType) {
        x.addText(name + ": " + ((IdType) e).getValue());
        return true;
    } else if (e instanceof UriType) {
        if (Utilities.isAbsoluteUrlLinkable(((UriType) e).getValue()) && allowLinks) {
            x.tx(name + ": ");
            x.ah(((UriType) e).getValue()).addText(((UriType) e).getValue());
        } else {
            x.addText(name + ": " + ((UriType) e).getValue());
        }
        return true;
    } else if (e instanceof DateTimeType) {
        x.addText(name + ": " + ((DateTimeType) e).toHumanDisplay());
        return true;
    } else if (e instanceof InstantType) {
        x.addText(name + ": " + ((InstantType) e).toHumanDisplay());
        return true;
    } else if (e instanceof Extension) {
        // x.tx("Extensions: todo");
        return false;
    } else if (e instanceof org.hl7.fhir.r5.model.DateType) {
        x.addText(name + ": " + ((org.hl7.fhir.r5.model.DateType) e).toHumanDisplay());
        return true;
    } else if (e instanceof Enumeration) {
        // todo: look up a display name if there is one
        x.addText(((Enumeration<?>) e).getValue().toString());
        return true;
    } else if (e instanceof BooleanType) {
        if (((BooleanType) e).hasValue()) {
            x.addText(name);
            x.addText(": ");
            x.addText(((BooleanType) e).getValueAsString());
            return true;
        }
    } else if (e instanceof CodeableReference) {
        if (((CodeableReference) e).hasReference()) {
            Reference r = ((CodeableReference) e).getReference();
            renderReference(res, x, r, allowLinks);
        } else {
            renderCodeableConcept(x, ((CodeableReference) e).getConcept(), showCodeDetails);
        }
        return true;
    } else if (e instanceof CodeableConcept) {
        renderCodeableConcept(x, (CodeableConcept) e, showCodeDetails);
        return true;
    } else if (e instanceof Coding) {
        renderCoding(x, (Coding) e, showCodeDetails);
        return true;
    } else if (e instanceof Annotation) {
        renderAnnotation(x, (Annotation) e, showCodeDetails);
        return true;
    } else if (e instanceof org.hl7.fhir.r5.model.IntegerType) {
        x.addText(Integer.toString(((org.hl7.fhir.r5.model.IntegerType) e).getValue()));
        return true;
    } else if (e instanceof org.hl7.fhir.r5.model.DecimalType) {
        x.addText(((org.hl7.fhir.r5.model.DecimalType) e).getValue().toString());
        return true;
    } else if (e instanceof Identifier) {
        renderIdentifier(x, (Identifier) e);
        return true;
    } else if (e instanceof HumanName) {
        renderHumanName(x, (HumanName) e);
        return true;
    } else if (e instanceof SampledData) {
        renderSampledData(x, (SampledData) e);
        return true;
    } else if (e instanceof Address) {
        renderAddress(x, (Address) e);
        return true;
    } else if (e instanceof ContactPoint) {
        if (allowLinks) {
            renderContactPoint(x, (ContactPoint) e);
        } else {
            displayContactPoint(x, (ContactPoint) e);
        }
        return true;
    } else if (e instanceof Timing) {
        renderTiming(x, (Timing) e);
        return true;
    } else if (e instanceof Quantity) {
        renderQuantity(x, (Quantity) e, showCodeDetails);
        return true;
    } else if (e instanceof Ratio) {
        renderQuantity(x, ((Ratio) e).getNumerator(), showCodeDetails);
        x.tx("/");
        renderQuantity(x, ((Ratio) e).getDenominator(), showCodeDetails);
        return true;
    } else if (e instanceof Period) {
        Period p = (Period) e;
        x.addText(name + ": ");
        x.addText(!p.hasStart() ? "?ngen-2?" : p.getStartElement().toHumanDisplay());
        x.tx(" --> ");
        x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
        return true;
    } else if (e instanceof Reference) {
        Reference r = (Reference) e;
        if (r.hasDisplayElement())
            x.addText(r.getDisplay());
        else if (r.hasReferenceElement()) {
            ResourceWithReference tr = resolveReference(res, r.getReference());
            // getDisplayForReference(tr.getReference()));
            x.addText(tr == null ? r.getReference() : "?ngen-3");
        } else
            x.tx("?ngen-4?");
        return true;
    } else if (e instanceof Narrative) {
        return false;
    } else if (e instanceof Resource) {
        return false;
    } else if (e instanceof ContactDetail) {
        ContactDetail cd = (ContactDetail) e;
        if (cd.hasName()) {
            x.tx(cd.getName() + ": ");
        }
        boolean first = true;
        for (ContactPoint c : cd.getTelecom()) {
            if (first)
                first = false;
            else
                x.tx(",");
            if (allowLinks) {
                renderContactPoint(x, c);
            } else {
                displayContactPoint(x, c);
            }
        }
        return true;
    } else if (e instanceof Range) {
        return false;
    } else if (e instanceof Meta) {
        return false;
    } else if (e instanceof Dosage) {
        return false;
    } else if (e instanceof Signature) {
        return false;
    } else if (e instanceof UsageContext) {
        return false;
    } else if (e instanceof RelatedArtifact) {
        return false;
    } else if (e instanceof ElementDefinition) {
        return false;
    } else if (e instanceof Base64BinaryType) {
        return false;
    } else if (!(e instanceof Attachment))
        throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet");
    return false;
}
Also used : Meta(org.hl7.fhir.r5.model.Meta) Address(org.hl7.fhir.r5.model.Address) StringType(org.hl7.fhir.r5.model.StringType) Attachment(org.hl7.fhir.r5.model.Attachment) Dosage(org.hl7.fhir.r5.model.Dosage) Identifier(org.hl7.fhir.r5.model.Identifier) Coding(org.hl7.fhir.r5.model.Coding) Narrative(org.hl7.fhir.r5.model.Narrative) SampledData(org.hl7.fhir.r5.model.SampledData) PrimitiveType(org.hl7.fhir.r5.model.PrimitiveType) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) InstantType(org.hl7.fhir.r5.model.InstantType) Resource(org.hl7.fhir.r5.model.Resource) DomainResource(org.hl7.fhir.r5.model.DomainResource) Period(org.hl7.fhir.r5.model.Period) ResourceWithReference(org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference) Range(org.hl7.fhir.r5.model.Range) RelatedArtifact(org.hl7.fhir.r5.model.RelatedArtifact) IdType(org.hl7.fhir.r5.model.IdType) DateTimeType(org.hl7.fhir.r5.model.DateTimeType) UsageContext(org.hl7.fhir.r5.model.UsageContext) Timing(org.hl7.fhir.r5.model.Timing) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept) NotImplementedException(org.apache.commons.lang3.NotImplementedException) UriType(org.hl7.fhir.r5.model.UriType) HumanName(org.hl7.fhir.r5.model.HumanName) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) Ratio(org.hl7.fhir.r5.model.Ratio) Enumeration(org.hl7.fhir.r5.model.Enumeration) Reference(org.hl7.fhir.r5.model.Reference) ResourceWithReference(org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference) CodeableReference(org.hl7.fhir.r5.model.CodeableReference) BooleanType(org.hl7.fhir.r5.model.BooleanType) Quantity(org.hl7.fhir.r5.model.Quantity) Base(org.hl7.fhir.r5.model.Base) Annotation(org.hl7.fhir.r5.model.Annotation) Extension(org.hl7.fhir.r5.model.Extension) ContactDetail(org.hl7.fhir.r5.model.ContactDetail) CodeableReference(org.hl7.fhir.r5.model.CodeableReference) Signature(org.hl7.fhir.r5.model.Signature) CodeType(org.hl7.fhir.r5.model.CodeType) Base64BinaryType(org.hl7.fhir.r5.model.Base64BinaryType)

Example 49 with BaseWrapper

use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper 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.r5.renderers.utils.BaseWrappers.PropertyWrapper) BaseWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition)

Example 50 with BaseWrapper

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

the class ProfileDrivenRenderer method generateResourceSummary.

// 
// public void inject(Element er, XhtmlNode x, NarrativeStatus status, boolean pretty) {
// if (!x.hasAttribute("xmlns"))
// x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
// Element le = XMLUtil.getNamedChild(er, "language");
// String l = le == null ? null : le.getAttribute("value");
// if (!Utilities.noString(l)) {
// // use both - see https://www.w3.org/TR/i18n-html-tech-lang/#langvalues
// x.setAttribute("lang", l);
// x.setAttribute("xml:lang", l);
// }
// Element txt = XMLUtil.getNamedChild(er, "text");
// if (txt == null) {
// txt = er.getOwnerDocument().createElementNS(FormatUtilities.FHIR_NS, "text");
// Element n = XMLUtil.getFirstChild(er);
// while (n != null && (n.getNodeName().equals("id") || n.getNodeName().equals("meta") || n.getNodeName().equals("implicitRules") || n.getNodeName().equals("language")))
// n = XMLUtil.getNextSibling(n);
// if (n == null)
// er.appendChild(txt);
// else
// er.insertBefore(txt, n);
// }
// Element st = XMLUtil.getNamedChild(txt, "status");
// if (st == null) {
// st = er.getOwnerDocument().createElementNS(FormatUtilities.FHIR_NS, "status");
// Element n = XMLUtil.getFirstChild(txt);
// if (n == null)
// txt.appendChild(st);
// else
// txt.insertBefore(st, n);
// }
// st.setAttribute("value", status.toCode());
// Element div = XMLUtil.getNamedChild(txt, "div");
// if (div == null) {
// div = er.getOwnerDocument().createElementNS(FormatUtilities.XHTML_NS, "div");
// div.setAttribute("xmlns", FormatUtilities.XHTML_NS);
// txt.appendChild(div);
// }
// if (div.hasChildNodes())
// div.appendChild(er.getOwnerDocument().createElementNS(FormatUtilities.XHTML_NS, "hr"));
// new XhtmlComposer(XhtmlComposer.XML, pretty).compose(div, x);
// }
// 
// public void inject(org.hl7.fhir.r5.elementmodel.Element er, XhtmlNode x, NarrativeStatus status, boolean pretty) throws IOException, FHIRException {
// if (!x.hasAttribute("xmlns"))
// x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
// String l = er.getChildValue("language");
// if (!Utilities.noString(l)) {
// // use both - see https://www.w3.org/TR/i18n-html-tech-lang/#langvalues
// x.setAttribute("lang", l);
// x.setAttribute("xml:lang", l);
// }
// org.hl7.fhir.r5.elementmodel.Element txt = er.getNamedChild("text");
// if (txt == null) {
// txt = new org.hl7.fhir.r5.elementmodel.Element("text", er.getProperty().getChild(null, "text"));
// int i = 0;
// while (i < er.getChildren().size() && (er.getChildren().get(i).getName().equals("id") || er.getChildren().get(i).getName().equals("meta") || er.getChildren().get(i).getName().equals("implicitRules") || er.getChildren().get(i).getName().equals("language")))
// i++;
// if (i >= er.getChildren().size())
// er.getChildren().add(txt);
// else
// er.getChildren().add(i, txt);
// }
// org.hl7.fhir.r5.elementmodel.Element st = txt.getNamedChild("status");
// if (st == null) {
// st = new org.hl7.fhir.r5.elementmodel.Element("status", txt.getProperty().getChild(null, "status"));
// txt.getChildren().add(0, st);
// }
// st.setValue(status.toCode());
// org.hl7.fhir.r5.elementmodel.Element div = txt.getNamedChild("div");
// if (div == null) {
// div = new org.hl7.fhir.r5.elementmodel.Element("div", txt.getProperty().getChild(null, "div"));
// txt.getChildren().add(div);
// div.setValue(new XhtmlComposer(XhtmlComposer.XML, pretty).compose(x));
// }
// div.setValue(x.toString());
// div.setXhtml(x);
// }
// 
public void generateResourceSummary(XhtmlNode x, ResourceWrapper res, boolean textAlready, boolean showCodeDetails, boolean canLink) 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.fhirType();
    StructureDefinition profile = getContext().getWorker().fetchResource(StructureDefinition.class, path);
    if (profile == null)
        x.tx("unknown resource " + path);
    else {
        boolean firstElement = true;
        boolean last = false;
        for (PropertyWrapper p : res.children()) {
            if (!ignoreProperty(p) && !p.getElementDefinition().getBase().getPath().startsWith("Resource.")) {
                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, p.getValues())) {
                    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, canLink) || last;
                    }
                }
            }
        }
    }
}
Also used : PropertyWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) BaseWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) 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