Skip to content

Commit 26f9f91

Browse files
committed
Allow triage team to be optional
This updates the `team_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 a730931 commit 26f9f91

7 files changed

Lines changed: 24 additions & 15 deletions

File tree

app/models/triage.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# updated_at :datetime not null
1818
# patient_id :bigint not null
1919
# performed_by_user_id :bigint
20-
# team_id :bigint not null
20+
# team_id :bigint
2121
#
2222
# Indexes
2323
#
@@ -41,7 +41,7 @@ class Triage < ApplicationRecord
4141
audited associated_with: :patient
4242

4343
belongs_to :patient
44-
belongs_to :team
44+
belongs_to :team, optional: true
4545
belongs_to :performed_by,
4646
class_name: "User",
4747
foreign_key: :performed_by_user_id,

app/policies/triage_policy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def update?
1111

1212
class Scope < ApplicationPolicy::Scope
1313
def resolve
14-
scope.where(team: user.selected_team)
14+
scope.where(team: [nil, user.selected_team])
1515
end
1616
end
1717
end
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 MakeTriageTeamNull < ActiveRecord::Migration[8.1]
4+
def change
5+
change_column_null :triages, :team_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_08_143705) do
13+
ActiveRecord::Schema[8.1].define(version: 2026_01_08_150039) 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"
@@ -896,7 +896,7 @@
896896
t.bigint "performed_by_user_id"
897897
t.enum "programme_type", null: false, enum_type: "programme_type"
898898
t.integer "status", null: false
899-
t.bigint "team_id", null: false
899+
t.bigint "team_id"
900900
t.datetime "updated_at", null: false
901901
t.integer "vaccine_method"
902902
t.boolean "without_gelatine"

spec/factories/triages.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# updated_at :datetime not null
1818
# patient_id :bigint not null
1919
# performed_by_user_id :bigint
20-
# team_id :bigint not null
20+
# team_id :bigint
2121
#
2222
# Indexes
2323
#
@@ -38,8 +38,6 @@
3838
patient
3939
programme { Programme.sample }
4040

41-
team
42-
4341
notes { "" }
4442

4543
academic_year { created_at&.to_date&.academic_year || AcademicYear.current }

spec/models/triage_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# updated_at :datetime not null
1818
# patient_id :bigint not null
1919
# performed_by_user_id :bigint
20-
# team_id :bigint not null
20+
# team_id :bigint
2121
#
2222
# Indexes
2323
#
@@ -39,7 +39,7 @@
3939

4040
describe "associations" do
4141
it { should belong_to(:patient) }
42-
it { should belong_to(:team) }
42+
it { should belong_to(:team).optional(true) }
4343
it { should belong_to(:performed_by).optional(true) }
4444
end
4545

spec/policies/triage_policy_spec.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@
6060
let(:team) { create(:team) }
6161
let(:user) { create(:user, team:) }
6262

63-
let(:team_batch) { create(:triage, :safe_to_vaccinate, team:) }
64-
let(:non_team_batch) { create(:triage, :safe_to_vaccinate) }
65-
66-
it { should include(team_batch) }
67-
it { should_not include(non_team_batch) }
63+
let(:triage_for_team) { create(:triage, :safe_to_vaccinate, team:) }
64+
let(:triage_for_different_team) do
65+
create(:triage, :safe_to_vaccinate, team: create(:team))
66+
end
67+
let(:triage_for_all_teams) { create(:triage, :safe_to_vaccinate) }
68+
69+
it { should include(triage_for_team) }
70+
it { should_not include(triage_for_different_team) }
71+
it { should include(triage_for_all_teams) }
6872
end
6973
end
7074
end

0 commit comments

Comments
 (0)