Skip to content

Commit 31555f1

Browse files
authored
Merge pull request #4006 from nhsuk/add-to-organisation-programmes
Add programmes option to `add-to-organisation`
2 parents ff9b3ec + 00c19b9 commit 31555f1

6 files changed

Lines changed: 146 additions & 58 deletions

File tree

app/lib/mavis_cli/schools/add_to_organisation.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ class AddToOrganisation < Dry::CLI::Command
1414
required: true,
1515
desc: "The URN of the school"
1616

17-
def call(ods_code:, team:, urns:, **)
17+
option :programmes,
18+
type: :array,
19+
desc: "The programmes administered at the school"
20+
21+
def call(ods_code:, team:, urns:, programmes: [], **)
1822
organisation = Organisation.find_by(ods_code:)
1923

2024
if organisation.nil?
@@ -29,6 +33,13 @@ def call(ods_code:, team:, urns:, **)
2933
return
3034
end
3135

36+
programmes =
37+
if programmes.empty?
38+
organisation.programmes
39+
else
40+
Programme.where(type: programmes)
41+
end
42+
3243
ActiveRecord::Base.transaction do
3344
urns.each do |urn|
3445
location = Location.school.find_by(urn:)
@@ -43,9 +54,7 @@ def call(ods_code:, team:, urns:, **)
4354
end
4455

4556
location.update!(team:)
46-
location.create_default_programme_year_groups!(
47-
organisation.programmes
48-
)
57+
location.create_default_programme_year_groups!(programmes)
4958
end
5059
end
5160

app/models/location.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Location < ApplicationRecord
4949
has_many :sessions
5050

5151
has_one :organisation, through: :team
52+
has_many :programmes, -> { distinct }, through: :programme_year_groups
5253

5354
# This is based on the school statuses from the DfE GIAS data.
5455
enum :status,

docs/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Gets locations held by the service.
3535

3636
### Body
3737

38-
See [onboarding documentation](onboarding.md).
38+
See [onboarding documentation](managing-teams.md).
3939

4040
## `DELETE /organisations/:ods_code`
4141

docs/managing-teams.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Managing teams
2+
3+
Each SAIS team in Mavis will have their own set of schools, programmes they administer, and in some cases which schools they administer the programmes to and in which year groups.
4+
5+
## Onboarding for the first time
6+
7+
When first onboarding a new SAIS team, there’s a lot of information to include about it. The process involves creating a YAML file containing all the information about the organisation and using the `onboard` Rake task to add everything in to the service.
8+
9+
### Configuration file structure
10+
11+
```yaml
12+
organisation:
13+
name: # Unique name of the organisation
14+
email: # Contact email address
15+
phone: # Contact phone number
16+
ods_code: # Unique ODS code
17+
careplus_venue_code: # Venue code used in CarePlus exports
18+
privacy_notice_url: # URL of a privacy notice shown to parents
19+
privacy_policy_url: # URL of a privacy policy shown to parents
20+
reply_to_id: # Optional GOV.UK Notify Reply-To UUID
21+
22+
programmes: [] # A list of programmes (flu, hpv, menacwy, td_ipv)
23+
24+
teams:
25+
team1: # Identifier to link team with school and links below, not used in app
26+
name: # Name of the team
27+
email: # Contact email address
28+
phone: # Contact phone number
29+
reply_to_id: # Optional GOV.UK Notify Reply-To UUID
30+
31+
schools:
32+
team1: [] # URNs managed by a particular team
33+
34+
clinics:
35+
team1:
36+
- name: # Name of the clinic
37+
address_line_1: # First line of the address
38+
address_town: # Town of the address
39+
address_postcode: # Postcode of the address
40+
ods_code: # Unique ODS code
41+
```
42+
43+
[Example configuration files can be found in the repo][config-onboarding].
44+
45+
[config-onboarding]: /config/onboarding
46+
47+
### Rake task
48+
49+
Once the file has been written you can use the `onboard` Rake task to set everything up in the service.
50+
51+
```sh
52+
$ bundle exec rails onboard[path/to/configuration.yaml]
53+
```
54+
55+
If any validation errors are detected in the file they will be output and nothing will be processed, only if the file is completely valid will anything be processed.
56+
57+
## After onboarding
58+
59+
Once a team has been onboarding, the YAML configuration file can be deleted as it won’t be used again. Instead, a number of command line tools are provided for managing the team.
60+
61+
### Adding new schools to an organisation
62+
63+
The command `schools add-to-organisation` is provided to add new schools to an existing organisation.
64+
65+
```sh
66+
$ bin/mavis schools add-to-organisation ODS_CODE TEAM URNS
67+
```
68+
69+
- `ODS_CODE` refers to the ODS code of the organisation
70+
- `TEAM` refers to the name of the team in the organisation
71+
- `URNS` are the URNs of the schools to add
72+
73+
Optionally, it's also possible to customise which programmes are administered at a particular school:
74+
75+
```sh
76+
$ bin/mavis schools add-to-organisation ODS_CODE TEAM URNS --programmes VALUE1,VALUE2,...
77+
```
78+
79+
### Changing administered year groups of a school
80+
81+
Some SAIS teams will administer certain programmes to certain schools outside the normal year groups. For example, flu is often given at special education needs schools in years 12 and 13.
82+
83+
To modify the year groups per programme per school, the follow two commands are provided:
84+
85+
```sh
86+
$ bin/mavis schools add-programme-year-group URN PROGRAMME_TYPE YEAR_GROUPS
87+
$ bin/mavis schools remove-programme-year-group URN PROGRAMME_TYPE YEAR_GROUPS
88+
```
89+
90+
- `URN` refers to the URN of the school to edit
91+
- `PROGRAMME_TYPE` refers to the programme being edited
92+
- `YEAR_GROUPS` are the year groups to add or remove

docs/onboarding.md

Lines changed: 0 additions & 51 deletions
This file was deleted.

spec/features/cli_schools_add_to_organisation_spec.rb

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@
4040
end
4141
end
4242

43+
context "when customising the programmes" do
44+
it "runs successfully" do
45+
given_the_organisation_exists
46+
and_the_team_exists
47+
and_the_school_exists
48+
49+
when_i_run_the_command_with_flu_only
50+
then_the_school_is_added_to_the_organisation_with_flu_only
51+
end
52+
end
53+
4354
private
4455

4556
def command
@@ -48,22 +59,42 @@ def command
4859
)
4960
end
5061

62+
def command_with_flu_only
63+
Dry::CLI.new(MavisCLI).call(
64+
arguments: %w[
65+
schools
66+
add-to-organisation
67+
ABC
68+
Team
69+
123456
70+
--programmes
71+
flu
72+
]
73+
)
74+
end
75+
5176
def given_the_organisation_exists
52-
@organisation = create(:organisation, ods_code: "ABC")
77+
@programmes = [create(:programme, :flu), create(:programme, :hpv)]
78+
@organisation =
79+
create(:organisation, ods_code: "ABC", programmes: @programmes)
5380
end
5481

5582
def and_the_team_exists
5683
@team = create(:team, name: "Team", organisation: @organisation)
5784
end
5885

5986
def and_the_school_exists
60-
@school = create(:school, name: "School", urn: "123456", team: @team)
87+
@school = create(:school, name: "School", urn: "123456")
6188
end
6289

6390
def when_i_run_the_command
6491
@output = capture_error { command }
6592
end
6693

94+
def when_i_run_the_command_with_flu_only
95+
@output = capture_error { command_with_flu_only }
96+
end
97+
6798
def when_i_run_the_command_expecting_an_error
6899
@output = capture_error { command }
69100
end
@@ -82,5 +113,11 @@ def then_a_school_not_found_error_message_is_displayed
82113

83114
def then_the_school_is_added_to_the_organisation
84115
expect(@organisation.schools).to include(@school)
116+
expect(@school.programmes).to eq(@programmes)
117+
end
118+
119+
def then_the_school_is_added_to_the_organisation_with_flu_only
120+
expect(@organisation.schools).to include(@school)
121+
expect(@school.programmes).to contain_exactly(@programmes.first)
85122
end
86123
end

0 commit comments

Comments
 (0)