|
52 | 52 | it "return the count of contactable patients called" do |
53 | 53 | facility_1_contactable_patients = create_list(:patient, 3, :hypertension, assigned_facility: facility_1, recorded_at: five_months_ago) |
54 | 54 | facility_1_patient_with_out_phone = create(:patient, :hypertension, :without_phone_number, assigned_facility: facility_1, recorded_at: five_months_ago) |
55 | | - facility_1_patient_removed_from_list = create(:patient, :hypertension, :removed_from_overdue_list, assigned_facility: facility_1, recorded_at: five_months_ago) |
| 55 | + facility_1_patient_removed_from_list = create(:patient, :hypertension, assigned_facility: facility_1, recorded_at: five_months_ago) |
| 56 | + |
| 57 | + # Create appointments for all patients |
56 | 58 | facility_1_contactable_patients.each do |the_patient| |
57 | 59 | create(:appointment, patient: the_patient, scheduled_date: one_month_ago, facility: facility_1, device_created_at: two_months_ago) |
58 | 60 | end |
59 | | - create(:call_result, patient: facility_1_contactable_patients.first, device_created_at: this_month + 15.days) |
60 | | - create(:call_result, patient: facility_1_contactable_patients.second, device_created_at: this_month + 1.days) |
61 | | - create(:call_result, patient: facility_1_contactable_patients.third, device_created_at: two_months_ago + 1.days) |
62 | | - create(:call_result, patient: facility_1_patient_with_out_phone, device_created_at: this_month + 27.days) |
63 | | - create(:call_result, patient: facility_1_patient_removed_from_list, device_created_at: this_month + 4.days) |
| 61 | + create(:appointment, patient: facility_1_patient_with_out_phone, scheduled_date: one_month_ago, facility: facility_1, device_created_at: two_months_ago) |
| 62 | + create(:appointment, patient: facility_1_patient_removed_from_list, scheduled_date: one_month_ago, facility: facility_1, device_created_at: two_months_ago) |
| 63 | + |
| 64 | + # Create call results - deterministic result_type to avoid flakiness |
| 65 | + create(:call_result, patient: facility_1_contactable_patients.first, device_created_at: this_month + 15.days, result_type: :agreed_to_visit) |
| 66 | + create(:call_result, patient: facility_1_contactable_patients.second, device_created_at: this_month + 1.days, result_type: :agreed_to_visit) |
| 67 | + create(:call_result, patient: facility_1_contactable_patients.third, device_created_at: two_months_ago + 1.days, result_type: :agreed_to_visit) |
| 68 | + create(:call_result, patient: facility_1_patient_with_out_phone, device_created_at: this_month + 27.days, result_type: :agreed_to_visit) |
| 69 | + # Patient removed from overdue list has 2 call results: one initial removal, one follow-up |
| 70 | + create(:call_result, patient: facility_1_patient_removed_from_list, device_created_at: one_month_ago, result_type: :removed_from_overdue_list, remove_reason: :not_responding) |
| 71 | + create(:call_result, patient: facility_1_patient_removed_from_list, device_created_at: this_month + 4.days, result_type: :agreed_to_visit) |
64 | 72 |
|
65 | 73 | allow(Reports::PatientState).to receive(:get_refresh_months).and_return(ReportingHelpers.get_refresh_months_between_dates(5.months.ago.to_date, Date.today)) |
66 | 74 | RefreshReportingViews.new(views: views).call |
|
72 | 80 | facility_1_denominator = indicator.denominator(region, period, with_non_contactable: true) |
73 | 81 |
|
74 | 82 | expect(facility_1_numerator).to eq 6 |
75 | | - expect(facility_1_denominator).to eq 4 |
| 83 | + expect(facility_1_denominator).to eq 5 # 5 patients total: 3 contactable + 1 without phone + 1 removed from list |
76 | 84 | end |
77 | 85 | end |
78 | 86 | end |
0 commit comments