Search in sources :

Example 86 with ResourceWrapper

use of org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper in project org.hl7.fhir.core by hapifhir.

the class ResourceRenderer method resolveReference.

protected ResourceWithReference resolveReference(ResourceWrapper res, String url) {
    if (url == null)
        return null;
    if (url.startsWith("#") && res != null) {
        for (ResourceWrapper r : res.getContained()) {
            if (r.getId().equals(url.substring(1)))
                return new ResourceWithReference(null, r);
        }
        return null;
    }
    String version = null;
    if (url.contains("/_history/")) {
        version = url.substring(url.indexOf("/_history/") + 10);
        url = url.substring(0, url.indexOf("/_history/"));
    }
    if (rcontext != null) {
        BundleEntryComponent bundleResource = rcontext.resolve(url);
        if (bundleResource != null) {
            String bundleUrl = "#" + bundleResource.getResource().getResourceType().name() + "_" + bundleResource.getResource().getId();
            return new ResourceWithReference(bundleUrl, new ResourceWrapperDirect(this.context, bundleResource.getResource()));
        }
        org.hl7.fhir.r4b.elementmodel.Element bundleElement = rcontext.resolveElement(url, version);
        if (bundleElement != null) {
            String bundleUrl = null;
            Element br = bundleElement.getNamedChild("resource");
            if (br.getChildValue("id") != null) {
                bundleUrl = "#" + br.fhirType() + "_" + br.getChildValue("id");
            } else {
                bundleUrl = "#" + fullUrlToAnchor(bundleElement.getChildValue("fullUrl"));
            }
            return new ResourceWithReference(bundleUrl, new ResourceWrapperMetaElement(this.context, br));
        }
    }
    Resource ae = getContext().getWorker().fetchResource(null, url, version);
    if (ae != null)
        return new ResourceWithReference(url, new ResourceWrapperDirect(this.context, ae));
    else if (context.getResolver() != null) {
        return context.getResolver().resolve(context, url);
    } else
        return null;
}
Also used : ResourceWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.ResourceWrapper) Element(org.hl7.fhir.r4b.elementmodel.Element) BundleEntryComponent(org.hl7.fhir.r4b.model.Bundle.BundleEntryComponent) Element(org.hl7.fhir.r4b.elementmodel.Element) ResourceWrapperMetaElement(org.hl7.fhir.r4b.renderers.utils.ElementWrappers.ResourceWrapperMetaElement) CanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource) Resource(org.hl7.fhir.r4b.model.Resource) DomainResource(org.hl7.fhir.r4b.model.DomainResource) ResourceWithReference(org.hl7.fhir.r4b.renderers.utils.Resolver.ResourceWithReference) ResourceWrapperDirect(org.hl7.fhir.r4b.renderers.utils.DirectWrappers.ResourceWrapperDirect) ResourceWrapperMetaElement(org.hl7.fhir.r4b.renderers.utils.ElementWrappers.ResourceWrapperMetaElement)

Example 87 with ResourceWrapper

use of org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper in project org.hl7.fhir.core by hapifhir.

the class ResourceRenderer method renderCanonical.

public void renderCanonical(Resource res, XhtmlNode x, String url) throws UnsupportedEncodingException, IOException {
    ResourceWrapper rw = new ResourceWrapperDirect(this.context, res);
    renderCanonical(rw, x, url);
}
Also used : ResourceWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.ResourceWrapper) ResourceWrapperDirect(org.hl7.fhir.r4b.renderers.utils.DirectWrappers.ResourceWrapperDirect)

Example 88 with ResourceWrapper

use of org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper 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.r4b.renderers.utils.BaseWrappers.PropertyWrapper) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) Coding(org.hl7.fhir.r4b.model.Coding) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 89 with ResourceWrapper

use of org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper in project org.hl7.fhir.core by hapifhir.

the class ListRenderer method render.

public boolean render(XhtmlNode x, ResourceWrapper list) throws FHIRFormatError, DefinitionException, IOException {
    if (list.has("title")) {
        x.h2().tx(list.get("title").primitiveValue());
    }
    XhtmlNode t = x.table("clstu");
    XhtmlNode tr = t.tr();
    XhtmlNode td = tr.td();
    if (list.has("date")) {
        td.tx("Date: " + list.get("date").dateTimeValue().toHumanDisplay());
    }
    if (list.has("mode")) {
        td.tx("Mode: " + list.get("mode").primitiveValue());
    }
    if (list.has("status")) {
        td.tx("Status: " + list.get("status").primitiveValue());
    }
    if (list.has("code")) {
        td.tx("Code: " + displayBase(list.get("code")));
    }
    tr = t.tr();
    td = tr.td();
    if (list.has("subject")) {
        td.tx("Subject: ");
        shortForRef(td, list.get("subject"));
    }
    if (list.has("encounter")) {
        td.tx("Encounter: ");
        shortForRef(td, list.get("encounter"));
    }
    if (list.has("source")) {
        td.tx("Source: ");
        shortForRef(td, list.get("encounter"));
    }
    if (list.has("orderedBy")) {
        td.tx("Order: " + displayBase(list.get("orderedBy")));
    }
    // for (Annotation a : list.getNote()) {
    // renderAnnotation(a, x);
    // }
    boolean flag = false;
    boolean deleted = false;
    boolean date = false;
    for (BaseWrapper e : list.children("entry")) {
        flag = flag || e.has("flag");
        deleted = deleted || e.has("deleted");
        date = date || e.has("date");
    }
    t = x.table("grid");
    tr = t.tr().style("backgound-color: #eeeeee");
    tr.td().b().tx("Items");
    if (date) {
        tr.td().tx("Date");
    }
    if (flag) {
        tr.td().tx("Flag");
    }
    if (deleted) {
        tr.td().tx("Deleted");
    }
    for (BaseWrapper e : list.children("entry")) {
        tr = t.tr();
        shortForRef(tr.td(), e.get("item"));
        if (date) {
            tr.td().tx(e.has("date") ? e.get("date").dateTimeValue().toHumanDisplay() : "");
        }
        if (flag) {
            tr.td().tx(e.has("flag") ? displayBase(e.get("flag")) : "");
        }
        if (deleted) {
            tr.td().tx(e.has("deleted") ? e.get("deleted").primitiveValue() : "");
        }
    }
    return false;
}
Also used : BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 90 with ResourceWrapper

use of org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper in project org.hl7.fhir.core by hapifhir.

the class LiquidRenderer method render.

@Override
public boolean render(XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
    LiquidEngine engine = new LiquidEngine(context.getWorker(), context.getServices());
    XhtmlNode xn;
    try {
        LiquidDocument doc = engine.parse(liquidTemplate, "template");
        String html = engine.evaluate(doc, r.getBase(), rcontext);
        xn = new XhtmlParser().parseFragment(html);
        if (!x.getName().equals("div"))
            throw new FHIRException("Error in template: Root element is not 'div'");
    } catch (FHIRException | IOException e) {
        xn = new XhtmlNode(NodeType.Element, "div");
        xn.para().b().style("color: maroon").tx("Exception generating Narrative: " + e.getMessage());
    }
    x.getChildNodes().addAll(xn.getChildNodes());
    return true;
}
Also used : LiquidDocument(org.hl7.fhir.r4b.utils.LiquidEngine.LiquidDocument) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) IOException(java.io.IOException) LiquidEngine(org.hl7.fhir.r4b.utils.LiquidEngine) FHIRException(org.hl7.fhir.exceptions.FHIRException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)57 BaseWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper)17 BaseWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper)17 NotImplementedException (org.apache.commons.lang3.NotImplementedException)13 PropertyWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper)13 PropertyWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper)13 ResourceWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper)9 ResourceWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.ResourceWrapper)8 IOException (java.io.IOException)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)7 Base64 (org.apache.commons.codec.binary.Base64)6 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)6 ResourceWithReference (org.hl7.fhir.r4b.renderers.utils.Resolver.ResourceWithReference)6 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)6 ResourceWithReference (org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference)6 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)6 Row (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 ArrayList (java.util.ArrayList)5 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)3