Search in sources :

Example 51 with ResourceWrapper

use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.ResourceWrapper 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, int indent, ResourceContext rc) 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) {
        if (e.hasPrimitiveValue())
            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.r4.model.DateType)
        x.addText(((org.hl7.fhir.r4.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.r4.model.IntegerType) {
        x.addText(Integer.toString(((org.hl7.fhir.r4.model.IntegerType) e).getValue()));
    } else if (e instanceof org.hl7.fhir.r4.model.DecimalType) {
        x.addText(((org.hl7.fhir.r4.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, defn.getPath(), rc != null && rc.resourceResource != null ? rc.resourceResource.getId() : null);
    } 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(), rc);
            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("#"), rc);
            }
        } else if (tr != null && tr.getResource() != null) {
            generateResourceSummary(c, tr.getResource(), r.getReference().startsWith("#"), r.getReference().startsWith("#"), rc);
        } 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, indent + 1, rc);
    }
}
Also used : Base64(org.apache.commons.codec.binary.Base64) NotImplementedException(org.apache.commons.lang3.NotImplementedException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) org.hl7.fhir.r4.model(org.hl7.fhir.r4.model) Enumeration(org.hl7.fhir.r4.model.Enumeration) EventTiming(org.hl7.fhir.r4.model.Timing.EventTiming)

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

Example 53 with ResourceWrapper

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

Example 54 with ResourceWrapper

use of org.hl7.fhir.r4b.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.r5.utils.LiquidEngine.LiquidDocument) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) IOException(java.io.IOException) LiquidEngine(org.hl7.fhir.r5.utils.LiquidEngine) FHIRException(org.hl7.fhir.exceptions.FHIRException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 55 with ResourceWrapper

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

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