-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathapp_session_actions_component.rb
More file actions
184 lines (152 loc) · 4.42 KB
/
app_session_actions_component.rb
File metadata and controls
184 lines (152 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# frozen_string_literal: true
class AppSessionActionsComponent < ViewComponent::Base
erb_template <<-ERB
<%= render AppCardComponent.new do |card| %>
<% card.with_heading(level: 3) { "Action required" } %>
<% if rows.any? %>
<%= govuk_summary_list(rows:) %>
<% else %>
<p class="nhsuk-body">No action required</p>
<% end %>
<% end %>
ERB
def initialize(session)
@session = session
end
private
attr_reader :session
delegate :govuk_summary_list, to: :helpers
delegate :academic_year, :programmes, :team, to: :session
def patients = session.patients
def rows
@rows ||= [
no_nhs_number_row,
unmatched_consent_row,
no_consent_response_row,
conflicting_consent_row,
triage_required_row,
register_attendance_row,
ready_for_vaccinator_row
].compact
end
def no_nhs_number_row
count = patients.without_nhs_number.count
href = session_patients_path(session, missing_nhs_number: true)
generate_row(:children_without_nhs_number, count:, href:)
end
def unmatched_consent_row
count = ConsentForm.for_session(session).unmatched.count
href = consent_forms_path(session_slug: @session.slug)
generate_row(:unmatched_responses, count:, href:)
end
def no_consent_response_row
count = session.patients_with_no_consent_response_count
href =
session_patients_path(
session,
programme_status_group: "needs_consent",
programme_statuses: %w[needs_consent_no_response]
)
actions = [
{
text: "Send reminders",
href: session_manage_consent_reminders_path(session)
}
]
generate_row(:children_with_no_consent_response, count:, href:, actions:)
end
def conflicting_consent_row
count =
patients.has_programme_status(
"has_refusal_consent_conflicts",
programme: programmes,
academic_year:
).count
href =
session_patients_path(
session,
programme_status_group: "has_refusal",
programme_statuses: %w[has_refusal_consent_conflicts]
)
generate_row(:children_with_conflicting_consent_response, count:, href:)
end
def triage_required_row
count =
patients.has_programme_status(
"needs_triage",
programme: programmes,
academic_year:
).count
href =
session_patients_path(
session,
programme_status_group: "needs_triage",
programme_statuses: []
)
generate_row(:children_requiring_triage, count:, href:)
end
def register_attendance_row
return nil unless session.requires_registration? && session.today?
status = "unknown"
count = patients.has_registration_status(status, session:).count
href = session_patients_path(session, registration_status: status)
generate_row(:children_to_register, count:, href:)
end
def ready_for_vaccinator_row
return nil unless session.today?
counts_by_programme =
session.programmes.index_with do |programme|
patients
.has_registration_status(%w[attending completed], session:)
.includes_statuses
.count do |patient|
patient.consent_given_and_safe_to_vaccinate?(
programme:,
academic_year:
)
end
end
return nil if counts_by_programme.values.all?(&:zero?)
texts =
if counts_by_programme.values.all?(&:zero?)
["No children"]
else
counts_by_programme.map do |programme, count|
text =
I18n.t(
:children_for_programme,
count:,
programme: programme.name_in_sentence
)
href = session_record_path(session, programme_types: [programme.type])
count.positive? ? helpers.link_to(text, href) : text
end
end
actions =
unless counts_by_programme.values.all?(&:zero?)
[{ text: "Record", href: session_record_path(session) }]
end
{
key: {
text: "Ready for vaccinator"
},
value: {
text: safe_join(texts, tag.br)
},
actions: actions
}
end
def generate_row(key, count:, href: nil, actions: nil)
return nil if count.zero?
{
key: {
text: I18n.t(:title, scope: key)
},
value: {
text:
(href ? helpers.link_to(I18n.t(key, count:), href).html_safe : text)
},
actions:
}
end
end