Search in sources :

Example 1 with NarrativeStatus

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

the class Factory method newNarrative.

public static Narrative newNarrative(NarrativeStatus status, String html) throws IOException, FHIRException {
    Narrative n = new Narrative();
    n.setStatus(status);
    try {
        n.setDiv(new XhtmlParser().parseFragment("<div>" + Utilities.escapeXml(html) + "</div>"));
    } catch (org.hl7.fhir.exceptions.FHIRException e) {
        throw new FHIRException(e.getMessage(), e);
    }
    return n;
}
Also used : XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) FHIRException(org.hl7.fhir.exceptions.FHIRException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 2 with NarrativeStatus

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

the class NarrativeGenerator method inject.

private void inject(DomainResource r, XhtmlNode x, NarrativeStatus status) {
    if (!r.hasText() || !r.getText().hasDiv() || r.getText().getDiv().getChildNodes().isEmpty()) {
        r.setText(new Narrative());
        r.getText().setDiv(x);
        r.getText().setStatus(status);
    } else {
        XhtmlNode n = r.getText().getDiv();
        n.addTag("hr");
        n.getChildNodes().addAll(x.getChildNodes());
    }
}
Also used : Narrative(org.hl7.fhir.dstu2016may.model.Narrative) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 3 with NarrativeStatus

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

the class NarrativeGenerator method inject.

private void inject(Element er, XhtmlNode x, NarrativeStatus status) {
    Element txt = XMLUtil.getNamedChild(er, "text");
    if (txt == null) {
        txt = er.getOwnerDocument().createElementNS(FormatUtilities.FHIR_NS, "text");
        Element n = XMLUtil.getFirstChild(er);
        while (n != null && (n.getNodeName().equals("id") || n.getNodeName().equals("meta") || n.getNodeName().equals("implicitRules") || n.getNodeName().equals("language"))) n = XMLUtil.getNextSibling(n);
        if (n == null)
            er.appendChild(txt);
        else
            er.insertBefore(txt, n);
    }
    Element st = XMLUtil.getNamedChild(txt, "status");
    if (st == null) {
        st = er.getOwnerDocument().createElementNS(FormatUtilities.FHIR_NS, "status");
        Element n = XMLUtil.getFirstChild(txt);
        if (n == null)
            txt.appendChild(st);
        else
            txt.insertBefore(st, n);
    }
    st.setAttribute("value", status.toCode());
    Element div = XMLUtil.getNamedChild(txt, "div");
    if (div == null) {
        div = er.getOwnerDocument().createElementNS(FormatUtilities.XHTML_NS, "div");
        div.setAttribute("xmlns", FormatUtilities.XHTML_NS);
        txt.appendChild(div);
    }
    if (div.hasChildNodes())
        div.appendChild(er.getOwnerDocument().createElementNS(FormatUtilities.XHTML_NS, "hr"));
    new XhtmlComposer(true, false).compose(div, x);
}
Also used : Element(org.w3c.dom.Element) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer)

Example 4 with NarrativeStatus

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

the class Factory method newNarrative.

public static Narrative newNarrative(NarrativeStatus status, String html) throws IOException, FHIRException {
    Narrative n = new Narrative();
    n.setStatus(status);
    try {
        n.setDiv(new XhtmlParser().parseFragment("<div>" + Utilities.escapeXml(html) + "</div>"));
    } catch (org.hl7.fhir.exceptions.FHIRException e) {
        throw new FHIRException(e.getMessage(), e);
    }
    return n;
}
Also used : XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) FHIRException(org.hl7.fhir.exceptions.FHIRException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 5 with NarrativeStatus

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

the class NarrativeGenerator method inject.

private void inject(org.hl7.fhir.dstu3.elementmodel.Element er, XhtmlNode x, NarrativeStatus status) throws DefinitionException, IOException {
    if (!x.hasAttribute("xmlns"))
        x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
    org.hl7.fhir.dstu3.elementmodel.Element txt = er.getNamedChild("text");
    if (txt == null) {
        txt = new org.hl7.fhir.dstu3.elementmodel.Element("text", er.getProperty().getChild(null, "text"));
        int i = 0;
        while (i < er.getChildren().size() && (er.getChildren().get(i).getName().equals("id") || er.getChildren().get(i).getName().equals("meta") || er.getChildren().get(i).getName().equals("implicitRules") || er.getChildren().get(i).getName().equals("language"))) i++;
        if (i >= er.getChildren().size())
            er.getChildren().add(txt);
        else
            er.getChildren().add(i, txt);
    }
    org.hl7.fhir.dstu3.elementmodel.Element st = txt.getNamedChild("status");
    if (st == null) {
        st = new org.hl7.fhir.dstu3.elementmodel.Element("status", txt.getProperty().getChild(null, "status"));
        txt.getChildren().add(0, st);
    }
    st.setValue(status.toCode());
    org.hl7.fhir.dstu3.elementmodel.Element div = txt.getNamedChild("div");
    if (div == null) {
        div = new org.hl7.fhir.dstu3.elementmodel.Element("div", txt.getProperty().getChild(null, "div"));
        txt.getChildren().add(div);
        div.setValue(new XhtmlComposer(XhtmlComposer.XML).compose(x));
    }
    div.setXhtml(x);
}
Also used : XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)8 FHIRException (org.hl7.fhir.exceptions.FHIRException)5 XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)5 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)5 Element (org.w3c.dom.Element)4 Narrative (org.hl7.fhir.dstu2.model.Narrative)1 Narrative (org.hl7.fhir.dstu2016may.model.Narrative)1 ContactPoint (org.hl7.fhir.dstu3.model.ContactPoint)1 Narrative (org.hl7.fhir.dstu3.model.Narrative)1 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)1 Narrative (org.hl7.fhir.r4b.model.Narrative)1 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)1 BaseWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper)1 PropertyWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper)1 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)1 Narrative (org.hl7.fhir.r5.model.Narrative)1 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)1 BaseWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper)1 PropertyWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper)1