Skip to content

Commit 4dd42fb

Browse files
authored
Merge pull request #5964 from nhsuk/fix-already-vaccinated-flow
Fix already vaccinated flow
2 parents 716cabe + 3986578 commit 4dd42fb

12 files changed

Lines changed: 442 additions & 23 deletions

app/components/app_vaccination_record_summary_component.rb

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,15 @@ def call
234234
end
235235
end
236236

237-
if @vaccination_record.performed_by.present?
238-
summary_list.with_row do |row|
239-
row.with_key { "Vaccinator" }
240-
row.with_value { vaccinator_value }
241-
if (href = @change_links[:vaccinator])
242-
row.with_action(
243-
text: "Change",
244-
visually_hidden_text: "vaccinator",
245-
href:
246-
)
247-
end
237+
summary_list.with_row do |row|
238+
row.with_key { "Vaccinator" }
239+
row.with_value { vaccinator_value }
240+
if (href = @change_links[:vaccinator])
241+
row.with_action(
242+
text: "Change",
243+
visually_hidden_text: "vaccinator",
244+
href:
245+
)
248246
end
249247
end
250248

@@ -293,6 +291,20 @@ def call
293291
end
294292
end
295293

294+
if @vaccination_record.reported_by.present?
295+
summary_list.with_row do |row|
296+
row.with_key { "Reported by" }
297+
row.with_value { @vaccination_record.reported_by&.full_name }
298+
end
299+
end
300+
301+
if @vaccination_record.reported_at.present?
302+
summary_list.with_row do |row|
303+
row.with_key { "Reported on" }
304+
row.with_value { @vaccination_record.reported_at.to_fs(:long) }
305+
end
306+
end
307+
296308
correct_feature_flags_enabled =
297309
Programme.all.any? { Flipper.enabled?(:imms_api_sync_job, it) } &&
298310
Flipper.enabled?(:imms_api_integration)
@@ -327,10 +339,13 @@ def source_value
327339
end
328340

329341
def outcome_value
330-
highlight_if(
331-
VaccinationRecord.human_enum_name(:outcome, @vaccination_record.outcome),
332-
@vaccination_record.outcome_changed?
333-
)
342+
outcome = VaccinationRecord.human_enum_name(:outcome, @vaccination_record.outcome)
343+
344+
if @vaccination_record.already_had? && @vaccination_record.reported_as_already_vaccinated?
345+
outcome = VaccinationRecord.human_enum_name(:outcome, "administered")
346+
end
347+
348+
highlight_if(outcome, @vaccination_record.outcome_changed?)
334349
end
335350

336351
def programme_value
@@ -418,8 +433,10 @@ def vaccinator_value
418433
value =
419434
if @vaccination_record.performed_by == @current_user
420435
"You (#{@current_user.full_name})"
421-
else
436+
elsif @vaccination_record.performed_by
422437
@vaccination_record.performed_by&.full_name
438+
else
439+
"Unknown"
423440
end
424441

425442
highlight_if(

app/controllers/draft_vaccination_records_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def handle_mmr_or_mmrv
147147
end
148148

149149
def handle_location
150-
if @draft_vaccination_record.national_reporting_user_and_record?
150+
if @session&.generic_clinic? ||
151+
@draft_vaccination_record.national_reporting_user_and_record?
151152
location_id = update_params[:location_id]
152153

153154
if location_id == "unknown"

app/controllers/patient_sessions/programmes_controller.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,24 @@ def record_already_vaccinated
1919

2020
draft_vaccination_record.clear_attributes
2121
draft_vaccination_record.update!(
22-
first_active_wizard_step: :confirm,
22+
dose_sequence: dose_sequence,
23+
first_active_wizard_step:
24+
eligible_for_mmr_or_mmrv? ? :mmr_or_mmrv : :date_and_time,
2325
location_id: nil,
2426
location_name: "Unknown",
2527
outcome: :already_had,
2628
patient: @patient,
27-
performed_at: Time.current,
28-
performed_by_user_id: current_user.id,
2929
performed_ods_code: current_team.organisation.ods_code,
3030
programme: @programme,
31+
reported_by_id: current_user.id,
32+
reported_at: Time.current,
3133
session: @session,
3234
source: "service"
3335
)
3436

35-
redirect_to draft_vaccination_record_path("confirm")
37+
redirect_to draft_vaccination_record_path(
38+
eligible_for_mmr_or_mmrv? ? "mmr-or-mmrv" : "date-and-time"
39+
)
3640
end
3741

3842
private

app/models/draft_vaccination_record.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class DraftVaccinationRecord
3636
attribute :performed_ods_code, :string
3737
attribute :programme_type, :string
3838
attribute :protocol, :string
39+
attribute :reported_at, :datetime
40+
attribute :reported_by_id, :integer
3941
attribute :session_id, :integer
4042
attribute :source, :string
4143
attribute :supplied_by_user_id, :integer
@@ -59,6 +61,12 @@ def wizard_steps
5961
[
6062
:identity,
6163
(:notes unless national_reporting_user_and_record?),
64+
(
65+
if programme&.mmr? && (administered? || already_had?) &&
66+
patient.eligible_for_mmrv?
67+
:mmr_or_mmrv
68+
end
69+
),
6270
:date_and_time,
6371
(:outcome if can_change_outcome?),
6472
(:supplier if requires_supplied_by?),
@@ -185,6 +193,10 @@ def already_had?
185193
outcome == "already_had"
186194
end
187195

196+
def reported_as_already_vaccinated?
197+
already_had? && reported_by_id.present?
198+
end
199+
188200
# So that a form error matches to a field in this model
189201
alias_method :administered, :administered?
190202

@@ -215,6 +227,11 @@ def performed_by_user=(value)
215227
self.performed_by_user_id = value.id
216228
end
217229

230+
def reported_by
231+
return nil if reported_by_id.nil?
232+
User.find(reported_by_id)
233+
end
234+
218235
def session
219236
return nil if session_id.nil?
220237

@@ -400,6 +417,8 @@ def writable_attribute_names
400417
performed_ods_code
401418
programme_type
402419
protocol
420+
reported_at
421+
reported_by_id
403422
session_id
404423
source
405424
supplied_by_user_id

app/models/vaccination_record.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
# performed_ods_code :string
3434
# programme_type :enum not null
3535
# protocol :integer
36+
# reported_at :datetime
3637
# source :integer not null
3738
# uuid :uuid not null
3839
# created_at :datetime not null
@@ -43,6 +44,7 @@
4344
# nhs_immunisations_api_id :string
4445
# patient_id :bigint not null
4546
# performed_by_user_id :bigint
47+
# reported_by_id :bigint
4648
# session_id :bigint
4749
# supplied_by_user_id :bigint
4850
# vaccine_id :bigint
@@ -60,6 +62,7 @@
6062
# index_vaccination_records_on_performed_by_user_id (performed_by_user_id)
6163
# index_vaccination_records_on_performed_ods_code_and_patient_id (performed_ods_code,patient_id) WHERE (session_id IS NULL)
6264
# index_vaccination_records_on_programme_type (programme_type)
65+
# index_vaccination_records_on_reported_by_id (reported_by_id)
6366
# index_vaccination_records_on_session_id (session_id)
6467
# index_vaccination_records_on_supplied_by_user_id (supplied_by_user_id)
6568
# index_vaccination_records_on_uuid (uuid) UNIQUE
@@ -70,6 +73,7 @@
7073
# fk_rails_... (next_dose_delay_triage_id => triages.id)
7174
# fk_rails_... (patient_id => patients.id)
7275
# fk_rails_... (performed_by_user_id => users.id)
76+
# fk_rails_... (reported_by_id => users.id)
7377
# fk_rails_... (session_id => sessions.id)
7478
# fk_rails_... (supplied_by_user_id => users.id)
7579
# fk_rails_... (vaccine_id => vaccines.id)
@@ -108,6 +112,10 @@ class VaccinationRecord < ApplicationRecord
108112
belongs_to :vaccine, optional: true
109113

110114
belongs_to :performed_by_user, class_name: "User", optional: true
115+
belongs_to :reported_by,
116+
class_name: "User",
117+
foreign_key: :reported_by_id,
118+
optional: true
111119
belongs_to :supplied_by,
112120
class_name: "User",
113121
foreign_key: :supplied_by_user_id,
@@ -261,6 +269,10 @@ class << self
261269

262270
def not_administered? = !administered?
263271

272+
def reported_as_already_vaccinated?
273+
already_had? && reported_by_id.present?
274+
end
275+
264276
def show_in_academic_year?(current_academic_year)
265277
if programme.seasonal?
266278
academic_year == current_academic_year

app/views/draft_vaccination_records/confirm.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
show_notes:,
3939
) %>
4040

41-
<% if @draft_vaccination_record.administered? %>
42-
<% if @draft_vaccination_record.vaccine_method_matches_consent_and_triage? %>
41+
<% if @draft_vaccination_record.administered? || @draft_vaccination_record.reported_as_already_vaccinated? %>
42+
<% if @draft_vaccination_record.vaccine_method_matches_consent_and_triage? || @draft_vaccination_record.reported_as_already_vaccinated? %>
4343
<%= render AppCardComponent.new do |card| %>
4444
<% card.with_heading { "Vaccination details" } %>
4545
<%= render vaccination_summary %>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
class AddReportedByAndReportedAtToVaccinationRecords < ActiveRecord::Migration[
4+
8.1
5+
]
6+
def change
7+
add_reference :vaccination_records,
8+
:reported_by,
9+
foreign_key: {
10+
to_table: :users
11+
},
12+
index: true
13+
add_column :vaccination_records, :reported_at, :datetime
14+
end
15+
end

db/schema.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,8 @@
955955
t.string "performed_ods_code"
956956
t.enum "programme_type", null: false, enum_type: "programme_type"
957957
t.integer "protocol"
958+
t.datetime "reported_at"
959+
t.bigint "reported_by_id"
958960
t.bigint "session_id"
959961
t.integer "source", null: false
960962
t.bigint "supplied_by_user_id"
@@ -972,6 +974,7 @@
972974
t.index ["performed_by_user_id"], name: "index_vaccination_records_on_performed_by_user_id"
973975
t.index ["performed_ods_code", "patient_id"], name: "index_vaccination_records_on_performed_ods_code_and_patient_id", where: "(session_id IS NULL)"
974976
t.index ["programme_type"], name: "index_vaccination_records_on_programme_type"
977+
t.index ["reported_by_id"], name: "index_vaccination_records_on_reported_by_id"
975978
t.index ["session_id"], name: "index_vaccination_records_on_session_id"
976979
t.index ["supplied_by_user_id"], name: "index_vaccination_records_on_supplied_by_user_id"
977980
t.index ["uuid"], name: "index_vaccination_records_on_uuid", unique: true
@@ -1122,6 +1125,7 @@
11221125
add_foreign_key "vaccination_records", "sessions"
11231126
add_foreign_key "vaccination_records", "triages", column: "next_dose_delay_triage_id"
11241127
add_foreign_key "vaccination_records", "users", column: "performed_by_user_id"
1128+
add_foreign_key "vaccination_records", "users", column: "reported_by_id"
11251129
add_foreign_key "vaccination_records", "users", column: "supplied_by_user_id"
11261130
add_foreign_key "vaccination_records", "vaccines"
11271131

spec/factories/vaccination_records.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
# performed_ods_code :string
3434
# programme_type :enum not null
3535
# protocol :integer
36+
# reported_at :datetime
3637
# source :integer not null
3738
# uuid :uuid not null
3839
# created_at :datetime not null
@@ -43,6 +44,7 @@
4344
# nhs_immunisations_api_id :string
4445
# patient_id :bigint not null
4546
# performed_by_user_id :bigint
47+
# reported_by_id :bigint
4648
# session_id :bigint
4749
# supplied_by_user_id :bigint
4850
# vaccine_id :bigint
@@ -60,6 +62,7 @@
6062
# index_vaccination_records_on_performed_by_user_id (performed_by_user_id)
6163
# index_vaccination_records_on_performed_ods_code_and_patient_id (performed_ods_code,patient_id) WHERE (session_id IS NULL)
6264
# index_vaccination_records_on_programme_type (programme_type)
65+
# index_vaccination_records_on_reported_by_id (reported_by_id)
6366
# index_vaccination_records_on_session_id (session_id)
6467
# index_vaccination_records_on_supplied_by_user_id (supplied_by_user_id)
6568
# index_vaccination_records_on_uuid (uuid) UNIQUE
@@ -70,6 +73,7 @@
7073
# fk_rails_... (next_dose_delay_triage_id => triages.id)
7174
# fk_rails_... (patient_id => patients.id)
7275
# fk_rails_... (performed_by_user_id => users.id)
76+
# fk_rails_... (reported_by_id => users.id)
7377
# fk_rails_... (session_id => sessions.id)
7478
# fk_rails_... (supplied_by_user_id => users.id)
7579
# fk_rails_... (vaccine_id => vaccines.id)

0 commit comments

Comments
 (0)