Skip to content

Commit 33d91ad

Browse files
committed
Extract health answers into its own card on the patient session pagei
Moves answers to health questions out of the consent card into a standalone AppPatientSessionHealthAnswersComponent. The card renders as a warning callout when any health answer is "yes", with the heading including a count of yes responses.
1 parent 17eb909 commit 33d91ad

5 files changed

Lines changed: 126 additions & 11 deletions

File tree

app/components/app_patient_session_consent_component.html.erb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,4 @@
5050
<% end %>
5151
<% end %>
5252

53-
<% if show_health_answers? %>
54-
<hr class="nhsuk-section-break nhsuk-section-break--visible nhsuk-section-break--l">
55-
56-
<h5 class="nhsuk-heading-s nhsuk-u-margin-bottom-2">All answers to health questions</h5>
57-
58-
<%= render AppHealthAnswersSummaryComponent.new(grouped_consents) %>
59-
<% end %>
6053
<% end %>

app/components/app_patient_session_consent_component.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@ def who_refused
129129
grouped_consents.find(&:response_refused?)&.who_responded
130130
end
131131

132-
def show_health_answers?
133-
grouped_consents.any?(&:response_given?)
134-
end
135-
136132
def consent_notifications
137133
patient
138134
.consent_notifications
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# frozen_string_literal: true
2+
3+
class AppPatientSessionHealthAnswersComponent < ViewComponent::Base
4+
erb_template <<~ERB
5+
<% if any_yes_health_answers? %>
6+
<%= render AppWarningCalloutComponent.new(heading:, level: 2) do %>
7+
<%= render AppHealthAnswersSummaryComponent.new(grouped_consents) %>
8+
<% end %>
9+
<% else %>
10+
<%= render AppCardComponent.new(section: true) do |card| %>
11+
<% card.with_heading(level: 2) { heading } %>
12+
<%= render AppHealthAnswersSummaryComponent.new(grouped_consents) %>
13+
<% end %>
14+
<% end %>
15+
ERB
16+
17+
def render? = grouped_consents.any?(&:response_given?)
18+
19+
def initialize(patient:, session:, programme:)
20+
@patient = patient
21+
@session = session
22+
@programme = programme
23+
end
24+
25+
private
26+
27+
attr_reader :patient, :session, :programme
28+
29+
delegate :academic_year, to: :session
30+
31+
def heading
32+
count = yes_health_answers_count
33+
if count.positive?
34+
"All answers to health questions, including #{count} #{"Yes response".pluralize(count)}"
35+
else
36+
"All answers to health questions"
37+
end
38+
end
39+
40+
def yes_health_answers_count
41+
grouped_consents.sum do |consent|
42+
consent.health_answers.count(&:response_yes?)
43+
end
44+
end
45+
46+
def any_yes_health_answers?
47+
grouped_consents.any? do |consent|
48+
consent.health_answers.any?(&:response_yes?)
49+
end
50+
end
51+
52+
def grouped_consents
53+
@grouped_consents ||=
54+
ConsentGrouper.call(
55+
patient
56+
.consents
57+
.for_programme(programme)
58+
.where(academic_year:)
59+
.includes(:consent_form, :parent)
60+
.order(created_at: :desc),
61+
programme_type: programme.type,
62+
academic_year:
63+
)
64+
end
65+
end

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
<%= render AppPatientSessionConsentComponent.new(patient: @patient, session: @session, programme: @programme) %>
1414

15+
<%= render AppPatientSessionHealthAnswersComponent.new(patient: @patient, session: @session, programme: @programme) %>
16+
1517
<%= render AppPatientSessionTriageComponent.new(patient: @patient, session: @session, programme: @programme, current_user:, triage_form: @triage_form) %>
1618

1719
<%= render AppPatientSessionRecordComponent.new(patient: @patient, session: @session, programme: @programme, current_user:, vaccinate_form: @vaccinate_form) %>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# frozen_string_literal: true
2+
3+
describe AppPatientSessionHealthAnswersComponent do
4+
subject(:rendered) { render_inline(component) }
5+
6+
let(:component) { described_class.new(patient:, session:, programme:) }
7+
8+
let(:programme) { Programme.hpv }
9+
let(:session) { create(:session, programmes: [programme]) }
10+
let(:patient) { create(:patient, session:) }
11+
12+
context "without any given consent" do
13+
it { expect(rendered.to_html).to be_blank }
14+
end
15+
16+
context "with refused consent" do
17+
before { create(:consent, :refused, patient:, programme:) }
18+
19+
it { expect(rendered.to_html).to be_blank }
20+
end
21+
22+
context "with given consent, all no health answers" do
23+
before do
24+
create(:consent, :given, :no_contraindications, patient:, programme:)
25+
end
26+
27+
it { should have_css("section", text: "All answers to health questions") }
28+
it { should_not have_css(".nhsuk-card--warning") }
29+
it { should_not have_text("Yes response") }
30+
end
31+
32+
context "with given consent with 1 yes health answer" do
33+
before do
34+
create(:consent, :given, :health_question_notes, patient:, programme:)
35+
end
36+
37+
it { should have_css(".nhsuk-card--warning") }
38+
it { should have_text("including 1 Yes response") }
39+
end
40+
41+
context "with given consent with multiple yes health answers" do
42+
before do
43+
create(
44+
:consent,
45+
:given,
46+
patient:,
47+
programme:,
48+
health_answers: [
49+
HealthAnswer.new(question: "Question 1", response: "yes"),
50+
HealthAnswer.new(question: "Question 2", response: "yes"),
51+
HealthAnswer.new(question: "Question 3", response: "no")
52+
]
53+
)
54+
end
55+
56+
it { should have_css(".nhsuk-card--warning") }
57+
it { should have_text("including 2 Yes responses") }
58+
end
59+
end

0 commit comments

Comments
 (0)