Skip to content

Commit e66c33a

Browse files
committed
Ensure clinic records are included in school session offline exports
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.
1 parent 3ddeba6 commit e66c33a

File tree

2 files changed

+123
-43
lines changed

2 files changed

+123
-43
lines changed

app/lib/reports/offline_session_exporter.rb

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -81,48 +81,46 @@ 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_urn
90-
school_name
91-
care_setting
92-
person_dob
93-
year_group
94-
person_gender_code
95-
person_address_line_1
96-
person_postcode
97-
nhs_number
98-
consent_status
99-
consent_details
100-
health_question_answers
101-
triage_status
102-
triaged_by
103-
triage_date
104-
triage_notes
105-
gillick_status
106-
gillick_assessment_date
107-
gillick_assessed_by
108-
gillick_assessment_notes
109-
vaccinated
110-
date_of_vaccination
111-
time_of_vaccination
112-
programme
113-
vaccine_given
114-
performing_professional_email
115-
batch_number
116-
batch_expiry_date
117-
anatomical_site
118-
dose_sequence
119-
reason_not_vaccinated
120-
notes
121-
session_id
122-
uuid
123-
].tap do |values|
124-
values.insert(6, :clinic_name) if location.generic_clinic?
125-
end
84+
@columns ||= %i[
85+
person_forename
86+
person_surname
87+
organisation_code
88+
school_urn
89+
school_name
90+
clinic_name
91+
care_setting
92+
person_dob
93+
year_group
94+
person_gender_code
95+
person_address_line_1
96+
person_postcode
97+
nhs_number
98+
consent_status
99+
consent_details
100+
health_question_answers
101+
triage_status
102+
triaged_by
103+
triage_date
104+
triage_notes
105+
gillick_status
106+
gillick_assessment_date
107+
gillick_assessed_by
108+
gillick_assessment_notes
109+
vaccinated
110+
date_of_vaccination
111+
time_of_vaccination
112+
programme
113+
vaccine_given
114+
performing_professional_email
115+
batch_number
116+
batch_expiry_date
117+
anatomical_site
118+
dose_sequence
119+
reason_not_vaccinated
120+
notes
121+
session_id
122+
uuid
123+
]
126124
end
127125

128126
def patient_sessions

spec/lib/reports/offline_session_exporter_spec.rb

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def validation_formula(worksheet:, column_name:, row: 1)
5858
ORGANISATION_CODE
5959
SCHOOL_URN
6060
SCHOOL_NAME
61+
CLINIC_NAME
6162
CARE_SETTING
6263
PERSON_DOB
6364
YEAR_GROUP
@@ -116,6 +117,7 @@ def validation_formula(worksheet:, column_name:, row: 1)
116117
"BATCH_EXPIRY_DATE" => nil,
117118
"BATCH_NUMBER" => "",
118119
"CARE_SETTING" => 1,
120+
"CLINIC_NAME" => "",
119121
"CONSENT_DETAILS" => "",
120122
"CONSENT_STATUS" => "",
121123
"DATE_OF_VACCINATION" => nil,
@@ -193,6 +195,7 @@ def validation_formula(worksheet:, column_name:, row: 1)
193195
"ANATOMICAL_SITE" => "left upper arm",
194196
"BATCH_NUMBER" => batch.name,
195197
"CARE_SETTING" => 1,
198+
"CLINIC_NAME" => "",
196199
"CONSENT_DETAILS" => "",
197200
"CONSENT_STATUS" => "",
198201
"DOSE_SEQUENCE" => 1,
@@ -281,6 +284,7 @@ def validation_formula(worksheet:, column_name:, row: 1)
281284
"ANATOMICAL_SITE" => "left upper arm",
282285
"BATCH_NUMBER" => batch.name,
283286
"CARE_SETTING" => nil,
287+
"CLINIC_NAME" => "",
284288
"CONSENT_DETAILS" => "",
285289
"CONSENT_STATUS" => "",
286290
"DOSE_SEQUENCE" => 1,
@@ -322,6 +326,83 @@ def validation_formula(worksheet:, column_name:, row: 1)
322326
end
323327
end
324328

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

@@ -346,6 +427,7 @@ def validation_formula(worksheet:, column_name:, row: 1)
346427
"BATCH_EXPIRY_DATE" => nil,
347428
"BATCH_NUMBER" => nil,
348429
"CARE_SETTING" => 1,
430+
"CLINIC_NAME" => "",
349431
"CONSENT_DETAILS" => "",
350432
"CONSENT_STATUS" => "",
351433
"DOSE_SEQUENCE" => "",
@@ -497,8 +579,8 @@ def validation_formula(worksheet:, column_name:, row: 1)
497579
ORGANISATION_CODE
498580
SCHOOL_URN
499581
SCHOOL_NAME
500-
CARE_SETTING
501582
CLINIC_NAME
583+
CARE_SETTING
502584
PERSON_DOB
503585
YEAR_GROUP
504586
PERSON_GENDER_CODE

0 commit comments

Comments
 (0)