Merge branch 'master' of github.com:jamesagnew/hapi-fhir

This commit is contained in:
James 2017-10-18 12:51:34 -04:00
commit ca52588491
9 changed files with 3964 additions and 3836 deletions

View File

@ -180,7 +180,7 @@ public class JpaSystemProviderDstu3 extends BaseJpaSystemProviderDstu2Plus<Bundl
@OperationParam(name = "searchParam", min = 1, max = 1) String theSearchParam, @OperationParam(name = "searchParam", min = 1, max = 1) String theSearchParam,
@OperationParam(name = "text", min = 1, max = 1) String theText @OperationParam(name = "text", min = 1, max = 1) String theText
) { ) {
JpaSystemProviderDstu3.validateFulltextSearchEnabled(mySearchDao);
if (isBlank(theContext)) { if (isBlank(theContext)) {
throw new InvalidRequestException("Parameter 'context' must be provided"); throw new InvalidRequestException("Parameter 'context' must be provided");

View File

@ -2105,6 +2105,9 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
} }
private String resolve(String uri, String ref) { private String resolve(String uri, String ref) {
if (isBlank(uri)) {
return ref;
}
String[] up = uri.split("\\/"); String[] up = uri.split("\\/");
String[] rp = ref.split("\\/"); String[] rp = ref.split("\\/");
if (context.getResourceNames().contains(up[up.length-2]) && context.getResourceNames().contains(rp[0])) { if (context.getResourceNames().contains(up[up.length-2]) && context.getResourceNames().contains(rp[0])) {

View File

@ -884,4 +884,5 @@ public class FhirInstanceValidatorDstu3Test {
TestUtil.clearAllStaticFieldsForUnitTest(); TestUtil.clearAllStaticFieldsForUnitTest();
} }
} }

View File

@ -1,17 +1,7 @@
package org.hl7.fhir.dstu3.hapi.validation; package org.hl7.fhir.dstu3.hapi.validation;
import static org.hamcrest.Matchers.containsString; import ca.uhn.fhir.context.FhirContext;
import static org.hamcrest.Matchers.empty; import ca.uhn.fhir.util.TestUtil;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.SingleValidationMessage; import ca.uhn.fhir.validation.SingleValidationMessage;
import ca.uhn.fhir.validation.ValidationResult; import ca.uhn.fhir.validation.ValidationResult;
@ -20,38 +10,39 @@ import org.hl7.fhir.dstu3.context.IWorkerContext;
import org.hl7.fhir.dstu3.hapi.ctx.HapiWorkerContext; import org.hl7.fhir.dstu3.hapi.ctx.HapiWorkerContext;
import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport; import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport;
import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport.CodeValidationResult; import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport.CodeValidationResult;
import org.hl7.fhir.dstu3.model.CodeSystem; import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.dstu3.model.CodeSystem.CodeSystemContentMode; import org.hl7.fhir.dstu3.model.CodeSystem.CodeSystemContentMode;
import org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent; import org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent;
import org.hl7.fhir.dstu3.model.CodeType;
import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.IntegerType;
import org.hl7.fhir.dstu3.model.Questionnaire;
import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent; import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent;
import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType; import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType;
import org.hl7.fhir.dstu3.model.QuestionnaireResponse;
import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseItemComponent; import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseItemComponent;
import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseStatus; import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseStatus;
import org.hl7.fhir.dstu3.model.Reference;
import org.hl7.fhir.dstu3.model.StringType;
import org.hl7.fhir.dstu3.model.ValueSet;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import ca.uhn.fhir.context.FhirContext; import java.util.ArrayList;
import ca.uhn.fhir.util.TestUtil; import java.util.List;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class QuestionnaireResponseValidatorDstu3Test { public class QuestionnaireResponseValidatorDstu3Test {
private static DefaultProfileValidationSupport myDefaultValidationSupport = new DefaultProfileValidationSupport(); public static final IdType ID_ICC_QUESTIONNAIRE_SETUP = new IdType("Questionnaire/profile");
private static FhirContext ourCtx = FhirContext.forDstu3();
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);
private static final String CODE_ICC_SCHOOLTYPE_PT = "PT";
private static final IdType ID_VS_SCHOOLTYPE = new IdType("ValueSet/schooltype");
private static final String SYSTEMURI_ICC_SCHOOLTYPE = "http://ehealthinnovation/icc/ns/schooltype";
private static DefaultProfileValidationSupport myDefaultValidationSupport = new DefaultProfileValidationSupport();
private static FhirContext ourCtx = FhirContext.forDstu3();
private FhirInstanceValidator myInstanceVal; private FhirInstanceValidator myInstanceVal;
private FhirValidator myVal; private FhirValidator myVal;
private IValidationSupport myValSupport; private IValidationSupport myValSupport;
private IWorkerContext myWorkerCtx; private IWorkerContext myWorkerCtx;
@Before @Before
@ -59,28 +50,30 @@ public class QuestionnaireResponseValidatorDstu3Test {
myValSupport = mock(IValidationSupport.class); myValSupport = mock(IValidationSupport.class);
// new DefaultProfileValidationSupport(); // new DefaultProfileValidationSupport();
myWorkerCtx = new HapiWorkerContext(ourCtx, myValSupport); myWorkerCtx = new HapiWorkerContext(ourCtx, myValSupport);
myVal = ourCtx.newValidator(); myVal = ourCtx.newValidator();
myVal.setValidateAgainstStandardSchema(false); myVal.setValidateAgainstStandardSchema(false);
myVal.setValidateAgainstStandardSchematron(false); myVal.setValidateAgainstStandardSchematron(false);
ValidationSupportChain validationSupport = new ValidationSupportChain(myValSupport, myDefaultValidationSupport); ValidationSupportChain validationSupport = new ValidationSupportChain(myValSupport, myDefaultValidationSupport);
myInstanceVal = new FhirInstanceValidator(validationSupport); myInstanceVal = new FhirInstanceValidator(validationSupport);
myVal.registerValidatorModule(myInstanceVal); myVal.registerValidatorModule(myInstanceVal);
} }
private ValidationResult stripBindingHasNoSourceMessage(ValidationResult theErrors) { private ValidationResult stripBindingHasNoSourceMessage(ValidationResult theErrors) {
List<SingleValidationMessage> messages = new ArrayList<SingleValidationMessage>(theErrors.getMessages()); List<SingleValidationMessage> messages = new ArrayList<SingleValidationMessage>(theErrors.getMessages());
for (int i = 0; i < messages.size(); i++) { for (int i = 0; i < messages.size(); i++) {
if (messages.get(i).getMessage().contains("has no source, so can't")) { if (messages.get(i).getMessage().contains("has no source, so can't")) {
messages.remove(i); messages.remove(i);
i--; i--;
} }
} }
return new ValidationResult(ourCtx, messages); return new ValidationResult(ourCtx, messages);
} }
@Test @Test
public void testAnswerWithWrongType() { public void testAnswerWithWrongType() {
Questionnaire q = new Questionnaire(); Questionnaire q = new Questionnaire();
@ -179,7 +172,7 @@ public class QuestionnaireResponseValidatorDstu3Test {
ourLog.info(errors.toString()); ourLog.info(errors.toString());
assertThat(errors.toString(), containsString("minimum required = 1, but only found 0 - QuestionnaireResponse.item")); assertThat(errors.toString(), containsString("minimum required = 1, but only found 0 - QuestionnaireResponse.item"));
} }
@Test @Test
public void testItemWithNoType() { public void testItemWithNoType() {
Questionnaire q = new Questionnaire(); Questionnaire q = new Questionnaire();
@ -221,6 +214,64 @@ public class QuestionnaireResponseValidatorDstu3Test {
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 testValidateQuestionnaireResponseWithValueSetChoiceAnswer() {
/*
* Create valueset
*/
ValueSet iccSchoolTypeVs = new ValueSet();
iccSchoolTypeVs.setId(ID_VS_SCHOOLTYPE);
iccSchoolTypeVs.getCompose().getIncludeFirstRep().setSystem(SYSTEMURI_ICC_SCHOOLTYPE);
iccSchoolTypeVs
.getCompose()
.getIncludeFirstRep()
.addConcept()
.setCode(CODE_ICC_SCHOOLTYPE_PT)
.setDisplay("Part Time");
/*
* Create Questionnaire
*/
Questionnaire questionnaire = new Questionnaire();
{
questionnaire.setId(ID_ICC_QUESTIONNAIRE_SETUP);
Questionnaire.QuestionnaireItemComponent basicGroup = questionnaire.addItem();
basicGroup.setLinkId("basic");
basicGroup.setType(Questionnaire.QuestionnaireItemType.GROUP);
basicGroup
.addItem()
.setLinkId("schoolType")
.setType(Questionnaire.QuestionnaireItemType.CHOICE)
.setOptions(new Reference(ID_VS_SCHOOLTYPE))
.setRequired(true);
}
/*
* Create response
*/
QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse();
questionnaireResponse.setStatus(QuestionnaireResponse.QuestionnaireResponseStatus.COMPLETED);
questionnaireResponse.setQuestionnaire(new Reference(ID_ICC_QUESTIONNAIRE_SETUP));
questionnaireResponse.getSubject().setReference("Patient/123");
QuestionnaireResponse.QuestionnaireResponseItemComponent basicGroup = questionnaireResponse
.addItem();
basicGroup.setLinkId("basic");
basicGroup
.addItem()
.setLinkId("schoolType")
.addAnswer()
.setValue(new Coding(SYSTEMURI_ICC_SCHOOLTYPE, CODE_ICC_SCHOOLTYPE_PT, ""));
when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(questionnaireResponse.getQuestionnaire().getReference()))).thenReturn(questionnaire);
when(myValSupport.fetchResource(any(FhirContext.class), eq(ValueSet.class), eq(ID_VS_SCHOOLTYPE.getValue()))).thenReturn(iccSchoolTypeVs);
ValidationResult errors = myVal.validateWithResult(questionnaireResponse);
ourLog.info(errors.toString());
assertThat(errors.toString(), containsString("No issues"));
}
@Test @Test
public void testOpenchoiceAnswer() { public void testOpenchoiceAnswer() {
String questionnaireRef = "http://example.com/Questionnaire/q1"; String questionnaireRef = "http://example.com/Questionnaire/q1";
@ -248,7 +299,7 @@ public class QuestionnaireResponseValidatorDstu3Test {
when(myValSupport.fetchResource(any(FhirContext.class), eq(ValueSet.class), eq("http://somevalueset"))).thenReturn(options); when(myValSupport.fetchResource(any(FhirContext.class), eq(ValueSet.class), eq("http://somevalueset"))).thenReturn(options);
when(myValSupport.validateCode(any(FhirContext.class), eq("http://codesystems.com/system"), eq("code0"), any(String.class))).thenReturn(new CodeValidationResult(new ConceptDefinitionComponent(new CodeType("code0")))); when(myValSupport.validateCode(any(FhirContext.class), eq("http://codesystems.com/system"), eq("code0"), any(String.class))).thenReturn(new CodeValidationResult(new ConceptDefinitionComponent(new CodeType("code0"))));
QuestionnaireResponse qa; QuestionnaireResponse qa;
ValidationResult errors; ValidationResult errors;
@ -389,19 +440,19 @@ public class QuestionnaireResponseValidatorDstu3Test {
//@formatter:off //@formatter:off
input = input.replaceAll( input = input.replaceAll(
"<answer>\n" + "<answer>\n" +
" <valueCoding>\n" + " <valueCoding>\n" +
" <system value=\"f69573b8-cb63-4d31-85a4-23ac784735ab\"/>\n" + " <system value=\"f69573b8-cb63-4d31-85a4-23ac784735ab\"/>\n" +
" <code value=\"2\"/>\n" + " <code value=\"2\"/>\n" +
" <display value=\"Once/twice\"/>\n" + " <display value=\"Once/twice\"/>\n" +
" </valueCoding>\n" + " </valueCoding>\n" +
" </answer>", " </answer>",
"<answer>\n" + "<answer>\n" +
" <valueCoding>\n" + " <valueCoding>\n" +
" <system value=\"f69573b8-cb63-4d31-85a4-23ac784735ab\"/>\n" + " <system value=\"f69573b8-cb63-4d31-85a4-23ac784735ab\"/>\n" +
" <code value=\"GGG\"/>\n" + " <code value=\"GGG\"/>\n" +
" <display value=\"Once/twice\"/>\n" + " <display value=\"Once/twice\"/>\n" +
" </valueCoding>\n" + " </valueCoding>\n" +
" </answer>"); " </answer>");
assertThat(input, containsString("GGG")); assertThat(input, containsString("GGG"));
//@formatter:on //@formatter:on

View File

@ -1,4 +1,4 @@
package ca.uhn.fhir.r4.validation; package org.hl7.fhir.r4.validation;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.empty;
@ -241,9 +241,9 @@ public class FhirInstanceValidatorR4Test {
myVal.registerValidatorModule(myInstanceVal); myVal.registerValidatorModule(myInstanceVal);
mySupportedCodeSystemsForExpansion = new HashMap<String, ValueSet.ValueSetExpansionComponent>(); mySupportedCodeSystemsForExpansion = new HashMap<>();
myValidConcepts = new ArrayList<String>(); myValidConcepts = new ArrayList<>();
when(myMockSupport.expandValueSet(any(FhirContext.class), any(ConceptSetComponent.class))).thenAnswer(new Answer<ValueSetExpansionComponent>() { when(myMockSupport.expandValueSet(any(FhirContext.class), any(ConceptSetComponent.class))).thenAnswer(new Answer<ValueSetExpansionComponent>() {
@Override @Override

View File

@ -1,57 +1,52 @@
package ca.uhn.fhir.validation; package org.hl7.fhir.r4.validation;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.util.TestUtil;
import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.SingleValidationMessage;
import ca.uhn.fhir.validation.ValidationResult;
import org.apache.commons.io.IOUtils;
import org.hl7.fhir.r4.context.IWorkerContext;
import org.hl7.fhir.r4.hapi.ctx.DefaultProfileValidationSupport;
import org.hl7.fhir.r4.hapi.ctx.HapiWorkerContext;
import org.hl7.fhir.r4.hapi.ctx.IValidationSupport;
import org.hl7.fhir.r4.hapi.ctx.IValidationSupport.CodeValidationResult;
import org.hl7.fhir.r4.hapi.ctx.ValidationSupportChain;
import org.hl7.fhir.r4.hapi.validation.FhirInstanceValidator;
import org.hl7.fhir.r4.model.*;
import org.hl7.fhir.r4.model.CodeSystem.CodeSystemContentMode;
import org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent;
import org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent;
import org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemType;
import org.hl7.fhir.r4.model.QuestionnaireResponse.QuestionnaireResponseItemComponent;
import org.hl7.fhir.r4.model.QuestionnaireResponse.QuestionnaireResponseStatus;
import org.hl7.fhir.r4.model.IdType;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
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.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertThat;
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;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.hl7.fhir.dstu3.context.IWorkerContext;
import org.hl7.fhir.dstu3.hapi.validation.DefaultProfileValidationSupport;
import org.hl7.fhir.dstu3.hapi.validation.FhirInstanceValidator;
import org.hl7.fhir.dstu3.hapi.ctx.HapiWorkerContext;
import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport;
import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport.CodeValidationResult;
import org.hl7.fhir.dstu3.hapi.validation.ValidationSupportChain;
import org.hl7.fhir.dstu3.model.CodeSystem;
import org.hl7.fhir.dstu3.model.CodeSystem.CodeSystemContentMode;
import org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent;
import org.hl7.fhir.dstu3.model.CodeType;
import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.IntegerType;
import org.hl7.fhir.dstu3.model.Questionnaire;
import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent;
import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType;
import org.hl7.fhir.dstu3.model.QuestionnaireResponse;
import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseItemComponent;
import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseStatus;
import org.hl7.fhir.dstu3.model.Reference;
import org.hl7.fhir.dstu3.model.StringType;
import org.hl7.fhir.dstu3.model.ValueSet;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.util.TestUtil;
public class QuestionnaireResponseValidatorR4Test { public class QuestionnaireResponseValidatorR4Test {
private static DefaultProfileValidationSupport myDefaultValidationSupport = new DefaultProfileValidationSupport(); public static final IdType ID_ICC_QUESTIONNAIRE_SETUP = new IdType("Questionnaire/profile");
private static FhirContext ourCtx = FhirContext.forDstu3();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(QuestionnaireResponseValidatorR4Test.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(QuestionnaireResponseValidatorR4Test.class);
private static final String CODE_ICC_SCHOOLTYPE_PT = "PT";
private static final IdType ID_VS_SCHOOLTYPE = new IdType("ValueSet/schooltype");
private static final String SYSTEMURI_ICC_SCHOOLTYPE = "http://ehealthinnovation/icc/ns/schooltype";
private static DefaultProfileValidationSupport myDefaultValidationSupport = new DefaultProfileValidationSupport();
private static FhirContext ourCtx = FhirContext.forR4();
private FhirInstanceValidator myInstanceVal; private FhirInstanceValidator myInstanceVal;
private FhirValidator myVal; private FhirValidator myVal;
private IValidationSupport myValSupport; private IValidationSupport myValSupport;
private IWorkerContext myWorkerCtx; private IWorkerContext myWorkerCtx;
@Before @Before
@ -59,28 +54,30 @@ public class QuestionnaireResponseValidatorR4Test {
myValSupport = mock(IValidationSupport.class); myValSupport = mock(IValidationSupport.class);
// new DefaultProfileValidationSupport(); // new DefaultProfileValidationSupport();
myWorkerCtx = new HapiWorkerContext(ourCtx, myValSupport); myWorkerCtx = new HapiWorkerContext(ourCtx, myValSupport);
myVal = ourCtx.newValidator(); myVal = ourCtx.newValidator();
myVal.setValidateAgainstStandardSchema(false); myVal.setValidateAgainstStandardSchema(false);
myVal.setValidateAgainstStandardSchematron(false); myVal.setValidateAgainstStandardSchematron(false);
ValidationSupportChain validationSupport = new ValidationSupportChain(myValSupport, myDefaultValidationSupport); ValidationSupportChain validationSupport = new ValidationSupportChain(myValSupport, myDefaultValidationSupport);
myInstanceVal = new FhirInstanceValidator(validationSupport); myInstanceVal = new FhirInstanceValidator(validationSupport);
myVal.registerValidatorModule(myInstanceVal); myVal.registerValidatorModule(myInstanceVal);
} }
private ValidationResult stripBindingHasNoSourceMessage(ValidationResult theErrors) { private ValidationResult stripBindingHasNoSourceMessage(ValidationResult theErrors) {
List<SingleValidationMessage> messages = new ArrayList<SingleValidationMessage>(theErrors.getMessages()); List<SingleValidationMessage> messages = new ArrayList<SingleValidationMessage>(theErrors.getMessages());
for (int i = 0; i < messages.size(); i++) { for (int i = 0; i < messages.size(); i++) {
if (messages.get(i).getMessage().contains("has no source, so can't")) { if (messages.get(i).getMessage().contains("has no source, so can't")) {
messages.remove(i); messages.remove(i);
i--; i--;
} }
} }
return new ValidationResult(ourCtx, messages); return new ValidationResult(ourCtx, messages);
} }
@Test @Test
public void testAnswerWithWrongType() { public void testAnswerWithWrongType() {
Questionnaire q = new Questionnaire(); Questionnaire q = new Questionnaire();
@ -177,9 +174,9 @@ public class QuestionnaireResponseValidatorR4Test {
ValidationResult errors = myVal.validateWithResult(qa); ValidationResult errors = myVal.validateWithResult(qa);
ourLog.info(errors.toString()); ourLog.info(errors.toString());
assertThat(errors.toString(), containsString("minimum required = 1, but only found 0 - QuestionnaireResponse.item")); assertThat(errors.toString(), containsString("ERROR - No LinkId, so can't be validated - QuestionnaireResponse"));
} }
@Test @Test
public void testItemWithNoType() { public void testItemWithNoType() {
Questionnaire q = new Questionnaire(); Questionnaire q = new Questionnaire();
@ -248,7 +245,7 @@ public class QuestionnaireResponseValidatorR4Test {
when(myValSupport.fetchResource(any(FhirContext.class), eq(ValueSet.class), eq("http://somevalueset"))).thenReturn(options); when(myValSupport.fetchResource(any(FhirContext.class), eq(ValueSet.class), eq("http://somevalueset"))).thenReturn(options);
when(myValSupport.validateCode(any(FhirContext.class), eq("http://codesystems.com/system"), eq("code0"), any(String.class))).thenReturn(new CodeValidationResult(new ConceptDefinitionComponent(new CodeType("code0")))); when(myValSupport.validateCode(any(FhirContext.class), eq("http://codesystems.com/system"), eq("code0"), any(String.class))).thenReturn(new CodeValidationResult(new ConceptDefinitionComponent(new CodeType("code0"))));
QuestionnaireResponse qa; QuestionnaireResponse qa;
ValidationResult errors; ValidationResult errors;
@ -375,6 +372,64 @@ public class QuestionnaireResponseValidatorR4Test {
assertThat(errors.toString(), containsString("LinkId \"link1\" not found in questionnaire")); assertThat(errors.toString(), containsString("LinkId \"link1\" not found in questionnaire"));
} }
@Test
public void testValidateQuestionnaireResponseWithValueSetChoiceAnswer() {
/*
* Create valueset
*/
ValueSet iccSchoolTypeVs = new ValueSet();
iccSchoolTypeVs.setId(ID_VS_SCHOOLTYPE);
iccSchoolTypeVs.getCompose().getIncludeFirstRep().setSystem(SYSTEMURI_ICC_SCHOOLTYPE);
iccSchoolTypeVs
.getCompose()
.getIncludeFirstRep()
.addConcept()
.setCode(CODE_ICC_SCHOOLTYPE_PT)
.setDisplay("Part Time");
/*
* Create Questionnaire
*/
Questionnaire questionnaire = new Questionnaire();
{
questionnaire.setId(ID_ICC_QUESTIONNAIRE_SETUP);
Questionnaire.QuestionnaireItemComponent basicGroup = questionnaire.addItem();
basicGroup.setLinkId("basic");
basicGroup.setType(Questionnaire.QuestionnaireItemType.GROUP);
basicGroup
.addItem()
.setLinkId("schoolType")
.setType(Questionnaire.QuestionnaireItemType.CHOICE)
.setOptions(new Reference(ID_VS_SCHOOLTYPE))
.setRequired(true);
}
/*
* Create response
*/
QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse();
questionnaireResponse.setStatus(QuestionnaireResponse.QuestionnaireResponseStatus.COMPLETED);
questionnaireResponse.setQuestionnaire(new Reference(ID_ICC_QUESTIONNAIRE_SETUP));
questionnaireResponse.getSubject().setReference("Patient/123");
QuestionnaireResponse.QuestionnaireResponseItemComponent basicGroup = questionnaireResponse
.addItem();
basicGroup.setLinkId("basic");
basicGroup
.addItem()
.setLinkId("schoolType")
.addAnswer()
.setValue(new Coding(SYSTEMURI_ICC_SCHOOLTYPE, CODE_ICC_SCHOOLTYPE_PT, ""));
when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(questionnaireResponse.getQuestionnaire().getReference()))).thenReturn(questionnaire);
when(myValSupport.fetchResource(any(FhirContext.class), eq(ValueSet.class), eq(ID_VS_SCHOOLTYPE.getValue()))).thenReturn(iccSchoolTypeVs);
ValidationResult errors = myVal.validateWithResult(questionnaireResponse);
ourLog.info(errors.toString());
assertThat(errors.toString(), containsString("No issues"));
}
// @Test // @Test
public void validateHealthConnexExample() throws Exception { public void validateHealthConnexExample() throws Exception {
String input = IOUtils.toString(QuestionnaireResponseValidatorR4Test.class.getResourceAsStream("/questionnaireanswers-0f431c50ddbe4fff8e0dd6b7323625fc.xml")); String input = IOUtils.toString(QuestionnaireResponseValidatorR4Test.class.getResourceAsStream("/questionnaireanswers-0f431c50ddbe4fff8e0dd6b7323625fc.xml"));
@ -389,19 +444,19 @@ public class QuestionnaireResponseValidatorR4Test {
//@formatter:off //@formatter:off
input = input.replaceAll( input = input.replaceAll(
"<answer>\n" + "<answer>\n" +
" <valueCoding>\n" + " <valueCoding>\n" +
" <system value=\"f69573b8-cb63-4d31-85a4-23ac784735ab\"/>\n" + " <system value=\"f69573b8-cb63-4d31-85a4-23ac784735ab\"/>\n" +
" <code value=\"2\"/>\n" + " <code value=\"2\"/>\n" +
" <display value=\"Once/twice\"/>\n" + " <display value=\"Once/twice\"/>\n" +
" </valueCoding>\n" + " </valueCoding>\n" +
" </answer>", " </answer>",
"<answer>\n" + "<answer>\n" +
" <valueCoding>\n" + " <valueCoding>\n" +
" <system value=\"f69573b8-cb63-4d31-85a4-23ac784735ab\"/>\n" + " <system value=\"f69573b8-cb63-4d31-85a4-23ac784735ab\"/>\n" +
" <code value=\"GGG\"/>\n" + " <code value=\"GGG\"/>\n" +
" <display value=\"Once/twice\"/>\n" + " <display value=\"Once/twice\"/>\n" +
" </valueCoding>\n" + " </valueCoding>\n" +
" </answer>"); " </answer>");
assertThat(input, containsString("GGG")); assertThat(input, containsString("GGG"));
//@formatter:on //@formatter:on
@ -417,4 +472,5 @@ public class QuestionnaireResponseValidatorR4Test {
TestUtil.clearAllStaticFieldsForUnitTest(); TestUtil.clearAllStaticFieldsForUnitTest();
} }
} }

View File

@ -1,9 +1,11 @@
package ca.uhn.fhir.validation; package org.hl7.fhir.r4.validation;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.ValidationResult;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Test; import org.junit.Test;

View File

@ -114,6 +114,12 @@
These were accidentally removed in HAPI FHIR 3.0.0. Thanks to These were accidentally removed in HAPI FHIR 3.0.0. Thanks to
GitHub user @CarthageKing for reporting! GitHub user @CarthageKing for reporting!
</action> </action>
<action type="fix">
The resource Profile Validator has been enhanced to not try to validate
bound fields where the binding strength is "example", and a crash was
resolved when validating QuestionnaireResponse answers with a type
of "choice" where the choice was bound to a ValueSet.
</action>
</release> </release>
<release version="3.0.0" date="2017-09-27"> <release version="3.0.0" date="2017-09-27">
<action type="add"> <action type="add">