use of org.hl7.fhir.r4b.utils.LiquidEngine.LiquidDocument in project org.hl7.fhir.core by hapifhir.
the class LiquidEngineTests method test.
@ParameterizedTest(name = "{index}: file{0}")
@MethodSource("data")
public void test(JsonObject test) throws Exception {
this.test = test;
LiquidDocument doc = engine.parse(test.get("template").getAsString(), "test-script");
String output = engine.evaluate(doc, loadResource(), null);
Assertions.assertTrue(test.get("output").getAsString().equals(output));
}
use of org.hl7.fhir.r4b.utils.LiquidEngine.LiquidDocument 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;
}
use of org.hl7.fhir.r4b.utils.LiquidEngine.LiquidDocument in project org.hl7.fhir.core by hapifhir.
the class LiquidEngineTests method test.
@ParameterizedTest(name = "{index}: file{0}")
@MethodSource("data")
public void test(JsonObject test) throws Exception {
this.test = test;
LiquidDocument doc = engine.parse(test.get("template").getAsString(), "test-script");
String output = engine.evaluate(doc, loadResource(), null);
Assertions.assertEquals(test.get("output").getAsString(), output);
}
use of org.hl7.fhir.r4b.utils.LiquidEngine.LiquidDocument 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;
}
use of org.hl7.fhir.r4b.utils.LiquidEngine.LiquidDocument in project org.hl7.fhir.core by hapifhir.
the class LiquidEngineTests method test.
@ParameterizedTest(name = "{index}: file{0}")
@MethodSource("data")
public void test(JsonObject test) throws Exception {
this.test = test;
LiquidDocument doc = engine.parse(test.get("template").getAsString(), "test-script");
String output = engine.evaluate(doc, loadResource(), null);
Assertions.assertEquals(test.get("output").getAsString(), output);
}
Aggregations