Skip to content

Commit 592ac27

Browse files
committed
Add AppTriageTableComponent
This component renders a list of triage notes and replaces the existing `AppTriageNotesComponent` to match the latest designs in the prototype.
1 parent bc98455 commit 592ac27

7 files changed

+111
-153
lines changed

app/components/app_patient_page_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<% if patient.triage_outcome.all[programme].any? %>
1717
<%= render AppCardComponent.new do |c| %>
1818
<% c.with_heading { "Triage notes" } %>
19-
<%= render AppTriageNotesComponent.new(patient_session:, programme:) %>
19+
<%= render AppTriageTableComponent.new(patient_session:, programme:) %>
2020
<% end %>
2121
<% end %>
2222

app/components/app_triage_notes_component.rb

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<%= govuk_table do |table| %>
2+
<% table.with_caption(text: "Triage notes", size: "s") %>
3+
4+
<% table.with_head do |head| %>
5+
<% head.with_row do |row| %>
6+
<% row.with_cell(text: "Date") %>
7+
<% row.with_cell(text: "Note") %>
8+
<% row.with_cell(text: "Outcome") %>
9+
<% end %>
10+
<% end %>
11+
12+
<% table.with_body do |body| %>
13+
<% triages.each do |triage| %>
14+
<% body.with_row do |row| %>
15+
<% row.with_cell do %>
16+
<%= triage.created_at.to_fs(:long) %>
17+
<br />
18+
<span class="nhsuk-u-secondary-text-color nhsuk-u-font-size-16">
19+
<%= triage.performed_by.full_name %>
20+
</span>
21+
<% end %>
22+
23+
<% row.with_cell(text: triage.notes) %>
24+
25+
<% row.with_cell(text: helpers.triage_outcome(triage)) %>
26+
<% end %>
27+
<% end %>
28+
<% end %>
29+
<% end %>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
class AppTriageTableComponent < ViewComponent::Base
4+
def initialize(patient_session:, programme:)
5+
super
6+
7+
@patient_session = patient_session
8+
@programme = programme
9+
end
10+
11+
def render?
12+
triages.any?
13+
end
14+
15+
private
16+
17+
attr_reader :patient_session, :programme
18+
19+
delegate :patient, :session, to: :patient_session
20+
21+
def triages
22+
@triages ||=
23+
patient.triage_outcome.all[programme].sort_by(&:created_at).reverse
24+
end
25+
end

app/helpers/triages_helper.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module TriagesHelper
4+
def triage_outcome(triage)
5+
if triage.invalidated?
6+
safe_join([tag.s(triage.human_enum_name(:status)), "Invalid"], tag.br)
7+
else
8+
triage.human_enum_name(:status)
9+
end
10+
end
11+
end

spec/components/app_triage_notes_component_spec.rb

Lines changed: 0 additions & 90 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
describe AppTriageTableComponent do
4+
let(:component) { described_class.new(patient_session:, programme:) }
5+
6+
let(:programme) { create(:programme) }
7+
let(:patient_session) { create(:patient_session, programmes: [programme]) }
8+
let(:patient) { patient_session.patient }
9+
10+
before { patient.strict_loading!(false) }
11+
12+
describe "#render?" do
13+
subject(:render?) { component.render? }
14+
15+
it { should be(false) }
16+
17+
context "with a triage response" do
18+
before { create(:triage, patient:, programme:) }
19+
20+
it { should be(true) }
21+
end
22+
end
23+
24+
describe "rendered component" do
25+
subject { render_inline(component) }
26+
27+
context "triaged as safe to vaccinate" do
28+
let!(:triage) do
29+
create(:triage, :ready_to_vaccinate, patient:, programme:)
30+
end
31+
32+
it { should have_css("caption", text: "Triage notes") }
33+
it { should have_content("Safe to vaccinate") }
34+
it { should have_content(triage.performed_by.full_name) }
35+
end
36+
37+
context "triaged as unsafe to vaccinate" do
38+
let!(:triage) { create(:triage, :do_not_vaccinate, patient:, programme:) }
39+
40+
it { should have_css("caption", text: "Triage notes") }
41+
it { should have_content("Do not vaccinate") }
42+
it { should have_content(triage.performed_by.full_name) }
43+
end
44+
end
45+
end

0 commit comments

Comments
 (0)