Skip to content

Commit 1460230

Browse files
committed
Merge pull request #4393 from nhsuk/healthcare-assistant-nasal-flu-pgd
Allow healthcare assistants to administer nasal spray via PGD supply
2 parents 16c539a + d7f5e98 commit 1460230

36 files changed

+488
-61
lines changed

app/components/app_patient_session_record_component.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
class AppPatientSessionRecordComponent < ViewComponent::Base
44
erb_template <<-ERB
5-
<h3 class="nhsuk-heading-m"><%= heading %></h3>
6-
7-
<% if helpers.policy(VaccinationRecord).new? %>
5+
<% if helpers.policy(vaccination_record).new? %>
6+
<h3 class="nhsuk-heading-m"><%= heading %></h3>
87
<%= render AppVaccinateFormComponent.new(vaccinate_form) %>
98
<% end %>
109
ERB
1110

12-
def initialize(patient_session, programme:, vaccinate_form: nil)
11+
def initialize(patient_session, programme:, current_user:, vaccinate_form:)
1312
super
1413

1514
@patient_session = patient_session
1615
@programme = programme
16+
@current_user = current_user
1717
@vaccinate_form = vaccinate_form || default_vaccinate_form
1818
end
1919

@@ -28,15 +28,24 @@ def render?
2828

2929
private
3030

31-
attr_reader :patient_session, :programme, :vaccinate_form
31+
attr_reader :patient_session, :current_user, :programme, :vaccinate_form
3232

3333
delegate :patient, :session, to: :patient_session
3434
delegate :academic_year, to: :session
3535

36+
def vaccination_record
37+
VaccinationRecord.new(patient:, session:, programme:)
38+
end
39+
3640
def default_vaccinate_form
3741
pre_screening_confirmed = patient.pre_screenings.today.exists?(programme:)
3842

39-
VaccinateForm.new(patient_session:, programme:, pre_screening_confirmed:)
43+
VaccinateForm.new(
44+
current_user:,
45+
patient_session:,
46+
programme:,
47+
pre_screening_confirmed:
48+
)
4049
end
4150

4251
def heading

app/components/app_vaccinate_form_component.html.erb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<%= form_with(
2-
model: vaccinate_form,
2+
model: form,
33
url:,
44
method: :post,
55
class: "nhsuk-card",
@@ -54,6 +54,20 @@
5454
<% end %>
5555

5656
<%= f.govuk_text_area :pre_screening_notes, label: { text: "Pre-screening notes (optional)" }, rows: 3 %>
57+
58+
<% if form.requires_supplied_by_user_id? %>
59+
<%= f.govuk_select :supplied_by_user_id,
60+
label: { text: "Which nurse identified and pre-screened the child and supplied the vaccine?" },
61+
data: { module: "autocomplete" } do %>
62+
<%= tag.option "", value: "" %>
63+
<% form.supplied_by_users.each do |user| %>
64+
<%= tag.option user.full_name,
65+
value: user.id,
66+
selected: user.id == form.supplied_by_user_id,
67+
data: { hint: user.email } %>
68+
<% end %>
69+
<% end %>
70+
<% end %>
5771
</section>
5872

5973
<hr class="nhsuk-section-break nhsuk-section-break--visible nhsuk-section-break--l">

app/components/app_vaccinate_form_component.rb

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

33
class AppVaccinateFormComponent < ViewComponent::Base
4-
def initialize(vaccinate_form)
4+
def initialize(form)
55
super
66

7-
@vaccinate_form = vaccinate_form
7+
@form = form
88
end
99

1010
private
1111

12-
attr_reader :vaccinate_form
12+
attr_reader :form
1313

14-
delegate :patient_session, :programme, to: :vaccinate_form
14+
delegate :patient_session, :programme, to: :form
1515
delegate :patient, :session, to: :patient_session
1616
delegate :academic_year, to: :session
1717

app/components/app_vaccination_record_summary_component.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,20 @@ def call
201201
end
202202
end
203203

204+
if @vaccination_record.supplied_by.present?
205+
summary_list.with_row do |row|
206+
row.with_key { "Supplier" }
207+
row.with_value { supplier_value }
208+
if (href = @change_links[:supplier])
209+
row.with_action(
210+
text: "Change",
211+
visually_hidden_text: "supplier",
212+
href:
213+
)
214+
end
215+
end
216+
end
217+
204218
if @vaccination_record.performed_by.present?
205219
summary_list.with_row do |row|
206220
row.with_key { "Vaccinator" }
@@ -331,6 +345,13 @@ def time_value
331345
)
332346
end
333347

348+
def supplier_value
349+
highlight_if(
350+
@vaccination_record.supplied_by&.full_name,
351+
@vaccination_record.supplied_by_user_id_changed?
352+
)
353+
end
354+
334355
def vaccinator_value
335356
value =
336357
if @vaccination_record.performed_by == @current_user

app/controllers/draft_vaccination_records_controller.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class DraftVaccinationRecordsController < ApplicationController
1717
before_action :validate_params, only: :update
1818
before_action :set_batches, if: -> { current_step == :batch }
1919
before_action :set_locations, if: -> { current_step == :location }
20+
before_action :set_supplied_by_users, if: -> { current_step == :supplier }
2021
before_action :set_back_link_path
2122

2223
after_action :verify_authorized
@@ -165,7 +166,8 @@ def update_params
165166
],
166167
location: %i[location_name],
167168
notes: %i[notes],
168-
outcome: %i[outcome]
169+
outcome: %i[outcome],
170+
supplier: %i[supplied_by_user_id]
169171
}.fetch(current_step)
170172

171173
params
@@ -193,7 +195,12 @@ def set_programme
193195

194196
def set_vaccination_record
195197
@vaccination_record =
196-
@draft_vaccination_record.vaccination_record || VaccinationRecord.new
198+
@draft_vaccination_record.vaccination_record ||
199+
VaccinationRecord.new(
200+
patient: @patient,
201+
session: @session,
202+
programme: @programme
203+
)
197204
end
198205

199206
def set_steps
@@ -226,6 +233,10 @@ def set_locations
226233
@locations = policy_scope(Location).community_clinic
227234
end
228235

236+
def set_supplied_by_users
237+
@supplied_by_users = current_team.users.show_in_suppliers
238+
end
239+
229240
def set_back_link_path
230241
@back_link_path =
231242
if @draft_vaccination_record.editing?

app/controllers/patient_sessions/programmes_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ def show
88
end
99

1010
def record_already_vaccinated
11-
unless @patient_session.can_record_as_already_vaccinated?(
12-
programme: @programme
13-
)
14-
redirect_to session_patient_path and return
15-
end
11+
authorize VaccinationRecord.new(
12+
patient: @patient,
13+
session: @session,
14+
programme: @programme
15+
)
1616

1717
draft_vaccination_record =
1818
DraftVaccinationRecord.new(request_session: session, current_user:)

app/controllers/patient_sessions/vaccinations_controller.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ class PatientSessions::VaccinationsController < PatientSessions::BaseController
99
after_action :verify_authorized
1010

1111
def create
12-
authorize VaccinationRecord
12+
authorize VaccinationRecord.new(
13+
patient: @patient,
14+
session: @session,
15+
programme: @programme
16+
)
1317

1418
draft_vaccination_record =
1519
DraftVaccinationRecord.new(request_session: session, current_user:)
@@ -26,9 +30,10 @@ def create
2630
if @vaccinate_form.save(draft_vaccination_record:)
2731
steps = draft_vaccination_record.wizard_steps
2832

29-
steps.delete(:notes) # this is on the confirmation page
30-
steps.delete(:identity) # this can only be changed from confirmation page
3133
steps.delete(:dose) # this can only be changed from confirmation page
34+
steps.delete(:identity) # this can only be changed from confirmation page
35+
steps.delete(:notes) # this is on the confirmation page
36+
steps.delete(:supplier) # this can only be changed from confirmation page
3237

3338
steps.delete(:date_and_time)
3439
steps.delete(:outcome) if draft_vaccination_record.administered?
@@ -63,6 +68,7 @@ def vaccinate_form_params
6368
identity_check_confirmed_by_patient
6469
pre_screening_confirmed
6570
pre_screening_notes
71+
supplied_by_user_id
6672
vaccine_id
6773
vaccine_method
6874
]

app/controllers/sessions/record_controller.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ def show
2525
scope = scope.has_registration_status(%w[attending completed])
2626
end
2727

28+
@vaccine_methods = @session.vaccine_methods_for(user: current_user)
29+
30+
if @vaccine_methods != @session.vaccine_methods
31+
scope =
32+
if @vaccine_methods.empty?
33+
scope.none
34+
else
35+
@vaccine_methods.reduce(scope) do |accumulator, vaccine_method|
36+
accumulator.has_vaccine_method(
37+
vaccine_method,
38+
programme: @session.programmes
39+
)
40+
end
41+
end
42+
end
43+
2844
patient_sessions =
2945
@form.apply(scope).consent_given_and_ready_to_vaccinate(
3046
programmes: @form.programmes,

app/forms/vaccinate_form.rb

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

16+
attribute :supplied_by_user_id, :integer
17+
1618
attribute :vaccine_method, :string
1719
attribute :delivery_site, :string
1820
attribute :dose_sequence, :integer
@@ -31,10 +33,16 @@ class VaccinateForm
3133
maximum: 300
3234
}
3335

34-
validates :vaccine_method, inclusion: { in: :vaccine_method_options }
3536
validates :pre_screening_notes, length: { maximum: 1000 }
36-
3737
validates :pre_screening_confirmed, presence: true, if: :administered?
38+
39+
validates :supplied_by_user_id,
40+
inclusion: {
41+
in: :supplied_by_user_id_values
42+
},
43+
if: :requires_supplied_by_user_id?
44+
45+
validates :vaccine_method, inclusion: { in: :vaccine_method_options }
3846
validates :delivery_site,
3947
inclusion: {
4048
in: :delivery_site_options
@@ -59,6 +67,12 @@ def delivery_site
5967
super
6068
end
6169

70+
def supplied_by_users
71+
current_user.selected_team.users.show_in_suppliers
72+
end
73+
74+
def requires_supplied_by_user_id? = !current_user.show_in_suppliers
75+
6276
def save(draft_vaccination_record:)
6377
return nil if invalid?
6478

@@ -93,6 +107,7 @@ def save(draft_vaccination_record:)
93107
draft_vaccination_record.patient_id = patient_session.patient_id
94108
draft_vaccination_record.performed_at = Time.current
95109
draft_vaccination_record.performed_by_user = current_user
110+
draft_vaccination_record.supplied_by_user_id = supplied_by_user_id
96111
draft_vaccination_record.performed_ods_code = organisation.ods_code
97112
draft_vaccination_record.programme = programme
98113
draft_vaccination_record.session_id = patient_session.session_id
@@ -106,6 +121,8 @@ def save(draft_vaccination_record:)
106121

107122
def administered? = vaccine_method != "none"
108123

124+
def supplied_by_user_id_values = supplied_by_users.pluck(:id)
125+
109126
def vaccine_method_options
110127
programme.vaccine_methods + ["none"]
111128
end

app/models/draft_vaccination_record.rb

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class DraftVaccinationRecord
1111
attribute :delivery_method, :string
1212
attribute :delivery_site, :string
1313
attribute :dose_sequence, :integer
14+
attribute :first_active_wizard_step, :string
1415
attribute :full_dose, :boolean
15-
attribute :protocol, :string
1616
attribute :identity_check_confirmed_by_other_name, :string
1717
attribute :identity_check_confirmed_by_other_relationship, :string
1818
attribute :identity_check_confirmed_by_patient, :boolean
@@ -27,8 +27,9 @@ class DraftVaccinationRecord
2727
attribute :performed_by_user_id, :integer
2828
attribute :performed_ods_code, :string
2929
attribute :programme_id, :integer
30+
attribute :protocol, :string
3031
attribute :session_id, :integer
31-
attribute :first_active_wizard_step, :string
32+
attribute :supplied_by_user_id, :integer
3233

3334
def initialize(current_user:, **attributes)
3435
@current_user = current_user
@@ -47,6 +48,7 @@ def wizard_steps
4748
:notes,
4849
:date_and_time,
4950
(:outcome if can_change_outcome?),
51+
(:supplier if requires_supplied_by?),
5052
(:delivery if administered?),
5153
(:dose if administered? && can_be_half_dose?),
5254
(:batch if administered?),
@@ -187,13 +189,27 @@ def programme=(value)
187189
def session
188190
return nil if session_id.nil?
189191

190-
SessionPolicy::Scope.new(@current_user, Session).resolve.find(session_id)
192+
SessionPolicy::Scope
193+
.new(@current_user, Session)
194+
.resolve
195+
.includes(:programmes)
196+
.find(session_id)
191197
end
192198

193199
def session=(value)
194200
self.session_id = value.id
195201
end
196202

203+
def supplied_by
204+
return nil if supplied_by_user_id.nil?
205+
206+
User.find(supplied_by_user_id)
207+
end
208+
209+
def supplied_by=(value)
210+
self.supplied_by_user_id = value.id
211+
end
212+
197213
def vaccination_record
198214
return nil if editing_id.nil?
199215

@@ -272,7 +288,6 @@ def writable_attribute_names
272288
delivery_site
273289
dose_sequence
274290
full_dose
275-
protocol
276291
identity_check
277292
location_id
278293
location_name
@@ -285,7 +300,9 @@ def writable_attribute_names
285300
performed_by_user_id
286301
performed_ods_code
287302
programme_id
303+
protocol
288304
session_id
305+
supplied_by_user_id
289306
vaccine_id
290307
]
291308
end
@@ -344,6 +361,10 @@ def can_change_outcome?
344361
outcome != "already_had" || editing? || session.nil? || session.today?
345362
end
346363

364+
def requires_supplied_by?
365+
performed_by_user && !performed_by_user&.show_in_suppliers
366+
end
367+
347368
def delivery_site_matches_delivery_method
348369
return if delivery_method.blank?
349370

0 commit comments

Comments
 (0)