Skip to content

Commit 3fe28fc

Browse files
committed
Display skipped school moves on import screens
This displays the skipped school moves on the import review screen and the completed import screen. This will not work if the import review screen flag is off, but given we want to remove the flag soon, and always have it on, that shouldn't be a problem.
1 parent 730695b commit 3fe28fc

4 files changed

Lines changed: 163 additions & 1 deletion

File tree

app/controllers/cohort_imports_controller.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ def show
7171
@cohort_import.changesets.includes(:patient).nhs_number_discrepancies
7272

7373
@cancelled = @cohort_import.changesets.from_file.cancelled
74+
@skipped_school_moves =
75+
@cohort_import
76+
.changesets
77+
.includes(:patient, patient: :school)
78+
.from_file
79+
.skipped_school_move
7480
end
7581

7682
render template: "imports/show",
@@ -186,5 +192,11 @@ def set_review_records
186192
.includes(:school, patient: :school)
187193
.ready_for_review
188194
.with_school_moves - @inter_team
195+
@skipped_school_moves =
196+
@cohort_import
197+
.changesets
198+
.includes(:patient, patient: :school)
199+
.ready_for_review
200+
.skipped_school_move
189201
end
190202
end

app/models/patient_changeset.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ class PatientChangeset < ApplicationRecord
7676
validate: true
7777

7878
enum :record_type,
79-
{ auto_match: 0, new_patient: 1, import_issue: 2, not_in_file: 3 },
79+
{
80+
auto_match: 0,
81+
new_patient: 1,
82+
import_issue: 2,
83+
not_in_file: 3,
84+
skipped_school_move: 4
85+
},
8086
validate: true
8187

8288
scope :nhs_number_discrepancies,
@@ -464,6 +470,8 @@ def stage_and_handle_pending_changes(existing_patient)
464470
def changeset_type
465471
if patient.id.nil?
466472
:new_patient
473+
elsif school_move_to_unknown_from_another_team?
474+
:skipped_school_move
467475
elsif patient.pending_changes.any?
468476
:import_issue
469477
else

app/views/imports/show.html.erb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
auto_matched_records: @auto_matched_records,
6666
import_issues: @import_issues,
6767
school_moves: @school_moves,
68+
skipped_school_moves: @skipped_school_moves || [],
6869
) %>
6970
<% end %>
7071

@@ -86,6 +87,27 @@
8687
</details>
8788
<% end %>
8889

90+
<% if @skipped_school_moves.present? %>
91+
<h3 class="nhsuk-u-reading-width">
92+
Records not imported - children at schools in other team areas
93+
</h3>
94+
<p class="nhsuk-hint">
95+
This upload included <%= @skipped_school_moves.count > 1 ? "children" : "a child" %> who <%= @skipped_school_moves.count == 1 ? "was" : "were" %> already
96+
registered at a school in another team's area. <%= @skipped_school_moves.count == 1 ? "This child remains" : "These children remain" %>
97+
at their current school.
98+
</p>
99+
<details class="nhsuk-details nhsuk-expander">
100+
<summary class="nhsuk-details__summary" data-module="app-sticky">
101+
<span class="nhsuk-details__summary-text">
102+
<%= pluralize(@skipped_school_moves.count, "record") %> not imported
103+
</span>
104+
</summary>
105+
<div class="nhsuk-details__text">
106+
<%= render AppImportReviewRecordsSummaryComponent.new(changesets: @skipped_school_moves) %>
107+
</div>
108+
</details>
109+
<% end %>
110+
89111
<% if @nhs_discrepancies.present? %>
90112
<h3 class="nhsuk-u-reading-width">
91113
NHS numbers updated from PDS
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# frozen_string_literal: true
2+
3+
describe "Import child records review" do
4+
around { |example| travel_to(Date.new(2023, 5, 20)) { example.run } }
5+
6+
scenario "Skips moving child from another team to unknown school" do
7+
given_i_am_signed_in
8+
and_two_teams_exist
9+
and_import_review_is_enabled
10+
and_a_patient_exists_in_another_teams_school
11+
12+
when_i_visit_the_import_page
13+
and_i_choose_to_import_child_records
14+
and_i_upload_a_file_moving_child_to_unknown_school
15+
then_i_should_see_the_import_review_page
16+
and_i_should_see_the_skipped_school_moves_summary
17+
18+
when_i_approve_the_import
19+
then_the_import_should_be_complete
20+
and_i_should_see_the_skipped_school_moves_summary
21+
and_the_patient_should_remain_at_their_current_school
22+
and_the_patient_should_not_be_linked_to_my_team
23+
end
24+
25+
def given_i_am_signed_in
26+
programmes = [Programme.hpv, Programme.menacwy, Programme.td_ipv]
27+
@team = create(:team, :with_generic_clinic, :with_one_nurse, programmes:)
28+
@user = @team.users.first
29+
30+
# Create a school in this team (children can be uploaded here)
31+
create(:school, urn: "123456", team: @team)
32+
33+
sign_in @user
34+
end
35+
36+
def and_two_teams_exist
37+
programmes = [Programme.hpv, Programme.menacwy, Programme.td_ipv]
38+
@other_team =
39+
create(:team, :with_one_nurse, programmes:, name: "Other Team")
40+
@other_school =
41+
create(
42+
:school,
43+
urn: "111222",
44+
name: "Other Team School",
45+
team: @other_team
46+
)
47+
end
48+
49+
def and_import_review_is_enabled
50+
Flipper.enable(:import_review_screen)
51+
end
52+
53+
def and_a_patient_exists_in_another_teams_school
54+
@patient =
55+
create(
56+
:patient,
57+
given_name: "Mark",
58+
family_name: "Doe",
59+
nhs_number: nil,
60+
date_of_birth: Date.new(2010, 1, 3),
61+
address_postcode: "SW1A 1AA",
62+
school: @other_school
63+
)
64+
65+
create(
66+
:patient_location,
67+
patient: @patient,
68+
location: @other_school,
69+
academic_year: AcademicYear.current
70+
)
71+
end
72+
73+
def when_i_visit_the_import_page
74+
visit "/dashboard"
75+
click_on "Import", match: :first
76+
end
77+
78+
def and_i_choose_to_import_child_records
79+
click_on "Upload records"
80+
choose "Child records"
81+
click_on "Continue"
82+
end
83+
84+
def and_i_upload_a_file_moving_child_to_unknown_school
85+
attach_file_fixture "cohort_import[csv]",
86+
"cohort_import/valid_unknown_school.csv"
87+
click_on "Continue"
88+
wait_for_import_to_complete_until_review(CohortImport)
89+
end
90+
91+
def then_i_should_see_the_import_review_page
92+
page.refresh
93+
click_on_most_recent_import(CohortImport)
94+
expect(page).to have_content("Review and approve")
95+
end
96+
97+
def and_i_should_see_the_skipped_school_moves_summary
98+
expect(page).to have_content("1 record not imported")
99+
expect(page).to have_content("at their current school")
100+
end
101+
102+
def when_i_approve_the_import
103+
click_on "Approve and import records"
104+
wait_for_import_to_commit(CohortImport)
105+
end
106+
107+
def then_the_import_should_be_complete
108+
expect(page).to have_content("Completed")
109+
end
110+
111+
def and_the_patient_should_remain_at_their_current_school
112+
@patient.reload
113+
expect(@patient.school).to eq(@other_school)
114+
end
115+
116+
def and_the_patient_should_not_be_linked_to_my_team
117+
expect(@patient.teams).not_to include(@team)
118+
expect(@patient.teams).to contain_exactly(@other_team)
119+
end
120+
end

0 commit comments

Comments
 (0)