Skip to content

Commit 41b5d0b

Browse files
authored
Merge pull request #6138 from NHSDigital/child-record-redesign-sessions-per-programme
Child record redesign - sessions per programme
2 parents c8c6b2d + 2eb44ca commit 41b5d0b

6 files changed

Lines changed: 220 additions & 13 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# frozen_string_literal: true
2+
3+
class AppPatientProgrammeSessionTableComponent < ViewComponent::Base
4+
erb_template <<-ERB
5+
<% if sessions.any? %>
6+
<%= govuk_table(html_attributes: { class: "nhsuk-table-responsive" }) do |table| %>
7+
<% table.with_head do |head| %>
8+
<% head.with_row do |row| %>
9+
<% row.with_cell(text: "Location") %>
10+
<% row.with_cell(text: "Session dates") %>
11+
<% row.with_cell(text: "Session outcome") %>
12+
<% end %>
13+
<% end %>
14+
15+
<% table.with_body do |body| %>
16+
<% sessions.each do |session| %>
17+
<% body.with_row do |row| %>
18+
<% row.with_cell do %>
19+
<span class="nhsuk-table-responsive__heading">Location</span>
20+
<%= link_to session.location.name,
21+
session_patient_programme_path(session, patient, programme_type) %>
22+
<% end %>
23+
24+
<% row.with_cell do %>
25+
<span class="nhsuk-table-responsive__heading">Session dates</span>
26+
<ul class="nhsuk-list">
27+
<% session.dates.each do |date| %>
28+
<li><%= date.to_fs(:long) %></li>
29+
<% end %>
30+
</ul>
31+
<% end %>
32+
33+
<% row.with_cell do %>
34+
<span class="nhsuk-table-responsive__heading">Session outcome</span>
35+
<%= session_outcome_tag(session, programme_type) %>
36+
<% end %>
37+
<% end %>
38+
<% end %>
39+
<% end %>
40+
<% end %>
41+
<% else %>
42+
<p class="nhsuk-body">No sessions</p>
43+
<% end %>
44+
ERB
45+
46+
def initialize(patient, current_team:, programme_type:)
47+
@patient = patient
48+
@current_team = current_team
49+
@programme_type = programme_type
50+
end
51+
52+
private
53+
54+
attr_reader :patient, :current_team, :programme_type
55+
56+
delegate :govuk_table, to: :helpers
57+
58+
def sessions
59+
@sessions ||=
60+
patient
61+
.sessions
62+
.for_team(current_team)
63+
.has_any_programme_types_of(programme_type)
64+
.includes(:location, :session_programme_year_groups)
65+
end
66+
67+
def session_outcome_tag(session, programme_type)
68+
vaccination_record =
69+
session
70+
.vaccination_records
71+
.where(programme_type:, patient:)
72+
.order(:performed_at_date, :performed_at_time)
73+
.last
74+
return "No outcome" unless vaccination_record
75+
76+
helpers.vaccination_record_status_tag(vaccination_record)
77+
end
78+
end

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@
1515
@patient, academic_year: AcademicYear.current, show_caption: false, programme: @programme,
1616
) %>
1717
<% end %>
18+
19+
<%= render AppCardComponent.new(section: true) do |card| %>
20+
<% card.with_heading { "Sessions" } %>
21+
<%= render AppPatientProgrammeSessionTableComponent.new(@patient, current_team:, programme_type: @programme.type) %>
22+
<% end %>

app/views/patients/show.html.erb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@
4949
) %>
5050
<% end %>
5151

52-
<%= render AppCardComponent.new(section: true) do |card| %>
53-
<% card.with_heading { "Sessions" } %>
54-
<%= render AppPatientSessionTableComponent.new(@patient, current_team:) %>
52+
<% unless Flipper.enabled?(:child_record_redesign) %>
53+
<%= render AppCardComponent.new(section: true) do |card| %>
54+
<% card.with_heading { "Sessions" } %>
55+
<%= render AppPatientSessionTableComponent.new(@patient, current_team:) %>
5556

56-
<% unless @in_generic_clinic %>
57-
<%= govuk_button_to "Invite to community clinic", invite_to_clinic_patient_path(@patient), secondary: true %>
57+
<% unless @in_generic_clinic %>
58+
<%= govuk_button_to "Invite to community clinic", invite_to_clinic_patient_path(@patient), secondary: true %>
59+
<% end %>
5860
<% end %>
5961
<% end %>
6062

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# frozen_string_literal: true
2+
3+
describe AppPatientProgrammeSessionTableComponent do
4+
subject { render_inline(component) }
5+
6+
let(:component) do
7+
described_class.new(patient, current_team: team, programme_type:)
8+
end
9+
let(:programme_type) { :hpv }
10+
let(:team) { create(:team) }
11+
12+
context "without a session" do
13+
let(:patient) { create(:patient) }
14+
15+
it { should have_content("No sessions") }
16+
end
17+
18+
context "with one session" do
19+
let(:programmes) { [Programme.hpv, Programme.mmr] }
20+
21+
let(:location) do
22+
create(:school, name: "Waterloo Road", programmes:, academic_year: 2024)
23+
end
24+
let(:session) do
25+
create(
26+
:session,
27+
team:,
28+
location:,
29+
programmes:,
30+
date: Date.new(2025, 1, 1)
31+
)
32+
end
33+
34+
# Can't use year_group here because we need an absolute date, not one
35+
# relative to the current academic year.
36+
let(:patient) { create(:patient, date_of_birth: Date.new(2011, 9, 1)) }
37+
38+
before { create_list(:patient_location, 1, patient:, session:) }
39+
40+
it { should have_link("Waterloo Road") }
41+
it { should have_content("1 January 2025") }
42+
43+
context "with multiple sessions" do
44+
let(:other_location) do
45+
create(
46+
:school,
47+
name: "Paddington Road",
48+
programmes: other_programmes,
49+
academic_year: 2024
50+
)
51+
end
52+
let(:other_session) do
53+
create(
54+
:session,
55+
team:,
56+
location: other_location,
57+
programmes: other_programmes,
58+
date: Date.new(2025, 2, 1)
59+
)
60+
end
61+
let(:other_programmes) { [Programme.hpv, Programme.menacwy] }
62+
63+
before do
64+
create(:patient_location, patient:, session: other_session)
65+
create(
66+
:vaccination_record,
67+
patient:,
68+
session:,
69+
outcome: :administered,
70+
performed_at_date: 1.month.ago,
71+
programme_type:
72+
)
73+
create(
74+
:vaccination_record,
75+
patient:,
76+
session:,
77+
outcome: :refused,
78+
performed_at_date: 1.year.ago,
79+
programme_type:
80+
)
81+
end
82+
83+
it { should have_link("Waterloo Road") }
84+
it { should have_content("1 January 2025") }
85+
it { should have_content("Vaccinated") }
86+
87+
it { should have_link("Paddington Road") }
88+
it { should have_content("1 February 2025") }
89+
it { should have_content("No outcome") }
90+
91+
context "with a programme type filter that matches only one session" do
92+
let(:component) do
93+
described_class.new(
94+
patient,
95+
current_team: team,
96+
programme_type: :menacwy
97+
)
98+
end
99+
100+
it { should_not have_link("Waterloo Road") }
101+
it { should have_link("Paddington Road") }
102+
end
103+
end
104+
end
105+
end

spec/components/app_patient_session_table_component_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
end
1515

1616
context "with a session" do
17-
let(:programmes) { [Programme.hpv] }
17+
let(:programmes) { [Programme.hpv, Programme.mmr] }
1818

1919
let(:location) do
2020
create(:school, name: "Waterloo Road", programmes:, academic_year: 2024)

spec/features/viewing_child_records_spec.rb

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
and_i_can_only_see_tabs_for_relevant_programmes
2020

2121
when_i_click_on_the_flu_tab
22-
then_i_see_the_childs_flu_information
22+
then_i_see_the_childs_flu_vaccinations
23+
and_i_see_the_childs_flu_sessions
2324
and_the_flu_tab_is_selected
2425

2526
when_i_click_on_the_hpv_tab
26-
then_i_see_the_childs_hpv_information
27+
then_i_see_the_childs_hpv_vaccinations
28+
and_i_see_the_childs_hpv_sessions
2729
and_the_hpv_tab_is_selected
2830
end
2931

@@ -88,6 +90,7 @@ def and_patients_exist
8890
def and_the_patient_is_vaccinated
8991
create(
9092
:vaccination_record,
93+
outcome: :administered,
9194
patient: @patient,
9295
programme: @hpv,
9396
session: @session
@@ -134,10 +137,9 @@ def when_i_click_on_the_flu_tab
134137
click_on "Flu"
135138
end
136139

137-
def then_i_see_the_childs_flu_information
140+
def then_i_see_the_childs_flu_vaccinations
138141
expect(page).to have_current_path(patient_programme_path(@patient, "flu"))
139142
expect(page).to have_css("h3.nhsuk-card__heading", text: "Vaccinations")
140-
expect(page).to have_css(".nhsuk-body", text: "No vaccinations")
141143
end
142144

143145
def and_the_flu_tab_is_selected
@@ -148,14 +150,29 @@ def when_i_click_on_the_hpv_tab
148150
click_on "HPV"
149151
end
150152

151-
def then_i_see_the_childs_hpv_information
153+
def then_i_see_the_childs_hpv_vaccinations
152154
expect(page).to have_current_path(patient_programme_path(@patient, "hpv"))
153155
expect(page).to have_css("h3.nhsuk-card__heading", text: "Vaccinations")
154-
expect(page).to have_css(".nhsuk-table__cell", text: "Recorded in Mavis")
155-
expect(page).to have_css(".nhsuk-table__cell", text: "Vaccinated")
156156
end
157157

158158
def and_the_hpv_tab_is_selected
159159
expect(page).to have_css(".app-secondary-navigation__current", text: "HPV")
160160
end
161+
162+
def and_i_see_the_childs_flu_sessions
163+
within(".nhsuk-card", text: "Sessions") do
164+
expect(page).to have_content("No sessions")
165+
end
166+
end
167+
168+
def and_i_see_the_childs_hpv_sessions
169+
within(".nhsuk-card", text: "Sessions") do
170+
expect(page).to have_link(
171+
@session.location.name,
172+
href: session_patient_programme_path(@session, @patient, "hpv")
173+
)
174+
expect(page).to have_content(@session.dates.first.to_fs(:long))
175+
expect(page).to have_content("Vaccinated")
176+
end
177+
end
161178
end

0 commit comments

Comments
 (0)