From d7754a321f30bb647c603c231b2fcdaf24828e44 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 9 Mar 2022 17:36:39 +1100 Subject: [PATCH] Fix snapshot generation - always populate constraint source properly --- .../fhir/r5/conformance/ProfileUtilities.java | 15 +++++++++ .../fhir/r5/test/ProfileUtilitiesTests.java | 31 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java index 26aeb35e0..55caa008f 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java @@ -1091,6 +1091,7 @@ public class ProfileUtilities extends TranslatingUtilities { ElementDefinition outcome = updateURLs(url, webUrl, currentBase.copy()); outcome.setPath(fixedPathDest(contextPathDst, outcome.getPath(), redirector, contextPathSrc)); updateFromBase(outcome, currentBase); + updateConstraintSources(outcome, srcSD.getUrl()); markDerived(outcome); if (resultPathBase == null) resultPathBase = outcome.getPath(); @@ -1927,6 +1928,15 @@ public class ProfileUtilities extends TranslatingUtilities { return res; } + private void updateConstraintSources(ElementDefinition ed, String url) { + for (ElementDefinitionConstraintComponent c : ed.getConstraint()) { + if (!c.hasSource()) { + c.setSource(url); + } + } + + } + private Set getListOfTypes(ElementDefinition e) { Set result = new HashSet<>(); for (TypeRefComponent t : e.getType()) { @@ -2422,6 +2432,11 @@ public class ProfileUtilities extends TranslatingUtilities { StructureDefinition sd = null; if (type.hasProfile()) { sd = context.fetchResource(StructureDefinition.class, type.getProfile().get(0).getValue()); + if (sd == null) { + if (xver != null && xver.matchingUrl(type.getProfile().get(0).getValue()) && xver.status(type.getProfile().get(0).getValue()) == XVerExtensionStatus.Valid) { + sd = xver.makeDefinition(type.getProfile().get(0).getValue()); + } + } if (sd == null) System.out.println("Failed to find referenced profile: " + type.getProfile()); } diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ProfileUtilitiesTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ProfileUtilitiesTests.java index e5a62e947..c7e650f8e 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ProfileUtilitiesTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ProfileUtilitiesTests.java @@ -7,6 +7,7 @@ import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r5.conformance.ProfileUtilities; import org.hl7.fhir.r5.model.Base; import org.hl7.fhir.r5.model.ElementDefinition; +import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent; import org.hl7.fhir.r5.model.IntegerType; import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule; @@ -51,6 +52,12 @@ public class ProfileUtilitiesTests { f.setBase(null); b.setRequirements(null); f.setRequirements(null); + for (ElementDefinitionConstraintComponent c : b.getConstraint()) { + c.setSource(null); + } + for (ElementDefinitionConstraintComponent c : f.getConstraint()) { + c.setSource(null); + } ok = Base.compareDeep(b, f, true); } } @@ -83,6 +90,12 @@ public class ProfileUtilitiesTests { if (ok) { ElementDefinition b = base.getSnapshot().getElement().get(i); ElementDefinition f = focus.getSnapshot().getElement().get(i); + for (ElementDefinitionConstraintComponent c : b.getConstraint()) { + c.setSource(null); + } + for (ElementDefinitionConstraintComponent c : f.getConstraint()) { + c.setSource(null); + } if (!f.hasBase() || !b.getPath().equals(f.getPath())) ok = false; else { @@ -128,6 +141,12 @@ public class ProfileUtilitiesTests { ElementDefinition f = focus.getSnapshot().getElement().get(i); b.setRequirements(null); f.setRequirements(null); + for (ElementDefinitionConstraintComponent c : b.getConstraint()) { + c.setSource(null); + } + for (ElementDefinitionConstraintComponent c : f.getConstraint()) { + c.setSource(null); + } if (!f.hasBase() || !b.getPath().equals(f.getPath())) { ok = false; } @@ -174,6 +193,12 @@ public class ProfileUtilitiesTests { ElementDefinition f = focus.getSnapshot().getElement().get(i); b.setRequirements(null); f.setRequirements(null); + for (ElementDefinitionConstraintComponent c : b.getConstraint()) { + c.setSource(null); + } + for (ElementDefinitionConstraintComponent c : f.getConstraint()) { + c.setSource(null); + } if (!f.hasBase() || !b.getPath().equals(f.getPath())) { ok = false; } @@ -221,6 +246,12 @@ public class ProfileUtilitiesTests { ElementDefinition f = focus.getSnapshot().getElement().get(i); b.setRequirements(null); f.setRequirements(null); + for (ElementDefinitionConstraintComponent c : b.getConstraint()) { + c.setSource(null); + } + for (ElementDefinitionConstraintComponent c : f.getConstraint()) { + c.setSource(null); + } if (!f.hasBase() || !b.getPath().equals(f.getPath())) { ok = false; }