Search in sources :

Example 11 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 {
                url = url.substring(0, url.indexOf("|"));
                x.code().tx(url);
                x.tx(": " + cr.present());
            }
        }
    }
}
Also used : CanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource) Resource(org.hl7.fhir.r4b.model.Resource) DomainResource(org.hl7.fhir.r4b.model.DomainResource) CanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource)

Example 12 with ResourceWrapper

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

the class ResourceRenderer method render.

public XhtmlNode render(ResourceWrapper r) throws IOException, FHIRException, EOperationOutcome {
    assert r.getContext() == context;
    XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
    boolean hasExtensions = render(x, r);
    if (r.hasNarrative()) {
        r.injectNarrative(x, hasExtensions ? NarrativeStatus.EXTENSIONS : NarrativeStatus.GENERATED);
    }
    return x;
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 13 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.r4b.renderers.utils.Resolver.ResourceWithReference) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 14 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, BaseWrapper r) throws UnsupportedEncodingException, IOException {
    XhtmlNode c = x;
    ResourceWithReference tr = null;
    String v;
    if (r.has("reference")) {
        v = r.get("reference").primitiveValue();
        tr = resolveReference(rw, v);
        if (!v.startsWith("#")) {
            if (tr != null && tr.getReference() != null)
                c = x.ah(tr.getReference());
            else
                c = x.ah(v);
        }
    } else {
        v = "";
    }
    // what to display: if text is provided, then that. if the reference was resolved, then show the generated narrative
    if (r.has("display")) {
        c.addText(r.get("display").primitiveValue());
        if (tr != null && tr.getResource() != null) {
            c.tx(". Generated Summary: ");
            new ProfileDrivenRenderer(context).generateResourceSummary(c, tr.getResource(), true, v.startsWith("#"), false);
        }
    } else if (tr != null && tr.getResource() != null) {
        new ProfileDrivenRenderer(context).generateResourceSummary(c, tr.getResource(), v.startsWith("#"), v.startsWith("#"), false);
    } else {
        c.addText(v);
    }
}
Also used : ResourceWithReference(org.hl7.fhir.r4b.renderers.utils.Resolver.ResourceWithReference) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 15 with ResourceWrapper

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