diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/CodeSystemRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/CodeSystemRenderer.java index bb8d121b2..55151f29d 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/CodeSystemRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/CodeSystemRenderer.java @@ -183,7 +183,7 @@ public class CodeSystemRenderer extends TerminologyRenderer { hierarchy = hierarchy || csNav.isRestructure(); List langs = new ArrayList<>(); - addMapHeaders(addTableHeaderRowStandard(t, hierarchy, display, definitions, commentS, version, deprecated, properties, null, null, false), maps); + addCopyColumn(addMapHeaders(addTableHeaderRowStandard(t, hierarchy, display, definitions, commentS, version, deprecated, properties, null, null, false), maps)); for (ConceptDefinitionComponent c : csNav.getConcepts(null)) { hasExtensions = addDefineRowToTable(t, c, 0, hierarchy, display, definitions, commentS, version, deprecated, maps, cs.getUrl(), cs, properties, csNav, langs, isSupplement) || hasExtensions; } @@ -202,6 +202,13 @@ public class CodeSystemRenderer extends TerminologyRenderer { return hasExtensions; } + private void addCopyColumn(XhtmlNode tr) { + if (context.isCopyButton()) { + tr.td().b().tx("Copy"); + } + + } + private boolean conceptsHaveDefinition(ConceptDefinitionComponent c) { if (c.hasDefinition()) { return true; @@ -492,6 +499,12 @@ public class CodeSystemRenderer extends TerminologyRenderer { } td = tr.td().colspan(Integer.toString(w)); } + if (context.isCopyButton()) { + td = tr.td(); + clipboard(td, "icon_clipboard_x.png", "XML", "\n"+(cs.getVersionNeeded() ? "\n" : "")+"\n\n"); + td.nbsp(); + clipboard(td, "icon_clipboard_j.png", "JSON", "\"system\" : \""+Utilities.escapeXml(cs.getUrl())+"\",\n"+(cs.getVersionNeeded() ? "\"version\" : \""+Utilities.escapeXml(cs.getVersion())+"\",\n" : "")+"\"code\" : \""+Utilities.escapeXml(c.getCode())+"\",\n\"display\" : \""+Utilities.escapeXml(c.getDisplay())+"\"\n"); + } return hasExtensions; } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/TerminologyRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/TerminologyRenderer.java index d7fe9c06e..ed14cd19b 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/TerminologyRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/TerminologyRenderer.java @@ -111,7 +111,7 @@ public abstract class TerminologyRenderer extends ResourceRenderer { } - protected void addMapHeaders(XhtmlNode tr, List maps) throws FHIRFormatError, DefinitionException, IOException { + protected XhtmlNode addMapHeaders(XhtmlNode tr, List maps) throws FHIRFormatError, DefinitionException, IOException { for (UsedConceptMap m : maps) { XhtmlNode td = tr.td(); XhtmlNode b = td.b(); @@ -120,6 +120,7 @@ public abstract class TerminologyRenderer extends ResourceRenderer { if (m.getDetails().isDoDescription() && m.getMap().hasDescription()) addMarkdown(td, m.getMap().getDescription()); } + return tr; } protected String getHeader() { @@ -311,8 +312,6 @@ public abstract class TerminologyRenderer extends ResourceRenderer { } } - - protected String getDisplayForConcept(String system, String version, String value) { if (value == null || system == null) return null; @@ -320,4 +319,13 @@ public abstract class TerminologyRenderer extends ResourceRenderer { return cl == null ? null : cl.getDisplay(); } + + protected void clipboard(XhtmlNode x, String img, String title, String source) { + XhtmlNode span = x.span("cursor: pointer", "Copy "+title+" Format to clipboard"); + span.attribute("onClick", "navigator.clipboard.writeText('"+Utilities.escapeJson(source)+"');"); + span.img(img).setAttribute("width", "24px").setAttribute("height", "16px"); + } + + + } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/RenderingContext.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/RenderingContext.java index 57bb8c20d..dc854c463 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/RenderingContext.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/RenderingContext.java @@ -131,6 +131,7 @@ public class RenderingContext { private DateTimeFormatter dateFormat; private DateTimeFormatter dateYearFormat; private DateTimeFormatter dateYearMonthFormat; + private boolean copyButton; /** * @@ -190,6 +191,7 @@ public class RenderingContext { res.targetVersion = targetVersion; res.locale = locale; res.showComments = showComments; + res.copyButton = copyButton; res.terminologyServiceOptions = terminologyServiceOptions.copy(); return res; @@ -596,6 +598,13 @@ public class RenderingContext { this.showComments = showComments; return this; } + public boolean isCopyButton() { + return copyButton; + } + public RenderingContext setCopyButton(boolean copyButton) { + this.copyButton = copyButton; + return this; + } } \ No newline at end of file