diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/instance/validation/QuestionnaireResponseValidator.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/instance/validation/QuestionnaireResponseValidator.java index 096a0308b6e..10ca289e142 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/instance/validation/QuestionnaireResponseValidator.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/instance/validation/QuestionnaireResponseValidator.java @@ -245,7 +245,7 @@ public class QuestionnaireResponseValidator extends BaseValidator { } } for (org.hl7.fhir.instance.model.QuestionnaireResponse.GroupComponent nextAnswerGroup : answerGroups) { - int index = theAnswerGroups.indexOf(answerGroups.get(1)); + int index = theAnswerGroups.indexOf(nextAnswerGroup); thePathStack.add("group(" + index + ")"); validateGroup(theErrors, nextQuestionGroup, nextAnswerGroup, thePathStack, theAnswers, theValidateRequired); thePathStack.removeLast(); diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/instance/hapi/validation/FhirInstanceValidatorTest.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/instance/hapi/validation/FhirInstanceValidatorTest.java index f6b9b9e7ea1..b2e69ff3949 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/instance/hapi/validation/FhirInstanceValidatorTest.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/instance/hapi/validation/FhirInstanceValidatorTest.java @@ -17,8 +17,11 @@ import org.apache.commons.io.IOUtils; import org.hl7.fhir.instance.model.DateType; import org.hl7.fhir.instance.model.Observation; import org.hl7.fhir.instance.model.Observation.ObservationStatus; +import org.hl7.fhir.instance.model.Questionnaire; +import org.hl7.fhir.instance.model.Questionnaire.AnswerFormat; import org.hl7.fhir.instance.model.QuestionnaireResponse; import org.hl7.fhir.instance.model.QuestionnaireResponse.QuestionnaireResponseStatus; +import org.hl7.fhir.instance.model.Reference; import org.hl7.fhir.instance.model.StringType; import org.junit.AfterClass; import org.junit.Ignore; @@ -223,6 +226,32 @@ public class FhirInstanceValidatorTest { assertTrue(result.isSuccessful()); } + + @Test + public void testQuestionnaireResponseValidator() { + final Questionnaire q = new Questionnaire(); + q.getGroup().addGroup().setLinkId("group1").addQuestion().setLinkId("foo").setType(AnswerFormat.BOOLEAN); + q.getGroup().addQuestion().setLinkId("bar").setType(AnswerFormat.TEXT); + + QuestionnaireResponse qr = new QuestionnaireResponse(); + qr.setStatus(QuestionnaireResponseStatus.COMPLETED); + qr.getGroup().addGroup().setLinkId("group1").addQuestion().setLinkId("foo"); + qr.getGroup().addQuestion().setLinkId("bar"); + qr.setQuestionnaire(new Reference("#q")); + qr.getQuestionnaire().setResource(q); + + FhirValidator val = ourCtxHl7OrgDstu2.newValidator(); + + FhirQuestionnaireResponseValidator module = new FhirQuestionnaireResponseValidator(); + val.registerValidatorModule(module); + + ValidationResult result = val.validateWithResult(qr); + + String encoded = ourCtxHl7OrgDstu2.newJsonParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome()); + ourLog.info(encoded); + + assertTrue(result.isSuccessful()); + } @AfterClass public static void afterClassClearContext() {