|
121 | 121 | and_i_go_to_the_import_page |
122 | 122 | then_i_should_see_import_issues_with_the_count |
123 | 123 | end |
| 124 | + |
| 125 | + scenario "Keep both records assigns changesets and PDS search results to the new patient" do |
| 126 | + given_the_app_is_setup |
| 127 | + and_import_review_screen_is_enabled |
| 128 | + and_pds_lookup_during_import_is_enabled |
| 129 | + stub_pds_search_to_return_no_patients |
| 130 | + and_an_existing_patient_record_exists_with_same_name_and_dob |
| 131 | + |
| 132 | + when_i_visit_the_import_page |
| 133 | + and_i_choose_to_import_child_records |
| 134 | + and_i_upload_a_file_with_duplicate_except_for_postcode |
| 135 | + |
| 136 | + when_i_review_the_duplicate_record |
| 137 | + and_i_choose_to_keep_both_records |
| 138 | + and_i_confirm_my_selection |
| 139 | + then_i_should_see_a_success_message |
| 140 | + |
| 141 | + then_the_changeset_should_belong_to_the_new_patient |
| 142 | + and_the_pds_search_results_should_belong_to_the_new_patient |
| 143 | + end |
124 | 144 | end |
125 | 145 |
|
126 | 146 | def given_the_app_is_setup |
@@ -363,4 +383,68 @@ def then_i_should_see_import_issues_with_the_count |
363 | 383 | expect(page).to have_link("Issues") |
364 | 384 | expect(page).to have_selector(".app-count", text: "(1)").twice |
365 | 385 | end |
| 386 | + |
| 387 | + def and_an_existing_patient_record_exists_with_same_name_and_dob |
| 388 | + @existing_patient = |
| 389 | + create( |
| 390 | + :patient, |
| 391 | + given_name: "Taylor", |
| 392 | + family_name: "Reed", |
| 393 | + nhs_number: nil, |
| 394 | + date_of_birth: Date.new(2010, 1, 1), |
| 395 | + address_line_1: "10 Downing Street", |
| 396 | + address_line_2: "", |
| 397 | + address_town: "London", |
| 398 | + address_postcode: "SW1A 1AA", |
| 399 | + school: Location.find_by!(urn: "123456") |
| 400 | + ) |
| 401 | + end |
| 402 | + |
| 403 | + def and_i_upload_a_file_with_duplicate_except_for_postcode |
| 404 | + attach_file( |
| 405 | + "cohort_import[csv]", |
| 406 | + "spec/fixtures/cohort_import/duplicate_except_postcode.csv" |
| 407 | + ) |
| 408 | + click_on "Continue" |
| 409 | + wait_for_import_to_complete(CohortImport) |
| 410 | + end |
| 411 | + |
| 412 | + def when_i_review_the_duplicate_record |
| 413 | + find(".nhsuk-details__summary", text: /1 upload issue/).click |
| 414 | + click_on "Review" |
| 415 | + end |
| 416 | + |
| 417 | + def and_i_choose_to_keep_both_records |
| 418 | + choose "Keep both child records" |
| 419 | + end |
| 420 | + |
| 421 | + def and_i_confirm_my_selection |
| 422 | + click_on "Resolve duplicate" |
| 423 | + end |
| 424 | + |
| 425 | + def then_i_should_see_a_success_message |
| 426 | + expect(page).to have_content("Record updated") |
| 427 | + end |
| 428 | + |
| 429 | + def then_the_changeset_should_belong_to_the_new_patient |
| 430 | + import = CohortImport.order(:created_at).last |
| 431 | + changeset = import.changesets.from_file.sole |
| 432 | + expect(changeset.reload.patient_id).to eq(new_patient.id) |
| 433 | + end |
| 434 | + |
| 435 | + def and_the_pds_search_results_should_belong_to_the_new_patient |
| 436 | + import = CohortImport.order(:created_at).last |
| 437 | + |
| 438 | + results = |
| 439 | + PDSSearchResult.where(import_type: "CohortImport", import_id: import.id) |
| 440 | + |
| 441 | + expect(results.pluck(:patient_id).uniq).to eq([new_patient.id]) |
| 442 | + end |
| 443 | + |
| 444 | + def new_patient |
| 445 | + Patient |
| 446 | + .where(given_name: "Taylor", family_name: "Reed") |
| 447 | + .where.not(id: @existing_patient.id) |
| 448 | + .sole |
| 449 | + end |
366 | 450 | end |
0 commit comments