Fix problem when profiling a base type that supports both Reference and canonical

This commit is contained in:
Lloyd McKenzie 2023-05-11 21:54:48 -05:00
parent 91de165e2c
commit 8c494278f4
1 changed files with 35 additions and 28 deletions

View File

@ -2396,29 +2396,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();
@ -2436,7 +2438,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 {
@ -2444,6 +2448,9 @@ public class ProfileUtilities extends TranslatingUtilities {
}
}
}
} else {
ok = true;
}
}
}
if (!ok) {