Search in sources :

Example 21 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(true, false).composePlainText(oo.getText().getDiv())));
                } else {
                    ValueSet vs = (ValueSet) r;
                    expansions.put(vs.getUrl(), new ValueSetExpansionOutcome(vs, null));
                }
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
    }
}
Also used : OperationOutcome(org.hl7.fhir.dstu2016may.model.OperationOutcome) Resource(org.hl7.fhir.dstu2016may.model.Resource) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ValueSetExpansionOutcome(org.hl7.fhir.dstu2016may.terminologies.ValueSetExpander.ValueSetExpansionOutcome) File(java.io.File) ValueSet(org.hl7.fhir.dstu2016may.model.ValueSet) FileInputStream(java.io.FileInputStream)

Example 22 with XhtmlComposer

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

the class JsonParserBase method composeXhtml.

protected void composeXhtml(String name, XhtmlNode html) throws IOException {
    if (!Utilities.noString(xhtmlMessage)) {
        prop(name, "<div>!-- " + xhtmlMessage + " --></div>");
    } else {
        XhtmlComposer comp = new XhtmlComposer(true, htmlPretty);
        prop(name, comp.compose(html));
    }
}
Also used : XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer)

Example 23 with XhtmlComposer

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

the class JsonParserBase method composeXhtml.

protected void composeXhtml(String name, XhtmlNode html) throws IOException {
    if (!Utilities.noString(xhtmlMessage)) {
        prop(name, "<div>!-- " + xhtmlMessage + " --></div>");
    } else {
        XhtmlComposer comp = new XhtmlComposer(true, htmlPretty);
        prop(name, comp.compose(html));
    }
}
Also used : XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer)

Example 24 with XhtmlComposer

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

the class XmlParserBase method composeXhtml.

protected void composeXhtml(String name, XhtmlNode html) throws IOException {
    if (!Utilities.noString(xhtmlMessage)) {
        xml.enter(XhtmlComposer.XHTML_NS, name);
        xml.comment(xhtmlMessage, false);
        xml.exit(XhtmlComposer.XHTML_NS, name);
    } else {
        XhtmlComposer comp = new XhtmlComposer(true, htmlPretty);
        // name is also found in the html and should the same
        // ? check that
        boolean oldPretty = xml.isPretty();
        xml.setPretty(htmlPretty);
        if (html.getNodeType() != NodeType.Text && html.getNsDecl() == null)
            xml.namespace(XhtmlComposer.XHTML_NS, null);
        comp.compose(xml, html);
        xml.setPretty(oldPretty);
    }
}
Also used : XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer)

Example 25 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, pretty).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)

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