Search in sources :

Example 1 with LiquidEngine

use of org.hl7.fhir.r4b.utils.LiquidEngine in project org.hl7.fhir.core by hapifhir.

the class LiquidEngineTests method setUp.

@BeforeEach
public void setUp() {
    engine = new LiquidEngine(TestingUtilities.context(), null);
    engine.setIncludeResolver(this);
}
Also used : LiquidEngine(org.hl7.fhir.r4.utils.LiquidEngine) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with LiquidEngine

use of org.hl7.fhir.r4b.utils.LiquidEngine in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generateByLiquid.

private boolean generateByLiquid(ResourceContext rcontext, DomainResource r, String liquidTemplate, Set<String> outputTracker) {
    LiquidEngine engine = new LiquidEngine(context, services);
    XhtmlNode x;
    try {
        LiquidDocument doc = engine.parse(liquidTemplate, "template");
        String html = engine.evaluate(doc, r, rcontext);
        x = new XhtmlParser().parseFragment(html);
        if (!x.getName().equals("div"))
            throw new FHIRException("Error in template: Root element is not 'div'");
    } catch (FHIRException | IOException e) {
        x = new XhtmlNode(NodeType.Element, "div");
        x.para().b().setAttribute("style", "color: maroon").tx("Exception generating Narrative: " + e.getMessage());
    }
    inject(r, x, NarrativeStatus.GENERATED);
    return true;
}
Also used : LiquidDocument(org.hl7.fhir.r4.utils.LiquidEngine.LiquidDocument) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 3 with LiquidEngine

use of org.hl7.fhir.r4b.utils.LiquidEngine in project org.hl7.fhir.core by hapifhir.

the class LiquidEngineTests method setUp.

@BeforeEach
public void setUp() throws Exception {
    engine = new LiquidEngine(TestingUtilities.context(), null);
    engine.setIncludeResolver(this);
}
Also used : LiquidEngine(org.hl7.fhir.r4b.utils.LiquidEngine) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with LiquidEngine

use of org.hl7.fhir.r4b.utils.LiquidEngine in project org.hl7.fhir.core by hapifhir.

the class LiquidRenderer method render.

@Override
public boolean render(XhtmlNode x, Resource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
    LiquidEngine engine = new LiquidEngine(context.getWorker(), context.getServices());
    XhtmlNode xn;
    try {
        engine.setIncludeResolver(new LiquidRendererIncludeResolver(context));
        LiquidDocument doc = engine.parse(liquidTemplate, "template");
        String html = engine.evaluate(doc, r, rcontext);
        xn = new XhtmlParser().parseFragment(html);
        if (!x.getName().equals("div"))
            throw new FHIRException("Error in template: Root element is not 'div'");
    } catch (FHIRException | IOException e) {
        xn = new XhtmlNode(NodeType.Element, "div");
        xn.para().b().style("color: maroon").tx("Exception generating Narrative: " + e.getMessage());
    }
    x.getChildNodes().addAll(xn.getChildNodes());
    return true;
}
Also used : LiquidDocument(org.hl7.fhir.r5.utils.LiquidEngine.LiquidDocument) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) IOException(java.io.IOException) LiquidEngine(org.hl7.fhir.r5.utils.LiquidEngine) FHIRException(org.hl7.fhir.exceptions.FHIRException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 5 with LiquidEngine

use of org.hl7.fhir.r4b.utils.LiquidEngine in project org.hl7.fhir.core by hapifhir.

the class ComparisonRenderer method processTemplate.

private String processTemplate(String template, String name, Map<String, Base> vars) {
    LiquidEngine engine = new LiquidEngine(contextRight, this);
    LiquidDocument doc = engine.parse(template, name + ".template");
    return engine.evaluate(doc, Tuple.fromMap(vars), vars);
}
Also used : LiquidDocument(org.hl7.fhir.r5.utils.LiquidEngine.LiquidDocument) LiquidEngine(org.hl7.fhir.r5.utils.LiquidEngine)

Aggregations

IOException (java.io.IOException)5 FHIRException (org.hl7.fhir.exceptions.FHIRException)5 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)5 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)5 LiquidEngine (org.hl7.fhir.r4b.utils.LiquidEngine)4 LiquidEngine (org.hl7.fhir.r5.utils.LiquidEngine)4 LiquidDocument (org.hl7.fhir.r4b.utils.LiquidEngine.LiquidDocument)3 LiquidDocument (org.hl7.fhir.r5.utils.LiquidEngine.LiquidDocument)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 LiquidEngine (org.hl7.fhir.r4.utils.LiquidEngine)1 LiquidDocument (org.hl7.fhir.r4.utils.LiquidEngine.LiquidDocument)1