|
15 | 15 | end |
16 | 16 |
|
17 | 17 | let(:programmes) { [Programme.hpv] } |
18 | | - let(:team) { create(:team, ods_code: "abc", programmes:) } |
| 18 | + let(:team) { create(:team, ods_code: "ABC", programmes:) } |
19 | 19 |
|
20 | 20 | let(:nhs_number) { "9449306168" } |
21 | 21 | let(:given_name) { "Harry" } |
|
25 | 25 | let(:vaccinator) { create(:user, team:) } |
26 | 26 | let(:valid_patient_data) do |
27 | 27 | { |
28 | | - "ORGANISATION_CODE" => "abc", |
| 28 | + "ORGANISATION_CODE" => "ABC", |
29 | 29 | "SCHOOL_NAME" => "Hogwarts", |
30 | 30 | "SCHOOL_URN" => "123456", |
31 | 31 | "PERSON_FORENAME" => given_name, |
|
2417 | 2417 |
|
2418 | 2418 | let(:import_type) { "bulk" } |
2419 | 2419 |
|
2420 | | - shared_examples "with existing vaccination records" do |programme| |
| 2420 | + shared_examples "date deduplication with existing vaccination records" do |programme| |
2421 | 2421 | let(:patient) { create(:patient, nhs_number:) } |
2422 | 2422 |
|
2423 | 2423 | let(:other_vaccination_record) do |
|
2429 | 2429 |
|
2430 | 2430 | before { other_vaccination_record } |
2431 | 2431 |
|
| 2432 | + it { should_not be_nil } |
2432 | 2433 | it { should_not eq other_vaccination_record } |
| 2434 | + its(:pending_changes) { should be_empty } |
2433 | 2435 | end |
2434 | 2436 |
|
2435 | 2437 | context "with an existing vaccination record on a different date in the same academic year" do |
2436 | 2438 | let(:performed_at) { Time.zone.local(2026, 1, 1, 12, 10, 2) } |
2437 | 2439 |
|
2438 | 2440 | before { other_vaccination_record } |
2439 | 2441 |
|
| 2442 | + it { should_not be_nil } |
2440 | 2443 | it { should_not eq other_vaccination_record } |
| 2444 | + its(:pending_changes) { should be_empty } |
2441 | 2445 | end |
2442 | 2446 |
|
2443 | 2447 | context "with an existing vaccination record on the same date" do |
|
2466 | 2470 |
|
2467 | 2471 | let(:data) { valid_bulk_flu_data } |
2468 | 2472 |
|
| 2473 | + let(:programme) { Programme.flu } |
| 2474 | + |
2469 | 2475 | it { should be_administered } |
2470 | 2476 |
|
2471 | | - its(:programme) { should eq(Programme.flu) } |
| 2477 | + its(:programme) { should eq programme } |
2472 | 2478 |
|
2473 | 2479 | its(:source) { should eq("bulk_upload") } |
2474 | 2480 |
|
|
2552 | 2558 |
|
2553 | 2559 | include_examples "with pseudo-postcodes" |
2554 | 2560 |
|
2555 | | - include_examples "with existing vaccination records", Programme.flu |
| 2561 | + include_examples "date deduplication with existing vaccination records", |
| 2562 | + Programme.flu |
| 2563 | + |
| 2564 | + context "when a similar vaccination record exists" do |
| 2565 | + let!(:other_vaccination_record) do |
| 2566 | + vaccine = Vaccine.find_by(nivs_name: "AstraZeneca Fluenz LAIV") |
| 2567 | + |
| 2568 | + create( |
| 2569 | + :vaccination_record, |
| 2570 | + :sourced_from_bulk_upload, |
| 2571 | + patient:, |
| 2572 | + programme:, |
| 2573 | + performed_at: Time.zone.local(2026, 1, 5, 0, 0, 0), |
| 2574 | + location:, |
| 2575 | + local_patient_id: "CIN-OXFORD-pat123456", |
| 2576 | + local_patient_id_uri: "https://cinnamon.nhs.uk/0de/system1", |
| 2577 | + performed_by_user: nil, |
| 2578 | + performed_by_given_name: vaccinator.given_name, |
| 2579 | + performed_by_family_name: vaccinator.family_name, |
| 2580 | + vaccine:, |
| 2581 | + batch: |
| 2582 | + create( |
| 2583 | + :batch, |
| 2584 | + team: nil, |
| 2585 | + name: "456", |
| 2586 | + expiry: Date.new(2026, 1, 6), |
| 2587 | + vaccine: |
| 2588 | + ) # different |
| 2589 | + ) |
| 2590 | + end |
| 2591 | + |
| 2592 | + it { should_not be_nil } |
| 2593 | + it { should_not eq other_vaccination_record } |
| 2594 | + its(:pending_changes) { should be_empty } |
| 2595 | + end |
| 2596 | + |
| 2597 | + context "when an identical vaccination record exists" do |
| 2598 | + let!(:other_vaccination_record) do |
| 2599 | + vaccine = Vaccine.find_by(nivs_name: "AstraZeneca Fluenz LAIV") |
| 2600 | + create( |
| 2601 | + :vaccination_record, |
| 2602 | + :sourced_from_bulk_upload, |
| 2603 | + patient:, |
| 2604 | + programme:, |
| 2605 | + performed_at: Time.zone.local(2026, 1, 5, 0, 0, 0), |
| 2606 | + location:, |
| 2607 | + local_patient_id: "CIN-OXFORD-pat123456", |
| 2608 | + local_patient_id_uri: "https://cinnamon.nhs.uk/0de/system1", |
| 2609 | + performed_by_user: nil, |
| 2610 | + performed_by_given_name: vaccinator.given_name, |
| 2611 | + performed_by_family_name: vaccinator.family_name, |
| 2612 | + vaccine:, |
| 2613 | + batch: |
| 2614 | + create( |
| 2615 | + :batch, |
| 2616 | + team: nil, |
| 2617 | + name: "123", |
| 2618 | + expiry: Date.new(2026, 1, 6), |
| 2619 | + vaccine: |
| 2620 | + ) # identical |
| 2621 | + ) |
| 2622 | + end |
| 2623 | + |
| 2624 | + it { should_not be_nil } |
| 2625 | + it { should eq other_vaccination_record } |
| 2626 | + its(:pending_changes) { should be_empty } |
| 2627 | + end |
2556 | 2628 | end |
2557 | 2629 |
|
2558 | 2630 | context "of type hpv" do |
|
2570 | 2642 |
|
2571 | 2643 | let(:data) { valid_bulk_hpv_data } |
2572 | 2644 |
|
| 2645 | + let(:programme) { Programme.hpv } |
| 2646 | + |
2573 | 2647 | it { should be_administered } |
2574 | 2648 |
|
2575 | | - its(:programme) { should eq(Programme.hpv) } |
| 2649 | + its(:programme) { should eq programme } |
2576 | 2650 |
|
2577 | 2651 | its(:source) { should eq("bulk_upload") } |
2578 | 2652 |
|
|
2649 | 2723 |
|
2650 | 2724 | include_examples "with pseudo-postcodes" |
2651 | 2725 |
|
2652 | | - include_examples "with existing vaccination records", Programme.hpv |
| 2726 | + include_examples "date deduplication with existing vaccination records", |
| 2727 | + Programme.hpv |
2653 | 2728 | end |
2654 | 2729 | end |
2655 | 2730 | end |
|
0 commit comments