Skip to content

Commit f4eab77

Browse files
authored
Merge pull request #6382 from NHSDigital/follow-up-record-flow
Follow up record flow
2 parents 9dccdf2 + 611470b commit f4eab77

30 files changed

Lines changed: 888 additions & 13 deletions

app/components/app_activity_log_component.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def consent_events
219219
original_response =
220220
if consent.withdrawn?
221221
"given"
222-
elsif consent.follow_up_requested?
222+
elsif consent.follow_up_requested? || consent.follow_up_resolved?
223223
"follow_up_requested"
224224
else
225225
consent.response
@@ -259,7 +259,7 @@ def consent_events
259259
}
260260
end
261261

262-
if consent.invalidated?
262+
if consent.invalidated? && !consent.follow_up_resolved?
263263
events << {
264264
title: "Consent from #{consent.name} invalidated",
265265
at: consent.invalidated_at,
@@ -275,6 +275,16 @@ def consent_events
275275
}
276276
end
277277

278+
if consent.follow_up_resolved?
279+
events << {
280+
title:
281+
"Consent response from #{consent.name} (#{consent.who_responded.downcase_first}) " \
282+
"followed-up: refusal #{consent.follow_up_outcome}",
283+
at: consent.follow_up_resolved_at,
284+
programmes: [consent.programme]
285+
}
286+
end
287+
278288
events
279289
end
280290
end

app/components/app_consent_summary_component.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def initialize(
66
change_links: {},
77
show_email_address: false,
88
show_notes: false,
9+
show_parent_name: false,
910
show_notify_parent: false,
1011
show_phone_number: false,
1112
show_programme: false,
@@ -15,6 +16,7 @@ def initialize(
1516
@change_links = change_links
1617
@show_email_address = show_email_address
1718
@show_notes = show_notes
19+
@show_parent_name = show_parent_name
1820
@show_notify_parent = show_notify_parent
1921
@show_phone_number = show_phone_number
2022
@show_programme = show_programme
@@ -27,6 +29,7 @@ def call = govuk_summary_list(rows:, actions: @change_links.present?)
2729

2830
attr_reader :consent,
2931
:change_links,
32+
:show_parent_name,
3033
:show_phone_number,
3134
:show_email_address,
3235
:show_programme,
@@ -37,12 +40,14 @@ def call = govuk_summary_list(rows:, actions: @change_links.present?)
3740
delegate :programme, to: :consent
3841
delegate :consent_response_tag,
3942
:govuk_summary_list,
43+
:consent_parent_name,
4044
:consent_parent_email,
4145
:consent_parent_phone,
4246
to: :helpers
4347

4448
def rows
4549
[
50+
parent_name_row,
4651
phone_number_row,
4752
email_address_row,
4853
programme_row,
@@ -57,6 +62,12 @@ def rows
5762
].compact
5863
end
5964

65+
def parent_name_row
66+
if show_parent_name && (name = consent_parent_name(consent)).present?
67+
{ key: { text: "Parent" }, value: { text: name } }
68+
end
69+
end
70+
6071
def phone_number_row
6172
if show_phone_number && (phone = consent_parent_phone(consent)).present?
6273
{ key: { text: "Phone number" }, value: { text: phone } }

app/components/app_session_actions_component.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def rows
3030
no_nhs_number_row,
3131
unmatched_consent_row,
3232
no_consent_response_row,
33+
follow_up_requested_row,
3334
conflicting_consent_row,
3435
triage_required_row,
3536
register_attendance_row,
@@ -73,6 +74,24 @@ def no_consent_response_row
7374
generate_row(:children_with_no_consent_response, count:, href:, actions:)
7475
end
7576

77+
def follow_up_requested_row
78+
count =
79+
patients.has_programme_status(
80+
"needs_consent_follow_up_requested",
81+
programme: programmes,
82+
academic_year:
83+
).count
84+
85+
href =
86+
session_patients_path(
87+
session,
88+
programme_status_group: "needs_consent",
89+
programme_statuses: %w[needs_consent_follow_up_requested]
90+
)
91+
92+
generate_row(:children_with_follow_up_requested, count:, href:)
93+
end
94+
7695
def conflicting_consent_row
7796
count =
7897
patients.has_programme_status(

app/controllers/draft_consents_controller.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ def update
4242

4343
@draft_consent.seed_health_questions if current_step == :agree
4444

45-
jump_to("confirm") if @draft_consent.editing? && current_step != :confirm
45+
if @draft_consent.editing? && !@draft_consent.follow_up_flow? &&
46+
current_step != :confirm
47+
jump_to("confirm")
48+
end
4649

4750
reload_steps
4851

@@ -82,6 +85,15 @@ def handle_confirm
8285
PatientStatusUpdater.call(patient: @patient)
8386
end
8487

88+
if (old_consent_id = @draft_consent.follow_up_consent_id)
89+
Consent.find(old_consent_id).resolve_follow_up!(
90+
outcome: :withdrawn,
91+
notes:
92+
"#{@draft_consent.human_enum_name(:response)} in follow-up discussion.",
93+
invalidate: true
94+
)
95+
end
96+
8597
if @draft_consent.send_confirmation?
8698
@consent.notifier.send_confirmation(
8799
session: @session,

app/controllers/patient_sessions/consents_controller.rb

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
class PatientSessions::ConsentsController < PatientSessions::BaseController
44
before_action :set_consent, except: %i[create send_request]
5+
before_action :set_consent_follow_up_form,
6+
only: %i[edit_follow_up update_follow_up]
7+
before_action :set_consent_confirm_refusal_form,
8+
only: %i[edit_confirm_refusal update_confirm_refusal]
9+
before_action :ensure_can_follow_up,
10+
only: %i[
11+
edit_follow_up
12+
update_follow_up
13+
edit_confirm_refusal
14+
update_confirm_refusal
15+
]
516
before_action :ensure_can_withdraw, only: %i[edit_withdraw update_withdraw]
617
before_action :ensure_can_invalidate,
718
only: %i[edit_invalidate update_invalidate]
@@ -51,6 +62,69 @@ def send_request
5162
def show
5263
end
5364

65+
def edit_follow_up
66+
render :follow_up
67+
end
68+
69+
def update_follow_up
70+
@form.assign_attributes(follow_up_params)
71+
72+
if @form.valid?
73+
if @form.decision_stands?
74+
redirect_to confirm_refusal_session_patient_programme_consent_path
75+
else
76+
@draft_consent =
77+
DraftConsent.new(request_session: session, current_user:)
78+
@draft_consent.clear_attributes
79+
@draft_consent.assign_attributes(create_params)
80+
@draft_consent.follow_up_consent_id = @consent.id
81+
@draft_consent.follow_up_flow = true
82+
@draft_consent.new_or_existing_contact = @consent.parent_id.to_s
83+
@draft_consent.route = "phone"
84+
85+
if @draft_consent.save
86+
redirect_to draft_consent_path("agree")
87+
else
88+
render :follow_up, status: :unprocessable_content
89+
end
90+
end
91+
else
92+
render :follow_up, status: :unprocessable_content
93+
end
94+
end
95+
96+
def edit_confirm_refusal
97+
render :confirm_refusal
98+
end
99+
100+
def update_confirm_refusal
101+
@form.assign_attributes(confirm_refusal_params)
102+
103+
if @form.valid?
104+
if @form.confirmed?
105+
@consent.resolve_follow_up!(
106+
outcome: :confirmed,
107+
notes: confirm_refusal_params[:notes].to_s
108+
)
109+
110+
@consent.notifier.send_confirmation(
111+
session: @session,
112+
triage: nil,
113+
sent_by: current_user
114+
)
115+
116+
redirect_to session_patient_programme_consent_path,
117+
flash: {
118+
success: "Consent from #{@consent.name} updated."
119+
}
120+
else
121+
redirect_to session_patient_programme_consent_path
122+
end
123+
else
124+
render :confirm_refusal, status: :unprocessable_content
125+
end
126+
end
127+
54128
def edit_withdraw
55129
render :withdraw
56130
end
@@ -104,16 +178,28 @@ def set_consent
104178
@patient
105179
.consents
106180
.where(academic_year: @session.academic_year)
107-
.includes(:consent_form, :parent, patient: :parent_relationships)
181+
.includes(:consent_form, :parent, :team, patient: :parent_relationships)
108182
.find(params[:id])
109183
end
110184

185+
def set_consent_follow_up_form
186+
@form = ConsentFollowUpForm.new
187+
end
188+
189+
def set_consent_confirm_refusal_form
190+
@form = ConsentConfirmRefusalForm.new
191+
end
192+
111193
def update_patient_status
112194
@consent.invalidate_all_triages_and_patient_specific_directions!
113195

114196
PatientStatusUpdater.call(patient: @patient)
115197
end
116198

199+
def ensure_can_follow_up
200+
redirect_to action: :show unless @consent.can_follow_up?
201+
end
202+
117203
def ensure_can_withdraw
118204
redirect_to action: :show unless @consent.can_withdraw?
119205
end
@@ -131,6 +217,14 @@ def create_params
131217
}
132218
end
133219

220+
def follow_up_params
221+
params.fetch(:consent_follow_up_form, {}).permit(:decision_stands)
222+
end
223+
224+
def confirm_refusal_params
225+
params.fetch(:consent_confirm_refusal_form, {}).permit(:confirmed, :notes)
226+
end
227+
134228
def withdraw_params
135229
params.expect(consent: %i[reason_for_refusal notes]).merge(
136230
response: "refused",

app/controllers/patients_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ def set_programme_statuses
9696
[]
9797
else
9898
Patient::ProgrammeStatus.statuses.keys -
99-
Patient::ProgrammeStatus::NOT_ELIGIBLE_STATUSES.keys -
100-
%w[needs_consent_follow_up_requested]
99+
Patient::ProgrammeStatus::NOT_ELIGIBLE_STATUSES.keys
101100
end
102101
end
103102

app/controllers/schools/patients_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def index
5454
def set_programme_statuses
5555
@programme_statuses =
5656
Patient::ProgrammeStatus.statuses.keys -
57-
Patient::ProgrammeStatus::NOT_ELIGIBLE_STATUSES.keys -
58-
%w[needs_consent_follow_up_requested]
57+
Patient::ProgrammeStatus::NOT_ELIGIBLE_STATUSES.keys
5958
end
6059
end

app/controllers/sessions/base_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def set_session
1717
def set_programme_statuses
1818
@programme_statuses =
1919
Patient::ProgrammeStatus.statuses.keys -
20-
Patient::ProgrammeStatus::NOT_ELIGIBLE_STATUSES.keys -
21-
%w[needs_consent_follow_up_requested]
20+
Patient::ProgrammeStatus::NOT_ELIGIBLE_STATUSES.keys
2221
end
2322
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
class ConsentConfirmRefusalForm
4+
include ActiveModel::Model
5+
include ActiveModel::Attributes
6+
7+
attribute :confirmed, :string
8+
attribute :notes, :string
9+
10+
validates :confirmed,
11+
inclusion: {
12+
in: %w[true false],
13+
message: "Select yes or no"
14+
}
15+
validates :notes, length: { maximum: 1000 }
16+
17+
def confirmed? = confirmed == "true"
18+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
class ConsentFollowUpForm
4+
include ActiveModel::Model
5+
include ActiveModel::Attributes
6+
7+
attribute :decision_stands, :string
8+
9+
validates :decision_stands,
10+
inclusion: {
11+
in: %w[true false],
12+
message: "Select yes or no"
13+
}
14+
15+
def decision_stands? = decision_stands == "true"
16+
end

0 commit comments

Comments
 (0)