This commit is contained in:
Grahame Grieve 2024-06-15 23:45:56 +10:00
parent 2f5ef0b216
commit ef2531367e
22 changed files with 972 additions and 1498 deletions

View File

@ -4,33 +4,41 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.ActorDefinition;
import org.hl7.fhir.r5.model.CapabilityStatement;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.Library;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.UrlType;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class ActorDefinitionRenderer extends ResourceRenderer {
public ActorDefinitionRenderer(RenderingContext context) {
super(context);
}
public ActorDefinitionRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
public ActorDefinitionRenderer(RenderingContext context) {
super(context);
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
throw new Error("ActorDefinitionRenderer only renders native resources directly");
}
public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException {
return render(x, (ActorDefinition) dr);
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
render(status, x, (ActorDefinition) r);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
public boolean render(XhtmlNode x, ActorDefinition acd) throws FHIRFormatError, DefinitionException, IOException {
public void render(RenderingStatus status, XhtmlNode x, ActorDefinition acd) throws FHIRFormatError, DefinitionException, IOException {
XhtmlNode tbl = x.table("grid");
XhtmlNode tr = tbl.tr();
tr.td().b().tx(context.formatPhrase(RenderingContext.ACTOR_DEF_ACT, acd.getName()) + " ");
@ -44,7 +52,7 @@ public class ActorDefinitionRenderer extends ResourceRenderer {
boolean first = true;
for (UrlType t : acd.getReference()) {
if (first) first = false; else x.br();
render(td, t);
renderUri(status, td, wrap(t));
}
}
if (acd.hasCapabilities()) {
@ -54,7 +62,7 @@ public class ActorDefinitionRenderer extends ResourceRenderer {
if (cs != null) {
td.ah(cs.getWebPath()).tx(cs.present());
} else {
render(td, acd.getCapabilitiesElement());
renderCanonical(status, wrap(acd), td, wrap(acd.getCapabilitiesElement()));
}
}
if (acd.hasDerivedFrom()) {
@ -67,11 +75,10 @@ public class ActorDefinitionRenderer extends ResourceRenderer {
if (df != null) {
td.ah(df.getWebPath()).tx(df.present());
} else {
render(td, t);
renderUri(status, td, wrap(t));
}
}
}
return false;
}
public void describe(XhtmlNode x, Library lib) {
@ -81,18 +88,5 @@ public class ActorDefinitionRenderer extends ResourceRenderer {
public String display(Library lib) {
return lib.present();
}
@Override
public String display(Resource r) throws UnsupportedEncodingException, IOException {
return ((Library) r).present();
}
@Override
public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
if (r.has("title")) {
return r.children("title").get(0).getBase().primitiveValue();
}
return "??";
}
}

View File

@ -21,6 +21,7 @@ import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.UsageContext;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.renderers.CodeResolver.CodeResolution;
import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.utils.PublicationHacker;
import org.hl7.fhir.r5.utils.ToolingExtensions;
@ -290,7 +291,7 @@ public class AdditionalBindingsRenderer {
if (usage) {
if (binding.usage != null) {
// TODO: This isn't rendered at all yet. Ideally, we want it to render with comparison...
new DataRenderer(context).render(tr.td(), binding.usage);
new DataRenderer(context).renderBase(new RenderingStatus(), tr.td(), binding.usage);
} else {
tr.td();
}

View File

@ -9,6 +9,7 @@ import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.Bundle;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r5.model.Bundle.BundleEntryRequestComponent;
import org.hl7.fhir.r5.model.Bundle.BundleEntryResponseComponent;
@ -21,79 +22,61 @@ import org.hl7.fhir.r5.model.Property;
import org.hl7.fhir.r5.model.Provenance;
import org.hl7.fhir.r5.model.Reference;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.utilities.xhtml.NodeType;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class BundleRenderer extends ResourceRenderer {
public BundleRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
}
public BundleRenderer(RenderingContext context) {
super(context);
public BundleRenderer(RenderingContext context) {
super(context);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return "Bundle";
}
public BundleRenderer setMultiLangMode(boolean multiLangMode) {
this.multiLangMode = multiLangMode;
return this;
}
@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;
}
@Override
public String display(Resource r) throws UnsupportedEncodingException, IOException {
return null;
}
@Override
public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
return null;
}
@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(context.formatPhrase(RenderingContext.BUND_REND_INVALID_DOC, b.getId(), entries.get(0).get("resource").fhirType()+"')"));
return renderDocument(x, b, entries);
} else if ("collection".equals(b.get("type").primitiveValue()) && allEntriesAreHistoryProvenance(entries)) {
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement b) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
List<ResourceElement> entries = b.children("entry");
if ("document".equals(b.primitiveValue("type"))) {
if (entries.isEmpty() || (entries.get(0).has("resource") && !"Composition".equals(entries.get(0).child("resource").fhirType())))
throw new FHIRException(context.formatPhrase(RenderingContext.BUND_REND_INVALID_DOC, b.getId(), entries.get(0).child("resource").fhirType()+"')"));
renderDocument(status, x, b, entries);
} else if ("collection".equals(b.primitiveValue("type")) && allEntriesAreHistoryProvenance(entries)) {
// nothing
} else {
XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
root.para().addText(formatPhrase(RenderingContext.BUNDLE_HEADER_ROOT, b.getId(), b.get("type").primitiveValue()));
root.para().addText(formatPhrase(RenderingContext.BUNDLE_HEADER_ROOT, b.getId(), b.primitiveValue("type")));
int i = 0;
for (BaseWrapper be : entries) {
for (ResourceElement be : entries) {
i++;
if (be.has("fullUrl")) {
root.an(makeInternalBundleLink(be.get("fullUrl").primitiveValue()));
root.an(makeInternalBundleLink(be.primitiveValue("fullUrl")));
}
if (be.has("resource")) {
if (be.getChildByName("resource").getValues().get(0).has("id")) {
root.an(be.get("resource").fhirType() + "_" + be.getChildByName("resource").getValues().get(0).get("id").primitiveValue());
root.an("hc"+be.get("resource").fhirType() + "_" + be.getChildByName("resource").getValues().get(0).get("id").primitiveValue());
if (be.child("resource").has("id")) {
root.an(be.child("resource").fhirType() + "_" + be.child("resource").primitiveValue("id"));
root.an("hc"+be.child("resource").fhirType() + "_" + be.child("resource").primitiveValue("id"));
} else {
String id = makeIdFromBundleEntry(be.get("fullUrl").primitiveValue());
root.an(be.get("resource").fhirType() + "_" + id);
root.an("hc"+be.get("resource").fhirType() + "_" + id);
String id = makeIdFromBundleEntry(be.primitiveValue("fullUrl"));
root.an(be.child("resource").fhirType() + "_" + id);
root.an("hc"+be.child("resource").fhirType() + "_" + id);
}
}
root.hr();
if (be.has("fullUrl")) {
root.para().addText(formatPhrase(RenderingContext.BUNDLE_HEADER_ENTRY_URL, Integer.toString(i), be.get("fullUrl").primitiveValue()));
root.para().addText(formatPhrase(RenderingContext.BUNDLE_HEADER_ENTRY_URL, Integer.toString(i), be.primitiveValue("fullUrl")));
} else {
root.para().addText(formatPhrase(RenderingContext.BUNDLE_HEADER_ENTRY, Integer.toString(i)));
}
@ -104,14 +87,14 @@ public class BundleRenderer extends ResourceRenderer {
// if (be.hasResponse())
// renderResponse(root, be.getResponse());
if (be.has("resource")) {
root.para().addText(formatPhrase(RenderingContext.BUNDLE_RESOURCE, be.get("resource").fhirType()));
ResourceWrapper rw = be.getChildByName("resource").getAsResource();
XhtmlNode xn = rw.getNarrative();
ResourceElement r = be.child("resource");
root.para().addText(formatPhrase(RenderingContext.BUNDLE_RESOURCE, r.fhirType()));
XhtmlNode xn = r.getNarrative();
if (xn == null || xn.isEmpty()) {
ResourceRenderer rr = RendererFactory.factory(rw, context);
ResourceRenderer rr = RendererFactory.factory(r, context);
try {
rr.setRcontext(new ResourceContext(rcontext, rw));
xn = rr.render(rw);
xn = new XhtmlNode(NodeType.Element, "div");
rr.renderResource(new RenderingStatus(), xn, r);
} catch (Exception e) {
xn = new XhtmlNode();
xn.para().b().tx(context.formatPhrase(RenderingContext.BUNDLE_REV_EXCP, e.getMessage()) + " ");
@ -119,26 +102,35 @@ public class BundleRenderer extends ResourceRenderer {
}
root.blockquote().para().addChildren(xn);
}
if (be.has("search")) {
renderSearch(x, be.child("search"));
}
if (be.has("request")) {
renderRequest(x, be.child("request"));
}
if (be.has("response")) {
renderResponse(x, be.child("response"));
}
}
}
return false;
}
private boolean renderDocument(XhtmlNode x, ResourceWrapper b, List<BaseWrapper> entries) throws UnsupportedEncodingException, FHIRException, IOException, EOperationOutcome {
private void renderDocument(RenderingStatus status, XhtmlNode x, ResourceElement b, List<ResourceElement> 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"));
ResourceElement comp = (ResourceElement) entries.get(0).child("resource");
ResourceElement subject = resolveReference(entries, comp.child("subject"));
if (subject != null) {
if (subject.hasNarrative()) {
x.addChildren(subject.getNarrative());
} else {
RendererFactory.factory(subject, context, new ResourceContext(rcontext, subject)).render(x, subject);
RendererFactory.factory(subject, context).renderResource(status, x, subject);
}
}
x.hr();
@ -146,32 +138,31 @@ public class BundleRenderer extends ResourceRenderer {
x.addChildren(comp.getNarrative());
x.hr();
}
List<BaseWrapper> sections = comp.children("section");
for (BaseWrapper section : sections) {
addSection(x, section, 2, false);
List<ResourceElement> sections = comp.children("section");
for (ResourceElement section : sections) {
addSection(status, x, section, 2, false);
}
return false;
}
private void addSection(XhtmlNode x, BaseWrapper section, int level, boolean nested) throws UnsupportedEncodingException, FHIRException, IOException {
private void addSection(RenderingStatus status, XhtmlNode x, ResourceElement section, int level, boolean nested) throws UnsupportedEncodingException, FHIRException, IOException {
if (section.has("title") || section.has("code") || section.has("text") || section.has("section")) {
XhtmlNode div = x.div();
if (section.has("title")) {
div.h(level).tx(section.get("title").primitiveValue());
div.h(level).tx(section.primitiveValue("title"));
} else if (section.has("code")) {
renderBase(div.h(level), section.get("code"));
renderDataType(status, div.h(level), section.child("code"));
}
if (section.has("text")) {
Base narrative = section.get("text");
ResourceElement narrative = section.child("text");
x.addChildren(narrative.getXhtml());
}
if (section.has("section")) {
List<BaseWrapper> sections = section.children("section");
for (BaseWrapper child : sections) {
List<ResourceElement> sections = section.children("section");
for (ResourceElement child : sections) {
if (nested) {
addSection(x.blockquote().para(), child, level+1, true);
addSection(status, x.blockquote().para(), child, level+1, true);
} else {
addSection(x, child, level+1, true);
addSection(status, x, child, level+1, true);
}
}
}
@ -179,194 +170,27 @@ public class BundleRenderer extends ResourceRenderer {
// children
}
private ResourceWrapper resolveReference(List<BaseWrapper> entries, Base base) throws UnsupportedEncodingException, FHIRException, IOException {
private ResourceElement resolveReference(List<ResourceElement> entries, ResourceElement base) throws UnsupportedEncodingException, FHIRException, IOException {
if (base == null) {
return null;
}
Property prop = base.getChildByName("reference");
if (prop.hasValues()) {
String ref = prop.getValues().get(0).primitiveValue();
if (ref != null) {
for (BaseWrapper entry : entries) {
if (entry.has("fullUrl")) {
String fu = entry.get("fullUrl").primitiveValue();
if (ref.equals(fu)) {
return (ResourceWrapper) entry.getChildByName("resource").getAsResource();
}
ResourceElement prop = base.child("reference");
if (prop != null && prop.hasPrimitiveValue()) {
for (ResourceElement entry : entries) {
if (entry.has("fullUrl")) {
String fu = entry.primitiveValue("fullUrl");
if (prop.primitiveValue().equals(fu)) {
return entry.child("resource");
}
}
}
}
return null;
}
private boolean renderDocument(XhtmlNode x, Bundle b) 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
Composition comp = (Composition) b.getEntry().get(0).getResource();
Resource subject = resolveReference(b, comp.getSubjectFirstRep());
if (subject != null) {
XhtmlNode nx = (subject instanceof DomainResource) ? ((DomainResource) subject).getText().getDiv() : null;
if (nx != null && !nx.isEmpty()) {
x.addChildren(nx);
} else {
RendererFactory.factory(subject, context).setRcontext(new ResourceContext(rcontext, subject)).render(x, subject);
}
}
x.hr();
if (!comp.getText().hasDiv()) {
ResourceRenderer rr = RendererFactory.factory(comp, getContext());
rr.setRcontext(new ResourceContext(rcontext, comp));
rr.render(comp);
}
if (comp.getText().hasDiv()) {
x.addChildren(comp.getText().getDiv());
x.hr();
}
for (SectionComponent section : comp.getSection()) {
addSection(x, section, 2, false, comp);
}
return false;
}
private Resource resolveReference(Bundle bnd, Reference reference) {
String ref = reference.getReference();
if (ref == null) {
return null;
}
for (BundleEntryComponent be : bnd.getEntry()) {
if (ref.equals(be.getFullUrl())) {
return be.getResource();
}
}
return null;
}
private void addSection(XhtmlNode x, SectionComponent section, int level, boolean nested, Composition c) throws UnsupportedEncodingException, FHIRException, IOException {
if (section.hasTitle() || section.hasCode() || section.hasText() || section.hasSection()) {
XhtmlNode div = x.div();
if (section.hasTitle()) {
div.h(level).tx(section.getTitle());
} else if (section.hasCode()) {
renderBase(div.h(level), section.getCode());
}
if (section.hasText()) {
x.addChildren(section.getText().getDiv());
}
if (section.hasEntry()) {
XhtmlNode ul = x.ul();
for (Reference r : section.getEntry()) {
renderReference(c, ul.li(), r);
}
}
if (section.hasSection()) {
List<SectionComponent> sections = section.getSection();
for (SectionComponent child : sections) {
if (nested) {
addSection(x.blockquote().para(), child, level+1, true, c);
} else {
addSection(x, child, level+1, true, c);
}
}
}
}
// children
}
public XhtmlNode render(Bundle b) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
if ((b.getType() == BundleType.COLLECTION && allEntresAreHistoryProvenance(b))) {
return null;
} else {
int start = 0;
boolean docMode = false;
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
if (b.getType() == BundleType.DOCUMENT) {
if (!b.hasEntry() || !(b.getEntryFirstRep().hasResource() && b.getEntryFirstRep().getResource() instanceof Composition)) {
throw new FHIRException(context.formatPhrase(RenderingContext.BUNDLE_REV_INV_DOC));
}
renderDocument(x, b);
start = 1;
docMode = true;
x.hr();
x.h2().addText(formatPhrase(RenderingContext.BUNDLE_DOCUMENT_CONTENT, b.getId(), b.getType().toCode()));
} else {
x.para().addText(formatPhrase(RenderingContext.BUNDLE_HEADER_ROOT, b.getId(), b.getType().toCode()));
}
int i = 0;
for (BundleEntryComponent be : b.getEntry()) {
i++;
if (i > start) {
if (be.hasFullUrl())
x.an(makeInternalBundleLink(be.getFullUrl()));
if (be.hasResource()) {
if (be.getResource().hasId()) {
x.an(be.getResource().getResourceType().name() + "_" + be.getResource().getId());
x.an("hc"+be.getResource().getResourceType().name() + "_" + be.getResource().getId());
} else {
String id = makeIdFromBundleEntry(be.getFullUrl());
x.an(be.getResource().getResourceType().name() + "_" + id);
x.an("hc"+be.getResource().getResourceType().name() + "_" + id);
}
}
x.hr();
if (docMode) {
if (be.hasFullUrl() && be.hasResource()) {
x.para().addText(formatPhrase(RenderingContext.BUNDLE_HEADER_DOC_ENTRY_URD, Integer.toString(i), be.getFullUrl(), be.getResource().fhirType(), be.getResource().getIdBase()));
} else if (be.hasFullUrl()) {
x.para().addText(formatPhrase(RenderingContext.BUNDLE_HEADER_DOC_ENTRY_U, Integer.toString(i), be.getFullUrl()));
} else if (be.hasResource()) {
x.para().addText(formatPhrase(RenderingContext.BUNDLE_HEADER_DOC_ENTRY_RD, Integer.toString(i), be.getResource().fhirType(), be.getResource().getIdBase()));
}
} else {
if (be.hasFullUrl()) {
x.para().addText(formatPhrase(RenderingContext.BUNDLE_HEADER_ENTRY_URL, Integer.toString(i), be.getFullUrl()));
} else {
x.para().addText(formatPhrase(RenderingContext.BUNDLE_HEADER_ENTRY, Integer.toString(i)));
}
if (be.hasRequest())
renderRequest(x, be.getRequest());
if (be.hasSearch())
renderSearch(x, be.getSearch());
if (be.hasResponse())
renderResponse(x, be.getResponse());
}
if (be.hasResource()) {
if (!docMode) {
x.para().addText(formatPhrase(RenderingContext.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 {
rr.setRcontext(new ResourceContext(rcontext, be.getResource()));
xn = rr.build(be.getResource());
} catch (Exception e) {
xn = makeExceptionXhtml(e, context.formatPhrase(RenderingContext.BUND_REND_GEN_NARR));
}
}
x.blockquote().para().getChildNodes().addAll(checkInternalLinks(b, xn.getChildNodes()));
}
}
}
}
return x;
}
}
public static boolean allEntriesAreHistoryProvenance(List<BaseWrapper> entries) throws UnsupportedEncodingException, FHIRException, IOException {
for (BaseWrapper be : entries) {
if (!"Provenance".equals(be.get("resource").fhirType())) {
public static boolean allEntriesAreHistoryProvenance(List<ResourceElement> entries) throws UnsupportedEncodingException, FHIRException, IOException {
for (ResourceElement be : entries) {
if (!"Provenance".equals(be.child("resource").fhirType())) {
return false;
}
}
@ -409,52 +233,48 @@ public class BundleRenderer extends ResourceRenderer {
}
}
private void renderSearch(XhtmlNode root, BundleEntrySearchComponent search) {
private void renderSearch(XhtmlNode root, ResourceElement search) {
StringBuilder b = new StringBuilder();
b.append(formatPhrase(RenderingContext.BUNDLE_SEARCH));
if (search.hasMode())
b.append(formatPhrase(RenderingContext.BUNDLE_SEARCH_MODE, search.getMode().toCode()));
if (search.hasScore()) {
if (search.hasMode())
if (search.has("mode"))
b.append(formatPhrase(RenderingContext.BUNDLE_SEARCH_MODE, search.primitiveValue("mode")));
if (search.has("score")) {
if (search.has("mode")) {
b.append(",");
b.append(formatPhrase(RenderingContext.BUNDLE_SEARCH_SCORE, search.getScore()));
}
b.append(formatPhrase(RenderingContext.BUNDLE_SEARCH_SCORE, search.primitiveValue("score")));
}
root.para().addText(b.toString());
}
private void renderResponse(XhtmlNode root, BundleEntryResponseComponent response) {
private void renderResponse(XhtmlNode root, ResourceElement response) {
root.para().addText(formatPhrase(RenderingContext.BUNDLE_RESPONSE));
StringBuilder b = new StringBuilder();
b.append(response.getStatus()+"\r\n");
if (response.hasLocation())
b.append(formatPhrase(RenderingContext.BUNDLE_LOCATION, response.getLocation())+"\r\n");
if (response.hasEtag())
b.append(formatPhrase(RenderingContext.BUNDLE_ETAG, response.getEtag())+"\r\n");
if (response.hasLastModified())
b.append(formatPhrase(RenderingContext.BUNDLE_LAST_MOD, response.getEtag())+"\r\n");
b.append(response.primitiveValue("status")+"\r\n");
if (response.has("location"))
b.append(formatPhrase(RenderingContext.BUNDLE_LOCATION, response.primitiveValue("location"))+"\r\n");
if (response.has("etag"))
b.append(formatPhrase(RenderingContext.BUNDLE_ETAG, response.primitiveValue("etag"))+"\r\n");
if (response.has("lastModified"))
b.append(formatPhrase(RenderingContext.BUNDLE_LAST_MOD, response.primitiveValue("lastModified"))+"\r\n");
root.pre().addText(b.toString());
}
private void renderRequest(XhtmlNode root, BundleEntryRequestComponent request) {
private void renderRequest(XhtmlNode root, ResourceElement request) {
root.para().addText(formatPhrase(RenderingContext.BUNDLE_REQUEST));
StringBuilder b = new StringBuilder();
b.append(request.getMethod()+" "+request.getUrl()+"\r\n");
if (request.hasIfNoneMatch())
b.append(formatPhrase(RenderingContext.BUNDLE_IF_NON_MATCH, request.getIfNoneMatch())+"\r\n");
if (request.hasIfModifiedSince())
b.append(formatPhrase(RenderingContext.BUNDLE_IF_MOD, request.getIfModifiedSince())+"\r\n");
if (request.hasIfMatch())
b.append(formatPhrase(RenderingContext.BUNDLE_IF_MATCH, request.getIfMatch())+"\r\n");
if (request.hasIfNoneExist())
b.append(formatPhrase(RenderingContext.BUNDLE_IF_NONE, request.getIfNoneExist())+"\r\n");
b.append(request.primitiveValue("method")+" "+request.primitiveValue("url")+"\r\n");
if (request.has("ifNoneMatch"))
b.append(formatPhrase(RenderingContext.BUNDLE_IF_NON_MATCH, request.primitiveValue("ifNoneMatch"))+"\r\n");
if (request.has("ifModifiedSince"))
b.append(formatPhrase(RenderingContext.BUNDLE_IF_MOD, request.primitiveValue("ifModifiedSince"))+"\r\n");
if (request.has("ifMatch"))
b.append(formatPhrase(RenderingContext.BUNDLE_IF_MATCH, request.primitiveValue("ifMatch"))+"\r\n");
if (request.has("ifNoneExist"))
b.append(formatPhrase(RenderingContext.BUNDLE_IF_NONE, request.primitiveValue("ifNoneExist"))+"\r\n");
root.pre().addText(b.toString());
}
public String display(Bundle bundle) throws UnsupportedEncodingException, IOException {
return "??";
}
public boolean canRender(Bundle b) {
for (BundleEntryComponent be : b.getEntry()) {
if (be.hasResource()) {

View File

@ -308,7 +308,7 @@ public class CapabilityStatementRenderer extends ResourceRenderer {
uList.li().addText(context.formatPhrase(RenderingContext.CAPABILITY_FHIR_VER, currentVersion.toCode()) + " ");
addSupportedFormats(uList, conf);
uList.li().addText(context.formatPhrase(RenderingContext.CAPABILITY_PUB_ON, displayDateTime(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), conf.getDateElement())) + " "));
uList.li().addText(context.formatPhrase(RenderingContext.CAPABILITY_PUB_ON, displayDateTime(wrap(conf.getDateElement())) + " "));
uList.li().addText(context.formatPhrase(RenderingContext.CAPABILITY_PUB_BY, conf.getPublisherElement().asStringValue()) + " ");

View File

@ -418,13 +418,13 @@ public class ConceptMapRenderer extends TerminologyRenderer {
pp.b().tx(context.formatPhrase(RenderingContext.CONC_MAP_GRP, gc) + " ");
pp.tx(context.formatPhrase(RenderingContext.CONC_MAP_FROM) + " ");
if (grp.hasSource()) {
renderCanonical(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), cm), pp, grp.getSource());
renderCanonical(wrap(cm), pp, grp.getSource());
} else {
pp.code(context.formatPhrase(RenderingContext.CONC_MAP_CODE_SYS_UNSPEC));
}
pp.tx(" to ");
if (grp.hasTarget()) {
renderCanonical(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), cm), pp, grp.getTarget());
renderCanonical(wrap(cm), pp, grp.getTarget());
} else {
pp.code(context.formatPhrase(RenderingContext.CONC_MAP_CODE_SYS_UNSPEC));
}

View File

@ -604,7 +604,7 @@ public class DataRenderer extends Renderer implements CodeResolver {
}
public String displayDataType(DataType type) {
return displayDataType(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), type));
return displayDataType(wrap(type));
}
public String displayDataType(ResourceElement type) {
@ -769,7 +769,7 @@ public class DataRenderer extends Renderer implements CodeResolver {
public void renderBase(RenderingStatus status, XhtmlNode x, Base b) throws FHIRFormatError, DefinitionException, IOException {
if (b instanceof DataType) {
renderDataType(status, x, new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), (DataType) b));
renderDataType(status, x, wrap((DataType) b));
} else {
x.tx(context.formatPhrase(RenderingContext.DATA_REND_NO_DISP, b.fhirType()) + " ");
}
@ -917,7 +917,7 @@ public class DataRenderer extends Renderer implements CodeResolver {
// }
private boolean renderPrimitiveWithNoValue(RenderingStatus status, XhtmlNode x, ResourceElement prim) throws FHIRFormatError, DefinitionException, IOException {
protected boolean renderPrimitiveWithNoValue(RenderingStatus status, XhtmlNode x, ResourceElement prim) throws FHIRFormatError, DefinitionException, IOException {
if (prim.hasPrimitiveValue()) {
return false;
}
@ -1108,7 +1108,7 @@ public class DataRenderer extends Renderer implements CodeResolver {
public String displayCoding(List<Coding> list) {
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
for (Coding c : list) {
b.append(displayCoding(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), c)));
b.append(displayCoding(wrap(c)));
}
return b.toString();
}
@ -1226,7 +1226,7 @@ public class DataRenderer extends Renderer implements CodeResolver {
}
public CodeResolution resolveCode(Coding code) {
return resolveCode(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), code));
return resolveCode(wrap(code));
}
public CodeResolution resolveCode(CodeableConcept code) {
@ -1771,7 +1771,7 @@ public class DataRenderer extends Renderer implements CodeResolver {
protected void renderQuantity(HierarchicalTableGenerator gen, List<Piece> pieces, Quantity q, boolean showCodeDetails) {
pieces.add(gen.new Piece(null, displayQuantity(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), q)), null));
pieces.add(gen.new Piece(null, displayQuantity(wrap(q)), null));
}
public String displayRange(ResourceElement q) {

View File

@ -2,18 +2,25 @@ package org.hl7.fhir.r5.renderers;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.context.ContextUtilities;
import org.hl7.fhir.r5.model.*;
import org.hl7.fhir.r5.model.ExampleScenario.*;
import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.KnownLinkType;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.utilities.xhtml.XhtmlDocument;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import net.sourceforge.plantuml.SourceStringReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
@ -22,26 +29,40 @@ import java.util.Map;
public class ExampleScenarioRenderer extends TerminologyRenderer {
public ExampleScenarioRenderer(RenderingContext context) {
super(context);
public ExampleScenarioRenderer(RenderingContext context) {
super(context);
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
throw new Error("ExampleScenarioRenderer only renders native resources directly");
}
public boolean render(XhtmlNode x, Resource scen) throws IOException {
return render(x, (ExampleScenario) scen);
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
render(status, x, (ExampleScenario) r);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
public boolean render(XhtmlNode x, ExampleScenario scen) throws FHIRException {
public void render(RenderingStatus status, XhtmlNode x, ExampleScenario scen) throws FHIRException {
try {
if (context.getScenarioMode() == null) {
return renderActors(x, scen);
renderActors(status, x, scen);
} else {
switch (context.getScenarioMode()) {
case ACTORS:
return renderActors(x, scen);
renderActors(status, x, scen);
break;
case INSTANCES:
return renderInstances(x, scen);
renderInstances(status, x, scen);
break;
case PROCESSES:
return renderProcesses(x, scen);
renderProcesses(status, x, scen);
break;
default:
throw new FHIRException(context.formatPhrase(RenderingContext.EX_SCEN_UN, context.getScenarioMode()) + " ");
}
@ -117,7 +138,7 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
String plantUml = "";
if (step.hasWorkflow()) {
XhtmlNode n = new XhtmlDocument();
renderCanonical(scen, n, step.getWorkflow());
renderCanonical(wrap(scen), n, step.getWorkflow());
XhtmlNode ref = n.getChildNodes().get(0);
plantUml += noteOver(scen.getActor(), context.formatPhrase(RenderingContext.EXAMPLE_SCEN_STEP_SCEN, trimPrefix(prefix), creolLink((ref.getContent()), ref.getAttribute("href"))));
} else if (step.hasProcess())
@ -208,7 +229,7 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
return s;
}
public boolean renderActors(XhtmlNode x, ExampleScenario scen) throws IOException {
public boolean renderActors(RenderingStatus status, XhtmlNode x, ExampleScenario scen) throws IOException {
XhtmlNode tbl = x.table("table-striped table-bordered");
XhtmlNode thead = tbl.tr();
thead.th().addText(context.formatPhrase(RenderingContext.GENERAL_NAME));
@ -225,7 +246,7 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
return true;
}
public boolean renderInstances(XhtmlNode x, ExampleScenario scen) throws IOException {
public boolean renderInstances(RenderingStatus status, XhtmlNode x, ExampleScenario scen) throws IOException {
XhtmlNode tbl = x.table("table-striped table-bordered");
XhtmlNode thead = tbl.tr();
thead.th().addText(context.formatPhrase(RenderingContext.GENERAL_NAME));
@ -256,23 +277,23 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
if (instance.hasStructureVersion())
typeCell.tx((context.formatPhrase(RenderingContext.EX_SCEN_FVER, instance.getStructureVersion()) + " ") + " ");
if (instance.hasStructureProfile()) {
renderCanonical(scen, typeCell, instance.getStructureProfile().toString());
renderCanonical(wrap(scen), typeCell, instance.getStructureProfile().toString());
} else {
renderCanonical(scen, typeCell, "http://hl7.org/fhir/StructureDefinition/" + instance.getStructureType().getCode());
renderCanonical(wrap(scen), typeCell, "http://hl7.org/fhir/StructureDefinition/" + instance.getStructureType().getCode());
}
} else {
render(typeCell, instance.getStructureVersionElement());
renderDataType(status, typeCell, wrap(instance.getStructureVersionElement()));
typeCell.tx(" "+(context.formatPhrase(RenderingContext.GENERAL_VER_LOW, instance.getStructureVersion())+" "));
if (instance.hasStructureProfile()) {
typeCell.tx(" ");
renderCanonical(scen, typeCell, instance.getStructureProfile().toString());
renderCanonical(wrap(scen), typeCell, instance.getStructureProfile().toString());
}
}
if (instance.hasContent() && instance.getContent().hasReference()) {
// Force end-user mode to avoid ugly references
RenderingContext.ResourceRendererMode mode = context.getMode();
context.setMode(RenderingContext.ResourceRendererMode.END_USER);
renderReference(scen, row.td(), instance.getContent().copy().setDisplay("here"));
renderReference(status, wrap(scen), row.td(), wrap(instance.getContent().copy().setDisplay("here")));
context.setMode(mode);
} else
row.td();
@ -307,7 +328,7 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
// Force end-user mode to avoid ugly references
RenderingContext.ResourceRendererMode mode = context.getMode();
context.setMode(RenderingContext.ResourceRendererMode.END_USER);
renderReference(scen, row.td(), version.getContent().copy().setDisplay("here"));
renderReference(status, wrap(scen), row.td(), wrap(version.getContent().copy().setDisplay("here")));
context.setMode(mode);
} else
row.td();
@ -319,7 +340,7 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
return true;
}
public boolean renderProcesses(XhtmlNode x, ExampleScenario scen) throws IOException {
public boolean renderProcesses(RenderingStatus status, XhtmlNode x, ExampleScenario scen) throws IOException {
Map<String, ExampleScenarioActorComponent> actors = new HashMap<>();
for (ExampleScenarioActorComponent actor: scen.getActor()) {
actors.put(actor.getKey(), actor);
@ -332,13 +353,13 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
int num = 1;
for (ExampleScenarioProcessComponent process : scen.getProcess()) {
renderProcess(x, process, Integer.toString(num), actors, instances);
renderProcess(status, x, process, Integer.toString(num), actors, instances);
num++;
}
return true;
}
public void renderProcess(XhtmlNode x, ExampleScenarioProcessComponent process, String prefix, Map<String, ExampleScenarioActorComponent> actors, Map<String, ExampleScenarioInstanceComponent> instances) throws IOException {
public void renderProcess(RenderingStatus status, XhtmlNode x, ExampleScenarioProcessComponent process, String prefix, Map<String, ExampleScenarioActorComponent> actors, Map<String, ExampleScenarioInstanceComponent> instances) throws IOException {
XhtmlNode div = x.div();
div.an("p_" + prefix);
div.b().tx(context.formatPhrase(RenderingContext.EX_SCEN_PROC, process.getTitle())+" ");
@ -363,14 +384,14 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
thead.th().addText(context.formatPhrase(RenderingContext.EX_SCEN_RES));
int stepCount = 1;
for (ExampleScenarioProcessStepComponent step: process.getStep()) {
renderStep(tbl, step, stepPrefix(prefix, step, stepCount), actors, instances);
renderStep(status, tbl, step, stepPrefix(prefix, step, stepCount), actors, instances);
stepCount++;
}
// Now go through the steps again and spit out any child processes
stepCount = 1;
for (ExampleScenarioProcessStepComponent step: process.getStep()) {
stepSubProcesses(tbl, step, stepPrefix(prefix, step, stepCount), actors, instances);
stepSubProcesses(status, tbl, step, stepPrefix(prefix, step, stepCount), actors, instances);
stepCount++;
}
}
@ -384,15 +405,15 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
return stepPrefix(prefix + "-Alt" + Integer.toString(altNum) + ".", step, stepCount);
}
private void stepSubProcesses(XhtmlNode x, ExampleScenarioProcessStepComponent step, String prefix, Map<String, ExampleScenarioActorComponent> actors, Map<String, ExampleScenarioInstanceComponent> instances) throws IOException {
private void stepSubProcesses(RenderingStatus status, XhtmlNode x, ExampleScenarioProcessStepComponent step, String prefix, Map<String, ExampleScenarioActorComponent> actors, Map<String, ExampleScenarioInstanceComponent> instances) throws IOException {
if (step.hasProcess())
renderProcess(x, step.getProcess(), prefix, actors, instances);
renderProcess(status, x, step.getProcess(), prefix, actors, instances);
if (step.hasAlternative()) {
int altNum = 1;
for (ExampleScenarioProcessStepAlternativeComponent alt: step.getAlternative()) {
int stepCount = 1;
for (ExampleScenarioProcessStepComponent altStep: alt.getStep()) {
stepSubProcesses(x, altStep, altStepPrefix(prefix, altStep, altNum, stepCount), actors, instances);
stepSubProcesses(status, x, altStep, altStepPrefix(prefix, altStep, altNum, stepCount), actors, instances);
stepCount++;
}
altNum++;
@ -400,7 +421,7 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
}
}
private boolean renderStep(XhtmlNode tbl, ExampleScenarioProcessStepComponent step, String stepLabel, Map<String, ExampleScenarioActorComponent> actors, Map<String, ExampleScenarioInstanceComponent> instances) throws IOException {
private boolean renderStep(RenderingStatus status, XhtmlNode tbl, ExampleScenarioProcessStepComponent step, String stepLabel, Map<String, ExampleScenarioActorComponent> actors, Map<String, ExampleScenarioInstanceComponent> instances) throws IOException {
XhtmlNode row = tbl.tr();
XhtmlNode prefixCell = row.td();
prefixCell.an("s_" + stepLabel);
@ -424,7 +445,7 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
name.tx(op.getTitle());
if (op.hasType()) {
name.tx(" - ");
renderCoding(name, op.getType());
renderCoding(status, name, wrap(op.getType()));
}
XhtmlNode descCell = row.td();
addMarkdown(descCell, op.getDescription());
@ -443,7 +464,7 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
addMarkdown(altHeading, alt.getDescription());
int stepCount = 1;
for (ExampleScenarioProcessStepComponent subStep : alt.getStep()) {
renderStep(tbl, subStep, altStepPrefix(stepLabel, step, altNum, stepCount), actors, instances);
renderStep(status, tbl, subStep, altStepPrefix(stepLabel, step, altNum, stepCount), actors, instances);
stepCount++;
}
altNum++;

View File

@ -17,117 +17,115 @@ import org.hl7.fhir.r5.model.Library;
import org.hl7.fhir.r5.model.ParameterDefinition;
import org.hl7.fhir.r5.model.RelatedArtifact;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class LibraryRenderer extends ResourceRenderer {
private static final int DATA_IMG_SIZE_CUTOFF = 4000;
public LibraryRenderer(RenderingContext context) {
super(context);
}
public LibraryRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
}
private static final int DATA_IMG_SIZE_CUTOFF = 4000;
public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException {
return render(x, (Library) dr);
public LibraryRenderer(RenderingContext context) {
super(context);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
public boolean render(XhtmlNode x, ResourceWrapper lib) throws FHIRFormatError, DefinitionException, IOException {
PropertyWrapper authors = lib.getChildByName("author");
PropertyWrapper editors = lib.getChildByName("editor");
PropertyWrapper reviewers = lib.getChildByName("reviewer");
PropertyWrapper endorsers = lib.getChildByName("endorser");
if ((authors != null && authors.hasValues()) || (editors != null && editors.hasValues()) || (reviewers != null && reviewers.hasValues()) || (endorsers != null && endorsers.hasValues())) {
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement lib) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
List<ResourceElement> authors = lib.children("author");
List<ResourceElement> editors = lib.children("editor");
List<ResourceElement> reviewers = lib.children("reviewer");
List<ResourceElement> endorsers = lib.children("endorser");
if (!authors.isEmpty() || !editors.isEmpty() || !reviewers.isEmpty() || !endorsers.isEmpty()) {
boolean email = hasCT(authors, "email") || hasCT(editors, "email") || hasCT(reviewers, "email") || hasCT(endorsers, "email");
boolean phone = hasCT(authors, "phone") || hasCT(editors, "phone") || hasCT(reviewers, "phone") || hasCT(endorsers, "phone");
boolean url = hasCT(authors, "url") || hasCT(editors, "url") || hasCT(reviewers, "url") || hasCT(endorsers, "url");
x.h2().tx(context.formatPhrase(RenderingContext.LIB_REND_PAR));
XhtmlNode t = x.table("grid");
if (authors != null) {
for (BaseWrapper cd : authors.getValues()) {
participantRow(t, (context.formatPhrase(RenderingContext.LIB_REND_AUT)), cd, email, phone, url);
}
for (ResourceElement cd : authors) {
participantRow(status, t, (context.formatPhrase(RenderingContext.LIB_REND_AUT)), cd, email, phone, url);
}
if (authors != null) {
for (BaseWrapper cd : editors.getValues()) {
participantRow(t, (context.formatPhrase(RenderingContext.LIB_REND_ED)), cd, email, phone, url);
}
for (ResourceElement cd : editors) {
participantRow(status, t, (context.formatPhrase(RenderingContext.LIB_REND_ED)), cd, email, phone, url);
}
if (authors != null) {
for (BaseWrapper cd : reviewers.getValues()) {
participantRow(t, (context.formatPhrase(RenderingContext.LIB_REND_REV)), cd, email, phone, url);
}
for (ResourceElement cd : reviewers) {
participantRow(status, t, (context.formatPhrase(RenderingContext.LIB_REND_REV)), cd, email, phone, url);
}
if (authors != null) {
for (BaseWrapper cd : endorsers.getValues()) {
participantRow(t, (context.formatPhrase(RenderingContext.LIB_REND_END)), cd, email, phone, url);
}
for (ResourceElement cd : endorsers) {
participantRow(status, t, (context.formatPhrase(RenderingContext.LIB_REND_END)), cd, email, phone, url);
}
}
PropertyWrapper artifacts = lib.getChildByName("relatedArtifact");
if (artifacts != null && artifacts.hasValues()) {
List<ResourceElement> artifacts = lib.children("relatedArtifact");
if (!artifacts.isEmpty()) {
x.h2().tx(context.formatPhrase(RenderingContext.LIB_REND_ART));
XhtmlNode t = x.table("grid");
boolean label = false;
boolean display = false;
boolean citation = false;
for (BaseWrapper ra : artifacts.getValues()) {
for (ResourceElement ra : artifacts) {
label = label || ra.has("label");
display = display || ra.has("display");
citation = citation || ra.has("citation");
}
for (BaseWrapper ra : artifacts.getValues()) {
for (ResourceElement ra : artifacts) {
renderArtifact(t, ra, lib, label, display, citation);
}
}
PropertyWrapper parameters = lib.getChildByName("parameter");
if (parameters != null && parameters.hasValues()) {
List<ResourceElement> parameters = lib.children("parameter");
if (!parameters.isEmpty()) {
x.h2().tx(context.formatPhrase(RenderingContext.GENERAL_PARS));
XhtmlNode t = x.table("grid");
boolean doco = false;
for (BaseWrapper p : parameters.getValues()) {
for (ResourceElement p : parameters) {
doco = doco || p.has("documentation");
}
for (BaseWrapper p : parameters.getValues()) {
for (ResourceElement p : parameters) {
renderParameter(t, p, doco);
}
}
PropertyWrapper dataRequirements = lib.getChildByName("dataRequirement");
if (dataRequirements != null && dataRequirements.hasValues()) {
List<ResourceElement> dataRequirements = lib.children("dataRequirement");
if (!dataRequirements.isEmpty()) {
x.h2().tx(context.formatPhrase(RenderingContext.LIB_REND_REQ));
for (BaseWrapper p : dataRequirements.getValues()) {
renderDataRequirement(x, (DataRequirement) p.getBase());
for (ResourceElement p : dataRequirements) {
renderDataRequirement(status, x, p);
}
}
PropertyWrapper contents = lib.getChildByName("content");
if (contents != null) {
List<ResourceElement> contents = lib.children("content");
if (!contents.isEmpty()) {
x.h2().tx(context.formatPhrase(RenderingContext.LIB_REND_CONT));
boolean isCql = false;
int counter = 0;
for (BaseWrapper p : contents.getValues()) {
Attachment att = (Attachment) p.getBase();
renderAttachment(x, att, isCql, counter, lib.getId());
isCql = isCql || (att.hasContentType() && att.getContentType().startsWith("text/cql"));
for (ResourceElement p : contents) {
renderAttachment(x, p, isCql, counter, lib.getId());
isCql = isCql || (p.has("contentType") && p.primitiveValue("contentType").startsWith("text/cql"));
counter++;
}
}
return false;
}
private boolean hasCT(PropertyWrapper prop, String type) throws UnsupportedEncodingException, FHIRException, IOException {
if (prop != null) {
for (BaseWrapper cd : prop.getValues()) {
PropertyWrapper telecoms = cd.getChildByName("telecom");
if (getContactPoint(telecoms, type) != null) {
private boolean hasCT(List<ResourceElement> list, String type) throws UnsupportedEncodingException, FHIRException, IOException {
for (ResourceElement cd : list) {
List<ResourceElement> telecoms = cd.children("telecom");
if (hasContactPoint(telecoms, type)) {
return true;
}
}
return false;
}
private boolean hasContactPoint(List<ResourceElement> list, String type) {
for (ResourceElement cd : list) {
for (ResourceElement t : cd.children("telecom")) {
if (type.equals(t.primitiveValue("system"))) {
return true;
}
}
@ -135,273 +133,135 @@ public class LibraryRenderer extends ResourceRenderer {
return false;
}
private boolean hasCT(List<ContactDetail> list, String type) {
for (ContactDetail cd : list) {
for (ContactPoint t : cd.getTelecom()) {
if (type.equals(t.getSystem().toCode())) {
return true;
private ResourceElement getContactPoint(List<ResourceElement> list, String type) {
for (ResourceElement cd : list) {
for (ResourceElement t : cd.children("telecom")) {
if (type.equals(t.primitiveValue("system"))) {
return t;
}
}
}
return false;
}
public boolean render(XhtmlNode x, Library lib) throws FHIRFormatError, DefinitionException, IOException {
if (lib.hasAuthor() || lib.hasEditor() || lib.hasReviewer() || lib.hasEndorser()) {
boolean email = hasCT(lib.getAuthor(), "email") || hasCT(lib.getEditor(), "email") || hasCT(lib.getReviewer(), "email") || hasCT(lib.getEndorser(), "email");
boolean phone = hasCT(lib.getAuthor(), "phone") || hasCT(lib.getEditor(), "phone") || hasCT(lib.getReviewer(), "phone") || hasCT(lib.getEndorser(), "phone");
boolean url = hasCT(lib.getAuthor(), "url") || hasCT(lib.getEditor(), "url") || hasCT(lib.getReviewer(), "url") || hasCT(lib.getEndorser(), "url");
x.h2().tx(context.formatPhrase(RenderingContext.LIB_REND_PAR));
XhtmlNode t = x.table("grid");
for (ContactDetail cd : lib.getAuthor()) {
participantRow(t, (context.formatPhrase(RenderingContext.LIB_REND_AUT)), cd, email, phone, url);
}
for (ContactDetail cd : lib.getEditor()) {
participantRow(t, (context.formatPhrase(RenderingContext.LIB_REND_ED)), cd, email, phone, url);
}
for (ContactDetail cd : lib.getReviewer()) {
participantRow(t, (context.formatPhrase(RenderingContext.LIB_REND_REV)), cd, email, phone, url);
}
for (ContactDetail cd : lib.getEndorser()) {
participantRow(t, (context.formatPhrase(RenderingContext.LIB_REND_END)), cd, email, phone, url);
}
}
if (lib.hasRelatedArtifact()) {
x.h2().tx(context.formatPhrase(RenderingContext.LIB_REND_ART));
XhtmlNode t = x.table("grid");
boolean label = false;
boolean display = false;
boolean citation = false;
for (RelatedArtifact ra : lib.getRelatedArtifact()) {
label = label || ra.hasLabel();
display = display || ra.hasDisplay();
citation = citation || ra.hasCitation();
}
for (RelatedArtifact ra : lib.getRelatedArtifact()) {
renderArtifact(t, ra, lib, label, display, citation);
}
}
if (lib.hasParameter()) {
x.h2().tx(context.formatPhrase(RenderingContext.GENERAL_PARS));
XhtmlNode t = x.table("grid");
boolean doco = false;
for (ParameterDefinition p : lib.getParameter()) {
doco = doco || p.hasDocumentation();
}
for (ParameterDefinition p : lib.getParameter()) {
renderParameter(t, p, doco);
}
}
if (lib.hasDataRequirement()) {
x.h2().tx(context.formatPhrase(RenderingContext.LIB_REND_REQ));
for (DataRequirement p : lib.getDataRequirement()) {
renderDataRequirement(x, p);
}
}
if (lib.hasContent()) {
x.h2().tx(context.formatPhrase(RenderingContext.LIB_REND_CONT));
boolean isCql = false;
int counter = 0;
for (Attachment att : lib.getContent()) {
renderAttachment(x, att, isCql, counter, lib.getId());
isCql = isCql || (att.hasContentType() && att.getContentType().startsWith("text/cql"));
counter++;
}
}
return false;
}
private void renderParameter(XhtmlNode t, BaseWrapper p, boolean doco) throws UnsupportedEncodingException, FHIRException, IOException {
XhtmlNode tr = t.tr();
tr.td().tx(p.has("name") ? p.get("name").primitiveValue() : null);
tr.td().tx(p.has("use") ? p.get("use").primitiveValue() : null);
tr.td().tx(p.has("min") ? p.get("min").primitiveValue() : null);
tr.td().tx(p.has("max") ? p.get("max").primitiveValue() : null);
tr.td().tx(p.has("type") ? p.get("type").primitiveValue() : null);
if (doco) {
tr.td().tx(p.has("documentation") ? p.get("documentation").primitiveValue() : null);
}
}
private void renderParameter(XhtmlNode t, ParameterDefinition p, boolean doco) {
XhtmlNode tr = t.tr();
tr.td().tx(p.getName());
tr.td().tx(p.getUse().getDisplay());
tr.td().tx(p.getMin());
tr.td().tx(p.getMax());
tr.td().tx(p.getType().getDisplay());
if (doco) {
tr.td().tx(p.getDocumentation());
}
}
private void renderArtifact(XhtmlNode t, BaseWrapper ra, ResourceWrapper lib, boolean label, boolean display, boolean citation) throws UnsupportedEncodingException, FHIRException, IOException {
XhtmlNode tr = t.tr();
tr.td().tx(ra.has("type") ? ra.get("type").primitiveValue() : null);
if (label) {
tr.td().tx(ra.has("label") ? ra.get("label").primitiveValue() : null);
}
if (display) {
tr.td().tx(ra.has("display") ? ra.get("display").primitiveValue() : null);
}
if (citation) {
tr.td().markdown(ra.has("citation") ? ra.get("citation").primitiveValue() : null, "Citation");
}
if (ra.has("resource")) {
renderCanonical(lib, tr.td(), ra.get("resource").primitiveValue());
} else {
tr.td().tx(ra.has("url") ? ra.get("url").primitiveValue() : null);
}
}
private void renderArtifact(XhtmlNode t, RelatedArtifact ra, Resource lib, boolean label, boolean display, boolean citation) throws IOException {
XhtmlNode tr = t.tr();
tr.td().tx(ra.getType().getDisplay());
if (label) {
tr.td().tx(ra.getLabel());
}
if (display) {
tr.td().tx(ra.getDisplay());
}
if (citation) {
tr.td().markdown(ra.getCitation(), "Citation");
}
if (ra.hasResource()) {
renderCanonical(lib, tr.td(), ra.getResource());
} else {
renderAttachment(tr.td(), ra.getDocument(), false, 0, lib.getId());
}
}
private void participantRow(XhtmlNode t, String label, BaseWrapper cd, boolean email, boolean phone, boolean url) throws UnsupportedEncodingException, FHIRException, IOException {
XhtmlNode tr = t.tr();
tr.td().tx(label);
tr.td().tx(cd.get("name") != null ? cd.get("name").primitiveValue() : null);
PropertyWrapper telecoms = cd.getChildByName("telecom");
if (email) {
renderContactPoint(tr.td(), getContactPoint(telecoms, "email"));
}
if (phone) {
renderContactPoint(tr.td(), getContactPoint(telecoms, "phone"));
}
if (url) {
renderContactPoint(tr.td(), getContactPoint(telecoms, "url"));
}
}
private ContactPoint getContactPoint(PropertyWrapper telecoms, String value) throws UnsupportedEncodingException, FHIRException, IOException {
for (BaseWrapper t : telecoms.getValues()) {
if (t.has("system")) {
String system = t.get("system").primitiveValue();
if (value.equals(system)) {
return (ContactPoint) t.getBase();
}
}
}
return null;
}
private void participantRow(XhtmlNode t, String label, ContactDetail cd, boolean email, boolean phone, boolean url) {
private void renderParameter(XhtmlNode t, ResourceElement p, boolean doco) throws UnsupportedEncodingException, FHIRException, IOException {
XhtmlNode tr = t.tr();
tr.td().tx(p.has("name") ? p.primitiveValue("name") : null);
tr.td().tx(p.has("use") ? p.primitiveValue("use") : null);
tr.td().tx(p.has("min") ? p.primitiveValue("min") : null);
tr.td().tx(p.has("max") ? p.primitiveValue("max") : null);
tr.td().tx(p.has("type") ? p.primitiveValue("type") : null);
if (doco) {
tr.td().tx(p.has("documentation") ? p.primitiveValue("documentation") : null);
}
}
private void renderArtifact(XhtmlNode t, ResourceElement ra, ResourceElement lib, boolean label, boolean display, boolean citation) throws UnsupportedEncodingException, FHIRException, IOException {
XhtmlNode tr = t.tr();
tr.td().tx(ra.has("type") ? ra.primitiveValue("type") : null);
if (label) {
tr.td().tx(ra.has("label") ? ra.primitiveValue("label") : null);
}
if (display) {
tr.td().tx(ra.has("display") ? ra.primitiveValue("display") : null);
}
if (citation) {
tr.td().markdown(ra.has("citation") ? ra.primitiveValue("citation") : null, "Citation");
}
if (ra.has("resource")) {
renderCanonical(lib, tr.td(), ra.primitiveValue("resource"));
} else {
tr.td().tx(ra.has("url") ? ra.primitiveValue("url") : null);
}
}
private void participantRow(RenderingStatus status, XhtmlNode t, String label, ResourceElement cd, boolean email, boolean phone, boolean url) throws UnsupportedEncodingException, FHIRException, IOException {
XhtmlNode tr = t.tr();
tr.td().tx(label);
tr.td().tx(cd.getName());
tr.td().tx(cd.has("name") ? cd.primitiveValue("name") : null);
List<ResourceElement> telecoms = cd.children("telecom");
if (email) {
renderContactPoint(tr.td(), cd.getEmail());
renderContactPoint(status, tr.td(), getContactPoint(telecoms, "email"));
}
if (phone) {
renderContactPoint(tr.td(), cd.getPhone());
renderContactPoint(status, tr.td(), getContactPoint(telecoms, "phone"));
}
if (url) {
renderContactPoint(tr.td(), cd.getUrl());
renderContactPoint(status, tr.td(), getContactPoint(telecoms, "url"));
}
}
public void describe(XhtmlNode x, Library lib) {
x.tx(display(lib));
}
public String display(Library lib) {
return lib.present();
}
@Override
public String display(Resource r) throws UnsupportedEncodingException, IOException {
return ((Library) r).present();
}
@Override
public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
if (r.has("title")) {
return r.children("title").get(0).getBase().primitiveValue();
}
return "??";
}
private void renderAttachment(XhtmlNode x, Attachment att, boolean noShowData, int counter, String baseId) {
boolean ref = !att.hasData() && att.hasUrl();
private void renderAttachment(XhtmlNode x, ResourceElement att, boolean noShowData, int counter, String baseId) {
String url = att.primitiveValue("url");
String title = att.primitiveValue("title");
String ct = att.primitiveValue("contentType");
boolean ref = !att.has("data") && att.has("url");
if (ref) {
XhtmlNode p = x.para();
if (att.hasTitle()) {
p.tx(att.getTitle());
if (att.has("title")) {
p.tx(title);
p.tx(": ");
}
Resource res = context.getContext().fetchResource(Resource.class, att.getUrl());
Resource res = context.getContext().fetchResource(Resource.class, url);
if (res == null || !res.hasWebPath()) {
p.code().ah(att.getUrl()).tx(att.getUrl());
p.code().ah(url).tx(url);
} else if (res instanceof CanonicalResource) {
p.code().ah(res.getWebPath()).tx(((CanonicalResource) res).present());
} else {
p.code().ah(res.getWebPath()).tx(att.getUrl());
p.code().ah(res.getWebPath()).tx(url);
}
p.tx(" (");
p.code().tx(att.getContentType());
p.code().tx(ct);
p.tx(lang(att));
p.tx(")");
} else if (!att.hasData()) {
} else if (!att.has("data")) {
XhtmlNode p = x.para();
if (att.hasTitle()) {
p.tx(att.getTitle());
if (att.has("title")) {
p.tx(title);
p.tx(": ");
}
p.code().tx(context.formatPhrase(RenderingContext.LIB_REND_NOCONT));
p.tx(" (");
p.code().tx(att.getContentType());
p.code().tx(ct);
p.tx(lang(att));
p.tx(")");
} else {
String txt = getText(att);
if (isImage(att.getContentType())) {
byte[] cnt = Base64.decodeBase64(att.primitiveValue("data"));
String txt = getText(cnt);
if (isImage(ct)) {
XhtmlNode p = x.para();
if (att.hasTitle()) {
p.tx(att.getTitle());
if (att.has("title")) {
p.tx(title);
p.tx(": (");
p.code().tx(att.getContentType());
p.code().tx(ct);
p.tx(lang(att));
p.tx(")");
}
else {
p.code().tx(att.getContentType()+lang(att));
p.code().tx(ct+lang(att));
}
if (att.getData().length < LibraryRenderer.DATA_IMG_SIZE_CUTOFF) {
x.img("data: "+att.getContentType()+">;base64,"+b64(att.getData()), "data");
if (cnt.length < LibraryRenderer.DATA_IMG_SIZE_CUTOFF) {
x.img("data: "+ct+">;base64,"+b64(cnt), "data");
} else {
String filename = "Library-"+baseId+(counter == 0 ? "" : "-"+Integer.toString(counter))+"."+imgExtension(att.getContentType());
String filename = "Library-"+baseId+(counter == 0 ? "" : "-"+Integer.toString(counter))+"."+imgExtension(ct);
x.img(filename, "data");
}
} else if (txt != null && !noShowData) {
XhtmlNode p = x.para();
if (att.hasTitle()) {
p.tx(att.getTitle());
if (att.has("title")) {
p.tx(title);
p.tx(": (");
p.code().tx(att.getContentType());
p.code().tx(ct);
p.tx(lang(att));
p.tx(")");
}
else {
p.code().tx(att.getContentType()+lang(att));
p.code().tx(ct+lang(att));
}
String prismCode = determinePrismCode(att);
String prismCode = determinePrismCode(ct);
if (prismCode != null && !tooBig(txt)) {
x.pre().code().setAttribute("class", "language-"+prismCode).tx(txt);
} else {
@ -409,14 +269,14 @@ public class LibraryRenderer extends ResourceRenderer {
}
} else {
XhtmlNode p = x.para();
if (att.hasTitle()) {
p.tx(att.getTitle());
if (att.has("title")) {
p.tx(title);
p.tx(": ");
}
p.code().tx(context.formatPhrase(RenderingContext.LIB_REND_SHOW));
p.code().tx(att.getContentType());
p.code().tx(ct);
p.tx(lang(att));
p.tx((context.formatPhrase(RenderingContext.LIB_REND_SIZE, Utilities.describeSize(att.getData().length))+" ")+")");
p.tx((context.formatPhrase(RenderingContext.LIB_REND_SIZE, Utilities.describeSize(cnt.length))+" ")+")");
}
}
}
@ -446,17 +306,17 @@ public class LibraryRenderer extends ResourceRenderer {
return imgExtension(contentType) != null;
}
private String lang(Attachment att) {
if (att.hasLanguage()) {
return ", language = "+describeLang(att.getLanguage());
private String lang(ResourceElement att) {
if (att.has("language")) {
return ", language = "+describeLang(att.primitiveValue("language"));
}
return "";
}
private String getText(Attachment att) {
private String getText( byte[] cnt) {
try {
try {
String src = new String(att.getData(), "UTF-8");
String src = new String(cnt, "UTF-8");
if (checkString(src)) {
return src;
}
@ -464,7 +324,7 @@ public class LibraryRenderer extends ResourceRenderer {
// ignore
}
try {
String src = new String(att.getData(), "UTF-16");
String src = new String(cnt, "UTF-16");
if (checkString(src)) {
return src;
}
@ -472,7 +332,7 @@ public class LibraryRenderer extends ResourceRenderer {
// ignore
}
try {
String src = new String(att.getData(), "ASCII");
String src = new String(cnt, "ASCII");
if (checkString(src)) {
return src;
}
@ -494,9 +354,8 @@ public class LibraryRenderer extends ResourceRenderer {
return true;
}
private String determinePrismCode(Attachment att) {
if (att.hasContentType()) {
String ct = att.getContentType();
private String determinePrismCode(String ct) {
if (!Utilities.noString(ct)) {
if (ct.contains(";")) {
ct = ct.substring(0, ct.indexOf(";"));
}
@ -524,10 +383,10 @@ public class LibraryRenderer extends ResourceRenderer {
case "application/typescript" : return "typescript";
case "text/cql" : return "sql"; // not that bad...
}
if (att.getContentType().contains("json+") || att.getContentType().contains("+json")) {
if (ct.contains("json+") || ct.contains("+json")) {
return "json";
}
if (att.getContentType().contains("xml+") || att.getContentType().contains("+xml")) {
if (ct.contains("xml+") || ct.contains("+xml")) {
return "xml";
}
}

View File

@ -11,9 +11,9 @@ import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.DataType;
import org.hl7.fhir.r5.model.Reference;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.LiquidEngine;
import org.hl7.fhir.r5.utils.LiquidEngine.ILiquidRenderingSupport;
@ -25,33 +25,27 @@ import org.hl7.fhir.utilities.xhtml.XhtmlParser;
public class LiquidRenderer extends ResourceRenderer implements ILiquidRenderingSupport {
public class LiquidRendererContxt {
private ResourceContext rcontext;
private ResourceWrapper resource;
public LiquidRendererContxt(ResourceContext rcontext, ResourceWrapper r) {
this.rcontext = rcontext;
this.resource = r;
}
public ResourceWrapper getResource() {
return resource;
}
}
private String liquidTemplate;
public LiquidRenderer(RenderingContext context, String liquidTemplate) {
super(context);
this.liquidTemplate = liquidTemplate;
private class LiquidRendererContext {
private RenderingStatus status;
private ResourceElement resource;
protected LiquidRendererContext(RenderingStatus status, ResourceElement resource) {
super();
this.status = status;
this.resource = resource;
}
}
public LiquidRenderer(RenderingContext context, ResourceContext rcontext, String liquidTemplate) {
super(context);
this.rcontext = rcontext;
public LiquidRenderer(RenderingContext context, String liquidTemplate) {
super(context);
this.liquidTemplate = liquidTemplate;
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
/**
@ -72,14 +66,14 @@ public class LiquidRenderer extends ResourceRenderer implements ILiquidRendering
}
@Override
public boolean render(XhtmlNode x, Resource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
LiquidEngine engine = new LiquidEngine(context.getWorker(), context.getServices());
XhtmlNode xn;
try {
engine.setIncludeResolver(new LiquidRendererIncludeResolver(context));
engine.setRenderingSupport(this);
LiquidDocument doc = engine.parse(liquidTemplate, "template");
String html = engine.evaluate(doc, r, rcontext);
String html = engine.evaluate(doc, r.getBase(), new LiquidRendererContext(status, r));
xn = new XhtmlParser().parseFragment(html);
if (!x.getName().equals("div"))
throw new FHIRException("Error in template: Root element is not 'div'");
@ -88,42 +82,7 @@ public class LiquidRenderer extends ResourceRenderer implements ILiquidRendering
xn.para().b().style("color: maroon").tx("Exception generating Narrative: "+e.getMessage());
}
x.getChildNodes().addAll(xn.getChildNodes());
return true;
}
@Override
public String display(Resource r) throws UnsupportedEncodingException, IOException {
return "not done yet";
}
public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
if (r.has("title")) {
return r.children("title").get(0).getBase().primitiveValue();
}
if (r.has("name")) {
return r.children("name").get(0).getBase().primitiveValue();
}
return "??";
}
@Override
public boolean render(XhtmlNode x, ResourceWrapper 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");
engine.setRenderingSupport(this);
String html = engine.evaluate(doc, r.getBase(), new LiquidRendererContxt(rcontext, r));
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;
status.setExtensions(true);
}
public RendererType getRendererType() {
@ -133,17 +92,17 @@ public class LiquidRenderer extends ResourceRenderer implements ILiquidRendering
@Override
public String renderForLiquid(Object appContext, Base base) throws FHIRException {
try {
LiquidRendererContext ctxt = (LiquidRendererContext) appContext;
ResourceElement r = null;
if (base instanceof Element) {
base = context.getParser().parseType((Element) base);
}
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
if (base instanceof Reference) {
renderReference(((LiquidRendererContxt) appContext).getResource(), x, (Reference) base);
r = new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), (Element) base);
} else if (base instanceof DataType) {
render(x, (DataType) base);
r = new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), (DataType) base);
} else {
x.tx(base.toString());
return base.toString();
}
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
renderDataType(ctxt.status, x, r);
String res = new XhtmlComposer(true).compose(x);
res = res.substring(5);
if (res.length() < 6) {

View File

@ -4,32 +4,46 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.NamingSystem;
import org.hl7.fhir.r5.model.NamingSystem.NamingSystemUniqueIdComponent;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class NamingSystemRenderer extends ResourceRenderer {
public NamingSystemRenderer(RenderingContext context) {
super(context);
}
public NamingSystemRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
public NamingSystemRenderer(RenderingContext context) {
super(context);
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
throw new Error("NamingSystemRenderer only renders native resources directly");
}
public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException {
return render(x, (NamingSystem) dr);
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
render(status, x, (NamingSystem) r);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
public boolean render(XhtmlNode x, NamingSystem ns) throws FHIRFormatError, DefinitionException, IOException {
public void render(RenderingStatus status, XhtmlNode x, NamingSystem ns) throws FHIRFormatError, DefinitionException, IOException {
x.h3().tx(context.formatPhrase(RenderingContext.GENERAL_SUMM));
XhtmlNode tbl = x.table("grid");
row(tbl, (context.formatPhrase(RenderingContext.GENERAL_DEFINING_URL)), ns.getUrl());
@ -88,13 +102,12 @@ public class NamingSystemRenderer extends ResourceRenderer {
tr.td().tx(id.getPreferredElement().primitiveValue());
}
if (hasPeriod) {
tr.td().tx(display(id.getPeriod()));
tr.td().tx(displayDataType(id.getPeriod()));
}
if (hasComment) {
tr.td().tx(id.getComment());
}
}
return false;
}
private XhtmlNode row(XhtmlNode tbl, String name) {
@ -117,19 +130,4 @@ public class NamingSystemRenderer extends ResourceRenderer {
return ns.present();
}
@Override
public String display(Resource r) throws UnsupportedEncodingException, IOException {
return ((NamingSystem) r).present();
}
public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
if (r.has("title")) {
return r.children("title").get(0).getBase().primitiveValue();
}
if (r.has("name")) {
return r.children("name").get(0).getBase().primitiveValue();
}
return "??";
}
}

View File

@ -26,6 +26,7 @@ import org.hl7.fhir.r5.model.UsageContext;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.renderers.CodeResolver.CodeResolution;
import org.hl7.fhir.r5.renderers.ObligationsRenderer.ObligationDetail;
import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.utils.PublicationHacker;
import org.hl7.fhir.r5.utils.ToolingExtensions;
@ -40,7 +41,7 @@ import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.hl7.fhir.utilities.xhtml.XhtmlNodeList;
public class ObligationsRenderer {
public class ObligationsRenderer extends Renderer {
public static class ObligationDetail {
private List<String> codes = new ArrayList<>();
private List<String> elementIds = new ArrayList<>();
@ -167,6 +168,7 @@ public class ObligationsRenderer {
private CodeResolver cr;
public ObligationsRenderer(String corePath, StructureDefinition profile, String path, RenderingContext context, IMarkdownProcessor md, CodeResolver cr) {
super(context);
this.corePath = corePath;
this.profile = profile;
this.path = path;
@ -286,24 +288,24 @@ public class ObligationsRenderer {
return abr;
}
public String render(String defPath, String anchorPrefix, List<ElementDefinition> inScopeElements) throws IOException {
public String render(RenderingStatus status, String defPath, String anchorPrefix, List<ElementDefinition> inScopeElements) throws IOException {
if (obligations.isEmpty()) {
return "";
} else {
XhtmlNode tbl = new XhtmlNode(NodeType.Element, "table");
tbl.attribute("class", "grid");
renderTable(tbl.getChildNodes(), true, defPath, anchorPrefix, inScopeElements);
renderTable(status, tbl.getChildNodes(), true, defPath, anchorPrefix, inScopeElements);
return new XhtmlComposer(false).compose(tbl);
}
}
public void renderTable(HierarchicalTableGenerator gen, Cell c, List<ElementDefinition> inScopeElements) throws FHIRFormatError, DefinitionException, IOException {
public void renderTable(RenderingStatus status, HierarchicalTableGenerator gen, Cell c, List<ElementDefinition> inScopeElements) throws FHIRFormatError, DefinitionException, IOException {
if (obligations.isEmpty()) {
return;
} else {
Piece piece = gen.new Piece("table").attr("class", "grid");
c.getPieces().add(piece);
renderTable(piece.getChildren(), false, gen.getDefPath(), gen.getAnchorPrefix(), inScopeElements);
renderTable(status, piece.getChildren(), false, gen.getDefPath(), gen.getAnchorPrefix(), inScopeElements);
}
}
@ -358,7 +360,7 @@ public class ObligationsRenderer {
}
public void renderTable(List<XhtmlNode> children, boolean fullDoco, String defPath, String anchorPrefix, List<ElementDefinition> inScopeElements) throws FHIRFormatError, DefinitionException, IOException {
public void renderTable(RenderingStatus status, List<XhtmlNode> children, boolean fullDoco, String defPath, String anchorPrefix, List<ElementDefinition> inScopeElements) throws FHIRFormatError, DefinitionException, IOException {
boolean doco = false;
boolean usage = false;
boolean actor = false;
@ -483,7 +485,7 @@ public class ObligationsRenderer {
XhtmlNode td = tr.td();
for (UsageContext u : ob.usage) {
if (first) first = false; else td.tx(", ");
new DataRenderer(context).render(td, u);
new DataRenderer(context).renderDataType(status, td, wrap(u));
}
} else {
tr.td();

View File

@ -1,11 +1,15 @@
package org.hl7.fhir.r5.renderers;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.model.CanonicalType;
import org.hl7.fhir.r5.model.CodeType;
import java.io.UnsupportedEncodingException;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.CanonicalType;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.CodeType;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.Enumeration;
import org.hl7.fhir.r5.model.Enumerations.FHIRTypes;
import org.hl7.fhir.r5.model.Enumerations.VersionIndependentResourceTypesAll;
@ -14,10 +18,11 @@ import org.hl7.fhir.r5.model.OperationDefinition;
import org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterComponent;
import org.hl7.fhir.r5.model.OperationDefinition.OperationParameterScope;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.KnownLinkType;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
@ -28,19 +33,27 @@ import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class OperationDefinitionRenderer extends TerminologyRenderer {
public OperationDefinitionRenderer(RenderingContext context) {
super(context);
}
public OperationDefinitionRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
}
public boolean render(XhtmlNode x, Resource dr) throws IOException, FHIRException, EOperationOutcome {
return render(x, (OperationDefinition) dr);
}
public boolean render(XhtmlNode x, OperationDefinition opd) throws IOException, FHIRException, EOperationOutcome {
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
throw new Error("OperationDefinitionRenderer only renders native resources directly");
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
render(status, x, (OperationDefinition) r);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
public void render(RenderingStatus status, XhtmlNode x, OperationDefinition opd) throws IOException, FHIRException, EOperationOutcome {
if (context.isHeader()) {
x.h2().addText(opd.getName());
x.para().addText(Utilities.capitalize(opd.getKind().toString())+": "+opd.getName());
@ -91,7 +104,6 @@ public class OperationDefinitionRenderer extends TerminologyRenderer {
genOpParam(tbl, "", p, opd);
}
addMarkdown(x, opd.getComment());
return true;
}
public void describe(XhtmlNode x, OperationDefinition opd) {

View File

@ -13,11 +13,9 @@ import org.hl7.fhir.r5.model.OperationOutcome.IssueSeverity;
import org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
@ -41,12 +39,13 @@ public class OperationOutcomeRenderer extends ResourceRenderer {
boolean hasSource = false;
boolean success = true;
for (ResourceElement i : op.children("issue")) {
success = success && i.getSeverity() == IssueSeverity.INFORMATION;
hasSource = hasSource || ExtensionHelper.hasExtension(i, ToolingExtensions.EXT_ISSUE_SOURCE);
success = success && "information".equals(i.primitiveValue("severity"));
hasSource = hasSource || i.hasExtension(ToolingExtensions.EXT_ISSUE_SOURCE);
}
if (success)
x.para().tx(context.formatPhrase(RenderingContext.OP_OUT_OK));
if (op.getIssue().size() > 0) {
if (success) {
x.para().tx(context.formatPhrase(RenderingContext.OP_OUT_OK));
}
if (op.has("issue")) {
XhtmlNode tbl = x.table("grid"); // on the basis that we'll most likely be rendered using the standard fhir css, but it doesn't really matter
XhtmlNode tr = tbl.tr();
tr.td().b().tx(context.formatPhrase(RenderingContext.OP_OUT_SEV));
@ -54,31 +53,30 @@ public class OperationOutcomeRenderer extends ResourceRenderer {
tr.td().b().tx(context.formatPhrase(RenderingContext.GENERAL_CODE));
tr.td().b().tx(context.formatPhrase(RenderingContext.GENERAL_DETAILS));
tr.td().b().tx(context.formatPhrase(RenderingContext.OP_OUT_DIAG));
if (hasSource)
tr.td().b().tx(context.formatPhrase(RenderingContext.OP_OUT_SRC));
for (OperationOutcomeIssueComponent i : op.getIssue()) {
if (hasSource) {
tr.td().b().tx(context.formatPhrase(RenderingContext.OP_OUT_SRC));
}
for (ResourceElement i : op.children("issue")) {
tr = tbl.tr();
tr.td().addText(i.getSeverity().toString());
tr.td().addText(i.primitiveValue("severity"));
XhtmlNode td = tr.td();
boolean d = false;
for (StringType s : i.hasExpression() ? i.getExpression() : i.getLocation()) {
for (ResourceElement s : i.has("expression") ? i.children("expression") : i.children("location")) {
if (d)
td.tx(", ");
else
d = true;
td.addText(s.getValue());
td.addText(s.primitiveValue());
}
tr.td().addText(i.getCode().getDisplay());
tr.td().addText(display(i.getDetails()));
smartAddText(tr.td(), i.getDiagnostics());
tr.td().addText(i.child("code").primitiveValue("display"));
tr.td().addText(i.primitiveValue("details"));
smartAddText(tr.td(), i.primitiveValue("diagnostics"));
if (hasSource) {
Extension ext = ExtensionHelper.getExtension(i, ToolingExtensions.EXT_ISSUE_SOURCE);
tr.td().addText(ext == null ? "" : display(ext));
ResourceElement ext = i.extension(ToolingExtensions.EXT_ISSUE_SOURCE);
tr.td().addText(ext == null || !ext.has("value") ? "" : displayDataType(ext.child("value")));
}
}
}
return true;
}
public void describe(XhtmlNode x, OperationOutcome oo) {
@ -89,16 +87,6 @@ public class OperationOutcomeRenderer extends ResourceRenderer {
return (context.formatPhrase(RenderingContext.GENERAL_TODO));
}
@Override
public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
return (context.formatPhrase(RenderingContext.GENERAL_TODO));
}
@Override
public String display(Resource r) throws UnsupportedEncodingException, IOException {
return display((OperationOutcome) r);
}
public static String toString(OperationOutcome oo) {
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
for (OperationOutcomeIssueComponent issue : oo.getIssue()) {

View File

@ -7,28 +7,22 @@ import java.util.List;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.Parameters;
import org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.utilities.xhtml.NodeType;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class ParametersRenderer extends ResourceRenderer {
public ParametersRenderer(RenderingContext context) {
super(context);
}
public ParametersRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
}
public ParametersRenderer(RenderingContext context) {
super(context);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return "todo";
}
public ParametersRenderer setMultiLangMode(boolean multiLangMode) {
this.multiLangMode = multiLangMode;
@ -36,50 +30,28 @@ public class ParametersRenderer extends ResourceRenderer {
}
@Override
public boolean render(XhtmlNode x, Resource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
x.h2().tx(context.formatPhrase(RenderingContext.GENERAL_PARS));
XhtmlNode tbl = x.table("grid");
params(tbl, ((Parameters) r).getParameter(), 0);
return false;
params(status, tbl, r.children("parameter"), 0);
}
@Override
public String display(Resource r) throws UnsupportedEncodingException, IOException {
return null;
}
@Override
public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
return null;
}
@Override
public boolean render(XhtmlNode x, ResourceWrapper params) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
x.h2().tx(context.formatPhrase(RenderingContext.GENERAL_PARS));
XhtmlNode tbl = x.table("grid");
PropertyWrapper pw = getProperty(params, "parameter");
if (valued(pw)) {
paramsW(tbl, pw.getValues(), 0);
}
return false;
}
private void paramsW(XhtmlNode tbl, List<BaseWrapper> list, int indent) throws FHIRFormatError, DefinitionException, FHIRException, IOException, EOperationOutcome {
for (BaseWrapper p : list) {
private void params(RenderingStatus status, XhtmlNode tbl, List<ResourceElement> list, int indent) throws FHIRFormatError, DefinitionException, FHIRException, IOException, EOperationOutcome {
for (ResourceElement p : list) {
XhtmlNode tr = tbl.tr();
XhtmlNode td = tr.td();
for (int i = 0; i < indent; i++) {
td.tx(XhtmlNode.NBSP);
}
if (p.has("name")) {
td.tx(p.get("name").primitiveValue());
td.tx(p.primitiveValue("name"));
} else {
td.tx("???");
}
if (p.has("value")) {
renderBase(tr.td(), p.get("value"));
renderDataType(status, tr.td(), p.child("value"));
} else if (p.has("resource")) {
ResourceWrapper rw = p.getChildByName("resource").getAsResource();
ResourceElement rw = p.child("resource");
td = tr.td();
XhtmlNode para = td.para();
para.tx(rw.fhirType()+"/"+rw.getId());
@ -89,47 +61,12 @@ public class ParametersRenderer extends ResourceRenderer {
if (x != null) {
td.addChildren(x);
} else {
ResourceRenderer rr = RendererFactory.factory(rw, context, rcontext);
rr.render(td, rw);
ResourceRenderer rr = RendererFactory.factory(rw, context);
rr.renderResource(status, td, rw);
}
} else if (p.has("part")) {
tr.td();
PropertyWrapper pw = getProperty(p, "part");
paramsW(tbl, pw.getValues(), 1);
}
}
}
public XhtmlNode render(Parameters params) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
div.h2().tx(context.formatPhrase(RenderingContext.GENERAL_PARS));
XhtmlNode tbl = div.table("grid");
params(tbl, params.getParameter(), 0);
return div;
}
private void params(XhtmlNode tbl, List<ParametersParameterComponent> list, int indent) throws FHIRFormatError, DefinitionException, FHIRException, IOException, EOperationOutcome {
for (ParametersParameterComponent p : list) {
XhtmlNode tr = tbl.tr();
XhtmlNode td = tr.td();
for (int i = 0; i < indent; i++) {
td.tx(XhtmlNode.NBSP);
}
td.tx(p.getName());
if (p.hasValue()) {
render(tr.td(), p.getValue());
} else if (p.hasResource()) {
Resource r = p.getResource();
td = tr.td();
XhtmlNode para = td.para();
para.tx(r.fhirType()+"/"+r.getId());
para.an(r.fhirType()+"_"+r.getId()).tx(" ");
para.an("hc"+r.fhirType()+"_"+r.getId()).tx(" ");
ResourceRenderer rr = RendererFactory.factory(r, context);
rr.render(td, r);
} else if (p.hasPart()) {
tr.td();
params(tbl, p.getPart(), 1);
params(status, tbl, p.children("part"), indent+1);
}
}
}

View File

@ -2,40 +2,40 @@ package org.hl7.fhir.r5.renderers;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import org.hl7.fhir.r5.model.CodeableConcept;
import org.hl7.fhir.r5.model.Provenance;
import org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent;
import org.hl7.fhir.r5.model.Reference;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.UriType;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class ProvenanceRenderer extends ResourceRenderer {
public ProvenanceRenderer(RenderingContext context) {
super(context);
public ProvenanceRenderer(RenderingContext context) {
super(context);
}
@Override
public String displayResource(ResourceElement prv) throws UnsupportedEncodingException, IOException {
return (context.formatPhrase(RenderingContext.PROV_FOR, displayReference(prv.firstChild("target")))+" ");
}
public boolean render(XhtmlNode x, Resource prv) throws UnsupportedEncodingException, IOException {
return render(x, (Provenance) prv);
}
public boolean render(XhtmlNode x, Provenance prv) throws UnsupportedEncodingException, IOException {
boolean hasExtensions = false;
if (!prv.getTarget().isEmpty()) {
if (prv.getTarget().size() == 1) {
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement prv) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
if (prv.has("target")) {
List<ResourceElement> tl = prv.children("target");
if (tl.size() == 1) {
XhtmlNode p = x.para();
p.tx(context.formatPhrase(RenderingContext.PROV_PROV)+" ");
renderReference(prv, p, prv.getTargetFirstRep());
renderReference(status, p, tl.get(0));
} else {
x.para().tx(context.formatPhrase(RenderingContext.PROV_PROVE)+" ");
XhtmlNode ul = x.ul();
for (Reference ref : prv.getTarget()) {
renderReference(prv, ul.li(), ref);
for (ResourceElement ref : tl) {
renderReference(status, ul.li(), ref);
}
}
}
@ -43,50 +43,47 @@ public class ProvenanceRenderer extends ResourceRenderer {
x.para().tx(context.formatPhrase(RenderingContext.GENERAL_SUMM));
XhtmlNode t = x.table("grid");
XhtmlNode tr;
if (prv.hasOccurred()) {
if (prv.has("occurred")) {
tr = t.tr();
tr.td().tx(context.formatPhrase(RenderingContext.PROV_OCC));
if (prv.hasOccurredPeriod()) {
renderPeriod(tr.td(), prv.getOccurredPeriod());
} else {
renderDateTime(tr.td(), prv.getOccurredDateTimeType());
}
renderDataType(status, tr.td(), prv.child("occurred"));
}
if (prv.hasRecorded()) {
if (prv.has("recorded")) {
tr = t.tr();
tr.td().tx(context.formatPhrase(RenderingContext.PROV_REC));
tr.td().addText(displayDateTime(prv.getRecordedElement()));
renderDataType(status, tr.td(), prv.child("recorded"));
}
if (prv.hasPolicy()) {
if (prv.has("policy")) {
List<ResourceElement> tl = prv.children("policy");
tr = t.tr();
tr.td().tx(context.formatPhrase(RenderingContext.PROV_POL));
if (prv.getPolicy().size() == 1) {
renderUri(tr.td(), prv.getPolicy().get(0));
if (tl.size() == 1) {
renderDataType(status, tr.td(), tl.get(0));
} else {
XhtmlNode ul = tr.td().ul();
for (UriType u : prv.getPolicy()) {
renderUri(ul.li(), u);
for (ResourceElement u : tl) {
renderDataType(status, ul.li(), u);
}
}
}
if (prv.hasLocation()) {
if (prv.has("location")) {
tr = t.tr();
tr.td().tx(context.formatPhrase(RenderingContext.GENERAL_LOCATION));
renderReference(prv, tr.td(), prv.getLocation());
renderDataType(status, tr.td(), prv.child("location"));
}
if (prv.hasActivity()) {
if (prv.has("activity")) {
tr = t.tr();
tr.td().tx(context.formatPhrase(RenderingContext.PROV_ACT));
renderCodeableConcept(tr.td(), prv.getActivity(), false);
renderDataType(status, tr.td(), prv.child("activity"));
}
boolean hasType = false;
boolean hasRole = false;
boolean hasOnBehalfOf = false;
for (ProvenanceAgentComponent a : prv.getAgent()) {
hasType = hasType || a.hasType();
hasRole = hasRole || a.hasRole();
hasOnBehalfOf = hasOnBehalfOf || a.hasOnBehalfOf();
for (ResourceElement a : prv.children("agent")) {
hasType = hasType || a.has("type");
hasRole = hasRole || a.has("role");
hasOnBehalfOf = hasOnBehalfOf || a.has("onBehalfOf");
}
x.para().b().tx(context.formatPhrase(RenderingContext.PROV_AGE));
t = x.table("grid");
@ -101,37 +98,36 @@ public class ProvenanceRenderer extends ResourceRenderer {
if (hasOnBehalfOf) {
tr.td().b().tx(context.formatPhrase(RenderingContext.PROV_BEHALF));
}
for (ProvenanceAgentComponent a : prv.getAgent()) {
for (ResourceElement a : prv.children("agent")) {
tr = t.tr();
if (hasType) {
if (a.hasType()) {
renderCodeableConcept(tr.td(), a.getType(), false);
if (a.has("type")) {
renderDataType(status, tr.td(), a.child("type"));
} else {
tr.td();
}
}
if (hasRole) {
if (a.hasRole()) {
if (a.getRole().size() == 1) {
renderCodeableConcept(tr.td(), a.getType(), false);
} else {
XhtmlNode ul = tr.td().ul();
for (CodeableConcept cc : a.getRole()) {
renderCodeableConcept(ul.li(), cc, false);
}
}
} else {
List<ResourceElement> tl = prv.children("role");
if (tl.size() == 0) {
tr.td();
} else if (tl.size() == 1) {
renderCodeableConcept(status, tr.td(), tl.get(0), false);
} else {
XhtmlNode ul = tr.td().ul();
for (ResourceElement cc : tl) {
renderCodeableConcept(status, ul.li(), cc, false);
}
}
}
if (a.hasWho()) {
renderReference(prv, tr.td(), a.getWho());
if (a.has("who")) {
renderReference(status, tr.td(), a.child("who"));
} else {
tr.td();
}
if (hasOnBehalfOf) {
if (a.hasOnBehalfOf()) {
renderReference(prv, tr.td(), a.getOnBehalfOf());
if (a.has("onBehalfOf")) {
renderReference(status, tr.td(), a.child("onBehalfOf"));
} else {
tr.td();
}
@ -139,20 +135,7 @@ public class ProvenanceRenderer extends ResourceRenderer {
}
// agent table
return hasExtensions;
}
public String display(Resource dr) throws UnsupportedEncodingException, IOException {
return display((Provenance) dr);
}
public String display(Provenance prv) throws UnsupportedEncodingException, IOException {
return (context.formatPhrase(RenderingContext.PROV_FOR, displayReference(prv, prv.getTargetFirstRep()))+" ");
}
@Override
public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
return (context.formatPhrase(RenderingContext.GENERAL_TODO));
}
}

View File

@ -5,8 +5,11 @@ import java.util.Date;
import org.hl7.fhir.r5.comparison.VersionComparisonAnnotation;
import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.DataType;
import org.hl7.fhir.r5.model.Enumeration;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.GenerationRules;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.KnownLinkType;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.ResourceRendererMode;
@ -230,4 +233,13 @@ public class Renderer {
public String toStr(Date value) {
return value.toString();
}
protected ResourceElement wrap(DataType type) {
return new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), type);
}
protected ResourceElement wrap(Resource resource) {
return new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), resource);
}
}

View File

@ -2,8 +2,10 @@ package org.hl7.fhir.r5.renderers;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.ActorDefinition;
import org.hl7.fhir.r5.model.CanonicalResource;
@ -18,170 +20,173 @@ import org.hl7.fhir.r5.model.Requirements.RequirementsStatementComponent;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.UrlType;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class RequirementsRenderer extends ResourceRenderer {
public RequirementsRenderer(RenderingContext context) {
super(context);
public RequirementsRenderer(RenderingContext context) {
super(context);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
public RequirementsRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
}
public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException {
return render(x, (Requirements) dr);
}
public boolean render(XhtmlNode x, Requirements req) throws FHIRFormatError, DefinitionException, IOException {
if (req.hasActor()) {
if (req.getActor().size() == 1) {
ActorDefinition acd = context.getWorker().fetchResource(ActorDefinition.class, req.getActor().get(0).getValue(), req);
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement req) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
if (req.has("actor")) {
List<ResourceElement> actors = req.children("actor");
if (actors.size() == 1) {
ActorDefinition acd = context.getWorker().fetchResource(ActorDefinition.class, actors.get(0).primitiveValue(), req);
XhtmlNode p = x.para();
p.tx(context.formatPhrase(RenderingContext.REQ_ACTOR)+" ");
if (acd == null) {
p.code(req.getActor().get(0).getValue());
p.code(actors.get(0).primitiveValue());
} else {
p.ah(acd.getWebPath()).tx(acd.present());
}
} else {
x.para().tx(context.formatPhrase(RenderingContext.REQ_FOLLOWING_ACTOR)+" ");
XhtmlNode ul = x.ul();
for (CanonicalType a : req.getActor()) {
ActorDefinition acd = context.getWorker().fetchResource(ActorDefinition.class, a.getValue(), req);
for (ResourceElement a : actors) {
ActorDefinition acd = context.getWorker().fetchResource(ActorDefinition.class, a.primitiveValue(), req);
if (acd == null) {
ul.li().code(a.getValue());
ul.li().code(a.primitiveValue());
} else {
ul.li().ah(acd.getWebPath()).tx(acd.present());
}
}
}
}
if (req.hasDerivedFrom()) {
if (req.getDerivedFrom().size() == 1) {
Requirements reqd = context.getWorker().fetchResource(Requirements.class, req.getDerivedFrom().get(0).getValue(), req);
if (req.has("derivedFrom")) {
List<ResourceElement> list = req.children("derivedFrom");
if (list.size() == 1) {
Requirements reqd = context.getWorker().fetchResource(Requirements.class, list.get(0).primitiveValue(), req);
XhtmlNode p = x.para();
p.tx(context.formatPhrase(RenderingContext.REQ_DERIVE)+" ");
if (reqd == null) {
p.code(req.getDerivedFrom().get(0).getValue());
p.code(list.get(0).primitiveValue());
} else {
p.ah(reqd.getWebPath()).tx(reqd.present());
}
} else {
x.para().tx(context.formatPhrase(RenderingContext.REQ_FOLLOWING_REQ)+" ");
XhtmlNode ul = x.ul();
for (CanonicalType a : req.getDerivedFrom()) {
Requirements reqd = context.getWorker().fetchResource(Requirements.class, a.getValue(), req);
for (ResourceElement a : list) {
Requirements reqd = context.getWorker().fetchResource(Requirements.class, a.primitiveValue(), req);
if (reqd == null) {
ul.li().code(a.getValue());
ul.li().code(a.primitiveValue());
} else {
ul.li().ah(reqd.getWebPath()).tx(reqd.present());
}
}
}
}
if (req.hasReference()) {
if (req.has("reference")) {
XhtmlNode p = x.para();
p.tx(context.formatPhrase(RenderingContext.GENERAL_REFS)+" ");
int i = 0;
for (UrlType c : req.getReference()) {
for (ResourceElement c : req.children("reference")) {
i++;
if (i>1) p.tx(", ");
String url = c.getValue();
String url = c.primitiveValue();
if (url.contains("#")) {
url = url.substring(0, url.indexOf("#"));
}
p.ah(c.getValue()).tx(url);
p.ah(c.primitiveValue()).tx(url);
}
}
XhtmlNode tbl = x.table("grid");
for (RequirementsStatementComponent stmt : req.getStatement()) {
for (ResourceElement stmt : req.children("statement")) {
XhtmlNode tr = tbl.tr();
String lbl = stmt.hasLabel() ? stmt.getLabel() : stmt.getKey();
String lbl = stmt.has("label") ? stmt.primitiveValue("label") : stmt..primitiveValue("key");
XhtmlNode td = tr.td();
td.b().an(stmt.getKey());
td.b().an(stmt.primitiveValue("key"));
td.tx(lbl);
td = tr.td();
boolean first = true;
CodeSystem cs = context.getWorker().fetchCodeSystem("http://hl7.org/fhir/conformance-expectation");
for (Enumeration<ConformanceExpectation> t : stmt.getConformance()) {
for (ResourceElement t : stmt.children("conformance")) {
if (first) first = false; else td.tx(", ");
if (cs != null) {
td.ah(cs.getWebPath()+"#conformance-expectation-"+t.asStringValue()).tx(t.asStringValue().toUpperCase());
td.ah(cs.getWebPath()+"#conformance-expectation-"+t.primitiveValue()).tx(t.primitiveValue().toUpperCase());
} else {
td.tx(t.asStringValue().toUpperCase());
td.tx(t.primitiveValue().toUpperCase());
}
}
td = tr.td();
addMarkdown(td, stmt.getRequirement());
if (stmt.hasDerivedFrom() || stmt.hasSatisfiedBy() || stmt.hasReference() || stmt.hasSource()) {
addMarkdown(td, stmt.primitiveValue("requirement"));
if (stmt.has("derivedFrom") || stmt.has("satisfiedBy") || stmt.has("reference") || stmt.has("source")) {
td.para().tx(context.formatPhrase(RenderingContext.REQ_LINKS)+" ");
XhtmlNode ul = td.ul();
if (stmt.hasDerivedFrom()) {
if (stmt.has("derivedFrom")) {
XhtmlNode li = ul.li();
li.tx(context.formatPhrase(RenderingContext.REQ_DERIVED)+" ");
String url = stmt.getDerivedFrom();
String url = stmt.primitiveValue("derivedFrom");
String key = url.contains("#") ? url.substring(url.indexOf("#")+1) : "";
if (url.contains("#")) { url = url.substring(0, url.indexOf("#")); };
Requirements reqr = context.getWorker().fetchResource(Requirements.class, url, req);
if (reqr != null) {
RequirementsStatementComponent stmtr = reqr.findStatement(key);
if (stmtr != null) {
li.ah(reqr.getWebPath()+"#"+key).tx(reqr.present() + " # " +(stmt.hasLabel() ? stmt.getLabel() : stmt.getKey()));
li.ah(reqr.getWebPath()+"#"+key).tx(reqr.present() + " # " +(stmt.has("label") ? stmt.primitiveValue("label") : stmt.primitiveValue("key")));
} else {
li.ah(reqr.getWebPath()+"#"+key).tx(reqr.present()+" # "+key);
}
} else {
li.code(stmt.getDerivedFrom());
li.code(stmt.primitiveValue("derivedFrom"));
}
}
if (stmt.hasSatisfiedBy()) {
if (stmt.has("satisfiedBy")) {
XhtmlNode li = ul.li();
li.tx(context.formatPhrase(RenderingContext.REQ_SATISFIED)+" ");
first = true;
for (UrlType c : stmt.getSatisfiedBy()) {
for (ResourceElement c : stmt.children("satisfiedBy")) {
if (first) first = false; else li.tx(", ");
String url = c.getValue();
String url = c.primitiveValue();
if (url.contains("#")) {
url = url.substring(0, url.indexOf("#"));
}
Resource r = context.getWorker().fetchResource(Resource.class, url, req);
if (r != null) {
String desc = getResourceDescription(r, null);
li.ah(c.getValue()).tx(desc);
li.ah(c.primitiveValue()).tx(desc);
} else {
li.ah(c.getValue()).tx(url);
li.ah(c.primitiveValue()).tx(url);
}
}
}
if (stmt.hasReference()) {
if (stmt.has("reference")) {
XhtmlNode li = ul.li();
li.tx(context.formatPhrase(RenderingContext.GENERAL_REFS)+" ");
int i = 0;
for (UrlType c : stmt.getReference()) {
for (ResourceElement c : stmt.children("reference")) {
i++;
if (i>1) li.tx(", ");
String url = c.getValue();
String url = c.primitiveValue();
if (url.contains("#")) {
url = url.substring(0, url.indexOf("#"));
}
li.ah(c.getValue()).tx(url);
li.ah(c.primitiveValue()).tx(url);
}
}
if (stmt.hasSource()) {
if (stmt.has("source")) {
XhtmlNode li = ul.li();
li.tx(context.formatPhrase(RenderingContext.GENERAL_SRC)+" ");
first = true;
for (Reference c : stmt.getSource()) {
for (ResourceElement c : stmt.children("source")) {
if (first) first = false; else li.tx(", ");
if (c.hasReference()) {
String url = c.getReference();
if (c.has("reference")) {
String url = c.primitiveValue("reference");
if (url.contains("#")) {
url = url.substring(0, url.indexOf("#"));
}
@ -191,16 +196,16 @@ public class RequirementsRenderer extends ResourceRenderer {
t = context.getResolver().resolve(context, url);
}
if (r != null) {
String desc = getResourceDescription(r, c.getDisplay());
li.ah(c.getReference()).tx(desc);
String desc = getResourceDescription(r, c.primitiveValue("display"));
li.ah(c.primitiveValue("reference")).tx(desc);
} else if (t != null) {
String desc = getResourceDescription(t, c.getDisplay());
String desc = getResourceDescription(t, c.primitiveValue("display"));
li.ah(t.getReference()).tx(desc);
} else {
li.ah(c.getReference()).tx(url);
li.ah(c.primitiveValue("reference")).tx(url);
}
} else if (c.hasDisplay()) {
li.tx(c.getDisplay());
} else if (c.has("display")) {
li.tx(c.primitiveValue("display"));
} else {
li.tx("??");
}
@ -208,9 +213,8 @@ public class RequirementsRenderer extends ResourceRenderer {
}
}
}
return false;
}
private String getResourceDescription(ResourceWithReference res, String display) throws UnsupportedEncodingException, IOException {
if (!Utilities.noString(display)) {
return display;
@ -236,17 +240,4 @@ public class RequirementsRenderer extends ResourceRenderer {
return lib.present();
}
@Override
public String display(Resource r) throws UnsupportedEncodingException, IOException {
return ((Library) r).present();
}
@Override
public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
if (r.has("title")) {
return r.children("title").get(0).getBase().primitiveValue();
}
return "??";
}
}

View File

@ -147,7 +147,7 @@ public abstract class ResourceRenderer extends DataRenderer {
// these three are what the descendants of this class override
public abstract void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome;
public void renderResource(RenderingStatus status, XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
renderResource(status, x, new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), r));
renderResource(status, x, wrap(r));
}
public abstract String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException;
@ -209,6 +209,12 @@ public abstract class ResourceRenderer extends DataRenderer {
x.addTag(0, "hr");
}
public void renderCanonical(RenderingStatus status, ResourceElement resource, XhtmlNode x, ResourceElement canonical) throws UnsupportedEncodingException, IOException {
if (!renderPrimitiveWithNoValue(status, x, canonical)) {
renderCanonical(resource, x, canonical.primitiveValue(), true, resource);
}
}
public void renderCanonical(ResourceElement res, XhtmlNode x, String url) throws UnsupportedEncodingException, IOException {
renderCanonical(res, x, url, true, res);
}
@ -299,7 +305,7 @@ public abstract class ResourceRenderer extends DataRenderer {
String link = null;
StringBuilder text = new StringBuilder();
if (r.hasReferenceElement() && allowLinks) {
tr = resolveReference(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), res), r.getReference());
tr = resolveReference(wrap(res), r.getReference());
if (!r.getReference().startsWith("#")) {
if (tr != null && tr.getReference() != null) {
@ -322,7 +328,7 @@ public abstract class ResourceRenderer extends DataRenderer {
if (!Utilities.noString(r.getReference())) {
text.append(r.getReference());
} else if (r.hasIdentifier()) {
text.append(displayIdentifier(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), r.getIdentifier())));
text.append(displayIdentifier(wrap(r.getIdentifier())));
} else {
text.append("??");
}

View File

@ -4,8 +4,10 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.model.CodeType;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.Enumeration;
import org.hl7.fhir.r5.model.Enumerations.SearchComparator;
import org.hl7.fhir.r5.model.Enumerations.SearchModifierCode;
@ -18,7 +20,7 @@ import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.KnownLinkType;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.StandardsStatus;
@ -27,19 +29,27 @@ import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class SearchParameterRenderer extends TerminologyRenderer {
public SearchParameterRenderer(RenderingContext context) {
super(context);
}
public SearchParameterRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
public SearchParameterRenderer(RenderingContext context) {
super(context);
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
throw new Error("SearchParameterRenderer only renders native resources directly");
}
public boolean render(XhtmlNode x, Resource dr) throws IOException, FHIRException, EOperationOutcome {
return render(x, (SearchParameter) dr);
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
render(status, x, (SearchParameter) r);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
public boolean render(XhtmlNode x, SearchParameter spd) throws IOException, FHIRException, EOperationOutcome {
public void render(RenderingStatus status, XhtmlNode x, SearchParameter spd) throws IOException, FHIRException, EOperationOutcome {
XhtmlNode h2 = x.h2();
h2.addText(spd.getName());
StandardsStatus ss = ToolingExtensions.getStandardsStatus(spd);
@ -161,7 +171,6 @@ public class SearchParameterRenderer extends TerminologyRenderer {
tr.td().code().tx(t.getExpression());
}
}
return false;
}
private boolean isAllConcreteResources(List<Enumeration<VersionIndependentResourceTypesAll>> list) {

View File

@ -9,20 +9,23 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.CodeType;
import org.hl7.fhir.r5.model.ConceptMap;
import org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent;
import org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent;
import org.hl7.fhir.r5.model.DataType;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.Enumeration;
import org.hl7.fhir.r5.model.IdType;
import org.hl7.fhir.r5.model.Enumerations.ConceptMapRelationship;
import org.hl7.fhir.r5.model.Enumerations.SearchComparator;
import org.hl7.fhir.r5.model.Enumerations.SearchModifierCode;
import org.hl7.fhir.r5.model.Enumerations.VersionIndependentResourceTypesAll;
import org.hl7.fhir.r5.model.IdType;
import org.hl7.fhir.r5.model.OperationDefinition;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.SearchParameter;
import org.hl7.fhir.r5.model.SearchParameter.SearchParameterComponentComponent;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.StructureMap;
import org.hl7.fhir.r5.model.StructureMap.StructureMapGroupComponent;
import org.hl7.fhir.r5.model.StructureMap.StructureMapGroupInputComponent;
import org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleComponent;
@ -33,27 +36,38 @@ import org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetParameterCo
import org.hl7.fhir.r5.model.StructureMap.StructureMapStructureComponent;
import org.hl7.fhir.r5.model.StructureMap.StructureMapTargetListMode;
import org.hl7.fhir.r5.model.StructureMap.StructureMapTransform;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.StructureMap;
import org.hl7.fhir.r5.model.UriType;
import org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent;
import org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent;
import org.hl7.fhir.r5.model.DataType;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.KnownLinkType;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities;
import org.hl7.fhir.utilities.StandardsStatus;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.xhtml.XhtmlFluent;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class StructureMapRenderer extends TerminologyRenderer {
public StructureMapRenderer(RenderingContext context) {
super(context);
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
throw new Error("StructureMapRenderer only renders native resources directly");
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
renderMap(status, x, (StructureMap) r);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
private static final String COLOR_COMMENT = "green";
private static final String COLOR_METADATA = "#cc00cc";
private static final String COLOR_CONST = "blue";
@ -62,24 +76,7 @@ public class StructureMapRenderer extends TerminologyRenderer {
private static final boolean MULTIPLE_TARGETS_ONELINE = true;
private static final String COLOR_SPECIAL = "#b36b00";
public StructureMapRenderer(RenderingContext context) {
super(context);
}
public StructureMapRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
}
public boolean render(XhtmlNode x, Resource dr) throws IOException, FHIRException, EOperationOutcome {
return render(x, (StructureMap) dr);
}
public boolean render(XhtmlNode x, StructureMap map) throws IOException, FHIRException, EOperationOutcome {
renderMap(x.pre("fml"), map);
return false;
}
public void renderMap(XhtmlNode x, StructureMap map) {
public void renderMap(RenderingStatus status, XhtmlNode x, StructureMap map) {
x.tx("\r\n");
if (VersionUtilities.isR5Plus(context.getContext().getVersion())) {
renderMetadata(x, "url", map.getUrlElement());

View File

@ -682,5 +682,11 @@ public class ResourceElement {
return propertyDefinition;
}
public List<XhtmlNode> getXhtml() {
}
public Base getBase() {
}
}