Added check for answering questions which are not enabled

This commit is contained in:
Matti Uusitalo 2018-11-09 12:55:13 +02:00
parent 63d2af04da
commit 507c78320c
2 changed files with 21 additions and 0 deletions

View File

@ -2780,6 +2780,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
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, element), "Item has answer, even though it is not enabled "+qItem.getLinkId());
validateQuestionannaireResponseItem(qsrc, qItem, errors, mapItem, stack, inProgress);
} else {
//item is missing, is the question enabled?

View File

@ -7,6 +7,8 @@ import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.ResultSeverityEnum;
import ca.uhn.fhir.validation.SingleValidationMessage;
import ca.uhn.fhir.validation.ValidationResult;
import org.hamcrest.Matchers;
import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport;
import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport.CodeValidationResult;
import org.hl7.fhir.dstu3.model.*;
@ -413,6 +415,24 @@ public class QuestionnaireResponseValidatorDstu3Test {
ourLog.info(errors.toString());
assertThat(errors.toString(), containsString("No issues"));
}
@Test
public void testGivenQuestionIsNotEnabledWithEnableWhenAnswersAreReportedAsErrors() throws Exception {
Questionnaire q = new Questionnaire();
q.addItem().setLinkId("link0").setRequired(false).setType(QuestionnaireItemType.STRING);
q.addItem().setLinkId("link2").setRequired(false).setType(QuestionnaireItemType.STRING).addEnableWhen().setQuestion("link0").setHasAnswer(true);
QuestionnaireResponse qr = new QuestionnaireResponse();
qr.setStatus(QuestionnaireResponseStatus.COMPLETED);
qr.getQuestionnaire().setReference("http://example.com/Questionnaire/q1");
qr.addItem().setLinkId("link2").addAnswer().setValue(new StringType("FOO"));
String reference = qr.getQuestionnaire().getReference();
when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(reference))).thenReturn(q);
ValidationResult errors = myVal.validateWithResult(qr);
assertThat(errors.toString(), Matchers.not(containsString("No issues")));
}
@Test
public void testEmbeddedItemInChoice() {