Skip to content

Commit a730931

Browse files
committed
Allow triage performed by to be optional
This updates the `performed_by_user_id` column on triages to be `NOT NULL`, allowing it to not be specified when we don't have a suitable user. The only place this will be set to `NULL` for now is when creating the automatic next dose delay triage. Jira-Issue: MAV-2991
1 parent 5c28e7c commit a730931

10 files changed

Lines changed: 66 additions & 34 deletions

app/components/app_patient_session_triage_component.html.erb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,8 @@
2929
<p>A nurse needs to decide if <%= patient.full_name %> is safe to vaccinate.</p>
3030
<% end %>
3131
<% elsif latest_triage %>
32-
<% if latest_triage.safe_to_vaccinate? %>
33-
<% if latest_triage.vaccine_method.present? && programme.has_multiple_vaccine_methods? %>
34-
<p><%= latest_triage.performed_by.full_name %> decided that <%= patient.full_name %> is safe to vaccinate using the <%= vaccination_method %> vaccine only.</p>
35-
<% else %>
36-
<p><%= latest_triage.performed_by.full_name %> decided that <%= patient.full_name %> is safe to vaccinate.</p>
37-
<% end %>
38-
<% elsif latest_triage.do_not_vaccinate? %>
39-
<p><%= latest_triage.performed_by.full_name %> decided that <%= patient.full_name %> should not be vaccinated.</p>
40-
<% elsif latest_triage.delay_vaccination? %>
41-
<p><%= latest_triage.performed_by.full_name %> decided that <%= patient.full_name %>'s vaccination should be delayed.</p>
32+
<% if (summary = triage_summary(latest_triage)) %>
33+
<p><%= summary %></p>
4234
<% end %>
4335

4436
<div class="nhsuk-button-group">

app/components/app_patient_session_triage_component.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def render? = consent_status.given? || !triage_status.not_required?
1919

2020
attr_reader :current_user, :triage_form
2121

22-
delegate :govuk_button_link_to, to: :helpers
22+
delegate :govuk_button_link_to, :triage_summary, to: :helpers
2323

2424
def programme_type = programme.type
2525

@@ -39,10 +39,6 @@ def consent_status
3939
patient.consent_status(programme:, academic_year:)
4040
end
4141

42-
def vaccination_method
43-
Vaccine.human_enum_name(:method_prefix, triage_status.vaccine_method)
44-
end
45-
4642
def latest_triage
4743
@latest_triage ||=
4844
TriageFinder.call(

app/components/app_triage_table_component.html.erb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
<% body.with_row do |row| %>
1515
<% row.with_cell do %>
1616
<%= triage.created_at.to_fs(:long) %>
17-
<br />
18-
<span class="nhsuk-u-secondary-text-colour nhsuk-u-font-size-16">
19-
<%= triage.performed_by.full_name %>
20-
</span>
17+
<% if (performed_by = triage.performed_by) %>
18+
<br />
19+
<span class="nhsuk-u-secondary-text-colour nhsuk-u-font-size-16">
20+
<%= performed_by.full_name %>
21+
</span>
22+
<% end %>
2123
<% end %>
2224

2325
<% row.with_cell(text: triage.notes) %>

app/helpers/triages_helper.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,31 @@ def triage_status_tag(triage)
4848
govuk_tag(text:, classes: "nhsuk-tag--#{colour}")
4949
end
5050
end
51+
52+
def triage_summary(triage)
53+
prefix =
54+
if (performed_by = triage.performed_by)
55+
"#{performed_by.full_name} decided that "
56+
else
57+
""
58+
end
59+
60+
suffix =
61+
if triage.safe_to_vaccinate?
62+
if triage.vaccine_method.present? &&
63+
triage.programme.has_multiple_vaccine_methods?
64+
vaccination_method =
65+
Vaccine.human_enum_name(:method_prefix, triage.vaccine_method)
66+
"is safe to vaccinate using the #{vaccination_method} vaccine only."
67+
else
68+
"is safe to vaccinate."
69+
end
70+
elsif triage.do_not_vaccinate?
71+
"should not be vaccinated."
72+
elsif triage.delay_vaccination?
73+
"’s vaccination should be delayed."
74+
end
75+
76+
"#{prefix}#{triage.patient.full_name} #{suffix}" if suffix
77+
end
5178
end

app/models/triage.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# created_at :datetime not null
1717
# updated_at :datetime not null
1818
# patient_id :bigint not null
19-
# performed_by_user_id :bigint not null
19+
# performed_by_user_id :bigint
2020
# team_id :bigint not null
2121
#
2222
# Indexes
@@ -37,12 +37,15 @@ class Triage < ApplicationRecord
3737
include BelongsToProgramme
3838
include Invalidatable
3939
include Notable
40-
include PerformableByUser
4140

4241
audited associated_with: :patient
4342

4443
belongs_to :patient
4544
belongs_to :team
45+
belongs_to :performed_by,
46+
class_name: "User",
47+
foreign_key: :performed_by_user_id,
48+
optional: true
4649

4750
enum :status,
4851
{
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class MakeTriagePerformedByNull < ActiveRecord::Migration[8.1]
4+
def change
5+
change_column_null :triages, :performed_by_user_id, true
6+
end
7+
end

db/schema.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[8.1].define(version: 2026_01_07_194410) do
13+
ActiveRecord::Schema[8.1].define(version: 2026_01_08_143705) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pg_catalog.plpgsql"
1616
enable_extension "pg_trgm"
@@ -893,7 +893,7 @@
893893
t.datetime "invalidated_at"
894894
t.text "notes", default: "", null: false
895895
t.bigint "patient_id", null: false
896-
t.bigint "performed_by_user_id", null: false
896+
t.bigint "performed_by_user_id"
897897
t.enum "programme_type", null: false, enum_type: "programme_type"
898898
t.integer "status", null: false
899899
t.bigint "team_id", null: false

spec/components/app_triage_table_component_spec.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,27 @@
2525
subject { render_inline(component) }
2626

2727
context "triaged as safe to vaccinate" do
28-
let!(:triage) do
29-
create(:triage, :safe_to_vaccinate, patient:, programme:)
30-
end
28+
before { create(:triage, :safe_to_vaccinate, patient:, programme:) }
3129

3230
it { should have_css("caption", text: "Triage notes") }
3331
it { should have_content("Safe to vaccinate") }
34-
it { should have_content(triage.performed_by.full_name) }
3532
end
3633

3734
context "triaged as unsafe to vaccinate" do
38-
let!(:triage) { create(:triage, :do_not_vaccinate, patient:, programme:) }
35+
before { create(:triage, :do_not_vaccinate, patient:, programme:) }
3936

4037
it { should have_css("caption", text: "Triage notes") }
4138
it { should have_content("Do not vaccinate") }
42-
it { should have_content(triage.performed_by.full_name) }
39+
end
40+
41+
context "with a performed by user" do
42+
before do
43+
create(:triage, :safe_to_vaccinate, patient:, programme:, performed_by:)
44+
end
45+
46+
let(:performed_by) { create(:nurse) }
47+
48+
it { should have_content(performed_by.full_name) }
4349
end
4450
end
4551
end

spec/factories/triages.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# created_at :datetime not null
1717
# updated_at :datetime not null
1818
# patient_id :bigint not null
19-
# performed_by_user_id :bigint not null
19+
# performed_by_user_id :bigint
2020
# team_id :bigint not null
2121
#
2222
# Indexes
@@ -38,8 +38,7 @@
3838
patient
3939
programme { Programme.sample }
4040

41-
performed_by
42-
team { performed_by.teams.first }
41+
team
4342

4443
notes { "" }
4544

spec/models/triage_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# created_at :datetime not null
1717
# updated_at :datetime not null
1818
# patient_id :bigint not null
19-
# performed_by_user_id :bigint not null
19+
# performed_by_user_id :bigint
2020
# team_id :bigint not null
2121
#
2222
# Indexes
@@ -40,7 +40,7 @@
4040
describe "associations" do
4141
it { should belong_to(:patient) }
4242
it { should belong_to(:team) }
43-
it { should belong_to(:performed_by) }
43+
it { should belong_to(:performed_by).optional(true) }
4444
end
4545

4646
describe "validations" do

0 commit comments

Comments
 (0)