|
|
@ -2,7 +2,6 @@ class Form |
|
|
|
attr_reader :form_definition, :sections, :subsections, :pages, :questions, |
|
|
|
attr_reader :form_definition, :sections, :subsections, :pages, :questions, |
|
|
|
:start_date, :end_date, :type, :name, :setup_definition, |
|
|
|
:start_date, :end_date, :type, :name, :setup_definition, |
|
|
|
:setup_sections, :form_sections |
|
|
|
:setup_sections, :form_sections |
|
|
|
attr_accessor :current_user |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
include Form::Setup |
|
|
|
include Form::Setup |
|
|
|
|
|
|
|
|
|
|
@ -30,9 +29,9 @@ class Form |
|
|
|
pages.find { |p| p.id == id.to_s.underscore } |
|
|
|
pages.find { |p| p.id == id.to_s.underscore } |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def get_question(id, case_log) |
|
|
|
def get_question(id, case_log, current_user = nil) |
|
|
|
all_questions = questions.select { |q| q.id == id.to_s.underscore } |
|
|
|
all_questions = questions.select { |q| q.id == id.to_s.underscore } |
|
|
|
routed_question = all_questions.find { |q| q.page.routed_to?(case_log) } if case_log |
|
|
|
routed_question = all_questions.find { |q| q.page.routed_to?(case_log, current_user) } if case_log |
|
|
|
routed_question || all_questions[0] |
|
|
|
routed_question || all_questions[0] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -40,20 +39,24 @@ class Form |
|
|
|
subsections.find { |s| s.pages.find { |p| p.id == page.id } } |
|
|
|
subsections.find { |s| s.pages.find { |p| p.id == page.id } } |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def next_page(page, case_log) |
|
|
|
def next_page(page, case_log, current_user) |
|
|
|
page_ids = subsection_for_page(page).pages.map(&:id) |
|
|
|
page_ids = subsection_for_page(page).pages.map(&:id) |
|
|
|
page_index = page_ids.index(page.id) |
|
|
|
page_index = page_ids.index(page.id) |
|
|
|
page_id = page.id.include?("value_check") && case_log[page.questions[0].id] == 1 && page.routed_to?(case_log) ? previous_page(page_ids, page_index, case_log) : page_ids[page_index + 1] |
|
|
|
page_id = if page.id.include?("value_check") && case_log[page.questions[0].id] == 1 && page.routed_to?(case_log, current_user) |
|
|
|
|
|
|
|
previous_page(page_ids, page_index, case_log, current_user) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
page_ids[page_index + 1] |
|
|
|
|
|
|
|
end |
|
|
|
nxt_page = get_page(page_id) |
|
|
|
nxt_page = get_page(page_id) |
|
|
|
|
|
|
|
|
|
|
|
return :check_answers if nxt_page.nil? |
|
|
|
return :check_answers if nxt_page.nil? |
|
|
|
return nxt_page.id if nxt_page.routed_to?(case_log) |
|
|
|
return nxt_page.id if nxt_page.routed_to?(case_log, current_user) |
|
|
|
|
|
|
|
|
|
|
|
next_page(nxt_page, case_log) |
|
|
|
next_page(nxt_page, case_log, current_user) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def next_page_redirect_path(page, case_log) |
|
|
|
def next_page_redirect_path(page, case_log, current_user) |
|
|
|
nxt_page = next_page(page, case_log) |
|
|
|
nxt_page = next_page(page, case_log, current_user) |
|
|
|
if nxt_page == :check_answers |
|
|
|
if nxt_page == :check_answers |
|
|
|
"case_log_#{subsection_for_page(page).id}_check_answers_path" |
|
|
|
"case_log_#{subsection_for_page(page).id}_check_answers_path" |
|
|
|
else |
|
|
|
else |
|
|
@ -115,23 +118,22 @@ class Form |
|
|
|
}.flatten |
|
|
|
}.flatten |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def invalidated_pages(case_log) |
|
|
|
def invalidated_pages(case_log, current_user = nil) |
|
|
|
pages.select { |p| p.invalidated?(case_log) } |
|
|
|
pages.reject { |p| p.routed_to?(case_log, current_user) } |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def invalidated_questions(case_log) |
|
|
|
def invalidated_questions(case_log) |
|
|
|
invalidated_page_questions(case_log) + invalidated_conditional_questions(case_log) |
|
|
|
invalidated_page_questions(case_log) + invalidated_conditional_questions(case_log) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def invalidated_page_questions(case_log) |
|
|
|
def invalidated_page_questions(case_log, current_user = nil) |
|
|
|
# we're already treating address fields as a special case and reset their values upon saving a case_log |
|
|
|
# we're already treating address fields as a special case and reset their values upon saving a case_log |
|
|
|
address_questions = %w[postcode_known la ppcodenk previous_la_known prevloc postcode_full ppostcode_full] |
|
|
|
address_questions = %w[postcode_known la ppcodenk previous_la_known prevloc postcode_full ppostcode_full] |
|
|
|
invalidated_pages(case_log).flat_map(&:questions).reject { |q| address_questions.include?(q.id) } || [] |
|
|
|
questions.reject { |q| q.page.routed_to?(case_log, current_user) || q.derived? || address_questions.include?(q.id) } || [] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def enabled_page_questions(case_log) |
|
|
|
def enabled_page_questions(case_log) |
|
|
|
pages_that_are_routed_to_or_derived = pages.select { |p| p.routed_to?(case_log) || p.derived } |
|
|
|
questions - invalidated_page_questions(case_log) |
|
|
|
pages_that_are_routed_to_or_derived.flat_map(&:questions) || [] |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def invalidated_conditional_questions(case_log) |
|
|
|
def invalidated_conditional_questions(case_log) |
|
|
@ -146,11 +148,11 @@ class Form |
|
|
|
questions.select { |q| q.type == "numeric" } |
|
|
|
questions.select { |q| q.type == "numeric" } |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def previous_page(page_ids, page_index, case_log) |
|
|
|
def previous_page(page_ids, page_index, case_log, current_user) |
|
|
|
prev_page = get_page(page_ids[page_index - 1]) |
|
|
|
prev_page = get_page(page_ids[page_index - 1]) |
|
|
|
return prev_page.id if prev_page.routed_to?(case_log) |
|
|
|
return prev_page.id if prev_page.routed_to?(case_log, current_user) |
|
|
|
|
|
|
|
|
|
|
|
previous_page(page_ids, page_index - 1, case_log) |
|
|
|
previous_page(page_ids, page_index - 1, case_log, current_user) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def send_chain(arr, case_log) |
|
|
|
def send_chain(arr, case_log) |
|
|
|