Merge pull request #880 from hdconradi/required-answer-can-be-missing-when-in-progress
Activate the QuestionnaireResponseValidatorDstu3Test again and add tests for missing required items
This commit is contained in:
commit
74e7152ce6
|
@ -3,6 +3,7 @@ package org.hl7.fhir.dstu3.hapi.validation;
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
import ca.uhn.fhir.validation.FhirValidator;
|
import ca.uhn.fhir.validation.FhirValidator;
|
||||||
|
import ca.uhn.fhir.validation.ResultSeverityEnum;
|
||||||
import ca.uhn.fhir.validation.SingleValidationMessage;
|
import ca.uhn.fhir.validation.SingleValidationMessage;
|
||||||
import ca.uhn.fhir.validation.ValidationResult;
|
import ca.uhn.fhir.validation.ValidationResult;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
@ -19,7 +20,6 @@ import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseItemC
|
||||||
import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseStatus;
|
import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseStatus;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -27,13 +27,13 @@ import java.util.List;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.empty;
|
import static org.hamcrest.Matchers.empty;
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@Ignore
|
|
||||||
public class QuestionnaireResponseValidatorDstu3Test {
|
public class QuestionnaireResponseValidatorDstu3Test {
|
||||||
public static final IdType ID_ICC_QUESTIONNAIRE_SETUP = new IdType("Questionnaire/profile");
|
public static final IdType ID_ICC_QUESTIONNAIRE_SETUP = new IdType("Questionnaire/profile");
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(QuestionnaireResponseValidatorDstu3Test.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(QuestionnaireResponseValidatorDstu3Test.class);
|
||||||
|
@ -274,6 +274,35 @@ public class QuestionnaireResponseValidatorDstu3Test {
|
||||||
assertThat(errors.toString(), containsString("No issues"));
|
assertThat(errors.toString(), containsString("No issues"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMissingRequiredAnswer() {
|
||||||
|
Questionnaire q = new Questionnaire();
|
||||||
|
q.addItem().setLinkId("link0")
|
||||||
|
.setType(QuestionnaireItemType.STRING)
|
||||||
|
.setRequired(true);
|
||||||
|
|
||||||
|
String reference = "http://example.com/Questionnaire/q1";
|
||||||
|
when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(reference)))
|
||||||
|
.thenReturn(q);
|
||||||
|
|
||||||
|
QuestionnaireResponse qa = new QuestionnaireResponse();
|
||||||
|
qa.getQuestionnaire().setReference(reference);
|
||||||
|
qa.addItem().setLinkId("link0");
|
||||||
|
qa.setStatus(QuestionnaireResponseStatus.INPROGRESS);
|
||||||
|
|
||||||
|
ValidationResult errors = myVal.validateWithResult(qa);
|
||||||
|
ourLog.info(errors.toString());
|
||||||
|
assertThat(errors.getMessages(), hasSize(1));
|
||||||
|
assertEquals(ResultSeverityEnum.WARNING, errors.getMessages().get(0).getSeverity());
|
||||||
|
|
||||||
|
qa.setStatus(QuestionnaireResponseStatus.COMPLETED);
|
||||||
|
|
||||||
|
errors = myVal.validateWithResult(qa);
|
||||||
|
ourLog.info(errors.toString());
|
||||||
|
assertThat(errors.getMessages(), hasSize(1));
|
||||||
|
assertEquals(ResultSeverityEnum.ERROR, errors.getMessages().get(0).getSeverity());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOpenchoiceAnswer() {
|
public void testOpenchoiceAnswer() {
|
||||||
String questionnaireRef = "http://example.com/Questionnaire/q1";
|
String questionnaireRef = "http://example.com/Questionnaire/q1";
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.hl7.fhir.r4.validation;
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
import ca.uhn.fhir.validation.FhirValidator;
|
import ca.uhn.fhir.validation.FhirValidator;
|
||||||
|
import ca.uhn.fhir.validation.ResultSeverityEnum;
|
||||||
import ca.uhn.fhir.validation.SingleValidationMessage;
|
import ca.uhn.fhir.validation.SingleValidationMessage;
|
||||||
import ca.uhn.fhir.validation.ValidationResult;
|
import ca.uhn.fhir.validation.ValidationResult;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
@ -30,6 +31,7 @@ import java.util.List;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.empty;
|
import static org.hamcrest.Matchers.empty;
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
|
@ -218,6 +220,35 @@ public class QuestionnaireResponseValidatorR4Test {
|
||||||
assertThat(errors.toString(), containsString("No response found for required item link0"));
|
assertThat(errors.toString(), containsString("No response found for required item link0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMissingRequiredAnswer() {
|
||||||
|
Questionnaire q = new Questionnaire();
|
||||||
|
q.addItem().setLinkId("link0")
|
||||||
|
.setType(QuestionnaireItemType.STRING)
|
||||||
|
.setRequired(true);
|
||||||
|
|
||||||
|
String reference = "http://example.com/Questionnaire/q1";
|
||||||
|
when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(reference)))
|
||||||
|
.thenReturn(q);
|
||||||
|
|
||||||
|
QuestionnaireResponse qa = new QuestionnaireResponse();
|
||||||
|
qa.setQuestionnaire(reference);
|
||||||
|
qa.addItem().setLinkId("link0");
|
||||||
|
qa.setStatus(QuestionnaireResponseStatus.INPROGRESS);
|
||||||
|
|
||||||
|
ValidationResult errors = myVal.validateWithResult(qa);
|
||||||
|
ourLog.info(errors.toString());
|
||||||
|
assertThat(errors.getMessages(), hasSize(1));
|
||||||
|
assertEquals(ResultSeverityEnum.WARNING, errors.getMessages().get(0).getSeverity());
|
||||||
|
|
||||||
|
qa.setStatus(QuestionnaireResponseStatus.COMPLETED);
|
||||||
|
|
||||||
|
errors = myVal.validateWithResult(qa);
|
||||||
|
ourLog.info(errors.toString());
|
||||||
|
assertThat(errors.getMessages(), hasSize(1));
|
||||||
|
assertEquals(ResultSeverityEnum.ERROR, errors.getMessages().get(0).getSeverity());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOpenchoiceAnswer() {
|
public void testOpenchoiceAnswer() {
|
||||||
String questionnaireRef = "http://example.com/Questionnaire/q1";
|
String questionnaireRef = "http://example.com/Questionnaire/q1";
|
||||||
|
|
Loading…
Reference in New Issue