Skip to content

Commit ec8ab80

Browse files
authored
Merge pull request #5177 from nhsuk/revert-refactor-important-notices
Revert refactor to important notices
2 parents 2faf833 + e1c17fc commit ec8ab80

22 files changed

Lines changed: 317 additions & 809 deletions

app/components/app_imports_navigation_component.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def call
2020
selected: active == :issues
2121
)
2222

23-
if policy(ImportantNotice).index?
23+
if policy(:notices).index?
2424
nav.with_item(
2525
href: imports_notices_path,
2626
text: notices_text,
@@ -42,7 +42,7 @@ def issues_text
4242
end
4343

4444
def notices_text
45-
count = policy_scope(ImportantNotice).count
45+
count = ImportantNotices.call(patient_scope: policy_scope(Patient)).length
4646

4747
text_with_count("Important notices", count)
4848
end

app/components/app_notices_table_component.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
<% body.with_row do |row| %>
2020
<% row.with_cell do %>
2121
<span class="nhsuk-table-responsive__heading">Date</span>
22-
<%= notice.recorded_at.to_date.to_fs(:long) %>
22+
<%= notice[:date_time].to_date.to_fs(:long) %>
2323
<% end %>
2424
<% row.with_cell do %>
2525
<span class="nhsuk-table-responsive__heading">Child</span>
26-
<%= link_to notice.patient.full_name, patient_path(notice.patient) %>
26+
<%= link_to notice[:patient].full_name, patient_path(notice[:patient]) %>
2727
<% end %>
2828
<% row.with_cell do %>
2929
<span class="nhsuk-table-responsive__heading">Notice</span>
30-
<%= notice.message %>
30+
<%= notice[:message] %>
3131
<% end %>
3232
<% end %>
3333
<% end %>

app/components/app_patient_card_component.rb

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class AppPatientCardComponent < ViewComponent::Base
66
<% card.with_heading(level: heading_level) { "Child’s details" } %>
77
88
<% important_notices.each do |notice| %>
9-
<%= render AppStatusComponent.new(text: notice) %>
9+
<%= render AppStatusComponent.new(text: notice[:message]) %>
1010
<% end %>
1111
1212
<%= render AppChildSummaryComponent.new(
@@ -46,40 +46,5 @@ def initialize(
4646

4747
def show_school_and_year_group = patient.show_year_group?(team: current_team)
4848

49-
def important_notices
50-
notices = patient.important_notices.where(team_id: current_team.id)
51-
52-
[
53-
(
54-
if patient.restricted?
55-
notices.restricted.order(recorded_at: :desc).first&.message
56-
end
57-
),
58-
(
59-
if patient.invalidated?
60-
notices.invalidated.order(recorded_at: :desc).first&.message
61-
end
62-
),
63-
*notices.deceased.first&.message,
64-
*gillick_no_notify_notices
65-
].compact
66-
end
67-
68-
def gillick_no_notify_notices
69-
no_notify_vaccination_records =
70-
patient.vaccination_records.select do
71-
it.notify_parents == false && it.team == current_team
72-
end
73-
74-
if no_notify_vaccination_records.any?
75-
vaccinations_sentence =
76-
"#{no_notify_vaccination_records.map(&:programme).uniq.map(&:name).to_sentence} " \
77-
"#{"vaccination".pluralize(no_notify_vaccination_records.length)}"
78-
79-
"Child gave consent for #{vaccinations_sentence} under Gillick competence and " \
80-
"does not want their parents to be notified. " \
81-
"These records will not be automatically synced with GP records. " \
82-
"Your team must let the child's GP know they were vaccinated."
83-
end
84-
end
49+
def important_notices = ImportantNotices.call(patient:)
8550
end

app/controllers/dashboard_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class DashboardController < ApplicationController
77

88
def index
99
@notices_count =
10-
(policy_scope(ImportantNotice).count if policy(ImportantNotice).index?)
10+
if policy(:notices).index?
11+
ImportantNotices.call(patient_scope: policy_scope(Patient)).length
12+
end
1113
end
1214
end

app/controllers/imports/notices_controller.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ class Imports::NoticesController < ApplicationController
44
layout "full"
55

66
def index
7-
authorize ImportantNotice
7+
authorize :notices
88

9-
@notices =
10-
policy_scope(ImportantNotice).includes(
11-
vaccination_record: :programme
12-
).order(recorded_at: :desc)
9+
@notices = ImportantNotices.call(patient_scope: policy_scope(Patient))
1310
end
1411
end

app/jobs/important_notice_generator_job.rb

Lines changed: 0 additions & 205 deletions
This file was deleted.

0 commit comments

Comments
 (0)