Skip to content

Commit 6749924

Browse files
committed
Add "careplus_integration_enabled_at" field to Patient
* Will be used by Automated Careplus reports Jira-Issue: MAV-7091
1 parent c4598bc commit 6749924

7 files changed

Lines changed: 132 additions & 76 deletions

File tree

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

app/lib/mavis_cli/reports/send_to_careplus.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ def resolve_credentials(ods_code:, workgroup:)
8888

8989
team = teams.sole
9090

91-
unless team.careplus_username.present? &&
92-
team.careplus_password.present?
93-
warn "Team '#{team.name}' does not have CarePlus credentials configured."
91+
unless team.has_careplus_credentials?
92+
warn "Team '#{team.name}' needs the CarePlus username, password, and namespace configured to send reports."
9493
return nil, nil, nil
9594
end
9695

app/models/team.rb

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,30 @@
44
#
55
# Table name: teams
66
#
7-
# id :bigint not null, primary key
8-
# careplus_namespace :string
9-
# careplus_password :string
10-
# careplus_staff_code :string
11-
# careplus_staff_type :string
12-
# careplus_username :string
13-
# careplus_venue_code :string
14-
# days_before_consent_reminders :integer default(7), not null
15-
# days_before_consent_requests :integer default(21), not null
16-
# email :string
17-
# name :text not null
18-
# national_reporting_cut_off_date :date
19-
# phone :string
20-
# phone_instructions :string
21-
# privacy_notice_url :string
22-
# privacy_policy_url :string
23-
# programme_types :enum not null, is an Array
24-
# type :integer not null
25-
# workgroup :string not null
26-
# created_at :datetime not null
27-
# updated_at :datetime not null
28-
# organisation_id :bigint not null
29-
# reply_to_id :uuid
7+
# id :bigint not null, primary key
8+
# careplus_automated_reports_enabled_at :datetime
9+
# careplus_namespace :string
10+
# careplus_password :string
11+
# careplus_staff_code :string
12+
# careplus_staff_type :string
13+
# careplus_username :string
14+
# careplus_venue_code :string
15+
# days_before_consent_reminders :integer default(7), not null
16+
# days_before_consent_requests :integer default(21), not null
17+
# email :string
18+
# name :text not null
19+
# national_reporting_cut_off_date :date
20+
# phone :string
21+
# phone_instructions :string
22+
# privacy_notice_url :string
23+
# privacy_policy_url :string
24+
# programme_types :enum not null, is an Array
25+
# type :integer not null
26+
# workgroup :string not null
27+
# created_at :datetime not null
28+
# updated_at :datetime not null
29+
# organisation_id :bigint not null
30+
# reply_to_id :uuid
3031
#
3132
# Indexes
3233
#
@@ -99,8 +100,12 @@ class Team < ApplicationRecord
99100
.where.not(careplus_username: nil)
100101
.where.not(careplus_password: nil)
101102
end
103+
scope :careplus_automated_reports_enabled,
104+
-> { where.not(careplus_automated_reports_enabled_at: nil) }
102105
scope :eligible_for_automated_careplus_reports,
103-
-> { careplus_enabled.has_careplus_credentials }
106+
-> do
107+
careplus_enabled.has_careplus_credentials.careplus_automated_reports_enabled
108+
end
104109

105110
enum :type,
106111
{ point_of_care: 0, national_reporting: 1, support: 2 },
@@ -172,8 +177,13 @@ def careplus_enabled?
172177
careplus_venue_code.present?
173178
end
174179

180+
def has_careplus_credentials?
181+
careplus_username.present? && careplus_password.present? &&
182+
careplus_namespace.present?
183+
end
184+
175185
def eligible_for_automated_careplus_reports?
176-
careplus_enabled? && careplus_username.present? &&
177-
careplus_password.present? && careplus_namespace.present?
186+
careplus_enabled? && has_careplus_credentials? &&
187+
careplus_automated_reports_enabled_at.present?
178188
end
179189
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 AddCareplusAutomatedReportsEnabledAtForTeam < ActiveRecord::Migration[8.1]
4+
def change
5+
add_column :teams, :careplus_automated_reports_enabled_at, :datetime
6+
end
7+
end

db/schema.rb

Lines changed: 2 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_automated_reports_enabled_at"
909910
t.string "careplus_namespace"
910911
t.string "careplus_password"
911912
t.string "careplus_staff_code"

spec/factories/teams.rb

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,30 @@
44
#
55
# Table name: teams
66
#
7-
# id :bigint not null, primary key
8-
# careplus_namespace :string
9-
# careplus_password :string
10-
# careplus_staff_code :string
11-
# careplus_staff_type :string
12-
# careplus_username :string
13-
# careplus_venue_code :string
14-
# days_before_consent_reminders :integer default(7), not null
15-
# days_before_consent_requests :integer default(21), not null
16-
# email :string
17-
# name :text not null
18-
# national_reporting_cut_off_date :date
19-
# phone :string
20-
# phone_instructions :string
21-
# privacy_notice_url :string
22-
# privacy_policy_url :string
23-
# programme_types :enum not null, is an Array
24-
# type :integer not null
25-
# workgroup :string not null
26-
# created_at :datetime not null
27-
# updated_at :datetime not null
28-
# organisation_id :bigint not null
29-
# reply_to_id :uuid
7+
# id :bigint not null, primary key
8+
# careplus_automated_reports_enabled_at :datetime
9+
# careplus_namespace :string
10+
# careplus_password :string
11+
# careplus_staff_code :string
12+
# careplus_staff_type :string
13+
# careplus_username :string
14+
# careplus_venue_code :string
15+
# days_before_consent_reminders :integer default(7), not null
16+
# days_before_consent_requests :integer default(21), not null
17+
# email :string
18+
# name :text not null
19+
# national_reporting_cut_off_date :date
20+
# phone :string
21+
# phone_instructions :string
22+
# privacy_notice_url :string
23+
# privacy_policy_url :string
24+
# programme_types :enum not null, is an Array
25+
# type :integer not null
26+
# workgroup :string not null
27+
# created_at :datetime not null
28+
# updated_at :datetime not null
29+
# organisation_id :bigint not null
30+
# reply_to_id :uuid
3031
#
3132
# Indexes
3233
#
@@ -93,6 +94,7 @@
9394
end
9495

9596
trait :with_careplus_enabled do
97+
careplus_automated_reports_enabled_at { Time.current }
9698
careplus_namespace { "MOCK" }
9799
careplus_staff_code { "LW5PM" }
98100
careplus_staff_type { "IN" }

spec/models/team_spec.rb

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,30 @@
44
#
55
# Table name: teams
66
#
7-
# id :bigint not null, primary key
8-
# careplus_namespace :string
9-
# careplus_password :string
10-
# careplus_staff_code :string
11-
# careplus_staff_type :string
12-
# careplus_username :string
13-
# careplus_venue_code :string
14-
# days_before_consent_reminders :integer default(7), not null
15-
# days_before_consent_requests :integer default(21), not null
16-
# email :string
17-
# name :text not null
18-
# national_reporting_cut_off_date :date
19-
# phone :string
20-
# phone_instructions :string
21-
# privacy_notice_url :string
22-
# privacy_policy_url :string
23-
# programme_types :enum not null, is an Array
24-
# type :integer not null
25-
# workgroup :string not null
26-
# created_at :datetime not null
27-
# updated_at :datetime not null
28-
# organisation_id :bigint not null
29-
# reply_to_id :uuid
7+
# id :bigint not null, primary key
8+
# careplus_automated_reports_enabled_at :datetime
9+
# careplus_namespace :string
10+
# careplus_password :string
11+
# careplus_staff_code :string
12+
# careplus_staff_type :string
13+
# careplus_username :string
14+
# careplus_venue_code :string
15+
# days_before_consent_reminders :integer default(7), not null
16+
# days_before_consent_requests :integer default(21), not null
17+
# email :string
18+
# name :text not null
19+
# national_reporting_cut_off_date :date
20+
# phone :string
21+
# phone_instructions :string
22+
# privacy_notice_url :string
23+
# privacy_policy_url :string
24+
# programme_types :enum not null, is an Array
25+
# type :integer not null
26+
# workgroup :string not null
27+
# created_at :datetime not null
28+
# updated_at :datetime not null
29+
# organisation_id :bigint not null
30+
# reply_to_id :uuid
3031
#
3132
# Indexes
3233
#
@@ -175,6 +176,11 @@
175176
create(:team, :with_careplus_enabled, careplus_username: nil)
176177
create(:team, :with_careplus_enabled, careplus_password: nil)
177178
create(:team, :with_careplus_enabled, careplus_namespace: nil)
179+
create(
180+
:team,
181+
:with_careplus_enabled,
182+
careplus_automated_reports_enabled_at: nil
183+
)
178184
create(
179185
:team,
180186
careplus_username: "careplus_user",
@@ -208,6 +214,24 @@
208214
end
209215
end
210216

217+
describe "#has_careplus_credentials?" do
218+
subject(:has_careplus_credentials?) { team.has_careplus_credentials? }
219+
220+
context "when CarePlus credentials are configured" do
221+
let(:team) { create(:team, :with_careplus_enabled) }
222+
223+
it { should be(true) }
224+
end
225+
226+
context "when CarePlus credentials are missing" do
227+
let(:team) do
228+
create(:team, :with_careplus_enabled, careplus_username: nil)
229+
end
230+
231+
it { should be(false) }
232+
end
233+
end
234+
211235
describe "#eligible_for_automated_careplus_reports?" do
212236
subject(:eligible_for_automated_careplus_reports?) do
213237
team.eligible_for_automated_careplus_reports?
@@ -227,6 +251,18 @@
227251
it { should be(false) }
228252
end
229253

254+
context "when CarePlus integration has not been enabled yet" do
255+
let(:team) do
256+
create(
257+
:team,
258+
:with_careplus_enabled,
259+
careplus_automated_reports_enabled_at: nil
260+
)
261+
end
262+
263+
it { should be(false) }
264+
end
265+
230266
context "when CarePlus export fields are missing" do
231267
let(:team) do
232268
create(

0 commit comments

Comments
 (0)