Skip to content

Commit ce8149e

Browse files
committed
Only include programmes in the CareplusExport if they exist in the export
* Makes this more clear to teams when viewed in the UI * Requires allowing this field to be empty in CareplusExport Jira-Issue: Mav-5742
1 parent 3808119 commit ce8149e

4 files changed

Lines changed: 10 additions & 8 deletions

File tree

app/lib/mavis_cli/reports/export_automated_careplus.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ def call(
108108
**scope_args
109109
)
110110

111+
programme_types =
112+
records.unscope(:order).distinct.pluck(:programme_type)
113+
111114
csv = ::Reports::AutomatedCareplusExporter.call(**scope_args)
112115

113116
now = Time.current
@@ -121,7 +124,7 @@ def call(
121124
academic_year: academic_year_value,
122125
date_from: parsed_start_date,
123126
date_to: parsed_end_date,
124-
programme_types: team.programme_types,
127+
programme_types:,
125128
scheduled_at: now,
126129
sent_at: now,
127130
status: :sent,

app/models/careplus_export.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class CareplusExport < ApplicationRecord
4444

4545
validates :academic_year, :scheduled_at, presence: true
4646
validates :date_from, :date_to, presence: true
47-
validates :programme_types, presence: true
4847
validates :date_to,
4948
comparison: {
5049
greater_than_or_equal_to: :date_from

spec/features/cli_reports_export_automated_careplus_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@
2626
date_from: Date.new(2025, 9, 1),
2727
date_to: Date.new(2026, 3, 10),
2828
status: "sent",
29-
csv_filename: File.basename(output_path)
29+
csv_filename: File.basename(output_path),
30+
programme_types: []
3031
)
3132
and_the_output_file_is_written
3233
and_the_success_message_is_displayed
3334
end
3435
end
3536

3637
context "when there are matching vaccination records" do
37-
it "links them to the export" do
38+
it "links them to the export and sets programme_types from the records" do
3839
given_an_organisation_with_a_single_team
3940
programme = Programme.hpv
4041
session = create(:session, team: @team, programmes: [programme])
@@ -45,9 +46,9 @@
4546
"--output=#{output_path}"
4647
)
4748

48-
expect(CareplusExport.last.vaccination_records).to include(
49-
vaccination_record
50-
)
49+
export = CareplusExport.last
50+
expect(export.vaccination_records).to include(vaccination_record)
51+
expect(export.programme_types).to eq([programme.type])
5152
end
5253
end
5354

spec/models/careplus_export_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
it { should validate_presence_of(:scheduled_at) }
5656
it { should validate_presence_of(:date_from) }
5757
it { should validate_presence_of(:date_to) }
58-
it { should validate_presence_of(:programme_types) }
5958

6059
describe "date_from_must_precede_date_to" do
6160
context "when date_to is before date_from" do

0 commit comments

Comments
 (0)