Skip to content

Commit ec09952

Browse files
authored
Merge pull request #4308 from nhsuk/fix-parent-deduplication-imports
Deduplicate parents before importing changesets
2 parents 2abaae7 + 08597e2 commit ec09952

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

app/jobs/commit_patient_changesets_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def perform(import)
3232

3333
def import_patients_and_parents(changesets, import)
3434
patients = changesets.map(&:patient)
35-
parents = changesets.flat_map(&:parents)
35+
parents = changesets.flat_map(&:parents).uniq
3636
relationships =
3737
changesets
3838
.flat_map(&:parent_relationships)

spec/features/import_child_pds_lookup_extravaganza_spec.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,11 @@ def and_an_existing_patient_record_exists
155155
type: "unknown"
156156
)
157157

158+
create(:parent, full_name: "David Williams", email: "david.w@email.com")
159+
158160
expect(Patient.count).to eq(3)
159161
expect(ParentRelationship.count).to eq(1)
160-
expect(Parent.count).to eq(1)
162+
expect(Parent.count).to eq(2)
161163
end
162164

163165
def and_pds_lookup_during_import_is_enabled
@@ -330,15 +332,12 @@ def and_i_see_address_differences_for_review
330332
def and_catherine_parents_are_handled_correctly
331333
catherine =
332334
Patient.find_by(given_name: "Catherine", family_name: "Williams")
333-
expect(catherine.parents.count).to eq(2)
335+
expect(catherine.parents.count).to eq(1)
334336

335337
guardian = catherine.parents.find_by(full_name: "David Williams")
336338
guardian_relationship =
337339
catherine.parent_relationships.find_by(parent: guardian)
338340
expect(guardian_relationship.type).to eq("guardian")
339-
340-
mother = catherine.parents.find_by(full_name: "Sarah Williams")
341-
expect(mother.phone).to be_present
342341
end
343342

344343
def and_charlie_has_no_parents_as_expected
@@ -392,14 +391,14 @@ def then_school_moves_are_created_appropriately
392391
end
393392

394393
def and_all_parent_relationships_are_established
395-
expect(Parent.count).to eq(8)
396-
expect(ParentRelationship.count).to eq(8)
394+
expect(Parent.count).to eq(7)
395+
expect(ParentRelationship.count).to eq(7)
397396

398397
father_relationships = ParentRelationship.where(type: "father")
399398
expect(father_relationships.count).to eq(3) # John Tweedle, Mike HomeDad, Robert Samson
400399

401400
mother_relationships = ParentRelationship.where(type: "mother")
402-
expect(mother_relationships.count).to eq(3) # Mary Tweedle, Linda Samson, Sarah Williams
401+
expect(mother_relationships.count).to eq(2) # Mary Tweedle, Linda Samson
403402

404403
guardian_relationships = ParentRelationship.where(type: "guardian")
405404
expect(guardian_relationships.count).to eq(1) # David Williams
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CHILD_SCHOOL_URN,PARENT_1_NAME,PARENT_1_RELATIONSHIP,PARENT_1_EMAIL,PARENT_1_PHONE,PARENT_2_NAME,PARENT_2_RELATIONSHIP,PARENT_2_EMAIL,PARENT_2_PHONE,CHILD_FIRST_NAME,CHILD_LAST_NAME,CHILD_PREFERRED_GIVEN_NAME,CHILD_DATE_OF_BIRTH,CHILD_YEAR_GROUP,CHILD_ADDRESS_LINE_1,CHILD_ADDRESS_LINE_2,CHILD_TOWN,CHILD_POSTCODE,CHILD_NHS_NUMBER
22
123456,John Tweedle,Father,john.tweedle@email.com,01234567890,Mary Tweedle,Mother,mary.tweedle@email.com,01234567891,Albert,Tweedle,,2009-12-29,8,38A Battersea Rise,,London,SW11 1EH,9999075320
33
123456,Robert Samson,Dad,bob.samson@email.com,01234567892,Linda Samson,Mum,linda.samson@email.com,,Betty,Samson,Beth,2010-01-01,8,123 High Street,,London,SW1A 1AA,
4-
123456,David Williams,Guardian,david.w@email.com,,Sarah Williams,Mother,sarah.w@email.com,01234567894,Catherine,Williams,,2009-05-15,8,456 New Street,,London,SW2 2BB,
4+
123456,David Williams,Guardian,david.w@email.com,,Sarah Williams,Mother,david.w@email.com,01234567894,Catherine,Williams,,2009-05-15,8,456 New Street,,London,SW2 2BB,
55
123456,,,,,,,,,Charlie,Brown,,2011-03-15,9,42 Wallaby Way,,London,SW2 2BB,
66
999999,Mike HomeDad,Father,mike@home.com,01234567895,,,,,Emma,Homeschool,,2010-06-01,8,123 Home Street,,London,SW3 3AA,
77
123456,Jane Doe,,,01234567896,,,,,Oliver,Green,,2010-08-15,8,789 Silent Street,,London,SW1W 8JL,9435753868

0 commit comments

Comments
 (0)