Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions app/lib/reports/systm_one_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ def vaccination_records
.administered
.where(programme:)
.for_academic_year(academic_year)
.includes(:batch, :location, :vaccine, :patient, :performed_by_user)
.includes(
:batch,
:location,
:patient,
:performed_by_user,
:session,
:vaccine
)

if start_date.present?
scope =
Expand Down Expand Up @@ -148,11 +155,19 @@ def row(vaccination_record:)
]
end

# TODO: Needs support for community and generic clinics.
def practice_code(vaccination_record)
location = vaccination_record.location

location.school? ? location.urn : location.ods_code
if location&.school?
location.urn
elsif location
location.ods_code
else
# TODO: Needs support for generic clinics. The `location_id` is
# `nil` but `location_name` is a human-readable string, so we
# have no choice but to use the location of the session.
vaccination_record.session.location.ods_code
end
end

def gender_code(code)
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/vaccination_records.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
uuid { SecureRandom.uuid }

location { session&.location unless session&.generic_clinic? }
location_name { "Unknown" if session.nil? }
location_name { "Unknown" if location.nil? }

notify_parents { true }

Expand Down
10 changes: 8 additions & 2 deletions spec/lib/reports/systm_one_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,15 @@
subject { csv_row["Practice code"] }

context "location is a gp clinic" do
let(:location) { create(:gp_practice) }
let(:location) { create(:gp_practice, team:) }

it { should eq location.ods_code }
it { should eq(location.ods_code) }
end

context "location is a generic clinic" do
let(:location) { create(:generic_clinic, team:) }

it { should eq(location.ods_code) }
end
end

Expand Down