Skip to content

Commit 29460d4

Browse files
committed
Revert "Implement logic needs consent status request scheduled/not scheduled"
This reverts commit 25e876a.
1 parent a80208a commit 29460d4

19 files changed

Lines changed: 62 additions & 380 deletions

app/components/app_patient_search_form_component.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
class AppPatientSearchFormComponent < ViewComponent::Base
44
# Remove these statuses once implemented.
5-
HIDDEN_PROGRAMME_STATUSES = %w[needs_consent_request_failed].freeze
5+
HIDDEN_PROGRAMME_STATUSES = %w[
6+
needs_consent_request_failed
7+
needs_consent_request_not_scheduled
8+
needs_consent_request_scheduled
9+
].freeze
610

711
def initialize(
812
form,

app/components/app_patient_session_consent_component.html.erb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
<p><%= patient.full_name %> is ready for the vaccinator.</p>
2222
<% elsif consent_status_value == :no_contact_details %>
2323
<p>We cannot send consent requests because we have no parent contact details.</p>
24-
<% elsif consent_status_value == :request_not_scheduled %>
25-
<p>No consent request is scheduled to be sent because the child has not been added to a scheduled session.</p>
26-
<% elsif consent_status_value == :request_scheduled %>
27-
<p>A consent request will be sent on <%= session.send_consent_requests_at.to_fs(:long) %>.</p>
2824
<% end %>
2925

3026
<div class="nhsuk-button-group">

app/components/app_patient_session_consent_component.rb

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ def consent_status_generator
6363
patient:,
6464
consents:,
6565
vaccination_records:,
66-
parents:,
67-
sessions: [session],
68-
consent_notifications:
66+
parents:
6967
)
7068
end
7169

@@ -78,14 +76,19 @@ def triage_status_generator
7876
consents:,
7977
triages:,
8078
vaccination_records:,
81-
parents:,
82-
sessions: [session],
83-
consent_notifications:
79+
parents:
8480
)
8581
end
8682

8783
def latest_consent_request
88-
@latest_consent_request ||= consent_notifications.first
84+
@latest_consent_request ||=
85+
patient
86+
.consent_notifications
87+
.request
88+
.has_all_programmes_of([programme])
89+
.for_academic_year(academic_year)
90+
.order(sent_at: :desc)
91+
.first
8992
end
9093

9194
def consents
@@ -113,14 +116,8 @@ def vaccination_records
113116
patient.vaccination_records.for_programme(programme).order_by_performed_at
114117
end
115118

116-
SEND_CONSENT_REQUEST_STATUSES = %i[
117-
no_response
118-
request_scheduled
119-
request_not_scheduled
120-
].freeze
121-
122119
def can_send_consent_request?
123-
consent_status_value.in?(SEND_CONSENT_REQUEST_STATUSES) &&
120+
consent_status_value == :no_response &&
124121
patient.send_notifications?(team: @session.team) &&
125122
session.can_receive_consent? && patient.parents.any?(&:contactable?)
126123
end
@@ -137,13 +134,4 @@ def who_refused
137134
def show_health_answers?
138135
grouped_consents.any?(&:response_given?)
139136
end
140-
141-
def consent_notifications
142-
patient
143-
.consent_notifications
144-
.request
145-
.has_all_programmes_of([programme])
146-
.for_academic_year(academic_year)
147-
.order(sent_at: :desc)
148-
end
149137
end

app/components/app_patient_session_triage_component.rb

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ def initialize(
1414
@current_user = current_user
1515
@triage_form = triage_form || default_triage_form
1616
@parents = patient.parents
17-
@patient_locations =
18-
patient.patient_locations.includes(
19-
location: [
20-
:location_programme_year_groups,
21-
{ team_locations: { sessions: :session_programme_year_groups } }
22-
]
23-
)
2417
end
2518

2619
def render?
@@ -35,8 +28,7 @@ def render?
3528
:programme,
3629
:current_user,
3730
:triage_form,
38-
:parents,
39-
:patient_locations
31+
:parents
4032

4133
delegate :academic_year, :team, to: :session
4234

@@ -85,9 +77,7 @@ def triage_status_generator
8577
consents:,
8678
triages:,
8779
vaccination_records:,
88-
parents:,
89-
sessions: [session],
90-
consent_notifications:
80+
parents:
9181
)
9282
end
9383

@@ -99,9 +89,7 @@ def consent_status_generator
9989
patient:,
10090
consents:,
10191
vaccination_records:,
102-
parents:,
103-
sessions: [session],
104-
consent_notifications:
92+
parents:
10593
)
10694
end
10795

@@ -130,12 +118,4 @@ def latest_triage
130118
def default_triage_form
131119
TriageForm.new(patient:, session:, programme:, current_user:)
132120
end
133-
134-
def consent_notifications
135-
patient
136-
.consent_notifications
137-
.request
138-
.has_all_programmes_of([programme])
139-
.for_academic_year(academic_year)
140-
end
141121
end

app/forms/triage_form.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ def consent_status_generator
130130
patient:,
131131
consents: patient.consents,
132132
vaccination_records: [],
133-
parents: [],
134-
sessions: [],
135-
consent_notifications: []
133+
parents: []
136134
)
137135
end
138136

app/lib/patient_status_updater.rb

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,12 @@ def update_programme_statuses!
4646
:attendance_record,
4747
:consents,
4848
:patient,
49+
:patient_locations,
4950
:triages,
5051
:vaccination_records,
51-
:parents,
52-
:consent_notifications,
53-
patient_locations: {
54-
location: [
55-
{ team_locations: { sessions: :session_programme_year_groups } }
56-
]
57-
}
52+
:parents
5853
)
5954
.find_in_batches do |batch|
60-
preload_location_programme_year_groups(batch)
61-
6255
batch.each(&:assign)
6356

6457
Patient::ProgrammeStatus.import!(
@@ -187,23 +180,4 @@ def programme_types_per_session_id_and_year_group
187180
hash[session_id][year_group] << programme_type
188181
end
189182
end
190-
191-
# We preload this association separately because including it in the nested
192-
# `patient_locations` preload (see includes above) caused the updater process
193-
# to be killed, even with very small batches. The likely cause is memory pressure
194-
# from eager loading a deeply nested association graph.
195-
#
196-
# Preloading it here for the distinct `Location` records in each batch keeps
197-
# `StatusGenerator::Programme` query-free without incurring the cost of the
198-
# larger nested preload.
199-
def preload_location_programme_year_groups(batch)
200-
locations = batch.flat_map(&:patient_locations).map(&:location).uniq
201-
202-
ActiveRecord::Associations::Preloader.new(
203-
records: locations,
204-
associations: {
205-
location_programme_year_groups: :location_year_group
206-
}
207-
).call
208-
end
209183
end

app/lib/status_generator/consent.rb

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@ def initialize(
77
patient:,
88
consents:,
99
vaccination_records:,
10-
parents:,
11-
sessions:,
12-
consent_notifications:
10+
parents:
1311
)
1412
@programme_type = programme_type
1513
@academic_year = academic_year
1614
@patient = patient
1715
@consents = consents
1816
@vaccination_records = vaccination_records
1917
@parents = parents
20-
@sessions = sessions
21-
@consent_notifications = consent_notifications
2218
end
2319

2420
def programme
@@ -36,10 +32,6 @@ def status
3632
:conflicts
3733
elsif status_should_be_no_contact_details?
3834
:no_contact_details
39-
elsif status_should_be_request_scheduled?
40-
:request_scheduled
41-
elsif status_should_be_request_not_scheduled?
42-
:request_not_scheduled
4335
elsif status_should_be_no_response?
4436
:no_response
4537
else
@@ -70,9 +62,7 @@ def disease_types
7062
:patient,
7163
:consents,
7264
:vaccination_records,
73-
:parents,
74-
:sessions,
75-
:consent_notifications
65+
:parents
7666

7767
def vaccinated?
7868
return @vaccinated if defined?(@vaccinated)
@@ -172,21 +162,4 @@ def latest_consents
172162
@latest_consents ||=
173163
ConsentGrouper.call(consents, programme_type:, academic_year:)
174164
end
175-
176-
def parents_contactable? = parents.any?(&:contactable?)
177-
178-
def status_should_be_request_scheduled?
179-
parents_contactable? && consent_notifications.empty? &&
180-
sessions.any? do
181-
# Not using send_consent_requests_at.future?
182-
# because it doesn't work with Timecop.
183-
it.send_consent_requests_at &&
184-
it.send_consent_requests_at > Time.current
185-
end
186-
end
187-
188-
def status_should_be_request_not_scheduled?
189-
parents_contactable? && consent_notifications.empty? &&
190-
(sessions.empty? || sessions.any? { it.send_consent_requests_at.nil? })
191-
end
192165
end

app/lib/status_generator/programme.rb

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ def initialize(
1717
triages:,
1818
attendance_record:,
1919
vaccination_records:,
20-
parents:,
21-
consent_notifications:
20+
parents:
2221
)
2322
@programme_type = programme_type
2423
@academic_year = academic_year
@@ -29,8 +28,6 @@ def initialize(
2928
@attendance_record = attendance_record
3029
@vaccination_records = vaccination_records
3130
@parents = parents
32-
@consent_notifications =
33-
find_matching_consent_notifications(consent_notifications)
3431

3532
@vaccination_criteria =
3633
VaccinationCriteria.new(
@@ -175,8 +172,7 @@ def consent_vaccine_methods
175172
:triages,
176173
:attendance_record,
177174
:vaccination_criteria,
178-
:parents,
179-
:consent_notifications
175+
:parents
180176

181177
delegate :vaccinated?,
182178
:vaccinated_vaccination_record,
@@ -241,11 +237,11 @@ def should_be_needs_consent_request_failed?
241237
end
242238

243239
def should_be_needs_consent_request_scheduled?
244-
is_eligible? && consent_status == :request_scheduled
240+
false # TODO: Implement this status.
245241
end
246242

247243
def should_be_needs_consent_request_not_scheduled?
248-
is_eligible? && consent_status == :request_not_scheduled
244+
false # TODO: Implement this status.
249245
end
250246

251247
def should_be_needs_consent_no_contact_details?
@@ -292,13 +288,6 @@ def default_programme_year_groups
292288
Programme.find(programme_type).default_year_groups
293289
end
294290

295-
def find_matching_consent_notifications(notifications)
296-
notifications.select do |notification|
297-
notification.programme_types.include?(programme_type) &&
298-
notification.session&.team_location&.academic_year == academic_year
299-
end
300-
end
301-
302291
def consent_generator
303292
@consent_generator ||=
304293
StatusGenerator::Consent.new(
@@ -307,9 +296,7 @@ def consent_generator
307296
patient:,
308297
consents:,
309298
vaccination_records:,
310-
parents:,
311-
sessions:,
312-
consent_notifications:
299+
parents:
313300
)
314301
end
315302

@@ -322,23 +309,7 @@ def triage_generator
322309
consents:,
323310
triages:,
324311
vaccination_records:,
325-
parents:,
326-
sessions:,
327-
consent_notifications:
312+
parents:
328313
)
329314
end
330-
331-
def sessions
332-
@sessions ||=
333-
patient_locations
334-
.reject { it.location.generic_clinic? }
335-
.flat_map do |patient_location|
336-
patient_location
337-
.location
338-
.team_locations
339-
.select { it.academic_year == academic_year }
340-
.flat_map(&:sessions)
341-
.select { it.programme_types.include?(programme_type) }
342-
end
343-
end
344315
end

0 commit comments

Comments
 (0)