Search in sources :

Example 61 with Narrative

use of org.hl7.fhir.r4b.model.Narrative in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generateByProfile.

private boolean generateByProfile(DomainResource r, StructureDefinition profile, boolean showCodeDetails) {
    XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
    x.para().b().tx("Generated Narrative" + (showCodeDetails ? " with Details" : ""));
    try {
        generateByProfile(r, profile, r, profile.getSnapshot().getElement(), profile.getSnapshot().getElement().get(0), getChildrenForPath(profile.getSnapshot().getElement(), r.getResourceType().toString()), x, r.getResourceType().toString(), showCodeDetails);
    } catch (Exception e) {
        e.printStackTrace();
        x.para().b().setAttribute("style", "color: maroon").tx("Exception generating Narrative: " + e.getMessage());
    }
    inject(r, x, NarrativeStatus.GENERATED);
    return true;
}
Also used : TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParseException(java.text.ParseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 62 with Narrative

use of org.hl7.fhir.r4b.model.Narrative in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generate.

/**
 * This generate is optimised for the FHIR build process itself in as much as it
 * generates hyperlinks in the narrative that are only going to be correct for
 * the purposes of the build. This is to be reviewed in the future.
 *
 * @param vs
 * @param codeSystems
 * @throws IOException
 * @throws DefinitionException
 * @throws FHIRFormatError
 * @throws Exception
 */
public boolean generate(ResourceContext rcontext, CodeSystem cs, boolean header) throws FHIRFormatError, DefinitionException, IOException {
    XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
    boolean hasExtensions = false;
    hasExtensions = generateDefinition(x, cs, header);
    inject(cs, x, hasExtensions ? NarrativeStatus.EXTENSIONS : NarrativeStatus.GENERATED);
    return true;
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 63 with Narrative

use of org.hl7.fhir.r4b.model.Narrative in project org.hl7.fhir.core by hapifhir.

the class JsonParser method composeNarrativeInner.

protected void composeNarrativeInner(Narrative element) throws IOException {
    composeElement(element);
    if (element.hasStatusElement()) {
        composeEnumerationCore("status", element.getStatusElement(), new Narrative.NarrativeStatusEnumFactory(), false);
        composeEnumerationExtras("status", element.getStatusElement(), new Narrative.NarrativeStatusEnumFactory(), false);
    }
    if (element.hasDiv()) {
        XhtmlNode node = element.getDiv();
        if (node.getNsDecl() == null) {
            node.attribute("xmlns", XHTML_NS);
        }
        composeXhtml("div", node);
    }
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 64 with Narrative

use of org.hl7.fhir.r4b.model.Narrative in project org.hl7.fhir.core by hapifhir.

the class BundleRenderer method render.

public XhtmlNode render(Bundle b) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
    if (b.getType() == BundleType.DOCUMENT) {
        if (!b.hasEntry() || !(b.getEntryFirstRep().hasResource() && b.getEntryFirstRep().getResource() instanceof Composition)) {
            throw new FHIRException("Invalid document - first entry is not a Composition");
        }
        XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
        renderDocument(x, b);
        return x;
    } else if ((b.getType() == BundleType.COLLECTION && allEntresAreHistoryProvenance(b))) {
        return null;
    } else {
        XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
        root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ROOT, b.getId(), b.getType().toCode()));
        int i = 0;
        for (BundleEntryComponent be : b.getEntry()) {
            i++;
            if (be.hasFullUrl())
                root.an(makeInternalBundleLink(be.getFullUrl()));
            if (be.hasResource() && be.getResource().hasId())
                root.an(be.getResource().getResourceType().name() + "_" + be.getResource().getId());
            root.hr();
            if (be.hasFullUrl()) {
                root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ENTRY_URL, Integer.toString(i), be.getFullUrl()));
            } else {
                root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ENTRY, Integer.toString(i)));
            }
            if (be.hasRequest())
                renderRequest(root, be.getRequest());
            if (be.hasSearch())
                renderSearch(root, be.getSearch());
            if (be.hasResponse())
                renderResponse(root, be.getResponse());
            if (be.hasResource()) {
                root.para().addText(formatMessage(RENDER_BUNDLE_RESOURCE, be.getResource().fhirType()));
                if (be.hasResource()) {
                    XhtmlNode xn = null;
                    if (be.getResource() instanceof DomainResource) {
                        DomainResource dr = (DomainResource) be.getResource();
                        xn = dr.getText().getDiv();
                    }
                    if (xn == null || xn.isEmpty()) {
                        ResourceRenderer rr = RendererFactory.factory(be.getResource(), context);
                        try {
                            xn = rr.build(be.getResource());
                        } catch (Exception e) {
                            xn = makeExceptionXhtml(e, "generating narrative");
                        }
                    }
                    root.blockquote().getChildNodes().addAll(checkInternalLinks(b, xn.getChildNodes()));
                }
            }
        }
        return root;
    }
}
Also used : Composition(org.hl7.fhir.r4b.model.Composition) BundleEntryComponent(org.hl7.fhir.r4b.model.Bundle.BundleEntryComponent) DomainResource(org.hl7.fhir.r4b.model.DomainResource) FHIRException(org.hl7.fhir.exceptions.FHIRException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 65 with Narrative

use of org.hl7.fhir.r4b.model.Narrative in project org.hl7.fhir.core by hapifhir.

the class BundleRenderer method addSection.

private void addSection(XhtmlNode x, BaseWrapper section, int level, boolean nested) throws UnsupportedEncodingException, FHIRException, IOException {
    if (section.has("title") || section.has("code") || section.has("text") || section.has("section")) {
        XhtmlNode div = x.div();
        if (section.has("title")) {
            div.h(level).tx(section.get("title").primitiveValue());
        } else if (section.has("code")) {
            renderBase(div.h(level), section.get("code"));
        }
        if (section.has("text")) {
            Base narrative = section.get("text");
            x.addChildren(narrative.getXhtml());
        }
        if (section.has("section")) {
            List<BaseWrapper> sections = section.children("section");
            for (BaseWrapper child : sections) {
                if (nested) {
                    addSection(x.blockquote(), child, level + 1, true);
                } else {
                    addSection(x, child, level + 1, true);
                }
            }
        }
    }
// children
}
Also used : BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) Base(org.hl7.fhir.r4b.model.Base) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)80 FHIRException (org.hl7.fhir.exceptions.FHIRException)40 IOException (java.io.IOException)34 NotImplementedException (org.apache.commons.lang3.NotImplementedException)30 UnsupportedEncodingException (java.io.UnsupportedEncodingException)27 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)23 Test (org.junit.Test)22 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)19 ArrayList (java.util.ArrayList)19 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)17 Narrative (org.hl7.fhir.r4.model.Narrative)15 Narrative (org.hl7.fhir.r5.model.Narrative)15 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)14 XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)14 GET (javax.ws.rs.GET)12 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)12 IBaseOperationOutcome (org.hl7.fhir.instance.model.api.IBaseOperationOutcome)12 FileNotFoundException (java.io.FileNotFoundException)10 LinkedHashMap (java.util.LinkedHashMap)10