Fix handling resources in bundles when type is profiled

This commit is contained in:
Grahame Grieve 2020-09-17 15:45:47 +10:00
parent e33ffca749
commit fa778fbf03
2 changed files with 13 additions and 8 deletions

View File

@ -10,8 +10,8 @@ Bundle_BUNDLE_Entry_NoFullUrl = Bundle entry missing fullUrl
Bundle_BUNDLE_Entry_NoProfile = No profile found for contained resource of type ''{0}''
Bundle_BUNDLE_Entry_NotFound = Can''t find ''{0}'' in the bundle ({1})
Bundle_BUNDLE_Entry_Orphan = Entry {0} isn''t reachable by traversing from first Bundle entry
Bundle_BUNDLE_Entry_Type = The type ''{0}'' is not valid - no resources allowed here
Bundle_BUNDLE_Entry_Type2 = The type ''{0}'' is not valid - must be {1}
Bundle_BUNDLE_Entry_Type = The type ''{0}'' is not valid - no resources allowed here (allowed = {1})
Bundle_BUNDLE_Entry_Type2 = The type ''{0}'' is not valid - must be {1} (allowed = {2})
Bundle_BUNDLE_Entry_Type3 = The type ''{0}'' is not valid - must be one of {1}
Bundle_BUNDLE_FullUrl_Missing = Relative Reference appears inside Bundle whose entry is missing a fullUrl
Bundle_BUNDLE_FullUrl_NeedVersion = Entries matching fullURL {0} should declare meta/versionId because there are version-specific references
@ -156,9 +156,9 @@ Terminology_TX_NoValid_17 = The value provided (''{0}'') is not in the value set
Terminology_TX_NoValid_18 = The value provided (''{0}'') is not in the value set {1} ({2}), and a code is recommended to come from this value set){3}
Terminology_TX_NoValid_2 = None of the codes provided are in the value set {0} ({1}), and a code should come from this value set unless it has no suitable code) (codes = {2})
Terminology_TX_NoValid_3 = None of the codes provided are in the value set {0} ({1}), and a code is recommended to come from this value set) (codes = {2})
Terminology_TX_NoValid_4 = The Coding provided ({2}) is not in the value set {0}, and a code is required from this value set{1}
Terminology_TX_NoValid_5 = The Coding provided ({2}) is not in the value set {0}, and a code should come from this value set unless it has no suitable code{1}
Terminology_TX_NoValid_6 = The Coding provided ({2}) is not in the value set {0}, and a code is recommended to come from this value set{1}
Terminology_TX_NoValid_4 = The Coding provided ({2}) is not in the value set {0}, and a code is required from this value set {1}
Terminology_TX_NoValid_5 = The Coding provided ({2}) is not in the value set {0}, and a code should come from this value set unless it has no suitable code {1}
Terminology_TX_NoValid_6 = The Coding provided ({2}) is not in the value set {0}, and a code is recommended to come from this value set {1}
Terminology_TX_NoValid_7 = None of the codes provided could be validated against the maximum value set {0} ({1}), (error = {2})
Terminology_TX_NoValid_8 = None of the codes provided are in the maximum value set {0} ({1}), and a code from this value set is required) (codes = {2})
Terminology_TX_NoValid_9 = The code provided could not be validated against the maximum value set {0} ({1}), (error = {2})

View File

@ -3943,15 +3943,17 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
private void validateContains(ValidatorHostContext hostContext, List<ValidationMessage> errors, String path, ElementDefinition child, ElementDefinition context, Element resource, Element element, NodeStack stack, IdStatus idstatus) throws FHIRException {
String resourceName = element.getType();
TypeRefComponent trr = null;
CommaSeparatedStringBuilder bt = new CommaSeparatedStringBuilder();
for (TypeRefComponent tr : child.getType()) {
if (tr.getCode().equals("Resource")) {
bt.append(tr.getCode());
if (tr.getCode().equals("Resource") || tr.getCode().equals(resourceName) ) {
trr = tr;
break;
}
}
stack.qualifyPath(".ofType("+resourceName+")");
if (trr == null) {
rule(errors, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), false, I18nConstants.BUNDLE_BUNDLE_ENTRY_TYPE, resourceName);
rule(errors, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), false, I18nConstants.BUNDLE_BUNDLE_ENTRY_TYPE, resourceName, bt.toString());
} else if (isValidResourceType(resourceName, trr)) {
// special case: resource wrapper is reset if we're crossing a bundle boundary, but not otherwise
ValidatorHostContext hc = null;
@ -4002,7 +4004,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
}
private boolean isValidResourceType(String type, TypeRefComponent def) {
if (!def.hasProfile()) {
if (!def.hasProfile() && def.getCode().equals("Resource")) {
return true;
}
if (def.getCode().equals(type)) {
return true;
}
List<StructureDefinition> list = new ArrayList<>();