From f52df7c0cc6e145bf91bdb2421f3245a2b43bfb9 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 20 Jul 2023 08:21:51 +1000 Subject: [PATCH] Fix obligation rendering message --- .../r5/renderers/ObligationsRenderer.java | 95 ++++++++++++++++++- .../StructureDefinitionRenderer.java | 13 ++- 2 files changed, 104 insertions(+), 4 deletions(-) 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 795b7cb29..b7aaf40f6 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 @@ -66,6 +66,9 @@ public class ObligationsRenderer { for (Extension usage : ext.getExtensionsByUrl("usage")) { this.usage.add(usage.getValueUsageContext()); } + for (Extension eid : ext.getExtensionsByUrl("elementId")) { + this.elementIds.add(eid.getValue().primitiveValue()); + } this.isUnchanged = ext.hasUserData(ProfileUtilities.UD_DERIVATION_EQUALS); } @@ -165,6 +168,10 @@ public class ObligationsRenderer { seeObligations(list, null, false, "$all"); } + public void seeRootObligations(String eid, List list) { + seeRootObligations(eid, list, null, false, "$all"); + } + public void seeObligations(List list, List compList, boolean compare, String id) { HashMap compBindings = new HashMap(); if (compare && compList!=null) { @@ -179,7 +186,7 @@ public class ObligationsRenderer { for (Extension ext : list) { ObligationDetail obd = obligationDetail(ext); - if (("$all".equals(id) && !obd.hasActor()) || (obd.hasActor(id))) { + if ("$all".equals(id) || (obd.hasActor(id))) { if (compare && compList!=null) { ObligationDetail match = null; do { @@ -192,8 +199,9 @@ public class ObligationsRenderer { obligations.add(obd); if (obd.compare!=null) compBindings.remove(obd.compare.getKey()); - } else + } else { obligations.add(obd); + } } } for (ObligationDetail b: compBindings.values()) { @@ -202,6 +210,61 @@ public class ObligationsRenderer { } } + public void seeRootObligations(String eid, List list, List compList, boolean compare, String id) { + HashMap compBindings = new HashMap(); + if (compare && compList!=null) { + for (Extension ext : compList) { + if (forElement(eid, ext)) { + ObligationDetail abr = obligationDetail(ext); + if (compBindings.containsKey(abr.getKey())) { + abr.incrementCount(); + } + compBindings.put(abr.getKey(), abr); + } + } + } + + for (Extension ext : list) { + if (forElement(eid, ext)) { + ObligationDetail obd = obligationDetail(ext); + obd.elementIds.clear(); + if ("$all".equals(id) || (obd.hasActor(id))) { + if (compare && compList!=null) { + ObligationDetail match = null; + do { + match = compBindings.get(obd.getKey()); + if (obd.alreadyMatched()) + obd.incrementCount(); + } while (match!=null && obd.alreadyMatched()); + if (match!=null) + obd.setCompare(match); + obligations.add(obd); + if (obd.compare!=null) + compBindings.remove(obd.compare.getKey()); + } else { + obligations.add(obd); + } + } + } + } + for (ObligationDetail b: compBindings.values()) { + b.removed = true; + obligations.add(b); + } + } + + + private boolean forElement(String eid, Extension ext) { + + for (Extension exid : ext.getExtensionsByUrl("elementId")) { + if (eid.equals(exid.getValue().primitiveValue())) { + return true; + } + } + return false; + } + + protected ObligationDetail obligationDetail(Extension ext) { ObligationDetail abr = new ObligationDetail(ext); return abr; @@ -273,11 +336,13 @@ public class ObligationsRenderer { boolean usage = false; boolean actor = false; boolean filter = false; + boolean elementId = false; for (ObligationDetail binding : obligations) { actor = actor || binding.actorId!=null || (binding.compare!=null && binding.compare.actorId !=null); doco = doco || binding.getDoco(fullDoco)!=null || (binding.compare!=null && binding.compare.getDoco(fullDoco)!=null); usage = usage || !binding.usage.isEmpty() || (binding.compare!=null && !binding.compare.usage.isEmpty()); filter = filter || binding.filter != null || (binding.compare!=null && binding.compare.filter!=null); + elementId = elementId || !binding.elementIds.isEmpty() || (binding.compare!=null && !binding.compare.elementIds.isEmpty()); } XhtmlNode tr = new XhtmlNode(NodeType.Element, "tr"); @@ -286,6 +351,9 @@ public class ObligationsRenderer { if (actor) { tr.td().style("font-size: 11px").tx("Actor"); } + if (elementId) { + tr.td().style("font-size: 11px").tx("Elements"); + } if (usage) { tr.td().style("font-size: 11px").tx("Usage"); } @@ -342,6 +410,29 @@ public class ObligationsRenderer { } } } + if (elementId) { + XhtmlNode elementIds = tr.td().style("font-size: 11px"); + if (ob.compare!=null && ob.elementIds.equals(ob.compare.elementIds)) + elementIds.style(STYLE_UNCHANGED); + for (String eid : ob.elementIds) { + elementIds.sep(", "); + ElementDefinition ed = profile.getSnapshot().getElementById(eid); + if (ed != null) { + elementIds.ah("#"+eid).tx(ed.getName()); + } else { + elementIds.code().tx(eid); + } + } + + if (ob.compare!=null && !ob.compare.elementIds.isEmpty()) { + for (String eid : ob.compare.elementIds) { + if (!ob.elementIds.contains(eid)) { + elementIds.sep(", "); + elementIds.span(STYLE_REMOVED, null).code().tx(eid); + } + } + } + } if (usage) { if (ob.usage != null) { boolean first = true; diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/StructureDefinitionRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/StructureDefinitionRenderer.java index 5f0ff0cc2..8d00f8240 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/StructureDefinitionRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/StructureDefinitionRenderer.java @@ -837,8 +837,14 @@ public class StructureDefinitionRenderer extends ResourceRenderer { if (element != null && element.getIsModifier()) { checkForNoChange(element.getIsModifierElement(), gc.addStyledText(translate("sd.table", "This element is a modifier element"), "?!", null, null, null, false)); } - if (element != null && element.getMustSupport()) { - checkForNoChange(element.getMustSupportElement(), gc.addStyledText(translate("sd.table", "This element must be supported"), "S", "white", "red", null, false)); + if (element != null) { + if (element.getMustSupport() && element.hasExtension(ToolingExtensions.EXT_OBLIGATION)) { + checkForNoChange(element.getMustSupportElement(), gc.addStyledText(translate("sd.table", "This element has obligations and must be supported"), "SO", "white", "red", null, false)); + } else if (element.getMustSupport()) { + checkForNoChange(element.getMustSupportElement(), gc.addStyledText(translate("sd.table", "This element must be supported"), "S", "white", "red", null, false)); + } else if (element != null && element.hasExtension(ToolingExtensions.EXT_OBLIGATION)) { + checkForNoChange(element.getMustSupportElement(), gc.addStyledText(translate("sd.table", "This element has obligations"), "O", "white", "red", null, false)); + } } if (element != null && element.getIsSummary()) { checkForNoChange(element.getIsSummaryElement(), gc.addStyledText(translate("sd.table", "This element is included in summaries"), "\u03A3", null, null, null, false)); @@ -1381,6 +1387,9 @@ public class StructureDefinitionRenderer extends ResourceRenderer { if (definition.hasExtension(ToolingExtensions.EXT_OBLIGATION)) { obr.seeObligations(definition.getExtensionsByUrl(ToolingExtensions.EXT_OBLIGATION)); } + if (!definition.getPath().contains(".") && profile.hasExtension(ToolingExtensions.EXT_OBLIGATION)) { + obr.seeObligations(profile.getExtensionsByUrl(ToolingExtensions.EXT_OBLIGATION)); + } obr.renderTable(gen, c); if (definition.hasMaxLength() && definition.getMaxLength()!=0) {