Skip to content

Commit

Permalink
Add important notices
Browse files Browse the repository at this point in the history
This adds the ability to show important notices, which at the moment
refers to patients who have died since they were added in to the
service.
  • Loading branch information
thomasleese committed Oct 17, 2024
1 parent 8b5b214 commit eb3203e
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 7 deletions.
31 changes: 31 additions & 0 deletions app/components/app_notices_table_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div class="nhsuk-table__panel-with-heading-tab">
<h3 class="nhsuk-table__heading-tab">
<%= pluralize(deceased_patients.count, "notice") %>
</h3>

<%= govuk_table(html_attributes: {
class: "nhsuk-table-responsive",
}) do |table| %>
<% table.with_head do |head| %>
<% head.with_row do |row| %>
<% row.with_cell(text: "Child") %>
<% row.with_cell(text: "Notice") %>
<% end %>
<% end %>
<% table.with_body do |body| %>
<% deceased_patients.each do |deceased_patient| %>
<% body.with_row do |row| %>
<% row.with_cell do %>
<span class="nhsuk-table-responsive__heading">Child</span>
<%= link_to deceased_patient.full_name, patient_path(deceased_patient) %>
<% end %>
<% row.with_cell do %>
<span class="nhsuk-table-responsive__heading">Notice</span>
Record updated with child’s date of death
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
</div>
17 changes: 17 additions & 0 deletions app/components/app_notices_table_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

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

@deceased_patients = deceased_patients
end

def render?
deceased_patients.present?
end

private

attr_reader :deceased_patients
end
13 changes: 13 additions & 0 deletions app/components/app_patient_summary_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def call
row.with_key { "Date of birth" }
row.with_value { format_date_of_birth }
end
if @patient.deceased?
summary_list.with_row do |row|
row.with_key { "Date of death" }
row.with_value { format_date_of_death }
end
end
summary_list.with_row do |row|
row.with_key { "Gender" }
row.with_value { format_gender_code }
Expand Down Expand Up @@ -93,6 +99,13 @@ def format_date_of_birth
)
end

def format_date_of_death
highlight_if(
@patient.date_of_death.to_fs(:long),
@patient.date_of_death_changed?
)
end

def format_gender_code
highlight_if(
@patient.gender_code.to_s.humanize,
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/cohorts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def index

def show
@cohort = policy_scope(Cohort).find(params[:id])
@pagy, @patients = pagy(@cohort.patients.includes(:school).order_by_name)
@pagy, @patients =
pagy(@cohort.patients.not_deceased.includes(:school).order_by_name)
end

private
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/notices_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class NoticesController < ApplicationController
layout "full"

def index
@deceased_patients = policy_scope(Patient).deceased
end
end
2 changes: 1 addition & 1 deletion app/controllers/patients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class PatientsController < ApplicationController
include Pagy::Backend

def index
@pagy, @patients = pagy(policy_scope(Patient).order_by_name)
@pagy, @patients = pagy(policy_scope(Patient).not_deceased.order_by_name)

render layout: "full"
end
Expand Down
3 changes: 3 additions & 0 deletions app/models/patient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class Patient < ApplicationRecord

scope :without_nhs_number, -> { where(nhs_number: [nil, ""]) }

scope :not_deceased, -> { where(date_of_death: nil) }
scope :deceased, -> { where.not(date_of_death: nil) }

validates :given_name, :family_name, :date_of_birth, presence: true

validates :nhs_number,
Expand Down
9 changes: 4 additions & 5 deletions app/models/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,10 @@ def create_patient_sessions!
cohorts = team.cohorts.for_year_groups(year_groups, academic_year:)

patients_in_cohorts =
Patient.where(
cohort: cohorts,
school: location,
date_of_death: nil
).includes(:upcoming_sessions, vaccination_records: :programme)
Patient
.where(cohort: cohorts, school: location)
.not_deceased
.includes(:upcoming_sessions, vaccination_records: :programme)

required_programmes = Set.new(programmes)

Expand Down
6 changes: 6 additions & 0 deletions app/views/application/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
aria: { current: request.path.start_with?(vaccines_path) ?
"true" : nil } %>
</li>
<li class="nhsuk-header__navigation-item app-header__navigation-item--divider">
<%= link_to "Notices", notices_path,
class: "nhsuk-header__navigation-link",
aria: { current: request.path.start_with?(notices_path) ?
"true" : nil } %>
</li>
<li class="nhsuk-header__navigation-item app-header__navigation-item--divider">
<%= link_to t("teams.show.title"), team_path,
class: "nhsuk-header__navigation-link",
Expand Down
3 changes: 3 additions & 0 deletions app/views/notices/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= h1 t("notices.index.title"), size: "xl" %>
<%= render AppNoticesTableComponent.new(deceased_patients: @deceased_patients) %>
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,9 @@ en:
import_issues:
index:
title: Import issues
notices:
index:
title: Important notices
mailers:
consent_form_mailer:
reasons_for_refusal:
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
end
end

resources :notices, only: :index

resources :patients, only: %i[index show]

resources :programmes, only: %i[index show] do
Expand Down
24 changes: 24 additions & 0 deletions spec/features/manage_children_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
then_i_see_the_child
end

scenario "Viewing important notices" do
given_my_team_exists
and_a_deceased_patient_exists

when_i_click_on_notices
then_i_see_the_notice_of_date_of_death
end

def given_my_team_exists
@team = create(:team, :with_one_nurse)
end
Expand All @@ -21,6 +29,10 @@ def and_patients_exist
create_list(:patient, 9, team: @team)
end

def and_a_deceased_patient_exists
@deceased_patient = create(:patient, :deceased, team: @team)
end

def when_i_click_on_children
sign_in @team.users.first

Expand All @@ -40,4 +52,16 @@ def then_i_see_the_child
expect(page).to have_title("JS")
expect(page).to have_content("John Smith")
end

def when_i_click_on_notices
sign_in @team.users.first

visit "/dashboard"
click_on "Notices"
end

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
end

0 comments on commit eb3203e

Please sign in to comment.