diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java index a4a14c2bf..363155ca0 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java @@ -5170,11 +5170,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat ok = rule(errors, IssueType.INVALID, element.line(), element.col(), stack.addToLiteralPath(resourceName), defn != null, I18nConstants.VALIDATION_VAL_PROFILE_NODEFINITION, resourceName); } - String type = defn.getKind() == StructureDefinitionKind.LOGICAL ? defn.getName() : defn.getType(); // special case: we have a bundle, and the profile is not for a bundle. We'll try the first entry instead - if (!type.equals(resourceName) && resourceName.equals(BUNDLE)) { + if (!typeMatchesDefn(resourceName, defn) && resourceName.equals(BUNDLE)) { NodeStack first = getFirstEntry(stack); - if (first != null && first.getElement().getType().equals(type)) { + if (first != null && typeMatchesDefn(first.getElement().getType(), defn)) { element = first.getElement(); stack = first; resourceName = element.getType(); @@ -5182,7 +5181,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat } // todo: validate everything in this bundle. } - ok = rule(errors, IssueType.INVALID, -1, -1, stack.getLiteralPath(), type.equals(resourceName), I18nConstants.VALIDATION_VAL_PROFILE_WRONGTYPE, type, resourceName); + ok = rule(errors, IssueType.INVALID, -1, -1, stack.getLiteralPath(), typeMatchesDefn(resourceName, defn), I18nConstants.VALIDATION_VAL_PROFILE_WRONGTYPE, defn.getName(), resourceName); if (ok) { if (idstatus == IdStatus.REQUIRED && (element.getNamedChild(ID) == null)) { @@ -5201,6 +5200,14 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat } } + private boolean typeMatchesDefn(String name, StructureDefinition defn) { + if (defn.getKind() == StructureDefinitionKind.LOGICAL) { + return name.equals(defn.getType()) || name.equals(defn.getName()) || name.equals(defn.getId()); + } else { + return name.matches(defn.getType()); + } + } + private NodeStack getFirstEntry(NodeStack bundle) { List list = new ArrayList(); bundle.getElement().getNamedChildren(ENTRY, list);