Skip to content

Commit 8770c64

Browse files
committed
Refactor how consent forms are modelled per programme
This refactors how consents forms model the information related to giving consent to multiple programmes in the same form. This change isn't strictly related to Flu, but future work will build upon it. The main change is to move whether a programme has been given consent for or not out of the `ConsentForm` model and in to the individual `ConsentFormProgramme` models. At the moment we only support up to two programmes in a single consent form, but this would open the door to allowing more than two programmes in a single consent form. Where before the model looked something like: - `ConsentForm` with many programmes - `response` one of `given`, `given_one` or `refused` - `chosen_vaccines` either `nil` or `hpv`, `menacwy`, `td_ipv` The model now looks something like: - `ConsentForm` with many programmes - Each programme - `response` one of either `given` or `refused` I've made this change in preparation for Flu where we will also need to store the preferred vaccine method or methods and the `ConsentFormProgramme` seemed like the right place for it. Although this could be done without this refactor, there was a mismatch between where we were storing the consent response and where we were storing preferences specific to the programme. Jira-Issue: MAV-1230
1 parent c3b6eb5 commit 8770c64

File tree

18 files changed

+303
-207
lines changed

18 files changed

+303
-207
lines changed

app/components/app_consent_confirmation_component.rb

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,22 @@ def initialize(consent_form)
1414
end
1515

1616
def title
17-
case response
18-
when "given"
19-
"Consent confirmed"
20-
when "given_one"
21-
chosen_programme = chosen_programmes.first.name
22-
"Consent for the #{chosen_programme} vaccination confirmed"
23-
when "refused"
24-
"Consent refused"
17+
if response_given?
18+
if refused_programmes.empty?
19+
"Consent confirmed"
20+
else
21+
"Consent for the #{given_vaccinations} confirmed"
22+
end
2523
else
26-
raise "unrecognised consent response: #{response}"
24+
"Consent refused"
2725
end
2826
end
2927

3028
private
3129

32-
delegate :chosen_programmes,
33-
:not_chosen_programmes,
34-
:response,
30+
delegate :given_programmes,
31+
:refused_programmes,
32+
:response_given?,
3533
:parent_email,
3634
to: :@consent_form
3735

@@ -40,33 +38,26 @@ def full_name
4038
end
4139

4240
def panel_text
43-
case response
44-
when "given", "given_one"
41+
if response_given?
4542
if @consent_form.needs_triage?
4643
<<-END_OF_TEXT
4744
As you answered ‘yes’ to some of the health questions, we need to check
48-
the #{chosen_vaccinations_are} suitable for #{full_name}. We’ll review
45+
the #{given_vaccinations_are} suitable for #{full_name}. We’ll review
4946
your answers and get in touch again soon.
5047
END_OF_TEXT
5148
else
52-
"#{full_name} is due to get the #{chosen_vaccinations} at school" +
49+
"#{full_name} is due to get the #{given_vaccinations} at school" +
5350
(session_dates.present? ? " on #{session_dates}" : "")
5451
end
55-
when "refused"
56-
"You’ve told us that you do not want #{full_name} to get the" \
57-
" #{not_chosen_vaccinations} at school"
5852
else
59-
raise "unrecognised consent response: #{response}"
53+
"You’ve told us that you do not want #{full_name} to get the" \
54+
" #{refused_vaccinations} at school"
6055
end
6156
end
6257

63-
def chosen_vaccinations
64-
vaccinations_text(chosen_programmes)
65-
end
58+
def given_vaccinations = vaccinations_text(given_programmes)
6659

67-
def not_chosen_vaccinations
68-
vaccinations_text(not_chosen_programmes)
69-
end
60+
def refused_vaccinations = vaccinations_text(refused_programmes)
7061

7162
def vaccinations_text(programmes)
7263
programme_names =
@@ -79,8 +70,8 @@ def vaccinations_text(programmes)
7970
)
8071
end
8172

82-
def chosen_vaccinations_are
83-
"#{chosen_vaccinations} #{chosen_programmes.one? ? "is" : "are"}"
73+
def given_vaccinations_are
74+
"#{given_vaccinations} #{given_programmes.one? ? "is" : "are"}"
8475
end
8576

8677
def session_dates

app/controllers/concerns/consent_form_mailer_concern.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ module ConsentFormMailerConcern
44
extend ActiveSupport::Concern
55

66
def send_consent_form_confirmation(consent_form)
7-
if consent_form.consent_refused?
8-
send_consent_form_confirmation_refused(consent_form)
9-
else
7+
if consent_form.response_given?
108
ProgrammeGrouper
11-
.call(consent_form.chosen_programmes)
9+
.call(consent_form.given_programmes)
1210
.each_value do |programmes|
1311
if consent_form.needs_triage?
1412
EmailDeliveryJob.perform_later(
@@ -41,10 +39,12 @@ def send_consent_form_confirmation(consent_form)
4139
end
4240

4341
ProgrammeGrouper
44-
.call(consent_form.not_chosen_programmes)
42+
.call(consent_form.refused_programmes)
4543
.each_value do |programmes|
4644
send_consent_form_confirmation_refused(consent_form, programmes:)
4745
end
46+
else
47+
send_consent_form_confirmation_refused(consent_form)
4848
end
4949
end
5050

app/controllers/parent_interface/consent_forms/edit_controller.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class ConsentForms::EditController < ConsentForms::BaseController
1111
HOME_EDUCATED_SCHOOL_ID = "home-educated"
1212

1313
def show
14+
set_response if current_step == :consent
15+
1416
render_wizard
1517
end
1618

@@ -47,6 +49,7 @@ def update
4749
jump_to("contact-method", skip_to_confirm: true)
4850
end
4951
elsif current_step == :consent
52+
@consent_form.update_programme_responses
5053
@consent_form.seed_health_questions
5154
end
5255

@@ -94,7 +97,7 @@ def update_params
9497
parent_contact_method_type
9598
parent_contact_method_other_details
9699
],
97-
consent: %i[response chosen_vaccine],
100+
consent: %i[response chosen_programme],
98101
reason: %i[reason],
99102
reason_notes: %i[reason_notes],
100103
address: %i[address_line_1 address_line_2 address_town address_postcode]
@@ -122,6 +125,18 @@ def set_health_answer
122125
@health_answer = @consent_form.health_answers[@question_number]
123126
end
124127

128+
def set_response
129+
if @consent_form.response_given? && @consent_form.response_refused?
130+
@consent_form.response = "given_one"
131+
@consent_form.chosen_programme =
132+
@consent_form.given_programmes.first&.type
133+
elsif @consent_form.response_given?
134+
@consent_form.response = "given"
135+
elsif @consent_form.response_refused?
136+
@consent_form.response = "refused"
137+
end
138+
end
139+
125140
def validate_params
126141
case current_step
127142
when :date_of_birth

app/models/consent.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def self.from_consent_form!(consent_form, patient:, current_user:)
159159
consent_form.find_or_create_parent_with_relationship_to!(patient:)
160160

161161
consent_given =
162-
consent_form.chosen_programmes.map do |programme|
162+
consent_form.given_programmes.map do |programme|
163163
patient.consents.create!(
164164
consent_form:,
165165
organisation: consent_form.organisation,
@@ -175,7 +175,7 @@ def self.from_consent_form!(consent_form, patient:, current_user:)
175175
end
176176

177177
consent_refused =
178-
consent_form.not_chosen_programmes.map do |programme|
178+
consent_form.refused_programmes.map do |programme|
179179
patient.consents.create!(
180180
consent_form:,
181181
organisation: consent_form.organisation,

0 commit comments

Comments
 (0)