Skip to content

Commit d4a1ba4

Browse files
authored
Small validation improvements to SystmOne import (#3448)
This makes a number of small fixes to the SystmOne import to ensure users can upload files without vaccines and to hide dose sequence validation if a programme isn't present. [Jira Issue](https://nhsd-jira.digital.nhs.uk/browse/MAV-1046)
2 parents 9370d08 + 47909d4 commit d4a1ba4

4 files changed

Lines changed: 54 additions & 14 deletions

File tree

app/models/immunisation_import_row.rb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,17 @@ def session
297297
end
298298
end
299299

300+
def vaccine_nivs_name
301+
parsed_vaccination_description_string&.dig(:vaccine_name) ||
302+
vaccine_name&.to_s
303+
end
304+
300305
def vaccine
301306
@vaccine ||=
302-
begin
303-
nivs_name =
304-
parsed_vaccination_description_string&.dig(:vaccine_name) ||
305-
vaccine_name&.to_s
306-
307-
organisation.vaccines.includes(:programme).find_by(nivs_name:)
308-
end
307+
organisation
308+
.vaccines
309+
.includes(:programme)
310+
.find_by(nivs_name: vaccine_nivs_name)
309311
end
310312

311313
def batch
@@ -331,10 +333,7 @@ def programmes_by_name
331333
end
332334
end
333335

334-
delegate :default_dose_sequence,
335-
:maximum_dose_sequence,
336-
to: :programme,
337-
allow_nil: true
336+
delegate :default_dose_sequence, :maximum_dose_sequence, to: :programme
338337

339338
def offline_recording? = session_id.present?
340339

@@ -611,6 +610,8 @@ def validate_delivery_site
611610
end
612611

613612
def validate_dose_sequence
613+
return if programme.nil?
614+
614615
field = dose_sequence.presence || combined_vaccination_and_dose_sequence
615616

616617
if field.present?
@@ -956,7 +957,7 @@ def validate_vaccine
956957
"is not given in the #{programme.name} programme"
957958
)
958959
end
959-
elsif field.present?
960+
elsif vaccine_nivs_name.present?
960961
errors.add(field.header, "This vaccine is not available in this session.")
961962
end
962963
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Date of birth,NHS number,Vaccination area code,Vaccination batch number,Vaccination reason,Vaccination type,First name,Postcode,Sex,Surname,Event date,Event location type,Event time,Organisation ID,School,School code,Patient Count
22
20100912,7420180008,,123013325,,Cervarix 1,Chyna,LE3 2DA,Female,Pickle,20240514,School,,,Eton College,110158,
3+
20100913,,,123013325,,HPV,Renie,LE1 2DA,Female,Parrish,20240514,School,,,Eton College,110158,

spec/models/immunisation_import_row_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@
182182
end
183183
end
184184

185+
context "without a vaccine" do
186+
let(:data) { valid_data.except("VACCINE_GIVEN") }
187+
188+
it { should be_valid }
189+
end
190+
185191
context "with an invalid reason not vaccinated" do
186192
let(:data) do
187193
{ "VACCINATED" => "N", "REASON_NOT_VACCINATED" => "unknown" }
@@ -836,6 +842,18 @@
836842
end
837843
end
838844

845+
context "without a vaccine" do
846+
let(:data) { valid_data.except("VACCINE_GIVEN") }
847+
848+
it "doesn't set a vaccine" do
849+
expect(vaccination_record.vaccine).to be_nil
850+
end
851+
852+
it "does set a programme" do
853+
expect(vaccination_record.programme).not_to be_nil
854+
end
855+
end
856+
839857
context "with an existing vaccination record" do
840858
let!(:existing_vaccination_record) do
841859
create(
@@ -1023,6 +1041,26 @@
10231041
it { expect(immunisation_import_row).to be_invalid }
10241042
end
10251043

1044+
context "with an invalid value and no programme" do
1045+
let(:programmes) { [create(:programme, :hpv)] }
1046+
1047+
let(:data) do
1048+
valid_data.merge(
1049+
"PROGRAMME" => "Unknown",
1050+
"VACCINE_GIVEN" => "Unknown",
1051+
"DOSE_SEQUENCE" => "abc"
1052+
)
1053+
end
1054+
1055+
it "has errors about the programme but not the dose sequence" do
1056+
expect(immunisation_import_row).to be_invalid
1057+
expect(immunisation_import_row.errors["PROGRAMME"]).to eq(
1058+
["This programme is not available in this session."]
1059+
)
1060+
expect(immunisation_import_row.errors["DOSE_SEQUENCE"]).to be_empty
1061+
end
1062+
end
1063+
10261064
context "with a valid value" do
10271065
let(:programmes) { [create(:programme, :hpv)] }
10281066

spec/models/immunisation_import_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@
250250
# stree-ignore
251251
expect { process! }
252252
.to change(immunisation_import, :processed_at).from(nil)
253-
.and change(immunisation_import.vaccination_records, :count).by(1)
254-
.and change(immunisation_import.patients, :count).by(1)
253+
.and change(immunisation_import.vaccination_records, :count).by(2)
254+
.and change(immunisation_import.patients, :count).by(2)
255255
.and change(immunisation_import.batches, :count).by(1)
256256
.and not_change(immunisation_import.patient_sessions, :count)
257257

0 commit comments

Comments
 (0)