Skip to content

Commit 3d555a7

Browse files
committed
Add needs_consent_no_contact_details status and supporting logic
This adds a new `Patient::ProgrammeStatus#status` where if a child is eligible for the programme and hasn't been sent any consent requests and doesn't have any parent contact details to send consent requests to. Jira-Issue: MAV-502
1 parent 79e811f commit 3d555a7

9 files changed

Lines changed: 49 additions & 9 deletions

File tree

app/lib/patient_status_updater.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def update_programme_statuses!
4848
:patient,
4949
:patient_locations,
5050
:triages,
51-
:vaccination_records
51+
:vaccination_records,
52+
:parents
5253
)
5354
.find_in_batches(batch_size: 10_000) do |batch|
5455
batch.each(&:assign)

app/lib/status_generator/programme.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def initialize(
1616
consents:,
1717
triages:,
1818
attendance_record:,
19-
vaccination_records:
19+
vaccination_records:,
20+
parents:
2021
)
2122
@programme_type = programme_type
2223
@academic_year = academic_year
@@ -25,6 +26,8 @@ def initialize(
2526
@consents = consents
2627
@triages = triages
2728
@attendance_record = attendance_record
29+
@vaccination_records = vaccination_records
30+
@parents = parents
2831

2932
@vaccination_criteria =
3033
VaccinationCriteria.new(
@@ -54,6 +57,8 @@ def status
5457
:cannot_vaccinate_absent
5558
elsif should_be_cannot_vaccinate_do_not_vaccinate?
5659
:cannot_vaccinate_do_not_vaccinate
60+
elsif should_be_needs_consent_no_contact_details?
61+
:needs_consent_no_contact_details
5762
elsif should_be_needs_consent_no_response?
5863
:needs_consent_no_response
5964
elsif should_be_cannot_vaccinate_delay_vaccination?
@@ -160,7 +165,8 @@ def consent_vaccine_methods
160165
:consents,
161166
:triages,
162167
:attendance_record,
163-
:vaccination_criteria
168+
:vaccination_criteria,
169+
:parents
164170

165171
delegate :vaccinated?,
166172
:vaccinated_vaccination_record,
@@ -232,6 +238,12 @@ def should_be_needs_consent_request_not_scheduled?
232238
false # TODO: Implement this status.
233239
end
234240

241+
def should_be_needs_consent_no_contact_details?
242+
is_eligible? && !parents_contactable?
243+
end
244+
245+
def parents_contactable? = parents.any?
246+
235247
def year_group = patient.year_group(academic_year:)
236248

237249
def is_eligible?

app/models/parent.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class Parent < ApplicationRecord
6464
presence: true,
6565
if: :contact_method_other?
6666

67+
scope :contactable,
68+
-> { where.not(email: [nil, ""]).or(where.not(phone: [nil, ""])) }
69+
6770
def self.match_existing(patient:, email:, phone:, full_name:)
6871
if email.present? && (parent = Parent.find_by(email:))
6972
return parent

app/models/patient/programme_status.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class Patient::ProgrammeStatus < ApplicationRecord
6363
through: :patient,
6464
source: :attendance_records
6565

66+
has_many :parents, -> { contactable }, through: :patient
67+
6668
GROUPS = %w[
6769
not_eligible
6870
needs_consent
@@ -80,7 +82,8 @@ class Patient::ProgrammeStatus < ApplicationRecord
8082
"needs_consent_request_scheduled" => 11,
8183
"needs_consent_request_failed" => 12,
8284
"needs_consent_no_response" => 13,
83-
"needs_consent_follow_up_requested" => 14
85+
"needs_consent_follow_up_requested" => 14,
86+
"needs_consent_no_contact_details" => 15
8487
}.freeze
8588

8689
HAS_REFUSAL_STATUSES = {
@@ -188,7 +191,8 @@ def generator
188191
consents:,
189192
triages:,
190193
attendance_record:,
191-
vaccination_records:
194+
vaccination_records:,
195+
parents:
192196
)
193197
end
194198
end

config/locales/status.en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ en:
5757
needs_consent_request_failed: Needs consent
5858
needs_consent_request_not_scheduled: Needs consent
5959
needs_consent_request_scheduled: Needs consent
60+
needs_consent_no_contact_details: No contact details
6061
needs_triage: Needs triage
6162
not_eligible: Not eligible
6263
vaccinated: Vaccinated
@@ -84,6 +85,7 @@ en:
8485
needs_consent_request_failed: blue
8586
needs_consent_request_not_scheduled: blue
8687
needs_consent_request_scheduled: blue
88+
needs_consent_no_contact_details: blue
8789
needs_triage: blue
8890
not_eligible: grey
8991
vaccinated: white
@@ -103,6 +105,7 @@ en:
103105
needs_consent_request_failed: Request failed
104106
needs_consent_request_not_scheduled: Request not scheduled
105107
needs_consent_request_scheduled: Request scheduled
108+
needs_consent_no_contact_details: No contact details
106109
vaccinated_already: Already had the vaccine
107110
vaccinated_fully: Vaccinated
108111
registration:

spec/components/app_patient_programmes_table_component_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
end
4747

4848
context "when vaccinated last year" do
49-
let(:patient) { create(:patient, session:) }
49+
let(:patient) { create(:patient, session:, parents: [create(:parent)]) }
5050

5151
before do
5252
create(

spec/features/vaccination_programmes_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def given_patients_exist_in_year_eleven
6969
year_group: 10,
7070
given_name: "John",
7171
family_name: "Smith",
72+
parents: [create(:parent)],
7273
school:
7374
)
7475

spec/lib/patient_programme_status_resolver_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@
110110
let(:date_of_birth) { Date.new(2019, 12, 31) }
111111

112112
context "and eligible for 1st dose" do
113-
let(:patient) { create(:patient, date_of_birth:, session:) }
113+
let(:patient) do
114+
create(:patient, date_of_birth:, session:, parents: [create(:parent)])
115+
end
114116

115117
before do
116118
PatientStatusUpdater.call(patient:)

spec/lib/status_generator/programme_spec.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
consents: patient.consents,
1414
triages: patient.triages,
1515
attendance_record: patient.attendance_records.first,
16-
vaccination_records: patient.vaccination_records.order_by_performed_at
16+
vaccination_records: patient.vaccination_records.order_by_performed_at,
17+
parents: patient.parents.contactable
1718
)
1819
end
1920

2021
let(:programme) { Programme.sample }
2122
let(:session) { create(:session, programmes: [programme]) }
22-
let(:patient) { create(:patient, session:) }
23+
let(:patient) { create(:patient, session:, parents:) }
24+
let(:parents) { [create(:parent)] }
2325
let(:location) { create(:school) }
2426

2527
context "when already vaccinated" do
@@ -368,6 +370,18 @@
368370
its(:vaccine_methods) { should be_nil }
369371
its(:without_gelatine) { should be_nil }
370372

373+
context "when there are no contact details for parents and no consent request has been sent" do
374+
let(:parents) { [create(:parent, :non_contactable)] }
375+
376+
its(:status) { should be(:needs_consent_no_contact_details) }
377+
end
378+
379+
context "when there are no parent relationships and no consent request has been sent" do
380+
let(:parents) { [] }
381+
382+
its(:status) { should be(:needs_consent_no_contact_details) }
383+
end
384+
371385
context "with a multi-dose programme" do
372386
let(:programme) { Programme.mmr }
373387

0 commit comments

Comments
 (0)