Skip to content

Commit aef6a1c

Browse files
committed
Hide school and year group for some patients
If a patient has aged out of all the programmes administered by the SAIS team, we should no longer show their school or year group. This is necessary because some schools will keep teaching patients beyond the normal vaccination programme year groups (for example year 12s and 13s). We would still want these patients to show in the list of children, but we need to make sure their year group and school are no longer visible. Jira-Issue: MAV-1512
1 parent 468e5dc commit aef6a1c

File tree

13 files changed

+99
-27
lines changed

13 files changed

+99
-27
lines changed

app/components/app_child_summary_component.rb

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
class AppChildSummaryComponent < ViewComponent::Base
44
def initialize(
55
child,
6-
team: nil,
6+
current_team: nil,
77
show_parents: false,
8+
show_school_and_year_group: true,
89
change_links: {},
910
remove_links: {}
1011
)
1112
super
1213

1314
@child = child
14-
@team = team
15+
@current_team = current_team
1516
@show_parents = show_parents
17+
@show_school_and_year_group = show_school_and_year_group
1618
@change_links = change_links
1719
@remove_links = remove_links
1820
end
@@ -72,14 +74,16 @@ def call
7274
row.with_value { format_address }
7375
end
7476
end
75-
summary_list.with_row do |row|
76-
row.with_key { "School" }
77-
row.with_value { format_school }
78-
end
79-
if @child.respond_to?(:year_group)
77+
if @show_school_and_year_group
8078
summary_list.with_row do |row|
81-
row.with_key { "Year group" }
82-
row.with_value { format_year_group }
79+
row.with_key { "School" }
80+
row.with_value { format_school }
81+
end
82+
if @child.respond_to?(:year_group)
83+
summary_list.with_row do |row|
84+
row.with_key { "Year group" }
85+
row.with_value { format_year_group }
86+
end
8387
end
8488
end
8589
if (gp_practice = @child.try(:gp_practice))
@@ -129,7 +133,9 @@ def academic_year = AcademicYear.current
129133

130134
def archive_reason
131135
@archive_reason ||=
132-
(ArchiveReason.find_by(team: @team, patient: @child) if @team)
136+
if @current_team
137+
ArchiveReason.find_by(team: @current_team, patient: @child)
138+
end
133139
end
134140

135141
def format_nhs_number

app/components/app_patient_card_component.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ class AppPatientCardComponent < ViewComponent::Base
2424
<% end %>
2525
2626
<%= render AppChildSummaryComponent.new(
27-
patient, team:, show_parents: true, change_links:, remove_links:
27+
patient,
28+
current_team:,
29+
show_parents: true,
30+
show_school_and_year_group:,
31+
change_links:,
32+
remove_links:
2833
) %>
2934
3035
<%= content %>
@@ -33,21 +38,27 @@ class AppPatientCardComponent < ViewComponent::Base
3338

3439
def initialize(
3540
patient,
36-
team: nil,
41+
current_team:,
3742
change_links: {},
3843
remove_links: {},
3944
heading_level: 3
4045
)
4146
super
4247

4348
@patient = patient
44-
@team = team
49+
@current_team = current_team
4550
@change_links = change_links
4651
@remove_links = remove_links
4752
@heading_level = heading_level
4853
end
4954

5055
private
5156

52-
attr_reader :patient, :team, :change_links, :remove_links, :heading_level
57+
attr_reader :patient,
58+
:current_team,
59+
:change_links,
60+
:remove_links,
61+
:heading_level
62+
63+
def show_school_and_year_group = patient.show_year_group?(team: current_team)
5364
end

app/controllers/programmes/patients_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def index
1212
patients.includes(
1313
:consent_statuses,
1414
:triage_statuses,
15-
:vaccination_statuses
15+
:vaccination_statuses,
16+
school: :location_programme_year_groups
1617
)
1718

1819
@form.academic_year = @academic_year

app/models/patient.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,16 @@ def year_group(academic_year: nil)
326326
birth_academic_year.to_year_group(academic_year:)
327327
end
328328

329-
def year_group_changed?
330-
birth_academic_year_changed?
329+
def year_group_changed? = birth_academic_year_changed?
330+
331+
def show_year_group?(team:, academic_year: nil)
332+
year_group = self.year_group(academic_year:)
333+
programme_year_groups =
334+
school&.programme_year_groups || team.programme_year_groups
335+
336+
team.programmes.any? do |programme|
337+
programme_year_groups[programme].include?(year_group)
338+
end
331339
end
332340

333341
def consent_status(programme:, academic_year:)

app/models/user.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ def selected_organisation
109109
def selected_team
110110
# TODO: Select the right team based on the user's workgroup.
111111
@selected_team ||=
112-
Team.includes(:programmes).find_by(organisation: selected_organisation)
112+
Team.includes(:location_programme_year_groups, :programmes).find_by(
113+
organisation: selected_organisation
114+
)
113115
end
114116

115117
def requires_email_and_password?

app/views/consent_forms/patient.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<%= page_title %>
1111
<% end %>
1212

13-
<%= render AppPatientCardComponent.new(@patient) %>
13+
<%= render AppPatientCardComponent.new(@patient, current_team:) %>
1414

1515
<%= render AppConsentFormCardComponent.new(@consent_form) %>
1616

app/views/patients/edit.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
end,
1818
} %>
1919

20-
<%= render AppPatientCardComponent.new(@patient, change_links:, remove_links:, heading_level: 2) %>
20+
<%= render AppPatientCardComponent.new(@patient, current_team:, change_links:, remove_links:, heading_level: 2) %>
2121

2222
<%= govuk_button_link_to "Continue", patient_path(@patient) %>

app/views/patients/edit/nhs_number_merge.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Updating the NHS number for <%= @patient.full_name %> will merge their record with an existing record:
1414
</p>
1515

16-
<%= render AppPatientCardComponent.new(@existing_patient) %>
16+
<%= render AppPatientCardComponent.new(@existing_patient, current_team:) %>
1717

1818
<%= form_with model: @form, url: edit_nhs_number_merge_patient_path(@patient), method: :put do |f| %>
1919
<%= f.hidden_field :nhs_number %>

app/views/patients/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
nav.with_item(href: log_patient_path(@patient), text: "Activity log")
1515
end %>
1616

17-
<%= render AppPatientCardComponent.new(@patient, team: current_team) do %>
17+
<%= render AppPatientCardComponent.new(@patient, current_team:) do %>
1818
<% if @patient.not_archived?(team: current_user.selected_team) %>
1919
<div class="app-button-group">
2020
<%= govuk_button_link_to "Edit child record", edit_patient_path(@patient), secondary: true %>

app/views/programmes/patients/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
programme: @programme,
3838
academic_year: @academic_year,
3939
triage_status: @form.triage_status,
40-
show_year_group: true,
40+
show_year_group: patient.show_year_group?(team: current_team),
4141
) %>
4242
<% end %>
4343
<% end %>

0 commit comments

Comments
 (0)