Skip to content

Commit 769c371

Browse files
committed
Fix content in views when patient moving across teams
We were previously identifying the source team through the patient's school. This won't work when the patient is in nil school, we must use the patient's teams through locations here.
1 parent 24a9deb commit 769c371

7 files changed

Lines changed: 36 additions & 9 deletions

app/components/app_import_review_school_moves_summary_component.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@
3737
<%= destination_school_name(changeset) %>
3838
</span>
3939
<% if school_move_across_teams?(changeset) %>
40+
<% source_team = changeset.patient.teams_via_patient_locations.first %>
4041
<div class="nhsuk-u-margin-top-1">
4142
<%= render(
4243
AppStatusComponent.new(
43-
text: "This child is moving in from #{changeset.patient.school.teams.first.name}'s area",
44+
text: "This child is moving in from #{source_team.name}'s area",
4445
small: true,
4546
classes: "nhsuk-u-margin-top-1 nhsuk-u-margin-bottom-0",
4647
)

app/components/app_import_review_school_moves_summary_component.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ def destination_school(changeset)
3030
end
3131

3232
def school_move_across_teams?(changeset)
33-
patient = changeset.patient
3433
dest_school = destination_school(changeset)
3534

36-
dest_school && patient.school && patient.school.teams.any? &&
37-
(dest_school.teams & patient.school.teams).empty?
35+
current_teams = changeset.patient.teams_via_patient_locations
36+
return false if current_teams.empty?
37+
38+
new_teams = dest_school&.teams || [changeset.import.team]
39+
40+
(new_teams & current_teams).empty?
3841
end
3942
end

app/components/app_patient_card_component.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,13 @@ def gillick_no_notify_notices
9292
end
9393

9494
def team_changed_notices
95-
return unless patient.school
96-
9795
valid_notices =
9896
patient
9997
.important_notices
10098
.team_changed
10199
.includes(:school_move_log_entry)
102100
.where(team: current_team)
103-
.where.not(team: patient.school.teams)
101+
.where.not(team: patient.teams_via_patient_locations)
104102

105103
valid_notices.map(&:message)
106104
end

app/views/school_moves/show.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
<% card.with_heading(level: 2) { "#{@school_move.human_enum_name(:source)} record" } %>
2020
<% if @school_move.from_another_team? %>
2121
<div class="nhsuk-u-margin-top-1">
22+
<% source_team = @school_move.patient.teams_via_patient_locations.first %>
2223
<%= render AppStatusComponent.new(text: "Confirming this school move will bring #{@school_move.patient.given_name} " \
23-
"into your area from #{@school_move.patient.school.teams.first.name}") %>
24+
"into your area from #{source_team.name}") %>
2425
</div>
2526
<% end %>
2627
<%= render AppChildSummaryComponent.new(@patient_with_changes) %>

spec/components/app_import_review_component_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@
124124
]
125125
end
126126

127+
before do
128+
create(
129+
:patient_location,
130+
patient: inter_team_patient,
131+
location: other_location
132+
)
133+
end
134+
127135
include_examples "section with details",
128136
title:
129137
"Children moving from another SAIS team's area - resolve after import",
@@ -155,6 +163,14 @@
155163
]
156164
end
157165

166+
before do
167+
create(
168+
:patient_location,
169+
patient: inter_team_patient,
170+
location: other_location
171+
)
172+
end
173+
158174
it "renders separate expander for close matches" do
159175
expect(rendered).to have_css(
160176
".nhsuk-details__summary-text",

spec/components/app_import_review_school_moves_summary_component_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@
113113
]
114114
end
115115

116+
before { create(:patient_location, patient:, location: current_school) }
117+
116118
it "displays inter-team move status message" do
117119
expect(rendered).to have_css(
118120
".app-status",
@@ -326,6 +328,12 @@
326328

327329
before do
328330
current_school.attach_to_team!(team2, academic_year:)
331+
create(
332+
:patient_location,
333+
patient:,
334+
location: current_school,
335+
academic_year:
336+
)
329337
changesets.first.data["review"]["school_move"] = {
330338
"school_id" => destination_school.id,
331339
"home_educated" => false

spec/components/app_patient_card_component_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
end
6060

6161
before do
62-
create(:patient_team, team:, patient:)
62+
create(:patient_location, patient:, location: school)
6363
school_move.confirm!
6464
end
6565

0 commit comments

Comments
 (0)