Skip to content

Commit 8eabac5

Browse files
authored
Merge pull request #4202 from nhsuk/cli-generate-cohort-import-updates
Update cohort import filename
2 parents 30b3878 + afb2368 commit 8eabac5

File tree

3 files changed

+76
-6
lines changed

3 files changed

+76
-6
lines changed

app/lib/mavis_cli/generate/cohort_imports.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,25 @@ class CohortImports < Dry::CLI::Command
1111
required: true,
1212
default: 10,
1313
desc: "Number of patients to create"
14+
option :ods_code,
15+
type: :string,
16+
default: "A9A5A",
17+
desc: "ODS code of the organisation to use for the cohort import"
1418

15-
def call(patients:)
19+
def call(patients:, ods_code:)
1620
MavisCLI.load_rails
1721

1822
patient_count = patients.to_i
19-
puts "Generating cohort import with #{patient_count} patients..."
2023
progress_bar = MavisCLI.progress_bar(patient_count)
2124

25+
puts "Generating cohort import for ods code #{ods_code} with" \
26+
" #{patient_count} patients..."
27+
2228
result =
2329
::Generate::CohortImports.call(
24-
patient_count: patient_count,
25-
progress_bar: progress_bar
30+
ods_code:,
31+
patient_count:,
32+
progress_bar:
2633
)
2734

2835
puts "\nCohort import CSV generated: #{result}"

lib/generate/cohort_imports.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,19 @@ def patients
7474
delegate :organisation, to: :team
7575

7676
def cohort_import_csv_filepath
77+
timestamp = Time.current.strftime("%Y%m%d%H%M%S")
78+
size =
79+
ActiveSupport::NumberHelper.number_to_human(
80+
@patient_count,
81+
units: {
82+
thousand: "k",
83+
million: "m"
84+
},
85+
format: "%n%u"
86+
)
7787
Rails.root.join(
78-
"tmp/perf-test-cohort-import-#{organisation.ods_code}-#{programme.type}.csv"
88+
"tmp/cohort-import-" \
89+
"#{organisation.ods_code}-#{programme.type}-#{size}-#{timestamp}.csv"
7990
)
8091
end
8192

@@ -174,7 +185,7 @@ def build_patient
174185
end
175186
end
176187

177-
def date_of_birth_for_year(year_group, academic_year: AcademicYear.current)
188+
def date_of_birth_for_year(year_group, academic_year: AcademicYear.pending)
178189
if year_group < 12
179190
rand(
180191
year_group.to_birth_academic_year(
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# frozen_string_literal: true
2+
3+
describe "mavis generate cohort-imports" do
4+
it "generates a cohort import CSV file" do
5+
given_an_organisation_exists
6+
and_there_are_three_sessions_in_the_organisation
7+
when_i_run_the_generate_cohort_imports_command
8+
then_a_cohort_import_csv_file_is_created
9+
end
10+
11+
def given_an_organisation_exists
12+
@programme = Programme.hpv.first || create(:programme, :hpv)
13+
@organisation = create(:organisation, ods_code: "R1Y")
14+
end
15+
16+
def and_there_are_three_sessions_in_the_organisation
17+
@sessions =
18+
create_list(
19+
:session,
20+
3,
21+
organisation: @organisation,
22+
programmes: [@programme]
23+
)
24+
end
25+
26+
def when_i_run_the_generate_cohort_imports_command
27+
freeze_time do
28+
@output =
29+
capture_output do
30+
Dry::CLI.new(MavisCLI).call(
31+
arguments: %w[generate cohort-imports -o R1Y -p 100]
32+
)
33+
end
34+
@timestamp = Time.current.strftime("%Y%m%d%H%M%S")
35+
end
36+
end
37+
38+
def then_a_cohort_import_csv_file_is_created
39+
expect(@output).to include(
40+
"Generating cohort import for ods code R1Y with 100 patients"
41+
)
42+
expect(@output).to match(
43+
/Cohort import CSV generated:.*cohort-import-R1Y-hpv-100-#{@timestamp}.csv/
44+
)
45+
46+
expect(
47+
File.readlines(
48+
Rails.root.join("tmp", "cohort-import-R1Y-hpv-100-#{@timestamp}.csv")
49+
).length
50+
).to eq 101
51+
end
52+
end

0 commit comments

Comments
 (0)