Skip to content

Commit

Permalink
Show restricted patients in important notices
Browse files Browse the repository at this point in the history
This adds restricted patients to the important notices page shown next
to deceased patients.
  • Loading branch information
thomasleese committed Oct 18, 2024
1 parent 7478042 commit bb855e1
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
10 changes: 5 additions & 5 deletions app/components/app_notices_table_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="nhsuk-table__panel-with-heading-tab">
<h3 class="nhsuk-table__heading-tab">
<%= pluralize(deceased_patients.count, "notice") %>
<%= pluralize(notices.count, "notice") %>
</h3>

<%= govuk_table(html_attributes: {
Expand All @@ -15,19 +15,19 @@
<% end %>
<% table.with_body do |body| %>
<% deceased_patients.each do |deceased_patient| %>
<% notices.each do |notice| %>
<% body.with_row do |row| %>
<% row.with_cell do %>
<span class="nhsuk-table-responsive__heading">Date</span>
<%= deceased_patient.date_of_death_recorded_at.to_date.to_fs(:long) %>
<%= notice[:date_time].to_date.to_fs(:long) %>
<% end %>
<% row.with_cell do %>
<span class="nhsuk-table-responsive__heading">Child</span>
<%= link_to deceased_patient.full_name, patient_path(deceased_patient) %>
<%= link_to notice[:patient].full_name, patient_path(notice[:patient]) %>
<% end %>
<% row.with_cell do %>
<span class="nhsuk-table-responsive__heading">Notice</span>
Record updated with child’s date of death
<%= notice[:message] %>
<% end %>
<% end %>
<% end %>
Expand Down
29 changes: 26 additions & 3 deletions app/components/app_notices_table_component.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
# frozen_string_literal: true

class AppNoticesTableComponent < ViewComponent::Base
def initialize(deceased_patients:)
def initialize(deceased_patients:, restricted_patients:)
super

@deceased_patients = deceased_patients
@restricted_patients = restricted_patients
end

def render?
deceased_patients.present?
@deceased_patients.present? || @restricted_patients.present?
end

private

attr_reader :deceased_patients
def notices
(deceased_notices + restricted_notices).sort_by { _1[:date] }.reverse
end

def deceased_notices
@deceased_patients.map do |patient|
{
patient:,
date_time: patient.date_of_death_recorded_at,
message: "Record updated with child’s date of death"
}
end
end

def restricted_notices
@restricted_patients.map do |patient|
{
patient:,
date_time: patient.restricted_at,
message: "Record flagged as sensitive"
}
end
end
end
1 change: 1 addition & 0 deletions app/controllers/notices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ class NoticesController < ApplicationController

def index
@deceased_patients = policy_scope(Patient).deceased
@restricted_patients = policy_scope(Patient).restricted
end
end
2 changes: 1 addition & 1 deletion app/views/notices/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= h1 t("notices.index.title"), size: "xl" %>
<% if @deceased_patients.any? %>
<%= render AppNoticesTableComponent.new(deceased_patients: @deceased_patients) %>
<%= render AppNoticesTableComponent.new(deceased_patients: @deceased_patients, restricted_patients: @restricted_patients) %>
<% else %>
<p class="nhsuk-body"><%= t("notices.index.no_results") %></p>
<% end %>
11 changes: 11 additions & 0 deletions spec/features/manage_children_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
then_i_see_no_notices

when_a_deceased_patient_exists
and_a_restricted_patient_exists
and_i_click_on_notices
then_i_see_the_notice_of_date_of_death
and_i_see_the_notice_of_sensitive
end

def given_my_team_exists
Expand All @@ -36,6 +38,10 @@ def when_a_deceased_patient_exists
@deceased_patient = create(:patient, :deceased, team: @team)
end

def and_a_restricted_patient_exists
@restricted_patient = create(:patient, :restricted, team: @team)
end

def when_i_click_on_children
sign_in @team.users.first

Expand Down Expand Up @@ -73,4 +79,9 @@ def then_i_see_the_notice_of_date_of_death
expect(page).to have_content(@deceased_patient.full_name)
expect(page).to have_content("Record updated with child’s date of death")
end

def and_i_see_the_notice_of_sensitive
expect(page).to have_content(@restricted_patient.full_name)
expect(page).to have_content("Record flagged as sensitive")
end
end

0 comments on commit bb855e1

Please sign in to comment.