Merge pull request #1259 from hapifhir/Type-validation-fixes

Fix problem when profiling a base type that supports both Reference a…
This commit is contained in:
Grahame Grieve 2023-06-19 02:36:33 +10:00 committed by GitHub
commit 96cadbed47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 28 deletions

View File

@ -2679,29 +2679,31 @@ public class ProfileUtilities extends TranslatingUtilities {
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
String t = ts.getWorkingCode();
for (TypeRefComponent td : base.getType()) {;
boolean matchType = false;
String tt = td.getWorkingCode();
b.append(tt);
if (td.hasCode() && (tt.equals(t))) {
ok = true;
matchType = true;
}
if (!ok) {
if (!matchType) {
StructureDefinition sdt = context.fetchTypeDefinition(tt);
if (sdt != null && (sdt.getAbstract() || sdt.getKind() == StructureDefinitionKind.LOGICAL)) {
StructureDefinition sdb = context.fetchTypeDefinition(t);
while (sdb != null && !ok) {
ok = sdb.getType().equals(sdt.getType());
while (sdb != null && !matchType) {
matchType = sdb.getType().equals(sdt.getType());
sdb = context.fetchResource(StructureDefinition.class, sdb.getBaseDefinition(), sdb);
}
}
}
// work around for old badly generated SDs
if (DONT_DO_THIS && Utilities.existsInList(tt, "Extension", "uri", "string", "Element")) {
ok = true;
matchType = true;
}
if (DONT_DO_THIS && Utilities.existsInList(tt, "Resource","DomainResource") && pkp.isResource(t)) {
ok = true;
matchType = true;
}
if (ok && ts.hasTargetProfile()) {
if (matchType) {
if (ts.hasTargetProfile()) {
// check that any derived target has a reference chain back to one of the base target profiles
for (UriType u : ts.getTargetProfile()) {
String url = u.getValue();
@ -2719,7 +2721,9 @@ public class ProfileUtilities extends TranslatingUtilities {
tgtOk = td.hasTargetProfile(url);
}
}
if (!tgtOk) {
if (tgtOk)
ok = true;
else {
if (messages == null) {
throw new FHIRException(context.formatMessage(I18nConstants.ERROR_AT__THE_TARGET_PROFILE__IS_NOT__VALID_CONSTRAINT_ON_THE_BASE_, purl, derived.getPath(), url, td.getTargetProfile()));
} else {
@ -2727,6 +2731,9 @@ public class ProfileUtilities extends TranslatingUtilities {
}
}
}
} else {
ok = true;
}
}
}
if (!ok) {