Skip to content

Commit 17d5b7f

Browse files
committed
Seed verbal consent health questions
This ensures that if changing the response when recording a verbal consent, the health questions are seeded correctly to match the vaccines that have been consented to. Jira-Issue: MAV-1391
1 parent d361221 commit 17d5b7f

5 files changed

Lines changed: 66 additions & 12 deletions

File tree

app/controllers/draft_consents_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def update
4242
@draft_consent.assign_attributes(update_params)
4343
end
4444

45+
@draft_consent.seed_health_questions if current_step == :agree
46+
4547
jump_to("confirm") if @draft_consent.editing? && current_step != :confirm
4648

4749
set_steps

app/models/draft_consent.rb

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,40 @@ def vaccine_method_injection? = vaccine_methods.include?("injection")
355355

356356
def vaccine_method_nasal? = vaccine_methods.include?("nasal")
357357

358+
def seed_health_questions
359+
return unless response_given?
360+
361+
# If the health answers change due to the chosen vaccines changing, we
362+
# want to try and keep as much as what the parents already wrote intact.
363+
# We do this be saving the answers to the question title (as the IDs
364+
# and ordering can change).
365+
366+
existing_health_answers =
367+
health_answers.each_with_object({}) do |health_answer, memo|
368+
memo[health_answer.question] = {
369+
response: health_answer.response,
370+
notes: health_answer.notes
371+
}
372+
end
373+
374+
vaccines = programme.vaccines.where(method: vaccine_methods)
375+
376+
self.health_answers =
377+
HealthAnswersDeduplicator
378+
.call(vaccines:)
379+
.map do |health_answer|
380+
if (
381+
existing_health_answer =
382+
existing_health_answers[health_answer.question]
383+
)
384+
health_answer.response = existing_health_answer[:response]
385+
health_answer.notes = existing_health_answer[:notes]
386+
end
387+
388+
health_answer
389+
end
390+
end
391+
358392
private
359393

360394
def readable_attribute_names
@@ -408,10 +442,7 @@ def reset_unused_fields
408442
self.notes = "" unless notes_required?
409443

410444
if response_given?
411-
if health_answers.empty?
412-
vaccine = programme.vaccines.first # assumes all vaccines in the programme have the same questions
413-
self.health_answers = vaccine.health_questions.to_health_answers
414-
end
445+
seed_health_questions if health_answers.empty?
415446
else
416447
self.health_answers = []
417448
end

app/views/draft_consents/questions.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
<% @draft_consent.health_answers.each_with_index do |health_answer, index| %>
1818
<%= f.fields_for "question_#{index}", health_answer do |ff| %>
19-
<%= ff.govuk_radio_buttons_fieldset(:question,
19+
<%= ff.govuk_radio_buttons_fieldset :question,
2020
legend: { size: "s", text: health_answer.question },
21-
hint: { text: health_answer.hint }) do %>
21+
hint: { text: health_answer.hint } do %>
2222
<%= ff.govuk_radio_button :response, "yes",
2323
label: { text: "Yes" },
2424
link_errors: true do %>

spec/features/self_consent_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ def and_the_nurse_records_consent_for_the_child
237237

238238
def and_the_child_can_give_their_own_consent_that_the_nurse_records
239239
click_on "Change method"
240+
240241
choose "Child (Gillick competent)"
241242
5.times { click_on "Continue" }
242243

spec/features/verbal_consent_given_spec.rb

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
# frozen_string_literal: true
22

33
describe "Verbal consent" do
4-
scenario "Given" do
4+
scenario "Given HPV" do
55
given_an_hpv_programme_is_underway
66
and_i_am_signed_in
7+
78
when_i_record_that_verbal_consent_was_given
89
then_an_email_is_sent_to_the_parent_confirming_their_consent
910
and_a_text_is_sent_to_the_parent_confirming_their_consent
1011
and_the_patients_status_is_safe_to_vaccinate
1112
and_i_can_see_the_consent_response_details
1213
end
1314

14-
scenario "Given flu nasal consent" do
15+
scenario "Given flu nasal spray" do
1516
given_an_flu_programme_is_underway
1617
and_i_am_signed_in
18+
1719
when_i_record_that_verbal_nasal_consent_was_given
1820
and_the_patients_status_is_safe_to_vaccinate_with_nasal_spray
1921
end
2022

23+
scenario "Given flu nasal spray and injection" do
24+
given_an_flu_programme_is_underway
25+
and_i_am_signed_in
26+
27+
when_i_record_that_verbal_nasal_and_injection_consent_was_given
28+
end
29+
2130
def given_an_hpv_programme_is_underway
2231
create_programme(:hpv)
2332
end
@@ -41,19 +50,32 @@ def create_programme(programme_type)
4150
end
4251

4352
def when_i_record_that_verbal_consent_was_given
44-
record_that_verbal_consent_was_given(consent_option: "Yes, they agree")
53+
record_that_verbal_consent_was_given(
54+
consent_option: "Yes, they agree",
55+
number_of_health_questions: 4
56+
)
4557
end
4658

4759
def when_i_record_that_verbal_nasal_consent_was_given
4860
record_that_verbal_consent_was_given(
4961
consent_option: "Yes, for the nasal spray",
62+
number_of_health_questions: 10,
63+
triage_option: "Yes, it’s safe to vaccinate with nasal spray"
64+
)
65+
end
66+
67+
def when_i_record_that_verbal_nasal_and_injection_consent_was_given
68+
record_that_verbal_consent_was_given(
69+
consent_option: "Yes, for the nasal spray",
70+
number_of_health_questions: 11,
5071
triage_option: "Yes, it’s safe to vaccinate with nasal spray",
5172
injective_alternative: true
5273
)
5374
end
5475

5576
def record_that_verbal_consent_was_given(
5677
consent_option:,
78+
number_of_health_questions:,
5779
triage_option: "Yes, it’s safe to vaccinate",
5880
injective_alternative: false
5981
)
@@ -86,11 +108,9 @@ def record_that_verbal_consent_was_given(
86108
if consent_option.include?("nasal")
87109
choose injective_alternative ? "Yes" : "No"
88110
end
89-
90111
click_button "Continue"
91112

92-
# assumes all vaccines in the programme have the same questions
93-
@programme.vaccines.first.health_questions.size.times do |index|
113+
number_of_health_questions.times do |index|
94114
find_all(".nhsuk-fieldset")[index].choose "No"
95115
end
96116

0 commit comments

Comments
 (0)