Skip to content

Commit d0b184a

Browse files
committed
Permit recording a Flu vaccination
This refactors the logic related to determining the common delivery sites and the delivery method when recording a vaccination to allow for Flu vaccinations to be recorded. For now this doens't implement the full logic, specifically it doesn't pick the delivery method according to the consent, but I've left a `TODO` common so we know where to put this logic in the future.
1 parent d18f44d commit d0b184a

File tree

6 files changed

+77
-74
lines changed

6 files changed

+77
-74
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/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: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,6 @@ def available_delivery_sites
7979
vaccines.flat_map(&:available_delivery_sites).uniq
8080
end
8181

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

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/models/programme_spec.rb

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -110,38 +110,8 @@
110110
end
111111
end
112112

113-
describe "#common_delivery_sites" do
114-
subject(:common_delivery_sites) { programme.common_delivery_sites }
115-
116-
context "with a Flu programme" do
117-
let(:programme) { build(:programme, :flu) }
118-
119-
it "raises an error" do
120-
expect { common_delivery_sites }.to raise_error(NotImplementedError)
121-
end
122-
end
123-
124-
context "with an HPV programme" do
125-
let(:programme) { build(:programme, :hpv) }
126-
127-
it { should eq(%w[left_arm_upper_position right_arm_upper_position]) }
128-
end
129-
130-
context "with an MenACWY programme" do
131-
let(:programme) { build(:programme, :menacwy) }
132-
133-
it { should eq(%w[left_arm_upper_position right_arm_upper_position]) }
134-
end
135-
136-
context "with an Td/IPV programme" do
137-
let(:programme) { build(:programme, :td_ipv) }
138-
139-
it { should eq(%w[left_arm_upper_position right_arm_upper_position]) }
140-
end
141-
end
142-
143113
describe "#vaccinated_dose_sequence" do
144-
subject(:vaccinated_dose_sequence) { programme.vaccinated_dose_sequence }
114+
subject { programme.vaccinated_dose_sequence }
145115

146116
context "with a Flu programme" do
147117
let(:programme) { build(:programme, :flu) }

0 commit comments

Comments
 (0)