Skip to content

Commit 18d3f18

Browse files
committed
Import and export performing professional names
This stores the performing professional names on the vaccination record (if the information is available) and again exports it to DPS (if the information is available). These values must be provided by Flu, and may be provided for HPV.
1 parent 59ca549 commit 18d3f18

File tree

5 files changed

+142
-14
lines changed

5 files changed

+142
-14
lines changed

app/models/dps_export.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ def csv
3636
csv << DPSExportRow::FIELDS.map(&:upcase)
3737

3838
vaccination_records
39-
.includes(:batch, :location, :patient, :session, :team, :vaccine)
39+
.includes(
40+
:batch,
41+
:location,
42+
:patient,
43+
:performed_by_user,
44+
:session,
45+
:team,
46+
:vaccine
47+
)
4048
.order(:recorded_at)
4149
.strict_loading
4250
.find_each { csv << DPSExportRow.new(_1).to_a }

app/models/dps_export_row.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ def action_flag
108108
end
109109

110110
def performing_professional_forename
111-
# is not required
111+
vaccination_record.performed_by&.given_name
112112
end
113113

114114
def performing_professional_surname
115-
# is not required
115+
vaccination_record.performed_by&.family_name
116116
end
117117

118118
def recorded_date

app/models/immunisation_import_row.rb

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ class ImmunisationImportRow
6161
allow_nil: true
6262
validates :care_setting, presence: true, if: :requires_care_setting?
6363

64+
validates :performed_by_given_name,
65+
:performed_by_family_name,
66+
presence: true,
67+
if: :requires_performed_by?
68+
6469
def initialize(data:, campaign:, user:, imported_from:)
6570
@data = data
6671
@campaign = campaign
@@ -79,12 +84,14 @@ def to_vaccination_record
7984
recorded_at:
8085
).find_or_create_by!(
8186
administered_at:,
87+
batch:,
8288
delivery_method:,
8389
delivery_site:,
8490
dose_sequence:,
8591
patient_session:,
92+
performed_by_family_name:,
93+
performed_by_given_name:,
8694
reason:,
87-
batch:,
8895
vaccine:
8996
)
9097
end
@@ -261,6 +268,14 @@ def care_setting
261268
nil
262269
end
263270

271+
def performed_by_given_name
272+
@data["PERFORMING_PROFESSIONAL_FORENAME"]&.strip&.presence
273+
end
274+
275+
def performed_by_family_name
276+
@data["PERFORMING_PROFESSIONAL_SURNAME"]&.strip&.presence
277+
end
278+
264279
private
265280

266281
attr_reader :imported_from
@@ -348,7 +363,11 @@ def campaign_end_date_or_today
348363
end
349364

350365
def requires_care_setting?
351-
vaccine&.type == "hpv"
366+
vaccine&.hpv?
367+
end
368+
369+
def requires_performed_by?
370+
vaccine&.flu?
352371
end
353372

354373
def parse_date(key)

spec/models/dps_export_row_spec.rb

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
}
2727
)
2828
end
29+
let(:performed_by) { create(:user, family_name: "Doe", given_name: "Jane") }
30+
let(:performed_by_given_name) { nil }
31+
let(:performed_by_family_name) { nil }
2932
let(:vaccination_record) do
3033
create(
3134
:vaccination_record,
@@ -35,7 +38,9 @@
3538
delivery_site: :left_arm_upper_position,
3639
dose_sequence: 1,
3740
patient_session:,
38-
performed_by: create(:user, family_name: "Doe", given_name: "Jane"),
41+
performed_by:,
42+
performed_by_given_name:,
43+
performed_by_family_name:,
3944
recorded_at: Time.zone.local(2024, 7, 23, 19, 31, 47),
4045
uuid: "ea4860a5-6d97-4f31-b640-f5c50f43bfd2",
4146
vaccine:
@@ -101,12 +106,40 @@
101106
expect(array[11]).to eq "new"
102107
end
103108

104-
it "has performing_professional_forename" do
105-
expect(array[12]).to be_nil
109+
describe "performing_professional_forename" do
110+
subject(:performing_professional_forename) { array[12] }
111+
112+
it { should eq("Jane") }
113+
114+
context "without a user" do
115+
let(:performed_by) { nil }
116+
117+
it { should be_nil }
118+
119+
context "with a name" do
120+
let(:performed_by_given_name) { "Jane" }
121+
122+
it { should eq("Jane") }
123+
end
124+
end
106125
end
107126

108-
it "has performing_professional_surname" do
109-
expect(array[13]).to be_nil
127+
describe "performing_professional_surname" do
128+
subject(:performing_professional_surname) { array[13] }
129+
130+
it { should eq("Doe") }
131+
132+
context "without a user" do
133+
let(:performed_by) { nil }
134+
135+
it { should be_nil }
136+
137+
context "with a name" do
138+
let(:performed_by_family_name) { "Doe" }
139+
140+
it { should eq("Doe") }
141+
end
142+
end
110143
end
111144

112145
it "has recorded_date" do

spec/models/immunisation_import_row_spec.rb

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
"PERSON_GENDER_CODE" => "Male",
3939
"NHS_NUMBER" => nhs_number,
4040
"DATE_OF_VACCINATION" => "20240101",
41-
"VACCINE_GIVEN" => "AstraZeneca Fluenz Tetra LAIV"
41+
"VACCINE_GIVEN" => "AstraZeneca Fluenz Tetra LAIV",
42+
"PERFORMING_PROFESSIONAL_FORENAME" => "John",
43+
"PERFORMING_PROFESSIONAL_SURNAME" => "Smith"
4244
}
4345
end
4446

@@ -218,7 +220,35 @@
218220
"PERSON_POSTCODE" => "SW1A 1AA",
219221
"PERSON_GENDER_CODE" => "Male",
220222
"DATE_OF_VACCINATION" => "20240101",
221-
"VACCINE_GIVEN" => "AstraZeneca Fluenz Tetra LAIV"
223+
"VACCINE_GIVEN" => "AstraZeneca Fluenz Tetra LAIV",
224+
"PERFORMING_PROFESSIONAL_FORENAME" => "John",
225+
"PERFORMING_PROFESSIONAL_SURNAME" => "Smith"
226+
}
227+
end
228+
229+
it { should be_valid }
230+
end
231+
232+
context "with valid fields for HPV" do
233+
let(:campaign) { create(:campaign, :hpv, academic_year: 2023) }
234+
235+
let(:data) do
236+
{
237+
"ORGANISATION_CODE" => "abc",
238+
"BATCH_EXPIRY_DATE" => "20210101",
239+
"BATCH_NUMBER" => "123",
240+
"ANATOMICAL_SITE" => "left thigh",
241+
"SCHOOL_NAME" => "Hogwarts",
242+
"SCHOOL_URN" => "123456",
243+
"PERSON_FORENAME" => "Harry",
244+
"PERSON_SURNAME" => "Potter",
245+
"PERSON_DOB" => "20120101",
246+
"PERSON_POSTCODE" => "SW1A 1AA",
247+
"PERSON_GENDER_CODE" => "Male",
248+
"DATE_OF_VACCINATION" => "20240101",
249+
"VACCINE_GIVEN" => "Gardasil9",
250+
"DOSE_SEQUENCE" => "1",
251+
"CARE_SETTING" => "1"
222252
}
223253
end
224254

@@ -829,15 +859,53 @@
829859
end
830860
end
831861

862+
describe "#performed_by_given_name" do
863+
subject(:performed_by_given_name) do
864+
immunisation_import_row.performed_by_given_name
865+
end
866+
867+
context "without a value" do
868+
let(:data) { {} }
869+
870+
it { should be_nil }
871+
end
872+
873+
context "with a value" do
874+
let(:data) { { "PERFORMING_PROFESSIONAL_FORENAME" => "John" } }
875+
876+
it { should eq("John") }
877+
end
878+
end
879+
880+
describe "#performed_by_family_name" do
881+
subject(:performed_by_family_name) do
882+
immunisation_import_row.performed_by_family_name
883+
end
884+
885+
context "without a value" do
886+
let(:data) { {} }
887+
888+
it { should be_nil }
889+
end
890+
891+
context "with a value" do
892+
let(:data) { { "PERFORMING_PROFESSIONAL_SURNAME" => "Smith" } }
893+
894+
it { should eq("Smith") }
895+
end
896+
end
897+
832898
describe "#to_vaccination_record" do
833899
subject(:vaccination_record) do
834900
immunisation_import_row.to_vaccination_record
835901
end
836902

837903
let(:data) { valid_data }
838904

839-
it "does not have a vaccinator as that isn't provided in the import" do
840-
expect(vaccination_record.performed_by).to be_nil
905+
it "has a vaccinator" do
906+
expect(vaccination_record.performed_by).to have_attributes(
907+
full_name: "John Smith"
908+
)
841909
end
842910

843911
it "sets the administered at time" do

0 commit comments

Comments
 (0)