Search in sources :

Example 26 with XhtmlComposer

use of org.hl7.fhir.utilities.xhtml.XhtmlComposer in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generateByProfile.

private String generateByProfile(Element er, StructureDefinition profile, boolean showCodeDetails) throws IOException {
    XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
    x.addTag("p").addTag("b").addText("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.addTag("p").addTag("b").setAttribute("style", "color: maroon").addText("Exception generating Narrative: " + e.getMessage());
    }
    inject(er, x, NarrativeStatus.GENERATED);
    return new XhtmlComposer(true, false).compose(x);
}
Also used : XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 27 with XhtmlComposer

use of org.hl7.fhir.utilities.xhtml.XhtmlComposer 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 28 with XhtmlComposer

use of org.hl7.fhir.utilities.xhtml.XhtmlComposer 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)

Example 29 with XhtmlComposer

use of org.hl7.fhir.utilities.xhtml.XhtmlComposer in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generate.

public String generate(ResourceContext rcontext, org.hl7.fhir.dstu3.elementmodel.Element er, boolean showCodeDetails) throws IOException, DefinitionException {
    if (rcontext == null)
        rcontext = new ResourceContext(null, er);
    XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
    x.para().b().tx("Generated Narrative" + (showCodeDetails ? " with Details" : ""));
    try {
        ResurceWrapperMetaElement resw = new ResurceWrapperMetaElement(er);
        BaseWrapperMetaElement base = new BaseWrapperMetaElement(er, null, er.getProperty().getStructure(), er.getProperty().getDefinition());
        base.children();
        generateByProfile(resw, er.getProperty().getStructure(), base, er.getProperty().getStructure().getSnapshot().getElement(), er.getProperty().getDefinition(), base.children, x, er.fhirType(), showCodeDetails);
    } catch (Exception e) {
        e.printStackTrace();
        x.para().b().setAttribute("style", "color: maroon").tx("Exception generating Narrative: " + e.getMessage());
    }
    inject(er, x, NarrativeStatus.GENERATED);
    return new XhtmlComposer(XhtmlComposer.XML).compose(x);
}
Also used : XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) 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 30 with XhtmlComposer

use of org.hl7.fhir.utilities.xhtml.XhtmlComposer in project org.hl7.fhir.core by hapifhir.

the class ValueSetExpansionCache method loadCache.

private void loadCache() throws FHIRFormatError, IOException {
    File[] files = new File(cacheFolder).listFiles();
    for (File f : files) {
        if (f.getName().endsWith(".xml")) {
            final FileInputStream is = new FileInputStream(f);
            try {
                Resource r = context.newXmlParser().setOutputStyle(OutputStyle.PRETTY).parse(is);
                if (r instanceof OperationOutcome) {
                    OperationOutcome oo = (OperationOutcome) r;
                    expansions.put(ToolingExtensions.getExtension(oo, VS_ID_EXT).getValue().toString(), new ValueSetExpansionOutcome(new XhtmlComposer(XhtmlComposer.XML, false).composePlainText(oo.getText().getDiv()), TerminologyServiceErrorClass.UNKNOWN));
                } else if (r instanceof ValueSet) {
                    ValueSet vs = (ValueSet) r;
                    if (vs.hasExpansion())
                        expansions.put(vs.getUrl(), new ValueSetExpansionOutcome(vs));
                    else {
                        canonicals.put(vs.getUrl(), vs);
                        if (vs.hasVersion())
                            canonicals.put(vs.getUrl() + "|" + vs.getVersion(), vs);
                    }
                } else if (r instanceof MetadataResource) {
                    MetadataResource md = (MetadataResource) r;
                    canonicals.put(md.getUrl(), md);
                    if (md.hasVersion())
                        canonicals.put(md.getUrl() + "|" + md.getVersion(), md);
                }
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
    }
}
Also used : MetadataResource(org.hl7.fhir.r4.model.MetadataResource) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) Resource(org.hl7.fhir.r4.model.Resource) MetadataResource(org.hl7.fhir.r4.model.MetadataResource) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ValueSetExpansionOutcome(org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome) File(java.io.File) ValueSet(org.hl7.fhir.r4.model.ValueSet) FileInputStream(java.io.FileInputStream)

Aggregations

XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)78 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)31 FHIRException (org.hl7.fhir.exceptions.FHIRException)15 IOException (java.io.IOException)14 FileOutputStream (java.io.FileOutputStream)13 NotImplementedException (org.apache.commons.lang3.NotImplementedException)11 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)11 File (java.io.File)10 FileNotFoundException (java.io.FileNotFoundException)10 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)10 RenderingContext (org.hl7.fhir.r5.renderers.utils.RenderingContext)10 FileInputStream (java.io.FileInputStream)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 HashMap (java.util.HashMap)7 TransformerException (javax.xml.transform.TransformerException)7 XmlParser (org.hl7.fhir.r5.formats.XmlParser)7 ValueSet (org.hl7.fhir.r5.model.ValueSet)7 CanonicalResource (org.hl7.fhir.r5.model.CanonicalResource)6 URISyntaxException (java.net.URISyntaxException)5 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)5