Skip to content

Commit 5b21738

Browse files
committed
Add AppGillickAssessmentComponent
This adds a component that renders the table of consent responses, which comes from the existing `AppPatientPageComponent`.
1 parent 3c5d243 commit 5b21738

File tree

5 files changed

+112
-55
lines changed

5 files changed

+112
-55
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<% if gillick_assessment || can_assess? %>
2+
<%= render AppCardComponent.new do |card| %>
3+
<% card.with_heading { "Gillick assessment" } %>
4+
5+
<% if gillick_assessment %>
6+
<% if gillick_assessment.gillick_competent? %>
7+
<p class="app-status app-status--aqua-green">
8+
<svg class="nhsuk-icon nhsuk-icon__tick" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true">
9+
<path d="M18.4 7.8l-8.5 8.4L5.6 12" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="round"></path>
10+
</svg>
11+
Child assessed as Gillick competent
12+
</p>
13+
<% else %>
14+
<p class="app-status app-status--red">
15+
<svg class="nhsuk-icon nhsuk-icon__cross" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true">
16+
<path d="M18.6 6.5c.5.5.5 1.5 0 2l-4 4 4 4c.5.6.5 1.4 0 2-.4.4-.7.4-1 .4-.5 0-.9 0-1.2-.3l-3.9-4-4 4c-.3.3-.5.3-1 .3a1.5 1.5 0 0 1-1-2.4l3.9-4-4-4c-.5-.5-.5-1.4 0-2 .6-.7 1.5-.7 2.2 0l3.9 3.9 4-4c.6-.6 1.4-.6 2 0Z" fill="currentColor"></path>
17+
</svg>
18+
Child assessed as not Gillick competent
19+
</p>
20+
<% end %>
21+
22+
<% if (notes = gillick_assessment.notes).present? %>
23+
<p class="nhsuk-body"><%= notes %></p>
24+
<% end %>
25+
26+
<% if helpers.policy(gillick_assessment).edit? %>
27+
<p class="nhsuk-body">
28+
<%= govuk_button_link_to "Edit Gillick competence",
29+
edit_session_patient_programme_gillick_assessment_path(
30+
session,
31+
patient,
32+
programme,
33+
), class: "app-button--secondary nhsuk-u-margin-bottom-0" %>
34+
</p>
35+
<% end %>
36+
<% elsif can_assess? %>
37+
<p class="nhsuk-body">
38+
<%= govuk_button_link_to "Assess Gillick competence",
39+
edit_session_patient_programme_gillick_assessment_path(
40+
session,
41+
patient,
42+
programme,
43+
), class: "app-button--secondary nhsuk-u-margin-bottom-0" %>
44+
</p>
45+
<% end %>
46+
<% end %>
47+
<% end %>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
class AppGillickAssessmentComponent < ViewComponent::Base
4+
def initialize(patient_session:, programme:)
5+
super
6+
7+
@patient_session = patient_session
8+
@programme = programme
9+
end
10+
11+
private
12+
13+
attr_reader :patient_session, :programme
14+
15+
delegate :patient, :session, to: :patient_session
16+
17+
def gillick_assessment
18+
@gillick_assessment ||= patient_session.gillick_assessment(programme)
19+
end
20+
21+
def can_assess?
22+
patient_session.session.today? && helpers.policy(GillickAssessment).new?
23+
end
24+
end

app/components/app_patient_page_component.html.erb

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,7 @@
1313

1414
<%= render AppPatientCardComponent.new(patient) %>
1515

16-
<% if display_gillick_assessment_card? %>
17-
<%= render AppCardComponent.new do |c| %>
18-
<% c.with_heading { "Gillick assessment" } %>
19-
<% if (gillick_assessment = patient_session.gillick_assessment(programme)) %>
20-
<% if gillick_assessment.gillick_competent? %>
21-
<p class="app-status app-status--aqua-green">
22-
<svg class="nhsuk-icon nhsuk-icon__tick" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true">
23-
<path d="M18.4 7.8l-8.5 8.4L5.6 12" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="round"></path>
24-
</svg>
25-
Child assessed as Gillick competent
26-
</p>
27-
<% else %>
28-
<p class="app-status app-status--red">
29-
<svg class="nhsuk-icon nhsuk-icon__cross" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true">
30-
<path d="M18.6 6.5c.5.5.5 1.5 0 2l-4 4 4 4c.5.6.5 1.4 0 2-.4.4-.7.4-1 .4-.5 0-.9 0-1.2-.3l-3.9-4-4 4c-.3.3-.5.3-1 .3a1.5 1.5 0 0 1-1-2.4l3.9-4-4-4c-.5-.5-.5-1.4 0-2 .6-.7 1.5-.7 2.2 0l3.9 3.9 4-4c.6-.6 1.4-.6 2 0Z" fill="currentColor"></path>
31-
</svg>
32-
Child assessed as not Gillick competent
33-
</p>
34-
<% end %>
35-
36-
<% if (notes = gillick_assessment.notes).present? %>
37-
<p class="nhsuk-body"><%= notes %></p>
38-
<% end %>
39-
40-
<% if helpers.policy(gillick_assessment).edit? %>
41-
<p class="nhsuk-body">
42-
<%= govuk_button_link_to "Edit Gillick competence",
43-
edit_session_patient_programme_gillick_assessment_path(
44-
session,
45-
patient,
46-
programme,
47-
), class: "app-button--secondary nhsuk-u-margin-bottom-0" %>
48-
</p>
49-
<% end %>
50-
<% elsif gillick_assessment_can_be_recorded? %>
51-
<p class="nhsuk-body">
52-
<%= govuk_button_link_to "Assess Gillick competence",
53-
edit_session_patient_programme_gillick_assessment_path(
54-
session,
55-
patient,
56-
programme,
57-
), class: "app-button--secondary nhsuk-u-margin-bottom-0" %>
58-
</p>
59-
<% end %>
60-
<% end %>
61-
<% end %>
16+
<%= render AppGillickAssessmentComponent.new(patient_session:, programme:) %>
6217

6318
<%= render AppCardComponent.new do |c| %>
6419
<% c.with_heading { "Consent" } %>

app/components/app_patient_page_component.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ def display_health_questions?
2727
patient.consent_outcome.latest[programme].any?(&:response_given?)
2828
end
2929

30-
def display_gillick_assessment_card?
31-
patient_session.gillick_assessment(programme) ||
32-
gillick_assessment_can_be_recorded?
33-
end
34-
35-
def gillick_assessment_can_be_recorded?
36-
patient_session.session.today? && helpers.policy(GillickAssessment).new?
37-
end
38-
3930
def default_vaccinate_form
4031
pre_screening = patient_session.pre_screenings.last
4132

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
describe AppGillickAssessmentComponent do
4+
subject(:rendered) { render_inline(component) }
5+
6+
let(:programmes) { [create(:programme, :hpv)] }
7+
let(:vaccine) { programme.vaccines.first }
8+
9+
let(:component) do
10+
described_class.new(patient_session:, programme: programmes.first)
11+
end
12+
13+
before { stub_authorization(allowed: true) }
14+
15+
describe "rendered component" do
16+
subject { render_inline(component) }
17+
18+
let(:patient_session) do
19+
create(
20+
:patient_session,
21+
:session_in_progress,
22+
:gillick_competent,
23+
programmes:
24+
)
25+
end
26+
27+
context "with a nurse user" do
28+
before { stub_authorization(allowed: true) }
29+
30+
it { should have_link("Edit Gillick competence") }
31+
it { should have_heading("Gillick assessment") }
32+
end
33+
34+
context "with an admin user" do
35+
before { stub_authorization(allowed: false) }
36+
37+
it { should_not have_link("Edit Gillick competence") }
38+
end
39+
end
40+
end

0 commit comments

Comments
 (0)