Skip to content

Commit 3f333a5

Browse files
committed
Add "careplus_integration_enabled_at" field to Patient
* Will be used by Automated Careplus reports Jira-Issue: MAV-XXX
1 parent 76b18c5 commit 3f333a5

5 files changed

Lines changed: 54 additions & 15 deletions

File tree

app/models/team.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Table name: teams
66
#
77
# id :bigint not null, primary key
8+
# careplus_integration_enabled_at :datetime
89
# careplus_namespace :string
910
# careplus_password :string
1011
# careplus_staff_code :string
@@ -30,10 +31,11 @@
3031
#
3132
# Indexes
3233
#
33-
# index_teams_on_name (name) UNIQUE
34-
# index_teams_on_organisation_id (organisation_id)
35-
# index_teams_on_programme_types (programme_types) USING gin
36-
# index_teams_on_workgroup (workgroup) UNIQUE
34+
# index_teams_on_careplus_integration_enabled_at (careplus_integration_enabled_at)
35+
# index_teams_on_name (name) UNIQUE
36+
# index_teams_on_organisation_id (organisation_id)
37+
# index_teams_on_programme_types (programme_types) USING gin
38+
# index_teams_on_workgroup (workgroup) UNIQUE
3739
#
3840
# Foreign Keys
3941
#
@@ -99,8 +101,12 @@ class Team < ApplicationRecord
99101
.where.not(careplus_username: nil)
100102
.where.not(careplus_password: nil)
101103
end
104+
scope :careplus_integration_enabled,
105+
-> { where.not(careplus_integration_enabled_at: nil) }
102106
scope :eligible_for_automated_careplus_reports,
103-
-> { careplus_enabled.has_careplus_credentials }
107+
-> do
108+
careplus_enabled.has_careplus_credentials.careplus_integration_enabled
109+
end
104110

105111
enum :type,
106112
{ point_of_care: 0, national_reporting: 1, support: 2 },
@@ -174,6 +180,7 @@ def careplus_enabled?
174180

175181
def eligible_for_automated_careplus_reports?
176182
careplus_enabled? && careplus_username.present? &&
177-
careplus_password.present? && careplus_namespace.present?
183+
careplus_password.present? && careplus_namespace.present? &&
184+
careplus_integration_enabled_at.present?
178185
end
179186
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
class AddCareplusIntegrationEnabledAtForTeam < ActiveRecord::Migration[8.1]
4+
def change
5+
add_column :teams, :careplus_integration_enabled_at, :datetime
6+
add_index :teams, :careplus_integration_enabled_at
7+
end
8+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
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_04_22_120000) do
13+
ActiveRecord::Schema[8.1].define(version: 2026_04_22_121000) 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"
@@ -906,6 +906,7 @@
906906
end
907907

908908
create_table "teams", force: :cascade do |t|
909+
t.datetime "careplus_integration_enabled_at"
909910
t.string "careplus_namespace"
910911
t.string "careplus_password"
911912
t.string "careplus_staff_code"
@@ -928,6 +929,7 @@
928929
t.integer "type", null: false
929930
t.datetime "updated_at", null: false
930931
t.string "workgroup", null: false
932+
t.index ["careplus_integration_enabled_at"], name: "index_teams_on_careplus_integration_enabled_at"
931933
t.index ["name"], name: "index_teams_on_name", unique: true
932934
t.index ["organisation_id"], name: "index_teams_on_organisation_id"
933935
t.index ["programme_types"], name: "index_teams_on_programme_types", using: :gin

spec/factories/teams.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Table name: teams
66
#
77
# id :bigint not null, primary key
8+
# careplus_integration_enabled_at :datetime
89
# careplus_namespace :string
910
# careplus_password :string
1011
# careplus_staff_code :string
@@ -30,10 +31,11 @@
3031
#
3132
# Indexes
3233
#
33-
# index_teams_on_name (name) UNIQUE
34-
# index_teams_on_organisation_id (organisation_id)
35-
# index_teams_on_programme_types (programme_types) USING gin
36-
# index_teams_on_workgroup (workgroup) UNIQUE
34+
# index_teams_on_careplus_integration_enabled_at (careplus_integration_enabled_at)
35+
# index_teams_on_name (name) UNIQUE
36+
# index_teams_on_organisation_id (organisation_id)
37+
# index_teams_on_programme_types (programme_types) USING gin
38+
# index_teams_on_workgroup (workgroup) UNIQUE
3739
#
3840
# Foreign Keys
3941
#
@@ -93,6 +95,7 @@
9395
end
9496

9597
trait :with_careplus_enabled do
98+
careplus_integration_enabled_at { Time.current }
9699
careplus_namespace { "MOCK" }
97100
careplus_staff_code { "LW5PM" }
98101
careplus_staff_type { "IN" }

spec/models/team_spec.rb

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Table name: teams
66
#
77
# id :bigint not null, primary key
8+
# careplus_integration_enabled_at :datetime
89
# careplus_namespace :string
910
# careplus_password :string
1011
# careplus_staff_code :string
@@ -30,10 +31,11 @@
3031
#
3132
# Indexes
3233
#
33-
# index_teams_on_name (name) UNIQUE
34-
# index_teams_on_organisation_id (organisation_id)
35-
# index_teams_on_programme_types (programme_types) USING gin
36-
# index_teams_on_workgroup (workgroup) UNIQUE
34+
# index_teams_on_careplus_integration_enabled_at (careplus_integration_enabled_at)
35+
# index_teams_on_name (name) UNIQUE
36+
# index_teams_on_organisation_id (organisation_id)
37+
# index_teams_on_programme_types (programme_types) USING gin
38+
# index_teams_on_workgroup (workgroup) UNIQUE
3739
#
3840
# Foreign Keys
3941
#
@@ -175,6 +177,11 @@
175177
create(:team, :with_careplus_enabled, careplus_username: nil)
176178
create(:team, :with_careplus_enabled, careplus_password: nil)
177179
create(:team, :with_careplus_enabled, careplus_namespace: nil)
180+
create(
181+
:team,
182+
:with_careplus_enabled,
183+
careplus_integration_enabled_at: nil
184+
)
178185
create(
179186
:team,
180187
careplus_username: "careplus_user",
@@ -227,6 +234,18 @@
227234
it { should be(false) }
228235
end
229236

237+
context "when CarePlus integration has not been enabled yet" do
238+
let(:team) do
239+
create(
240+
:team,
241+
:with_careplus_enabled,
242+
careplus_integration_enabled_at: nil
243+
)
244+
end
245+
246+
it { should be(false) }
247+
end
248+
230249
context "when CarePlus export fields are missing" do
231250
let(:team) do
232251
create(

0 commit comments

Comments
 (0)