Sorting ValueSet.expansion.contains in the tx tests

This commit is contained in:
Grahame Grieve 2023-08-21 19:35:10 +10:00
parent 69d2a12a2b
commit f795394fd2
4 changed files with 37 additions and 9 deletions

View File

@ -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) {

View File

@ -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);
}
}
}

View File

@ -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;
}
}
}

View File

@ -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<ValueSetExpansionContainsComponent> {
@Override
public int compare(ValueSetExpansionContainsComponent o1, ValueSetExpansionContainsComponent o2) {
return o1.getCode().compareTo(o2.getCode());
}
}
public static class ExpParameterSorter implements Comparator<ValueSetExpansionParameterComponent> {
@Override