Search in sources :

Example 41 with Narrative

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

the class CCDAConverter method addReference.

protected String addReference(DomainResource r, String title, String id) throws Exception {
    if (r.getText() == null)
        r.setText(new Narrative());
    if (r.getText().getDiv() == null) {
        r.getText().setStatus(NarrativeStatus.GENERATED);
        new NarrativeGenerator("", "", context).generate(r);
    }
    r.setMeta(new Meta().setLastUpdatedElement(InstantType.now()));
    r.setId(id);
    feed.getEntry().add(new BundleEntryComponent().setResource(r));
    return id;
}
Also used : NarrativeGenerator(org.hl7.fhir.dstu3.utils.NarrativeGenerator) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)

Example 42 with Narrative

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

the class NarrativeGenerator method generateDocumentNarrative.

public XhtmlNode generateDocumentNarrative(Bundle feed) {
    /*
     When the document is presented for human consumption, applications must present the collated narrative portions of the following resources in order:
     * The Composition resource
     * The Subject resource
     * Resources referenced in the section.content
     */
    XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
    Composition comp = (Composition) feed.getEntry().get(0).getResource();
    root.getChildNodes().add(comp.getText().getDiv());
    Resource subject = ResourceUtilities.getById(feed, null, comp.getSubject().getReference());
    if (subject != null && subject instanceof DomainResource) {
        root.addTag("hr");
        root.getChildNodes().add(((DomainResource) subject).getText().getDiv());
    }
    List<SectionComponent> sections = comp.getSection();
    renderSections(feed, root, sections, 1);
    return root;
}
Also used : Composition(org.hl7.fhir.dstu2.model.Composition) DomainResource(org.hl7.fhir.dstu2.model.DomainResource) Resource(org.hl7.fhir.dstu2.model.Resource) DomainResource(org.hl7.fhir.dstu2.model.DomainResource) SectionComponent(org.hl7.fhir.dstu2.model.Composition.SectionComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 43 with Narrative

use of org.hl7.fhir.r4b.model.Narrative 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) 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)
        x.addText("Extensions: Todo");
    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.dstu2.model.DateType)
        x.addText(((org.hl7.fhir.dstu2.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.dstu2.model.IntegerType) {
        x.addText(Integer.toString(((org.hl7.fhir.dstu2.model.IntegerType) e).getValue()));
    } else if (e instanceof org.hl7.fhir.dstu2.model.DecimalType) {
        x.addText(((org.hl7.fhir.dstu2.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.addText("/");
        renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
    } else if (e instanceof Period) {
        Period p = (Period) e;
        x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
        x.addText(" --> ");
        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.addTag("a").attribute("href", tr.getReference());
                else
                    c = x.addTag("a").attribute("href", 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) {
                c.addText(". Generated Summary: ");
                generateResourceSummary(c, tr.getResource(), true, r.getReference().startsWith("#"));
            }
        } else if (tr != 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.addText("todo-bundle");
    } else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta))
        throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet");
}
Also used : Meta(org.hl7.fhir.dstu2.model.Meta) Base64(org.apache.commons.codec.binary.Base64) Address(org.hl7.fhir.dstu2.model.Address) StringType(org.hl7.fhir.dstu2.model.StringType) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Attachment(org.hl7.fhir.dstu2.model.Attachment) UriType(org.hl7.fhir.dstu2.model.UriType) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) HumanName(org.hl7.fhir.dstu2.model.HumanName) ContactPoint(org.hl7.fhir.dstu2.model.ContactPoint) Identifier(org.hl7.fhir.dstu2.model.Identifier) Coding(org.hl7.fhir.dstu2.model.Coding) Narrative(org.hl7.fhir.dstu2.model.Narrative) SampledData(org.hl7.fhir.dstu2.model.SampledData) Ratio(org.hl7.fhir.dstu2.model.Ratio) ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition) InstantType(org.hl7.fhir.dstu2.model.InstantType) Enumeration(org.hl7.fhir.dstu2.model.Enumeration) Reference(org.hl7.fhir.dstu2.model.Reference) BooleanType(org.hl7.fhir.dstu2.model.BooleanType) Resource(org.hl7.fhir.dstu2.model.Resource) DomainResource(org.hl7.fhir.dstu2.model.DomainResource) Quantity(org.hl7.fhir.dstu2.model.Quantity) Period(org.hl7.fhir.dstu2.model.Period) Range(org.hl7.fhir.dstu2.model.Range) Base(org.hl7.fhir.dstu2.model.Base) Annotation(org.hl7.fhir.dstu2.model.Annotation) IdType(org.hl7.fhir.dstu2.model.IdType) Extension(org.hl7.fhir.dstu2.model.Extension) DateTimeType(org.hl7.fhir.dstu2.model.DateTimeType) CodeType(org.hl7.fhir.dstu2.model.CodeType) EventTiming(org.hl7.fhir.dstu2.model.Timing.EventTiming) Timing(org.hl7.fhir.dstu2.model.Timing) Base64BinaryType(org.hl7.fhir.dstu2.model.Base64BinaryType) CodeableConcept(org.hl7.fhir.dstu2.model.CodeableConcept)

Example 44 with Narrative

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

the class Narrative method copy.

public Narrative copy() {
    Narrative dst = new Narrative();
    copyValues(dst);
    dst.status = status == null ? null : status.copy();
    dst.div = div == null ? null : div.copy();
    return dst;
}
Also used : INarrative(org.hl7.fhir.instance.model.api.INarrative)

Example 45 with Narrative

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

the class RdfParser method composeNarrative.

protected void composeNarrative(Complex parent, String parentType, String name, Narrative element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeElement(t, "Narrative", name, element, index);
    if (element.hasStatusElement())
        composeEnum(t, "Narrative", "status", element.getStatusElement(), -1);
    if (element.hasDiv())
        composeXhtml(t, "Narrative", "div", element.getDiv(), -1);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

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