Skip to content

Commit 876ae42

Browse files
authored
Normalise whitespace in NHS number (#3560)
When editing the NHS number of a patient we should normalise the whitespace on the NHS number to ensure that it's accepted and is valid. We do this already for spaces, but not for special unicode whitespace characters.
2 parents d688203 + 9357b94 commit 876ae42

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

app/models/patient.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ class Patient < ApplicationRecord
186186

187187
encrypts :address_line_1, :address_line_2, :address_town
188188

189-
normalizes :nhs_number, with: -> { _1.blank? ? nil : _1.gsub(/\s/, "") }
189+
normalizes :nhs_number,
190+
with: -> do
191+
it.blank? ? nil : it.normalise_whitespace.gsub(/\s/, "")
192+
end
190193

191194
before_destroy :destroy_childless_parents
192195

spec/models/patient_spec.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@
157157
end
158158
end
159159

160+
describe "normalizations" do
161+
let(:patient) { described_class.new }
162+
163+
it do
164+
expect(patient).to normalize(:nhs_number).from(
165+
"012\u200D345\u200D6789"
166+
).to("0123456789")
167+
end
168+
169+
it { should normalize(:nhs_number).from(" 0123456789 ").to("0123456789") }
170+
171+
it { should normalize(:address_postcode).from(" SW111AA ").to("SW11 1AA") }
172+
end
173+
160174
describe "#vaccination_records" do
161175
subject(:vaccination_records) { patient.vaccination_records }
162176

@@ -173,9 +187,6 @@
173187
it { should_not include(discarded_vaccination_record) }
174188
end
175189

176-
it { should normalize(:nhs_number).from(" 0123456789 ").to("0123456789") }
177-
it { should normalize(:address_postcode).from(" SW111AA ").to("SW11 1AA") }
178-
179190
describe "#match_existing" do
180191
subject(:match_existing) do
181192
described_class.match_existing(

0 commit comments

Comments
 (0)