Search in sources :

Example 6 with QuestionnaireItemEnableWhenComponent

use of org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemEnableWhenComponent in project org.hl7.fhir.core by hapifhir.

the class EnableWhenEvaluator method isQuestionEnabled.

/**
 * 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.
 * <p>
 * The context Questionnaire and QuestionnaireResponse are always available
 */
public boolean isQuestionEnabled(ValidatorHostContext hostContext, QuestionnaireItemComponent qitem, QStack qstack, FHIRPathEngine engine) {
    if (hasExpressionExtension(qitem)) {
        String expr = getExpression(qitem);
        ExpressionNode node = engine.parse(expr);
        return engine.evaluateToBoolean(hostContext, qstack.a, qstack.a, qstack.a, node);
    }
    if (!qitem.hasEnableWhen()) {
        return true;
    }
    List<EnableWhenResult> evaluationResults = new ArrayList<>();
    for (QuestionnaireItemEnableWhenComponent enableCondition : qitem.getEnableWhen()) {
        evaluationResults.add(evaluateCondition(enableCondition, qitem, qstack));
    }
    return checkConditionResults(evaluationResults, qitem);
}
Also used : ExpressionNode(org.hl7.fhir.r5.model.ExpressionNode) ArrayList(java.util.ArrayList) QuestionnaireItemEnableWhenComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemEnableWhenComponent)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)4 ArrayList (java.util.ArrayList)3 QuestionnaireItemEnableWhenComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemEnableWhenComponent)3 QuestionnaireItemComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemComponent)2 QuestionnaireItemEnableWhenComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemEnableWhenComponent)2 QuestionnaireItemInitialComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemInitialComponent)2 ValueSet (org.hl7.fhir.r4b.model.ValueSet)2 QuestionnaireItemComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent)2 QuestionnaireItemInitialComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemInitialComponent)2 ValueSet (org.hl7.fhir.r5.model.ValueSet)2 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)2 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)2 Row (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)2 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)1 CodeableConcept (org.hl7.fhir.r4b.model.CodeableConcept)1 Coding (org.hl7.fhir.r4b.model.Coding)1 Extension (org.hl7.fhir.r4b.model.Extension)1 QuestionnaireItemAnswerOptionComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemAnswerOptionComponent)1 Element (org.hl7.fhir.r5.elementmodel.Element)1 BooleanType (org.hl7.fhir.r5.model.BooleanType)1