Skip to content

Commit c992b53

Browse files
authored
Merge pull request #3958 from nhsuk/record-vaccination-multiple-methods
2 parents a2f82e7 + b955001 commit c992b53

11 files changed

Lines changed: 157 additions & 84 deletions

app/components/app_vaccinate_form_component.html.erb

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,43 @@
6565

6666
<% hint = "Pre-screening checks must be completed for vaccination to go ahead" %>
6767

68-
<%= f.govuk_radio_buttons_fieldset :administered, legend: nil do %>
69-
<% if common_delivery_sites_options.length > 1 %>
70-
<%= f.govuk_radio_button :administered, true, label: { text: "Yes" }, hint: { text: hint }, link_errors: true do %>
71-
<%= f.govuk_collection_radio_buttons :delivery_site,
72-
common_delivery_sites_options,
73-
:value,
74-
:label,
75-
legend: {
76-
text: "Where will the injection be given?",
77-
size: "s",
78-
} %>
68+
<%= f.govuk_radio_buttons_fieldset :vaccine_method, legend: nil do %>
69+
<% vaccine_methods.each_with_index do |vaccine_method, index| %>
70+
<% if index == 1 %>
71+
<%= f.govuk_radio_divider %>
72+
<% end %>
73+
74+
<% label = if index.zero?
75+
"Yes"
76+
else
77+
"No — but they can have the #{Vaccine.human_enum_name(:method_prefix, vaccine_method)} #{programme.name_in_sentence} instead"
78+
end %>
79+
80+
<% options = common_delivery_site_options(vaccine_method) %>
81+
82+
<% if options.length > 1 %>
83+
<%= f.govuk_radio_button :vaccine_method, vaccine_method, label: { text: label }, hint: { text: hint }, link_errors: index.zero? do %>
84+
<%= f.govuk_collection_radio_buttons :delivery_site,
85+
options,
86+
:value,
87+
:label,
88+
legend: {
89+
text: "Where will the #{Vaccine.human_enum_name(:method, vaccine_method).downcase} be given?",
90+
size: "s",
91+
} %>
92+
<% end %>
93+
<% else %>
94+
<%= f.govuk_radio_button :vaccine_method, vaccine_method, label: { text: label }, hint: { text: hint }, link_errors: index.zero? do %>
95+
<%= f.hidden_field :delivery_site, value: options.first.value %>
96+
<% end %>
97+
<% end %>
98+
99+
<% if index.zero? %>
100+
<%= f.govuk_radio_button :vaccine_method, "none", label: { text: "No" } %>
79101
<% end %>
80-
<% else %>
81-
<%= f.govuk_radio_button :administered, true, label: { text: "Yes" }, hint: { text: hint }, link_errors: true %>
82-
<%= f.hidden_field :delivery_site, value: common_delivery_sites_options.first.value %>
83102
<% end %>
84-
<%= f.govuk_radio_button :administered, false, label: { text: "No" } %>
85103
<% end %>
86104

87-
<%= f.hidden_field :delivery_method, value: delivery_method %>
88105
<%= f.hidden_field :dose_sequence, value: dose_sequence %>
89106
<%= f.hidden_field :programme_id, value: programme.id %>
90107

app/components/app_vaccinate_form_component.rb

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,50 +18,41 @@ def url
1818
session_patient_programme_vaccinations_path(session, patient, programme)
1919
end
2020

21-
def delivery_method
22-
if patient.approved_vaccine_methods(programme:).include?("nasal")
23-
"nasal_spray"
24-
else
25-
"intramuscular"
26-
end
21+
def vaccine_methods
22+
patient.approved_vaccine_methods(programme:)
2723
end
2824

2925
def dose_sequence
3026
programme.default_dose_sequence
3127
end
3228

3329
COMMON_DELIVERY_SITES = {
34-
"intramuscular" => %w[left_arm_upper_position right_arm_upper_position],
35-
"nasal_spray" => %w[nose]
30+
"injection" => %w[left_arm_upper_position right_arm_upper_position],
31+
"nasal" => %w[nose]
3632
}.freeze
3733

3834
CommonDeliverySite = Struct.new(:value, :label)
3935

40-
def common_delivery_sites_options
41-
@common_delivery_sites_options ||=
42-
begin
43-
options =
44-
COMMON_DELIVERY_SITES
45-
.fetch(delivery_method)
46-
.map do |value|
47-
label = VaccinationRecord.human_enum_name(:delivery_site, value)
48-
CommonDeliverySite.new(value:, label:)
49-
end
50-
51-
if delivery_method.in?(Vaccine::INJECTION_DELIVERY_METHODS)
52-
options << CommonDeliverySite.new(value: "other", label: "Other")
36+
def common_delivery_site_options(vaccine_method)
37+
options =
38+
COMMON_DELIVERY_SITES
39+
.fetch(vaccine_method)
40+
.map do |value|
41+
label = VaccinationRecord.human_enum_name(:delivery_site, value)
42+
CommonDeliverySite.new(value:, label:)
5343
end
5444

55-
options
56-
end
45+
if vaccine_method == "injection"
46+
options << CommonDeliverySite.new(value: "other", label: "Other")
47+
end
48+
49+
options
5750
end
5851

5952
def vaccination_name
6053
vaccination =
6154
if programme.has_multiple_vaccine_methods?
62-
vaccine_method =
63-
Vaccine.delivery_method_to_vaccine_method(delivery_method)
64-
Vaccine.human_enum_name(:method, vaccine_method).downcase
55+
Vaccine.human_enum_name(:method, vaccine_methods.first).downcase
6556
else
6657
"vaccination"
6758
end
@@ -73,6 +64,5 @@ def ask_not_taking_medication? = programme.doubles? || programme.flu?
7364

7465
def ask_not_pregnant? = programme.td_ipv?
7566

76-
def ask_asthma_flare_up? =
77-
delivery_method.in?(Vaccine::NASAL_DELIVERY_METHODS)
67+
def ask_asthma_flare_up? = vaccine_methods.include?("nasal")
7868
end

app/controllers/patient_sessions/vaccinations_controller.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ def create
5454
def vaccinate_form_params
5555
params.expect(
5656
vaccinate_form: %i[
57-
administered
58-
delivery_method
5957
delivery_site
6058
dose_sequence
6159
identity_check_confirmed_by_other_name
@@ -64,15 +62,13 @@ def vaccinate_form_params
6462
pre_screening_confirmed
6563
pre_screening_notes
6664
vaccine_id
65+
vaccine_method
6766
]
6867
)
6968
end
7069

7170
def set_todays_batch
72-
vaccine_method =
73-
Vaccine.delivery_method_to_vaccine_method(
74-
vaccinate_form_params[:delivery_method]
75-
)
71+
vaccine_method = vaccinate_form_params[:vaccine_method]
7672
return if vaccine_method.nil?
7773

7874
id = todays_batch_id(programme: @programme, vaccine_method:)

app/forms/vaccinate_form.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ class VaccinateForm
1313
attribute :pre_screening_confirmed, :boolean
1414
attribute :pre_screening_notes, :string
1515

16-
attribute :administered, :boolean
17-
attribute :delivery_method, :string
16+
attribute :vaccine_method, :string
1817
attribute :delivery_site, :string
1918
attribute :dose_sequence, :integer
2019
attribute :programme_id, :integer
@@ -32,12 +31,11 @@ class VaccinateForm
3231
maximum: 300
3332
}
3433

35-
validates :administered, inclusion: [true, false]
34+
validates :vaccine_method, inclusion: { in: :vaccine_method_options }
3635
validates :pre_screening_notes, length: { maximum: 1000 }
3736

38-
with_options if: :administered do
37+
with_options if: :administered? do
3938
validates :pre_screening_confirmed, presence: true
40-
validates :delivery_method, presence: true
4139
validates :delivery_site, presence: true
4240
end
4341

@@ -48,7 +46,7 @@ def save(draft_vaccination_record:)
4846

4947
draft_vaccination_record.reset!
5048

51-
if administered
49+
if administered?
5250
draft_vaccination_record.outcome = "administered"
5351

5452
if delivery_site != "other"
@@ -80,6 +78,18 @@ def save(draft_vaccination_record:)
8078

8179
delegate :organisation, to: :patient_session
8280

81+
def administered? = vaccine_method != "none"
82+
83+
def vaccine_method_options
84+
programme.vaccine_methods + ["none"]
85+
end
86+
87+
def delivery_method
88+
if administered?
89+
Vaccine::AVAILABLE_DELIVERY_METHODS.fetch(vaccine_method).first
90+
end
91+
end
92+
8393
def pre_screening
8494
@pre_screening ||=
8595
patient_session.pre_screenings.build(

app/models/draft_vaccination_record.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,12 @@ def reset_unused_fields
296296
end
297297
end
298298

299-
def can_be_half_dose?
300-
delivery_method.in?(Vaccine::NASAL_DELIVERY_METHODS)
299+
def vaccine_method
300+
Vaccine.delivery_method_to_vaccine_method(delivery_method)
301301
end
302302

303+
def can_be_half_dose? = vaccine_method == "nasal"
304+
303305
def can_change_outcome?
304306
outcome != "already_had" || editing? || session.nil? || session.today?
305307
end
@@ -312,14 +314,14 @@ def delivery_site_matches_delivery_method
312314
return
313315
end
314316

315-
case delivery_method
316-
when *Vaccine::NASAL_DELIVERY_METHODS
317-
if delivery_site != "nose"
318-
errors.add(:delivery_site, :nasal_spray_must_be_nose)
319-
end
320-
when *Vaccine::INJECTION_DELIVERY_METHODS
321-
if delivery_site == "nose"
317+
allowed_delivery_sites =
318+
Vaccine::AVAILABLE_DELIVERY_SITES.fetch(vaccine_method)
319+
320+
unless delivery_site.in?(allowed_delivery_sites)
321+
if vaccine_method == "injection"
322322
errors.add(:delivery_site, :injection_cannot_be_nose)
323+
else
324+
errors.add(:delivery_site, :nasal_spray_must_be_nose)
323325
end
324326
end
325327

app/models/patient.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ def consent_given_and_safe_to_vaccinate?(programme:, vaccine_method: nil)
333333
return false unless consent_status(programme:).given?
334334

335335
unless triage_status(programme:).safe_to_vaccinate? ||
336-
triage_status(programme:).delay_vaccination? ||
337336
triage_status(programme:).not_required?
338337
return false
339338
end

app/models/vaccine.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,9 @@ def available_delivery_sites
7777
AVAILABLE_DELIVERY_SITES.fetch(method)
7878
end
7979

80-
NASAL_DELIVERY_METHODS = %w[nasal_spray].freeze
81-
INJECTION_DELIVERY_METHODS = %w[intramuscular subcutaneous].freeze
82-
8380
AVAILABLE_DELIVERY_METHODS = {
84-
"nasal" => NASAL_DELIVERY_METHODS,
85-
"injection" => INJECTION_DELIVERY_METHODS
81+
"nasal" => %w[nasal_spray].freeze,
82+
"injection" => %w[intramuscular subcutaneous].freeze
8683
}.freeze
8784

8885
def available_delivery_methods

config/locales/en.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ en:
121121
inclusion: Choose a status
122122
vaccinate_form:
123123
attributes:
124-
administered:
125-
inclusion: Choose if they are ready to vaccinate
126124
delivery_site:
127125
blank: Choose where the injection will be given
128126
identity_check_confirmed_by_other_name:
@@ -137,6 +135,8 @@ en:
137135
blank: Confirm you’ve checked the pre-screening statements are true
138136
pre_screening_notes:
139137
too_long: Enter notes that are less than %{count} characters long
138+
vaccine_method:
139+
inclusion: Choose if they are ready to vaccinate
140140
vaccination_report:
141141
attributes:
142142
file_format:

0 commit comments

Comments
 (0)