Skip to content

Commit 53c575a

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 f2984a8 commit 53c575a

4 files changed

Lines changed: 95 additions & 0 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/programmes/show.html.erb

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

1515
<%= render AppPatientSessionTriageComponent.new(patient: @patient, session: @session, programme: @programme, current_user:, triage_form: @triage_form) %>
1616

17+
<%= render AppPatientSessionPsdComponent.new(patient: @patient, session: @session, programme: @programme) %>
18+
1719
<%= render AppPatientSessionRecordComponent.new(patient: @patient, session: @session, programme: @programme, current_user:, vaccinate_form: @vaccinate_form) %>
1820
</div>
1921
</div>
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

0 commit comments

Comments
 (0)