Skip to content

Commit 9285136

Browse files
committed
Add AppPatientSessionPsdComponent
Shows a PSD status card ("PSD added" / "PSD not added") on the patient session page, only rendered when the session has PSD enabled.
1 parent 65ed6bc commit 9285136

6 files changed

Lines changed: 97 additions & 14 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<%= render AppCardComponent.new(section: true) do |card| %>
2+
<% card.with_heading(level: 2) { "Patient Specific Directions (PSD)" } %>
3+
4+
<p><%= psd_status %></p>
5+
<% end %>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
class AppPatientSessionPsdComponent < ViewComponent::Base
4+
def initialize(patient:, session:, programme:)
5+
@patient = patient
6+
@session = session
7+
@programme = programme
8+
end
9+
10+
def render?
11+
session.psd_enabled?
12+
end
13+
14+
private
15+
16+
attr_reader :patient, :session, :programme
17+
18+
delegate :academic_year, :team, to: :session
19+
20+
def psd_status
21+
has_patient_specific_direction? ? "PSD added" : "PSD not added"
22+
end
23+
24+
def has_patient_specific_direction?
25+
patient
26+
.patient_specific_directions
27+
.not_invalidated
28+
.for_programme(programme)
29+
.where(team:, academic_year:)
30+
.exists?
31+
end
32+
end

app/views/patient_sessions/_header.html.erb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,6 @@
2727
<%= patient_year_group(@patient, academic_year: @academic_year) %>
2828
</p>
2929

30-
<%= render AppActionListComponent.new do |action_list| %>
31-
<% if @programme && @session.psd_enabled? %>
32-
<% action_list.with_item do %>
33-
<% if @patient.has_patient_specific_direction?(academic_year: @academic_year, programme_type: @programme.type, team: current_team) %>
34-
<%= render AppStatusTagComponent.new(:added, context: :patient_specific_direction) %>
35-
<% else %>
36-
<%= render AppStatusTagComponent.new(:not_added, context: :patient_specific_direction) %>
37-
<% end %>
38-
<% end %>
39-
<% end %>
40-
<% end %>
41-
4230
<%= render AppStickyNavigationComponent.new do %>
4331
<%= render AppSecondaryNavigationComponent.new do |nav|
4432
@session.programmes_for(patient: @patient).each do |programme|

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 AppPatientSessionTriageComponent.new(patient: @patient, session: @session, programme: @programme, current_user:, triage_form: @triage_form) %>
1414

15+
<%= render AppPatientSessionPsdComponent.new(patient: @patient, session: @session, programme: @programme) %>
16+
1517
<%= render AppPatientSessionRegistrationComponent.new(patient: @patient, session: @session) %>
1618

1719
<%= render AppPatientSessionRecordComponent.new(patient: @patient, session: @session, programme: @programme, current_user:, vaccinate_form: @vaccinate_form) %>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# frozen_string_literal: true
2+
3+
describe AppPatientSessionPsdComponent do
4+
subject(:rendered) { render_inline(component) }
5+
6+
let(:component) { described_class.new(patient:, session:, programme:) }
7+
8+
let(:programme) { Programme.flu }
9+
let(:session) { create(:session, :psd_enabled, programmes: [programme]) }
10+
let(:patient) { create(:patient, session:) }
11+
12+
context "when the session does not use PSDs" do
13+
let(:session) { create(:session, programmes: [programme]) }
14+
15+
it "does not render" do
16+
expect(component.render?).to be false
17+
end
18+
end
19+
20+
context "when the session uses PSDs" do
21+
it { should have_heading("Patient Specific Directions (PSD)") }
22+
23+
context "and the patient does not have a PSD" do
24+
it { should have_text("PSD not added") }
25+
end
26+
27+
context "and the patient has a PSD" do
28+
before do
29+
create(
30+
:patient_specific_direction,
31+
patient:,
32+
programme:,
33+
team: session.team,
34+
academic_year: session.academic_year
35+
)
36+
end
37+
38+
it { should have_text("PSD added") }
39+
end
40+
41+
context "and the patient has an invalidated PSD" do
42+
before do
43+
create(
44+
:patient_specific_direction,
45+
:invalidated,
46+
patient:,
47+
programme:,
48+
team: session.team,
49+
academic_year: session.academic_year
50+
)
51+
end
52+
53+
it { should have_text("PSD not added") }
54+
end
55+
end
56+
end

spec/features/triage_required_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,11 @@ def and_the_vaccine_method_is_recorded_as_nasal
456456
end
457457

458458
def then_i_should_see_the_patient_tagged_psd_added
459-
within(".app-action-list") { expect(page).to have_content("PSD added") }
459+
expect(page).to have_content("PSD added")
460460
end
461461

462462
def then_i_should_see_the_patient_tagged_psd_not_added
463-
within(".app-action-list") { expect(page).to have_content("PSD not added") }
463+
expect(page).to have_content("PSD not added")
464464
end
465465

466466
def then_i_should_see_the_patient_with_status_psd_added

0 commit comments

Comments
 (0)