Skip to content

Commit 1464136

Browse files
Merge pull request #4176 from nhsuk/show-gillick-no-notify-patients-in-notices
Show gillick-no-notify patients in important notices
2 parents fb72160 + 3d2578f commit 1464136

File tree

8 files changed

+284
-58
lines changed

8 files changed

+284
-58
lines changed

app/assets/stylesheets/components/_status.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
gap: nhsuk-spacing(1);
99

1010
.nhsuk-icon {
11+
flex-shrink: 0;
12+
height: 1.5em;
1113
margin-left: nhsuk-spacing(-1);
1214
margin-top: nhsuk-spacing(-1);
15+
width: 1.5em;
1316
}
1417

1518
&--aqua-green {

app/components/app_notices_table_component.rb

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,39 @@ class AppNoticesTableComponent < ViewComponent::Base
44
def initialize(
55
deceased_patients:,
66
invalidated_patients:,
7-
restricted_patients:
7+
restricted_patients:,
8+
has_vaccination_records_dont_notify_parents_patients:
89
)
910
super
1011

1112
@deceased_patients = deceased_patients
1213
@invalidated_patients = invalidated_patients
1314
@restricted_patients = restricted_patients
15+
@has_vaccination_records_dont_notify_parents_patients =
16+
has_vaccination_records_dont_notify_parents_patients
1417
end
1518

1619
def render?
1720
@deceased_patients.present? || @invalidated_patients.present? ||
18-
@restricted_patients.present?
21+
@restricted_patients.present? ||
22+
@has_vaccination_records_dont_notify_parents_patients.present?
1923
end
2024

2125
private
2226

2327
def notices
24-
(deceased_notices + invalidated_notices + restricted_notices)
25-
.sort_by { _1[:date] }
26-
.reverse
27-
end
28-
29-
def deceased_notices
30-
@deceased_patients.map do |patient|
31-
{
32-
patient:,
33-
date_time: patient.date_of_death_recorded_at,
34-
message: "Record updated with child’s date of death"
35-
}
36-
end
37-
end
38-
39-
def invalidated_notices
40-
@invalidated_patients.map do |patient|
41-
{
42-
patient:,
43-
date_time: patient.invalidated_at,
44-
message: "Record flagged as invalid"
45-
}
46-
end
47-
end
48-
49-
def restricted_notices
50-
@restricted_patients.map do |patient|
51-
{
52-
patient:,
53-
date_time: patient.restricted_at,
54-
message: "Record flagged as sensitive"
55-
}
56-
end
28+
all_patients =
29+
(
30+
@deceased_patients + @invalidated_patients + @restricted_patients +
31+
@has_vaccination_records_dont_notify_parents_patients
32+
).uniq
33+
34+
notices =
35+
all_patients.flat_map do |patient|
36+
helpers
37+
.patient_important_notices(patient)
38+
.map { |notification| notification.merge(patient:) }
39+
end
40+
notices.sort_by { it[:date_time] }.reverse
5741
end
5842
end

app/components/app_patient_card_component.rb

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,9 @@ class AppPatientCardComponent < ViewComponent::Base
44
erb_template <<-ERB
55
<%= render AppCardComponent.new(heading_level:, section: true) do |card| %>
66
<% card.with_heading { "Child’s details" } %>
7-
8-
<% if patient.date_of_death.present? %>
9-
<%= render AppStatusComponent.new(
10-
text: "Record updated with child’s date of death"
11-
) %>
12-
<% end %>
13-
14-
<% if patient.invalidated? %>
15-
<%= render AppStatusComponent.new(
16-
text: "Record flagged as invalid"
17-
) %>
18-
<% end %>
19-
20-
<% if patient.restricted? %>
21-
<%= render AppStatusComponent.new(
22-
text: "Record flagged as sensitive"
23-
) %>
7+
8+
<% helpers.patient_important_notices(patient).each do |notification| %>
9+
<%= render AppStatusComponent.new(text: notification[:message]) %>
2410
<% end %>
2511
2612
<%= render AppChildSummaryComponent.new(

app/controllers/imports/notices_controller.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@ class Imports::NoticesController < ApplicationController
66
def index
77
authorize :notices
88

9-
@deceased_patients = policy_scope(Patient).deceased
10-
@invalidated_patients = policy_scope(Patient).invalidated
11-
@restricted_patients = policy_scope(Patient).restricted
9+
@deceased_patients =
10+
policy_scope(Patient).deceased.includes(vaccination_records: :programme)
11+
@invalidated_patients =
12+
policy_scope(Patient).invalidated.includes(
13+
vaccination_records: :programme
14+
)
15+
@restricted_patients =
16+
policy_scope(Patient).restricted.includes(vaccination_records: :programme)
17+
@has_vaccination_records_dont_notify_parents_patients =
18+
policy_scope(
19+
Patient
20+
).has_vaccination_records_dont_notify_parents.includes(
21+
vaccination_records: :programme
22+
)
1223
end
1324
end

app/helpers/patients_helper.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,51 @@ def patient_year_group(patient, academic_year:)
5252
def patient_parents(patient)
5353
format_parents_with_relationships(patient.parent_relationships)
5454
end
55+
56+
def patient_important_notices(patient)
57+
notifications = []
58+
59+
if patient.deceased?
60+
notifications << {
61+
date_time: patient.date_of_death_recorded_at,
62+
message: "Record updated with child’s date of death"
63+
}
64+
end
65+
66+
if patient.invalidated?
67+
notifications << {
68+
date_time: patient.invalidated_at,
69+
message: "Record flagged as invalid"
70+
}
71+
end
72+
73+
if patient.restricted?
74+
notifications << {
75+
date_time: patient.restricted_at,
76+
message: "Record flagged as sensitive"
77+
}
78+
end
79+
80+
no_notify_vaccination_records =
81+
patient.vaccination_records.select { it.notify_parents == false }
82+
if no_notify_vaccination_records.any?
83+
notifications << {
84+
date_time: no_notify_vaccination_records.maximum(:performed_at),
85+
message:
86+
"Child gave consent for #{format_vaccinations(no_notify_vaccination_records)} under Gillick competence and " \
87+
"does not want their parents to be notified. " \
88+
"These records will not be automatically synced with GP records. " \
89+
"Your team must let the child's GP know they were vaccinated."
90+
}
91+
end
92+
93+
notifications.sort_by { |notification| notification[:date_time] }.reverse
94+
end
95+
96+
private
97+
98+
def format_vaccinations(vaccination_records)
99+
"#{vaccination_records.map(&:programme).map(&:name).to_sentence} " \
100+
"#{"vaccination".pluralize(vaccination_records.length)}"
101+
end
55102
end

app/models/patient.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,22 @@ class Patient < ApplicationRecord
122122
scope :not_deceased, -> { where(date_of_death: nil) }
123123
scope :restricted, -> { where.not(restricted_at: nil) }
124124

125-
scope :with_notice, -> { deceased.or(restricted).or(invalidated) }
125+
scope :has_vaccination_records_dont_notify_parents,
126+
-> do
127+
joins(:vaccination_records).where(
128+
vaccination_records: {
129+
notify_parents: false
130+
}
131+
).distinct
132+
end
133+
134+
scope :with_notice,
135+
-> do
136+
(
137+
deceased + restricted + invalidated +
138+
has_vaccination_records_dont_notify_parents
139+
).uniq
140+
end
126141

127142
scope :appear_in_programmes,
128143
->(programmes, academic_year:) do

app/views/imports/notices/index.html.erb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44

55
<%= render AppImportsNavigationComponent.new(active: :notices) %>
66

7-
<% if @deceased_patients.any? || @invalidated_patients.any? || @restricted_patients.any? %>
8-
<%= render AppNoticesTableComponent.new(deceased_patients: @deceased_patients, invalidated_patients: @invalidated_patients, restricted_patients: @restricted_patients) %>
7+
<% if @deceased_patients.any? || @invalidated_patients.any? || @restricted_patients.any? || @has_vaccination_records_dont_notify_parents_patients.any? %>
8+
<%= render AppNoticesTableComponent.new(
9+
deceased_patients: @deceased_patients,
10+
invalidated_patients: @invalidated_patients,
11+
restricted_patients: @restricted_patients,
12+
has_vaccination_records_dont_notify_parents_patients: @has_vaccination_records_dont_notify_parents_patients,
13+
) %>
914
<% else %>
1015
<p class="nhsuk-body"><%= t(".no_results") %></p>
1116
<% end %>

0 commit comments

Comments
 (0)