use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class ResourceRoundTripTests method test.
@Test
public void test() throws IOException, FHIRException, EOperationOutcome {
DomainResource res = (DomainResource) new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "unicode.xml"));
RenderingContext rc = new RenderingContext(TestingUtilities.context(), null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.END_USER);
RendererFactory.factory(res, rc).render(res);
IOUtils.copy(TestingUtilities.loadTestResourceStream("r5", "unicode.xml"), new FileOutputStream(TestingUtilities.tempFile("gen", "unicode.xml")));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilities.tempFile("gen", "unicode.out.xml")), res);
}
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, Resource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
XhtmlNode n = render((Bundle) r);
x.addChildren(n.getChildNodes());
return false;
}
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.
public XhtmlNode render(Bundle b) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
if (b.getType() == BundleType.DOCUMENT) {
if (!b.hasEntry() || !(b.getEntryFirstRep().hasResource() && b.getEntryFirstRep().getResource() instanceof Composition)) {
throw new FHIRException("Invalid document - first entry is not a Composition");
}
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
renderDocument(x, b);
return x;
} else if ((b.getType() == BundleType.COLLECTION && allEntresAreHistoryProvenance(b))) {
return null;
} else {
XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ROOT, b.getId(), b.getType().toCode()));
int i = 0;
for (BundleEntryComponent be : b.getEntry()) {
i++;
if (be.hasFullUrl())
root.an(makeInternalBundleLink(be.getFullUrl()));
if (be.hasResource() && be.getResource().hasId())
root.an(be.getResource().getResourceType().name() + "_" + be.getResource().getId());
root.hr();
if (be.hasFullUrl()) {
root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ENTRY_URL, Integer.toString(i), be.getFullUrl()));
} else {
root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ENTRY, Integer.toString(i)));
}
if (be.hasRequest())
renderRequest(root, be.getRequest());
if (be.hasSearch())
renderSearch(root, be.getSearch());
if (be.hasResponse())
renderResponse(root, be.getResponse());
if (be.hasResource()) {
root.para().addText(formatMessage(RENDER_BUNDLE_RESOURCE, be.getResource().fhirType()));
if (be.hasResource()) {
XhtmlNode xn = null;
if (be.getResource() instanceof DomainResource) {
DomainResource dr = (DomainResource) be.getResource();
xn = dr.getText().getDiv();
}
if (xn == null || xn.isEmpty()) {
ResourceRenderer rr = RendererFactory.factory(be.getResource(), context);
try {
xn = rr.build(be.getResource());
} catch (Exception e) {
xn = makeExceptionXhtml(e, "generating narrative");
}
}
root.blockquote().para().getChildNodes().addAll(checkInternalLinks(b, xn.getChildNodes()));
}
}
}
return root;
}
}
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().para().addChildren(xn);
}
}
}
return false;
}
Aggregations