From 3c56640d579b444c0ab6773afcd8af0849bffeab Mon Sep 17 00:00:00 2001 From: Matti Uusitalo Date: Thu, 13 Dec 2018 13:29:17 +0200 Subject: [PATCH] Do not force enableWhen to have system --- hapi-fhir-validation/pom.xml | 2 +- .../DefaultEnableWhenEvaluator.java | 2 +- ...estionnaireResponseValidatorDstu3Test.java | 29 +++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-validation/pom.xml b/hapi-fhir-validation/pom.xml index 39a6c5f7d16..3a7742e2efd 100644 --- a/hapi-fhir-validation/pom.xml +++ b/hapi-fhir-validation/pom.xml @@ -11,7 +11,7 @@ hapi-fhir-validation bundle - 3.6.3-PHRFIX + 3.6.4-PHRFIX HAPI FHIR - Validation diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/r4/validation/DefaultEnableWhenEvaluator.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/r4/validation/DefaultEnableWhenEvaluator.java index 291e9cba785..9588fa0373c 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/r4/validation/DefaultEnableWhenEvaluator.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/r4/validation/DefaultEnableWhenEvaluator.java @@ -188,7 +188,7 @@ public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator { } private boolean compareSystems(Coding expectedCoding, Coding value) { - if (expectedCoding.hasSystem() != value.hasSystem()) { + if (expectedCoding.hasSystem() && !value.hasSystem()) { return false; } if (expectedCoding.hasSystem()) { diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireResponseValidatorDstu3Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireResponseValidatorDstu3Test.java index ac2d4876148..e1ffa326572 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireResponseValidatorDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireResponseValidatorDstu3Test.java @@ -580,6 +580,35 @@ public class QuestionnaireResponseValidatorDstu3Test { } + @Test + public void testChoiceItemsEnableWhenHasNoSystemYetAnswerHasSystem() throws Exception { + Questionnaire q = new Questionnaire(); + Coding qcoding = new Coding(); + qcoding.setCode("male"); + qcoding.setSystem("http://hl7.org/fhir/administrative-gender"); + q.addItem().setLinkId("1B").setRequired(true).setType(CHOICE).addOption().setValue(qcoding); + Coding enablewhenCoding = new Coding(); + enablewhenCoding.setCode("male"); + q.addItem().setLinkId("2B").setType(BOOLEAN).addEnableWhen().setQuestion("1B").setAnswer(enablewhenCoding); + + QuestionnaireResponse qr = new QuestionnaireResponse(); + qr.setStatus(COMPLETED); + qr.getQuestionnaire().setReference(QUESTIONNAIRE_URL); + QuestionnaireResponseItemComponent qrItem = qr.addItem().setLinkId("1B"); + Coding coding = new Coding(); + coding.setCode("male"); + coding.setSystem("http://hl7.org/fhir/administrative-gender"); + QuestionnaireResponseItemAnswerComponent answer = qrItem.addAnswer(); + answer.setValue(coding); + qr.addItem().setLinkId("2B").addAnswer().setValue(new BooleanType(true)); + + 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(), containsString("No issues")); + } + @Test public void testEmbeddedItemInChoice() { String questionnaireRef = QUESTIONNAIRE_URL;