Skip to content

Commit 4ddfc47

Browse files
committed
wip
1 parent 477ff81 commit 4ddfc47

17 files changed

+129
-20
lines changed

app/components/app_patient_session_record_component.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ class AppPatientSessionRecordComponent < ViewComponent::Base
88
<% end %>
99
ERB
1010

11-
def initialize(patient_session, programme:, vaccinate_form: nil)
11+
def initialize(patient_session, programme:, current_user:, vaccinate_form:)
1212
super
1313

1414
@patient_session = patient_session
1515
@programme = programme
16+
@current_user = current_user
1617
@vaccinate_form = vaccinate_form || default_vaccinate_form
1718
end
1819

@@ -27,7 +28,7 @@ def render?
2728

2829
private
2930

30-
attr_reader :patient_session, :programme, :vaccinate_form
31+
attr_reader :patient_session, :current_user, :programme, :vaccinate_form
3132

3233
delegate :patient, :session, to: :patient_session
3334
delegate :academic_year, to: :session
@@ -39,7 +40,12 @@ def vaccination_record
3940
def default_vaccinate_form
4041
pre_screening_confirmed = patient.pre_screenings.today.exists?(programme:)
4142

42-
VaccinateForm.new(patient_session:, programme:, pre_screening_confirmed:)
43+
VaccinateForm.new(
44+
current_user:,
45+
patient_session:,
46+
programme:,
47+
pre_screening_confirmed:
48+
)
4349
end
4450

4551
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ 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+
end
209+
end
210+
204211
if @vaccination_record.performed_by.present?
205212
summary_list.with_row do |row|
206213
row.with_key { "Vaccinator" }
@@ -331,6 +338,13 @@ def time_value
331338
)
332339
end
333340

341+
def supplier_value
342+
highlight_if(
343+
@vaccination_record.supplied_by&.full_name,
344+
@vaccination_record.supplied_by_user_id_changed?
345+
)
346+
end
347+
334348
def vaccinator_value
335349
value =
336350
if @vaccination_record.performed_by == @current_user

app/controllers/draft_vaccination_records_controller.rb

Lines changed: 5 additions & 0 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
@@ -231,6 +232,10 @@ def set_locations
231232
@locations = policy_scope(Location).community_clinic
232233
end
233234

235+
def set_supplied_by_users
236+
@supplied_by_users = current_team.users.show_in_suppliers
237+
end
238+
234239
def set_back_link_path
235240
@back_link_path =
236241
if @draft_vaccination_record.editing?

app/forms/vaccinate_form.rb

Lines changed: 17 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,10 @@ def delivery_site
5967
super
6068
end
6169

70+
def supplied_by_users = current_user.selected_team.users.show_in_suppliers
71+
72+
def requires_supplied_by_user_id? = !current_user.show_in_suppliers
73+
6274
def save(draft_vaccination_record:)
6375
return nil if invalid?
6476

@@ -93,6 +105,7 @@ def save(draft_vaccination_record:)
93105
draft_vaccination_record.patient_id = patient_session.patient_id
94106
draft_vaccination_record.performed_at = Time.current
95107
draft_vaccination_record.performed_by_user = current_user
108+
draft_vaccination_record.supplied_by_user_id = supplied_by_user_id
96109
draft_vaccination_record.performed_ods_code = organisation.ods_code
97110
draft_vaccination_record.programme = programme
98111
draft_vaccination_record.session_id = patient_session.session_id
@@ -106,6 +119,8 @@ def save(draft_vaccination_record:)
106119

107120
def administered? = vaccine_method != "none"
108121

122+
def supplied_by_user_id_values = supplied_by_users.pluck(:id)
123+
109124
def vaccine_method_options
110125
programme.vaccine_methods + ["none"]
111126
end

app/models/draft_vaccination_record.rb

Lines changed: 15 additions & 3 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
@@ -198,6 +199,16 @@ def session=(value)
198199
self.session_id = value.id
199200
end
200201

202+
def supplied_by
203+
return nil if supplied_by_user_id.nil?
204+
205+
User.find(supplied_by_user_id)
206+
end
207+
208+
def supplied_by=(value)
209+
self.supplied_by_user_id = value.id
210+
end
211+
201212
def vaccination_record
202213
return nil if editing_id.nil?
203214

@@ -276,7 +287,6 @@ def writable_attribute_names
276287
delivery_site
277288
dose_sequence
278289
full_dose
279-
protocol
280290
identity_check
281291
location_id
282292
location_name
@@ -289,7 +299,9 @@ def writable_attribute_names
289299
performed_by_user_id
290300
performed_ods_code
291301
programme_id
302+
protocol
292303
session_id
304+
supplied_by_user_id
293305
vaccine_id
294306
]
295307
end

app/models/user.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class User < ApplicationRecord
7272
scope :recently_active,
7373
-> { where(last_sign_in_at: 1.week.ago..Time.current) }
7474

75+
scope :show_in_suppliers,
76+
-> { recently_active.where(show_in_suppliers: true) }
77+
7578
enum :fallback_role,
7679
{
7780
nurse: 0,

app/views/draft_vaccination_records/confirm.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
delivery_site: wizard_path("delivery"),
2121
dose_volume: @draft_vaccination_record.wizard_steps.include?(:dose) ? wizard_path("dose") : nil,
2222
identity: wizard_path("identity"),
23+
supplier: wizard_path("supplier"),
2324
location: @draft_vaccination_record.wizard_steps.include?(:location) ? wizard_path("location") : nil,
2425
notes: wizard_path("notes"),
2526
outcome: @draft_vaccination_record.wizard_steps.include?(:outcome) ? wizard_path("outcome") : nil,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<% content_for :before_main do %>
2+
<%= render AppBacklinkComponent.new(@back_link_path) %>
3+
<% end %>
4+
5+
<% title = "Which nurse identified and pre-screened the child and supplied the vaccine?" %>
6+
<% content_for :page_title, title %>
7+
8+
<%= form_with model: @draft_vaccination_record, url: wizard_path, method: :put do |f| %>
9+
<%= f.govuk_error_summary %>
10+
11+
<%= f.govuk_radio_buttons_fieldset :supplied_by_user_id,
12+
caption: { text: @patient.full_name, size: "l" },
13+
legend: { size: "l", tag: "h1",
14+
text: title } do %>
15+
16+
<% @supplied_by_users.each do |user| %>
17+
<%= f.govuk_radio_button :supplied_by_user_id, user.id, label: { text: user.full_name } %>
18+
<% end %>
19+
<% end %>
20+
21+
<%= f.govuk_submit "Continue" %>
22+
<% end %>

0 commit comments

Comments
 (0)