Skip to content

Commit 8c7430f

Browse files
Add auto acceptance of preferred names
Automatically accept `:preferred_given_name` and `:preferred_family_name`, if the value in Mavis is `nil`, and the incoming value is not `nil`.
1 parent e1d1f53 commit 8c7430f

File tree

3 files changed

+158
-1
lines changed

3 files changed

+158
-1
lines changed

app/models/patient_import_row.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ def to_patient
5757
%w[male female not_specified]
5858
)
5959

60+
auto_accept_attribute(
61+
existing_patient,
62+
attributes,
63+
:preferred_given_name,
64+
:present?
65+
)
66+
auto_accept_attribute(
67+
existing_patient,
68+
attributes,
69+
:preferred_family_name,
70+
:present?
71+
)
72+
6073
if address_postcode.present? &&
6174
address_postcode.to_postcode != existing_patient.address_postcode
6275
attributes.merge!(

spec/models/class_import_row_spec.rb

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,81 @@
304304
end
305305
end
306306

307+
context "with an existing patient without preferred names" do
308+
let(:data) do
309+
valid_data.merge(
310+
"CHILD_PREFERRED_FIRST_NAME" => "Jim",
311+
"CHILD_PREFERRED_LAST_NAME" => "Smithy"
312+
)
313+
end
314+
315+
let!(:existing_patient) do
316+
create(
317+
:patient,
318+
address_postcode: "SW1A 1AA",
319+
family_name: "Smith",
320+
given_name: "Jimmy",
321+
date_of_birth: Date.new(2010, 1, 1)
322+
)
323+
end
324+
325+
it { should eq(existing_patient) }
326+
327+
it "saves the incoming preferred names" do
328+
expect(patient).to have_attributes(
329+
preferred_given_name: "Jim",
330+
preferred_family_name: "Smithy"
331+
)
332+
end
333+
334+
it "doesn't stage the preferred names differences" do
335+
expect(patient.pending_changes).to be_empty
336+
end
337+
end
338+
339+
context "with an existing patient already with preferred names" do
340+
let(:data) do
341+
valid_data.merge(
342+
"CHILD_PREFERRED_FIRST_NAME" => "Jim",
343+
"CHILD_PREFERRED_LAST_NAME" => "Smithy"
344+
)
345+
end
346+
347+
let!(:existing_patient) do
348+
create(
349+
:patient,
350+
address_postcode: "SW1A 1AA",
351+
family_name: "Smith",
352+
given_name: "Jimmy",
353+
preferred_given_name: "Jimothy",
354+
preferred_family_name: "Smithers",
355+
nhs_number: "9990000018",
356+
address_line_1: "10 Downing Street",
357+
address_line_2: "",
358+
address_town: "London",
359+
birth_academic_year: 2009,
360+
date_of_birth: Date.new(2010, 1, 1),
361+
registration: "8AB"
362+
)
363+
end
364+
365+
it { should eq(existing_patient) }
366+
367+
it "does not save the incoming gender" do
368+
expect(patient).to have_attributes(
369+
preferred_given_name: "Jimothy",
370+
preferred_family_name: "Smithers"
371+
)
372+
end
373+
374+
it "does stage the gender differences" do
375+
expect(patient.pending_changes).to include(
376+
"preferred_given_name" => "Jim",
377+
"preferred_family_name" => "Smithy"
378+
)
379+
end
380+
end
381+
307382
context "with an existing patient without address" do
308383
let(:data) do
309384
valid_data.merge(

spec/models/cohort_import_row_spec.rb

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"CHILD_POSTCODE" => "SW1A 1AA",
3030
"CHILD_FIRST_NAME" => "Jimmy",
3131
"CHILD_LAST_NAME" => "Smith",
32-
"CHILD_PREFERRED_GIVEN_NAME" => "Jim",
32+
"CHILD_PREFERRED_FIRST_NAME" => "Jim",
33+
"CHILD_PREFERRED_LAST_NAME" => "Smithy",
3334
"CHILD_DATE_OF_BIRTH" => "2010-01-01",
3435
"CHILD_GENDER" => "Male",
3536
"CHILD_NHS_NUMBER" => "9990000018",
@@ -291,6 +292,74 @@
291292
end
292293
end
293294

295+
context "with an existing patient without preferred names" do
296+
let!(:existing_patient) do
297+
create(
298+
:patient,
299+
address_postcode: "SW1A 1AA",
300+
family_name: "Smith",
301+
gender_code: "male",
302+
given_name: "Jimmy",
303+
nhs_number: "9990000018",
304+
address_line_1: "10 Downing Street",
305+
address_line_2: "",
306+
address_town: "London",
307+
birth_academic_year: 2009,
308+
date_of_birth: Date.new(2010, 1, 1),
309+
registration: "8AB"
310+
)
311+
end
312+
313+
it { should eq(existing_patient) }
314+
315+
it "saves the incoming preferred names" do
316+
expect(patient).to have_attributes(
317+
preferred_given_name: "Jim",
318+
preferred_family_name: "Smithy"
319+
)
320+
end
321+
322+
it "doesn't stage the preferred names differences" do
323+
expect(patient.pending_changes).to be_empty
324+
end
325+
end
326+
327+
context "with an existing patient already with preferred names" do
328+
let!(:existing_patient) do
329+
create(
330+
:patient,
331+
address_postcode: "SW1A 1AA",
332+
given_name: "Jimmy",
333+
family_name: "Smith",
334+
preferred_given_name: "Jimothy",
335+
preferred_family_name: "Smithers",
336+
nhs_number: "9990000018",
337+
address_line_1: "10 Downing Street",
338+
address_line_2: "",
339+
address_town: "London",
340+
birth_academic_year: 2009,
341+
date_of_birth: Date.new(2010, 1, 1),
342+
registration: "8AB"
343+
)
344+
end
345+
346+
it { should eq(existing_patient) }
347+
348+
it "does not save the incoming gender" do
349+
expect(patient).to have_attributes(
350+
preferred_given_name: "Jimothy",
351+
preferred_family_name: "Smithers"
352+
)
353+
end
354+
355+
it "does stage the gender differences" do
356+
expect(patient.pending_changes).to include(
357+
"preferred_given_name" => "Jim",
358+
"preferred_family_name" => "Smithy"
359+
)
360+
end
361+
end
362+
294363
context "with an existing patient without address (ex. postcode)" do
295364
let!(:existing_patient) do
296365
create(

0 commit comments

Comments
 (0)