Skip to content

Commit 422e5c3

Browse files
authored
Merge pull request #3901 from nhsuk/improve-test-patient-creation
Add progress bar to the CLI command `mavis generate cohort-imports`
2 parents f387d2f + a7a5abf commit 422e5c3

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

app/lib/mavis_cli/generate/cohort_imports.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ class CohortImports < Dry::CLI::Command
1515
def call(patients:)
1616
MavisCLI.load_rails
1717

18-
::Generate::CohortImports.call(patient_count: patients.to_i)
18+
patient_count = patients.to_i
19+
puts "Generating cohort import with #{patient_count} patients..."
20+
progress_bar = MavisCLI.progress_bar(patient_count)
21+
22+
result =
23+
::Generate::CohortImports.call(
24+
patient_count: patient_count,
25+
progress_bar: progress_bar
26+
)
27+
28+
puts "\nCohort import CSV generated: #{result}"
1929
end
2030
end
2131
end

lib/generate/cohort_imports.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ class CohortImports
3636
:programme,
3737
:urns,
3838
:patient_count,
39-
:school_year_groups
39+
:school_year_groups,
40+
:progress_bar
4041

4142
def initialize(
4243
ods_code: "A9A5A",
4344
programme: "hpv",
4445
urns: nil,
4546
school_year_groups: nil,
46-
patient_count: 10
47+
patient_count: 10,
48+
progress_bar: nil
4749
)
4850
@organisation = Organisation.find_by(ods_code:)
4951
@programme = Programme.find_by(type: programme)
@@ -56,6 +58,7 @@ def initialize(
5658
.pluck(:urn)
5759
@school_year_groups = school_year_groups
5860
@patient_count = patient_count
61+
@progress_bar = progress_bar
5962
@nhs_numbers = Set.new
6063
end
6164

@@ -121,6 +124,7 @@ def write_cohort_import_csv
121124
patient.parent_relationships.second&.type,
122125
patient.school.urn
123126
]
127+
progress_bar&.increment
124128
end
125129
end
126130
cohort_import_csv_filepath.to_s

0 commit comments

Comments
 (0)