From 1c8797f628ece0df5097f28983ce5790773ee87b Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 28 Feb 2020 14:27:04 +1100 Subject: [PATCH 1/5] support slicing on patternCoding --- .../instance/InstanceValidator.java | 36 +++++++++++++++++++ pom.xml | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java index 93b597899..0f730aad3 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java @@ -3209,6 +3209,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat CodeableConcept cc = (CodeableConcept) pattern; expression.append(" and "); buildCodeableConceptExpression(ed, expression, discriminator, cc); + } else if (pattern instanceof Coding) { + Coding c = (Coding) pattern; + expression.append(" and "); + buildCodingExpression(ed, expression, discriminator, c); } else if (pattern instanceof Identifier) { Identifier ii = (Identifier) pattern; expression.append(" and "); @@ -3290,6 +3294,34 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat } } + private void buildCodingExpression(ElementDefinition ed, StringBuilder expression, String discriminator, Coding c) + throws DefinitionException { + if (c.hasExtension()) + throw new DefinitionException("Unsupported CodeableConcept pattern - extensions are not allowed - for discriminator(" + discriminator + ") for slice " + ed.getId()); + expression.append(discriminator + ".coding.where("); + boolean first = true; + if (c.hasSystem()) { + first = false; + expression.append("system = '" + c.getSystem() + "'"); + } + if (c.hasVersion()) { + if (first) first = false; + else expression.append(" and "); + expression.append("version = '" + c.getVersion() + "'"); + } + if (c.hasCode()) { + if (first) first = false; + else expression.append(" and "); + expression.append("code = '" + c.getCode() + "'"); + } + if (c.hasDisplay()) { + if (first) first = false; + else expression.append(" and "); + expression.append("display = '" + c.getDisplay() + "'"); + } + expression.append(").exists()"); + } + private void buildFixedExpression(ElementDefinition ed, StringBuilder expression, String discriminator, ElementDefinition criteriaElement) throws DefinitionException { DataType fixed = criteriaElement.getFixed(); if (fixed instanceof CodeableConcept) { @@ -3300,6 +3332,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat Identifier ii = (Identifier) fixed; expression.append(" and "); buildIdentifierExpression(ed, expression, discriminator, ii); + } else if (fixed instanceof Coding) { + Coding c = (Coding) fixed; + expression.append(" and "); + buildCodingExpression(ed, expression, discriminator, c); } else { expression.append(" and ("); if (fixed instanceof StringType) { diff --git a/pom.xml b/pom.xml index cef42f11a..34b9e5de2 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ 4.2.0 - 1.0.43-SNAPSHOT + 1.0.44-SNAPSHOT org.hl7.fhir.core From 4ab61c9c8c3f133b884d8c81162bbf6d19298bef Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 28 Feb 2020 14:27:52 +1100 Subject: [PATCH 2/5] Release new version 4.2.4 --- org.hl7.fhir.convertors/pom.xml | 2 +- org.hl7.fhir.dstu2/pom.xml | 2 +- org.hl7.fhir.dstu2016may/pom.xml | 2 +- org.hl7.fhir.dstu3/pom.xml | 2 +- org.hl7.fhir.r4/pom.xml | 2 +- org.hl7.fhir.r5/pom.xml | 2 +- org.hl7.fhir.utilities/pom.xml | 2 +- org.hl7.fhir.validation.cli/pom.xml | 2 +- org.hl7.fhir.validation/pom.xml | 2 +- pom.xml | 2 +- release.bat | 4 ++-- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/org.hl7.fhir.convertors/pom.xml b/org.hl7.fhir.convertors/pom.xml index 44f1561eb..386cb6075 100644 --- a/org.hl7.fhir.convertors/pom.xml +++ b/org.hl7.fhir.convertors/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 4.2.3-SNAPSHOT + 4.2.4-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.dstu2/pom.xml b/org.hl7.fhir.dstu2/pom.xml index 3d1359628..8798a7c21 100644 --- a/org.hl7.fhir.dstu2/pom.xml +++ b/org.hl7.fhir.dstu2/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 4.2.3-SNAPSHOT + 4.2.4-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.dstu2016may/pom.xml b/org.hl7.fhir.dstu2016may/pom.xml index 3860925ed..6526c67cb 100644 --- a/org.hl7.fhir.dstu2016may/pom.xml +++ b/org.hl7.fhir.dstu2016may/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 4.2.3-SNAPSHOT + 4.2.4-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.dstu3/pom.xml b/org.hl7.fhir.dstu3/pom.xml index 9c9bf14db..16696da7d 100644 --- a/org.hl7.fhir.dstu3/pom.xml +++ b/org.hl7.fhir.dstu3/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 4.2.3-SNAPSHOT + 4.2.4-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.r4/pom.xml b/org.hl7.fhir.r4/pom.xml index b35910da6..7b7343c5b 100644 --- a/org.hl7.fhir.r4/pom.xml +++ b/org.hl7.fhir.r4/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 4.2.3-SNAPSHOT + 4.2.4-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.r5/pom.xml b/org.hl7.fhir.r5/pom.xml index 5e15bd691..6f7557d32 100644 --- a/org.hl7.fhir.r5/pom.xml +++ b/org.hl7.fhir.r5/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 4.2.3-SNAPSHOT + 4.2.4-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.utilities/pom.xml b/org.hl7.fhir.utilities/pom.xml index 8fec8d5f6..158b125b3 100644 --- a/org.hl7.fhir.utilities/pom.xml +++ b/org.hl7.fhir.utilities/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 4.2.3-SNAPSHOT + 4.2.4-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.validation.cli/pom.xml b/org.hl7.fhir.validation.cli/pom.xml index 66d657b1a..ae7a2e26f 100644 --- a/org.hl7.fhir.validation.cli/pom.xml +++ b/org.hl7.fhir.validation.cli/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 4.2.3-SNAPSHOT + 4.2.4-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.validation/pom.xml b/org.hl7.fhir.validation/pom.xml index 2ec87b9e1..ca3de0043 100644 --- a/org.hl7.fhir.validation/pom.xml +++ b/org.hl7.fhir.validation/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 4.2.3-SNAPSHOT + 4.2.4-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index 34b9e5de2..18eca1e2e 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ each other. It is fine to bump the point version of this POM without affecting HAPI FHIR. --> - 4.2.3-SNAPSHOT + 4.2.4-SNAPSHOT 4.2.0 diff --git a/release.bat b/release.bat index 0017128e6..36d29b406 100644 --- a/release.bat +++ b/release.bat @@ -1,7 +1,7 @@ @echo off -set oldver=4.2.2 -set newver=4.2.3 +set oldver=4.2.3 +set newver=4.2.4 echo .. echo ========================================================================= From a3d7acdf351d43bdd8fa1c4211af51b0ce4a3354 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 28 Feb 2020 15:16:44 +1100 Subject: [PATCH 3/5] Release new version 4.2.4 --- .../org/hl7/fhir/validation/instance/InstanceValidator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java index 0f730aad3..942bd2c16 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java @@ -3298,7 +3298,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat throws DefinitionException { if (c.hasExtension()) throw new DefinitionException("Unsupported CodeableConcept pattern - extensions are not allowed - for discriminator(" + discriminator + ") for slice " + ed.getId()); - expression.append(discriminator + ".coding.where("); + expression.append(discriminator + ".where("); boolean first = true; if (c.hasSystem()) { first = false; From 95959ed01aa9ee9ad68bf33dc7978427c5431adc Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 28 Feb 2020 15:57:21 +1100 Subject: [PATCH 4/5] enhance snapshot generation tests to allow specifying version for the base --- .../fhir/r5/test/utils/TestingUtilities.java | 20 +++++++++++++------ .../fhir/r5/test/SnapShotGenerationTests.java | 9 ++++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java index 1a2686032..744646a7b 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java @@ -26,6 +26,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -41,6 +42,7 @@ import org.hl7.fhir.r5.model.Parameters; import org.hl7.fhir.utilities.CSFile; import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.Utilities; +import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.cache.PackageCacheManager; import org.hl7.fhir.utilities.cache.ToolsVersion; @@ -59,22 +61,28 @@ import com.google.gson.JsonSyntaxException; public class TestingUtilities { private static final boolean SHOW_DIFF = true; - static public IWorkerContext fcontext; + static public Map fcontexts; - public static IWorkerContext context() { - if (fcontext == null) { + public static IWorkerContext context() { + return context("4.0.1"); + } + public static IWorkerContext context(String version) { + if (fcontexts == null) { + fcontexts = new HashMap<>(); + } + if (!fcontexts.containsKey(version)) { PackageCacheManager pcm; try { pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION); - fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); + IWorkerContext fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage(VersionUtilities.packageForVersion(version), version)); fcontext.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml"))); fcontext.setExpansionProfile(new Parameters()); + fcontexts.put(version, fcontext); } catch (Exception e) { throw new Error(e); } - } - return fcontext; + return fcontexts.get(version); } static public boolean silent; diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/SnapShotGenerationTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/SnapShotGenerationTests.java index 9c1bfd7e1..e61e74d2e 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/SnapShotGenerationTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/SnapShotGenerationTests.java @@ -108,6 +108,8 @@ public class SnapShotGenerationTests { private boolean fail; private boolean newSliceProcessing; private boolean debug; + private String version; + private List rules = new ArrayList<>(); private StructureDefinition source; private StructureDefinition included; @@ -121,6 +123,11 @@ public class SnapShotGenerationTests { fail = "true".equals(test.getAttribute("fail")); newSliceProcessing = !"false".equals(test.getAttribute("new-slice-processing")); debug = "true".equals(test.getAttribute("debug")); + if (test.hasAttribute("version")) { + version = test.getAttribute("version"); + } else { + version = "4.0.1"; + } id = test.getAttribute("id"); include = test.getAttribute("include"); @@ -493,7 +500,7 @@ public class SnapShotGenerationTests { throw new Exception("URL mismatch on base: "+base.getUrl()+" wanting "+test.getSource().getBaseDefinition()); StructureDefinition output = test.getSource().copy(); - ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), messages , new TestPKP()); + ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(test.version), messages , new TestPKP()); pu.setNewSlicingProcessing(test.isNewSliceProcessing()); pu.setThrowException(false); pu.setDebug(test.isDebug()); From b15d72a7558298fd80beeb5174944977b3700906 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sat, 29 Feb 2020 06:21:02 +1100 Subject: [PATCH 5/5] fix to compile + adjust validator messages --- .../org/hl7/fhir/validation/instance/InstanceValidator.java | 6 +++--- .../org/hl7/fhir/validation/tests/ValidationTestSuite.java | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java index 942bd2c16..ef8207ce2 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java @@ -1403,10 +1403,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat if (xverManager.matchingUrl(url)) { switch (xverManager.status(url)) { case BadVersion: - rule(errors, IssueType.INVALID, element.line(), element.col(), path + "[url='" + url + "']", false, "Extension url '" + url + "' is not valid (invalidVersion \"" + xverManager.getVersion(url) + "\")"); + rule(errors, IssueType.INVALID, element.line(), element.col(), path + "[url='" + url + "']", false, "Extension url '" + url + "' is not valid (invalid Version \"" + xverManager.getVersion(url) + "\")"); break; case Unknown: - rule(errors, IssueType.INVALID, element.line(), element.col(), path + "[url='" + url + "']", false, "Extension url '" + url + "' is not valid (unknown Element id \"" + xverManager.getElementId(url) + "\")"); + rule(errors, IssueType.INVALID, element.line(), element.col(), path + "[url='" + url + "']", false, "Extension url '" + url + "' is not valid (invalid Element id \"" + xverManager.getElementId(url) + "\")"); break; case Invalid: rule(errors, IssueType.INVALID, element.line(), element.col(), path + "[url='" + url + "']", false, "Extension url '" + url + "' is not valid (Element id \"" + xverManager.getElementId(url) + "\" is valid, but cannot be used in a cross-version paradigm because there has been no changes across the relevant versions)"); @@ -1783,7 +1783,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat if (e.primitiveValue() == null) rule(errors, IssueType.INVALID, e.line(), e.col(), path, e.hasChildren(), "Primitive types must have a value or must have child extensions"); else if (e.primitiveValue().length() == 0) - rule(errors, IssueType.INVALID, e.line(), e.col(), path, e.hasChildren(), "Primitive types must have a value that is not empty"); + rule(errors, IssueType.INVALID, e.line(), e.col(), path, e.hasChildren(), "@value cannot be empty"); else if (StringUtils.isWhitespace(e.primitiveValue())) warning(errors, IssueType.INVALID, e.line(), e.col(), path, e.hasChildren(), "Primitive types should not only be whitespace"); return; diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTestSuite.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTestSuite.java index 331a37715..373c9cacb 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTestSuite.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTestSuite.java @@ -118,7 +118,10 @@ public class ValidationTestSuite implements IEvaluationContext, IValidatorResour } vCurr = ve.get(v); vCurr.setFetcher(this); - TestingUtilities.fcontext = vCurr.getContext(); + if (TestingUtilities.fcontexts == null) { + TestingUtilities.fcontexts = new HashMap<>(); + } + TestingUtilities.fcontexts.put(v, vCurr.getContext()); if (content.has("use-test") && !content.get("use-test").getAsBoolean()) return;