Skip to content

Commit 6774df9

Browse files
authored
Merge pull request #4321 from nhsuk/systm-one-no-location
Handle `nil` vaccination record location
2 parents 0c5bf08 + 5a9f91d commit 6774df9

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

app/lib/reports/systm_one_exporter.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ def vaccination_records
8989
.administered
9090
.where(programme:)
9191
.for_academic_year(academic_year)
92-
.includes(:batch, :location, :vaccine, :patient, :performed_by_user)
92+
.includes(
93+
:batch,
94+
:location,
95+
:patient,
96+
:performed_by_user,
97+
:session,
98+
:vaccine
99+
)
93100

94101
if start_date.present?
95102
scope =
@@ -148,11 +155,19 @@ def row(vaccination_record:)
148155
]
149156
end
150157

151-
# TODO: Needs support for community and generic clinics.
152158
def practice_code(vaccination_record)
153159
location = vaccination_record.location
154160

155-
location.school? ? location.urn : location.ods_code
161+
if location&.school?
162+
location.urn
163+
elsif location
164+
location.ods_code
165+
else
166+
# TODO: Needs support for generic clinics. The `location_id` is
167+
# `nil` but `location_name` is a human-readable string, so we
168+
# have no choice but to use the location of the session.
169+
vaccination_record.session.location.ods_code
170+
end
156171
end
157172

158173
def gender_code(code)

spec/factories/vaccination_records.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
uuid { SecureRandom.uuid }
104104

105105
location { session&.location unless session&.generic_clinic? }
106-
location_name { "Unknown" if session.nil? }
106+
location_name { "Unknown" if location.nil? }
107107

108108
notify_parents { true }
109109

spec/lib/reports/systm_one_exporter_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,15 @@
149149
subject { csv_row["Practice code"] }
150150

151151
context "location is a gp clinic" do
152-
let(:location) { create(:gp_practice) }
152+
let(:location) { create(:gp_practice, team:) }
153153

154-
it { should eq location.ods_code }
154+
it { should eq(location.ods_code) }
155+
end
156+
157+
context "location is a generic clinic" do
158+
let(:location) { create(:generic_clinic, team:) }
159+
160+
it { should eq(location.ods_code) }
155161
end
156162
end
157163

0 commit comments

Comments
 (0)