Skip to content

Commit 6c985a6

Browse files
authored
Merge pull request #3936 from nhsuk/todays-batch-vaccine-method
Allow default daily batch per vaccine method
2 parents 9436104 + 986b8fd commit 6c985a6

17 files changed

Lines changed: 189 additions & 87 deletions

app/components/app_consent_confirmation_component.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,11 @@ def vaccinations_text(consent_form_programmes)
6666
.map do |consent_form_programme|
6767
programme = consent_form_programme.programme
6868

69-
if programme.flu?
70-
if consent_form_programme.vaccine_method_nasal?
71-
"nasal flu"
72-
elsif consent_form_programme.vaccine_method_injection?
73-
"flu injection"
74-
else
75-
programme.name_in_sentence
76-
end
69+
if programme.has_multiple_vaccine_methods?
70+
vaccine_method = consent_form_programme.vaccine_methods.first
71+
method_prefix =
72+
Vaccine.human_enum_name(:method_prefix, vaccine_method)
73+
"#{method_prefix} #{programme.name_in_sentence}".lstrip
7774
else
7875
programme.name_in_sentence
7976
end

app/components/app_patient_session_record_component.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,11 @@ def default_vaccinate_form
3939

4040
def heading
4141
vaccination =
42-
if programme.flu?
43-
if PatientSession
44-
.where(patient_id: patient.id)
45-
.has_vaccine_method(:nasal, programme:)
46-
.exists?
47-
"vaccination with nasal spray"
48-
else
49-
"vaccination with injection"
50-
end
42+
if programme.has_multiple_vaccine_methods?
43+
vaccine_method = patient.approved_vaccine_methods(programme:).first
44+
method_string =
45+
Vaccine.human_enum_name(:method, vaccine_method).downcase
46+
"vaccination with #{method_string}"
5147
else
5248
"vaccination"
5349
end

app/components/app_vaccinate_form_component.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def url
2020

2121
def delivery_method
2222
if patient.approved_vaccine_methods(programme:).include?("nasal")
23-
:nasal_spray
23+
"nasal_spray"
2424
else
25-
:intramuscular
25+
"intramuscular"
2626
end
2727
end
2828

@@ -31,8 +31,8 @@ def dose_sequence
3131
end
3232

3333
COMMON_DELIVERY_SITES = {
34-
intramuscular: %w[left_arm_upper_position right_arm_upper_position],
35-
nasal_spray: %w[nose]
34+
"intramuscular" => %w[left_arm_upper_position right_arm_upper_position],
35+
"nasal_spray" => %w[nose]
3636
}.freeze
3737

3838
CommonDeliverySite = Struct.new(:value, :label)
@@ -48,7 +48,7 @@ def common_delivery_sites_options
4848
CommonDeliverySite.new(value:, label:)
4949
end
5050

51-
if delivery_method == :intramuscular
51+
if delivery_method.in?(Vaccine::INJECTION_DELIVERY_METHODS)
5252
options << CommonDeliverySite.new(value: "other", label: "Other")
5353
end
5454

@@ -58,8 +58,10 @@ def common_delivery_sites_options
5858

5959
def vaccination_name
6060
vaccination =
61-
if programme.flu?
62-
delivery_method == :nasal_spray ? "nasal spray" : "injection"
61+
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
6365
else
6466
"vaccination"
6567
end
@@ -71,5 +73,6 @@ def ask_not_taking_medication? = programme.doubles? || programme.flu?
7173

7274
def ask_not_pregnant? = programme.td_ipv?
7375

74-
def ask_asthma_flare_up? = programme.flu? && delivery_method == :nasal_spray
76+
def ask_asthma_flare_up? =
77+
delivery_method.in?(Vaccine::NASAL_DELIVERY_METHODS)
7578
end

app/controllers/concerns/todays_batch_concern.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,30 @@
33
module TodaysBatchConcern
44
extend ActiveSupport::Concern
55

6-
def todays_batch_id(programme:)
7-
if (todays_batch = session.dig(:todays_batch, programme.type))
6+
def todays_batch_id(programme:, vaccine_method:)
7+
if (
8+
todays_batch =
9+
session.dig(:todays_batch, programme.type, vaccine_method)
10+
)
811
if todays_batch[:date] == Date.current.iso8601
912
todays_batch[:id].to_i
1013
else
11-
unset_todays_batch(programme:)
14+
unset_todays_batch(programme:, vaccine_method:)
1215
nil
1316
end
1417
end
1518
end
1619

1720
def todays_batch=(batch)
1821
session[:todays_batch] ||= {}
19-
session[:todays_batch][batch.programme.type] = {
22+
session[:todays_batch][batch.programme.type] ||= {}
23+
session[:todays_batch][batch.programme.type][batch.vaccine.method] = {
2024
id: batch.id,
2125
date: Date.current.iso8601
2226
}
2327
end
2428

25-
def unset_todays_batch(programme:)
26-
session[:todays_batch]&.delete(programme.type)
29+
def unset_todays_batch(programme:, vaccine_method:)
30+
session.dig(:todays_batch, programme.type)&.delete(vaccine_method)
2731
end
2832
end

app/controllers/patient_sessions/vaccinations_controller.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,20 @@ def vaccinate_form_params
6868
end
6969

7070
def set_todays_batch
71+
vaccine_method =
72+
Vaccine.delivery_method_to_vaccine_method(
73+
vaccinate_form_params[:delivery_method]
74+
)
75+
return if vaccine_method.nil?
76+
77+
id = todays_batch_id(programme: @programme, vaccine_method:)
78+
return if id.nil?
79+
7180
@todays_batch =
7281
policy_scope(Batch)
7382
.where(vaccine: @session.vaccines)
7483
.not_archived
7584
.not_expired
76-
.find_by(id: todays_batch_id(programme: @programme))
85+
.find_by(id:)
7786
end
7887
end

app/controllers/sessions/record_controller.rb

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Sessions::RecordController < ApplicationController
1212

1313
before_action :set_todays_batches, only: :show
1414
before_action :set_programme, except: :show
15+
before_action :set_vaccine_method, except: :show
1516
before_action :set_batches, except: :show
1617

1718
def show
@@ -41,9 +42,8 @@ def show
4142
end
4243

4344
def edit_batch
44-
@todays_batch =
45-
authorize @batches.find_by(id: todays_batch_id(programme: @programme)),
46-
:edit?
45+
id = todays_batch_id(programme: @programme, vaccine_method: @vaccine_method)
46+
@todays_batch = authorize @batches.find(id), :edit?
4747

4848
render :batch
4949
end
@@ -80,11 +80,16 @@ def set_session
8080
def set_todays_batches
8181
all_batches =
8282
@session.programmes.index_with do |programme|
83-
policy_scope(Batch)
84-
.where(vaccine: @session.vaccines)
85-
.not_archived
86-
.not_expired
87-
.find_by(id: todays_batch_id(programme:))
83+
programme.vaccine_methods.filter_map do |vaccine_method|
84+
id = todays_batch_id(programme:, vaccine_method:)
85+
next if id.nil?
86+
87+
policy_scope(Batch)
88+
.where(vaccine: @session.vaccines)
89+
.not_archived
90+
.not_expired
91+
.find_by(id:)
92+
end
8893
end
8994

9095
@todays_batches = all_batches.compact
@@ -94,10 +99,17 @@ def set_programme
9499
@programme = policy_scope(Programme).find_by!(type: params[:programme_type])
95100
end
96101

102+
def set_vaccine_method
103+
@vaccine_method = params[:vaccine_method]
104+
end
105+
97106
def set_batches
107+
vaccines =
108+
@session.vaccines.where(programme: @programme, method: @vaccine_method)
109+
98110
@batches =
99111
policy_scope(Batch)
100-
.where(vaccine: @session.vaccines.where(programme: @programme))
112+
.where(vaccine: vaccines)
101113
.not_archived
102114
.not_expired
103115
.order_by_name_and_expiration

app/controllers/vaccines_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ def index
1515
.order_by_name_and_expiration
1616
.group_by(&:vaccine_id)
1717

18-
@todays_batch_id_by_programme =
18+
@todays_batch_id_by_programme_and_vaccine_methods =
1919
policy_scope(Programme).index_with do |programme|
20-
todays_batch_id(programme:)
20+
programme.vaccine_methods.index_with do |vaccine_method|
21+
todays_batch_id(programme:, vaccine_method:)
22+
end
2123
end
2224
end
2325

app/lib/govuk_notify_personalisation.rb

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -396,25 +396,21 @@ def programme_names
396396
def programme_names_and_methods
397397
@programme_names_and_methods ||=
398398
programmes.map do |programme|
399-
next programme.name unless programme.flu?
400-
401-
if vaccination_record
402-
if vaccination_record.delivery_method_nasal_spray?
403-
"nasal spray flu"
404-
else
405-
"injected flu"
406-
end
407-
elsif patient &&
408-
(
409-
vaccine_methods = patient.approved_vaccine_methods(programme:)
410-
).present?
411-
if vaccine_methods.first == "nasal"
412-
"nasal spray flu"
413-
else
414-
"injected flu"
415-
end
399+
if programme.has_multiple_vaccine_methods?
400+
vaccine_method =
401+
if vaccination_record
402+
Vaccine.delivery_method_to_vaccine_method(
403+
vaccination_record.delivery_method
404+
)
405+
elsif patient
406+
patient.approved_vaccine_methods(programme:).first
407+
end
408+
409+
method_prefix =
410+
Vaccine.human_enum_name(:method_prefix, vaccine_method)
411+
"#{method_prefix} #{programme.name_in_sentence}".lstrip
416412
else
417-
"flu"
413+
programme.name_in_sentence
418414
end
419415
end
420416
end

app/views/sessions/record/batch.html.erb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
<%= render AppBacklinkComponent.new(session_record_path(@session), name: "record") %>
33
<% end %>
44

5-
<% page_title = "Select a default batch for this session" %>
5+
<% programme_name_and_method = if @programme.has_multiple_vaccine_methods?
6+
"#{@programme.name_in_sentence} #{Vaccine.human_enum_name(:vaccine_method, @vaccine_method)}.downcase"
7+
else
8+
"#{@programme.name_in_sentence}"
9+
end %>
10+
11+
<% page_title = "Select a default #{programme_name_and_method} batch for this session" %>
612
<% content_for :page_title, page_title %>
713

814
<%= form_with model: @todays_batch, url: batch_session_record_path(@session, @programme), method: :post do |f| %>
@@ -14,11 +20,16 @@
1420
<% @batches.each_with_index do |batch, index| %>
1521
<% label = proc do %>
1622
<span class="app-u-monospace"><%= batch.name %></span>
23+
(<%= batch.vaccine.brand %>)
24+
<% end %>
25+
26+
<% hint = proc do %>
1727
<% if (expiry = batch.expiry) %>
18-
(expires <%= expiry.to_fs(:long) %>)
28+
Expires <%= expiry.to_fs(:long) %>
1929
<% end %>
2030
<% end %>
21-
<%= f.govuk_radio_button :id, batch.id, label:, link_errors: index.zero? %>
31+
32+
<%= f.govuk_radio_button :id, batch.id, label:, hint:, link_errors: index.zero? %>
2233
<% end %>
2334
<% end %>
2435

app/views/sessions/record/show.html.erb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,21 @@
1717
</h2>
1818

1919
<ul class="nhsuk-list nhsuk-list--bullet">
20-
<% @todays_batches.each do |programme, batch| %>
21-
<li>
22-
<%= batch.vaccine.brand %> (<%= programme.name %>): <span class="app-u-monospace"><%= batch.name %></span>
23-
<a class="nhsuk-link nhsuk-u-margin-left-2" href="<%= batch_session_record_path(@session, programme) %>">Change default batch<span class="nhsuk-u-visually-hidden"> for <%= batch.vaccine.brand %></span></a>
24-
</li>
20+
<% @todays_batches.each do |programme, batches| %>
21+
<% batches.each do |batch| %>
22+
<% programme_name = if programme.has_multiple_vaccine_methods?
23+
"#{programme.name_in_sentence} #{batch.vaccine.human_enum_name(:method).downcase}"
24+
else
25+
programme.name_in_sentence
26+
end %>
27+
28+
<li>
29+
<%= batch.vaccine.brand %> (<%= programme_name %>): <span class="app-u-monospace"><%= batch.name %></span>
30+
<a class="nhsuk-link nhsuk-u-margin-left-2" href="<%= batch_session_record_path(@session, programme, batch.vaccine.method) %>">
31+
Change default batch<span class="nhsuk-u-visually-hidden"> for <%= batch.vaccine.brand %></span>
32+
</a>
33+
</li>
34+
<% end %>
2535
<% end %>
2636
</ul>
2737
<% end %>

0 commit comments

Comments
 (0)