Skip to content

Commit c63739e

Browse files
murugaplthomasleese
authored andcommitted
Show consent actions on the summary card
Move follow-up, withdraw, and invalidate action links from the consent show page's action list into the consent card heading, so nurses can act directly from the patient session page without clicking through first. Action link logic is defined once in the consent helper and is shared by both the card component and the show page.
1 parent f86a194 commit c63739e

5 files changed

Lines changed: 103 additions & 22 deletions

File tree

app/components/app_card_component.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ class AppCardComponent < ViewComponent::Base
4141
def initialize(
4242
colour: nil,
4343
link_to: nil,
44+
clickable: nil,
4445
feature: false,
4546
secondary: false,
4647
compact: false,
4748
filters: false,
4849
section: false
4950
)
5051
@link_to = link_to
52+
@clickable = clickable.nil? ? link_to.present? : clickable
5153
@colour = colour
5254
@feature = filters || feature
5355
@secondary = secondary
@@ -63,7 +65,7 @@ def top_level_tag = @section ? "section" : "div"
6365
def card_classes
6466
[
6567
"nhsuk-card",
66-
("nhsuk-card--clickable" if @link_to.present?),
68+
("nhsuk-card--clickable" if @clickable),
6769
("nhsuk-card--feature" if @feature),
6870
("nhsuk-card--secondary" if @secondary),
6971
"app-card",

app/components/app_consent_card_component.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def initialize(consent, session:)
88

99
def call
1010
render AppCardComponent.new(**card_options) do |card|
11-
card.with_heading(level: 6) { heading }
11+
card.with_heading(level: 6, actions:) { heading }
1212
render AppConsentSummaryComponent.new(
1313
consent,
1414
show_email_address: true,
@@ -28,7 +28,8 @@ def link_to
2828
session_patient_programme_consent_path(session, patient, programme, consent)
2929
end
3030

31-
def card_options = { link_to:, colour: "offset", compact: true }
31+
def card_options =
32+
{ link_to:, clickable: false, colour: "offset", compact: true }
3233

3334
def heading
3435
if consent.via_self_consent?
@@ -37,4 +38,8 @@ def heading
3738
"#{consent.name} (#{consent.who_responded})"
3839
end
3940
end
41+
42+
def actions
43+
helpers.consent_action_links(consent, session:)
44+
end
4045
end

app/helpers/consents_helper.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,53 @@ def consent_response_tag(consent)
9696
end
9797
end
9898

99+
def consent_action_links(consent, session:)
100+
patient = consent.patient
101+
programme = consent.programme
102+
103+
follow_up_link =
104+
if consent.can_follow_up?
105+
{
106+
text: "Follow up",
107+
href:
108+
follow_up_session_patient_programme_consent_path(
109+
session,
110+
patient,
111+
programme,
112+
consent
113+
)
114+
}
115+
end
116+
withdraw_link =
117+
if consent.can_withdraw?
118+
{
119+
text: "Withdraw consent",
120+
href:
121+
withdraw_session_patient_programme_consent_path(
122+
session,
123+
patient,
124+
programme,
125+
consent
126+
)
127+
}
128+
end
129+
invalidate_link =
130+
if consent.can_invalidate?
131+
{
132+
text: "Mark as invalid",
133+
href:
134+
invalidate_session_patient_programme_consent_path(
135+
session,
136+
patient,
137+
programme,
138+
consent
139+
)
140+
}
141+
end
142+
143+
[follow_up_link, withdraw_link, invalidate_link].compact
144+
end
145+
99146
def consent_parent_name(consentable)
100147
consentable.parent_full_name.presence ||
101148
(consentable.respond_to?(:parent) ? consentable.parent&.full_name : nil)

app/views/patient_sessions/consents/show.html.erb

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,8 @@
55
<%= h1 "Consent response from #{@consent.name}" %>
66

77
<%= render AppActionListComponent.new do |action_list| %>
8-
<% if @consent.can_follow_up? %>
9-
<% action_list.with_item(
10-
text: "Follow up",
11-
href: follow_up_session_patient_programme_consent_path,
12-
) %>
13-
<% end %>
14-
15-
<% if @consent.can_withdraw? %>
16-
<% action_list.with_item(
17-
text: "Withdraw consent",
18-
href: withdraw_session_patient_programme_consent_path,
19-
) %>
20-
<% end %>
21-
22-
<% if @consent.can_invalidate? %>
23-
<% action_list.with_item(
24-
text: "Mark as invalid",
25-
href: invalidate_session_patient_programme_consent_path,
26-
) %>
8+
<% consent_action_links(@consent, session: @session).each do |action| %>
9+
<% action_list.with_item(**action) %>
2710
<% end %>
2811
<% end %>
2912

spec/components/app_consent_card_component_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,50 @@
3939
it { should have_content("Response") }
4040
it { should have_content("Consent given") }
4141

42+
describe "actions" do
43+
context "when consent is given" do
44+
it { should have_link("Withdraw consent") }
45+
it { should have_link("Mark as invalid") }
46+
it { should_not have_link("Follow up") }
47+
end
48+
49+
context "when follow-up is requested" do
50+
let(:consent) do
51+
create(
52+
:consent,
53+
:follow_up_requested,
54+
patient:,
55+
parent:,
56+
programme:,
57+
team:,
58+
submitted_at: Time.zone.local(2024, 1, 1)
59+
)
60+
end
61+
62+
it { should have_link("Follow up") }
63+
it { should have_link("Mark as invalid") }
64+
it { should_not have_link("Withdraw consent") }
65+
end
66+
67+
context "when consent is invalidated" do
68+
let(:consent) do
69+
create(
70+
:consent,
71+
:invalidated,
72+
patient:,
73+
parent:,
74+
programme:,
75+
team:,
76+
submitted_at: Time.zone.local(2024, 1, 1)
77+
)
78+
end
79+
80+
it { should_not have_link("Follow up") }
81+
it { should_not have_link("Withdraw consent") }
82+
it { should_not have_link("Mark as invalid") }
83+
end
84+
end
85+
4286
context "with the flu programme" do
4387
let(:programme) { Programme.flu }
4488
let(:consent) { create(:consent, programme:, vaccine_methods: %w[nasal]) }

0 commit comments

Comments
 (0)