From 0ba9061e0b6e6c7b2f8a289ad9f7c4b55b70773a Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 27 Sep 2019 08:49:44 +1000 Subject: [PATCH] fixes to snapshot generation --- .../fhir/r5/conformance/ProfileUtilities.java | 14 +++++++---- .../hl7/fhir/r5/model/ElementDefinition.java | 16 ++++++++++++ .../snapshot-generation/t11-expected.xml | 25 ++++++++----------- .../snapshot-generation/t11-input.xml | 2 +- .../snapshot-generation/t4a-expected.xml | 4 +-- .../snapshot-generation/t4a-input.xml | 4 +-- 6 files changed, 41 insertions(+), 24 deletions(-) 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 6e5e135a7..8dd51e2cc 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 @@ -1295,7 +1295,8 @@ public class ProfileUtilities extends TranslatingUtilities { if (usage.hasBinding()) res.setBinding(usage.getBinding().copy()); for (ElementDefinitionConstraintComponent c : usage.getConstraint()) - res.addConstraint(c); + if (!res.hasConstraint(c.getKey())) + res.addConstraint(c); for (Extension e : usage.getExtension()) { if (!res.hasExtension(e.getUrl())) res.addExtension(e.copy()); @@ -1971,13 +1972,16 @@ public class ProfileUtilities extends TranslatingUtilities { s.setSource(base.getId()); } if (derived.hasConstraint()) { - for (ElementDefinitionConstraintComponent s : derived.getConstraint()) { - ElementDefinitionConstraintComponent inv = s.copy(); - base.getConstraint().add(inv); + for (ElementDefinitionConstraintComponent s : derived.getConstraint()) { + if (!base.hasConstraint(s.getKey())) { + ElementDefinitionConstraintComponent inv = s.copy(); + base.getConstraint().add(inv); + } } } for (IdType id : derived.getCondition()) { - base.getCondition().add(id); + if (!base.hasCondition(id)) + base.getCondition().add(id); } // now, check that we still have a bindable type; if not, delete the binding - see task 8477 diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/ElementDefinition.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/ElementDefinition.java index 138ccf3ae..3d816f984 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/ElementDefinition.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/ElementDefinition.java @@ -7576,6 +7576,22 @@ When pattern[x] is used to constrain a complex object, it means that each proper public String present() { return hasId() ? getId() : getPath(); + } + + public boolean hasCondition(IdType id) { + for (IdType c : getCondition()) { + if (c.primitiveValue().equals(id.primitiveValue())) + return true; + } + return false; + } + + public boolean hasConstraint(String key) { + for (ElementDefinitionConstraintComponent c : getConstraint()) { + if (c.getKey().equals(key)) + return true; + } + return false; } diff --git a/org.hl7.fhir.r5/src/test/resources/snapshot-generation/t11-expected.xml b/org.hl7.fhir.r5/src/test/resources/snapshot-generation/t11-expected.xml index dcb13c4cb..cb66ff129 100644 --- a/org.hl7.fhir.r5/src/test/resources/snapshot-generation/t11-expected.xml +++ b/org.hl7.fhir.r5/src/test/resources/snapshot-generation/t11-expected.xml @@ -36,8 +36,13 @@ - ..3 - + + 0.. + 3 + + + Extension + Slice: Unordered, Open by value:url @@ -362,8 +367,8 @@ - - + + @@ -373,7 +378,7 @@ - + @@ -393,14 +398,6 @@ - - - - - - - - @@ -1602,7 +1599,7 @@ - + diff --git a/org.hl7.fhir.r5/src/test/resources/snapshot-generation/t11-input.xml b/org.hl7.fhir.r5/src/test/resources/snapshot-generation/t11-input.xml index 6ac5ad60c..3e7a13536 100644 --- a/org.hl7.fhir.r5/src/test/resources/snapshot-generation/t11-input.xml +++ b/org.hl7.fhir.r5/src/test/resources/snapshot-generation/t11-input.xml @@ -38,7 +38,7 @@ - + diff --git a/org.hl7.fhir.r5/src/test/resources/snapshot-generation/t4a-expected.xml b/org.hl7.fhir.r5/src/test/resources/snapshot-generation/t4a-expected.xml index 80abdfd5f..34ddf43bb 100644 --- a/org.hl7.fhir.r5/src/test/resources/snapshot-generation/t4a-expected.xml +++ b/org.hl7.fhir.r5/src/test/resources/snapshot-generation/t4a-expected.xml @@ -1,7 +1,7 @@ - +
@@ -53,7 +53,7 @@
- + diff --git a/org.hl7.fhir.r5/src/test/resources/snapshot-generation/t4a-input.xml b/org.hl7.fhir.r5/src/test/resources/snapshot-generation/t4a-input.xml index 24901e98d..477d75522 100644 --- a/org.hl7.fhir.r5/src/test/resources/snapshot-generation/t4a-input.xml +++ b/org.hl7.fhir.r5/src/test/resources/snapshot-generation/t4a-input.xml @@ -1,9 +1,9 @@ - + - +