From 84f7133cf1591d124b4fadc218e3e74b15e140e3 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 17 Feb 2022 02:05:02 +1100 Subject: [PATCH 1/6] remove debugging statements --- .../java/org/hl7/fhir/r5/conformance/ProfileUtilities.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java index 4e78b128b..3db5f1d77 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java @@ -2524,10 +2524,10 @@ public class ProfileUtilities extends TranslatingUtilities { // re-enabled 11-Feb 2022 GDG - we do want to do this. At least, $assemble in davinci-dtr, where the markdown comes from the SDC IG, and an SDC local reference must be changed to point to SDC. in this case, it's called when generating snapshots // added processRelatives parameter to deal with this (well, to try) if (processRelatives && webUrl != null) { - System.out.println("Making "+url+" relative to '"+webUrl+"'"); +// System.out.println("Making "+url+" relative to '"+webUrl+"'"); b.append(webUrl); } else { - System.out.println("Not making "+url+" relative to '"+webUrl+"'"); +// System.out.println("Not making "+url+" relative to '"+webUrl+"'"); } i = i + 1; } From d66c5abec0d8d661dd75b44e4f77c8348f9350c6 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sat, 19 Feb 2022 21:40:16 +1100 Subject: [PATCH 2/6] Add UTGCaseConvertor for future reference --- .../misc/utg/UTGCaseSensitivePopulator.java | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/utg/UTGCaseSensitivePopulator.java diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/utg/UTGCaseSensitivePopulator.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/utg/UTGCaseSensitivePopulator.java new file mode 100644 index 000000000..b7284759f --- /dev/null +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/utg/UTGCaseSensitivePopulator.java @@ -0,0 +1,105 @@ +package org.hl7.fhir.convertors.misc.utg; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.time.LocalDate; +import java.time.ZoneId; +import java.util.Calendar; +import java.util.Date; + +import org.hl7.fhir.exceptions.FHIRFormatError; +import org.hl7.fhir.r4.formats.IParser; +import org.hl7.fhir.r4.formats.IParser.OutputStyle; +import org.hl7.fhir.r4.formats.JsonParser; +import org.hl7.fhir.r4.formats.XmlParser; +import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.Bundle.BundleType; +import org.hl7.fhir.r4.model.CodeSystem; +import org.hl7.fhir.r4.model.CodeSystem.CodeSystemContentMode; +import org.hl7.fhir.r4.model.Period; +import org.hl7.fhir.r4.model.Provenance; +import org.hl7.fhir.r4.model.Provenance.ProvenanceAgentComponent; +import org.hl7.fhir.r4.model.Resource; +import org.hl7.fhir.utilities.Utilities; + +public class UTGCaseSensitivePopulator { + + public static void main(String[] args) throws FileNotFoundException, IOException { + new UTGCaseSensitivePopulator().process(new File(args[0])); + + } + + private void process(File root) throws FileNotFoundException, IOException { + Bundle bundle = new Bundle(); + bundle.setType(BundleType.COLLECTION); + bundle.setId("hxutg1-1-0-12"); + + scanFolders(root, bundle); + new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(root.getAbsolutePath(), "input", "sourceOfTruth", "history", "utgrel1hx-1-0-12.json")), bundle); + System.out.println("Done"); + } + + private void scanFolders(File folder, Bundle bundle) throws FileNotFoundException, IOException { + Calendar today = Calendar.getInstance(); + Date dt = today.getTime(); + today.set(Calendar.HOUR_OF_DAY, 0); + Date d = today.getTime(); + System.out.println("Scan "+folder.getAbsolutePath()); + + for (File f : folder.listFiles()) { + if (f.isDirectory() && !f.getName().equals("retired")) { + scanFolders(f, bundle); + } else if (f.getName().endsWith(".xml")) { + processFile(f, bundle, new XmlParser(), d, dt); + } else if (f.getName().endsWith(".json")) { + processFile(f, bundle, new JsonParser(), d, dt); + } + } + + } + + private void processFile(File f, Bundle bundle, IParser parser, Date d, Date dt) { + try { + Resource r = parser.parse(new FileInputStream(f)); + if (r instanceof CodeSystem) { + if (processCodeSystem((CodeSystem) r, bundle, d, dt)) { + parser.setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(f), r); + } + } + } catch (Exception e) { + } + + } + + private boolean processCodeSystem(CodeSystem cs, Bundle bundle, Date d, Date dt) { + if (cs.hasCaseSensitive()) { + return false; + } + if (!cs.getUrl().startsWith("http://terminology.hl7.org") || cs.getContent() == CodeSystemContentMode.NOTPRESENT) { + return false; + } + cs.setCaseSensitive(true); + Provenance p = new Provenance(); + p.setId("cs-286-"+cs.getId()); + p.addTarget().setReference("CodeSystem/"+cs.getId()); + p.setOccurred(new Period()); + p.getOccurredPeriod().setEnd(d); + p.setRecorded(dt); + p.addReason().setText("Populate Missing caseSensitive property;UP-286").addCoding().setSystem("http://terminology.hl7.org/CodeSystem/v3-ActReason").setCode("METAMGT"); + p.getActivity().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/v3-DataOperation").setCode("UPDATE"); + ProvenanceAgentComponent agent = p.addAgent(); + agent.getType().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/provenance-participant-type").setCode("author"); + agent.getWho().setDisplay("Grahame Grieve"); + agent = p.addAgent(); + agent.getType().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/provenance-participant-type").setCode("custodian"); + agent.getWho().setDisplay("Vocabulary WG"); + + bundle.addEntry().setFullUrl("http://terminology.hl7.org/fhir/Provenance/cs-286-"+cs.getId()).setResource(p); + + return true; + } + +} From a1912cd42336bd54a1cb287ab21ad5eb83762367 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sat, 19 Feb 2022 21:41:50 +1100 Subject: [PATCH 3/6] fix various rendering issues from core spec --- .../java/org/hl7/fhir/r5/renderers/BundleRenderer.java | 8 ++++---- .../org/hl7/fhir/r5/renderers/CodeSystemRenderer.java | 4 ++-- .../java/org/hl7/fhir/r5/renderers/PatientRenderer.java | 2 +- .../fhir/r5/renderers/QuestionnaireResponseRenderer.java | 8 +++++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/BundleRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/BundleRenderer.java index 2765f08bc..044a1ddcf 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/BundleRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/BundleRenderer.java @@ -104,7 +104,7 @@ public class BundleRenderer extends ResourceRenderer { xn.para().b().tx("Exception generating narrative: "+e.getMessage()); } } - root.blockquote().addChildren(xn); + root.blockquote().para().addChildren(xn); } } } @@ -156,7 +156,7 @@ public class BundleRenderer extends ResourceRenderer { List sections = section.children("section"); for (BaseWrapper child : sections) { if (nested) { - addSection(x.blockquote(), child, level+1, true); + addSection(x.blockquote().para(), child, level+1, true); } else { addSection(x, child, level+1, true); } @@ -241,7 +241,7 @@ public class BundleRenderer extends ResourceRenderer { List sections = section.getSection(); for (SectionComponent child : sections) { if (nested) { - addSection(x.blockquote(), child, level+1, true); + addSection(x.blockquote().para(), child, level+1, true); } else { addSection(x, child, level+1, true); } @@ -300,7 +300,7 @@ public class BundleRenderer extends ResourceRenderer { xn = makeExceptionXhtml(e, "generating narrative"); } } - root.blockquote().getChildNodes().addAll(checkInternalLinks(b, xn.getChildNodes())); + root.blockquote().para().getChildNodes().addAll(checkInternalLinks(b, xn.getChildNodes())); } } } 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 cf647b1a2..ef3309e8e 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 @@ -51,7 +51,7 @@ public class CodeSystemRenderer extends TerminologyRenderer { h.addText(cs.hasTitle() ? cs.getTitle() : cs.getName()); addMarkdown(x, cs.getDescription()); if (cs.hasCopyright()) - generateCopyright(x, cs); + generateCopyright(x, cs ); } generateProperties(x, cs); @@ -245,7 +245,7 @@ public class CodeSystemRenderer extends TerminologyRenderer { if (cs == null) { return false; } - return CodeSystemUtilities.hasCode(cs, code); + return code == null ? false : CodeSystemUtilities.hasCode(cs, code); } return false; } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/PatientRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/PatientRenderer.java index 2c08b10ab..3115055cd 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/PatientRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/PatientRenderer.java @@ -223,7 +223,7 @@ public class PatientRenderer extends ResourceRenderer { @Override public boolean render(XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException { - describe(x, r); + describe(x.para(), r); return false; } } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/QuestionnaireResponseRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/QuestionnaireResponseRenderer.java index 2a765f651..65f2d4b3e 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/QuestionnaireResponseRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/QuestionnaireResponseRenderer.java @@ -168,10 +168,12 @@ public class QuestionnaireResponseRenderer extends ResourceRenderer { r.getCells().add(gen.new Cell(null, context.getDefinitionsTarget() == null ? "" : context.getDefinitionsTarget()+"#item."+linkId, linkId, null, null)); r.getCells().add(gen.new Cell(null, null, text, null, null)); r.getCells().add(gen.new Cell(null, null, null, null, null)); - if (answers.size() == 0) { + if (answers == null || answers.size() == 0) { r.getCells().add(gen.new Cell(null, null, null, null, null)); - for (BaseWrapper si : items) { - renderTreeItem(gen, r.getSubRows(), q, si); + if (items != null) { + for (BaseWrapper si : items) { + renderTreeItem(gen, r.getSubRows(), q, si); + } } } else if (answers.size() == 1) { BaseWrapper ans = answers.get(0); From 99b8122728034312fabe0d1607f11bd565ec40d4 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sat, 19 Feb 2022 21:43:14 +1100 Subject: [PATCH 4/6] Fix rendering problem. to XML resources --- .../main/java/org/hl7/fhir/utilities/xhtml/XhtmlComposer.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlComposer.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlComposer.java index 0b661a872..1ff09d550 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlComposer.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlComposer.java @@ -314,6 +314,9 @@ public class XhtmlComposer { else if (node.getNodeType() == NodeType.Element) { Element child = e.getOwnerDocument().createElementNS(XHTML_NS, node.getName()); e.appendChild(child); + for (String n : node.getAttributes().keySet()) { + child.setAttribute(n, node.getAttribute(n)); + } for (XhtmlNode c : node.getChildNodes()) { appendChild(child, c); } From 4923382138706a8be75184e33f9c675184de6730 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sat, 19 Feb 2022 21:45:28 +1100 Subject: [PATCH 5/6] fix whitespace in messages --- org.hl7.fhir.utilities/src/main/resources/Messages.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.hl7.fhir.utilities/src/main/resources/Messages.properties b/org.hl7.fhir.utilities/src/main/resources/Messages.properties index 1ae381d35..921678728 100644 --- a/org.hl7.fhir.utilities/src/main/resources/Messages.properties +++ b/org.hl7.fhir.utilities/src/main/resources/Messages.properties @@ -670,7 +670,7 @@ TYPE_SPECIFIC_CHECKS_DT_URL_EXAMPLE = Example URLs are not allowed in this conte UNICODE_BIDI_CONTROLS_CHARS_DISALLOWED = The Unicode sequence has bi-di control characters which are not allowed in this context: {1} UNICODE_BIDI_CONTROLS_CHARS_MATCH = The Unicode sequence has unterminated bi-di control characters (see CVE-2021-42574): {1} CODESYSTEM_CS_HL7_MISSING_ELEMENT_SHALL = HL7 Defined CodeSystems SHALL have a stated value for the {0} element so that users know the status and meaning of the code system clearly -CODESYSTEM_CS_HL7_MISSING_ELEMENT_SHOULD = HL7 Defined CodeSystems SHOULD have a stated value for the {0} element so that users know the status and meaning of the code system clearly +CODESYSTEM_CS_HL7_MISSING_ELEMENT_SHOULD = HL7 Defined CodeSystems SHOULD have a stated value for the {0} element so that users know the status and meaning of the code system clearly CODESYSTEM_CS_NONHL7_MISSING_ELEMENT = CodeSystems SHOULD have a stated value for the {0} element so that users know the status and meaning of the code system clearly CODESYSTEM_CS_HL7_PRESENT_ELEMENT_SUPPL = CodeSystems SHOULD NOT have a stated value for the {0} element when they are a supplement CODESYSTEM_CS_HL7_PRESENT_ELEMENT_SUPPL_WRONG = CodeSystem Supplements SHALL have a content value of 'supplement' From 98ba40748e5b414bf1dd85dff58944ea1d848017 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sat, 19 Feb 2022 21:46:05 +1100 Subject: [PATCH 6/6] Follow content reference when rendering XML resources --- .../fhir/r5/conformance/ProfileUtilities.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java index 3db5f1d77..26aeb35e0 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java @@ -553,7 +553,17 @@ public class ProfileUtilities extends TranslatingUtilities { } public List getChildList(StructureDefinition structure, ElementDefinition element) { - return getChildList(structure, element.getPath(), element.getId(), false); + if (element.hasContentReference()) { + ElementDefinition target = element; + for (ElementDefinition t : structure.getSnapshot().getElement()) { + if (t.getId().equals(element.getContentReference().substring(1))) { + target = t; + } + } + return getChildList(structure, target.getPath(), target.getId(), false); + } else { + return getChildList(structure, element.getPath(), element.getId(), false); + } } public void updateMaps(StructureDefinition base, StructureDefinition derived) throws DefinitionException { @@ -3680,7 +3690,7 @@ public class ProfileUtilities extends TranslatingUtilities { } - private String codeForAggregation(AggregationMode a) { + public static String codeForAggregation(AggregationMode a) { switch (a) { case BUNDLED : return "b"; case CONTAINED : return "c"; @@ -3689,7 +3699,7 @@ public class ProfileUtilities extends TranslatingUtilities { } } - private String hintForAggregation(AggregationMode a) { + public static String hintForAggregation(AggregationMode a) { if (a != null) return a.getDefinition(); else