Skip to content

Commit 5e98cfc

Browse files
committed
Handle nil vaccination record location
In the SystmOne exporter. This situation can occur if a vaccination is recorded in the community clinic, where the `location` will be `nil`, and the `location_name` will be set instead. This change was made in aae7b83, previously vaccination records in the generic clinic would have a location of the generic clinic, but we want to move to a world where the location is the specific community clinic where the record took place. This error was spotted by the regression tests and fixes this Sentry error: https://good-machine.sentry.io/issues/6818602795/
1 parent 4d45ddd commit 5e98cfc

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 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)