use of org.hl7.fhir.r5.utils.EOperationOutcome 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.r5.utils.EOperationOutcome in project kindling by HL7.
the class PageProcessor method genExample.
private String genExample(Example example, int headerLevelContext, String genlevel) throws IOException, EOperationOutcome, FHIRException {
String xml = XMLUtil.elementToString(example.getXml().getDocumentElement());
Resource res = new XmlParser().parse(xml);
if (!(res instanceof DomainResource))
return "";
DomainResource dr = (DomainResource) res;
if (!dr.hasText() || !dr.getText().hasDiv()) {
RenderingContext lrc = rc.copy().setHeaderLevelContext(headerLevelContext);
RendererFactory.factory(dr, lrc).render(dr);
}
return new XhtmlComposer(XhtmlComposer.HTML).compose(dr.getText().getDiv());
}
use of org.hl7.fhir.r5.utils.EOperationOutcome in project kindling by HL7.
the class Publisher method buildConceptMap.
private ConceptMap buildConceptMap(String path, ValueSet vs, ResourceDefn rd) throws EOperationOutcome, FHIRException, IOException {
ConceptMap cm = new ConceptMap();
cm.setUserData("path", "sc-" + vs.getUserString("path"));
cm.setUserData("resource-definition", rd);
cm.setId("sc-" + vs.getId());
cm.setUrl("http://hl7.org/fhir/ConceptMap/" + cm.getId());
cm.setVersion(page.getVersion().toCode());
cm.setName(vs.getName() + "CanonicalMap");
cm.setTitle("Canonical Mapping for \"" + vs.present() + "\"");
cm.setStatus(PublicationStatus.DRAFT);
cm.setDate(vs.getDate());
cm.setPublisher(vs.getPublisher());
cm.addContact(vs.getContactFirstRep());
cm.setDescription("Canonical Mapping for \"" + vs.getDescription() + "\"");
cm.setSource(new CanonicalType(vs.getUrl()));
cm.setTarget(new CanonicalType("http://hl7.org/fhir/ValueSet/resource-status"));
List<String> canonical = page.getDefinitions().getStatusCodes().get("@code");
List<String> self = page.getDefinitions().getStatusCodes().get(path);
ConceptMapGroupComponent grp = cm.addGroup();
grp.setTarget("http://hl7.org/fhir/resource-status");
grp.setSource(vs.getCompose().getIncludeFirstRep().getSystem());
for (int i = 0; i < self.size(); i++) {
if (!Utilities.noString(self.get(i))) {
String cc = canonical.get(i);
String sc = self.get(i);
SourceElementComponent e = grp.addElement();
e.setCode(sc);
TargetElementComponent t = e.addTarget();
t.setCode(cc);
t.setRelationship(ConceptMapRelationship.EQUIVALENT);
}
}
if (!grp.hasElement())
return null;
page.getConceptMaps().see(cm, page.packageInfo());
statusCodeConceptMaps.add(cm);
return cm;
}
use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class BundleRenderer method renderDocument.
private boolean renderDocument(XhtmlNode x, ResourceWrapper b, List<BaseWrapper> entries) throws UnsupportedEncodingException, FHIRException, IOException, EOperationOutcome {
// from the spec:
//
// When the document is presented for human consumption, applications SHOULD present the collated narrative portions in order:
// * The subject resource Narrative
// * The Composition resource Narrative
// * The section.text Narratives
ResourceWrapper comp = (ResourceWrapper) entries.get(0).getChildByName("resource").getAsResource();
ResourceWrapper subject = resolveReference(entries, comp.get("subject"));
if (subject != null) {
if (subject.hasNarrative()) {
x.addChildren(subject.getNarrative());
} else {
RendererFactory.factory(subject, context).render(x, subject);
}
}
x.hr();
if (comp.hasNarrative()) {
x.addChildren(comp.getNarrative());
x.hr();
}
List<BaseWrapper> sections = comp.children("section");
for (BaseWrapper section : sections) {
addSection(x, section, 2, false);
}
return false;
}
use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class BundleRenderer method render.
@Override
public boolean render(XhtmlNode x, ResourceWrapper b) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
List<BaseWrapper> entries = b.children("entry");
if ("document".equals(b.get("type").primitiveValue())) {
if (entries.isEmpty() || (entries.get(0).has("resource") && !"Composition".equals(entries.get(0).get("resource").fhirType())))
throw new FHIRException("Invalid document '" + b.getId() + "' - first entry is not a Composition ('" + entries.get(0).get("resource").fhirType() + "')");
return renderDocument(x, b, entries);
} else if ("collection".equals(b.get("type").primitiveValue()) && allEntriesAreHistoryProvenance(entries)) {
// nothing
} else {
XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ROOT, b.getId(), b.get("type").primitiveValue()));
int i = 0;
for (BaseWrapper be : entries) {
i++;
if (be.has("fullUrl")) {
root.an(makeInternalBundleLink(be.get("fullUrl").primitiveValue()));
}
if (be.has("resource") && be.getChildByName("resource").getValues().get(0).has("id")) {
root.an(be.get("resource").fhirType() + "_" + be.getChildByName("resource").getValues().get(0).get("id").primitiveValue());
}
root.hr();
if (be.has("fullUrl")) {
root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ENTRY_URL, Integer.toString(i), be.get("fullUrl").primitiveValue()));
} else {
root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ENTRY, Integer.toString(i)));
}
// renderResponse(root, be.getResponse());
if (be.has("resource")) {
root.para().addText(formatMessage(RENDER_BUNDLE_RESOURCE, be.get("resource").fhirType()));
ResourceWrapper rw = be.getChildByName("resource").getAsResource();
XhtmlNode xn = rw.getNarrative();
if (xn == null || xn.isEmpty()) {
ResourceRenderer rr = RendererFactory.factory(rw, context);
try {
xn = rr.render(rw);
} catch (Exception e) {
xn = new XhtmlNode();
xn.para().b().tx("Exception generating narrative: " + e.getMessage());
}
}
root.blockquote().addChildren(xn);
}
}
}
return false;
}
Aggregations