Handle case where base hasn't got a snapshot generating snapshots

This commit is contained in:
Grahame Grieve 2023-06-29 13:17:15 +10:00
parent 2cdd92868b
commit 236cf06946
2 changed files with 21 additions and 5 deletions

View File

@ -607,8 +607,13 @@ public class ProfilePathProcessor {
} }
if (src == null) if (src == null)
throw new DefinitionException(profileUtilities.getContext().formatMessage(I18nConstants.UNABLE_TO_FIND_ELEMENT__IN_, eid, firstTypeProfile.getValue())); throw new DefinitionException(profileUtilities.getContext().formatMessage(I18nConstants.UNABLE_TO_FIND_ELEMENT__IN_, eid, firstTypeProfile.getValue()));
} else } else {
if (firstTypeStructureDefinition.getSnapshot().getElement().isEmpty()) {
throw new FHIRException(profileUtilities.getContext().formatMessage(I18nConstants.SNAPSHOT_IS_EMPTY, firstTypeStructureDefinition.getVersionedUrl(), "Source for first element"));
} else {
src = firstTypeStructureDefinition.getSnapshot().getElement().get(0); src = firstTypeStructureDefinition.getSnapshot().getElement().get(0);
}
}
template = src.copy().setPath(currentBase.getPath()); template = src.copy().setPath(currentBase.getPath());
template.setSliceName(null); template.setSliceName(null);
// temporary work around // temporary work around

View File

@ -621,7 +621,14 @@ public class ProfileUtilities extends TranslatingUtilities {
if (!base.getType().equals(derived.getType()) && derived.getDerivation() == TypeDerivationRule.CONSTRAINT) { if (!base.getType().equals(derived.getType()) && derived.getDerivation() == TypeDerivationRule.CONSTRAINT) {
throw new DefinitionException(context.formatMessage(I18nConstants.BASE__DERIVED_PROFILES_HAVE_DIFFERENT_TYPES____VS___, base.getUrl(), base.getType(), derived.getUrl(), derived.getType())); throw new DefinitionException(context.formatMessage(I18nConstants.BASE__DERIVED_PROFILES_HAVE_DIFFERENT_TYPES____VS___, base.getUrl(), base.getType(), derived.getUrl(), derived.getType()));
} }
if (!base.hasSnapshot()) {
StructureDefinition sdb = context.fetchResource(StructureDefinition.class, base.getBaseDefinition());
if (sdb == null)
throw new DefinitionException(context.formatMessage(I18nConstants.UNABLE_TO_FIND_BASE__FOR_, base.getBaseDefinition(), base.getUrl()));
checkNotGenerating(sdb, "an extension base");
generateSnapshot(sdb, base, base.getUrl(), (sdb.hasWebPath()) ? Utilities.extractBaseUrl(sdb.getWebPath()) : webUrl, base.getName());
}
fixTypeOfResourceId(base); fixTypeOfResourceId(base);
if (snapshotStack.contains(derived.getUrl())) { if (snapshotStack.contains(derived.getUrl())) {
@ -810,7 +817,7 @@ public class ProfileUtilities extends TranslatingUtilities {
} }
if (!slice.checkMinMax()) { if (!slice.checkMinMax()) {
String msg = "The slice definition for "+slice.getFocus().getId()+" has a maximum of "+slice.getFocus().getMax()+" which is less than the minimum of "+slice.getFocus().getMin(); String msg = "The slice definition for "+slice.getFocus().getId()+" has a maximum of "+slice.getFocus().getMax()+" which is less than the minimum of "+slice.getFocus().getMin();
messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.VALUE, url+"#"+slice.getFocus().getId(), msg, ValidationMessage.IssueSeverity.WARNING)); messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.VALUE, url+"#"+"#"+slice.getFocus().getId(), msg, ValidationMessage.IssueSeverity.WARNING));
} }
slices.remove(s); slices.remove(s);
} }
@ -2289,7 +2296,7 @@ public class ProfileUtilities extends TranslatingUtilities {
} }
if (profile==null) { if (profile==null) {
profile = source.getType().size() == 1 && source.getTypeFirstRep().hasProfile() ? context.fetchResource(StructureDefinition.class, source.getTypeFirstRep().getProfile().get(0).getValue(), derivedSrc) : null; profile = source.getType().size() == 1 && source.getTypeFirstRep().hasProfile() ? context.fetchResource(StructureDefinition.class, source.getTypeFirstRep().getProfile().get(0).getValue(), derivedSrc) : null;
if (profile != null && !"Extension".equals(profile.getType()) && profile.getKind() != StructureDefinitionKind.RESOURCE) { if (profile != null && !"Extension".equals(profile.getType()) && profile.getKind() != StructureDefinitionKind.RESOURCE && profile.getKind() != StructureDefinitionKind.LOGICAL) {
profile = null; profile = null;
} }
} }
@ -4379,4 +4386,8 @@ public class ProfileUtilities extends TranslatingUtilities {
return messages; return messages;
} }
public static boolean isResourceBoundary(ElementDefinition ed) {
return ed.getType().size() == 1 && "Resource".equals(ed.getTypeFirstRep().getCode());
}
} }