use of org.hl7.fhir.utilities.xhtml.XhtmlParser 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;
}
use of org.hl7.fhir.utilities.xhtml.XhtmlParser 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;
}
use of org.hl7.fhir.utilities.xhtml.XhtmlParser in project org.hl7.fhir.core by hapifhir.
the class CompartmentDefinitionRenderer method render.
public boolean render(XhtmlNode x, CompartmentDefinition cpd) throws FHIRFormatError, DefinitionException, IOException {
StringBuilder in = new StringBuilder();
StringBuilder out = new StringBuilder();
for (CompartmentDefinitionResourceComponent cc : cpd.getResource()) {
CommaSeparatedStringBuilder rules = new CommaSeparatedStringBuilder();
if (!cc.hasParam()) {
out.append(" <li><a href=\"").append(cc.getCode().toLowerCase()).append(".html\">").append(cc.getCode()).append("</a></li>\r\n");
} else if (!rules.equals("{def}")) {
for (StringType p : cc.getParam()) rules.append(p.asStringValue());
in.append(" <tr><td><a href=\"").append(cc.getCode().toLowerCase()).append(".html\">").append(cc.getCode()).append("</a></td><td>").append(rules.toString()).append("</td></tr>\r\n");
}
}
XhtmlNode xn;
xn = new XhtmlParser().parseFragment("<div><p>\r\nThe following resources may be in this compartment:\r\n</p>\r\n" + "<table class=\"grid\">\r\n" + " <tr><td><b>Resource</b></td><td><b>Inclusion Criteria</b></td></tr>\r\n" + in.toString() + "</table>\r\n" + "<p>\r\nA resource is in this compartment if the nominated search parameter (or chain) refers to the patient resource that defines the compartment.\r\n</p>\r\n" + "<p>\r\n\r\n</p>\r\n" + "<p>\r\nThe following resources are never in this compartment:\r\n</p>\r\n" + "<ul>\r\n" + out.toString() + "</ul></div>\r\n");
x.getChildNodes().addAll(xn.getChildNodes());
return true;
}
use of org.hl7.fhir.utilities.xhtml.XhtmlParser in project org.hl7.fhir.core by hapifhir.
the class DataRenderer method addMarkdown.
// -- 2. Markdown support -------------------------------------------------------
protected void addMarkdown(XhtmlNode x, String text) throws FHIRFormatError, IOException, DefinitionException {
if (text != null) {
// 1. custom FHIR extensions
while (text.contains("[[[")) {
String left = text.substring(0, text.indexOf("[[["));
String link = text.substring(text.indexOf("[[[") + 3, text.indexOf("]]]"));
String right = text.substring(text.indexOf("]]]") + 3);
String url = link;
String[] parts = link.split("\\#");
StructureDefinition p = getContext().getWorker().fetchResource(StructureDefinition.class, parts[0]);
if (p == null)
p = getContext().getWorker().fetchTypeDefinition(parts[0]);
if (p == null)
p = getContext().getWorker().fetchResource(StructureDefinition.class, link);
if (p != null) {
url = p.getUserString("path");
if (url == null)
url = p.getUserString("filename");
} else
throw new DefinitionException("Unable to resolve markdown link " + link);
text = left + "[" + link + "](" + url + ")" + right;
}
// 2. markdown
String s = getContext().getMarkdown().process(Utilities.escapeXml(text), "narrative generator");
XhtmlParser p = new XhtmlParser();
XhtmlNode m;
try {
m = p.parse("<div>" + s + "</div>", "div");
} catch (org.hl7.fhir.exceptions.FHIRFormatError e) {
throw new FHIRFormatError(e.getMessage(), e);
}
x.getChildNodes().addAll(m.getChildNodes());
}
}
use of org.hl7.fhir.utilities.xhtml.XhtmlParser 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;
}
Aggregations