From 3eda8580fc9165cb1c257d71b3cccf564323ba17 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 21 Feb 2023 16:46:02 +1100 Subject: [PATCH] fix rendering for conditional references --- .../hl7/fhir/r5/context/ContextUtilities.java | 32 +++++++++++++++---- .../fhir/r5/renderers/ResourceRenderer.java | 9 ++++-- .../hl7/fhir/utilities/xhtml/XhtmlFluent.java | 4 ++- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/ContextUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/ContextUtilities.java index 581a19363..b5e16816f 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/ContextUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/ContextUtilities.java @@ -43,6 +43,8 @@ public class ContextUtilities implements ProfileKnowledgeProvider { private XVerExtensionManager xverManager; private Map oidCache = new HashMap<>(); private List allStructuresList = new ArrayList(); + private List canonicalResourceNames; + private List concreteResourceNames; public ContextUtilities(IWorkerContext context) { super(); @@ -197,15 +199,19 @@ public class ContextUtilities implements ProfileKnowledgeProvider { * @return a list of the resource names that are canonical resources defined for this version */ public List getCanonicalResourceNames() { - List names = new ArrayList<>(); - for (StructureDefinition sd : allStructures()) { - if (sd.getKind() == StructureDefinitionKind.RESOURCE && !sd.getAbstract() && hasUrlProperty(sd)) { - names.add(sd.getType()); + if (canonicalResourceNames == null) { + canonicalResourceNames = new ArrayList<>(); + Set names = new HashSet<>(); + for (StructureDefinition sd : allStructures()) { + if (sd.getKind() == StructureDefinitionKind.RESOURCE && !sd.getAbstract() && hasUrlProperty(sd)) { + names.add(sd.getType()); + } } + canonicalResourceNames.addAll(Utilities.sorted(names)); } - return names; + return canonicalResourceNames; } - + /** * @return a list of all structure definitions, with snapshots generated (if possible) */ @@ -370,5 +376,19 @@ public class ContextUtilities implements ProfileKnowledgeProvider { return null; } + public List getConcreteResources() { + if (concreteResourceNames == null) { + concreteResourceNames = new ArrayList<>(); + Set names = new HashSet<>(); + for (StructureDefinition sd : allStructures()) { + if (sd.getKind() == StructureDefinitionKind.RESOURCE && !sd.getAbstract()) { + names.add(sd.getType()); + } + } + concreteResourceNames.addAll(Utilities.sorted(names)); + } + return concreteResourceNames; + } + } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ResourceRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ResourceRenderer.java index c9d57ba5d..e848bcff6 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ResourceRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ResourceRenderer.java @@ -223,12 +223,15 @@ public abstract class ResourceRenderer extends DataRenderer { tr = resolveReference(rw, r.getReference()); if (!r.getReference().startsWith("#")) { - if (tr != null && tr.getReference() != null) + if (tr != null && tr.getReference() != null) { c = x.ah(tr.getReference()); - else + } else if (r.getReference().contains("?")) { + x.tx("Conditional Reference: "); + c = x.code(""); + } else { c = x.ah(r.getReference()); + } } else { - c = x.ah(r.getReference()); } } else { diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlFluent.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlFluent.java index 93f1158d0..75a9b456f 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlFluent.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlFluent.java @@ -150,7 +150,9 @@ public abstract class XhtmlFluent { public XhtmlNode code(String text) { - return addTag("code").tx(text); + XhtmlNode code = addTag("code"); + code.tx(text); + return code; } public XhtmlNode code() {