Bundle rendering improvements

This commit is contained in:
Grahame Grieve 2022-08-09 20:19:20 +10:00
parent 21b6fb5e7c
commit 61a39b60bb
4 changed files with 120 additions and 45 deletions

View File

@ -66,6 +66,7 @@ import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.utils.DOMWrappers.BaseWrapperElement;
import org.hl7.fhir.r5.renderers.utils.DOMWrappers.ResourceWrapperElement;
import org.hl7.fhir.r5.renderers.utils.DirectWrappers;
import org.hl7.fhir.r5.renderers.utils.ElementWrappers;
import org.hl7.fhir.r5.renderers.utils.DirectWrappers.BaseWrapperDirect;
import org.hl7.fhir.r5.renderers.utils.DirectWrappers.PropertyWrapperDirect;
import org.hl7.fhir.r5.renderers.utils.DirectWrappers.ResourceWrapperDirect;
@ -106,7 +107,10 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
if (context.isAddGeneratedNarrativeHeader()) {
x.para().b().tx("Generated Narrative: "+r.fhirType());
}
if (context.isTechnicalMode()) {
if (!Utilities.noString(r.getId())) {
x.an(r.getId());
}
if (context.isTechnicalMode() && !context.isContained()) {
renderResourceHeader(r, x);
}
try {
@ -395,9 +399,17 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
if (rw == null) {
renderReference(res, x, r);
} else {
String ref = context.getResolver().urlForContained(context, res.fhirType(), res.getId(), rw.fhirType(), rw.getId());
if (ref == null) {
x.an(rw.getId());
ResourceRenderer rr = RendererFactory.factory(rw, context.copy().setAddGeneratedNarrativeHeader(false));
RenderingContext ctxtc = context.copy();
ctxtc.setAddGeneratedNarrativeHeader(false);
ctxtc.setContained(true);
ResourceRenderer rr = RendererFactory.factory(rw, ctxtc);
rr.render(parent.blockquote(), rw);
} else {
x.ah(ref).tx("See "+rw.fhirType());
}
}
}
} else {
@ -687,10 +699,14 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
boolean showCodeDetails, int indent, PropertyWrapper p, ElementDefinition child) throws UnsupportedEncodingException, IOException, EOperationOutcome {
Map<String, String> displayHints = readDisplayHints(child);
if ("DomainResource.contained".equals(child.getBase().getPath())) {
// if (p.getValues().size() > 0 && child != null) {
System.out.print("-");
// for (BaseWrapper v : p.getValues()) {
// x.an(v.get("id").primitiveValue());
// }
// x.hr();
// RenderingContext ctxt = context.clone();
// ctxt.setContained(true);
// ResourceRenderer rnd = RendererFactory.factory(v.fhirType(), ctxt);
// ResourceWrapper rw = new ElementWrappers.ResourceWrapperMetaElement(ctxt, (org.hl7.fhir.r5.elementmodel.Element) v.getBase());
// rnd.render(x.blockquote(), rw);
// }
} else if (!exemptFromRendering(child)) {
if (isExtension(p)) {

View File

@ -105,6 +105,7 @@ public class RenderingContext {
private boolean canonicalUrlsAsLinks;
private boolean pretty;
private boolean header;
private boolean contained;
private ValidationOptions terminologyServiceOptions = new ValidationOptions();
private boolean noSlowLookup;
@ -153,11 +154,53 @@ public class RenderingContext {
this.locale = new Locale.Builder().setLanguageTag("en-US").build();
profileUtilities = new ProfileUtilities(worker, null, null);
}
public RenderingContext copy() {
RenderingContext res = new RenderingContext(worker, markdown, terminologyServiceOptions, specificationLink, localPrefix, lang, mode);
res.resolver = resolver;
res.templateProvider = templateProvider;
res.services = services;
res.parser = parser;
res.headerLevelContext = headerLevelContext;
res.canonicalUrlsAsLinks = canonicalUrlsAsLinks;
res.pretty = pretty;
res.contained = contained;
res.noSlowLookup = noSlowLookup;
res.tooCostlyNoteEmpty = tooCostlyNoteEmpty;
res.tooCostlyNoteNotEmpty = tooCostlyNoteNotEmpty;
res.tooCostlyNoteEmptyDependent = tooCostlyNoteEmptyDependent;
res.tooCostlyNoteNotEmptyDependent = tooCostlyNoteNotEmptyDependent;
res.codeSystemPropList.addAll(codeSystemPropList);
res.profileUtilities = profileUtilities;
res.definitionsTarget = definitionsTarget;
res.destDir = destDir;
res.addGeneratedNarrativeHeader = addGeneratedNarrativeHeader;
res.questionnaireMode = questionnaireMode;
res.header = header;
res.selfLink = selfLink;
res.inlineGraphics = inlineGraphics;
res.timeZoneId = timeZoneId;
res.dateTimeFormat = dateTimeFormat;
res.dateFormat = dateFormat;
res.dateYearFormat = dateYearFormat;
res.dateYearMonthFormat = dateYearMonthFormat;
res.targetVersion = targetVersion;
res.locale = locale;
res.terminologyServiceOptions = terminologyServiceOptions.copy();
return res;
}
public IWorkerContext getContext() {
return worker;
}
// -- 2. Markdown support -------------------------------------------------------
public ProfileUtilities getProfileUtilities() {
@ -338,41 +381,6 @@ public class RenderingContext {
return this;
}
public RenderingContext copy() {
RenderingContext res = new RenderingContext(worker, markdown, terminologyServiceOptions, specificationLink, localPrefix, lang, mode);
res.resolver = resolver;
res.templateProvider = templateProvider;
res.services = services;
res.parser = parser;
res.headerLevelContext = headerLevelContext;
res.canonicalUrlsAsLinks = canonicalUrlsAsLinks;
res.pretty = pretty;
res.noSlowLookup = noSlowLookup;
res.tooCostlyNoteEmpty = tooCostlyNoteEmpty;
res.tooCostlyNoteNotEmpty = tooCostlyNoteNotEmpty;
res.tooCostlyNoteEmptyDependent = tooCostlyNoteEmptyDependent;
res.tooCostlyNoteNotEmptyDependent = tooCostlyNoteNotEmptyDependent;
res.codeSystemPropList.addAll(codeSystemPropList);
res.profileUtilities = profileUtilities;
res.definitionsTarget = definitionsTarget;
res.destDir = destDir;
res.addGeneratedNarrativeHeader = addGeneratedNarrativeHeader;
res.questionnaireMode = questionnaireMode;
res.header = header;
res.selfLink = selfLink;
res.inlineGraphics = inlineGraphics;
res.timeZoneId = timeZoneId;
res.dateTimeFormat = dateTimeFormat;
res.dateFormat = dateFormat;
res.dateYearFormat = dateYearFormat;
res.dateYearMonthFormat = dateYearMonthFormat;
return res;
}
public boolean isInlineGraphics() {
return inlineGraphics;
@ -557,5 +565,13 @@ public class RenderingContext {
this.mode = mode;
}
public boolean isContained() {
return contained;
}
public void setContained(boolean contained) {
this.contained = contained;
}
}

View File

@ -18,6 +18,9 @@ public class Resolver {
public interface IReferenceResolver {
ResourceWithReference resolve(RenderingContext context, String url);
// returns null if contained resource is inlined
String urlForContained(RenderingContext context, String containingType, String containingId, String containedType, String containedId);
}
public static class ResourceContext {

View File

@ -0,0 +1,40 @@
package org.hl7.fhir.r5.utils;
import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy;
import org.hl7.fhir.r5.context.IWorkerContext.PackageVersion;
public class PackageHackerR5 {
public static void fixLoadedResource(CanonicalResourceProxy r, PackageVersion packageInfo) {
if ("http://terminology.hl7.org/CodeSystem/v2-0391|2.6".equals(r.getUrl())) {
r.hack("http://terminology.hl7.org/CodeSystem/v2-0391-2.6", "2.6");
}
if ("http://terminology.hl7.org/CodeSystem/v2-0391|2.4".equals(r.getUrl())) {
r.hack("http://terminology.hl7.org/CodeSystem/v2-0391-2.4", "2.4");
}
if ("http://terminology.hl7.org/CodeSystem/v2-0360|2.7".equals(r.getUrl())) {
r.hack("http://terminology.hl7.org/CodeSystem/v2-0360-2.7", "2.7");
}
if ("http://terminology.hl7.org/CodeSystem/v2-0006|2.1".equals(r.getUrl())) {
r.hack("http://terminology.hl7.org/CodeSystem/v2-0006-2.1", "2.1");
}
if ("http://terminology.hl7.org/CodeSystem/v2-0360|2.7".equals(r.getUrl())) {
r.hack("http://terminology.hl7.org/CodeSystem/v2-0360-2.7", "2.7");
}
if ("http://terminology.hl7.org/CodeSystem/v2-0006|2.4".equals(r.getUrl())) {
r.hack("http://terminology.hl7.org/CodeSystem/v2-0006-2.4", "2.4");
}
if ("http://terminology.hl7.org/CodeSystem/v2-0360|2.3.1".equals(r.getUrl())) {
r.hack("http://terminology.hl7.org/CodeSystem/v2-0360-2.3.1", "2.3.1");
}
if (r.hasUrl() && r.getUrl().contains("|")) {
assert false;
}
}
}