|
|
|
@ -14,10 +14,12 @@ class Form::Page
|
|
|
|
|
@subsection = subsection |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
delegate :form, to: :subsection |
|
|
|
|
|
|
|
|
|
def routed_to?(case_log) |
|
|
|
|
return true unless depends_on || subsection.depends_on |
|
|
|
|
|
|
|
|
|
subsection.enabled?(case_log) && depends_on_met(case_log) |
|
|
|
|
subsection.enabled?(case_log) && form.depends_on_met(depends_on, case_log) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def non_conditional_questions |
|
|
|
@ -36,27 +38,4 @@ private
|
|
|
|
|
q.conditional_for.keys if q.type == "radio" |
|
|
|
|
}.compact |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def send_chain(arr, case_log) |
|
|
|
|
Array(arr).inject(case_log) { |o, a| o.public_send(*a) } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def depends_on_met(case_log) |
|
|
|
|
return true unless depends_on |
|
|
|
|
|
|
|
|
|
depends_on.any? do |conditions_set| |
|
|
|
|
conditions_set.all? do |question, value| |
|
|
|
|
if value.is_a?(Hash) && value.key?("operator") |
|
|
|
|
operator = value["operator"] |
|
|
|
|
operand = value["operand"] |
|
|
|
|
case_log[question]&.send(operator, operand) |
|
|
|
|
else |
|
|
|
|
parts = question.split(".") |
|
|
|
|
case_log_value = send_chain(parts, case_log) |
|
|
|
|
|
|
|
|
|
value.nil? ? case_log_value == value : !case_log_value.nil? && case_log_value == value |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|