Search in sources :

Example 86 with Narrative

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

the class NarrativeGenerator method generateByProfile.

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

Example 87 with Narrative

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

the class JsonParser method composeNarrativeProperties.

protected void composeNarrativeProperties(Narrative element) throws IOException {
    composeDataTypeProperties(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 88 with Narrative

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

the class XmlParserBase method compose.

/**
 * Compose a resource to a stream, possibly using pretty presentation for a human reader, and maybe a different choice in the xhtml narrative (used in the spec in one place, but should not be used in production)
 * @
 */
public void compose(OutputStream stream, Resource resource, boolean htmlPretty) throws IOException {
    XMLWriter writer = new XMLWriter(stream, "UTF-8");
    writer.setPretty(style == OutputStyle.PRETTY);
    writer.start();
    compose(writer, resource, htmlPretty);
    writer.end();
}
Also used : IXMLWriter(org.hl7.fhir.utilities.xml.IXMLWriter) XMLWriter(org.hl7.fhir.utilities.xml.XMLWriter)

Example 89 with Narrative

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

the class ProfileDrivenRenderer method generateByProfile.

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

Example 90 with Narrative

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

the class ProfileDrivenRenderer method render.

@Override
public boolean render(XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException {
    if (context.isAddGeneratedNarrativeHeader()) {
        x.para().b().tx("Generated Narrative");
    }
    if (context.isTechnicalMode()) {
        renderResourceHeader(r, x);
    }
    try {
        StructureDefinition sd = r.getDefinition();
        if (sd == null) {
            throw new FHIRException("Cannot find definition for " + r.fhirType());
        } else {
            ElementDefinition ed = sd.getSnapshot().getElement().get(0);
            containedIds.clear();
            hasExtensions = false;
            generateByProfile(r, sd, r.root(), sd.getSnapshot().getElement(), ed, context.getProfileUtilities().getChildList(sd, ed), x, r.fhirType(), context.isTechnicalMode(), 0);
        }
    } catch (Exception e) {
        System.out.println("Error Generating Narrative for " + r.fhirType() + "/" + r.getId() + ": " + e.getMessage());
        e.printStackTrace();
        x.para().b().style("color: maroon").tx("Exception generating Narrative: " + e.getMessage());
    }
    return hasExtensions;
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

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