From 80ca7e31f9d1cde3be9c10f415972ffdb747dbf1 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 11 Aug 2022 19:16:49 +1000 Subject: [PATCH] Improvements to SearchParameterRenderer --- .../r5/renderers/SearchParameterRenderer.java | 51 ++++++++++++++----- .../hl7/fhir/r5/utils/ToolingExtensions.java | 1 + .../org/hl7/fhir/utilities/Utilities.java | 8 +++ 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/SearchParameterRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/SearchParameterRenderer.java index 6c96a64a1..b93c31767 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/SearchParameterRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/SearchParameterRenderer.java @@ -2,6 +2,7 @@ package org.hl7.fhir.r5.renderers; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.util.List; import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.FHIRException; @@ -37,7 +38,7 @@ public class SearchParameterRenderer extends TerminologyRenderer { } public boolean render(XhtmlNode x, Resource dr) throws IOException, FHIRException, EOperationOutcome { - return render(x, (OperationDefinition) dr); + return render(x, (SearchParameter) dr); } public boolean render(XhtmlNode x, SearchParameter spd) throws IOException, FHIRException, EOperationOutcome { @@ -56,7 +57,7 @@ public class SearchParameterRenderer extends TerminologyRenderer { for (CodeType t : spd.getBase()) { StructureDefinition sd = context.getWorker().fetchTypeDefinition(t.toString()); if (sd != null && sd.hasUserData("path")) { - td.sep(", ").ah(sd.getUserString("path")).tx(t.getCode()); + td.ah(sd.getUserString("path")).sep(", ").tx(t.getCode()); } else { td.sep(", ").tx(t.getCode()); } @@ -82,12 +83,18 @@ public class SearchParameterRenderer extends TerminologyRenderer { tr = tbl.tr(); tr.td().tx(Utilities.pluralize("Target Resources", spd.getTarget().size())); td = tr.td(); - for (CodeType t : spd.getTarget()) { - StructureDefinition sd = context.getWorker().fetchTypeDefinition(t.toString()); - if (sd != null && sd.hasUserData("path")) { - td.sep(", ").ah(sd.getUserString("path")).tx(t.getCode()); - } else { - td.sep(", ").tx(t.getCode()); + if (isAllConcreteResources(spd.getTarget())) { + td.ah(Utilities.pathURL(context.getSpecificationLink(), "resourcelist.html")).tx("All Resources"); + } else { + for (CodeType t : spd.getTarget()) { + StructureDefinition sd = context.getWorker().fetchTypeDefinition(t.toString()); + if (sd != null && sd.hasUserData("path")) { + td.sep(", "); + td.ah(sd.getUserString("path")).tx(t.getCode()); + } else { + td.sep(", "); + td.tx(t.getCode()); + } } } } @@ -105,9 +112,11 @@ public class SearchParameterRenderer extends TerminologyRenderer { if (spd.hasComparator()) { tr = tbl.tr(); tr.td().tx("Comparators"); - td = tr.td().tx("Allowed: "); + td = tr.td(); + td.tx("Allowed: "); for (Enumeration t : spd.getComparator()) { - td.sep(", ").tx(t.asStringValue()); + td.sep(", "); + td.tx(t.asStringValue()); } } if (spd.hasModifier()) { @@ -115,7 +124,8 @@ public class SearchParameterRenderer extends TerminologyRenderer { tr.td().tx("Modifiers"); td = tr.td().tx("Allowed: "); for (Enumeration t : spd.getModifier()) { - td.sep(", ").tx(t.asStringValue()); + td.sep(", "); + td.tx(t.asStringValue()); } } if (spd.hasChain()) { @@ -123,7 +133,8 @@ public class SearchParameterRenderer extends TerminologyRenderer { tr.td().tx("Chains"); td = tr.td().tx("Allowed: "); for (StringType t : spd.getChain()) { - td.sep(", ").tx(t.asStringValue()); + td.sep(", "); + td.tx(t.asStringValue()); } } @@ -144,6 +155,22 @@ public class SearchParameterRenderer extends TerminologyRenderer { return false; } + private boolean isAllConcreteResources(List target) { + for (String s : context.getWorker().getResourceNames()) { + StructureDefinition sd = context.getWorker().fetchTypeDefinition(s); + if (!sd.getAbstract() && !Utilities.existsInList(sd.getType(), "Parameters")) { + boolean found = false; + for (CodeType c : target) { + found = found || sd.getName().equals(c.getValue()); + } + if (!found) { + return false; + } + } + } + return true; + } + public void describe(XhtmlNode x, OperationDefinition opd) { x.tx(display(opd)); } 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 0c0c3c990..c6903ad5d 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 @@ -158,6 +158,7 @@ public class ToolingExtensions { public static final String EXT_SEC_CAT = "http://hl7.org/fhir/StructureDefinition/structuredefinition-security-category"; public static final String EXT_RESOURCE_CATEGORY = "http://hl7.org/fhir/StructureDefinition/structuredefinition-category"; public static final String EXT_RESOURCE_INTERFACE = "http://hl7.org/fhir/StructureDefinition/structuredefinition-interface"; + public static final String EXT_RESOURCE_IMPLEMENTS = "http://hl7.org/fhir/StructureDefinition/structuredefinition-implements"; public static final String EXT_TABLE_NAME = "http://hl7.org/fhir/StructureDefinition/structuredefinition-table-name"; public static final String EXT_OO_FILE = "http://hl7.org/fhir/StructureDefinition/operationoutcome-file"; public static final String EXT_WORKGROUP = "http://hl7.org/fhir/StructureDefinition/structuredefinition-wg"; diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java index 8bb68f5b7..3eb5189b0 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java @@ -892,6 +892,14 @@ public class Utilities { return false; } + public static String stringJoin(String sep, String... array) { + CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder(sep); + for (String s : array) + if (!noString(s)) + b.append(s); + return b.toString(); + } + public static String getFileNameForName(String name) { return name.toLowerCase();