cleanup
This commit is contained in:
parent
3a1d621f65
commit
52246a8ce5
|
@ -35,7 +35,6 @@ import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
||||||
/**
|
/**
|
||||||
* Evaluates Questionnaire.item.enableWhen against a QuestionnaireResponse.
|
* Evaluates Questionnaire.item.enableWhen against a QuestionnaireResponse.
|
||||||
* Ignores possible modifierExtensions and extensions.
|
* Ignores possible modifierExtensions and extensions.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class EnableWhenEvaluator {
|
public class EnableWhenEvaluator {
|
||||||
public static final String LINKID_ELEMENT = "linkId";
|
public static final String LINKID_ELEMENT = "linkId";
|
||||||
|
@ -52,14 +51,17 @@ public class EnableWhenEvaluator {
|
||||||
this.q = q;
|
this.q = q;
|
||||||
this.a = a;
|
this.a = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QuestionnaireItemComponent getQ() {
|
public QuestionnaireItemComponent getQ() {
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Element getA() {
|
public Element getA() {
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class QStack extends ArrayList<QuestionnaireAnswerPair> {
|
public static class QStack extends ArrayList<QuestionnaireAnswerPair> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
@ -98,14 +100,8 @@ public class EnableWhenEvaluator {
|
||||||
/**
|
/**
|
||||||
* Evaluation result of enableWhen condition
|
* Evaluation result of enableWhen condition
|
||||||
*
|
*
|
||||||
* @param enabled
|
* @param enabled Evaluation result
|
||||||
* Evaluation result
|
* @param enableWhenCondition Evaluated enableWhen condition
|
||||||
* @param linkId
|
|
||||||
* LinkId of the questionnaire item
|
|
||||||
* @param enableWhenCondition
|
|
||||||
* Evaluated enableWhen condition
|
|
||||||
* @param responseItem
|
|
||||||
* item in QuestionnaireResponse
|
|
||||||
*/
|
*/
|
||||||
public EnableWhenResult(boolean enabled, QuestionnaireItemEnableWhenComponent enableWhenCondition) {
|
public EnableWhenResult(boolean enabled, QuestionnaireItemEnableWhenComponent enableWhenCondition) {
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
|
@ -120,17 +116,13 @@ public class EnableWhenEvaluator {
|
||||||
return enableWhenCondition;
|
return enableWhenCondition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the stack contains a set of QR items that represent the tree of the QR being validated, each tagged with the definition of the item from the Q for the QR being validated
|
* the stack contains a set of QR items that represent the tree of the QR being validated, each tagged with the definition of the item from the Q for the QR being validated
|
||||||
*
|
* <p>
|
||||||
* the itembeing validated is in the context of the stack. For root items, the stack is empty.
|
* the itembeing validated is in the context of the stack. For root items, the stack is empty.
|
||||||
*
|
* <p>
|
||||||
* The context Questionnaire and QuestionnaireResponse are always available
|
* The context Questionnaire and QuestionnaireResponse are always available
|
||||||
*
|
|
||||||
* @param questionnaireItem
|
|
||||||
* @param questionnaireResponse
|
|
||||||
* @param qstack
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public boolean isQuestionEnabled(ValidatorHostContext hostContext, QuestionnaireItemComponent qitem, QStack qstack, FHIRPathEngine engine) {
|
public boolean isQuestionEnabled(ValidatorHostContext hostContext, QuestionnaireItemComponent qitem, QStack qstack, FHIRPathEngine engine) {
|
||||||
if (hasExpressionExtension(qitem)) {
|
if (hasExpressionExtension(qitem)) {
|
||||||
|
@ -174,7 +166,8 @@ public class EnableWhenEvaluator {
|
||||||
public boolean checkConditionResults(List<EnableWhenResult> evaluationResults, QuestionnaireItemComponent questionnaireItem) {
|
public boolean checkConditionResults(List<EnableWhenResult> evaluationResults, QuestionnaireItemComponent questionnaireItem) {
|
||||||
if ((questionnaireItem.hasEnableBehavior() && questionnaireItem.getEnableBehavior() == EnableWhenBehavior.ANY) || evaluationResults.size() == 1) {
|
if ((questionnaireItem.hasEnableBehavior() && questionnaireItem.getEnableBehavior() == EnableWhenBehavior.ANY) || evaluationResults.size() == 1) {
|
||||||
return evaluationResults.stream().anyMatch(EnableWhenResult::isEnabled);
|
return evaluationResults.stream().anyMatch(EnableWhenResult::isEnabled);
|
||||||
} if (questionnaireItem.hasEnableBehavior() && questionnaireItem.getEnableBehavior() == EnableWhenBehavior.ALL){
|
}
|
||||||
|
if (questionnaireItem.hasEnableBehavior() && questionnaireItem.getEnableBehavior() == EnableWhenBehavior.ALL) {
|
||||||
return evaluationResults.stream().allMatch(EnableWhenResult::isEnabled);
|
return evaluationResults.stream().allMatch(EnableWhenResult::isEnabled);
|
||||||
}
|
}
|
||||||
//TODO: Throw exception? enableBehavior is mandatory when there are multiple conditions
|
//TODO: Throw exception? enableBehavior is mandatory when there are multiple conditions
|
||||||
|
@ -289,13 +282,13 @@ public class EnableWhenEvaluator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively look for answers to questions with the given link id, working upwards given the context
|
* Recursively look for answers to questions with the given link id, working upwards given the context
|
||||||
*
|
* <p>
|
||||||
* For discussion about this, see https://chat.fhir.org/#narrow/stream/179255-questionnaire/topic/enable-when
|
* For discussion about this, see https://chat.fhir.org/#narrow/stream/179255-questionnaire/topic/enable-when
|
||||||
*
|
* <p>
|
||||||
- given sourceQ - question that contains the enableWhen reference and targetQ - question that the enableWhen references in the Q and also sourceA - answer for sourceQ and targetA - answer for targetQ in the QR
|
* - given sourceQ - question that contains the enableWhen reference and targetQ - question that the enableWhen references in the Q and also sourceA - answer for sourceQ and targetA - answer for targetQ in the QR
|
||||||
- work up from sourceQ until you find the Q group that also contains targetQ - this is groupQ
|
* - work up from sourceQ until you find the Q group that also contains targetQ - this is groupQ
|
||||||
- work up from sourceA until you find the QR group that matches groupQ - this is groupA
|
* - work up from sourceA until you find the QR group that matches groupQ - this is groupA
|
||||||
- any targetA in groupA are input for the enableWhen decision
|
* - any targetA in groupA are input for the enableWhen decision
|
||||||
*/
|
*/
|
||||||
private List<Element> findQuestionAnswers(QStack qstack, QuestionnaireItemComponent sourceQ, QuestionnaireItemEnableWhenComponent ew) {
|
private List<Element> findQuestionAnswers(QStack qstack, QuestionnaireItemComponent sourceQ, QuestionnaireItemEnableWhenComponent ew) {
|
||||||
QuestionnaireItemComponent targetQ = qstack.getQ().getQuestion(ew.getQuestion());
|
QuestionnaireItemComponent targetQ = qstack.getQ().getQuestion(ew.getQuestion());
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.hl7.fhir.validation.profile;
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
Loading…
Reference in New Issue