Skip to content

Commit 37c882d

Browse files
committed
Use workgroup as team identifier
This updates various places where the team was being identified by the ODS code of it's organisation to the workgroup. This is because a single organisation can have multiple teams, and the workgroup is the way of identifying them individually. Jira-Issue: MAV-1280
1 parent 0c5da35 commit 37c882d

21 files changed

+78
-169
lines changed

app/controllers/api/testing/teams_controller.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ def destroy
99

1010
keep_itself = ActiveModel::Type::Boolean.new.cast(params[:keep_itself])
1111

12-
# TODO: Select the right team based on an identifier.
13-
team =
14-
Team.joins(:organisation).find_by!(
15-
organisation: {
16-
ods_code: params[:ods_code]
17-
}
18-
)
12+
team = Team.find_by!(workgroup: params[:workgroup])
1913

2014
@start_time = Time.zone.now
2115

app/lib/mavis_cli/clinics/add_to_team.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,17 @@ module Clinics
55
class AddToTeam < Dry::CLI::Command
66
desc "Add an existing clinic to a team"
77

8-
argument :team_ods_code, required: true, desc: "The ODS code of the team"
8+
argument :workgroup, required: true, desc: "The ODS code of the team"
99
argument :subteam, required: true, desc: "The subteam of the team"
10-
argument :clinic_ods_codes,
10+
argument :ods_codes,
1111
type: :array,
1212
required: true,
1313
desc: "The ODS codes of the clinics"
1414

15-
def call(team_ods_code:, subteam:, clinic_ods_codes:, **)
15+
def call(workgroup:, subteam:, ods_codes:, **)
1616
MavisCLI.load_rails
1717

18-
# TODO: Select the right team based on an identifier.
19-
team =
20-
Team.joins(:organisation).find_by(
21-
organisation: {
22-
ods_code: team_ods_code
23-
}
24-
)
18+
team = Team.find_by(workgroup:)
2519

2620
if team.nil?
2721
warn "Could not find team."
@@ -36,7 +30,7 @@ def call(team_ods_code:, subteam:, clinic_ods_codes:, **)
3630
end
3731

3832
ActiveRecord::Base.transaction do
39-
clinic_ods_codes.each do |ods_code|
33+
ods_codes.each do |ods_code|
4034
location = Location.clinic.find_by(ods_code:)
4135

4236
if location.nil?

app/lib/mavis_cli/generate/consents.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ module MavisCLI
66
module Generate
77
class Consents < Dry::CLI::Command
88
desc "Generate consents"
9-
option :team,
10-
aliases: ["-o"],
9+
option :team_workgroup,
10+
aliases: ["-w"],
1111
default: "A9A5A",
12-
desc: "ODS code of team to generate consents for"
12+
desc: "Workgroup of team to generate consents for"
1313
option :programme_type,
1414
aliases: ["-p"],
1515
default: "hpv",
@@ -33,7 +33,7 @@ class Consents < Dry::CLI::Command
3333
desc: "Number of refused consents to create"
3434

3535
def call(
36-
team:,
36+
team_workgroup:,
3737
programme_type:,
3838
given:,
3939
needing_triage:,
@@ -46,9 +46,7 @@ def call(
4646
session = Session.find(session_id) if session_id
4747

4848
::Generate::Consents.call(
49-
# TODO: Select the right team based on an identifier.
50-
team:
51-
Team.joins(:organisation).find_by(organisation: { ods_code: team }),
49+
team: Team.find_by(workgroup: team_workgroup),
5250
programme: Programme.find_by(type: programme_type),
5351
session:,
5452
given: given.to_i,

app/lib/mavis_cli/generate/vaccination_records.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ module MavisCLI
44
module Generate
55
class VaccinationRecords < Dry::CLI::Command
66
desc "Generate vaccination records (and attendances if required)"
7-
option :team,
8-
aliases: ["-o"],
7+
option :team_workgroup,
8+
aliases: ["-w"],
99
default: "A9A5A",
10-
desc: "ODS code of team to generate consents for"
10+
desc: "Workgroup of team to generate consents for"
1111
option :programme_type,
1212
aliases: ["-p"],
1313
default: "hpv",
@@ -23,15 +23,19 @@ class VaccinationRecords < Dry::CLI::Command
2323
aliases: ["-A"],
2424
desc: "Number of administered vaccination records to create"
2525

26-
def call(team:, programme_type:, administered:, session_id: nil, **)
26+
def call(
27+
team_workgroup:,
28+
programme_type:,
29+
administered:,
30+
session_id: nil,
31+
**
32+
)
2733
MavisCLI.load_rails
2834

2935
session = Session.find(session_id) if session_id
3036

3137
::Generate::VaccinationRecords.call(
32-
# TODO: Select the right team based on an identifier.
33-
team:
34-
Team.joins(:organisation).find_by(organisation: { ods_code: team }),
38+
team: Team.find_by(workgroup: team_workgroup),
3539
programme: Programme.includes(:teams).find_by(type: programme_type),
3640
session:,
3741
administered: administered.to_i

app/lib/mavis_cli/schools/add_to_team.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Schools
55
class AddToTeam < Dry::CLI::Command
66
desc "Add an existing school to a team"
77

8-
argument :ods_code, required: true, desc: "The ODS code of the team"
8+
argument :workgroup, required: true, desc: "The ODS code of the team"
99
argument :subteam, required: true, desc: "The subteam of the team"
1010
argument :urns,
1111
type: :array,
@@ -16,11 +16,10 @@ class AddToTeam < Dry::CLI::Command
1616
type: :array,
1717
desc: "The programmes administered at the school"
1818

19-
def call(ods_code:, subteam:, urns:, programmes: [], **)
19+
def call(workgroup:, subteam:, urns:, programmes: [], **)
2020
MavisCLI.load_rails
2121

22-
# TODO: Select the right team based on an identifier.
23-
team = Team.joins(:organisation).find_by(organisation: { ods_code: })
22+
team = Team.find_by(workgroup:)
2423

2524
if team.nil?
2625
warn "Could not find team."

app/lib/mavis_cli/teams/add_programme.rb

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,14 @@ module Teams
55
class AddProgramme < Dry::CLI::Command
66
desc "Adds a programme to a team"
77

8-
argument :ods_code,
9-
required: true,
10-
desc: "The ODS code of the organisation"
11-
12-
argument :name, required: true, desc: "The name of the team"
8+
argument :workgroup, required: true, desc: "The workgroup of the team"
139

1410
argument :type, required: true, desc: "The type of programme to add"
1511

16-
def call(ods_code:, name:, type:)
12+
def call(workgroup:, type:)
1713
MavisCLI.load_rails
1814

19-
organisation = Organisation.find_by(ods_code:)
20-
21-
if organisation.nil?
22-
warn "Could not find organisation."
23-
return
24-
end
25-
26-
team = organisation.teams.find_by(name:)
15+
team = Team.find_by(workgroup:)
2716

2817
if team.nil?
2918
warn "Could not find team."

app/lib/mavis_cli/teams/create_sessions.rb

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,16 @@ module Teams
55
class CreateSessions < Dry::CLI::Command
66
desc "Create sessions for all locations"
77

8-
argument :ods_code,
9-
required: true,
10-
desc: "The ODS code of the organisation"
11-
12-
argument :name, required: true, desc: "The name of the team"
8+
argument :workgroup, required: true, desc: "The workgroup of the team"
139

1410
option :academic_year,
1511
type: :integer,
1612
desc: "The academic year to create the sessions for"
1713

18-
def call(ods_code:, name:, academic_year: nil)
14+
def call(workgroup:, academic_year: nil)
1915
MavisCLI.load_rails
2016

21-
organisation = Organisation.find_by(ods_code:)
22-
23-
if organisation.nil?
24-
warn "Could not find organisation."
25-
return
26-
end
27-
28-
team = organisation.teams.find_by(name:)
17+
team = Team.find_by(workgroup:)
2918

3019
if team.nil?
3120
warn "Could not find team."

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
unless Rails.env.production?
9191
namespace :testing do
9292
resources :locations, only: :index
93-
resources :teams, only: :destroy, param: :ods_code
93+
resources :teams, only: :destroy, param: :workgroup
9494
post "/onboard", to: "onboard#create"
9595
end
9696
end

db/seeds.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ def create_gp_practices
2020
end
2121

2222
def create_team(ods_code:)
23-
# TODO: Select the right team based on an identifier.
24-
Team.joins(:organisation).find_by(organisation: { ods_code: }) ||
23+
workgroup = ods_code.downcase
24+
25+
Team.find_by(workgroup:) ||
2526
FactoryBot.create(
2627
:team,
2728
:with_generic_clinic,
2829
ods_code:,
29-
programmes: Programme.all
30+
programmes: Programme.all,
31+
workgroup:
3032
)
3133
end
3234

lib/generate/cohort_imports.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ class CohortImports
4141
:progress_bar
4242

4343
def initialize(
44-
ods_code: "A9A5A",
44+
team_workgroup: "A9A5A",
4545
programme: "hpv",
4646
urns: nil,
4747
school_year_groups: nil,
4848
patient_count: 10,
4949
progress_bar: nil
5050
)
51-
# TODO: Select the right team based on an identifier.
52-
@team = Team.joins(:organisation).find_by(organisation: { ods_code: })
51+
@team = Team.find_by(workgroup: team_workgroup)
5352
@programme = Programme.find_by(type: programme)
5453
@urns =
5554
urns || @team.locations.select { it.urn.present? }.sample(3).pluck(:urn)

0 commit comments

Comments
 (0)