Fix for not checking invariants on content references (e.g. ValueSet.compose.exclude)

This commit is contained in:
Grahame Grieve 2020-05-18 06:20:29 +10:00
parent 58fe151f79
commit 47d8ba4558
1 changed files with 23 additions and 12 deletions

View File

@ -2185,10 +2185,12 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
boolean matchingResource = false; boolean matchingResource = false;
for (CanonicalType target : containerType.getTargetProfile()) { for (CanonicalType target : containerType.getTargetProfile()) {
StructureDefinition sd = resolveProfile(profile, target.asStringValue()); StructureDefinition sd = resolveProfile(profile, target.asStringValue());
if (rule(errors, IssueType.NOTFOUND, element.line(), element.col(), path, sd != null, I18nConstants.REFERENCE_REF_CANTRESOLVEPROFILE, target.asStringValue())) {
if (("http://hl7.org/fhir/StructureDefinition/" + sd.getType()).equals(tu)) { if (("http://hl7.org/fhir/StructureDefinition/" + sd.getType()).equals(tu)) {
matchingResource = true; matchingResource = true;
break; break;
} }
}
} }
rule(errors, IssueType.STRUCTURE, element.line(), element.col(), path, matchingResource, I18nConstants.REFERENCE_REF_WRONGTARGET, reference.getType(), container.getType("Reference").getTargetProfile()); rule(errors, IssueType.STRUCTURE, element.line(), element.col(), path, matchingResource, I18nConstants.REFERENCE_REF_WRONGTARGET, reference.getType(), container.getType("Reference").getTargetProfile());
@ -3627,6 +3629,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
} }
} else if (ei.definition.getContentReference() != null) { } else if (ei.definition.getContentReference() != null) {
typeDefn = resolveNameReference(profile.getSnapshot(), ei.definition.getContentReference()); typeDefn = resolveNameReference(profile.getSnapshot(), ei.definition.getContentReference());
} else if (ei.definition.getType().size() == 1 && ("Element".equals(ei.definition.getType().get(0).getWorkingCode()) || "BackboneElement".equals(ei.definition.getType().get(0).getWorkingCode()))) { } else if (ei.definition.getType().size() == 1 && ("Element".equals(ei.definition.getType().get(0).getWorkingCode()) || "BackboneElement".equals(ei.definition.getType().get(0).getWorkingCode()))) {
if (ei.definition.getType().get(0).hasProfile()) { if (ei.definition.getType().get(0).hasProfile()) {
CanonicalType pu = ei.definition.getType().get(0).getProfile().get(0); CanonicalType pu = ei.definition.getType().get(0).getProfile().get(0);
@ -3654,7 +3657,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
String thisExtension = null; String thisExtension = null;
boolean checkDisplay = true; boolean checkDisplay = true;
checkInvariants(hostContext, errors, profile, ei.definition, resource, ei.getElement(), localStack, true); checkInvariants(hostContext, errors, profile, typeDefn != null ? typeDefn : ei.definition, resource, ei.getElement(), localStack, true);
ei.getElement().markValidation(profile, ei.definition); ei.getElement().markValidation(profile, ei.definition);
boolean elementValidated = false; boolean elementValidated = false;
@ -3910,18 +3913,20 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
ElementDefinition ed = childDefinitions.get(i); ElementDefinition ed = childDefinitions.get(i);
boolean childUnsupportedSlicing = false; boolean childUnsupportedSlicing = false;
boolean process = true; boolean process = true;
if (ed.hasSlicing() && !ed.getSlicing().getOrdered()) if (ed.hasSlicing() && !ed.getSlicing().getOrdered()) {
slicingPath = ed.getPath(); slicingPath = ed.getPath();
else if (slicingPath != null && ed.getPath().equals(slicingPath)) } else if (slicingPath != null && ed.getPath().equals(slicingPath)) {
; // nothing ; // nothing
else if (slicingPath != null && !ed.getPath().startsWith(slicingPath)) } else if (slicingPath != null && !ed.getPath().startsWith(slicingPath)) {
slicingPath = null; slicingPath = null;
}
// where are we with slicing // where are we with slicing
if (ed.hasSlicing()) { if (ed.hasSlicing()) {
if (slicer != null && slicer.getPath().equals(ed.getPath())) { if (slicer != null && slicer.getPath().equals(ed.getPath())) {
String errorContext = "profile " + profile.getUrl(); String errorContext = "profile " + profile.getUrl();
if (!resource.getChildValue(ID).isEmpty()) if (!resource.getChildValue(ID).isEmpty()) {
errorContext += "; instance " + resource.getChildValue("id"); errorContext += "; instance " + resource.getChildValue("id");
}
throw new DefinitionException(context.formatMessage(I18nConstants.SLICE_ENCOUNTERED_MIDWAY_THROUGH_SET_PATH___ID___, slicer.getPath(), slicer.getId(), errorContext)); throw new DefinitionException(context.formatMessage(I18nConstants.SLICE_ENCOUNTERED_MIDWAY_THROUGH_SET_PATH___ID___, slicer.getPath(), slicer.getId(), errorContext));
} }
slicer = ed; slicer = ed;
@ -3941,9 +3946,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
int lastSlice = -1; int lastSlice = -1;
for (ElementInfo ei : children) { for (ElementInfo ei : children) {
String sliceInfo = ""; String sliceInfo = "";
if (slicer != null) if (slicer != null) {
sliceInfo = " (slice: " + slicer.getPath() + ")"; sliceInfo = " (slice: " + slicer.getPath() + ")";
if (!unsupportedSlicing) }
if (!unsupportedSlicing) {
if (ei.additionalSlice && ei.definition != null) { if (ei.additionalSlice && ei.definition != null) {
if (ei.definition.getSlicing().getRules().equals(ElementDefinition.SlicingRules.OPEN) || if (ei.definition.getSlicing().getRules().equals(ElementDefinition.SlicingRules.OPEN) ||
ei.definition.getSlicing().getRules().equals(ElementDefinition.SlicingRules.OPENATEND) && true /* TODO: replace "true" with condition to check that this element is at "end" */) { ei.definition.getSlicing().getRules().equals(ElementDefinition.SlicingRules.OPENATEND) && true /* TODO: replace "true" with condition to check that this element is at "end" */) {
@ -3956,9 +3962,11 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
} }
} else { } else {
// Don't raise this if we're in an abstract profile, like Resource // Don't raise this if we're in an abstract profile, like Resource
if (!profile.getAbstract()) if (!profile.getAbstract()) {
rule(errors, IssueType.NOTSUPPORTED, ei.line(), ei.col(), ei.getPath(), (ei.definition != null), I18nConstants.VALIDATION_VAL_PROFILE_NOTALLOWED, profile.getUrl()); rule(errors, IssueType.NOTSUPPORTED, ei.line(), ei.col(), ei.getPath(), (ei.definition != null), I18nConstants.VALIDATION_VAL_PROFILE_NOTALLOWED, profile.getUrl());
}
} }
}
// TODO: Should get the order of elements correct when parsing elements that are XML attributes vs. elements // TODO: Should get the order of elements correct when parsing elements that are XML attributes vs. elements
boolean isXmlAttr = false; boolean isXmlAttr = false;
if (ei.definition != null) { if (ei.definition != null) {
@ -3974,14 +3982,17 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
boolean ok = (ei.definition == null) || (ei.index >= last) || isXmlAttr; boolean ok = (ei.definition == null) || (ei.index >= last) || isXmlAttr;
rule(errors, IssueType.INVALID, ei.line(), ei.col(), ei.getPath(), ok, I18nConstants.VALIDATION_VAL_PROFILE_OUTOFORDER, profile.getUrl(), ei.getName()); rule(errors, IssueType.INVALID, ei.line(), ei.col(), ei.getPath(), ok, I18nConstants.VALIDATION_VAL_PROFILE_OUTOFORDER, profile.getUrl(), ei.getName());
} }
if (ei.slice != null && ei.index == last && ei.slice.getSlicing().getOrdered()) if (ei.slice != null && ei.index == last && ei.slice.getSlicing().getOrdered()) {
rule(errors, IssueType.INVALID, ei.line(), ei.col(), ei.getPath(), (ei.definition == null) || (ei.sliceindex >= lastSlice) || isXmlAttr, I18nConstants.VALIDATION_VAL_PROFILE_SLICEORDER, profile.getUrl(), ei.getName()); rule(errors, IssueType.INVALID, ei.line(), ei.col(), ei.getPath(), (ei.definition == null) || (ei.sliceindex >= lastSlice) || isXmlAttr, I18nConstants.VALIDATION_VAL_PROFILE_SLICEORDER, profile.getUrl(), ei.getName());
if (ei.definition == null || !isXmlAttr) }
if (ei.definition == null || !isXmlAttr) {
last = ei.index; last = ei.index;
if (ei.slice != null) }
if (ei.slice != null) {
lastSlice = ei.sliceindex; lastSlice = ei.sliceindex;
else } else {
lastSlice = -1; lastSlice = -1;
}
} }
return problematicPaths; return problematicPaths;
} }