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 java.io.UnsupportedEncodingException;
import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError; import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.ActorDefinition; import org.hl7.fhir.r5.model.ActorDefinition;
import org.hl7.fhir.r5.model.CapabilityStatement; 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.Library;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.UrlType; 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.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; import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class ActorDefinitionRenderer extends ResourceRenderer { public class ActorDefinitionRenderer extends ResourceRenderer {
public ActorDefinitionRenderer(RenderingContext context) { public ActorDefinitionRenderer(RenderingContext context) {
super(context); super(context);
} }
public ActorDefinitionRenderer(RenderingContext context, ResourceContext rcontext) { @Override
super(context, rcontext); 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 { @Override
return render(x, (ActorDefinition) dr); 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 tbl = x.table("grid");
XhtmlNode tr = tbl.tr(); XhtmlNode tr = tbl.tr();
tr.td().b().tx(context.formatPhrase(RenderingContext.ACTOR_DEF_ACT, acd.getName()) + " "); tr.td().b().tx(context.formatPhrase(RenderingContext.ACTOR_DEF_ACT, acd.getName()) + " ");
@ -44,7 +52,7 @@ public class ActorDefinitionRenderer extends ResourceRenderer {
boolean first = true; boolean first = true;
for (UrlType t : acd.getReference()) { for (UrlType t : acd.getReference()) {
if (first) first = false; else x.br(); if (first) first = false; else x.br();
render(td, t); renderUri(status, td, wrap(t));
} }
} }
if (acd.hasCapabilities()) { if (acd.hasCapabilities()) {
@ -54,7 +62,7 @@ public class ActorDefinitionRenderer extends ResourceRenderer {
if (cs != null) { if (cs != null) {
td.ah(cs.getWebPath()).tx(cs.present()); td.ah(cs.getWebPath()).tx(cs.present());
} else { } else {
render(td, acd.getCapabilitiesElement()); renderCanonical(status, wrap(acd), td, wrap(acd.getCapabilitiesElement()));
} }
} }
if (acd.hasDerivedFrom()) { if (acd.hasDerivedFrom()) {
@ -67,11 +75,10 @@ public class ActorDefinitionRenderer extends ResourceRenderer {
if (df != null) { if (df != null) {
td.ah(df.getWebPath()).tx(df.present()); td.ah(df.getWebPath()).tx(df.present());
} else { } else {
render(td, t); renderUri(status, td, wrap(t));
} }
} }
} }
return false;
} }
public void describe(XhtmlNode x, Library lib) { public void describe(XhtmlNode x, Library lib) {
@ -82,17 +89,4 @@ public class ActorDefinitionRenderer extends ResourceRenderer {
return lib.present(); 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.UsageContext;
import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.renderers.CodeResolver.CodeResolution; 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.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.utils.PublicationHacker; import org.hl7.fhir.r5.utils.PublicationHacker;
import org.hl7.fhir.r5.utils.ToolingExtensions; import org.hl7.fhir.r5.utils.ToolingExtensions;
@ -290,7 +291,7 @@ public class AdditionalBindingsRenderer {
if (usage) { if (usage) {
if (binding.usage != null) { if (binding.usage != null) {
// TODO: This isn't rendered at all yet. Ideally, we want it to render with comparison... // 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 { } else {
tr.td(); tr.td();
} }

View File

@ -9,6 +9,7 @@ import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError; import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.Base; import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.Bundle; 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.BundleEntryComponent;
import org.hl7.fhir.r5.model.Bundle.BundleEntryRequestComponent; import org.hl7.fhir.r5.model.Bundle.BundleEntryRequestComponent;
import org.hl7.fhir.r5.model.Bundle.BundleEntryResponseComponent; import org.hl7.fhir.r5.model.Bundle.BundleEntryResponseComponent;
@ -21,10 +22,9 @@ import org.hl7.fhir.r5.model.Property;
import org.hl7.fhir.r5.model.Provenance; import org.hl7.fhir.r5.model.Provenance;
import org.hl7.fhir.r5.model.Reference; import org.hl7.fhir.r5.model.Reference;
import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper; import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.utils.RenderingContext; 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.EOperationOutcome;
import org.hl7.fhir.utilities.xhtml.NodeType; import org.hl7.fhir.utilities.xhtml.NodeType;
import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.hl7.fhir.utilities.xhtml.XhtmlNode;
@ -32,14 +32,14 @@ import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class BundleRenderer extends ResourceRenderer { public class BundleRenderer extends ResourceRenderer {
public BundleRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
}
public BundleRenderer(RenderingContext context) { public BundleRenderer(RenderingContext context) {
super(context); super(context);
} }
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return "Bundle";
}
public BundleRenderer setMultiLangMode(boolean multiLangMode) { public BundleRenderer setMultiLangMode(boolean multiLangMode) {
this.multiLangMode = multiLangMode; this.multiLangMode = multiLangMode;
@ -47,53 +47,36 @@ public class BundleRenderer extends ResourceRenderer {
} }
@Override @Override
public boolean render(XhtmlNode x, Resource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome { public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement b) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
XhtmlNode n = render((Bundle) r); List<ResourceElement> entries = b.children("entry");
x.addChildren(n.getChildNodes()); if ("document".equals(b.primitiveValue("type"))) {
return false; 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);
@Override } else if ("collection".equals(b.primitiveValue("type")) && allEntriesAreHistoryProvenance(entries)) {
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)) {
// nothing // nothing
} else { } else {
XhtmlNode root = new XhtmlNode(NodeType.Element, "div"); 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; int i = 0;
for (BaseWrapper be : entries) { for (ResourceElement be : entries) {
i++; i++;
if (be.has("fullUrl")) { if (be.has("fullUrl")) {
root.an(makeInternalBundleLink(be.get("fullUrl").primitiveValue())); root.an(makeInternalBundleLink(be.primitiveValue("fullUrl")));
} }
if (be.has("resource")) { if (be.has("resource")) {
if (be.getChildByName("resource").getValues().get(0).has("id")) { if (be.child("resource").has("id")) {
root.an(be.get("resource").fhirType() + "_" + be.getChildByName("resource").getValues().get(0).get("id").primitiveValue()); root.an(be.child("resource").fhirType() + "_" + be.child("resource").primitiveValue("id"));
root.an("hc"+be.get("resource").fhirType() + "_" + be.getChildByName("resource").getValues().get(0).get("id").primitiveValue()); root.an("hc"+be.child("resource").fhirType() + "_" + be.child("resource").primitiveValue("id"));
} else { } else {
String id = makeIdFromBundleEntry(be.get("fullUrl").primitiveValue()); String id = makeIdFromBundleEntry(be.primitiveValue("fullUrl"));
root.an(be.get("resource").fhirType() + "_" + id); root.an(be.child("resource").fhirType() + "_" + id);
root.an("hc"+be.get("resource").fhirType() + "_" + id); root.an("hc"+be.child("resource").fhirType() + "_" + id);
} }
} }
root.hr(); root.hr();
if (be.has("fullUrl")) { 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 { } else {
root.para().addText(formatPhrase(RenderingContext.BUNDLE_HEADER_ENTRY, Integer.toString(i))); root.para().addText(formatPhrase(RenderingContext.BUNDLE_HEADER_ENTRY, Integer.toString(i)));
} }
@ -104,14 +87,14 @@ public class BundleRenderer extends ResourceRenderer {
// if (be.hasResponse()) // if (be.hasResponse())
// renderResponse(root, be.getResponse()); // renderResponse(root, be.getResponse());
if (be.has("resource")) { if (be.has("resource")) {
root.para().addText(formatPhrase(RenderingContext.BUNDLE_RESOURCE, be.get("resource").fhirType())); ResourceElement r = be.child("resource");
ResourceWrapper rw = be.getChildByName("resource").getAsResource(); root.para().addText(formatPhrase(RenderingContext.BUNDLE_RESOURCE, r.fhirType()));
XhtmlNode xn = rw.getNarrative(); XhtmlNode xn = r.getNarrative();
if (xn == null || xn.isEmpty()) { if (xn == null || xn.isEmpty()) {
ResourceRenderer rr = RendererFactory.factory(rw, context); ResourceRenderer rr = RendererFactory.factory(r, context);
try { try {
rr.setRcontext(new ResourceContext(rcontext, rw)); xn = new XhtmlNode(NodeType.Element, "div");
xn = rr.render(rw); rr.renderResource(new RenderingStatus(), xn, r);
} catch (Exception e) { } catch (Exception e) {
xn = new XhtmlNode(); xn = new XhtmlNode();
xn.para().b().tx(context.formatPhrase(RenderingContext.BUNDLE_REV_EXCP, e.getMessage()) + " "); 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); 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: // from the spec:
// //
// When the document is presented for human consumption, applications SHOULD present the collated narrative portions in order: // When the document is presented for human consumption, applications SHOULD present the collated narrative portions in order:
// * The subject resource Narrative // * The subject resource Narrative
// * The Composition resource Narrative // * The Composition resource Narrative
// * The section.text Narratives // * The section.text Narratives
ResourceWrapper comp = (ResourceWrapper) entries.get(0).getChildByName("resource").getAsResource(); ResourceElement comp = (ResourceElement) entries.get(0).child("resource");
ResourceWrapper subject = resolveReference(entries, comp.get("subject")); ResourceElement subject = resolveReference(entries, comp.child("subject"));
if (subject != null) { if (subject != null) {
if (subject.hasNarrative()) { if (subject.hasNarrative()) {
x.addChildren(subject.getNarrative()); x.addChildren(subject.getNarrative());
} else { } else {
RendererFactory.factory(subject, context, new ResourceContext(rcontext, subject)).render(x, subject); RendererFactory.factory(subject, context).renderResource(status, x, subject);
} }
} }
x.hr(); x.hr();
@ -146,32 +138,31 @@ public class BundleRenderer extends ResourceRenderer {
x.addChildren(comp.getNarrative()); x.addChildren(comp.getNarrative());
x.hr(); x.hr();
} }
List<BaseWrapper> sections = comp.children("section"); List<ResourceElement> sections = comp.children("section");
for (BaseWrapper section : sections) { for (ResourceElement section : sections) {
addSection(x, section, 2, false); 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")) { if (section.has("title") || section.has("code") || section.has("text") || section.has("section")) {
XhtmlNode div = x.div(); XhtmlNode div = x.div();
if (section.has("title")) { if (section.has("title")) {
div.h(level).tx(section.get("title").primitiveValue()); div.h(level).tx(section.primitiveValue("title"));
} else if (section.has("code")) { } else if (section.has("code")) {
renderBase(div.h(level), section.get("code")); renderDataType(status, div.h(level), section.child("code"));
} }
if (section.has("text")) { if (section.has("text")) {
Base narrative = section.get("text"); ResourceElement narrative = section.child("text");
x.addChildren(narrative.getXhtml()); x.addChildren(narrative.getXhtml());
} }
if (section.has("section")) { if (section.has("section")) {
List<BaseWrapper> sections = section.children("section"); List<ResourceElement> sections = section.children("section");
for (BaseWrapper child : sections) { for (ResourceElement child : sections) {
if (nested) { if (nested) {
addSection(x.blockquote().para(), child, level+1, true); addSection(status, x.blockquote().para(), child, level+1, true);
} else { } else {
addSection(x, child, level+1, true); addSection(status, x, child, level+1, true);
} }
} }
} }
@ -179,20 +170,17 @@ public class BundleRenderer extends ResourceRenderer {
// children // 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) { if (base == null) {
return null; return null;
} }
Property prop = base.getChildByName("reference"); ResourceElement prop = base.child("reference");
if (prop.hasValues()) { if (prop != null && prop.hasPrimitiveValue()) {
String ref = prop.getValues().get(0).primitiveValue(); for (ResourceElement entry : entries) {
if (ref != null) { if (entry.has("fullUrl")) {
for (BaseWrapper entry : entries) { String fu = entry.primitiveValue("fullUrl");
if (entry.has("fullUrl")) { if (prop.primitiveValue().equals(fu)) {
String fu = entry.get("fullUrl").primitiveValue(); return entry.child("resource");
if (ref.equals(fu)) {
return (ResourceWrapper) entry.getChildByName("resource").getAsResource();
}
} }
} }
} }
@ -200,173 +188,9 @@ public class BundleRenderer extends ResourceRenderer {
return null; return null;
} }
private boolean renderDocument(XhtmlNode x, Bundle b) throws UnsupportedEncodingException, FHIRException, IOException, EOperationOutcome { public static boolean allEntriesAreHistoryProvenance(List<ResourceElement> entries) throws UnsupportedEncodingException, FHIRException, IOException {
// from the spec: for (ResourceElement be : entries) {
// if (!"Provenance".equals(be.child("resource").fhirType())) {
// 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())) {
return false; 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(); StringBuilder b = new StringBuilder();
b.append(formatPhrase(RenderingContext.BUNDLE_SEARCH)); b.append(formatPhrase(RenderingContext.BUNDLE_SEARCH));
if (search.hasMode()) if (search.has("mode"))
b.append(formatPhrase(RenderingContext.BUNDLE_SEARCH_MODE, search.getMode().toCode())); b.append(formatPhrase(RenderingContext.BUNDLE_SEARCH_MODE, search.primitiveValue("mode")));
if (search.hasScore()) { if (search.has("score")) {
if (search.hasMode()) if (search.has("mode")) {
b.append(","); 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()); 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)); root.para().addText(formatPhrase(RenderingContext.BUNDLE_RESPONSE));
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
b.append(response.getStatus()+"\r\n"); b.append(response.primitiveValue("status")+"\r\n");
if (response.hasLocation()) if (response.has("location"))
b.append(formatPhrase(RenderingContext.BUNDLE_LOCATION, response.getLocation())+"\r\n"); b.append(formatPhrase(RenderingContext.BUNDLE_LOCATION, response.primitiveValue("location"))+"\r\n");
if (response.hasEtag()) if (response.has("etag"))
b.append(formatPhrase(RenderingContext.BUNDLE_ETAG, response.getEtag())+"\r\n"); b.append(formatPhrase(RenderingContext.BUNDLE_ETAG, response.primitiveValue("etag"))+"\r\n");
if (response.hasLastModified()) if (response.has("lastModified"))
b.append(formatPhrase(RenderingContext.BUNDLE_LAST_MOD, response.getEtag())+"\r\n"); b.append(formatPhrase(RenderingContext.BUNDLE_LAST_MOD, response.primitiveValue("lastModified"))+"\r\n");
root.pre().addText(b.toString()); 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)); root.para().addText(formatPhrase(RenderingContext.BUNDLE_REQUEST));
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
b.append(request.getMethod()+" "+request.getUrl()+"\r\n"); b.append(request.primitiveValue("method")+" "+request.primitiveValue("url")+"\r\n");
if (request.hasIfNoneMatch()) if (request.has("ifNoneMatch"))
b.append(formatPhrase(RenderingContext.BUNDLE_IF_NON_MATCH, request.getIfNoneMatch())+"\r\n"); b.append(formatPhrase(RenderingContext.BUNDLE_IF_NON_MATCH, request.primitiveValue("ifNoneMatch"))+"\r\n");
if (request.hasIfModifiedSince()) if (request.has("ifModifiedSince"))
b.append(formatPhrase(RenderingContext.BUNDLE_IF_MOD, request.getIfModifiedSince())+"\r\n"); b.append(formatPhrase(RenderingContext.BUNDLE_IF_MOD, request.primitiveValue("ifModifiedSince"))+"\r\n");
if (request.hasIfMatch()) if (request.has("ifMatch"))
b.append(formatPhrase(RenderingContext.BUNDLE_IF_MATCH, request.getIfMatch())+"\r\n"); b.append(formatPhrase(RenderingContext.BUNDLE_IF_MATCH, request.primitiveValue("ifMatch"))+"\r\n");
if (request.hasIfNoneExist()) if (request.has("ifNoneExist"))
b.append(formatPhrase(RenderingContext.BUNDLE_IF_NONE, request.getIfNoneExist())+"\r\n"); b.append(formatPhrase(RenderingContext.BUNDLE_IF_NONE, request.primitiveValue("ifNoneExist"))+"\r\n");
root.pre().addText(b.toString()); root.pre().addText(b.toString());
} }
public String display(Bundle bundle) throws UnsupportedEncodingException, IOException {
return "??";
}
public boolean canRender(Bundle b) { public boolean canRender(Bundle b) {
for (BundleEntryComponent be : b.getEntry()) { for (BundleEntryComponent be : b.getEntry()) {
if (be.hasResource()) { 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()) + " "); uList.li().addText(context.formatPhrase(RenderingContext.CAPABILITY_FHIR_VER, currentVersion.toCode()) + " ");
addSupportedFormats(uList, conf); 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()) + " "); 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.b().tx(context.formatPhrase(RenderingContext.CONC_MAP_GRP, gc) + " ");
pp.tx(context.formatPhrase(RenderingContext.CONC_MAP_FROM) + " "); pp.tx(context.formatPhrase(RenderingContext.CONC_MAP_FROM) + " ");
if (grp.hasSource()) { if (grp.hasSource()) {
renderCanonical(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), cm), pp, grp.getSource()); renderCanonical(wrap(cm), pp, grp.getSource());
} else { } else {
pp.code(context.formatPhrase(RenderingContext.CONC_MAP_CODE_SYS_UNSPEC)); pp.code(context.formatPhrase(RenderingContext.CONC_MAP_CODE_SYS_UNSPEC));
} }
pp.tx(" to "); pp.tx(" to ");
if (grp.hasTarget()) { if (grp.hasTarget()) {
renderCanonical(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), cm), pp, grp.getTarget()); renderCanonical(wrap(cm), pp, grp.getTarget());
} else { } else {
pp.code(context.formatPhrase(RenderingContext.CONC_MAP_CODE_SYS_UNSPEC)); 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) { public String displayDataType(DataType type) {
return displayDataType(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), type)); return displayDataType(wrap(type));
} }
public String displayDataType(ResourceElement 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 { public void renderBase(RenderingStatus status, XhtmlNode x, Base b) throws FHIRFormatError, DefinitionException, IOException {
if (b instanceof DataType) { if (b instanceof DataType) {
renderDataType(status, x, new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), (DataType) b)); renderDataType(status, x, wrap((DataType) b));
} else { } else {
x.tx(context.formatPhrase(RenderingContext.DATA_REND_NO_DISP, b.fhirType()) + " "); 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()) { if (prim.hasPrimitiveValue()) {
return false; return false;
} }
@ -1108,7 +1108,7 @@ public class DataRenderer extends Renderer implements CodeResolver {
public String displayCoding(List<Coding> list) { public String displayCoding(List<Coding> list) {
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder(); CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
for (Coding c : list) { for (Coding c : list) {
b.append(displayCoding(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), c))); b.append(displayCoding(wrap(c)));
} }
return b.toString(); return b.toString();
} }
@ -1226,7 +1226,7 @@ public class DataRenderer extends Renderer implements CodeResolver {
} }
public CodeResolution resolveCode(Coding code) { public CodeResolution resolveCode(Coding code) {
return resolveCode(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), code)); return resolveCode(wrap(code));
} }
public CodeResolution resolveCode(CodeableConcept 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) { 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) { 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.FileFormat;
import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.FileFormatOption;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.context.ContextUtilities; import org.hl7.fhir.r5.context.ContextUtilities;
import org.hl7.fhir.r5.model.*; import org.hl7.fhir.r5.model.*;
import org.hl7.fhir.r5.model.ExampleScenario.*; 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.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.RenderingContext.KnownLinkType;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.utilities.xhtml.XhtmlDocument; import org.hl7.fhir.utilities.xhtml.XhtmlDocument;
import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import net.sourceforge.plantuml.SourceStringReader; import net.sourceforge.plantuml.SourceStringReader;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -26,22 +33,36 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
super(context); super(context);
} }
public boolean render(XhtmlNode x, Resource scen) throws IOException { @Override
return render(x, (ExampleScenario) scen); 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, ExampleScenario scen) throws FHIRException { @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 void render(RenderingStatus status, XhtmlNode x, ExampleScenario scen) throws FHIRException {
try { try {
if (context.getScenarioMode() == null) { if (context.getScenarioMode() == null) {
return renderActors(x, scen); renderActors(status, x, scen);
} else { } else {
switch (context.getScenarioMode()) { switch (context.getScenarioMode()) {
case ACTORS: case ACTORS:
return renderActors(x, scen); renderActors(status, x, scen);
break;
case INSTANCES: case INSTANCES:
return renderInstances(x, scen); renderInstances(status, x, scen);
break;
case PROCESSES: case PROCESSES:
return renderProcesses(x, scen); renderProcesses(status, x, scen);
break;
default: default:
throw new FHIRException(context.formatPhrase(RenderingContext.EX_SCEN_UN, context.getScenarioMode()) + " "); throw new FHIRException(context.formatPhrase(RenderingContext.EX_SCEN_UN, context.getScenarioMode()) + " ");
} }
@ -117,7 +138,7 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
String plantUml = ""; String plantUml = "";
if (step.hasWorkflow()) { if (step.hasWorkflow()) {
XhtmlNode n = new XhtmlDocument(); XhtmlNode n = new XhtmlDocument();
renderCanonical(scen, n, step.getWorkflow()); renderCanonical(wrap(scen), n, step.getWorkflow());
XhtmlNode ref = n.getChildNodes().get(0); 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")))); plantUml += noteOver(scen.getActor(), context.formatPhrase(RenderingContext.EXAMPLE_SCEN_STEP_SCEN, trimPrefix(prefix), creolLink((ref.getContent()), ref.getAttribute("href"))));
} else if (step.hasProcess()) } else if (step.hasProcess())
@ -208,7 +229,7 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
return s; 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 tbl = x.table("table-striped table-bordered");
XhtmlNode thead = tbl.tr(); XhtmlNode thead = tbl.tr();
thead.th().addText(context.formatPhrase(RenderingContext.GENERAL_NAME)); thead.th().addText(context.formatPhrase(RenderingContext.GENERAL_NAME));
@ -225,7 +246,7 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
return true; 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 tbl = x.table("table-striped table-bordered");
XhtmlNode thead = tbl.tr(); XhtmlNode thead = tbl.tr();
thead.th().addText(context.formatPhrase(RenderingContext.GENERAL_NAME)); thead.th().addText(context.formatPhrase(RenderingContext.GENERAL_NAME));
@ -256,23 +277,23 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
if (instance.hasStructureVersion()) if (instance.hasStructureVersion())
typeCell.tx((context.formatPhrase(RenderingContext.EX_SCEN_FVER, instance.getStructureVersion()) + " ") + " "); typeCell.tx((context.formatPhrase(RenderingContext.EX_SCEN_FVER, instance.getStructureVersion()) + " ") + " ");
if (instance.hasStructureProfile()) { if (instance.hasStructureProfile()) {
renderCanonical(scen, typeCell, instance.getStructureProfile().toString()); renderCanonical(wrap(scen), typeCell, instance.getStructureProfile().toString());
} else { } 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 { } else {
render(typeCell, instance.getStructureVersionElement()); renderDataType(status, typeCell, wrap(instance.getStructureVersionElement()));
typeCell.tx(" "+(context.formatPhrase(RenderingContext.GENERAL_VER_LOW, instance.getStructureVersion())+" ")); typeCell.tx(" "+(context.formatPhrase(RenderingContext.GENERAL_VER_LOW, instance.getStructureVersion())+" "));
if (instance.hasStructureProfile()) { if (instance.hasStructureProfile()) {
typeCell.tx(" "); typeCell.tx(" ");
renderCanonical(scen, typeCell, instance.getStructureProfile().toString()); renderCanonical(wrap(scen), typeCell, instance.getStructureProfile().toString());
} }
} }
if (instance.hasContent() && instance.getContent().hasReference()) { if (instance.hasContent() && instance.getContent().hasReference()) {
// Force end-user mode to avoid ugly references // Force end-user mode to avoid ugly references
RenderingContext.ResourceRendererMode mode = context.getMode(); RenderingContext.ResourceRendererMode mode = context.getMode();
context.setMode(RenderingContext.ResourceRendererMode.END_USER); 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); context.setMode(mode);
} else } else
row.td(); row.td();
@ -307,7 +328,7 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
// Force end-user mode to avoid ugly references // Force end-user mode to avoid ugly references
RenderingContext.ResourceRendererMode mode = context.getMode(); RenderingContext.ResourceRendererMode mode = context.getMode();
context.setMode(RenderingContext.ResourceRendererMode.END_USER); 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); context.setMode(mode);
} else } else
row.td(); row.td();
@ -319,7 +340,7 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
return true; 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<>(); Map<String, ExampleScenarioActorComponent> actors = new HashMap<>();
for (ExampleScenarioActorComponent actor: scen.getActor()) { for (ExampleScenarioActorComponent actor: scen.getActor()) {
actors.put(actor.getKey(), actor); actors.put(actor.getKey(), actor);
@ -332,13 +353,13 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
int num = 1; int num = 1;
for (ExampleScenarioProcessComponent process : scen.getProcess()) { for (ExampleScenarioProcessComponent process : scen.getProcess()) {
renderProcess(x, process, Integer.toString(num), actors, instances); renderProcess(status, x, process, Integer.toString(num), actors, instances);
num++; num++;
} }
return true; 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(); XhtmlNode div = x.div();
div.an("p_" + prefix); div.an("p_" + prefix);
div.b().tx(context.formatPhrase(RenderingContext.EX_SCEN_PROC, process.getTitle())+" "); 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)); thead.th().addText(context.formatPhrase(RenderingContext.EX_SCEN_RES));
int stepCount = 1; int stepCount = 1;
for (ExampleScenarioProcessStepComponent step: process.getStep()) { 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++; stepCount++;
} }
// Now go through the steps again and spit out any child processes // Now go through the steps again and spit out any child processes
stepCount = 1; stepCount = 1;
for (ExampleScenarioProcessStepComponent step: process.getStep()) { 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++; stepCount++;
} }
} }
@ -384,15 +405,15 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
return stepPrefix(prefix + "-Alt" + Integer.toString(altNum) + ".", step, stepCount); 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()) if (step.hasProcess())
renderProcess(x, step.getProcess(), prefix, actors, instances); renderProcess(status, x, step.getProcess(), prefix, actors, instances);
if (step.hasAlternative()) { if (step.hasAlternative()) {
int altNum = 1; int altNum = 1;
for (ExampleScenarioProcessStepAlternativeComponent alt: step.getAlternative()) { for (ExampleScenarioProcessStepAlternativeComponent alt: step.getAlternative()) {
int stepCount = 1; int stepCount = 1;
for (ExampleScenarioProcessStepComponent altStep: alt.getStep()) { 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++; stepCount++;
} }
altNum++; 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 row = tbl.tr();
XhtmlNode prefixCell = row.td(); XhtmlNode prefixCell = row.td();
prefixCell.an("s_" + stepLabel); prefixCell.an("s_" + stepLabel);
@ -424,7 +445,7 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
name.tx(op.getTitle()); name.tx(op.getTitle());
if (op.hasType()) { if (op.hasType()) {
name.tx(" - "); name.tx(" - ");
renderCoding(name, op.getType()); renderCoding(status, name, wrap(op.getType()));
} }
XhtmlNode descCell = row.td(); XhtmlNode descCell = row.td();
addMarkdown(descCell, op.getDescription()); addMarkdown(descCell, op.getDescription());
@ -443,7 +464,7 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
addMarkdown(altHeading, alt.getDescription()); addMarkdown(altHeading, alt.getDescription());
int stepCount = 1; int stepCount = 1;
for (ExampleScenarioProcessStepComponent subStep : alt.getStep()) { 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++; stepCount++;
} }
altNum++; altNum++;

View File

@ -17,11 +17,10 @@ import org.hl7.fhir.r5.model.Library;
import org.hl7.fhir.r5.model.ParameterDefinition; import org.hl7.fhir.r5.model.ParameterDefinition;
import org.hl7.fhir.r5.model.RelatedArtifact; import org.hl7.fhir.r5.model.RelatedArtifact;
import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper; import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
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.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.Utilities;
import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.hl7.fhir.utilities.xhtml.XhtmlNode;
@ -33,101 +32,100 @@ public class LibraryRenderer extends ResourceRenderer {
super(context); super(context);
} }
public LibraryRenderer(RenderingContext context, ResourceContext rcontext) { @Override
super(context, rcontext); public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
} }
public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException { @Override
return render(x, (Library) dr); public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement lib) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
}
public boolean render(XhtmlNode x, ResourceWrapper lib) throws FHIRFormatError, DefinitionException, IOException { List<ResourceElement> authors = lib.children("author");
PropertyWrapper authors = lib.getChildByName("author"); List<ResourceElement> editors = lib.children("editor");
PropertyWrapper editors = lib.getChildByName("editor"); List<ResourceElement> reviewers = lib.children("reviewer");
PropertyWrapper reviewers = lib.getChildByName("reviewer"); List<ResourceElement> endorsers = lib.children("endorser");
PropertyWrapper endorsers = lib.getChildByName("endorser"); if (!authors.isEmpty() || !editors.isEmpty() || !reviewers.isEmpty() || !endorsers.isEmpty()) {
if ((authors != null && authors.hasValues()) || (editors != null && editors.hasValues()) || (reviewers != null && reviewers.hasValues()) || (endorsers != null && endorsers.hasValues())) {
boolean email = hasCT(authors, "email") || hasCT(editors, "email") || hasCT(reviewers, "email") || hasCT(endorsers, "email"); 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 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"); boolean url = hasCT(authors, "url") || hasCT(editors, "url") || hasCT(reviewers, "url") || hasCT(endorsers, "url");
x.h2().tx(context.formatPhrase(RenderingContext.LIB_REND_PAR)); x.h2().tx(context.formatPhrase(RenderingContext.LIB_REND_PAR));
XhtmlNode t = x.table("grid"); XhtmlNode t = x.table("grid");
if (authors != null) { for (ResourceElement cd : authors) {
for (BaseWrapper cd : authors.getValues()) { participantRow(status, t, (context.formatPhrase(RenderingContext.LIB_REND_AUT)), cd, email, phone, url);
participantRow(t, (context.formatPhrase(RenderingContext.LIB_REND_AUT)), cd, email, phone, url);
}
} }
if (authors != null) {
for (BaseWrapper cd : editors.getValues()) { for (ResourceElement cd : editors) {
participantRow(t, (context.formatPhrase(RenderingContext.LIB_REND_ED)), cd, email, phone, url); participantRow(status, t, (context.formatPhrase(RenderingContext.LIB_REND_ED)), cd, email, phone, url);
}
} }
if (authors != null) { for (ResourceElement cd : reviewers) {
for (BaseWrapper cd : reviewers.getValues()) { participantRow(status, t, (context.formatPhrase(RenderingContext.LIB_REND_REV)), cd, email, phone, url);
participantRow(t, (context.formatPhrase(RenderingContext.LIB_REND_REV)), cd, email, phone, url);
}
} }
if (authors != null) { for (ResourceElement cd : endorsers) {
for (BaseWrapper cd : endorsers.getValues()) { participantRow(status, t, (context.formatPhrase(RenderingContext.LIB_REND_END)), cd, email, phone, url);
participantRow(t, (context.formatPhrase(RenderingContext.LIB_REND_END)), cd, email, phone, url);
}
} }
} }
PropertyWrapper artifacts = lib.getChildByName("relatedArtifact"); List<ResourceElement> artifacts = lib.children("relatedArtifact");
if (artifacts != null && artifacts.hasValues()) { if (!artifacts.isEmpty()) {
x.h2().tx(context.formatPhrase(RenderingContext.LIB_REND_ART)); x.h2().tx(context.formatPhrase(RenderingContext.LIB_REND_ART));
XhtmlNode t = x.table("grid"); XhtmlNode t = x.table("grid");
boolean label = false; boolean label = false;
boolean display = false; boolean display = false;
boolean citation = false; boolean citation = false;
for (BaseWrapper ra : artifacts.getValues()) { for (ResourceElement ra : artifacts) {
label = label || ra.has("label"); label = label || ra.has("label");
display = display || ra.has("display"); display = display || ra.has("display");
citation = citation || ra.has("citation"); citation = citation || ra.has("citation");
} }
for (BaseWrapper ra : artifacts.getValues()) { for (ResourceElement ra : artifacts) {
renderArtifact(t, ra, lib, label, display, citation); renderArtifact(t, ra, lib, label, display, citation);
} }
} }
PropertyWrapper parameters = lib.getChildByName("parameter"); List<ResourceElement> parameters = lib.children("parameter");
if (parameters != null && parameters.hasValues()) { if (!parameters.isEmpty()) {
x.h2().tx(context.formatPhrase(RenderingContext.GENERAL_PARS)); x.h2().tx(context.formatPhrase(RenderingContext.GENERAL_PARS));
XhtmlNode t = x.table("grid"); XhtmlNode t = x.table("grid");
boolean doco = false; boolean doco = false;
for (BaseWrapper p : parameters.getValues()) { for (ResourceElement p : parameters) {
doco = doco || p.has("documentation"); doco = doco || p.has("documentation");
} }
for (BaseWrapper p : parameters.getValues()) { for (ResourceElement p : parameters) {
renderParameter(t, p, doco); renderParameter(t, p, doco);
} }
} }
PropertyWrapper dataRequirements = lib.getChildByName("dataRequirement"); List<ResourceElement> dataRequirements = lib.children("dataRequirement");
if (dataRequirements != null && dataRequirements.hasValues()) { if (!dataRequirements.isEmpty()) {
x.h2().tx(context.formatPhrase(RenderingContext.LIB_REND_REQ)); x.h2().tx(context.formatPhrase(RenderingContext.LIB_REND_REQ));
for (BaseWrapper p : dataRequirements.getValues()) { for (ResourceElement p : dataRequirements) {
renderDataRequirement(x, (DataRequirement) p.getBase()); renderDataRequirement(status, x, p);
} }
} }
PropertyWrapper contents = lib.getChildByName("content"); List<ResourceElement> contents = lib.children("content");
if (contents != null) { if (!contents.isEmpty()) {
x.h2().tx(context.formatPhrase(RenderingContext.LIB_REND_CONT)); x.h2().tx(context.formatPhrase(RenderingContext.LIB_REND_CONT));
boolean isCql = false; boolean isCql = false;
int counter = 0; int counter = 0;
for (BaseWrapper p : contents.getValues()) { for (ResourceElement p : contents) {
Attachment att = (Attachment) p.getBase(); renderAttachment(x, p, isCql, counter, lib.getId());
renderAttachment(x, att, isCql, counter, lib.getId()); isCql = isCql || (p.has("contentType") && p.primitiveValue("contentType").startsWith("text/cql"));
isCql = isCql || (att.hasContentType() && att.getContentType().startsWith("text/cql"));
counter++; counter++;
} }
} }
}
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; return false;
} }
private boolean hasCT(PropertyWrapper prop, String type) throws UnsupportedEncodingException, FHIRException, IOException { private boolean hasContactPoint(List<ResourceElement> list, String type) {
if (prop != null) { for (ResourceElement cd : list) {
for (BaseWrapper cd : prop.getValues()) { for (ResourceElement t : cd.children("telecom")) {
PropertyWrapper telecoms = cd.getChildByName("telecom"); if (type.equals(t.primitiveValue("system"))) {
if (getContactPoint(telecoms, type) != null) {
return true; return true;
} }
} }
@ -135,273 +133,135 @@ public class LibraryRenderer extends ResourceRenderer {
return false; return false;
} }
private boolean hasCT(List<ContactDetail> list, String type) { private ResourceElement getContactPoint(List<ResourceElement> list, String type) {
for (ContactDetail cd : list) { for (ResourceElement cd : list) {
for (ContactPoint t : cd.getTelecom()) { for (ResourceElement t : cd.children("telecom")) {
if (type.equals(t.getSystem().toCode())) { if (type.equals(t.primitiveValue("system"))) {
return true; 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; 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(); XhtmlNode tr = t.tr();
tr.td().tx(label); 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) { if (email) {
renderContactPoint(tr.td(), cd.getEmail()); renderContactPoint(status, tr.td(), getContactPoint(telecoms, "email"));
} }
if (phone) { if (phone) {
renderContactPoint(tr.td(), cd.getPhone()); renderContactPoint(status, tr.td(), getContactPoint(telecoms, "phone"));
} }
if (url) { 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) { private void renderAttachment(XhtmlNode x, ResourceElement att, boolean noShowData, int counter, String baseId) {
return lib.present(); String url = att.primitiveValue("url");
} String title = att.primitiveValue("title");
String ct = att.primitiveValue("contentType");
@Override boolean ref = !att.has("data") && att.has("url");
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();
if (ref) { if (ref) {
XhtmlNode p = x.para(); XhtmlNode p = x.para();
if (att.hasTitle()) { if (att.has("title")) {
p.tx(att.getTitle()); p.tx(title);
p.tx(": "); p.tx(": ");
} }
Resource res = context.getContext().fetchResource(Resource.class, att.getUrl()); Resource res = context.getContext().fetchResource(Resource.class, url);
if (res == null || !res.hasWebPath()) { if (res == null || !res.hasWebPath()) {
p.code().ah(att.getUrl()).tx(att.getUrl()); p.code().ah(url).tx(url);
} else if (res instanceof CanonicalResource) { } else if (res instanceof CanonicalResource) {
p.code().ah(res.getWebPath()).tx(((CanonicalResource) res).present()); p.code().ah(res.getWebPath()).tx(((CanonicalResource) res).present());
} else { } else {
p.code().ah(res.getWebPath()).tx(att.getUrl()); p.code().ah(res.getWebPath()).tx(url);
} }
p.tx(" ("); p.tx(" (");
p.code().tx(att.getContentType()); p.code().tx(ct);
p.tx(lang(att)); p.tx(lang(att));
p.tx(")"); p.tx(")");
} else if (!att.hasData()) { } else if (!att.has("data")) {
XhtmlNode p = x.para(); XhtmlNode p = x.para();
if (att.hasTitle()) { if (att.has("title")) {
p.tx(att.getTitle()); p.tx(title);
p.tx(": "); p.tx(": ");
} }
p.code().tx(context.formatPhrase(RenderingContext.LIB_REND_NOCONT)); p.code().tx(context.formatPhrase(RenderingContext.LIB_REND_NOCONT));
p.tx(" ("); p.tx(" (");
p.code().tx(att.getContentType()); p.code().tx(ct);
p.tx(lang(att)); p.tx(lang(att));
p.tx(")"); p.tx(")");
} else { } else {
String txt = getText(att); byte[] cnt = Base64.decodeBase64(att.primitiveValue("data"));
if (isImage(att.getContentType())) { String txt = getText(cnt);
if (isImage(ct)) {
XhtmlNode p = x.para(); XhtmlNode p = x.para();
if (att.hasTitle()) { if (att.has("title")) {
p.tx(att.getTitle()); p.tx(title);
p.tx(": ("); p.tx(": (");
p.code().tx(att.getContentType()); p.code().tx(ct);
p.tx(lang(att)); p.tx(lang(att));
p.tx(")"); p.tx(")");
} }
else { else {
p.code().tx(att.getContentType()+lang(att)); p.code().tx(ct+lang(att));
} }
if (att.getData().length < LibraryRenderer.DATA_IMG_SIZE_CUTOFF) { if (cnt.length < LibraryRenderer.DATA_IMG_SIZE_CUTOFF) {
x.img("data: "+att.getContentType()+">;base64,"+b64(att.getData()), "data"); x.img("data: "+ct+">;base64,"+b64(cnt), "data");
} else { } 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"); x.img(filename, "data");
} }
} else if (txt != null && !noShowData) { } else if (txt != null && !noShowData) {
XhtmlNode p = x.para(); XhtmlNode p = x.para();
if (att.hasTitle()) { if (att.has("title")) {
p.tx(att.getTitle()); p.tx(title);
p.tx(": ("); p.tx(": (");
p.code().tx(att.getContentType()); p.code().tx(ct);
p.tx(lang(att)); p.tx(lang(att));
p.tx(")"); p.tx(")");
} }
else { 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)) { if (prismCode != null && !tooBig(txt)) {
x.pre().code().setAttribute("class", "language-"+prismCode).tx(txt); x.pre().code().setAttribute("class", "language-"+prismCode).tx(txt);
} else { } else {
@ -409,14 +269,14 @@ public class LibraryRenderer extends ResourceRenderer {
} }
} else { } else {
XhtmlNode p = x.para(); XhtmlNode p = x.para();
if (att.hasTitle()) { if (att.has("title")) {
p.tx(att.getTitle()); p.tx(title);
p.tx(": "); p.tx(": ");
} }
p.code().tx(context.formatPhrase(RenderingContext.LIB_REND_SHOW)); p.code().tx(context.formatPhrase(RenderingContext.LIB_REND_SHOW));
p.code().tx(att.getContentType()); p.code().tx(ct);
p.tx(lang(att)); 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; return imgExtension(contentType) != null;
} }
private String lang(Attachment att) { private String lang(ResourceElement att) {
if (att.hasLanguage()) { if (att.has("language")) {
return ", language = "+describeLang(att.getLanguage()); return ", language = "+describeLang(att.primitiveValue("language"));
} }
return ""; return "";
} }
private String getText(Attachment att) { private String getText( byte[] cnt) {
try { try {
try { try {
String src = new String(att.getData(), "UTF-8"); String src = new String(cnt, "UTF-8");
if (checkString(src)) { if (checkString(src)) {
return src; return src;
} }
@ -464,7 +324,7 @@ public class LibraryRenderer extends ResourceRenderer {
// ignore // ignore
} }
try { try {
String src = new String(att.getData(), "UTF-16"); String src = new String(cnt, "UTF-16");
if (checkString(src)) { if (checkString(src)) {
return src; return src;
} }
@ -472,7 +332,7 @@ public class LibraryRenderer extends ResourceRenderer {
// ignore // ignore
} }
try { try {
String src = new String(att.getData(), "ASCII"); String src = new String(cnt, "ASCII");
if (checkString(src)) { if (checkString(src)) {
return src; return src;
} }
@ -494,9 +354,8 @@ public class LibraryRenderer extends ResourceRenderer {
return true; return true;
} }
private String determinePrismCode(Attachment att) { private String determinePrismCode(String ct) {
if (att.hasContentType()) { if (!Utilities.noString(ct)) {
String ct = att.getContentType();
if (ct.contains(";")) { if (ct.contains(";")) {
ct = ct.substring(0, ct.indexOf(";")); ct = ct.substring(0, ct.indexOf(";"));
} }
@ -524,10 +383,10 @@ public class LibraryRenderer extends ResourceRenderer {
case "application/typescript" : return "typescript"; case "application/typescript" : return "typescript";
case "text/cql" : return "sql"; // not that bad... 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"; return "json";
} }
if (att.getContentType().contains("xml+") || att.getContentType().contains("+xml")) { if (ct.contains("xml+") || ct.contains("+xml")) {
return "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.DataType;
import org.hl7.fhir.r5.model.Reference; import org.hl7.fhir.r5.model.Reference;
import org.hl7.fhir.r5.model.Resource; 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.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.EOperationOutcome;
import org.hl7.fhir.r5.utils.LiquidEngine; import org.hl7.fhir.r5.utils.LiquidEngine;
import org.hl7.fhir.r5.utils.LiquidEngine.ILiquidRenderingSupport; 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 LiquidRenderer extends ResourceRenderer implements ILiquidRenderingSupport {
public class LiquidRendererContxt { private String liquidTemplate;
private ResourceContext rcontext; private class LiquidRendererContext {
private ResourceWrapper resource; private RenderingStatus status;
private ResourceElement resource;
public LiquidRendererContxt(ResourceContext rcontext, ResourceWrapper r) { protected LiquidRendererContext(RenderingStatus status, ResourceElement resource) {
this.rcontext = rcontext; super();
this.resource = r; this.status = status;
} this.resource = resource;
public ResourceWrapper getResource() {
return resource;
} }
} }
private String liquidTemplate;
public LiquidRenderer(RenderingContext context, String liquidTemplate) { public LiquidRenderer(RenderingContext context, String liquidTemplate) {
super(context); super(context);
this.liquidTemplate = liquidTemplate; this.liquidTemplate = liquidTemplate;
} }
public LiquidRenderer(RenderingContext context, ResourceContext rcontext, String liquidTemplate) { @Override
super(context); public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
this.rcontext = rcontext; return canonicalTitle(r);
this.liquidTemplate = liquidTemplate;
} }
/** /**
@ -72,14 +66,14 @@ public class LiquidRenderer extends ResourceRenderer implements ILiquidRendering
} }
@Override @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()); LiquidEngine engine = new LiquidEngine(context.getWorker(), context.getServices());
XhtmlNode xn; XhtmlNode xn;
try { try {
engine.setIncludeResolver(new LiquidRendererIncludeResolver(context)); engine.setIncludeResolver(new LiquidRendererIncludeResolver(context));
engine.setRenderingSupport(this); engine.setRenderingSupport(this);
LiquidDocument doc = engine.parse(liquidTemplate, "template"); 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); xn = new XhtmlParser().parseFragment(html);
if (!x.getName().equals("div")) if (!x.getName().equals("div"))
throw new FHIRException("Error in template: Root element is not '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()); xn.para().b().style("color: maroon").tx("Exception generating Narrative: "+e.getMessage());
} }
x.getChildNodes().addAll(xn.getChildNodes()); x.getChildNodes().addAll(xn.getChildNodes());
return true; status.setExtensions(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;
} }
public RendererType getRendererType() { public RendererType getRendererType() {
@ -133,17 +92,17 @@ public class LiquidRenderer extends ResourceRenderer implements ILiquidRendering
@Override @Override
public String renderForLiquid(Object appContext, Base base) throws FHIRException { public String renderForLiquid(Object appContext, Base base) throws FHIRException {
try { try {
LiquidRendererContext ctxt = (LiquidRendererContext) appContext;
ResourceElement r = null;
if (base instanceof Element) { if (base instanceof Element) {
base = context.getParser().parseType((Element) base); r = new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), (Element) base);
} else if (base instanceof DataType) {
r = new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), (DataType) base);
} else {
return base.toString();
} }
XhtmlNode x = new XhtmlNode(NodeType.Element, "div"); XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
if (base instanceof Reference) { renderDataType(ctxt.status, x, r);
renderReference(((LiquidRendererContxt) appContext).getResource(), x, (Reference) base);
} else if (base instanceof DataType) {
render(x, (DataType) base);
} else {
x.tx(base.toString());
}
String res = new XhtmlComposer(true).compose(x); String res = new XhtmlComposer(true).compose(x);
res = res.substring(5); res = res.substring(5);
if (res.length() < 6) { if (res.length() < 6) {

View File

@ -4,32 +4,46 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError; 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;
import org.hl7.fhir.r5.model.NamingSystem.NamingSystemUniqueIdComponent; import org.hl7.fhir.r5.model.NamingSystem.NamingSystemUniqueIdComponent;
import org.hl7.fhir.r5.model.Resource; 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.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.terminologies.CodeSystemUtilities;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.ToolingExtensions; import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class NamingSystemRenderer extends ResourceRenderer { public class NamingSystemRenderer extends ResourceRenderer {
public NamingSystemRenderer(RenderingContext context) { public NamingSystemRenderer(RenderingContext context) {
super(context); super(context);
} }
public NamingSystemRenderer(RenderingContext context, ResourceContext rcontext) { @Override
super(context, rcontext); 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 { @Override
return render(x, (NamingSystem) dr); public void renderResource(RenderingStatus status, XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
render(status, x, (NamingSystem) r);
} }
public boolean render(XhtmlNode x, NamingSystem ns) throws FHIRFormatError, DefinitionException, IOException { @Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
public void render(RenderingStatus status, XhtmlNode x, NamingSystem ns) throws FHIRFormatError, DefinitionException, IOException {
x.h3().tx(context.formatPhrase(RenderingContext.GENERAL_SUMM)); x.h3().tx(context.formatPhrase(RenderingContext.GENERAL_SUMM));
XhtmlNode tbl = x.table("grid"); XhtmlNode tbl = x.table("grid");
row(tbl, (context.formatPhrase(RenderingContext.GENERAL_DEFINING_URL)), ns.getUrl()); 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()); tr.td().tx(id.getPreferredElement().primitiveValue());
} }
if (hasPeriod) { if (hasPeriod) {
tr.td().tx(display(id.getPeriod())); tr.td().tx(displayDataType(id.getPeriod()));
} }
if (hasComment) { if (hasComment) {
tr.td().tx(id.getComment()); tr.td().tx(id.getComment());
} }
} }
return false;
} }
private XhtmlNode row(XhtmlNode tbl, String name) { private XhtmlNode row(XhtmlNode tbl, String name) {
@ -117,19 +130,4 @@ public class NamingSystemRenderer extends ResourceRenderer {
return ns.present(); 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.model.ValueSet;
import org.hl7.fhir.r5.renderers.CodeResolver.CodeResolution; import org.hl7.fhir.r5.renderers.CodeResolver.CodeResolution;
import org.hl7.fhir.r5.renderers.ObligationsRenderer.ObligationDetail; 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.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.utils.PublicationHacker; import org.hl7.fhir.r5.utils.PublicationHacker;
import org.hl7.fhir.r5.utils.ToolingExtensions; 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.XhtmlNode;
import org.hl7.fhir.utilities.xhtml.XhtmlNodeList; import org.hl7.fhir.utilities.xhtml.XhtmlNodeList;
public class ObligationsRenderer { public class ObligationsRenderer extends Renderer {
public static class ObligationDetail { public static class ObligationDetail {
private List<String> codes = new ArrayList<>(); private List<String> codes = new ArrayList<>();
private List<String> elementIds = new ArrayList<>(); private List<String> elementIds = new ArrayList<>();
@ -167,6 +168,7 @@ public class ObligationsRenderer {
private CodeResolver cr; private CodeResolver cr;
public ObligationsRenderer(String corePath, StructureDefinition profile, String path, RenderingContext context, IMarkdownProcessor md, CodeResolver cr) { public ObligationsRenderer(String corePath, StructureDefinition profile, String path, RenderingContext context, IMarkdownProcessor md, CodeResolver cr) {
super(context);
this.corePath = corePath; this.corePath = corePath;
this.profile = profile; this.profile = profile;
this.path = path; this.path = path;
@ -286,24 +288,24 @@ public class ObligationsRenderer {
return abr; 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()) { if (obligations.isEmpty()) {
return ""; return "";
} else { } else {
XhtmlNode tbl = new XhtmlNode(NodeType.Element, "table"); XhtmlNode tbl = new XhtmlNode(NodeType.Element, "table");
tbl.attribute("class", "grid"); 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); 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()) { if (obligations.isEmpty()) {
return; return;
} else { } else {
Piece piece = gen.new Piece("table").attr("class", "grid"); Piece piece = gen.new Piece("table").attr("class", "grid");
c.getPieces().add(piece); 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 doco = false;
boolean usage = false; boolean usage = false;
boolean actor = false; boolean actor = false;
@ -483,7 +485,7 @@ public class ObligationsRenderer {
XhtmlNode td = tr.td(); XhtmlNode td = tr.td();
for (UsageContext u : ob.usage) { for (UsageContext u : ob.usage) {
if (first) first = false; else td.tx(", "); if (first) first = false; else td.tx(", ");
new DataRenderer(context).render(td, u); new DataRenderer(context).renderDataType(status, td, wrap(u));
} }
} else { } else {
tr.td(); tr.td();

View File

@ -3,9 +3,13 @@ package org.hl7.fhir.r5.renderers;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException; 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.CanonicalType;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.CodeType; 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.Enumeration;
import org.hl7.fhir.r5.model.Enumerations.FHIRTypes; import org.hl7.fhir.r5.model.Enumerations.FHIRTypes;
import org.hl7.fhir.r5.model.Enumerations.VersionIndependentResourceTypesAll; import org.hl7.fhir.r5.model.Enumerations.VersionIndependentResourceTypesAll;
@ -15,9 +19,10 @@ import org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterCom
import org.hl7.fhir.r5.model.OperationDefinition.OperationParameterScope; import org.hl7.fhir.r5.model.OperationDefinition.OperationParameterScope;
import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StructureDefinition; 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.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.RenderingContext.KnownLinkType;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.utils.EOperationOutcome; import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.ToolingExtensions; import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
@ -28,19 +33,27 @@ import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class OperationDefinitionRenderer extends TerminologyRenderer { public class OperationDefinitionRenderer extends TerminologyRenderer {
public OperationDefinitionRenderer(RenderingContext context) { public OperationDefinitionRenderer(RenderingContext context) {
super(context); super(context);
} }
public OperationDefinitionRenderer(RenderingContext context, ResourceContext rcontext) { @Override
super(context, rcontext); public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
throw new Error("OperationDefinitionRenderer only renders native resources directly");
} }
public boolean render(XhtmlNode x, Resource dr) throws IOException, FHIRException, EOperationOutcome { @Override
return render(x, (OperationDefinition) dr); public void renderResource(RenderingStatus status, XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
render(status, x, (OperationDefinition) r);
} }
public boolean render(XhtmlNode x, OperationDefinition opd) throws IOException, FHIRException, EOperationOutcome { @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()) { if (context.isHeader()) {
x.h2().addText(opd.getName()); x.h2().addText(opd.getName());
x.para().addText(Utilities.capitalize(opd.getKind().toString())+": "+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); genOpParam(tbl, "", p, opd);
} }
addMarkdown(x, opd.getComment()); addMarkdown(x, opd.getComment());
return true;
} }
public void describe(XhtmlNode x, OperationDefinition opd) { 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.OperationOutcome.OperationOutcomeIssueComponent;
import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StringType; 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.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.utils.RenderingContext; import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement; 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.EOperationOutcome;
import org.hl7.fhir.r5.utils.ToolingExtensions; import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
@ -41,12 +39,13 @@ public class OperationOutcomeRenderer extends ResourceRenderer {
boolean hasSource = false; boolean hasSource = false;
boolean success = true; boolean success = true;
for (ResourceElement i : op.children("issue")) { for (ResourceElement i : op.children("issue")) {
success = success && i.getSeverity() == IssueSeverity.INFORMATION; success = success && "information".equals(i.primitiveValue("severity"));
hasSource = hasSource || ExtensionHelper.hasExtension(i, ToolingExtensions.EXT_ISSUE_SOURCE); hasSource = hasSource || i.hasExtension(ToolingExtensions.EXT_ISSUE_SOURCE);
} }
if (success) if (success) {
x.para().tx(context.formatPhrase(RenderingContext.OP_OUT_OK)); x.para().tx(context.formatPhrase(RenderingContext.OP_OUT_OK));
if (op.getIssue().size() > 0) { }
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 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(); XhtmlNode tr = tbl.tr();
tr.td().b().tx(context.formatPhrase(RenderingContext.OP_OUT_SEV)); 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_CODE));
tr.td().b().tx(context.formatPhrase(RenderingContext.GENERAL_DETAILS)); tr.td().b().tx(context.formatPhrase(RenderingContext.GENERAL_DETAILS));
tr.td().b().tx(context.formatPhrase(RenderingContext.OP_OUT_DIAG)); tr.td().b().tx(context.formatPhrase(RenderingContext.OP_OUT_DIAG));
if (hasSource) if (hasSource) {
tr.td().b().tx(context.formatPhrase(RenderingContext.OP_OUT_SRC)); tr.td().b().tx(context.formatPhrase(RenderingContext.OP_OUT_SRC));
for (OperationOutcomeIssueComponent i : op.getIssue()) { }
for (ResourceElement i : op.children("issue")) {
tr = tbl.tr(); tr = tbl.tr();
tr.td().addText(i.getSeverity().toString()); tr.td().addText(i.primitiveValue("severity"));
XhtmlNode td = tr.td(); XhtmlNode td = tr.td();
boolean d = false; 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) if (d)
td.tx(", "); td.tx(", ");
else else
d = true; d = true;
td.addText(s.getValue()); td.addText(s.primitiveValue());
} }
tr.td().addText(i.getCode().getDisplay()); tr.td().addText(i.child("code").primitiveValue("display"));
tr.td().addText(display(i.getDetails())); tr.td().addText(i.primitiveValue("details"));
smartAddText(tr.td(), i.getDiagnostics()); smartAddText(tr.td(), i.primitiveValue("diagnostics"));
if (hasSource) { if (hasSource) {
Extension ext = ExtensionHelper.getExtension(i, ToolingExtensions.EXT_ISSUE_SOURCE); ResourceElement ext = i.extension(ToolingExtensions.EXT_ISSUE_SOURCE);
tr.td().addText(ext == null ? "" : display(ext)); tr.td().addText(ext == null || !ext.has("value") ? "" : displayDataType(ext.child("value")));
} }
} }
} }
return true;
} }
public void describe(XhtmlNode x, OperationOutcome oo) { public void describe(XhtmlNode x, OperationOutcome oo) {
@ -89,16 +87,6 @@ public class OperationOutcomeRenderer extends ResourceRenderer {
return (context.formatPhrase(RenderingContext.GENERAL_TODO)); 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) { public static String toString(OperationOutcome oo) {
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder(); CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
for (OperationOutcomeIssueComponent issue : oo.getIssue()) { for (OperationOutcomeIssueComponent issue : oo.getIssue()) {

View File

@ -7,16 +7,9 @@ import java.util.List;
import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError; 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.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.EOperationOutcome;
import org.hl7.fhir.utilities.xhtml.NodeType;
import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class ParametersRenderer extends ResourceRenderer { public class ParametersRenderer extends ResourceRenderer {
@ -25,10 +18,11 @@ public class ParametersRenderer extends ResourceRenderer {
super(context); super(context);
} }
public ParametersRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return "todo";
}
public ParametersRenderer setMultiLangMode(boolean multiLangMode) { public ParametersRenderer setMultiLangMode(boolean multiLangMode) {
this.multiLangMode = multiLangMode; this.multiLangMode = multiLangMode;
@ -36,50 +30,28 @@ public class ParametersRenderer extends ResourceRenderer {
} }
@Override @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)); x.h2().tx(context.formatPhrase(RenderingContext.GENERAL_PARS));
XhtmlNode tbl = x.table("grid"); XhtmlNode tbl = x.table("grid");
params(tbl, ((Parameters) r).getParameter(), 0); params(status, tbl, r.children("parameter"), 0);
return false;
} }
@Override private void params(RenderingStatus status, XhtmlNode tbl, List<ResourceElement> list, int indent) throws FHIRFormatError, DefinitionException, FHIRException, IOException, EOperationOutcome {
public String display(Resource r) throws UnsupportedEncodingException, IOException { for (ResourceElement p : list) {
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) {
XhtmlNode tr = tbl.tr(); XhtmlNode tr = tbl.tr();
XhtmlNode td = tr.td(); XhtmlNode td = tr.td();
for (int i = 0; i < indent; i++) { for (int i = 0; i < indent; i++) {
td.tx(XhtmlNode.NBSP); td.tx(XhtmlNode.NBSP);
} }
if (p.has("name")) { if (p.has("name")) {
td.tx(p.get("name").primitiveValue()); td.tx(p.primitiveValue("name"));
} else { } else {
td.tx("???"); td.tx("???");
} }
if (p.has("value")) { if (p.has("value")) {
renderBase(tr.td(), p.get("value")); renderDataType(status, tr.td(), p.child("value"));
} else if (p.has("resource")) { } else if (p.has("resource")) {
ResourceWrapper rw = p.getChildByName("resource").getAsResource(); ResourceElement rw = p.child("resource");
td = tr.td(); td = tr.td();
XhtmlNode para = td.para(); XhtmlNode para = td.para();
para.tx(rw.fhirType()+"/"+rw.getId()); para.tx(rw.fhirType()+"/"+rw.getId());
@ -89,47 +61,12 @@ public class ParametersRenderer extends ResourceRenderer {
if (x != null) { if (x != null) {
td.addChildren(x); td.addChildren(x);
} else { } else {
ResourceRenderer rr = RendererFactory.factory(rw, context, rcontext); ResourceRenderer rr = RendererFactory.factory(rw, context);
rr.render(td, rw); rr.renderResource(status, td, rw);
} }
} else if (p.has("part")) { } else if (p.has("part")) {
tr.td(); tr.td();
PropertyWrapper pw = getProperty(p, "part"); params(status, tbl, p.children("part"), indent+1);
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);
} }
} }
} }

View File

@ -2,15 +2,14 @@ package org.hl7.fhir.r5.renderers;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.List;
import org.hl7.fhir.r5.model.CodeableConcept; import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.r5.model.Provenance; import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent; import org.hl7.fhir.exceptions.FHIRFormatError;
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.r5.renderers.utils.RenderingContext; 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; import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class ProvenanceRenderer extends ResourceRenderer { public class ProvenanceRenderer extends ResourceRenderer {
@ -19,23 +18,24 @@ public class ProvenanceRenderer extends ResourceRenderer {
super(context); super(context);
} }
public boolean render(XhtmlNode x, Resource prv) throws UnsupportedEncodingException, IOException { @Override
return render(x, (Provenance) prv); public String displayResource(ResourceElement prv) throws UnsupportedEncodingException, IOException {
return (context.formatPhrase(RenderingContext.PROV_FOR, displayReference(prv.firstChild("target")))+" ");
} }
public boolean render(XhtmlNode x, Provenance prv) throws UnsupportedEncodingException, IOException { @Override
boolean hasExtensions = false; public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement prv) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
if (prv.has("target")) {
if (!prv.getTarget().isEmpty()) { List<ResourceElement> tl = prv.children("target");
if (prv.getTarget().size() == 1) { if (tl.size() == 1) {
XhtmlNode p = x.para(); XhtmlNode p = x.para();
p.tx(context.formatPhrase(RenderingContext.PROV_PROV)+" "); p.tx(context.formatPhrase(RenderingContext.PROV_PROV)+" ");
renderReference(prv, p, prv.getTargetFirstRep()); renderReference(status, p, tl.get(0));
} else { } else {
x.para().tx(context.formatPhrase(RenderingContext.PROV_PROVE)+" "); x.para().tx(context.formatPhrase(RenderingContext.PROV_PROVE)+" ");
XhtmlNode ul = x.ul(); XhtmlNode ul = x.ul();
for (Reference ref : prv.getTarget()) { for (ResourceElement ref : tl) {
renderReference(prv, ul.li(), ref); renderReference(status, ul.li(), ref);
} }
} }
} }
@ -43,50 +43,47 @@ public class ProvenanceRenderer extends ResourceRenderer {
x.para().tx(context.formatPhrase(RenderingContext.GENERAL_SUMM)); x.para().tx(context.formatPhrase(RenderingContext.GENERAL_SUMM));
XhtmlNode t = x.table("grid"); XhtmlNode t = x.table("grid");
XhtmlNode tr; XhtmlNode tr;
if (prv.hasOccurred()) { if (prv.has("occurred")) {
tr = t.tr(); tr = t.tr();
tr.td().tx(context.formatPhrase(RenderingContext.PROV_OCC)); tr.td().tx(context.formatPhrase(RenderingContext.PROV_OCC));
if (prv.hasOccurredPeriod()) { renderDataType(status, tr.td(), prv.child("occurred"));
renderPeriod(tr.td(), prv.getOccurredPeriod());
} else {
renderDateTime(tr.td(), prv.getOccurredDateTimeType());
}
} }
if (prv.hasRecorded()) { if (prv.has("recorded")) {
tr = t.tr(); tr = t.tr();
tr.td().tx(context.formatPhrase(RenderingContext.PROV_REC)); 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 = t.tr();
tr.td().tx(context.formatPhrase(RenderingContext.PROV_POL)); tr.td().tx(context.formatPhrase(RenderingContext.PROV_POL));
if (prv.getPolicy().size() == 1) { if (tl.size() == 1) {
renderUri(tr.td(), prv.getPolicy().get(0)); renderDataType(status, tr.td(), tl.get(0));
} else { } else {
XhtmlNode ul = tr.td().ul(); XhtmlNode ul = tr.td().ul();
for (UriType u : prv.getPolicy()) { for (ResourceElement u : tl) {
renderUri(ul.li(), u); renderDataType(status, ul.li(), u);
} }
} }
} }
if (prv.hasLocation()) { if (prv.has("location")) {
tr = t.tr(); tr = t.tr();
tr.td().tx(context.formatPhrase(RenderingContext.GENERAL_LOCATION)); 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 = t.tr();
tr.td().tx(context.formatPhrase(RenderingContext.PROV_ACT)); 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 hasType = false;
boolean hasRole = false; boolean hasRole = false;
boolean hasOnBehalfOf = false; boolean hasOnBehalfOf = false;
for (ProvenanceAgentComponent a : prv.getAgent()) { for (ResourceElement a : prv.children("agent")) {
hasType = hasType || a.hasType(); hasType = hasType || a.has("type");
hasRole = hasRole || a.hasRole(); hasRole = hasRole || a.has("role");
hasOnBehalfOf = hasOnBehalfOf || a.hasOnBehalfOf(); hasOnBehalfOf = hasOnBehalfOf || a.has("onBehalfOf");
} }
x.para().b().tx(context.formatPhrase(RenderingContext.PROV_AGE)); x.para().b().tx(context.formatPhrase(RenderingContext.PROV_AGE));
t = x.table("grid"); t = x.table("grid");
@ -101,37 +98,36 @@ public class ProvenanceRenderer extends ResourceRenderer {
if (hasOnBehalfOf) { if (hasOnBehalfOf) {
tr.td().b().tx(context.formatPhrase(RenderingContext.PROV_BEHALF)); tr.td().b().tx(context.formatPhrase(RenderingContext.PROV_BEHALF));
} }
for (ProvenanceAgentComponent a : prv.getAgent()) { for (ResourceElement a : prv.children("agent")) {
tr = t.tr(); tr = t.tr();
if (hasType) { if (hasType) {
if (a.hasType()) { if (a.has("type")) {
renderCodeableConcept(tr.td(), a.getType(), false); renderDataType(status, tr.td(), a.child("type"));
} else { } else {
tr.td(); tr.td();
} }
} }
if (hasRole) { if (hasRole) {
if (a.hasRole()) { List<ResourceElement> tl = prv.children("role");
if (a.getRole().size() == 1) { if (tl.size() == 0) {
renderCodeableConcept(tr.td(), a.getType(), false);
} else {
XhtmlNode ul = tr.td().ul();
for (CodeableConcept cc : a.getRole()) {
renderCodeableConcept(ul.li(), cc, false);
}
}
} else {
tr.td(); 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()) { if (a.has("who")) {
renderReference(prv, tr.td(), a.getWho()); renderReference(status, tr.td(), a.child("who"));
} else { } else {
tr.td(); tr.td();
} }
if (hasOnBehalfOf) { if (hasOnBehalfOf) {
if (a.hasOnBehalfOf()) { if (a.has("onBehalfOf")) {
renderReference(prv, tr.td(), a.getOnBehalfOf()); renderReference(status, tr.td(), a.child("onBehalfOf"));
} else { } else {
tr.td(); tr.td();
} }
@ -139,20 +135,7 @@ public class ProvenanceRenderer extends ResourceRenderer {
} }
// agent table // 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.comparison.VersionComparisonAnnotation;
import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.model.Base; 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.Enumeration;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.utils.RenderingContext; 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.GenerationRules;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.KnownLinkType; import org.hl7.fhir.r5.renderers.utils.RenderingContext.KnownLinkType;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.ResourceRendererMode; import org.hl7.fhir.r5.renderers.utils.RenderingContext.ResourceRendererMode;
@ -230,4 +233,13 @@ public class Renderer {
public String toStr(Date value) { public String toStr(Date value) {
return value.toString(); 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.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.List;
import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError; import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.ActorDefinition; import org.hl7.fhir.r5.model.ActorDefinition;
import org.hl7.fhir.r5.model.CanonicalResource; import org.hl7.fhir.r5.model.CanonicalResource;
@ -18,9 +20,12 @@ import org.hl7.fhir.r5.model.Requirements.RequirementsStatementComponent;
import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.UrlType; import org.hl7.fhir.r5.model.UrlType;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper; 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.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.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference; 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.Utilities;
import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.hl7.fhir.utilities.xhtml.XhtmlNode;
@ -30,158 +35,158 @@ public class RequirementsRenderer extends ResourceRenderer {
super(context); super(context);
} }
public RequirementsRenderer(RenderingContext context, ResourceContext rcontext) { @Override
super(context, rcontext); public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
} }
public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException { @Override
return render(x, (Requirements) dr); 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");
public boolean render(XhtmlNode x, Requirements req) throws FHIRFormatError, DefinitionException, IOException { if (actors.size() == 1) {
if (req.hasActor()) { ActorDefinition acd = context.getWorker().fetchResource(ActorDefinition.class, actors.get(0).primitiveValue(), req);
if (req.getActor().size() == 1) {
ActorDefinition acd = context.getWorker().fetchResource(ActorDefinition.class, req.getActor().get(0).getValue(), req);
XhtmlNode p = x.para(); XhtmlNode p = x.para();
p.tx(context.formatPhrase(RenderingContext.REQ_ACTOR)+" "); p.tx(context.formatPhrase(RenderingContext.REQ_ACTOR)+" ");
if (acd == null) { if (acd == null) {
p.code(req.getActor().get(0).getValue()); p.code(actors.get(0).primitiveValue());
} else { } else {
p.ah(acd.getWebPath()).tx(acd.present()); p.ah(acd.getWebPath()).tx(acd.present());
} }
} else { } else {
x.para().tx(context.formatPhrase(RenderingContext.REQ_FOLLOWING_ACTOR)+" "); x.para().tx(context.formatPhrase(RenderingContext.REQ_FOLLOWING_ACTOR)+" ");
XhtmlNode ul = x.ul(); XhtmlNode ul = x.ul();
for (CanonicalType a : req.getActor()) { for (ResourceElement a : actors) {
ActorDefinition acd = context.getWorker().fetchResource(ActorDefinition.class, a.getValue(), req); ActorDefinition acd = context.getWorker().fetchResource(ActorDefinition.class, a.primitiveValue(), req);
if (acd == null) { if (acd == null) {
ul.li().code(a.getValue()); ul.li().code(a.primitiveValue());
} else { } else {
ul.li().ah(acd.getWebPath()).tx(acd.present()); ul.li().ah(acd.getWebPath()).tx(acd.present());
} }
} }
} }
} }
if (req.hasDerivedFrom()) { if (req.has("derivedFrom")) {
if (req.getDerivedFrom().size() == 1) { List<ResourceElement> list = req.children("derivedFrom");
Requirements reqd = context.getWorker().fetchResource(Requirements.class, req.getDerivedFrom().get(0).getValue(), req); if (list.size() == 1) {
Requirements reqd = context.getWorker().fetchResource(Requirements.class, list.get(0).primitiveValue(), req);
XhtmlNode p = x.para(); XhtmlNode p = x.para();
p.tx(context.formatPhrase(RenderingContext.REQ_DERIVE)+" "); p.tx(context.formatPhrase(RenderingContext.REQ_DERIVE)+" ");
if (reqd == null) { if (reqd == null) {
p.code(req.getDerivedFrom().get(0).getValue()); p.code(list.get(0).primitiveValue());
} else { } else {
p.ah(reqd.getWebPath()).tx(reqd.present()); p.ah(reqd.getWebPath()).tx(reqd.present());
} }
} else { } else {
x.para().tx(context.formatPhrase(RenderingContext.REQ_FOLLOWING_REQ)+" "); x.para().tx(context.formatPhrase(RenderingContext.REQ_FOLLOWING_REQ)+" ");
XhtmlNode ul = x.ul(); XhtmlNode ul = x.ul();
for (CanonicalType a : req.getDerivedFrom()) { for (ResourceElement a : list) {
Requirements reqd = context.getWorker().fetchResource(Requirements.class, a.getValue(), req); Requirements reqd = context.getWorker().fetchResource(Requirements.class, a.primitiveValue(), req);
if (reqd == null) { if (reqd == null) {
ul.li().code(a.getValue()); ul.li().code(a.primitiveValue());
} else { } else {
ul.li().ah(reqd.getWebPath()).tx(reqd.present()); ul.li().ah(reqd.getWebPath()).tx(reqd.present());
} }
} }
} }
} }
if (req.hasReference()) { if (req.has("reference")) {
XhtmlNode p = x.para(); XhtmlNode p = x.para();
p.tx(context.formatPhrase(RenderingContext.GENERAL_REFS)+" "); p.tx(context.formatPhrase(RenderingContext.GENERAL_REFS)+" ");
int i = 0; int i = 0;
for (UrlType c : req.getReference()) { for (ResourceElement c : req.children("reference")) {
i++; i++;
if (i>1) p.tx(", "); if (i>1) p.tx(", ");
String url = c.getValue(); String url = c.primitiveValue();
if (url.contains("#")) { if (url.contains("#")) {
url = url.substring(0, url.indexOf("#")); url = url.substring(0, url.indexOf("#"));
} }
p.ah(c.getValue()).tx(url); p.ah(c.primitiveValue()).tx(url);
} }
} }
XhtmlNode tbl = x.table("grid"); XhtmlNode tbl = x.table("grid");
for (RequirementsStatementComponent stmt : req.getStatement()) { for (ResourceElement stmt : req.children("statement")) {
XhtmlNode tr = tbl.tr(); 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(); XhtmlNode td = tr.td();
td.b().an(stmt.getKey()); td.b().an(stmt.primitiveValue("key"));
td.tx(lbl); td.tx(lbl);
td = tr.td(); td = tr.td();
boolean first = true; boolean first = true;
CodeSystem cs = context.getWorker().fetchCodeSystem("http://hl7.org/fhir/conformance-expectation"); 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 (first) first = false; else td.tx(", ");
if (cs != null) { 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 { } else {
td.tx(t.asStringValue().toUpperCase()); td.tx(t.primitiveValue().toUpperCase());
} }
} }
td = tr.td(); td = tr.td();
addMarkdown(td, stmt.getRequirement()); addMarkdown(td, stmt.primitiveValue("requirement"));
if (stmt.hasDerivedFrom() || stmt.hasSatisfiedBy() || stmt.hasReference() || stmt.hasSource()) { if (stmt.has("derivedFrom") || stmt.has("satisfiedBy") || stmt.has("reference") || stmt.has("source")) {
td.para().tx(context.formatPhrase(RenderingContext.REQ_LINKS)+" "); td.para().tx(context.formatPhrase(RenderingContext.REQ_LINKS)+" ");
XhtmlNode ul = td.ul(); XhtmlNode ul = td.ul();
if (stmt.hasDerivedFrom()) { if (stmt.has("derivedFrom")) {
XhtmlNode li = ul.li(); XhtmlNode li = ul.li();
li.tx(context.formatPhrase(RenderingContext.REQ_DERIVED)+" "); 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) : ""; String key = url.contains("#") ? url.substring(url.indexOf("#")+1) : "";
if (url.contains("#")) { url = url.substring(0, url.indexOf("#")); }; if (url.contains("#")) { url = url.substring(0, url.indexOf("#")); };
Requirements reqr = context.getWorker().fetchResource(Requirements.class, url, req); Requirements reqr = context.getWorker().fetchResource(Requirements.class, url, req);
if (reqr != null) { if (reqr != null) {
RequirementsStatementComponent stmtr = reqr.findStatement(key); RequirementsStatementComponent stmtr = reqr.findStatement(key);
if (stmtr != null) { 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 { } else {
li.ah(reqr.getWebPath()+"#"+key).tx(reqr.present()+" # "+key); li.ah(reqr.getWebPath()+"#"+key).tx(reqr.present()+" # "+key);
} }
} else { } else {
li.code(stmt.getDerivedFrom()); li.code(stmt.primitiveValue("derivedFrom"));
} }
} }
if (stmt.hasSatisfiedBy()) { if (stmt.has("satisfiedBy")) {
XhtmlNode li = ul.li(); XhtmlNode li = ul.li();
li.tx(context.formatPhrase(RenderingContext.REQ_SATISFIED)+" "); li.tx(context.formatPhrase(RenderingContext.REQ_SATISFIED)+" ");
first = true; first = true;
for (UrlType c : stmt.getSatisfiedBy()) { for (ResourceElement c : stmt.children("satisfiedBy")) {
if (first) first = false; else li.tx(", "); if (first) first = false; else li.tx(", ");
String url = c.getValue(); String url = c.primitiveValue();
if (url.contains("#")) { if (url.contains("#")) {
url = url.substring(0, url.indexOf("#")); url = url.substring(0, url.indexOf("#"));
} }
Resource r = context.getWorker().fetchResource(Resource.class, url, req); Resource r = context.getWorker().fetchResource(Resource.class, url, req);
if (r != null) { if (r != null) {
String desc = getResourceDescription(r, null); String desc = getResourceDescription(r, null);
li.ah(c.getValue()).tx(desc); li.ah(c.primitiveValue()).tx(desc);
} else { } else {
li.ah(c.getValue()).tx(url); li.ah(c.primitiveValue()).tx(url);
} }
} }
} }
if (stmt.hasReference()) { if (stmt.has("reference")) {
XhtmlNode li = ul.li(); XhtmlNode li = ul.li();
li.tx(context.formatPhrase(RenderingContext.GENERAL_REFS)+" "); li.tx(context.formatPhrase(RenderingContext.GENERAL_REFS)+" ");
int i = 0; int i = 0;
for (UrlType c : stmt.getReference()) { for (ResourceElement c : stmt.children("reference")) {
i++; i++;
if (i>1) li.tx(", "); if (i>1) li.tx(", ");
String url = c.getValue(); String url = c.primitiveValue();
if (url.contains("#")) { if (url.contains("#")) {
url = url.substring(0, url.indexOf("#")); 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(); XhtmlNode li = ul.li();
li.tx(context.formatPhrase(RenderingContext.GENERAL_SRC)+" "); li.tx(context.formatPhrase(RenderingContext.GENERAL_SRC)+" ");
first = true; first = true;
for (Reference c : stmt.getSource()) { for (ResourceElement c : stmt.children("source")) {
if (first) first = false; else li.tx(", "); if (first) first = false; else li.tx(", ");
if (c.hasReference()) { if (c.has("reference")) {
String url = c.getReference(); String url = c.primitiveValue("reference");
if (url.contains("#")) { if (url.contains("#")) {
url = url.substring(0, url.indexOf("#")); url = url.substring(0, url.indexOf("#"));
} }
@ -191,16 +196,16 @@ public class RequirementsRenderer extends ResourceRenderer {
t = context.getResolver().resolve(context, url); t = context.getResolver().resolve(context, url);
} }
if (r != null) { if (r != null) {
String desc = getResourceDescription(r, c.getDisplay()); String desc = getResourceDescription(r, c.primitiveValue("display"));
li.ah(c.getReference()).tx(desc); li.ah(c.primitiveValue("reference")).tx(desc);
} else if (t != null) { } else if (t != null) {
String desc = getResourceDescription(t, c.getDisplay()); String desc = getResourceDescription(t, c.primitiveValue("display"));
li.ah(t.getReference()).tx(desc); li.ah(t.getReference()).tx(desc);
} else { } else {
li.ah(c.getReference()).tx(url); li.ah(c.primitiveValue("reference")).tx(url);
} }
} else if (c.hasDisplay()) { } else if (c.has("display")) {
li.tx(c.getDisplay()); li.tx(c.primitiveValue("display"));
} else { } else {
li.tx("??"); li.tx("??");
} }
@ -208,7 +213,6 @@ public class RequirementsRenderer extends ResourceRenderer {
} }
} }
} }
return false;
} }
private String getResourceDescription(ResourceWithReference res, String display) throws UnsupportedEncodingException, IOException { private String getResourceDescription(ResourceWithReference res, String display) throws UnsupportedEncodingException, IOException {
@ -236,17 +240,4 @@ public class RequirementsRenderer extends ResourceRenderer {
return lib.present(); 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 // 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 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 { 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; public abstract String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException;
@ -209,6 +209,12 @@ public abstract class ResourceRenderer extends DataRenderer {
x.addTag(0, "hr"); 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 { public void renderCanonical(ResourceElement res, XhtmlNode x, String url) throws UnsupportedEncodingException, IOException {
renderCanonical(res, x, url, true, res); renderCanonical(res, x, url, true, res);
} }
@ -299,7 +305,7 @@ public abstract class ResourceRenderer extends DataRenderer {
String link = null; String link = null;
StringBuilder text = new StringBuilder(); StringBuilder text = new StringBuilder();
if (r.hasReferenceElement() && allowLinks) { 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 (!r.getReference().startsWith("#")) {
if (tr != null && tr.getReference() != null) { if (tr != null && tr.getReference() != null) {
@ -322,7 +328,7 @@ public abstract class ResourceRenderer extends DataRenderer {
if (!Utilities.noString(r.getReference())) { if (!Utilities.noString(r.getReference())) {
text.append(r.getReference()); text.append(r.getReference());
} else if (r.hasIdentifier()) { } else if (r.hasIdentifier()) {
text.append(displayIdentifier(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), r.getIdentifier()))); text.append(displayIdentifier(wrap(r.getIdentifier())));
} else { } else {
text.append("??"); text.append("??");
} }

View File

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

View File

@ -9,20 +9,23 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException; 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.CodeSystem;
import org.hl7.fhir.r5.model.CodeType;
import org.hl7.fhir.r5.model.ConceptMap; 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.Enumeration;
import org.hl7.fhir.r5.model.IdType;
import org.hl7.fhir.r5.model.Enumerations.ConceptMapRelationship; import org.hl7.fhir.r5.model.Enumerations.ConceptMapRelationship;
import org.hl7.fhir.r5.model.Enumerations.SearchComparator; import org.hl7.fhir.r5.model.IdType;
import org.hl7.fhir.r5.model.Enumerations.SearchModifierCode;
import org.hl7.fhir.r5.model.Enumerations.VersionIndependentResourceTypesAll;
import org.hl7.fhir.r5.model.OperationDefinition; import org.hl7.fhir.r5.model.OperationDefinition;
import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.SearchParameter; import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.model.SearchParameter.SearchParameterComponentComponent; 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.StructureMapGroupComponent;
import org.hl7.fhir.r5.model.StructureMap.StructureMapGroupInputComponent; import org.hl7.fhir.r5.model.StructureMap.StructureMapGroupInputComponent;
import org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleComponent; 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.StructureMapStructureComponent;
import org.hl7.fhir.r5.model.StructureMap.StructureMapTargetListMode; import org.hl7.fhir.r5.model.StructureMap.StructureMapTargetListMode;
import org.hl7.fhir.r5.model.StructureMap.StructureMapTransform; 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.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;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.KnownLinkType; 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.EOperationOutcome;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities; 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.Utilities;
import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.xhtml.XhtmlFluent;
import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class StructureMapRenderer extends TerminologyRenderer { 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_COMMENT = "green";
private static final String COLOR_METADATA = "#cc00cc"; private static final String COLOR_METADATA = "#cc00cc";
private static final String COLOR_CONST = "blue"; 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 boolean MULTIPLE_TARGETS_ONELINE = true;
private static final String COLOR_SPECIAL = "#b36b00"; private static final String COLOR_SPECIAL = "#b36b00";
public StructureMapRenderer(RenderingContext context) { public void renderMap(RenderingStatus status, XhtmlNode x, StructureMap map) {
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) {
x.tx("\r\n"); x.tx("\r\n");
if (VersionUtilities.isR5Plus(context.getContext().getVersion())) { if (VersionUtilities.isR5Plus(context.getContext().getVersion())) {
renderMetadata(x, "url", map.getUrlElement()); renderMetadata(x, "url", map.getUrlElement());

View File

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