Merge pull request #886 from hdconradi/instance-validator-npe-on-itemtype
Instance validator NPE on itemtype
This commit is contained in:
commit
6d8ebe2df1
|
@ -2588,19 +2588,23 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
|||
break;
|
||||
case CHOICE:
|
||||
String itemType=validateQuestionnaireResponseItemType(errors, answer, ns, "Coding", "date", "time", "integer", "string");
|
||||
if (itemType != null) {
|
||||
if (itemType.equals("Coding")) validateAnswerCode(errors, answer, ns, qsrc, qItem, false);
|
||||
else if (itemType.equals("date")) checkOption(errors, answer, ns, qsrc, qItem, "date");
|
||||
else if (itemType.equals("time")) checkOption(errors, answer, ns, qsrc, qItem, "time");
|
||||
else if (itemType.equals("integer")) checkOption(errors, answer, ns, qsrc, qItem, "integer");
|
||||
else if (itemType.equals("string")) checkOption(errors, answer, ns, qsrc, qItem, "string");
|
||||
}
|
||||
break;
|
||||
case OPENCHOICE:
|
||||
itemType=validateQuestionnaireResponseItemType(errors, answer, ns, "Coding", "date", "time", "integer", "string");
|
||||
if (itemType != null) {
|
||||
if (itemType.equals("Coding")) validateAnswerCode(errors, answer, ns, qsrc, qItem, true);
|
||||
else if (itemType.equals("date")) checkOption(errors, answer, ns, qsrc, qItem, "date");
|
||||
else if (itemType.equals("time")) checkOption(errors, answer, ns, qsrc, qItem, "time");
|
||||
else if (itemType.equals("integer")) checkOption(errors, answer, ns, qsrc, qItem, "integer");
|
||||
else if (itemType.equals("string")) checkOption(errors, answer, ns, qsrc, qItem, "string", true);
|
||||
}
|
||||
break;
|
||||
case QUESTION:
|
||||
case NULL:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.hl7.fhir.dstu3.hapi.validation;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import ca.uhn.fhir.validation.FhirValidator;
|
||||
import ca.uhn.fhir.validation.ResultSeverityEnum;
|
||||
|
@ -216,6 +217,156 @@ public class QuestionnaireResponseValidatorDstu3Test {
|
|||
assertThat(errors.toString(), containsString("No response found for required item link0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmbeddedItemInChoice() {
|
||||
String questionnaireRef = "http://example.com/Questionnaire/q1";
|
||||
String valueSetRef = "http://somevalueset";
|
||||
String codeSystemUrl = "http://codesystems.com/system";
|
||||
String codeValue = "code0";
|
||||
|
||||
// create the questionnaire
|
||||
QuestionnaireItemComponent item1 = new QuestionnaireItemComponent();
|
||||
item1.setLinkId("link1")
|
||||
.setType(QuestionnaireItemType.CHOICE)
|
||||
.setOptions(new Reference(valueSetRef));
|
||||
|
||||
item1.addItem().setLinkId("link11")
|
||||
.setType(QuestionnaireItemType.TEXT);
|
||||
|
||||
Questionnaire q = new Questionnaire();
|
||||
q.addItem(item1);
|
||||
when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(questionnaireRef)))
|
||||
.thenReturn(q);
|
||||
|
||||
CodeSystem codeSystem = new CodeSystem();
|
||||
codeSystem.setContent(CodeSystemContentMode.COMPLETE);
|
||||
codeSystem.setUrl(codeSystemUrl);
|
||||
codeSystem.addConcept().setCode(codeValue);
|
||||
when(myValSupport.fetchCodeSystem(any(FhirContext.class), eq(codeSystemUrl)))
|
||||
.thenReturn(codeSystem);
|
||||
|
||||
ValueSet options = new ValueSet();
|
||||
options.getCompose().addInclude().setSystem(codeSystemUrl).addConcept().setCode(codeValue);
|
||||
when(myValSupport.fetchResource(any(FhirContext.class), eq(ValueSet.class), eq(valueSetRef)))
|
||||
.thenReturn(options);
|
||||
when(myValSupport.validateCode(any(FhirContext.class), eq(codeSystemUrl), eq(codeValue), any(String.class)))
|
||||
.thenReturn(new CodeValidationResult(new ConceptDefinitionComponent(new CodeType(codeValue))));
|
||||
|
||||
IParser xmlParser = ourCtx.newXmlParser().setPrettyPrint(true);
|
||||
String qXml = xmlParser.encodeResourceToString(q);
|
||||
ourLog.info(qXml);
|
||||
|
||||
// create the response
|
||||
QuestionnaireResponse qa = new QuestionnaireResponse();
|
||||
qa.setStatus(QuestionnaireResponseStatus.INPROGRESS);
|
||||
qa.getQuestionnaire().setReference(questionnaireRef);
|
||||
qa.addItem().setLinkId("link1")
|
||||
.addAnswer()
|
||||
.addItem().setLinkId("link11");
|
||||
|
||||
String rXml = xmlParser.encodeResourceToString(qa);
|
||||
ourLog.info(rXml);
|
||||
|
||||
ValidationResult errors = myVal.validateWithResult(qa);
|
||||
|
||||
ourLog.info(errors.toString());
|
||||
assertThat(errors.getMessages(), empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmbeddedItemInOpenChoice() {
|
||||
String questionnaireRef = "http://example.com/Questionnaire/q1";
|
||||
String valueSetRef = "http://somevalueset";
|
||||
String codeSystemUrl = "http://codesystems.com/system";
|
||||
String codeValue = "code0";
|
||||
|
||||
// create the questionnaire
|
||||
QuestionnaireItemComponent item1 = new QuestionnaireItemComponent();
|
||||
item1.setLinkId("link1")
|
||||
.setType(QuestionnaireItemType.OPENCHOICE)
|
||||
.setOptions(new Reference(valueSetRef));
|
||||
|
||||
item1.addItem().setLinkId("link11")
|
||||
.setType(QuestionnaireItemType.TEXT);
|
||||
|
||||
Questionnaire q = new Questionnaire();
|
||||
q.addItem(item1);
|
||||
when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(questionnaireRef)))
|
||||
.thenReturn(q);
|
||||
|
||||
CodeSystem codeSystem = new CodeSystem();
|
||||
codeSystem.setContent(CodeSystemContentMode.COMPLETE);
|
||||
codeSystem.setUrl(codeSystemUrl);
|
||||
codeSystem.addConcept().setCode(codeValue);
|
||||
when(myValSupport.fetchCodeSystem(any(FhirContext.class), eq(codeSystemUrl)))
|
||||
.thenReturn(codeSystem);
|
||||
|
||||
ValueSet options = new ValueSet();
|
||||
options.getCompose().addInclude().setSystem(codeSystemUrl).addConcept().setCode(codeValue);
|
||||
when(myValSupport.fetchResource(any(FhirContext.class), eq(ValueSet.class), eq(valueSetRef)))
|
||||
.thenReturn(options);
|
||||
when(myValSupport.validateCode(any(FhirContext.class), eq(codeSystemUrl), eq(codeValue), any(String.class)))
|
||||
.thenReturn(new CodeValidationResult(new ConceptDefinitionComponent(new CodeType(codeValue))));
|
||||
|
||||
IParser xmlParser = ourCtx.newXmlParser().setPrettyPrint(true);
|
||||
String qXml = xmlParser.encodeResourceToString(q);
|
||||
ourLog.info(qXml);
|
||||
|
||||
// create the response
|
||||
QuestionnaireResponse qa = new QuestionnaireResponse();
|
||||
qa.setStatus(QuestionnaireResponseStatus.INPROGRESS);
|
||||
qa.getQuestionnaire().setReference(questionnaireRef);
|
||||
qa.addItem().setLinkId("link1")
|
||||
.addAnswer()
|
||||
.addItem().setLinkId("link11");
|
||||
|
||||
String rXml = xmlParser.encodeResourceToString(qa);
|
||||
ourLog.info(rXml);
|
||||
|
||||
ValidationResult errors = myVal.validateWithResult(qa);
|
||||
|
||||
ourLog.info(errors.toString());
|
||||
assertThat(errors.getMessages(), empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmbeddedItemInString() {
|
||||
String questionnaireRef = "http://example.com/Questionnaire/q1";
|
||||
|
||||
// create the questionnaire
|
||||
QuestionnaireItemComponent item1 = new QuestionnaireItemComponent();
|
||||
item1.setLinkId("link1")
|
||||
.setType(QuestionnaireItemType.TEXT);
|
||||
|
||||
item1.addItem().setLinkId("link11")
|
||||
.setType(QuestionnaireItemType.TEXT);
|
||||
|
||||
Questionnaire q = new Questionnaire();
|
||||
q.addItem(item1);
|
||||
when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(questionnaireRef)))
|
||||
.thenReturn(q);
|
||||
|
||||
IParser xmlParser = ourCtx.newXmlParser().setPrettyPrint(true);
|
||||
String qXml = xmlParser.encodeResourceToString(q);
|
||||
ourLog.info(qXml);
|
||||
|
||||
// create the response
|
||||
QuestionnaireResponse qa = new QuestionnaireResponse();
|
||||
qa.setStatus(QuestionnaireResponseStatus.INPROGRESS);
|
||||
qa.getQuestionnaire().setReference(questionnaireRef);
|
||||
qa.addItem().setLinkId("link1")
|
||||
.addAnswer()
|
||||
.addItem().setLinkId("link11");
|
||||
|
||||
String rXml = xmlParser.encodeResourceToString(qa);
|
||||
ourLog.info(rXml);
|
||||
|
||||
ValidationResult errors = myVal.validateWithResult(qa);
|
||||
|
||||
ourLog.info(errors.toString());
|
||||
assertThat(errors.getMessages(), empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateQuestionnaireResponseWithValueSetChoiceAnswer() {
|
||||
/*
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.hl7.fhir.r4.validation;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import ca.uhn.fhir.validation.FhirValidator;
|
||||
import ca.uhn.fhir.validation.ResultSeverityEnum;
|
||||
|
@ -221,6 +222,155 @@ public class QuestionnaireResponseValidatorR4Test {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testEmbeddedItemInChoice() {
|
||||
String questionnaireRef = "http://example.com/Questionnaire/q1";
|
||||
String valueSetRef = "http://somevalueset";
|
||||
String codeSystemUrl = "http://codesystems.com/system";
|
||||
String codeValue = "code0";
|
||||
|
||||
// create the questionnaire
|
||||
QuestionnaireItemComponent item1 = new QuestionnaireItemComponent();
|
||||
item1.setLinkId("link1")
|
||||
.setType(QuestionnaireItemType.CHOICE)
|
||||
.setOptions(valueSetRef);
|
||||
|
||||
item1.addItem().setLinkId("link11")
|
||||
.setType(QuestionnaireItemType.TEXT);
|
||||
|
||||
Questionnaire q = new Questionnaire();
|
||||
q.addItem(item1);
|
||||
when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(questionnaireRef)))
|
||||
.thenReturn(q);
|
||||
|
||||
CodeSystem codeSystem = new CodeSystem();
|
||||
codeSystem.setContent(CodeSystemContentMode.COMPLETE);
|
||||
codeSystem.setUrl(codeSystemUrl);
|
||||
codeSystem.addConcept().setCode(codeValue);
|
||||
when(myValSupport.fetchCodeSystem(any(FhirContext.class), eq(codeSystemUrl)))
|
||||
.thenReturn(codeSystem);
|
||||
|
||||
ValueSet options = new ValueSet();
|
||||
options.getCompose().addInclude().setSystem(codeSystemUrl).addConcept().setCode(codeValue);
|
||||
when(myValSupport.fetchResource(any(FhirContext.class), eq(ValueSet.class), eq(valueSetRef)))
|
||||
.thenReturn(options);
|
||||
when(myValSupport.validateCode(any(FhirContext.class), eq(codeSystemUrl), eq(codeValue), any(String.class)))
|
||||
.thenReturn(new CodeValidationResult(new ConceptDefinitionComponent(new CodeType(codeValue))));
|
||||
|
||||
IParser xmlParser = ourCtx.newXmlParser().setPrettyPrint(true);
|
||||
String qXml = xmlParser.encodeResourceToString(q);
|
||||
ourLog.info(qXml);
|
||||
|
||||
// create the response
|
||||
QuestionnaireResponse qa = new QuestionnaireResponse();
|
||||
qa.setStatus(QuestionnaireResponseStatus.INPROGRESS);
|
||||
qa.setQuestionnaire(questionnaireRef);
|
||||
qa.addItem().setLinkId("link1")
|
||||
.addAnswer()
|
||||
.addItem().setLinkId("link11");
|
||||
|
||||
String rXml = xmlParser.encodeResourceToString(qa);
|
||||
ourLog.info(rXml);
|
||||
|
||||
ValidationResult errors = myVal.validateWithResult(qa);
|
||||
|
||||
ourLog.info(errors.toString());
|
||||
assertThat(errors.getMessages(), empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmbeddedItemInOpenChoice() {
|
||||
String questionnaireRef = "http://example.com/Questionnaire/q1";
|
||||
String valueSetRef = "http://somevalueset";
|
||||
String codeSystemUrl = "http://codesystems.com/system";
|
||||
String codeValue = "code0";
|
||||
|
||||
// create the questionnaire
|
||||
QuestionnaireItemComponent item1 = new QuestionnaireItemComponent();
|
||||
item1.setLinkId("link1")
|
||||
.setType(QuestionnaireItemType.OPENCHOICE)
|
||||
.setOptions(valueSetRef);
|
||||
|
||||
item1.addItem().setLinkId("link11")
|
||||
.setType(QuestionnaireItemType.TEXT);
|
||||
|
||||
Questionnaire q = new Questionnaire();
|
||||
q.addItem(item1);
|
||||
when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(questionnaireRef)))
|
||||
.thenReturn(q);
|
||||
|
||||
CodeSystem codeSystem = new CodeSystem();
|
||||
codeSystem.setContent(CodeSystemContentMode.COMPLETE);
|
||||
codeSystem.setUrl(codeSystemUrl);
|
||||
codeSystem.addConcept().setCode(codeValue);
|
||||
when(myValSupport.fetchCodeSystem(any(FhirContext.class), eq(codeSystemUrl)))
|
||||
.thenReturn(codeSystem);
|
||||
|
||||
ValueSet options = new ValueSet();
|
||||
options.getCompose().addInclude().setSystem(codeSystemUrl).addConcept().setCode(codeValue);
|
||||
when(myValSupport.fetchResource(any(FhirContext.class), eq(ValueSet.class), eq(valueSetRef)))
|
||||
.thenReturn(options);
|
||||
when(myValSupport.validateCode(any(FhirContext.class), eq(codeSystemUrl), eq(codeValue), any(String.class)))
|
||||
.thenReturn(new CodeValidationResult(new ConceptDefinitionComponent(new CodeType(codeValue))));
|
||||
|
||||
IParser xmlParser = ourCtx.newXmlParser().setPrettyPrint(true);
|
||||
String qXml = xmlParser.encodeResourceToString(q);
|
||||
ourLog.info(qXml);
|
||||
|
||||
// create the response
|
||||
QuestionnaireResponse qa = new QuestionnaireResponse();
|
||||
qa.setStatus(QuestionnaireResponseStatus.INPROGRESS);
|
||||
qa.setQuestionnaire(questionnaireRef);
|
||||
qa.addItem().setLinkId("link1")
|
||||
.addAnswer()
|
||||
.addItem().setLinkId("link11");
|
||||
|
||||
String rXml = xmlParser.encodeResourceToString(qa);
|
||||
ourLog.info(rXml);
|
||||
|
||||
ValidationResult errors = myVal.validateWithResult(qa);
|
||||
|
||||
ourLog.info(errors.toString());
|
||||
assertThat(errors.getMessages(), empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmbeddedItemInString() {
|
||||
String questionnaireRef = "http://example.com/Questionnaire/q1";
|
||||
|
||||
// create the questionnaire
|
||||
QuestionnaireItemComponent item1 = new QuestionnaireItemComponent();
|
||||
item1.setLinkId("link1")
|
||||
.setType(QuestionnaireItemType.TEXT);
|
||||
|
||||
item1.addItem().setLinkId("link11")
|
||||
.setType(QuestionnaireItemType.TEXT);
|
||||
|
||||
Questionnaire q = new Questionnaire();
|
||||
q.addItem(item1);
|
||||
when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(questionnaireRef)))
|
||||
.thenReturn(q);
|
||||
|
||||
IParser xmlParser = ourCtx.newXmlParser().setPrettyPrint(true);
|
||||
String qXml = xmlParser.encodeResourceToString(q);
|
||||
ourLog.info(qXml);
|
||||
|
||||
// create the response
|
||||
QuestionnaireResponse qa = new QuestionnaireResponse();
|
||||
qa.setStatus(QuestionnaireResponseStatus.INPROGRESS);
|
||||
qa.setQuestionnaire(questionnaireRef);
|
||||
qa.addItem().setLinkId("link1")
|
||||
.addAnswer()
|
||||
.addItem().setLinkId("link11");
|
||||
|
||||
String rXml = xmlParser.encodeResourceToString(qa);
|
||||
ourLog.info(rXml);
|
||||
|
||||
ValidationResult errors = myVal.validateWithResult(qa);
|
||||
|
||||
ourLog.info(errors.toString());
|
||||
assertThat(errors.getMessages(), empty());
|
||||
}
|
||||
|
||||
public void testMissingRequiredAnswer() {
|
||||
Questionnaire q = new Questionnaire();
|
||||
q.addItem().setLinkId("link0")
|
||||
|
|
Loading…
Reference in New Issue