Search in sources :

Example 41 with ResourceWrapper

use of org.hl7.fhir.r4b.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.r5.renderers.utils.BaseWrappers.ResourceWrapper) ResourceWrapperDirect(org.hl7.fhir.r5.renderers.utils.DirectWrappers.ResourceWrapperDirect)

Example 42 with ResourceWrapper

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

the class ResourceRenderer method renderReference.

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

Example 43 with ResourceWrapper

use of org.hl7.fhir.r4b.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.r5.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.r5.renderers.utils.BaseWrappers.ResourceWrapper) BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) ResourceWrapperMetaElement(org.hl7.fhir.r5.renderers.utils.ElementWrappers.ResourceWrapperMetaElement) Element(org.hl7.fhir.r5.elementmodel.Element) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) DomainResource(org.hl7.fhir.r5.model.DomainResource) Resource(org.hl7.fhir.r5.model.Resource) ResourceWithReference(org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference) ResourceWrapperDirect(org.hl7.fhir.r5.renderers.utils.DirectWrappers.ResourceWrapperDirect) Element(org.hl7.fhir.r5.elementmodel.Element) ResourceWrapperMetaElement(org.hl7.fhir.r5.renderers.utils.ElementWrappers.ResourceWrapperMetaElement)

Example 44 with ResourceWrapper

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

the class ResourceRenderer method renderReference.

public void renderReference(ResourceWrapper rw, XhtmlNode x, Reference r, boolean allowLinks) throws UnsupportedEncodingException, IOException {
    if (r == null) {
        x.tx("null!");
        return;
    }
    XhtmlNode c = null;
    ResourceWithReference tr = null;
    if (r.hasReferenceElement() && allowLinks) {
        tr = resolveReference(rw, r.getReference());
        if (!r.getReference().startsWith("#")) {
            if (tr != null && tr.getReference() != null)
                c = x.ah(tr.getReference());
            else
                c = x.ah(r.getReference());
        } else {
            c = x.ah(r.getReference());
        }
    } else {
        c = x.span(null, null);
    }
    if (tr != null && tr.getReference() != null && tr.getReference().startsWith("#")) {
        c.tx("See above (");
    }
    // what to display: if text is provided, then that. if the reference was resolved, then show the name, or the generated narrative
    String display = r.hasDisplayElement() ? r.getDisplay() : null;
    String name = tr != null && tr.getResource() != null ? tr.getResource().getNameFromResource() : null;
    if (display == null && (tr == null || tr.getResource() == null)) {
        c.addText(r.getReference());
    } else if (context.isTechnicalMode()) {
        c.addText(r.getReference());
        if (display != null) {
            c.addText(": " + display);
        }
        if ((tr == null || !tr.getReference().startsWith("#")) && name != null) {
            x.addText(" \"" + name + "\"");
        }
        if (r.hasExtension(ToolingExtensions.EXT_TARGET_ID)) {
            x.addText("(#" + r.getExtensionString(ToolingExtensions.EXT_TARGET_ID) + ")");
        } else if (r.hasExtension(ToolingExtensions.EXT_TARGET_PATH)) {
            x.addText("(#/" + r.getExtensionString(ToolingExtensions.EXT_TARGET_PATH) + ")");
        }
    } else {
        if (display != null) {
            c.addText(display);
        } else if (name != null) {
            c.addText(name);
        } else {
            c.tx(". Generated Summary: ");
            if (tr != null) {
                new ProfileDrivenRenderer(context).generateResourceSummary(c, tr.getResource(), true, r.getReference().startsWith("#"), true);
            }
        }
    }
    if (tr != null && tr.getReference() != null && tr.getReference().startsWith("#")) {
        c.tx(")");
    }
}
Also used : ResourceWithReference(org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 45 with ResourceWrapper

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

the class ResourceRenderer method renderCanonical.

public void renderCanonical(ResourceWrapper rw, XhtmlNode x, String url, boolean allowLinks) throws UnsupportedEncodingException, IOException {
    if (url == null) {
        return;
    }
    Resource target = context.getWorker().fetchResource(Resource.class, url);
    if (target == null || !(target instanceof CanonicalResource)) {
        x.code().tx(url);
    } else {
        CanonicalResource cr = (CanonicalResource) target;
        if (url.contains("|")) {
            if (target.hasUserData("path")) {
                x.ah(target.getUserString("path")).tx(cr.present() + " (version " + cr.getVersion() + ")");
            } else {
                url = url.substring(0, url.indexOf("|"));
                x.code().tx(url);
                x.tx(": " + cr.present() + " (version " + cr.getVersion() + ")");
            }
        } else {
            if (target.hasUserData("path")) {
                x.ah(target.getUserString("path")).tx(cr.present());
            } else {
                x.code().tx(url);
                x.tx(" (" + cr.present() + ")");
            }
        }
    }
}
Also used : CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) DomainResource(org.hl7.fhir.r5.model.DomainResource) Resource(org.hl7.fhir.r5.model.Resource) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource)

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