fix for questionnaire evaluation bug

This commit is contained in:
Grahame Grieve 2019-03-16 05:26:38 +11:00
parent a96c12899b
commit b0260fbfd8
9 changed files with 212 additions and 22 deletions

View File

@ -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<Element> findSubItems(Element item) {
List<Element> results = item.getChildren(LINKID_ELEMENT)
List<Element> results = item.getChildren(ITEM_ELEMENT)
.stream()
.flatMap(i -> findSubItems(i).stream())
.collect(Collectors.toList());

View File

@ -2955,7 +2955,7 @@ private boolean isAnswerRequirementFulfilled(QuestionnaireItemComponent qItem, L
for (QuestionnaireItemComponent qItem : qItems) {
List<Element> 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?

View File

@ -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<ValidationMessage> errorsProfile = new ArrayList<ValidationMessage>();
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<ValidationMessage> errors, JsonObject focus) {
int ec = 0;

View File

@ -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
}
}
}

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<Questionnaire xmlns="http://hl7.org/fhir">
<id value="questionnaire-enableWhen-test" />
<language value="en-US" />
<text>
<status value="generated" />
<div xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<p>enableWhen test</p>
</div>
</text>
<url value="http://hl7.org/fhir/us/hai/Questionnaire/questionnaire-enableWhen-test" />
<status value="draft" />
<item>
<linkId value="condition" />
<text value="condition" />
<type value="boolean" />
<required value="true" />
<repeats value="false" />
</item>
<item>
<linkId value="enable-when" />
<text value="enable when condition true" />
<type value="boolean" />
<enableWhen>
<question value="condition" />
<operator value="="/>
<answerBoolean value="true" />
</enableWhen>
<required value="true" />
<repeats value="false" />
</item>
</Questionnaire>

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<Questionnaire xmlns="http://hl7.org/fhir">
<id value="questionnaire-enableWhen-test" />
<language value="en-US" />
<text>
<status value="generated" />
<div xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<p>enableWhen test</p>
</div>
</text>
<url value="http://hl7.org/fhir/us/hai/Questionnaire/questionnaire-enableWhen-test" />
<status value="draft" />
<item>
<linkId value="condition" />
<text value="condition" />
<type value="boolean" />
<required value="true" />
<repeats value="false" />
</item>
<item>
<linkId value="enable-when" />
<text value="enable when condition true" />
<type value="boolean" />
<enableWhen>
<question value="condition" />
<answerBoolean value="true" />
</enableWhen>
<required value="true" />
<repeats value="false" />
</item>
</Questionnaire>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<QuestionnaireResponse xmlns="http://hl7.org/fhir">
<id value="questionnaireResponse-enableWhen-test" />
<text>
<status value="generated" />
<div xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<p>enableWhen test response</p>
</div>
</text>
<questionnaire value="http://hl7.org/fhir/us/hai/Questionnaire/questionnaire-enableWhen-test" />
<status value="completed" />
<item>
<linkId value="condition" />
<text value="condition" />
<answer>
<valueBoolean value="true" />
</answer>
</item>
<item>
<linkId value="enable-when" />
<text value="enable when condition true" />
<answer>
<valueBoolean value="false" />
</answer>
</item>
</QuestionnaireResponse>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<QuestionnaireResponse xmlns="http://hl7.org/fhir">
<id value="questionnaireResponse-enableWhen-test" />
<text>
<status value="generated" />
<div xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<p>enableWhen test response</p>
</div>
</text>
<questionnaire>
<reference value="http://hl7.org/fhir/us/hai/Questionnaire/questionnaire-enableWhen-test" />
</questionnaire>
<status value="completed" />
<item>
<linkId value="condition" />
<text value="condition" />
<answer>
<valueBoolean value="true" />
</answer>
</item>
<item>
<linkId value="enable-when" />
<text value="enable when condition true" />
<answer>
<valueBoolean value="false" />
</answer>
</item>
</QuestionnaireResponse>

45
release.bat Normal file
View File

@ -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