From 749b073de167fc9f52ad223fcc7617bbfa338469 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 27 Jun 2024 07:03:54 +1000 Subject: [PATCH] Obligation rendering improvements --- RELEASE_NOTES.md | 1 + .../org/hl7/fhir/r5/model/CanonicalType.java | 12 ++++++++ .../r5/renderers/ObligationsRenderer.java | 29 ++++++++++++------- .../hl7/fhir/r5/utils/ToolingExtensions.java | 1 + 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 0c742c450..fbb99bace 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -15,6 +15,7 @@ * don't raise needless and wrong exceptions about extension definitions when rendering * fix duplicate link creation * Stop recursive rendering crash + * Obligation rendering improvements * Handle extra profiles on resources in an IG when converting between versions * Fixed issue with actor title not rendering in obligations * Test and adaption for dateOp #1655 diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/CanonicalType.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/CanonicalType.java index d4290d695..a68df031f 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/CanonicalType.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/CanonicalType.java @@ -33,6 +33,8 @@ package org.hl7.fhir.r5.model; import java.net.URI; +import org.hl7.fhir.r5.utils.ToolingExtensions; + import ca.uhn.fhir.model.api.annotation.DatatypeDef; /** @@ -87,6 +89,16 @@ public class CanonicalType extends UriType { var s = primitiveValue(); return s == null || !s.contains("|") ? null : s.substring(s.indexOf("|")+1); } + + public String getCanonical() { + if (hasPrimitiveValue()) { + return primitiveValue(); + } + if (hasExtension(ToolingExtensions.EXT_ALTERNATE_CANONICAL)) { + return getExtensionString(ToolingExtensions.EXT_ALTERNATE_CANONICAL); + } + return null; + } } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ObligationsRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ObligationsRenderer.java index f3661b4b1..f5763c5fa 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ObligationsRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ObligationsRenderer.java @@ -19,6 +19,7 @@ import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.renderers.CodeResolver.CodeResolution; import org.hl7.fhir.r5.renderers.utils.RenderingContext; import org.hl7.fhir.r5.renderers.utils.ResourceWrapper; +import org.hl7.fhir.utilities.DebugUtilities; import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator; import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell; import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece; @@ -406,7 +407,7 @@ public class ObligationsRenderer extends Renderer { if (!ob.actors.isEmpty() || ob.compare.actors.isEmpty()) { boolean firstActor = true; for (CanonicalType anActor : ob.actors) { - ActorDefinition ad = context.getContext().fetchResource(ActorDefinition.class, anActor.getValue()); + ActorDefinition ad = context.getContext().fetchResource(ActorDefinition.class, anActor.getCanonical()); boolean existingActor = ob.compare != null && ob.compare.actors.contains(anActor); if (!firstActor) { @@ -416,7 +417,11 @@ public class ObligationsRenderer extends Renderer { if (!existingActor) actorId.style(STYLE_UNCHANGED); - actorId.addText(ad.getTitle()); + if (ad == null) { + actorId.addText(anActor.getCanonical()); + } else { + actorId.ah(ad.getWebPath()).tx(ad.getTitle()); + } } if (ob.compare != null) { @@ -428,7 +433,9 @@ public class ObligationsRenderer extends Renderer { firstActor = true; } actorId = actorId.span(STYLE_REMOVED, null); - if (compAd.hasWebPath()) { + if (compAd == null) { + actorId.ah(context.prefixLocalHref(compActor.toString()), compActor.toString()).tx(compActor.toString()); + } else if (compAd.hasWebPath()) { actorId.ah(context.prefixLocalHref(compAd.getWebPath()), compActor.toString()).tx(compAd.present()); } else { actorId.span(null, compActor.toString()).tx(compAd.present()); @@ -446,13 +453,15 @@ public class ObligationsRenderer extends Renderer { for (String eid : ob.elementIds) { elementIds.sep(", "); ElementDefinition ed = profile.getSnapshot().getElementById(eid); - boolean inScope = inScopePaths.contains(ed.getPath()); - String name = eid.substring(eid.indexOf(".") + 1); - if (ed != null && inScope) { - String link = defPath + "#" + anchorPrefix + eid; - elementIds.ah(context.prefixLocalHref(link)).tx(name); - } else { - elementIds.code().tx(name); + if (ed != null) { + boolean inScope = inScopePaths.contains(ed.getPath()); + String name = eid.substring(eid.indexOf(".") + 1); + if (ed != null && inScope) { + String link = defPath + "#" + anchorPrefix + eid; + elementIds.ah(context.prefixLocalHref(link)).tx(name); + } else { + elementIds.code().tx(name); + } } } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/ToolingExtensions.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/ToolingExtensions.java index 242798cf4..d4c845bcf 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/ToolingExtensions.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/ToolingExtensions.java @@ -274,6 +274,7 @@ public class ToolingExtensions { public static final String EXT_IG_URL = "http://hl7.org/fhir/tools/StructureDefinition/implementationguide-resource-uri"; public static final String EXT_VS_CS_SUPPL_NEEDED = "http://hl7.org/fhir/StructureDefinition/valueset-supplement"; public static final String EXT_TYPE_PARAMETER = "http://hl7.org/fhir/tools/StructureDefinition/type-parameter"; + public static final String EXT_ALTERNATE_CANONICAL = "http://hl7.org/fhir/StructureDefinition/alternate-canonical"; // specific extension helpers