Search in sources :

Example 6 with ResourceWithReference

use of org.hl7.fhir.r4b.renderers.utils.Resolver.ResourceWithReference in project org.hl7.fhir.core by hapifhir.

the class ListRenderer method shortForRef.

private XhtmlNode shortForRef(XhtmlNode x, Base ref) throws UnsupportedEncodingException, IOException {
    if (ref == null) {
        x.tx("(null)");
    } else {
        String disp = ref.getChildByName("display") != null && ref.getChildByName("display").hasValues() ? ref.getChildByName("display").getValues().get(0).primitiveValue() : null;
        if (ref.getChildByName("reference").hasValues()) {
            String url = ref.getChildByName("reference").getValues().get(0).primitiveValue();
            ResourceWithReference r = context.getResolver().resolve(context, url);
            if (r == null) {
                if (disp == null) {
                    disp = url;
                }
                x.tx(disp);
            } else if (r.getResource() != null) {
                RendererFactory.factory(r.getResource().getName(), context).renderReference(r.getResource(), x, (Reference) ref);
            } else {
                RendererFactory.factory(url, context).renderReference(r.getResource(), x, (Reference) ref);
            }
        } else if (disp != null) {
            x.tx(disp);
        } else {
            x.tx("?ngen-16?");
        }
    }
    return x;
}
Also used : ResourceWithReference(org.hl7.fhir.r4b.renderers.utils.Resolver.ResourceWithReference) Reference(org.hl7.fhir.r4b.model.Reference) ResourceWithReference(org.hl7.fhir.r4b.renderers.utils.Resolver.ResourceWithReference)

Example 7 with ResourceWithReference

use of org.hl7.fhir.r4b.renderers.utils.Resolver.ResourceWithReference in project org.hl7.fhir.core by hapifhir.

the class ListRenderer method shortForRef.

private XhtmlNode shortForRef(XhtmlNode x, Base ref) throws UnsupportedEncodingException, IOException {
    if (ref == null) {
        x.tx("(null)");
    } else {
        String disp = ref.getChildByName("display") != null && ref.getChildByName("display").hasValues() ? ref.getChildByName("display").getValues().get(0).primitiveValue() : null;
        if (ref.getChildByName("reference").hasValues()) {
            String url = ref.getChildByName("reference").getValues().get(0).primitiveValue();
            ResourceWithReference r = context.getResolver().resolve(context, url);
            if (r == null) {
                if (disp == null) {
                    disp = url;
                }
                x.tx(disp);
            } else if (r.getResource() != null) {
                RendererFactory.factory(r.getResource().getName(), context).renderReference(r.getResource(), x, (Reference) ref);
            } else {
                RendererFactory.factory(url, context).renderReference(r.getResource(), x, (Reference) ref);
            }
        } else if (disp != null) {
            x.tx(disp);
        } else {
            x.tx("?ngen-16?");
        }
    }
    return x;
}
Also used : Reference(org.hl7.fhir.r5.model.Reference) ResourceWithReference(org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference) ResourceWithReference(org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference)

Example 8 with ResourceWithReference

use of org.hl7.fhir.r4b.renderers.utils.Resolver.ResourceWithReference in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method renderLeaf.

private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints, String path) throws FHIRException, UnsupportedEncodingException, IOException {
    if (ew == null)
        return;
    Base e = ew.getBase();
    if (e instanceof StringType)
        x.addText(((StringType) e).getValue());
    else if (e instanceof CodeType)
        x.addText(((CodeType) e).getValue());
    else if (e instanceof IdType)
        x.addText(((IdType) e).getValue());
    else if (e instanceof Extension)
        return;
    else if (e instanceof InstantType)
        x.addText(((InstantType) e).toHumanDisplay());
    else if (e instanceof DateTimeType)
        x.addText(((DateTimeType) e).toHumanDisplay());
    else if (e instanceof Base64BinaryType)
        x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
    else if (e instanceof org.hl7.fhir.dstu3.model.DateType)
        x.addText(((org.hl7.fhir.dstu3.model.DateType) e).toHumanDisplay());
    else if (e instanceof Enumeration) {
        Object ev = ((Enumeration<?>) e).getValue();
        // todo: look up a display name if there is one
        x.addText(ev == null ? "" : ev.toString());
    } else if (e instanceof BooleanType)
        x.addText(((BooleanType) e).getValue().toString());
    else if (e instanceof CodeableConcept) {
        renderCodeableConcept((CodeableConcept) e, x, showCodeDetails);
    } else if (e instanceof Coding) {
        renderCoding((Coding) e, x, showCodeDetails);
    } else if (e instanceof Annotation) {
        renderAnnotation((Annotation) e, x);
    } else if (e instanceof Identifier) {
        renderIdentifier((Identifier) e, x);
    } else if (e instanceof org.hl7.fhir.dstu3.model.IntegerType) {
        x.addText(Integer.toString(((org.hl7.fhir.dstu3.model.IntegerType) e).getValue()));
    } else if (e instanceof org.hl7.fhir.dstu3.model.DecimalType) {
        x.addText(((org.hl7.fhir.dstu3.model.DecimalType) e).getValue().toString());
    } else if (e instanceof HumanName) {
        renderHumanName((HumanName) e, x);
    } else if (e instanceof SampledData) {
        renderSampledData((SampledData) e, x);
    } else if (e instanceof Address) {
        renderAddress((Address) e, x);
    } else if (e instanceof ContactPoint) {
        renderContactPoint((ContactPoint) e, x);
    } else if (e instanceof UriType) {
        renderUri((UriType) e, x);
    } else if (e instanceof Timing) {
        renderTiming((Timing) e, x);
    } else if (e instanceof Range) {
        renderRange((Range) e, x);
    } else if (e instanceof Quantity) {
        renderQuantity((Quantity) e, x, showCodeDetails);
    } else if (e instanceof Ratio) {
        renderQuantity(((Ratio) e).getNumerator(), x, showCodeDetails);
        x.tx("/");
        renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
    } else if (e instanceof Period) {
        Period p = (Period) e;
        x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
        x.tx(" --> ");
        x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
    } else if (e instanceof Reference) {
        Reference r = (Reference) e;
        XhtmlNode c = x;
        ResourceWithReference tr = null;
        if (r.hasReferenceElement()) {
            tr = resolveReference(res, r.getReference());
            if (!r.getReference().startsWith("#")) {
                if (tr != null && tr.getReference() != null)
                    c = x.ah(tr.getReference());
                else
                    c = x.ah(r.getReference());
            }
        }
        // what to display: if text is provided, then that. if the reference was resolved, then show the generated narrative
        if (r.hasDisplayElement()) {
            c.addText(r.getDisplay());
            if (tr != null && tr.getResource() != null) {
                c.tx(". Generated Summary: ");
                generateResourceSummary(c, tr.getResource(), true, r.getReference().startsWith("#"));
            }
        } else if (tr != null && tr.getResource() != null) {
            generateResourceSummary(c, tr.getResource(), r.getReference().startsWith("#"), r.getReference().startsWith("#"));
        } else {
            c.addText(r.getReference());
        }
    } else if (e instanceof Resource) {
        return;
    } else if (e instanceof ElementDefinition) {
        x.tx("todo-bundle");
    } else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta)) {
        StructureDefinition sd = context.fetchTypeDefinition(e.fhirType());
        if (sd == null)
            throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet, and no structure found");
        else
            generateByProfile(res, sd, ew, sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep(), getChildrenForPath(sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep().getPath()), x, path, showCodeDetails);
    }
}
Also used : Meta(org.hl7.fhir.dstu3.model.Meta) Base64(org.apache.commons.codec.binary.Base64) Address(org.hl7.fhir.dstu3.model.Address) StringType(org.hl7.fhir.dstu3.model.StringType) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Attachment(org.hl7.fhir.dstu3.model.Attachment) UriType(org.hl7.fhir.dstu3.model.UriType) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) HumanName(org.hl7.fhir.dstu3.model.HumanName) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) Narrative(org.hl7.fhir.dstu3.model.Narrative) SampledData(org.hl7.fhir.dstu3.model.SampledData) Ratio(org.hl7.fhir.dstu3.model.Ratio) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) InstantType(org.hl7.fhir.dstu3.model.InstantType) Enumeration(org.hl7.fhir.dstu3.model.Enumeration) Reference(org.hl7.fhir.dstu3.model.Reference) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) DomainResource(org.hl7.fhir.dstu3.model.DomainResource) MetadataResource(org.hl7.fhir.dstu3.model.MetadataResource) Resource(org.hl7.fhir.dstu3.model.Resource) Quantity(org.hl7.fhir.dstu3.model.Quantity) Period(org.hl7.fhir.dstu3.model.Period) Range(org.hl7.fhir.dstu3.model.Range) Base(org.hl7.fhir.dstu3.model.Base) Annotation(org.hl7.fhir.dstu3.model.Annotation) IdType(org.hl7.fhir.dstu3.model.IdType) Extension(org.hl7.fhir.dstu3.model.Extension) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) CodeType(org.hl7.fhir.dstu3.model.CodeType) EventTiming(org.hl7.fhir.dstu3.model.Timing.EventTiming) Timing(org.hl7.fhir.dstu3.model.Timing) Base64BinaryType(org.hl7.fhir.dstu3.model.Base64BinaryType) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 9 with ResourceWithReference

use of org.hl7.fhir.r4b.renderers.utils.Resolver.ResourceWithReference in project org.hl7.fhir.core by hapifhir.

the class ResourceRenderer method fetchResource.

protected ResourceWrapper fetchResource(BaseWrapper subject) throws UnsupportedEncodingException, FHIRException, IOException {
    if (context.getResolver() == null)
        return null;
    PropertyWrapper ref = subject.getChildByName("reference");
    if (ref == null || !ref.hasValues()) {
        return null;
    }
    String url = ref.value().getBase().primitiveValue();
    ResourceWithReference rr = context.getResolver().resolve(context, url);
    return rr == null ? null : rr.getResource();
}
Also used : PropertyWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper) ResourceWithReference(org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference)

Example 10 with ResourceWithReference

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

Aggregations

NotImplementedException (org.apache.commons.lang3.NotImplementedException)9 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)8 ResourceWithReference (org.hl7.fhir.r4b.renderers.utils.Resolver.ResourceWithReference)6 ResourceWithReference (org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference)6 Base64 (org.apache.commons.codec.binary.Base64)4 Address (org.hl7.fhir.dstu2.model.Address)2 Annotation (org.hl7.fhir.dstu2.model.Annotation)2 Attachment (org.hl7.fhir.dstu2.model.Attachment)2 Base (org.hl7.fhir.dstu2.model.Base)2 BooleanType (org.hl7.fhir.dstu2.model.BooleanType)2 CodeType (org.hl7.fhir.dstu2.model.CodeType)2 CodeableConcept (org.hl7.fhir.dstu2.model.CodeableConcept)2 Coding (org.hl7.fhir.dstu2.model.Coding)2 ContactPoint (org.hl7.fhir.dstu2.model.ContactPoint)2 DateTimeType (org.hl7.fhir.dstu2.model.DateTimeType)2 DomainResource (org.hl7.fhir.dstu2.model.DomainResource)2 Enumeration (org.hl7.fhir.dstu2.model.Enumeration)2 Extension (org.hl7.fhir.dstu2.model.Extension)2 HumanName (org.hl7.fhir.dstu2.model.HumanName)2 IdType (org.hl7.fhir.dstu2.model.IdType)2