Added operator evaluation for R4 enableWhen
This commit is contained in:
parent
69d9e5d2b2
commit
a12f5892e2
|
@ -36,8 +36,6 @@ import org.hl7.fhir.dstu3.model.Type;
|
|||
import org.hl7.fhir.dstu3.model.UriType;
|
||||
import org.hl7.fhir.dstu3.model.ValueSet;
|
||||
import org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionContainsComponent;
|
||||
import org.hl7.fhir.instance.validation.DefaultEnableWhenEvaluator;
|
||||
import org.hl7.fhir.instance.validation.IEnableWhenEvaluator;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;
|
||||
|
||||
|
@ -57,17 +55,6 @@ public class QuestionnaireResponseValidator extends BaseValidator {
|
|||
*/
|
||||
|
||||
private IWorkerContext myWorkerCtx;
|
||||
|
||||
// this is here not to introduce enabledWhen validation unless wanted
|
||||
private boolean skipEnabledCheck = true;
|
||||
|
||||
public boolean isSkipEnabledCheck() {
|
||||
return skipEnabledCheck;
|
||||
}
|
||||
|
||||
public void setSkipEnabledCheck(boolean skipEnabledCheck) {
|
||||
this.skipEnabledCheck = skipEnabledCheck;
|
||||
}
|
||||
|
||||
public QuestionnaireResponseValidator(IWorkerContext theWorkerCtx) {
|
||||
this.myWorkerCtx = theWorkerCtx;
|
||||
|
@ -228,7 +215,7 @@ public class QuestionnaireResponseValidator extends BaseValidator {
|
|||
|
||||
List<QuestionnaireResponseItemComponent> responseItems = findResponsesByLinkId(theResponseItems, linkId);
|
||||
if (responseItems.isEmpty()) {
|
||||
if ((skipEnabledCheck /*|| myEnableWhenEvaluator.isQuestionEnabled(nextQuestionnaireItem, theResponseItems)*/) && nextQuestionnaireItem.getRequired() ) {
|
||||
if (nextQuestionnaireItem.getRequired()) {
|
||||
if (theValidateRequired) {
|
||||
rule(theErrors, IssueType.BUSINESSRULE, thePathStack, false, "Missing required {0} with linkId[{1}]", itemType, linkId);
|
||||
} else {
|
||||
|
@ -403,3 +390,4 @@ public class QuestionnaireResponseValidator extends BaseValidator {
|
|||
return allowedAnswerTypes;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,110 +0,0 @@
|
|||
package org.hl7.fhir.instance.validation;
|
||||
|
||||
import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent;
|
||||
import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemEnableWhenComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hl7.fhir.dstu3.model.QuestionnaireResponse;
|
||||
import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseItemComponent;
|
||||
import org.hl7.fhir.r4.elementmodel.Element;
|
||||
|
||||
public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator {
|
||||
|
||||
@Override
|
||||
public boolean isQuestionEnabled(QuestionnaireItemComponent item, List<QuestionnaireResponseItemComponent> resp) {
|
||||
|
||||
boolean enabled = true;
|
||||
|
||||
if(item.hasEnableWhen()) {
|
||||
|
||||
enabled = false;
|
||||
|
||||
for( QuestionnaireItemEnableWhenComponent enable : item.getEnableWhen()) {
|
||||
|
||||
if(enable.getHasAnswer()) {
|
||||
// check if referenced question has answer
|
||||
|
||||
String itemId = enable.getQuestion();
|
||||
|
||||
for(QuestionnaireResponseItemComponent respItem : resp) {
|
||||
if(respItem.getLinkId().equalsIgnoreCase(itemId) && respItem.hasAnswer()) {
|
||||
|
||||
//TODO check answer value
|
||||
enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// and if not
|
||||
|
||||
String itemId = enable.getQuestion();
|
||||
|
||||
for(QuestionnaireResponseItemComponent respItem : resp) {
|
||||
if(respItem.getLinkId().equalsIgnoreCase(itemId) && !respItem.hasAnswer()) {
|
||||
|
||||
//TODO check answer value
|
||||
|
||||
enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isQuestionEnabled(org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent item,
|
||||
Element element) {
|
||||
boolean enabled = true;
|
||||
|
||||
if(item.hasEnableWhen()) {
|
||||
|
||||
enabled = false;
|
||||
|
||||
for( org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemEnableWhenComponent enable : item.getEnableWhen()) {
|
||||
|
||||
if(enable.hasAnswer()) {
|
||||
// check if referenced question has answer
|
||||
|
||||
String itemId = enable.getQuestion();
|
||||
|
||||
List<Element> items = new ArrayList<Element>();
|
||||
element.getNamedChildren("item", items);
|
||||
|
||||
for(Element respItem : items) {
|
||||
|
||||
// TODO toteuta uudelleen
|
||||
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
// and if not
|
||||
|
||||
String itemId = enable.getQuestion();
|
||||
|
||||
List<Element> items = new ArrayList<Element>();
|
||||
element.getNamedChildren("item", items);
|
||||
|
||||
for(Element respItem : items) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return enabled;
|
||||
}
|
||||
|
||||
}
|
|
@ -46,6 +46,7 @@ public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator {
|
|||
|
||||
protected EnableWhenResult evaluateCondition(QuestionnaireItemEnableWhenComponent enableCondition,
|
||||
Element questionnaireResponse, String linkId) {
|
||||
//TODO: Fix EnableWhenResult stuff
|
||||
List<Element> answerItems = findQuestionAnswers(questionnaireResponse,
|
||||
enableCondition.getQuestion());
|
||||
QuestionnaireItemOperator operator = enableCondition.getOperator();
|
||||
|
@ -98,6 +99,7 @@ public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator {
|
|||
} else if (questionnaireItemOperator == QuestionnaireItemOperator.GREATER_THAN){
|
||||
return result > 0;
|
||||
}
|
||||
throw new RuntimeException("Bad operator for PrimitiveType comparison");
|
||||
} else if (questionnaireItemOperator == QuestionnaireItemOperator.EQUAL){
|
||||
return actualAnswer.equalsShallow(expectedAnswer);
|
||||
} else if (questionnaireItemOperator == QuestionnaireItemOperator.NOT_EQUAL){
|
||||
|
@ -155,7 +157,7 @@ public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator {
|
|||
return true;
|
||||
}
|
||||
private List<Element> findSubItems(Element item) {
|
||||
List<Element> results = item.getChildren(ITEM_ELEMENT)
|
||||
List<Element> results = item.getChildren(LINKID_ELEMENT)
|
||||
.stream()
|
||||
.flatMap(i -> findSubItems(i).stream())
|
||||
.collect(Collectors.toList());
|
||||
|
@ -170,7 +172,4 @@ public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,8 +12,6 @@ import org.hl7.fhir.exceptions.DefinitionException;
|
|||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
import org.hl7.fhir.exceptions.PathEngineException;
|
||||
import org.hl7.fhir.exceptions.TerminologyServiceException;
|
||||
import org.hl7.fhir.instance.validation.DefaultEnableWhenEvaluator;
|
||||
import org.hl7.fhir.instance.validation.IEnableWhenEvaluator;
|
||||
import org.hl7.fhir.r4.conformance.ProfileUtilities;
|
||||
import org.hl7.fhir.r4.context.IWorkerContext;
|
||||
import org.hl7.fhir.r4.context.IWorkerContext.ValidationResult;
|
||||
|
|
Loading…
Reference in New Issue