fix bug with sorting where derived profile is adding more slice constraints

This commit is contained in:
Grahame Grieve 2020-01-30 11:05:30 +11:00
parent 6242a70b68
commit 408ceb1761
1 changed files with 10 additions and 8 deletions

View File

@ -4354,13 +4354,13 @@ public class ProfileUtilities extends TranslatingUtilities {
@Override @Override
public int compare(ElementDefinitionHolder o1, ElementDefinitionHolder o2) { public int compare(ElementDefinitionHolder o1, ElementDefinitionHolder o2) {
if (o1.getBaseIndex() == 0) if (o1.getBaseIndex() == 0)
o1.setBaseIndex(find(o1.getSelf().getPath())); o1.setBaseIndex(find(o1.getSelf().getPath(), true));
if (o2.getBaseIndex() == 0) if (o2.getBaseIndex() == 0)
o2.setBaseIndex(find(o2.getSelf().getPath())); o2.setBaseIndex(find(o2.getSelf().getPath(), true));
return o1.getBaseIndex() - o2.getBaseIndex(); return o1.getBaseIndex() - o2.getBaseIndex();
} }
private int find(String path) { private int find(String path, boolean mandatory) {
String op = path; String op = path;
int lc = 0; int lc = 0;
String actual = base+path.substring(prefixLength); String actual = base+path.substring(prefixLength);
@ -4392,10 +4392,12 @@ public class ProfileUtilities extends TranslatingUtilities {
throw new Error("Internal recursion detection: find() loop path recursion > "+MAX_RECURSION_LIMIT+" - check paths are valid (for path "+path+"/"+op+")"); throw new Error("Internal recursion detection: find() loop path recursion > "+MAX_RECURSION_LIMIT+" - check paths are valid (for path "+path+"/"+op+")");
} }
} }
if (mandatory) {
if (prefixLength == 0) if (prefixLength == 0)
errors.add("Differential contains path "+path+" which is not found in the base"); errors.add("Differential contains path "+path+" which is not found in the base");
else else
errors.add("Differential contains path "+path+" which is actually "+actual+", which is not found in the base"); errors.add("Differential contains path "+path+" which is actually "+actual+", which is not found in the base");
}
return 0; return 0;
} }
@ -4508,7 +4510,7 @@ public class ProfileUtilities extends TranslatingUtilities {
private void sortElements(ElementDefinitionHolder edh, ElementDefinitionComparer cmp, List<String> errors) throws FHIRException { private void sortElements(ElementDefinitionHolder edh, ElementDefinitionComparer cmp, List<String> errors) throws FHIRException {
if (edh.getChildren().size() == 1) if (edh.getChildren().size() == 1)
// special case - sort needsto allocate base numbers, but there'll be no sort if there's only 1 child. So in that case, we just go ahead and allocated base number directly // special case - sort needsto allocate base numbers, but there'll be no sort if there's only 1 child. So in that case, we just go ahead and allocated base number directly
edh.getChildren().get(0).baseIndex = cmp.find(edh.getChildren().get(0).getSelf().getPath()); edh.getChildren().get(0).baseIndex = cmp.find(edh.getChildren().get(0).getSelf().getPath(), false);
else else
Collections.sort(edh.getChildren(), cmp); Collections.sort(edh.getChildren(), cmp);
cmp.checkForErrors(errors); cmp.checkForErrors(errors);