Skip to content

Commit 281d8f2

Browse files
authored
Merge pull request #3679 from nhsuk/prepare-flu-vaccinations
Allow testing Flu programme
2 parents b61af56 + d0b184a commit 281d8f2

12 files changed

+134
-135
lines changed

app/components/app_vaccinate_form_component.html.erb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,20 @@
4949
</h2>
5050

5151
<%= f.govuk_radio_buttons_fieldset :administered, legend: nil do %>
52-
<%= f.govuk_radio_button :administered, true, label: { text: "Yes" }, link_errors: true do %>
53-
<%= f.govuk_collection_radio_buttons :delivery_site,
54-
common_delivery_sites_options,
55-
:value,
56-
:label,
57-
legend: {
58-
text: "Where will the injection be given?",
59-
size: "s",
60-
} %>
52+
<% if common_delivery_sites_options.length > 1 %>
53+
<%= f.govuk_radio_button :administered, true, label: { text: "Yes" }, link_errors: true do %>
54+
<%= f.govuk_collection_radio_buttons :delivery_site,
55+
common_delivery_sites_options,
56+
:value,
57+
:label,
58+
legend: {
59+
text: "Where will the injection be given?",
60+
size: "s",
61+
} %>
62+
<% end %>
63+
<% else %>
64+
<%= f.govuk_radio_button :administered, true, label: { text: "Yes" }, link_errors: true %>
65+
<%= f.hidden_field :delivery_site, value: common_delivery_sites_options.first.value %>
6166
<% end %>
6267
<%= f.govuk_radio_button :administered, false, label: { text: "No" } %>
6368
<% end %>

app/components/app_vaccinate_form_component.rb

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,37 @@ def url
2727
end
2828

2929
def delivery_method
30-
:intramuscular
30+
# TODO: Check which method has been consented to.
31+
programme.flu? ? :nasal_spray : :intramuscular
3132
end
3233

3334
def dose_sequence
3435
programme.default_dose_sequence
3536
end
3637

38+
COMMON_DELIVERY_SITES = {
39+
intramuscular: %w[left_arm_upper_position right_arm_upper_position],
40+
nasal_spray: %w[nose]
41+
}.freeze
42+
43+
CommonDeliverySite = Struct.new(:value, :label)
44+
3745
def common_delivery_sites_options
38-
options =
39-
programme.common_delivery_sites.map do
40-
OpenStruct.new(
41-
value: it,
42-
label: VaccinationRecord.human_enum_name(:delivery_site, it)
43-
)
46+
@common_delivery_sites_options ||=
47+
begin
48+
options =
49+
COMMON_DELIVERY_SITES
50+
.fetch(delivery_method)
51+
.map do |value|
52+
label = VaccinationRecord.human_enum_name(:delivery_site, value)
53+
CommonDeliverySite.new(value:, label:)
54+
end
55+
56+
if delivery_method == :intramuscular
57+
options << CommonDeliverySite.new(value: "other", label: "Other")
58+
end
59+
60+
options
4461
end
45-
46-
options + [OpenStruct.new(value: "other", label: "Other")]
4762
end
4863
end

app/components/app_vaccination_record_summary_component.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def initialize(
1616

1717
@batch = vaccination_record.batch
1818
@patient = vaccination_record.patient
19+
@programme = vaccination_record.programme
1920
@vaccine = vaccination_record.vaccine
2021
end
2122

@@ -218,10 +219,7 @@ def outcome_value
218219
end
219220

220221
def programme_value
221-
highlight_if(
222-
@vaccination_record.programme.name,
223-
@vaccination_record.programme_id_changed?
224-
)
222+
highlight_if(@programme.name, @vaccination_record.programme_id_changed?)
225223
end
226224

227225
def vaccine_value
@@ -318,7 +316,7 @@ def dose_number_value
318316
end
319317

320318
def dose_number
321-
return nil if @vaccine&.seasonal?
319+
return nil if @programme.seasonal?
322320

323321
dose_sequence = @vaccination_record.dose_sequence
324322

app/controllers/draft_vaccination_records_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def set_batches
199199

200200
method =
201201
if @draft_vaccination_record.delivery_method == "nasal_spray"
202-
"nasal_spray"
202+
"nasal"
203203
else
204204
"injection"
205205
end

app/models/programme.rb

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,16 @@ class Programme < ApplicationRecord
4646
{ flu: "flu", hpv: "hpv", menacwy: "menacwy", td_ipv: "td_ipv" },
4747
validate: true
4848

49-
def to_param
50-
type
51-
end
52-
53-
def doubles?
54-
menacwy? || td_ipv?
55-
end
49+
def to_param = type
5650

5751
def name
5852
human_enum_name(:type)
5953
end
6054

55+
def doubles? = menacwy? || td_ipv?
56+
57+
def seasonal? = flu?
58+
6159
YEAR_GROUPS_BY_TYPE = {
6260
"flu" => (0..11).to_a,
6361
"hpv" => (8..11).to_a,
@@ -81,15 +79,6 @@ def available_delivery_sites
8179
vaccines.flat_map(&:available_delivery_sites).uniq
8280
end
8381

84-
def common_delivery_sites
85-
if hpv? || menacwy? || td_ipv?
86-
%w[left_arm_upper_position right_arm_upper_position]
87-
else
88-
raise NotImplementedError,
89-
"Common delivery sites not implemented for #{type} vaccines."
90-
end
91-
end
92-
9382
DOSE_SEQUENCES = {
9483
"flu" => 1,
9584
"hpv" => 1,

app/models/vaccine.rb

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,19 @@ class Vaccine < ApplicationRecord
5151

5252
delegate :first_health_question, to: :health_questions
5353

54-
def active?
55-
!discontinued
56-
end
57-
58-
def contains_gelatine?
59-
programme.flu? && nasal?
60-
end
54+
def active? = !discontinued
6155

62-
def seasonal?
63-
programme.flu?
64-
end
56+
def contains_gelatine? = programme.flu? && nasal?
6557

6658
AVAILABLE_DELIVERY_SITES = {
67-
"injection" =>
68-
VaccinationRecord.delivery_sites.keys -
69-
%w[left_buttock right_buttock nose],
59+
"injection" => %w[
60+
left_arm_upper_position
61+
left_arm_lower_position
62+
right_arm_upper_position
63+
right_arm_lower_position
64+
left_thigh
65+
right_thigh
66+
],
7067
"nasal" => %w[nose]
7168
}.freeze
7269

db/seeds.rb

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@ def create_gp_practices
1919
FactoryBot.create_list(:gp_practice, 30)
2020
end
2121

22-
def create_organisation(ods_code:, programme_types: %w[hpv menacwy td_ipv])
22+
def create_organisation(ods_code:)
2323
organisation =
2424
Organisation.find_by(ods_code:) ||
2525
FactoryBot.create(:organisation, :with_generic_clinic, ods_code:)
2626

27-
programme_types
28-
.map { Programme.find_by!(type: it) }
29-
.each do |programme|
30-
FactoryBot.create(:organisation_programme, organisation:, programme:)
31-
end
27+
Programme.all.find_each do |programme|
28+
FactoryBot.create(:organisation_programme, organisation:, programme:)
29+
end
3230

3331
organisation
3432
end
@@ -85,14 +83,10 @@ def create_session(
8583
)
8684
year_groups ||= programmes.flat_map(&:year_groups).uniq
8785

88-
programmes.each do |programme|
89-
FactoryBot.create_list(
90-
:batch,
91-
3,
92-
organisation:,
93-
vaccine: programme.vaccines.active.first
94-
)
95-
end
86+
Vaccine
87+
.active
88+
.where(programme: programmes)
89+
.find_each { |vaccine| FactoryBot.create(:batch, organisation:, vaccine:) }
9690

9791
location = FactoryBot.create(:school, organisation:, year_groups:)
9892
date = completed ? 1.week.ago.to_date : Date.current
@@ -232,10 +226,15 @@ def create_school_moves(organisation)
232226
end
233227

234228
def create_organisation_sessions(user, organisation)
229+
flu = Programme.find_by!(type: "flu")
235230
hpv = Programme.find_by!(type: "hpv")
236231
menacwy = Programme.find_by!(type: "menacwy")
237232
td_ipv = Programme.find_by!(type: "td_ipv")
238233

234+
# Flu-only sessions
235+
create_session(user, organisation, programmes: [flu], completed: false)
236+
create_session(user, organisation, programmes: [hpv], completed: true)
237+
239238
# HPV-only sessions
240239
create_session(user, organisation, programmes: [hpv], completed: false)
241240
create_session(user, organisation, programmes: [hpv], completed: true)

spec/components/app_vaccinate_form_component_spec.rb

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# frozen_string_literal: true
22

33
describe AppVaccinateFormComponent do
4-
subject { render_inline(component) }
5-
6-
let(:heading) { "A Heading" }
7-
let(:body) { "A Body" }
8-
let(:programmes) { [create(:programme, :hpv)] }
4+
let(:programme) { create(:programme) }
5+
let(:programmes) { [programme] }
96
let(:session) { create(:session, :today, programmes:) }
107
let(:patient) do
118
create(
@@ -19,21 +16,12 @@
1916
create(:patient_session, :in_attendance, programmes:, patient:, session:)
2017
end
2118

22-
let(:vaccinate_form) do
23-
VaccinateForm.new(patient_session:, programme: programmes.first)
24-
end
19+
let(:vaccinate_form) { VaccinateForm.new(patient_session:, programme:) }
2520

2621
let(:component) { described_class.new(vaccinate_form) }
2722

2823
before { patient_session.strict_loading!(false) }
2924

30-
it { should have_css(".nhsuk-card") }
31-
32-
it { should have_heading("Is Hari ready for their HPV vaccination?") }
33-
34-
it { should have_field("Yes") }
35-
it { should have_field("No") }
36-
3725
describe "#render?" do
3826
subject(:render) { component.render? }
3927

@@ -53,4 +41,38 @@
5341
it { should be(false) }
5442
end
5543
end
44+
45+
describe "rendered content" do
46+
subject { render_inline(component) }
47+
48+
it { should have_css(".nhsuk-card") }
49+
50+
context "with a Flu programme" do
51+
let(:programme) { create(:programme, :flu) }
52+
53+
it { should have_heading("Is Hari ready for their Flu vaccination?") }
54+
55+
it { should have_field("Yes") }
56+
it { should have_field("No") }
57+
58+
it { should_not have_field("Left arm (upper position)") }
59+
it { should_not have_field("Right arm (upper position)") }
60+
it { should_not have_field("Nose") }
61+
it { should_not have_field("Other") }
62+
end
63+
64+
context "with an HPV programme" do
65+
let(:programme) { create(:programme, :hpv) }
66+
67+
it { should have_heading("Is Hari ready for their HPV vaccination?") }
68+
69+
it { should have_field("Yes") }
70+
it { should have_field("No") }
71+
72+
it { should have_field("Left arm (upper position)") }
73+
it { should have_field("Right arm (upper position)") }
74+
it { should_not have_field("Nose") }
75+
it { should have_field("Other") }
76+
end
77+
end
5678
end

spec/factories/programmes.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,7 @@
3939
vaccines do
4040
[
4141
association(:vaccine, :adjuvanted_quadrivalent, programme: instance),
42-
association(:vaccine, :cell_quadrivalent, programme: instance),
43-
association(:vaccine, :fluenz_tetra, programme: instance),
44-
association(:vaccine, :quadrivalent_influenza, programme: instance),
45-
association(
46-
:vaccine,
47-
:quadrivalent_influvac_tetra,
48-
programme: instance
49-
),
50-
association(:vaccine, :supemtek, programme: instance)
42+
association(:vaccine, :fluenz_tetra, programme: instance)
5143
]
5244
end
5345
end

spec/factories/vaccination_records.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272

7373
vaccine do
7474
if session
75-
programme.vaccines.active.first || association(:vaccine, programme:)
75+
programme.vaccines.active.sample || association(:vaccine, programme:)
7676
end
7777
end
7878

0 commit comments

Comments
 (0)