Skip to content

Commit 7f9a6d9

Browse files
committed
Add "check and confirm" import page
This adds an additional page when importing records that allows the user to review the records before confirming the import. I've also amended how we import vaccination records and sessions to ensure that we don't ignore duplicate records if the file had already been read in but not confirmed, whilst also preventing the same file from importing the same records multiple times.
1 parent be918bb commit 7f9a6d9

File tree

6 files changed

+91
-35
lines changed

6 files changed

+91
-35
lines changed

app/controllers/immunisation_imports_controller.rb

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
class ImmunisationImportsController < ApplicationController
44
before_action :set_campaign
5+
before_action :set_immunisation_import, only: %i[show edit update]
6+
before_action :set_vaccination_records, only: %i[edit show]
57

68
layout "two_thirds", only: :new
79

810
def index
911
@immunisation_imports =
1012
@campaign
1113
.immunisation_imports
14+
.recorded
1215
.includes(:user)
1316
.order(:created_at)
1417
.strict_loading
@@ -55,21 +58,25 @@ def create
5558
] = "#{ignored_count} records for children who were not vaccinated were omitted"
5659
end
5760

58-
redirect_to campaign_immunisation_import_path(
61+
redirect_to edit_campaign_immunisation_import_path(
5962
@campaign,
6063
@immunisation_import
6164
)
6265
end
6366

6467
def show
65-
@immunisation_import = @campaign.immunisation_imports.find(params[:id])
68+
end
6669

67-
@vaccination_records =
68-
@immunisation_import.vaccination_records.includes(
69-
:location,
70-
:patient,
71-
:session
72-
)
70+
def edit
71+
end
72+
73+
def update
74+
@immunisation_import.record!
75+
76+
redirect_to campaign_immunisation_import_path(
77+
@campaign,
78+
@immunisation_import
79+
)
7380
end
7481

7582
private
@@ -82,6 +89,19 @@ def set_campaign
8289
.find(params[:campaign_id])
8390
end
8491

92+
def set_immunisation_import
93+
@immunisation_import = @campaign.immunisation_imports.find(params[:id])
94+
end
95+
96+
def set_vaccination_records
97+
@vaccination_records =
98+
@immunisation_import.vaccination_records.includes(
99+
:location,
100+
:patient,
101+
:session
102+
)
103+
end
104+
85105
def immunisation_import_params
86106
params
87107
.fetch(:immunisation_import, {})

app/models/immunisation_import_row.rb

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,22 @@ def to_vaccination_record
7777

7878
return unless administered
7979

80-
VaccinationRecord.create_with(
81-
imported_from: @imported_from,
82-
notes:
83-
).find_or_initialize_by(
84-
administered_at:,
85-
batch:,
86-
delivery_method:,
87-
delivery_site:,
88-
dose_sequence:,
89-
patient_session:,
90-
performed_by_family_name:,
91-
performed_by_given_name:,
92-
reason:,
93-
vaccine:
94-
)
80+
VaccinationRecord
81+
.recorded
82+
.or(VaccinationRecord.where(imported_from:))
83+
.create_with(imported_from:, notes:, recorded_at: nil)
84+
.find_or_initialize_by(
85+
administered_at:,
86+
batch:,
87+
delivery_method:,
88+
delivery_site:,
89+
dose_sequence:,
90+
patient_session:,
91+
performed_by_family_name:,
92+
performed_by_given_name:,
93+
reason:,
94+
vaccine:
95+
)
9596
end
9697

9798
def patient
@@ -118,6 +119,8 @@ def session
118119
@session ||=
119120
@campaign
120121
.sessions
122+
.active
123+
.or(Session.where(imported_from:))
121124
.create_with(imported_from:, draft: true)
122125
.find_or_create_by!(
123126
date: session_date,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<% content_for :before_main do %>
2+
<%= render AppBacklinkComponent.new(
3+
href: new_campaign_immunisation_import_path(@campaign),
4+
name: @campaign.name,
5+
) %>
6+
<% end %>
7+
8+
<% title = "Check and confirm" %>
9+
10+
<span class="nhsuk-caption-l"><%= @campaign.name %></span>
11+
<%= h1 title, page_title: "#{@campaign.name}#{title}" %>
12+
13+
<%= govuk_button_to "Upload records", campaign_immunisation_import_path(
14+
@campaign,
15+
@immunisation_import
16+
), method: :put %>
17+
18+
<%= render AppVaccinationRecordTableComponent.new(@vaccination_records, new_records: true) %>

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
resources :immunisation_imports,
7575
path: "immunisation-imports",
76-
only: %i[index new create show]
76+
except: :destroy
7777

7878
resources :vaccination_records,
7979
path: "vaccination-records",

spec/features/immunisation_imports_upload_spec.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323

2424
when_i_upload_a_valid_file
2525
then_i_should_see_the_success_banner
26-
and_i_should_see_the_upload
26+
and_i_should_see_the_vaccination_records
27+
28+
when_i_click_on_upload_records
29+
then_i_should_see_the_upload
2730
and_i_should_see_the_vaccination_records
2831

2932
when_i_click_on_a_vaccination_record
@@ -115,12 +118,6 @@ def then_i_should_see_the_success_banner
115118
expect(page).to have_content("7 vaccinations uploaded")
116119
end
117120

118-
def and_i_should_see_the_upload
119-
expect(page).to have_content("Uploaded on")
120-
expect(page).to have_content("Uploaded byTest User")
121-
expect(page).to have_content("CampaignHPV")
122-
end
123-
124121
def and_i_should_see_the_vaccination_records
125122
expect(page).to have_content(
126123
"Full nameNHS numberDate of birthVaccination date"
@@ -131,6 +128,16 @@ def and_i_should_see_the_vaccination_records
131128
expect(page).to have_content("Vaccination date 14 May 2024")
132129
end
133130

131+
def when_i_click_on_upload_records
132+
click_on "Upload records"
133+
end
134+
135+
def then_i_should_see_the_upload
136+
expect(page).to have_content("Uploaded on")
137+
expect(page).to have_content("Uploaded byTest User")
138+
expect(page).to have_content("CampaignHPV")
139+
end
140+
134141
def when_i_click_on_a_vaccination_record
135142
click_on "Chyna Pickle"
136143
end

spec/models/immunisation_import_spec.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,15 @@
246246
let(:file) { "valid_flu.csv" }
247247

248248
it "sets the recorded at time" do
249-
expect { record! }.to change(immunisation_import, :recorded_at).from(nil)
249+
expect { record! }.to change(immunisation_import, :recorded_at).from(
250+
nil
251+
)
250252
end
251253

252254
it "records the vaccination records" do
253-
expect { record! }.to change(VaccinationRecord.recorded, :count).from(0).to(7)
255+
expect { record! }.to change(VaccinationRecord.recorded, :count).from(
256+
0
257+
).to(7)
254258
end
255259
end
256260

@@ -259,11 +263,15 @@
259263
let(:file) { "valid_hpv.csv" }
260264

261265
it "sets the recorded at time" do
262-
expect { record! }.to change(immunisation_import, :recorded_at).from(nil)
266+
expect { record! }.to change(immunisation_import, :recorded_at).from(
267+
nil
268+
)
263269
end
264270

265271
it "records the vaccination records" do
266-
expect { record! }.to change(VaccinationRecord.recorded, :count).from(0).to(7)
272+
expect { record! }.to change(VaccinationRecord.recorded, :count).from(
273+
0
274+
).to(7)
267275
end
268276
end
269277
end

0 commit comments

Comments
 (0)