Skip to content

Commit e6924f7

Browse files
Merge pull request #6034 from nhsuk/alistair/empty-cell-error-message
Fix validation errors
2 parents d673f82 + bc01f47 commit e6924f7

2 files changed

Lines changed: 84 additions & 36 deletions

File tree

app/models/immunisation_import_row.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,16 +833,20 @@ def validate_existing_patients
833833
def validate_local_patient_id
834834
return unless national_reporting?
835835

836-
if local_patient_id.blank?
836+
if local_patient_id.nil?
837837
errors.add(:base, "<code>LOCAL_PATIENT_ID</code> is required")
838+
elsif local_patient_id.blank?
839+
errors.add(local_patient_id&.header, "Enter a local patient ID.")
838840
end
839841
end
840842

841843
def validate_local_patient_id_uri
842844
return unless national_reporting?
843845

844-
if local_patient_id_uri.blank?
846+
if local_patient_id_uri.nil?
845847
errors.add(:base, "<code>LOCAL_PATIENT_ID_URI</code> is required")
848+
elsif local_patient_id_uri.blank?
849+
errors.add(local_patient_id_uri&.header, "Enter a local patient ID URI.")
846850
end
847851
end
848852

spec/models/immunisation_import_row_spec.rb

Lines changed: 78 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"PERFORMING_PROFESSIONAL_FORENAME" => vaccinator.given_name,
8282
"PERFORMING_PROFESSIONAL_SURNAME" => vaccinator.family_name,
8383
"VACCINE_GIVEN" => "AstraZeneca Fluenz LAIV",
84-
"ANATOMICAL_SITE" => "nasal",
84+
"ANATOMICAL_SITE" => "nasal"
8585
)
8686
end
8787
let(:valid_national_reporting_hpv_data) do
@@ -123,6 +123,9 @@
123123
context "with headers, but an empty row" do
124124
let(:data) do
125125
{
126+
"ORGANISATION_CODE" => "",
127+
"SCHOOL_NAME" => "",
128+
"SCHOOL_URN" => "",
126129
"NHS_NUMBER" => "",
127130
"PERSON_FORENAME" => "",
128131
"PERSON_SURNAME" => "",
@@ -132,42 +135,34 @@
132135
"PROGRAMME" => "",
133136
"DATE_OF_VACCINATION" => "",
134137
"REASON_NOT_VACCINATED" => "",
135-
"VACCINATED" => ""
138+
"VACCINATED" => "",
139+
"BATCH_EXPIRY_DATE" => "",
140+
"BATCH_NUMBER" => "",
141+
"ANATOMICAL_SITE" => "",
142+
"PERFORMING_PROFESSIONAL_FORENAME" => "",
143+
"PERFORMING_PROFESSIONAL_SURNAME" => "",
144+
"VACCINE_GIVEN" => ""
136145
}
137146
end
138147

139148
it "has the correct errors" do
140149
expect(immunisation_import_row).to be_invalid
141-
expect(immunisation_import_row.errors[:base]).to be_empty
142150

143-
expect(immunisation_import_row.errors["PERSON_FORENAME"]).to eq(
144-
["Enter a first name."]
145-
)
146-
expect(immunisation_import_row.errors["PERSON_SURNAME"]).to eq(
147-
["Enter a last name."]
148-
)
149-
expect(immunisation_import_row.errors["PERSON_DOB"]).to eq(
150-
["Enter a date of birth."]
151-
)
152-
expect(immunisation_import_row.errors["PERSON_POSTCODE"]).to eq(
153-
["Enter a valid postcode, such as SW1A 1AA."]
154-
)
155-
expect(immunisation_import_row.errors["PERSON_GENDER_CODE"]).to eq(
156-
["Enter a gender or gender code."]
157-
)
158-
expect(immunisation_import_row.errors["PROGRAMME"]).to eq(
159-
["Enter a programme."]
160-
)
161-
expect(immunisation_import_row.errors["DATE_OF_VACCINATION"]).to eq(
162-
["Enter a date."]
163-
)
164-
expect(immunisation_import_row.errors["REASON_NOT_VACCINATED"]).to eq(
165-
["Enter a valid reason."]
166-
)
167-
expect(immunisation_import_row.errors["VACCINATED"]).to eq(
168-
[
169-
"You need to record whether the child was vaccinated or not. Enter ‘Y’ or ‘N’ in the ‘VACCINATED’ column."
170-
]
151+
expect(immunisation_import_row.errors.to_hash).to eq(
152+
{
153+
VACCINATED: [
154+
"You need to record whether the child was vaccinated or not. " \
155+
"Enter ‘Y’ or ‘N’ in the ‘VACCINATED’ column."
156+
],
157+
DATE_OF_VACCINATION: ["Enter a date."],
158+
PERSON_DOB: ["Enter a date of birth."],
159+
PERSON_FORENAME: ["Enter a first name."],
160+
PERSON_GENDER_CODE: ["Enter a gender or gender code."],
161+
PERSON_SURNAME: ["Enter a last name."],
162+
PERSON_POSTCODE: ["Enter a valid postcode, such as SW1A 1AA."],
163+
PROGRAMME: ["Enter a programme."],
164+
REASON_NOT_VACCINATED: ["Enter a valid reason."]
165+
}
171166
)
172167
end
173168
end
@@ -1208,6 +1203,55 @@
12081203
include_examples "it is equivalent to `VACCINATED` being `Y`"
12091204
end
12101205

1206+
context "with headers, but an empty row" do
1207+
let(:data) do
1208+
{
1209+
"ORGANISATION_CODE" => "",
1210+
"SCHOOL_NAME" => "",
1211+
"SCHOOL_URN" => "",
1212+
"NHS_NUMBER" => "",
1213+
"PERSON_FORENAME" => "",
1214+
"PERSON_SURNAME" => "",
1215+
"PERSON_DOB" => "",
1216+
"PERSON_POSTCODE" => "",
1217+
"PERSON_GENDER_CODE" => "",
1218+
"DATE_OF_VACCINATION" => "",
1219+
"VACCINATED" => "",
1220+
"PERFORMING_PROFESSIONAL_FORENAME" => "",
1221+
"PERFORMING_PROFESSIONAL_SURNAME" => "",
1222+
"VACCINE_GIVEN" => "",
1223+
"ANATOMICAL_SITE" => "",
1224+
"BATCH_EXPIRY_DATE" => "",
1225+
"BATCH_NUMBER" => "",
1226+
"LOCAL_PATIENT_ID" => "",
1227+
"LOCAL_PATIENT_ID_URI" => ""
1228+
}
1229+
end
1230+
1231+
it "has the correct errors" do
1232+
expect(immunisation_import_row).to be_invalid
1233+
1234+
expect(immunisation_import_row.errors.to_hash).to eq(
1235+
{
1236+
BATCH_EXPIRY_DATE: ["Enter a batch expiry date."],
1237+
BATCH_NUMBER: ["Enter a batch number."],
1238+
DATE_OF_VACCINATION: ["Enter a date."],
1239+
ANATOMICAL_SITE: ["Enter an anatomical site."],
1240+
LOCAL_PATIENT_ID: ["Enter a local patient ID."],
1241+
LOCAL_PATIENT_ID_URI: ["Enter a local patient ID URI."],
1242+
PERSON_DOB: ["Enter a date of birth."],
1243+
PERSON_FORENAME: ["Enter a first name."],
1244+
PERSON_GENDER_CODE: ["Enter a gender or gender code."],
1245+
PERSON_SURNAME: ["Enter a last name."],
1246+
PERSON_POSTCODE: ["Enter a valid postcode, such as SW1A 1AA."],
1247+
ORGANISATION_CODE: ["Enter an organisation code."],
1248+
SCHOOL_URN: ["Enter a school URN."],
1249+
VACCINE_GIVEN: ["Enter a vaccine name."]
1250+
}
1251+
)
1252+
end
1253+
end
1254+
12111255
context "when `VACCINATED` is `Y`" do
12121256
let(:data) { basic_flu_data.merge({ "VACCINATED" => "Y" }) }
12131257

@@ -2664,12 +2708,12 @@
26642708
end
26652709

26662710
context "of type flu" do
2667-
shared_examples "accepts a VACCINE_GIVEN code" do |vaccine_given, snomed_product_code, anatomical_site: "right deltoid"|
2711+
shared_examples "accepts a VACCINE_GIVEN code" do |vaccine_given, snomed_product_code, anatomical_site|
26682712
context "with code: #{vaccine_given}" do
26692713
let(:data) do
26702714
valid_national_reporting_flu_data.merge(
26712715
"VACCINE_GIVEN" => vaccine_given,
2672-
"ANATOMICAL_SITE" => anatomical_site
2716+
"ANATOMICAL_SITE" => anatomical_site || "right deltoid"
26732717
)
26742718
end
26752719

@@ -2763,7 +2807,7 @@
27632807
include_examples "accepts a VACCINE_GIVEN code",
27642808
"AstraZeneca Fluenz LAIV",
27652809
"43208811000001106",
2766-
anatomical_site: "nasal"
2810+
"nasal"
27672811
include_examples "accepts a VACCINE_GIVEN code",
27682812
"Viatris Quadrivalent Influvac sub - unit Tetra - QIVe",
27692813
"45354911000001100"

0 commit comments

Comments
 (0)