From 0a3cc93c2fa500b6ae9a9b83f3cba9fa78342527 Mon Sep 17 00:00:00 2001 From: Louis Rolland Date: Wed, 11 Aug 2021 10:08:45 +0200 Subject: [PATCH 1/3] fix: #555 Handling minValue/maxValue in generate snapshot process --- .../fhir/dstu2/utils/ProfileUtilities.java | 76 ++++++++++++------- .../dstu2016may/utils/ProfileUtilities.java | 76 ++++++++++++------- .../dstu3/conformance/ProfileUtilities.java | 76 ++++++++++++------- .../fhir/r4/conformance/ProfileUtilities.java | 76 ++++++++++++------- .../fhir/r5/conformance/ProfileUtilities.java | 76 ++++++++++++------- 5 files changed, 235 insertions(+), 145 deletions(-) diff --git a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/ProfileUtilities.java b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/ProfileUtilities.java index 27ce8a7b0..e7f127b80 100644 --- a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/ProfileUtilities.java +++ b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/ProfileUtilities.java @@ -1,33 +1,33 @@ package org.hl7.fhir.dstu2.utils; -/* - Copyright (c) 2011+, HL7, Inc. - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of HL7 nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - */ +/* + Copyright (c) 2011+, HL7, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of HL7 nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + */ import java.io.IOException; @@ -1009,6 +1009,24 @@ public class ProfileUtilities { else derived.getMaxLengthElement().setUserData(DERIVATION_EQUALS, true); } + + if (derived.hasMaxValue()) { + if (!Base.compareDeep(derived.getMaxValue(), base.getMaxValue(), false)) + base.setMaxValue(derived.getMaxValue().copy()); + else if (trimDifferential) + derived.setMaxValue(null); + else + derived.getMaxValue().setUserData(DERIVATION_EQUALS, true); + } + + if (derived.hasMinValue()) { + if (!Base.compareDeep(derived.getMinValue(), base.getMinValue(), false)) + base.setMinValue(derived.getMinValue().copy()); + else if (trimDifferential) + derived.setMinValue(null); + else + derived.getMinValue().setUserData(DERIVATION_EQUALS, true); + } // todo: what to do about conditions? // condition : id 0..* @@ -2157,4 +2175,4 @@ public class ProfileUtilities { //} -} \ No newline at end of file +} diff --git a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/ProfileUtilities.java b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/ProfileUtilities.java index 321cadcbb..5f671340f 100644 --- a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/ProfileUtilities.java +++ b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/ProfileUtilities.java @@ -1,33 +1,33 @@ package org.hl7.fhir.dstu2016may.utils; -/* - Copyright (c) 2011+, HL7, Inc. - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of HL7 nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - */ +/* + Copyright (c) 2011+, HL7, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of HL7 nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + */ import java.io.IOException; @@ -1010,6 +1010,24 @@ public class ProfileUtilities { else derived.getMaxLengthElement().setUserData(DERIVATION_EQUALS, true); } + + if (derived.hasMaxValue()) { + if (!Base.compareDeep(derived.getMaxValue(), base.getMaxValue(), false)) + base.setMaxValue(derived.getMaxValue().copy()); + else if (trimDifferential) + derived.setMaxValue(null); + else + derived.getMaxValue().setUserData(DERIVATION_EQUALS, true); + } + + if (derived.hasMinValue()) { + if (!Base.compareDeep(derived.getMinValue(), base.getMinValue(), false)) + base.setMinValue(derived.getMinValue().copy()); + else if (trimDifferential) + derived.setMinValue(null); + else + derived.getMinValue().setUserData(DERIVATION_EQUALS, true); + } // todo: what to do about conditions? // condition : id 0..* @@ -2178,4 +2196,4 @@ public class ProfileUtilities { //} -} \ No newline at end of file +} diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/conformance/ProfileUtilities.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/conformance/ProfileUtilities.java index a497d3407..4d2b6fced 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/conformance/ProfileUtilities.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/conformance/ProfileUtilities.java @@ -1,33 +1,33 @@ package org.hl7.fhir.dstu3.conformance; -/* - Copyright (c) 2011+, HL7, Inc. - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of HL7 nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - */ +/* + Copyright (c) 2011+, HL7, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of HL7 nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + */ import java.io.IOException; @@ -1336,6 +1336,24 @@ public class ProfileUtilities extends TranslatingUtilities { else derived.getMaxLengthElement().setUserData(DERIVATION_EQUALS, true); } + + if (derived.hasMaxValue()) { + if (!Base.compareDeep(derived.getMaxValue(), base.getMaxValue(), false)) + base.setMaxValue(derived.getMaxValue().copy()); + else if (trimDifferential) + derived.setMaxValue(null); + else + derived.getMaxValue().setUserData(DERIVATION_EQUALS, true); + } + + if (derived.hasMinValue()) { + if (!Base.compareDeep(derived.getMinValue(), base.getMinValue(), false)) + base.setMinValue(derived.getMinValue().copy()); + else if (trimDifferential) + derived.setMinValue(null); + else + derived.getMinValue().setUserData(DERIVATION_EQUALS, true); + } // todo: what to do about conditions? // condition : id 0..* @@ -3681,4 +3699,4 @@ public class ProfileUtilities extends TranslatingUtilities { -} \ No newline at end of file +} diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileUtilities.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileUtilities.java index ce4c12493..76412361f 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileUtilities.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileUtilities.java @@ -1,33 +1,33 @@ package org.hl7.fhir.r4.conformance; -/* - Copyright (c) 2011+, HL7, Inc. - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of HL7 nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - */ +/* + Copyright (c) 2011+, HL7, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of HL7 nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + */ import java.io.IOException; @@ -1840,6 +1840,24 @@ public class ProfileUtilities extends TranslatingUtilities { else derived.getMaxLengthElement().setUserData(DERIVATION_EQUALS, true); } + + if (derived.hasMaxValue()) { + if (!Base.compareDeep(derived.getMaxValue(), base.getMaxValue(), false)) + base.setMaxValue(derived.getMaxValue().copy()); + else if (trimDifferential) + derived.setMaxValue(null); + else + derived.getMaxValue().setUserData(DERIVATION_EQUALS, true); + } + + if (derived.hasMinValue()) { + if (!Base.compareDeep(derived.getMinValue(), base.getMinValue(), false)) + base.setMinValue(derived.getMinValue().copy()); + else if (trimDifferential) + derived.setMinValue(null); + else + derived.getMinValue().setUserData(DERIVATION_EQUALS, true); + } // todo: what to do about conditions? // condition : id 0..* @@ -4753,4 +4771,4 @@ public class ProfileUtilities extends TranslatingUtilities { -} \ No newline at end of file +} 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 5a9d75ddd..729137e4c 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 @@ -4,34 +4,34 @@ import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; -/* - Copyright (c) 2011+, HL7, Inc. - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of HL7 nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - */ +/* + Copyright (c) 2011+, HL7, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of HL7 nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + */ import java.io.IOException; @@ -2826,6 +2826,24 @@ public class ProfileUtilities extends TranslatingUtilities { else derived.getMaxLengthElement().setUserData(DERIVATION_EQUALS, true); } + + if (derived.hasMaxValue()) { + if (!Base.compareDeep(derived.getMaxValue(), base.getMaxValue(), false)) + base.setMaxValue(derived.getMaxValue().copy()); + else if (trimDifferential) + derived.setMaxValue(null); + else + derived.getMaxValue().setUserData(DERIVATION_EQUALS, true); + } + + if (derived.hasMinValue()) { + if (!Base.compareDeep(derived.getMinValue(), base.getMinValue(), false)) + base.setMinValue(derived.getMinValue().copy()); + else if (trimDifferential) + derived.setMinValue(null); + else + derived.getMinValue().setUserData(DERIVATION_EQUALS, true); + } // todo: what to do about conditions? // condition : id 0..* @@ -6595,4 +6613,4 @@ public class ProfileUtilities extends TranslatingUtilities { return getElementById(structure, structure.getSnapshot().getElement(), element.getContentReference()); } -} \ No newline at end of file +} From daaa027f6686b674e33e42cf389edf13261bb489 Mon Sep 17 00:00:00 2001 From: Louis Rolland Date: Wed, 18 Aug 2021 10:53:57 +0200 Subject: [PATCH 2/3] test: #555 Handling minValue/maxValue in generation snapshot process --- .../fhir/r5/test/ProfileUtilitiesTests.java | 241 +++++++++++------- 1 file changed, 150 insertions(+), 91 deletions(-) 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 0c53d558b..d1bf6def0 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 @@ -1,27 +1,21 @@ package org.hl7.fhir.r5.test; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.fhir.ucum.UcumException; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r5.conformance.ProfileUtilities; -import org.hl7.fhir.r5.formats.IParser.OutputStyle; -import org.hl7.fhir.r5.formats.XmlParser; import org.hl7.fhir.r5.model.Base; import org.hl7.fhir.r5.model.ElementDefinition; +import org.hl7.fhir.r5.model.IntegerType; import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule; import org.hl7.fhir.r5.test.utils.TestingUtilities; -import org.hl7.fhir.r5.utils.EOperationOutcome; -import org.hl7.fhir.utilities.CSFile; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.validation.ValidationMessage; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.ArrayList; +import java.util.List; + public class ProfileUtilitiesTests { // /** @@ -32,7 +26,7 @@ public class ProfileUtilitiesTests { // * @throws EOperationOutcome // */ @Test - public void testSimple() throws FHIRException, FileNotFoundException, IOException, UcumException { + public void testSimple() throws FHIRException { StructureDefinition focus = new StructureDefinition(); StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy(); @@ -40,7 +34,7 @@ public class ProfileUtilitiesTests { focus.setBaseDefinition(base.getUrl()); focus.setType("Patient"); focus.setDerivation(TypeDerivationRule.CONSTRAINT); - List messages = new ArrayList(); + List messages = new ArrayList<>(); new ProfileUtilities(TestingUtilities.context(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://test.org/test", "Simple Test"); boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size(); @@ -62,11 +56,7 @@ public class ProfileUtilitiesTests { } } - if (!ok) { - compareXml(base, focus); - throw new FHIRException("Snap shot generation simple test failed"); - } else - System.out.println("Snap shot generation simple test passed"); + Assertions.assertTrue(ok); } @@ -79,13 +69,13 @@ public class ProfileUtilitiesTests { // * @throws EOperationOutcome // */ @Test - public void testSimple2() throws EOperationOutcome, Exception { + public void testSimple2() { StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/ValueSet").copy(); StructureDefinition focus = base.copy(); focus.setUrl(Utilities.makeUuidUrn()); focus.setSnapshot(null); focus.setDifferential(null); - List messages = new ArrayList(); + List messages = new ArrayList<>(); new ProfileUtilities(TestingUtilities.context(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://test.org", "Simple Test"); boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size(); @@ -111,59 +101,147 @@ public class ProfileUtilitiesTests { } } - if (!ok) { - compareXml(base, focus); - System.out.println("Snap shot generation simple test failed"); - throw new FHIRException("Snap shot generation simple test failed"); - } else - System.out.println("Snap shot generation simple test passed"); + Assertions.assertTrue(ok); + } + + /** + * Change one cardinality. + */ + @Test + void testCardinalityChange() { + StructureDefinition focus = new StructureDefinition(); + StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy(); + focus.setUrl(Utilities.makeUuidUrn()); + focus.setBaseDefinition(base.getUrl()); + focus.setType(base.getType()); + focus.setDerivation(TypeDerivationRule.CONSTRAINT); + ElementDefinition id = focus.getDifferential().addElement(); + id.setPath("Patient.identifier"); + id.setMin(1); + List messages = new ArrayList<>(); + new ProfileUtilities(TestingUtilities.context(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://test.org", "Simple Test"); + + boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size(); + for (int i = 0; i < base.getSnapshot().getElement().size(); i++) { + if (ok) { + ElementDefinition b = base.getSnapshot().getElement().get(i); + ElementDefinition f = focus.getSnapshot().getElement().get(i); + b.setRequirements(null); + f.setRequirements(null); + if (!f.hasBase() || !b.getPath().equals(f.getPath())) { + ok = false; + } + else { + if (f.getPath().equals("Patient.identifier")) { + ok = f.getMin() == 1; + if (ok) { + f.setMin(0); + } + } + if (!Base.compareDeep(b, f, true)) { + ok = Base.compareDeep(b, f, true); + } + } + } + } + + Assertions.assertTrue(ok); + } + + /** + * Change min value + */ + @Test + void testMinValueChange() { + // Given + StructureDefinition focus = new StructureDefinition(); + StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Appointment").copy(); + focus.setUrl(Utilities.makeUuidUrn()); + focus.setBaseDefinition(base.getUrl()); + focus.setType(base.getType()); + focus.setDerivation(TypeDerivationRule.CONSTRAINT); + ElementDefinition id = focus.getDifferential().addElement(); + id.setPath("Appointment.minutesDuration"); + id.setMinValue(new IntegerType(1)); + List messages = new ArrayList<>(); + // When + new ProfileUtilities(TestingUtilities.context(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://test.org", "Simple Test"); + // Then + boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size(); + for (int i = 0; i < base.getSnapshot().getElement().size(); i++) { + if (ok) { + ElementDefinition b = base.getSnapshot().getElement().get(i); + ElementDefinition f = focus.getSnapshot().getElement().get(i); + b.setRequirements(null); + f.setRequirements(null); + if (!f.hasBase() || !b.getPath().equals(f.getPath())) { + ok = false; + } + else { + if (f.getPath().equals("Appointment.minutesDuration")) { + ok = f.getMinValue() instanceof IntegerType && ((IntegerType) f.getMinValue()).getValue() == 1; + if (ok) { + // Can't set minValue to null so change base minValue to IntegerType(1) + b.setMinValue(new IntegerType(1)); + } + } + if (!Base.compareDeep(b, f, true)) { + ok = false; + } + } + } + } + + Assertions.assertTrue(ok); + } + + /** + * Change max value + */ + @Test + void testMaxValueChange() { + // Given + StructureDefinition focus = new StructureDefinition(); + StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Appointment").copy(); + focus.setUrl(Utilities.makeUuidUrn()); + focus.setBaseDefinition(base.getUrl()); + focus.setType(base.getType()); + focus.setDerivation(TypeDerivationRule.CONSTRAINT); + ElementDefinition id = focus.getDifferential().addElement(); + id.setPath("Appointment.minutesDuration"); + id.setMaxValue(new IntegerType(1)); + List messages = new ArrayList<>(); + // When + new ProfileUtilities(TestingUtilities.context(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://test.org", "Simple Test"); + // Then + boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size(); + for (int i = 0; i < base.getSnapshot().getElement().size(); i++) { + if (ok) { + ElementDefinition b = base.getSnapshot().getElement().get(i); + ElementDefinition f = focus.getSnapshot().getElement().get(i); + b.setRequirements(null); + f.setRequirements(null); + if (!f.hasBase() || !b.getPath().equals(f.getPath())) { + ok = false; + } + else { + if (f.getPath().equals("Appointment.minutesDuration")) { + ok = f.getMaxValue() instanceof IntegerType && ((IntegerType) f.getMaxValue()).getValue() == 1; + if (ok) { + // Can't set maxValue to null so change base maxValue to IntegerType(1) + b.setMaxValue(new IntegerType(1)); + } + } + if (!Base.compareDeep(b, f, true)) { + ok = false; + } + } + } + } + + Assertions.assertTrue(ok); } -// /** -// * Change one cardinality. -// * -// * @param context2 -// * @ -// * @throws EOperationOutcome -// */ -// private void testCardinalityChange() throws EOperationOutcome, Exception { -// StructureDefinition focus = new StructureDefinition(); -// StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy(); -// focus.setUrl(Utilities.makeUuidUrn()); -// focus.setBaseDefinition(base.getUrl()); -// focus.setType(base.getType()); -// focus.setDerivation(TypeDerivationRule.CONSTRAINT); -// ElementDefinition id = focus.getDifferential().addElement(); -// id.setPath("Patient.identifier"); -// id.setMin(1); -// List messages = new ArrayList(); -// new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" ); -// -// boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size(); -// for (int i = 0; i < base.getSnapshot().getElement().size(); i++) { -// if (ok) { -// ElementDefinition b = base.getSnapshot().getElement().get(i); -// ElementDefinition f = focus.getSnapshot().getElement().get(i); -// if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath())) -// ok = false; -// else { -// f.setBase(null); -// if (f.getPath().equals("Patient.identifier")) { -// ok = f.getMin() == 1; -// if (ok) -// f.setMin(0); -// } -// ok = ok && Base.compareDeep(b, f, true); -// } -// } -// } -// -// if (!ok) { -// compareXml(base, focus); -// throw new FHIRException("Snap shot generation chenge cardinality test failed"); -// } else -// System.out.println("Snap shot generation chenge cardinality test passed"); -// } // // /** // * check that documentation appending is working @@ -794,23 +872,4 @@ public class ProfileUtilitiesTests { // } // - private void compareXml(StructureDefinition base, StructureDefinition focus) throws FileNotFoundException, IOException { - base.setText(null); - focus.setText(null); - base.setDifferential(null); -// focus.setDifferential(null); - String f1 = Utilities.path("c:", "temp", "base.xml"); - String f2 = Utilities.path("c:", "temp", "derived.xml"); - new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(f1), base); - ; - new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(f2), focus); - ; - String diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge", "WinMergeU.exe"); - List command = new ArrayList(); - command.add("\"" + diff + "\" \"" + f1 + "\" \"" + f2 + "\""); - - ProcessBuilder builder = new ProcessBuilder(command); - builder.directory(new CSFile("c:\\temp")); - builder.start(); - } -} \ No newline at end of file +} From a90d8cb1691fb627a80f0e9bad7a50117f690ce8 Mon Sep 17 00:00:00 2001 From: Louis Rolland Date: Wed, 18 Aug 2021 10:54:17 +0200 Subject: [PATCH 3/3] fix: #555 Add release note --- RELEASE_NOTES.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 377191606..83609fe74 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,6 +1,7 @@ -* Conversion context added to conversions process -* Users can now define custom behavior for CodeSystems, Extensions, BundleEntries, and Types by extending BaseAdvisor. -* Resource Conversions are now thread-safe, each using their own instance of the conversion context that is unique -* ConversionFactory classes are statically accessed, to minimize changes downstream -* I need to add more tests, there were very few to begin with, and it's my next task -* All conversion libraries and no play makes Mark a dull boy +* Differential element fields minValue/maxValue are now correctly treated in the snapshot generation process +* Conversion context added to conversions process +* Users can now define custom behavior for CodeSystems, Extensions, BundleEntries, and Types by extending BaseAdvisor. +* Resource Conversions are now thread-safe, each using their own instance of the conversion context that is unique +* ConversionFactory classes are statically accessed, to minimize changes downstream +* I need to add more tests, there were very few to begin with, and it's my next task +* All conversion libraries and no play makes Mark a dull boy