From 236cf0694670e865bab74e9c4cac8b743285ea7f Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 29 Jun 2023 13:17:15 +1000 Subject: [PATCH] Handle case where base hasn't got a snapshot generating snapshots --- .../conformance/profile/ProfilePathProcessor.java | 11 ++++++++--- .../r5/conformance/profile/ProfileUtilities.java | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfilePathProcessor.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfilePathProcessor.java index ac0c54a6c..62029741d 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfilePathProcessor.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfilePathProcessor.java @@ -134,7 +134,7 @@ public class ProfilePathProcessor { null); - getInstance(profileUtilities) + getInstance(profileUtilities) .withResult(derived.getSnapshot()) .withDifferential(differential) .withBaseLimit(baseSnapshot.getElement().size() - 1) @@ -607,8 +607,13 @@ public class ProfilePathProcessor { } if (src == null) throw new DefinitionException(profileUtilities.getContext().formatMessage(I18nConstants.UNABLE_TO_FIND_ELEMENT__IN_, eid, firstTypeProfile.getValue())); - } else - src = firstTypeStructureDefinition.getSnapshot().getElement().get(0); + } 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); + } + } template = src.copy().setPath(currentBase.getPath()); template.setSliceName(null); // temporary work around diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java index de9cb3882..a03030508 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java @@ -621,7 +621,14 @@ public class ProfileUtilities extends TranslatingUtilities { 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())); } + 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); if (snapshotStack.contains(derived.getUrl())) { @@ -810,7 +817,7 @@ public class ProfileUtilities extends TranslatingUtilities { } 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(); - 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); } @@ -2289,7 +2296,7 @@ public class ProfileUtilities extends TranslatingUtilities { } if (profile==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; } } @@ -4379,4 +4386,8 @@ public class ProfileUtilities extends TranslatingUtilities { return messages; } + public static boolean isResourceBoundary(ElementDefinition ed) { + return ed.getType().size() == 1 && "Resource".equals(ed.getTypeFirstRep().getCode()); + } + }