Skip to content

Commit 57ea362

Browse files
committed
Use Patient::ConsentStatus
This updates the various parts of the code that relied on the `ConsentOutcome` class to determine the consent status of a patient to instead use the new `Patient::ConsentStatus` model with the status cached.
1 parent 1cafb20 commit 57ea362

37 files changed

+165
-112
lines changed

app/components/app_consent_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<%= render AppConsentStatusComponent.new(patient_session:, programme:) %>
22

3-
<% if patient.consent_outcome.no_response?(programme) %>
3+
<% if consent_status.no_response? %>
44
<% if latest_consent_request %>
55
<p class="nhsuk-body">
66
No-one responded to our requests for consent.

app/components/app_consent_component.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ def latest_consent_request
2727
.first
2828
end
2929

30+
def consent_status
31+
@consent_status ||= patient.consent_status(programme:)
32+
end
33+
3034
def can_send_consent_request?
31-
patient.consent_outcome.no_response?(programme) &&
32-
patient.send_notifications? && session.open_for_consent? &&
33-
patient.parents.any?
35+
consent_status.no_response? && patient.send_notifications? &&
36+
session.open_for_consent? && patient.parents.any?
3437
end
3538

3639
def status_colour(consent)

app/components/app_consent_status_component.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ def initialize(patient_session:, programme:)
99
end
1010

1111
def call
12-
case patient.consent_outcome.status[programme]
13-
when Patient::ConsentOutcome::GIVEN
12+
consent_status = patient.consent_status(programme:)
13+
if consent_status.given?
1414
icon_tick "Consent given", "aqua-green"
15-
when Patient::ConsentOutcome::REFUSED
15+
elsif consent_status.refused?
1616
icon_cross "Consent refused", "red"
17-
when Patient::ConsentOutcome::CONFLICTS
17+
elsif consent_status.conflicts?
1818
icon_cross "Conflicting consent", "dark-orange"
1919
end
2020
end

app/components/app_patient_session_search_result_card_component.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,15 @@ def status_tag
8787
render AppRegisterStatusTagComponent.new(
8888
patient_session.register_outcome.status
8989
)
90+
elsif context == :consent
91+
statuses =
92+
patient_session.programmes.index_with do |programme|
93+
patient.consent_status(programme:).status
94+
end
95+
render AppProgrammeStatusTagsComponent.new(statuses, outcome: :consent)
9096
else
9197
outcome =
9298
case context
93-
when :consent
94-
patient.consent_outcome
9599
when :triage
96100
patient.triage_outcome
97101
when :outcome

app/components/app_programme_session_table_component.rb

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,40 @@ def initialize(sessions, programme:)
1313
attr_reader :sessions, :programme
1414

1515
def cohort_count(session:)
16-
session.patient_sessions.length.to_s
16+
format_number(session.patient_sessions.count)
1717
end
1818

1919
def number_stat(session:)
20-
session.patient_sessions.select { yield it }.length.to_s
20+
format_number(session.patient_sessions.select { yield it }.length)
2121
end
2222

2323
def percentage_stat(session:)
24-
total_count = session.patient_sessions.length
25-
return nil if total_count.zero?
26-
27-
count = session.patient_sessions.select { yield it }.length
24+
format_percentage(
25+
session.patient_sessions.select { yield it }.length,
26+
session.patient_sessions.count
27+
)
28+
end
2829

29-
number_to_percentage(count / total_count.to_f * 100.0, precision: 0)
30+
def no_response_scope(session:)
31+
session.patient_sessions.where(
32+
Patient::ConsentStatus
33+
.for_patient_session
34+
.where(programme:)
35+
.no_response
36+
.arel
37+
.exists
38+
)
3039
end
3140

3241
def no_response_count(session:)
33-
number_stat(session:) { it.patient.consent_outcome.no_response?(programme) }
42+
format_number(no_response_scope(session:).count)
3443
end
3544

3645
def no_response_percentage(session:)
37-
percentage_stat(session:) do
38-
it.patient.consent_outcome.no_response?(programme)
39-
end
46+
format_percentage(
47+
no_response_scope(session:).count,
48+
session.patient_sessions.count
49+
)
4050
end
4151

4252
def triage_needed_count(session:)
@@ -50,4 +60,12 @@ def vaccinated_count(session:)
5060
def vaccinated_percentage(session:)
5161
percentage_stat(session:) { it.session_outcome.vaccinated?(programme) }
5262
end
63+
64+
def format_number(count) = count.to_s
65+
66+
def format_percentage(count, total_count)
67+
return nil if total_count.zero?
68+
69+
number_to_percentage(count / total_count.to_f * 100.0, precision: 0)
70+
end
5371
end

app/components/app_session_actions_component.rb

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,18 @@ def rows
3232
end
3333

3434
def no_consent_response_row
35-
consent_row(
36-
text: "No consent response",
37-
status: Patient::ConsentOutcome::NO_RESPONSE
38-
)
35+
consent_row("No consent response", status: "no_response")
3936
end
4037

4138
def conflicting_consent_row
42-
consent_row(
43-
text: "Conflicting consent",
44-
status: Patient::ConsentOutcome::CONFLICTS
45-
)
39+
consent_row("Conflicting consent", status: "conflicts")
4640
end
4741

48-
def consent_row(text:, status:)
42+
def consent_row(text, status:)
4943
count =
50-
patient_sessions.count do
51-
it.patient.consent_outcome.status.values_at(*it.programmes).any?(status)
52-
end
44+
patient_sessions.where(
45+
Patient::ConsentStatus.for_patient.where(status:).arel.exists
46+
).count
5347

5448
return nil if count.zero?
5549

app/components/app_session_details_summary_component.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ def cohort_row
3232
end
3333

3434
def consent_refused_row
35-
status = Patient::ConsentOutcome::REFUSED
3635
count =
37-
patient_sessions.count do
38-
it.patient.consent_outcome.status.values_at(*it.programmes).any?(status)
39-
end
36+
patient_sessions.where(
37+
Patient::ConsentStatus.for_patient_session.refused.arel.exists
38+
).count
39+
4040
href =
41-
session_consent_path(session, search_form: { consent_status: status })
41+
session_consent_path(session, search_form: { consent_status: "refused" })
4242

4343
{
4444
key: {

app/components/app_simple_status_banner_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def description
5252

5353
if patient.triage_outcome.required?(programme)
5454
reasons = [
55-
if patient.triage_outcome.consent_needs_triage?(programme:)
55+
if patient.consent_status(programme:).health_answers_require_follow_up?
5656
I18n.t(
5757
:consent_needs_triage,
5858
scope: %i[

app/controllers/consents_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def create
2626
end
2727

2828
def send_request
29-
return unless @patient.consent_outcome.no_response?(@programme)
29+
return unless @patient.consent_status(programme: @programme).no_response?
3030

3131
# For programmes that are administered together we should send the consent request together.
3232
programmes =

app/controllers/sessions/consent_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Sessions::ConsentController < ApplicationController
1212
layout "full"
1313

1414
def show
15-
@statuses = Patient::ConsentOutcome::STATUSES
15+
@statuses = Patient::ConsentStatus.statuses.keys
1616

1717
scope =
1818
@session.patient_sessions.preload_for_status.in_programmes(

0 commit comments

Comments
 (0)