From 69d2a12a2b1c8d08d3986dffc98529ee95db9e40 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 21 Aug 2023 16:29:54 +1000 Subject: [PATCH 1/2] fix bug handling invalid codes when expanding --- .../fhir/r5/terminologies/expansion/ValueSetExpander.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/expansion/ValueSetExpander.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/expansion/ValueSetExpander.java index 763fa7c3b..940d82155 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/expansion/ValueSetExpander.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/expansion/ValueSetExpander.java @@ -877,9 +877,9 @@ public class ValueSetExpander extends ValueSetProcessBase { def.checkNoModifiers("Code in Code System", "expanding"); inactive = CodeSystemUtilities.isInactive(cs, def); isAbstract = CodeSystemUtilities.isNotSelectable(cs, def); + addCode(dwc, inc.getSystem(), c.getCode(), !Utilities.noString(c.getDisplay()) ? c.getDisplay() : def.getDisplay(), c.hasDisplay() ? vsSrc.getLanguage() : cs.getLanguage(), null, mergeDesignations(def, convertDesignations(c.getDesignation())), + expParams, isAbstract, inactive, imports, noInactive, false, exp.getProperty(), makeCSProps(def.getDefinition(), def.getProperty()), null, def.getExtension(), c.getExtension(), exp); } - addCode(dwc, inc.getSystem(), c.getCode(), !Utilities.noString(c.getDisplay()) ? c.getDisplay() : def == null ? null : def.getDisplay(), c.hasDisplay() ? vsSrc.getLanguage() : cs.getLanguage(), null, mergeDesignations(def, convertDesignations(c.getDesignation())), - expParams, isAbstract, inactive, imports, noInactive, false, exp.getProperty(), def == null ? null : makeCSProps(def.getDefinition(), def.getProperty()), null, def == null ? null : def.getExtension(), c.getExtension(), exp); } } if (inc.getFilter().size() > 0) { @@ -963,7 +963,9 @@ public class ValueSetExpander extends ValueSetProcessBase { private List mergeDesignations(ConceptDefinitionComponent def, List list) { List res = new ArrayList<>(); - res.addAll(def.getDesignation()); + if (def != null) { + res.addAll(def.getDesignation()); + } res.addAll(list); return res; } From f795394fd2522c0c07608d9316883df39ed60313 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 21 Aug 2023 19:35:10 +1000 Subject: [PATCH 2/2] Sorting ValueSet.expansion.contains in the tx tests --- .../expansion/ValueSetExpander.java | 2 +- .../org/hl7/fhir/r5/utils/ElementVisitor.java | 21 +++++++++++++------ .../validation/special/TxTesterScrubbers.java | 11 ++++++++-- .../validation/special/TxTesterSorters.java | 12 +++++++++++ 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/expansion/ValueSetExpander.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/expansion/ValueSetExpander.java index 940d82155..bb6c813ea 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/expansion/ValueSetExpander.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/expansion/ValueSetExpander.java @@ -557,7 +557,7 @@ public class ValueSetExpander extends ValueSetProcessBase { try { if (source.hasCompose()) { - ExtensionsUtils.stripExtensions(focus.getCompose()); +// ExtensionsUtils.stripExtensions(focus.getCompose()); - disabled 23/05/2023 GDG - why was this ever thought to be a good idea? handleCompose(source.getCompose(), focus.getExpansion(), expParams, source.getUrl(), focus.getExpansion().getExtension(), source); } } catch (EFinished e) { diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/ElementVisitor.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/ElementVisitor.java index b2e6504a8..25acd88ed 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/ElementVisitor.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/ElementVisitor.java @@ -4,12 +4,17 @@ import org.hl7.fhir.r5.model.Base; import org.hl7.fhir.r5.model.Element; import org.hl7.fhir.r5.model.Property; import org.hl7.fhir.r5.model.Resource; +import org.hl7.fhir.r5.utils.ElementVisitor.ElementVisitorInstruction; public class ElementVisitor { + public enum ElementVisitorInstruction { + VISIT_CHILDREN, NO_VISIT_CHILDREN; + } + public interface IElementVisitor { - public void visit(Object context, Resource resource); - public void visit(Object context, Element element); + public ElementVisitorInstruction visit(Object context, Resource resource); + public ElementVisitorInstruction visit(Object context, Element element); } private IElementVisitor visitor; @@ -33,13 +38,17 @@ public class ElementVisitor { } public void visit(Object context, Resource res) { - visitor.visit(context, res); - visitBase(context, res); + ElementVisitorInstruction c = visitor.visit(context, res); + if (c == ElementVisitorInstruction.VISIT_CHILDREN) { + visitBase(context, res); + } } public void visit(Object context, Element e) { - visitor.visit(context, e); - visitBase(context, e); + ElementVisitorInstruction c = visitor.visit(context, e); + if (c == ElementVisitorInstruction.VISIT_CHILDREN) { + visitBase(context, e); + } } } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTesterScrubbers.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTesterScrubbers.java index f23d0fed5..c1cc2eb73 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTesterScrubbers.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTesterScrubbers.java @@ -8,6 +8,7 @@ import org.hl7.fhir.r5.model.Parameters; import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.utils.ElementVisitor; +import org.hl7.fhir.r5.utils.ElementVisitor.ElementVisitorInstruction; import org.hl7.fhir.r5.utils.ElementVisitor.IElementVisitor; import org.hl7.fhir.utilities.Utilities; @@ -53,16 +54,22 @@ public class TxTesterScrubbers { } @Override - public void visit(Object context, Resource resource) { + public ElementVisitorInstruction visit(Object context, Resource resource) { if (resource instanceof DomainResource) { DomainResource dr = (DomainResource) resource; dr.getExtension().removeIf(ext -> !isManagedExtension(ext)); } + return ElementVisitorInstruction.VISIT_CHILDREN; } @Override - public void visit(Object context, Element element) { + public ElementVisitorInstruction visit(Object context, Element element) { element.getExtension().removeIf(ext -> !isManagedExtension(ext)); + if (element.fhirType().equals("ValueSet.compose")) { + return ElementVisitorInstruction.NO_VISIT_CHILDREN; + } else { + return ElementVisitorInstruction.VISIT_CHILDREN; + } } } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTesterSorters.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTesterSorters.java index a2473049e..4c840218c 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTesterSorters.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTesterSorters.java @@ -41,6 +41,7 @@ public class TxTesterSorters { Collections.sort(vs.getExpansion().getParameter(), new TxTesterSorters.ExpParameterSorter()); Collections.sort(vs.getExpansion().getProperty(), new TxTesterSorters.PropertyDefnSorter()); Collections.sort(vs.getExpansion().getExtension(), new TxTesterSorters.ExtensionSorter()); + Collections.sort(vs.getExpansion().getContains(), new TxTesterSorters.ContainsSorter()); for (ValueSetExpansionContainsComponent cc : vs.getExpansion().getContains()) { sortContainsFeatures(cc); } @@ -48,6 +49,7 @@ public class TxTesterSorters { } public static void sortContainsFeatures(ValueSetExpansionContainsComponent cc) { + Collections.sort(cc.getContains(), new TxTesterSorters.ContainsSorter()); Collections.sort(cc.getExtension(), new TxTesterSorters.ExtensionSorter()); Collections.sort(cc.getDesignation(), new TxTesterSorters.DesignationSorter()); Collections.sort(cc.getProperty(), new TxTesterSorters.PropertyValueSorter()); @@ -129,6 +131,16 @@ public class TxTesterSorters { } + public static class ContainsSorter implements Comparator { + + @Override + public int compare(ValueSetExpansionContainsComponent o1, ValueSetExpansionContainsComponent o2) { + return o1.getCode().compareTo(o2.getCode()); + } + + } + + public static class ExpParameterSorter implements Comparator { @Override