From b0260fbfd8f45c162cca4a765dccf03a7fc2b091 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sat, 16 Mar 2019 05:26:38 +1100 Subject: [PATCH] fix for questionnaire evaluation bug --- .../DefaultEnableWhenEvaluator.java | 4 +- .../fhir/r5/validation/InstanceValidator.java | 2 +- .../validation/tests/ValidationTestSuite.java | 55 +++++++++++++------ .../validation-examples/manifest.json | 11 +++- .../questionnaire-enableWhen-test.xml | 32 +++++++++++ .../questionnaire-enableWhen-test3.xml | 31 +++++++++++ .../questionnaireResponse-enableWhen-test.xml | 26 +++++++++ ...questionnaireResponse-enableWhen-test3.xml | 28 ++++++++++ release.bat | 45 +++++++++++++++ 9 files changed, 212 insertions(+), 22 deletions(-) create mode 100644 org.hl7.fhir.validation/src/test/resources/validation-examples/questionnaire-enableWhen-test.xml create mode 100644 org.hl7.fhir.validation/src/test/resources/validation-examples/questionnaire-enableWhen-test3.xml create mode 100644 org.hl7.fhir.validation/src/test/resources/validation-examples/questionnaireResponse-enableWhen-test.xml create mode 100644 org.hl7.fhir.validation/src/test/resources/validation-examples/questionnaireResponse-enableWhen-test3.xml create mode 100644 release.bat diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/DefaultEnableWhenEvaluator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/DefaultEnableWhenEvaluator.java index 4615bbbbc..158839c9c 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/DefaultEnableWhenEvaluator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/DefaultEnableWhenEvaluator.java @@ -145,7 +145,7 @@ public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator { return result > 0; } - throw new UnprocessableEntityException("Bad operator for PrimitiveType comparison"); + throw new UnprocessableEntityException("Bad operator for PrimitiveType comparison: "+questionnaireItemOperator.toCode()); } @@ -198,7 +198,7 @@ public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator { return true; } private List findSubItems(Element item) { - List results = item.getChildren(LINKID_ELEMENT) + List results = item.getChildren(ITEM_ELEMENT) .stream() .flatMap(i -> findSubItems(i).stream()) .collect(Collectors.toList()); diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/InstanceValidator.java index 23a43fb65..cc07d481e 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/InstanceValidator.java @@ -2955,7 +2955,7 @@ private boolean isAnswerRequirementFulfilled(QuestionnaireItemComponent qItem, L for (QuestionnaireItemComponent qItem : qItems) { List mapItem = map.get(qItem.getLinkId()); if (mapItem != null){ - rule(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), myEnableWhenEvaluator.isQuestionEnabled(qItem, questionnaireResponseRoot), "Item has answer, even though it is not enabled "+qItem.getLinkId()); + rule(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), myEnableWhenEvaluator.isQuestionEnabled(qItem, questionnaireResponseRoot), "Item has answer, even though it is not enabled (item id = '"+qItem.getLinkId()+"')"); validateQuestionannaireResponseItem(qsrc, qItem, errors, mapItem, stack, inProgress, questionnaireResponseRoot); } else { //item is missing, is the question enabled? 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 3e4518826..421f4a50f 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 @@ -87,6 +87,7 @@ public class ValidationTestSuite implements IEvaluationContext, IValidatorResour private String name; private JsonObject content; + private static String veVersion; public ValidationTestSuite(String name, JsonObject content) { this.name = name; @@ -100,10 +101,24 @@ public class ValidationTestSuite implements IEvaluationContext, IValidatorResour @SuppressWarnings("deprecation") @Test public void test() throws Exception { - if (ve == null) { - ve = new ValidationEngine("hl7.fhir.core#4.0.0", DEF_TX, null, FhirPublication.R4); + String v = "5.0"; + if (content.has("version")) + v = content.get("version").getAsString(); + + if (ve == null || !v.equals(veVersion)) { + if (v.equals("5.0")) + ve = new ValidationEngine("hl7.fhir.core#4.1.0", DEF_TX, null, FhirPublication.R5); + else if (v.equals("3.0")) + ve = new ValidationEngine("hl7.fhir.core#3.0.1", DEF_TX, null, FhirPublication.STU3); + else if (v.equals("4.0")) + ve = new ValidationEngine("hl7.fhir.core#4.0.0", DEF_TX, null, FhirPublication.R4); + else if (v.equals("1.0")) + ve = new ValidationEngine("hl7.fhir.core#1.0.2", DEF_TX, null, FhirPublication.DSTU2); + else + throw new Exception("unknown version "+v); ve.getContext().setCanRunWithoutTerminology(true); TestingUtilities.fcontext = ve.getContext(); + veVersion = v; } if (content.has("use-test") && !content.get("use-test").getAsBoolean()) @@ -115,13 +130,13 @@ public class ValidationTestSuite implements IEvaluationContext, IValidatorResour val.getExtensionDomains().add(content.get("allowed-extension-domain").getAsString()); val.setFetcher(this); if (content.has("questionnaire")) { - ve.getContext().cacheResource(new XmlParser().parse(new FileInputStream(TestUtilities.resourceNameToFile("validation-examples", content.get("questionnaire").getAsString())))); + ve.getContext().cacheResource(loadResource(TestUtilities.resourceNameToFile("validation-examples", content.get("questionnaire").getAsString()), v)); } if (content.has("profiles")) { for (JsonElement je : content.getAsJsonArray("profiles")) { String p = je.getAsString(); String filename = TestUtilities.resourceNameToFile("validation-examples", p); - StructureDefinition sd = loadProfile(filename, Constants.VERSION); + StructureDefinition sd = loadProfile(filename, v); val.getContext().cacheResource(sd); } } @@ -135,7 +150,7 @@ public class ValidationTestSuite implements IEvaluationContext, IValidatorResour List errorsProfile = new ArrayList(); JsonObject profile = content.getAsJsonObject("profile"); String filename = TestUtilities.resourceNameToFile("validation-examples", profile.get("source").getAsString()); - String v = content.has("version") ? content.get("version").getAsString() : Constants.VERSION; + v = content.has("version") ? content.get("version").getAsString() : Constants.VERSION; StructureDefinition sd = loadProfile(filename, v); if (name.startsWith("Json.")) val.validate(null, errorsProfile, new FileInputStream(path), FhirFormat.JSON, sd); @@ -145,19 +160,8 @@ public class ValidationTestSuite implements IEvaluationContext, IValidatorResour } } - public StructureDefinition loadProfile(String filename, String v) - throws IOException, FHIRFormatError, FileNotFoundException, FHIRException, DefinitionException { - StructureDefinition sd = null; - if (Constants.VERSION.equals(v)) - sd = (StructureDefinition) new XmlParser().parse(new FileInputStream(filename)); - else if (org.hl7.fhir.dstu3.model.Constants.VERSION.equals(v)) - sd = (StructureDefinition) VersionConvertor_30_50.convertResource(new org.hl7.fhir.dstu3.formats.XmlParser().parse(new FileInputStream(filename)), false); - else if (org.hl7.fhir.dstu2016may.model.Constants.VERSION.equals(v)) - sd = (StructureDefinition) VersionConvertor_14_50.convertResource(new org.hl7.fhir.dstu2016may.formats.XmlParser().parse(new FileInputStream(filename))); - else if (org.hl7.fhir.dstu2.model.Constants.VERSION.equals(v)) - sd = (StructureDefinition) new VersionConvertor_10_50(null).convertResource(new org.hl7.fhir.dstu2.formats.XmlParser().parse(new FileInputStream(filename))); - else if (org.hl7.fhir.r4.model.Constants.VERSION.equals(v)) - sd = (StructureDefinition) VersionConvertor_40_50.convertResource(new org.hl7.fhir.r4.formats.XmlParser().parse(new FileInputStream(filename))); + public StructureDefinition loadProfile(String filename, String v) throws IOException, FHIRFormatError, FileNotFoundException, FHIRException, DefinitionException { + StructureDefinition sd = (StructureDefinition) loadResource(filename, v); if (!sd.hasSnapshot()) { ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), null, null); StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, sd.getBaseDefinition()); @@ -166,6 +170,21 @@ public class ValidationTestSuite implements IEvaluationContext, IValidatorResour } return sd; } + + public Resource loadResource(String filename, String v) throws IOException, FHIRFormatError, FileNotFoundException, FHIRException, DefinitionException { + if (Constants.VERSION.equals(v) || "5.0".equals(v)) + return new XmlParser().parse(new FileInputStream(filename)); + else if (org.hl7.fhir.dstu3.model.Constants.VERSION.equals(v) || "3.0".equals(v)) + return VersionConvertor_30_50.convertResource(new org.hl7.fhir.dstu3.formats.XmlParser().parse(new FileInputStream(filename)), false); + else if (org.hl7.fhir.dstu2016may.model.Constants.VERSION.equals(v) || "1.4".equals(v)) + return VersionConvertor_14_50.convertResource(new org.hl7.fhir.dstu2016may.formats.XmlParser().parse(new FileInputStream(filename))); + else if (org.hl7.fhir.dstu2.model.Constants.VERSION.equals(v) || "1.0".equals(v)) + return new VersionConvertor_10_50(null).convertResource(new org.hl7.fhir.dstu2.formats.XmlParser().parse(new FileInputStream(filename))); + else if (org.hl7.fhir.r4.model.Constants.VERSION.equals(v) || "4.0".equals(v)) + return VersionConvertor_40_50.convertResource(new org.hl7.fhir.r4.formats.XmlParser().parse(new FileInputStream(filename))); + else + throw new FHIRException("unknown version "+v); + } private void checkOutcomes(List errors, JsonObject focus) { int ec = 0; diff --git a/org.hl7.fhir.validation/src/test/resources/validation-examples/manifest.json b/org.hl7.fhir.validation/src/test/resources/validation-examples/manifest.json index 57ae649f7..9a560d816 100644 --- a/org.hl7.fhir.validation/src/test/resources/validation-examples/manifest.json +++ b/org.hl7.fhir.validation/src/test/resources/validation-examples/manifest.json @@ -331,7 +331,7 @@ } }, "uk-nhs-pat.xml" : { - "version" : "1.0.2", + "version" : "1.0", "use-test" : false, "allowed-extension-domain" : "http://hl7.org/fhir/ccda/StructureDefinition/", "errorCount": 0, @@ -451,6 +451,15 @@ "source" : "slice-profile-and-local-profile.xml", "errorCount": 0 } + }, + "questionnaireResponse-enableWhen-test.xml" : { + "questionnaire" : "questionnaire-enableWhen-test.xml", + "errorCount": 0 + }, + "questionnaireResponse-enableWhen-test3.xml" : { + "version" : "3.0", + "questionnaire" : "questionnaire-enableWhen-test3.xml", + "errorCount": 0 } } } diff --git a/org.hl7.fhir.validation/src/test/resources/validation-examples/questionnaire-enableWhen-test.xml b/org.hl7.fhir.validation/src/test/resources/validation-examples/questionnaire-enableWhen-test.xml new file mode 100644 index 000000000..5259dbd5a --- /dev/null +++ b/org.hl7.fhir.validation/src/test/resources/validation-examples/questionnaire-enableWhen-test.xml @@ -0,0 +1,32 @@ + + + + + + +
+

enableWhen test

+
+
+ + + + + + + + + + + + + + + + + + + + + +
diff --git a/org.hl7.fhir.validation/src/test/resources/validation-examples/questionnaire-enableWhen-test3.xml b/org.hl7.fhir.validation/src/test/resources/validation-examples/questionnaire-enableWhen-test3.xml new file mode 100644 index 000000000..ff47017f3 --- /dev/null +++ b/org.hl7.fhir.validation/src/test/resources/validation-examples/questionnaire-enableWhen-test3.xml @@ -0,0 +1,31 @@ + + + + + + +
+

enableWhen test

+
+
+ + + + + + + + + + + + + + + + + + + + +
diff --git a/org.hl7.fhir.validation/src/test/resources/validation-examples/questionnaireResponse-enableWhen-test.xml b/org.hl7.fhir.validation/src/test/resources/validation-examples/questionnaireResponse-enableWhen-test.xml new file mode 100644 index 000000000..a43b97555 --- /dev/null +++ b/org.hl7.fhir.validation/src/test/resources/validation-examples/questionnaireResponse-enableWhen-test.xml @@ -0,0 +1,26 @@ + + + + + +
+

enableWhen test response

+
+
+ + + + + + + + + + + + + + + + +
diff --git a/org.hl7.fhir.validation/src/test/resources/validation-examples/questionnaireResponse-enableWhen-test3.xml b/org.hl7.fhir.validation/src/test/resources/validation-examples/questionnaireResponse-enableWhen-test3.xml new file mode 100644 index 000000000..36517d8e4 --- /dev/null +++ b/org.hl7.fhir.validation/src/test/resources/validation-examples/questionnaireResponse-enableWhen-test3.xml @@ -0,0 +1,28 @@ + + + + + +
+

enableWhen test response

+
+
+ + + + + + + + + + + + + + + + + + +
diff --git a/release.bat b/release.bat new file mode 100644 index 000000000..1575a766d --- /dev/null +++ b/release.bat @@ -0,0 +1,45 @@ +REM replace versions before running +REM make sure you are committed + +echo =============================================================== +echo upgrade and release fhir.core from 3.7.15-SNAPSHOT to 3.7.16-SNAPSHOT +echo =============================================================== +pause + +call mvn versions:set -DnewVersion=3.7.16-SNAPSHOT + +echo +echo =============================================================== +echo upgraded version number using maven +echo next: do git commit / push +echo =============================================================== +pause + +call git commit -a -m "Release new version" +call git push origin master + +echo +echo =============================================================== +echo done git commit / push +echo next: replace references in java code + ivy +echo =============================================================== +pause + +call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\build" --fileMask "*.java" --excludeFileMask "*.dll, *.exe" --includeSubDirectories --find "3.7.15-SNAPSHOT" --replace "3.7.16-SNAPSHOT" +call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\build" --fileMask "*.xml" --excludeFileMask "*.dll, *.exe" --find "3.7.15-SNAPSHOT" --replace "3.7.16-SNAPSHOT" + +echo +echo =============================================================== +echo done replacing references +echo next: do maven release +echo =============================================================== +pause + +call mvn deploy + +echo +echo =============================================================== +echo all done +echo =============================================================== +pause + \ No newline at end of file