Skip to content

Commit 3c87bb1

Browse files
committed
Add changing campaign vaccines
This adds a new step for editing campaigns where the user can choose the vaccines that belong to a campaign. When creating a campaign the vaccines default to the active vaccines for a particular programme type, but we may need to add discontinued vaccines to campaigns that happened in the past, to support importing historical records.
1 parent 64c5c55 commit 3c87bb1

File tree

6 files changed

+77
-5
lines changed

6 files changed

+77
-5
lines changed

app/controllers/campaigns/edit_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ def dates_params
4848
params.require(:campaign).permit(:start_date, :end_date)
4949
end
5050

51+
def vaccines_params
52+
params.require(:campaign).permit(vaccine_ids: [])
53+
end
54+
5155
def confirm_params
5256
{ active: true }
5357
end

app/models/campaign.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,26 @@ class Campaign < ApplicationRecord
7979
}
8080
end
8181

82+
on_wizard_step :vaccines do
83+
validates :vaccines, presence: true
84+
end
85+
8286
on_wizard_step :confirm do
8387
validates :active, presence: true
8488
end
8589

8690
validate :vaccines_match_type
8791

8892
def wizard_steps
89-
%i[details dates confirm]
93+
[:details, :dates, (:vaccines if active), :confirm].compact
94+
end
95+
96+
def vaccine_ids
97+
@vaccine_ids ||= vaccines.map(&:id)
98+
end
99+
100+
def vaccine_ids=(ids)
101+
self.vaccines = Vaccine.where(id: ids)
90102
end
91103

92104
private

app/views/campaigns/edit/confirm.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<%= summary_list.with_row do |row| %>
4949
<%= row.with_key { "Vaccines" } %>
5050
<%= row.with_value { @campaign.vaccines.map(&:brand).join("<br>").html_safe } %>
51+
<%= row.with_action(text: "Change", href: campaign_edit_path(@campaign, :vaccines), visually_hidden_text: "vaccines") %>
5152
<% end %>
5253
<% end %>
5354
<% end %>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<% content_for :before_main do %>
2+
<%= render AppBacklinkComponent.new(
3+
href: @campaign.active ? campaign_edit_path(@campaign, :confirm) : previous_wizard_path,
4+
name: @campaign.active ? "edit programme" : "#{@previous_step} page of programme creation",
5+
) %>
6+
<% end %>
7+
8+
<% title = "Which vaccine(s) does this programme administer?" %>
9+
10+
<% content_for :page_title, title %>
11+
12+
<%= form_with model: @campaign, url: wizard_path, method: :put do |f| %>
13+
<%= f.govuk_error_summary %>
14+
15+
<%= f.govuk_collection_check_boxes :vaccine_ids, Vaccine.where(type: @campaign.type), :id, :brand, legend: { text: title, tag: "h1", size: "l" } %>
16+
17+
<%= f.govuk_submit %>
18+
<% end %>

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ en:
204204
blank: Choose a programme type
205205
inclusion: Choose a programme type
206206
vaccines:
207+
blank: Choose the vaccines this programme administers
207208
match_type: Vaccines must be suitable for the programme type
208209
consent:
209210
attributes:

spec/features/create_and_edit_campaigns_spec.rb

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
before { given_i_am_signed_in }
55

66
scenario "User creates a Flu campaign" do
7-
given_active_and_discontinued_flu_vaccines_exist
7+
given_active_flu_vaccines_exist
8+
and_discontinued_flu_vaccines_exist
89

910
when_i_go_to_the_campaigns_page
1011
and_i_click_on_the_new_campaign_button
@@ -28,6 +29,7 @@
2829

2930
scenario "User edits a Flu campaign" do
3031
given_a_flu_campaign_exists
32+
and_discontinued_flu_vaccines_exist
3133

3234
when_i_go_to_the_campaigns_page
3335
and_i_click_on_the_flu_campaign
@@ -44,13 +46,19 @@
4446
and_i_click_continue
4547
then_i_should_see_the_edit_confirm_page
4648

49+
when_i_click_on_change_vaccines
50+
and_i_select_the_flu_vaccines
51+
and_i_click_continue
52+
then_i_should_see_the_edit_confirm_page
53+
4754
when_i_confirm_the_campaign
4855
then_i_should_see_the_campaign_page
4956
and_i_should_see_the_flu_campaign
5057
end
5158

5259
scenario "User creates an HPV campaign" do
53-
given_active_and_discontinued_hpv_vaccines_exist
60+
given_active_hpv_vaccines_exist
61+
and_discontinued_hpv_vaccines_exist
5462

5563
when_i_go_to_the_campaigns_page
5664
and_i_click_on_the_new_campaign_button
@@ -74,6 +82,7 @@
7482

7583
scenario "User edits an HPV campaign" do
7684
given_an_hpv_campaign_exists
85+
and_discontinued_hpv_vaccines_exist
7786

7887
when_i_go_to_the_campaigns_page
7988
and_i_click_on_the_hpv_campaign
@@ -90,6 +99,11 @@
9099
and_i_click_continue
91100
then_i_should_see_the_edit_confirm_page
92101

102+
when_i_click_on_change_vaccines
103+
and_i_select_the_hpv_vaccines
104+
and_i_click_continue
105+
then_i_should_see_the_edit_confirm_page
106+
93107
when_i_confirm_the_campaign
94108
then_i_should_see_the_campaign_page
95109
and_i_should_see_the_hpv_campaign
@@ -100,13 +114,21 @@ def given_i_am_signed_in
100114
sign_in @team.users.first
101115
end
102116

103-
def given_active_and_discontinued_flu_vaccines_exist
117+
def given_active_flu_vaccines_exist
104118
create(:vaccine, :adjuvanted_quadrivalent)
119+
end
120+
121+
def and_discontinued_flu_vaccines_exist
105122
create(:vaccine, :fluad_tetra)
123+
create(:vaccine, :flucelvax_tetra)
106124
end
107125

108-
def given_active_and_discontinued_hpv_vaccines_exist
126+
def given_active_hpv_vaccines_exist
109127
create(:vaccine, :gardasil_9)
128+
end
129+
130+
def and_discontinued_hpv_vaccines_exist
131+
create(:vaccine, :cervarix)
110132
create(:vaccine, :gardasil)
111133
end
112134

@@ -241,4 +263,18 @@ def when_i_click_on_change_name
241263
def when_i_click_on_change_start_date
242264
within(".nhsuk-summary-list__row", text: "Start date") { click_on "Change" }
243265
end
266+
267+
def when_i_click_on_change_vaccines
268+
within(".nhsuk-summary-list__row", text: "Vaccines") { click_on "Change" }
269+
end
270+
271+
def and_i_select_the_flu_vaccines
272+
check "Fluad Tetra - aQIV"
273+
check "Flucelvax Tetra - QIVc"
274+
end
275+
276+
def and_i_select_the_hpv_vaccines
277+
check "Cervarix"
278+
check "Gardasil"
279+
end
244280
end

0 commit comments

Comments
 (0)