Skip to content

Commit c25ce5c

Browse files
authored
Ensure clinic records are included in school session offline exports (#3221)
When downloading the offline export for a school session, we include all vaccinations records for the patient to ensure the nurses can see all details about the patients. This means that some of those vaccination records may have come from a clinic, therefore when downloading the school spreadsheet we need to include `CLINIC_NAME` as a column to handle those records. https://good-machine.sentry.io/issues/6390050513/
2 parents 6bbdf80 + a08aa48 commit c25ce5c

File tree

2 files changed

+121
-42
lines changed

2 files changed

+121
-42
lines changed

app/lib/reports/offline_session_exporter.rb

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -81,47 +81,45 @@ def add_batch_numbers_sheets(package)
8181
end
8282

8383
def columns
84-
@columns ||=
85-
%i[
86-
person_forename
87-
person_surname
88-
organisation_code
89-
school_name
90-
care_setting
91-
person_dob
92-
year_group
93-
person_gender_code
94-
person_address_line_1
95-
person_postcode
96-
nhs_number
97-
consent_status
98-
consent_details
99-
health_question_answers
100-
triage_status
101-
triaged_by
102-
triage_date
103-
triage_notes
104-
gillick_status
105-
gillick_assessment_date
106-
gillick_assessed_by
107-
gillick_assessment_notes
108-
vaccinated
109-
date_of_vaccination
110-
time_of_vaccination
111-
programme
112-
vaccine_given
113-
performing_professional_email
114-
batch_number
115-
batch_expiry_date
116-
anatomical_site
117-
dose_sequence
118-
reason_not_vaccinated
119-
notes
120-
session_id
121-
uuid
122-
].tap do |values|
123-
values.insert(5, :clinic_name) if location.generic_clinic?
124-
end
84+
@columns ||= %i[
85+
person_forename
86+
person_surname
87+
organisation_code
88+
school_name
89+
clinic_name
90+
care_setting
91+
person_dob
92+
year_group
93+
person_gender_code
94+
person_address_line_1
95+
person_postcode
96+
nhs_number
97+
consent_status
98+
consent_details
99+
health_question_answers
100+
triage_status
101+
triaged_by
102+
triage_date
103+
triage_notes
104+
gillick_status
105+
gillick_assessment_date
106+
gillick_assessed_by
107+
gillick_assessment_notes
108+
vaccinated
109+
date_of_vaccination
110+
time_of_vaccination
111+
programme
112+
vaccine_given
113+
performing_professional_email
114+
batch_number
115+
batch_expiry_date
116+
anatomical_site
117+
dose_sequence
118+
reason_not_vaccinated
119+
notes
120+
session_id
121+
uuid
122+
]
125123
end
126124

127125
def patient_sessions

spec/lib/reports/offline_session_exporter_spec.rb

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def validation_formula(worksheet:, column_name:, row: 1)
5757
PERSON_SURNAME
5858
ORGANISATION_CODE
5959
SCHOOL_NAME
60+
CLINIC_NAME
6061
CARE_SETTING
6162
PERSON_DOB
6263
YEAR_GROUP
@@ -115,6 +116,7 @@ def validation_formula(worksheet:, column_name:, row: 1)
115116
"BATCH_EXPIRY_DATE" => nil,
116117
"BATCH_NUMBER" => "",
117118
"CARE_SETTING" => 1,
119+
"CLINIC_NAME" => "",
118120
"CONSENT_DETAILS" => "",
119121
"CONSENT_STATUS" => "",
120122
"DATE_OF_VACCINATION" => nil,
@@ -191,6 +193,7 @@ def validation_formula(worksheet:, column_name:, row: 1)
191193
"ANATOMICAL_SITE" => "left upper arm",
192194
"BATCH_NUMBER" => batch.name,
193195
"CARE_SETTING" => 1,
196+
"CLINIC_NAME" => "",
194197
"CONSENT_DETAILS" => "",
195198
"CONSENT_STATUS" => "",
196199
"DOSE_SEQUENCE" => 1,
@@ -278,6 +281,7 @@ def validation_formula(worksheet:, column_name:, row: 1)
278281
"ANATOMICAL_SITE" => "left upper arm",
279282
"BATCH_NUMBER" => batch.name,
280283
"CARE_SETTING" => nil,
284+
"CLINIC_NAME" => "",
281285
"CONSENT_DETAILS" => "",
282286
"CONSENT_STATUS" => "",
283287
"DOSE_SEQUENCE" => 1,
@@ -318,6 +322,82 @@ def validation_formula(worksheet:, column_name:, row: 1)
318322
end
319323
end
320324

325+
context "with a vaccinated patient outside the school session, but in a clinic" do
326+
let(:clinic_session) { organisation.generic_clinic_session }
327+
328+
let!(:vaccination_record) do
329+
create(
330+
:vaccination_record,
331+
performed_at:,
332+
batch:,
333+
patient:,
334+
session: clinic_session,
335+
programme:,
336+
performed_by: user,
337+
notes: "Some notes.",
338+
location_name: "Waterloo Hospital"
339+
)
340+
end
341+
342+
before do
343+
create(:patient_session, patient:, session:)
344+
create(:patient_session, patient:, session: clinic_session)
345+
end
346+
347+
it "adds a row with the vaccination details" do
348+
expect(rows.count).to eq(1)
349+
expect(
350+
rows.first.except(
351+
"BATCH_EXPIRY_DATE",
352+
"PERSON_DOB",
353+
"DATE_OF_VACCINATION"
354+
)
355+
).to eq(
356+
{
357+
"ANATOMICAL_SITE" => "left upper arm",
358+
"BATCH_NUMBER" => batch.name,
359+
"CARE_SETTING" => 2,
360+
"CLINIC_NAME" => "Waterloo Hospital",
361+
"CONSENT_DETAILS" => "",
362+
"CONSENT_STATUS" => "",
363+
"DOSE_SEQUENCE" => 1,
364+
"GILLICK_ASSESSED_BY" => nil,
365+
"GILLICK_ASSESSMENT_DATE" => nil,
366+
"GILLICK_ASSESSMENT_NOTES" => nil,
367+
"GILLICK_STATUS" => "",
368+
"HEALTH_QUESTION_ANSWERS" => "",
369+
"NHS_NUMBER" => patient.nhs_number,
370+
"NOTES" => "Some notes.",
371+
"ORGANISATION_CODE" => organisation.ods_code,
372+
"PERFORMING_PROFESSIONAL_EMAIL" => "nurse@example.com",
373+
"PERSON_ADDRESS_LINE_1" => patient.address_line_1,
374+
"PERSON_FORENAME" => patient.given_name,
375+
"PERSON_GENDER_CODE" => "Not known",
376+
"PERSON_POSTCODE" => patient.address_postcode,
377+
"PERSON_SURNAME" => patient.family_name,
378+
"PROGRAMME" => "HPV",
379+
"REASON_NOT_VACCINATED" => "",
380+
"SCHOOL_NAME" => "",
381+
"SESSION_ID" => clinic_session.id,
382+
"TIME_OF_VACCINATION" => "12:05:20",
383+
"TRIAGED_BY" => nil,
384+
"TRIAGE_DATE" => nil,
385+
"TRIAGE_NOTES" => nil,
386+
"TRIAGE_STATUS" => nil,
387+
"VACCINATED" => "Y",
388+
"VACCINE_GIVEN" => "Gardasil9",
389+
"UUID" => vaccination_record.uuid,
390+
"YEAR_GROUP" => patient.year_group
391+
}
392+
)
393+
expect(rows.first["BATCH_EXPIRY_DATE"].to_date).to eq(batch.expiry)
394+
expect(rows.first["PERSON_DOB"].to_date).to eq(patient.date_of_birth)
395+
expect(rows.first["DATE_OF_VACCINATION"].to_date).to eq(
396+
performed_at.to_date
397+
)
398+
end
399+
end
400+
321401
context "with a patient who couldn't be vaccinated" do
322402
before { create(:patient_session, patient:, session:) }
323403

@@ -342,6 +422,7 @@ def validation_formula(worksheet:, column_name:, row: 1)
342422
"BATCH_EXPIRY_DATE" => nil,
343423
"BATCH_NUMBER" => nil,
344424
"CARE_SETTING" => 1,
425+
"CLINIC_NAME" => "",
345426
"CONSENT_DETAILS" => "",
346427
"CONSENT_STATUS" => "",
347428
"DOSE_SEQUENCE" => "",
@@ -491,8 +572,8 @@ def validation_formula(worksheet:, column_name:, row: 1)
491572
PERSON_SURNAME
492573
ORGANISATION_CODE
493574
SCHOOL_NAME
494-
CARE_SETTING
495575
CLINIC_NAME
576+
CARE_SETTING
496577
PERSON_DOB
497578
YEAR_GROUP
498579
PERSON_GENDER_CODE

0 commit comments

Comments
 (0)