Skip to content

Commit a31551e

Browse files
authored
Merge pull request #6443 from NHSDigital/revert-needs-consent-sub-statuses
Revert "Consent sub-statuses to indicate whether requests have been scheduled or sent"
2 parents 04c84c3 + a2314ff commit a31551e

12 files changed

Lines changed: 22 additions & 426 deletions

File tree

app/controllers/patient_sessions/consents_controller.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,4 @@ def withdraw_params
141141
def invalidate_params
142142
params.expect(consent: :notes).merge(invalidated_at: Time.current)
143143
end
144-
145-
def consent_request_needed?
146-
programme_status =
147-
@patient.programme_status(@programme, academic_year: @academic_year)
148-
149-
programme_status.needs_consent_no_response? ||
150-
programme_status.needs_consent_request_scheduled? ||
151-
programme_status.needs_consent_request_not_scheduled?
152-
end
153144
end

app/lib/patient_status_updater.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,9 @@ def update_programme_statuses!
4646
:attendance_record,
4747
:consents,
4848
:patient,
49+
:patient_locations,
4950
:triages,
50-
:vaccination_records,
51-
:parents,
52-
:consent_notifications,
53-
:notify_log_entries,
54-
patient_locations: {
55-
location: [
56-
:location_programme_year_groups,
57-
{ team_locations: { sessions: :session_programme_year_groups } }
58-
]
59-
}
51+
:vaccination_records
6052
)
6153
.find_in_batches(batch_size: 10_000) do |batch|
6254
batch.each(&:assign)

app/lib/status_generator/programme.rb

Lines changed: 8 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ def initialize(
1616
consents:,
1717
triages:,
1818
attendance_record:,
19-
vaccination_records:,
20-
parents:,
21-
consent_notifications:,
22-
notify_log_entries:
19+
vaccination_records:
2320
)
2421
@programme_type = programme_type
2522
@academic_year = academic_year
@@ -28,10 +25,6 @@ def initialize(
2825
@consents = consents
2926
@triages = triages
3027
@attendance_record = attendance_record
31-
@vaccination_records = vaccination_records
32-
@parents = parents
33-
@consent_notifications = consent_notifications
34-
@notify_log_entries = notify_log_entries
3528

3629
@vaccination_criteria =
3730
VaccinationCriteria.new(
@@ -61,10 +54,6 @@ def status
6154
:cannot_vaccinate_absent
6255
elsif should_be_cannot_vaccinate_do_not_vaccinate?
6356
:cannot_vaccinate_do_not_vaccinate
64-
elsif should_be_needs_consent_no_contact_details?
65-
:needs_consent_no_contact_details
66-
elsif should_be_needs_consent_request_failed?
67-
:needs_consent_request_failed
6857
elsif should_be_needs_consent_no_response?
6958
:needs_consent_no_response
7059
elsif should_be_cannot_vaccinate_delay_vaccination?
@@ -79,6 +68,8 @@ def status
7968
:has_refusal_consent_refused
8069
elsif should_be_needs_consent_follow_up_requested?
8170
:needs_consent_follow_up_requested
71+
elsif should_be_needs_consent_request_failed?
72+
:needs_consent_request_failed
8273
elsif should_be_needs_consent_request_scheduled?
8374
:needs_consent_request_scheduled
8475
elsif should_be_needs_consent_request_not_scheduled?
@@ -169,10 +160,7 @@ def consent_vaccine_methods
169160
:consents,
170161
:triages,
171162
:attendance_record,
172-
:vaccination_criteria,
173-
:parents,
174-
:consent_notifications,
175-
:notify_log_entries
163+
:vaccination_criteria
176164

177165
delegate :vaccinated?,
178166
:vaccinated_vaccination_record,
@@ -207,8 +195,7 @@ def should_be_cannot_vaccinate_do_not_vaccinate?
207195
end
208196

209197
def should_be_needs_consent_no_response?
210-
is_eligible? && consent_notifications_requested? &&
211-
consent_status == :no_response
198+
is_eligible? && consent_status == :no_response
212199
end
213200

214201
def should_be_cannot_vaccinate_delay_vaccination?
@@ -234,49 +221,15 @@ def should_be_needs_consent_follow_up_requested?
234221
end
235222

236223
def should_be_needs_consent_request_failed?
237-
is_eligible? && consent_request_failed?
224+
false # TODO: Implement this status.
238225
end
239226

240227
def should_be_needs_consent_request_scheduled?
241-
is_eligible? && parents_contactable? && !consent_notifications_requested? &&
242-
sessions.any? { it.send_consent_requests_at&.present? }
228+
false # TODO: Implement this status.
243229
end
244230

245231
def should_be_needs_consent_request_not_scheduled?
246-
is_eligible? && parents_contactable? && !consent_notifications_requested? &&
247-
(sessions.empty? || sessions.any? { it.send_consent_requests_at.nil? })
248-
end
249-
250-
def should_be_needs_consent_no_contact_details?
251-
is_eligible? && !parents_contactable?
252-
end
253-
254-
def parents_contactable? = parents.any?
255-
256-
def consent_notifications_requested?
257-
@consent_notifications_requested ||=
258-
consent_notifications.any? do |notification|
259-
notification.programme_types.include?(programme.type) &&
260-
notification.session&.team_location&.academic_year == academic_year
261-
end
262-
end
263-
264-
def consent_request_failed?
265-
date_range = academic_year.to_academic_year_date_range
266-
267-
notify_log_entries.any? do |entry|
268-
next false unless entry.patient_id == patient.id
269-
next false unless date_range.cover?(entry.created_at.to_date)
270-
next false unless notify_log_entry_matches_programme_type?(entry)
271-
272-
entry.delivery_status.to_s.include?("failure")
273-
end
274-
end
275-
276-
def notify_log_entry_matches_programme_type?(entry)
277-
entry.notify_log_entry_programmes.any? do |programme|
278-
programme.programme_type == programme_type
279-
end
232+
false # TODO: Implement this status.
280233
end
281234

282235
def year_group = patient.year_group(academic_year:)
@@ -341,16 +294,4 @@ def triage_generator
341294
vaccination_records:
342295
)
343296
end
344-
345-
def sessions
346-
@sessions ||=
347-
patient_locations.flat_map do |patient_location|
348-
patient_location
349-
.location
350-
.team_locations
351-
.select { it.academic_year == academic_year }
352-
.flat_map(&:sessions)
353-
.select { it.programme_types.include?(programme_type) }
354-
end
355-
end
356297
end

app/models/parent.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ 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-
7067
def self.match_existing(patient:, email:, phone:, full_name:)
7168
if email.present? && (parent = Parent.find_by(email:))
7269
return parent

app/models/patient/programme_status.rb

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,7 @@ class Patient::ProgrammeStatus < ApplicationRecord
3838
belongs_to :location, optional: true
3939

4040
has_many :patient_locations,
41-
-> do
42-
includes(
43-
location: [
44-
:location_programme_year_groups,
45-
{
46-
team_locations: {
47-
sessions: :session_programme_year_groups
48-
}
49-
}
50-
]
51-
)
52-
end,
41+
-> { includes(location: :location_programme_year_groups) },
5342
through: :patient
5443

5544
has_many :consents,
@@ -74,16 +63,6 @@ class Patient::ProgrammeStatus < ApplicationRecord
7463
through: :patient,
7564
source: :attendance_records
7665

77-
has_many :parents, -> { contactable }, through: :patient
78-
79-
has_many :consent_notifications,
80-
-> { request.includes(session: :team_location) },
81-
through: :patient
82-
83-
has_many :notify_log_entries,
84-
-> { consent_request.includes(:notify_log_entry_programmes) },
85-
through: :patient
86-
8766
GROUPS = %w[
8867
not_eligible
8968
needs_consent
@@ -101,8 +80,7 @@ class Patient::ProgrammeStatus < ApplicationRecord
10180
"needs_consent_request_scheduled" => 11,
10281
"needs_consent_request_failed" => 12,
10382
"needs_consent_no_response" => 13,
104-
"needs_consent_follow_up_requested" => 14,
105-
"needs_consent_no_contact_details" => 15
83+
"needs_consent_follow_up_requested" => 14
10684
}.freeze
10785

10886
HAS_REFUSAL_STATUSES = {
@@ -210,10 +188,7 @@ def generator
210188
consents:,
211189
triages:,
212190
attendance_record:,
213-
vaccination_records:,
214-
parents:,
215-
consent_notifications:,
216-
notify_log_entries:
191+
vaccination_records:
217192
)
218193
end
219194
end

config/locales/status.en.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ 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: Needs consent
6160
needs_triage: Needs triage
6261
not_eligible: Not eligible
6362
vaccinated: Vaccinated
@@ -85,7 +84,6 @@ en:
8584
needs_consent_request_failed: blue
8685
needs_consent_request_not_scheduled: blue
8786
needs_consent_request_scheduled: blue
88-
needs_consent_no_contact_details: blue
8987
needs_triage: blue
9088
not_eligible: grey
9189
vaccinated: white
@@ -105,7 +103,6 @@ en:
105103
needs_consent_request_failed: Request failed
106104
needs_consent_request_not_scheduled: Request not scheduled
107105
needs_consent_request_scheduled: Request scheduled
108-
needs_consent_no_contact_details: No contact details
109106
vaccinated_already: Already had the vaccine
110107
vaccinated_fully: Vaccinated
111108
registration:

0 commit comments

Comments
 (0)