Skip to content

Commit 47924d1

Browse files
authored
Merge pull request #4019 from nhsuk/ensure-existing-records-are-uploaded
Ensure all changes are staged when recording offline
2 parents 896cf3b + f5e3eeb commit 47924d1

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

app/models/immunisation_import_row.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,33 +116,33 @@ def to_vaccination_record
116116
)
117117
end
118118

119+
attributes_to_stage_if_already_exists = {
120+
batch_id: batch&.id,
121+
delivery_method: delivery_method_value,
122+
delivery_site: delivery_site_value,
123+
notes: notes&.to_s,
124+
vaccine_id: vaccine&.id
125+
}
126+
119127
vaccination_record =
120128
if uuid.present?
121129
VaccinationRecord
122130
.joins(:organisation)
123131
.find_by!(organisations: { id: organisation.id }, uuid: uuid.to_s)
124-
.tap { _1.assign_attributes(attributes) }
132+
.tap { it.stage_changes(attributes) }
125133
else
126134
VaccinationRecord.find_or_initialize_by(attributes)
127135
end
128136

129137
if vaccination_record.persisted?
130-
vaccination_record.stage_changes(
131-
batch_id: batch&.id,
132-
delivery_method: delivery_method_value,
133-
delivery_site: delivery_site_value,
134-
notes: notes&.to_s,
135-
vaccine_id: vaccine&.id
136-
)
138+
vaccination_record.stage_changes(attributes_to_stage_if_already_exists)
137139
else
138140
# Postgres UUID generation is skipped in bulk import
139141
vaccination_record.uuid = SecureRandom.uuid
140142

141-
vaccination_record.batch = batch
142-
vaccination_record.delivery_method = delivery_method_value
143-
vaccination_record.delivery_site = delivery_site_value
144-
vaccination_record.notes = notes&.to_s
145-
vaccination_record.vaccine = vaccine
143+
vaccination_record.assign_attributes(
144+
attributes_to_stage_if_already_exists
145+
)
146146
end
147147

148148
vaccination_record

spec/features/hpv_vaccination_offline_spec.rb

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

1515
when_i_record_vaccination_outcomes_to_the_spreadsheet_and_export_it_to_csv
1616
and_i_upload_the_modified_csv_file
17-
then_i_see_there_are_previously_imported_records
17+
then_i_see_there_are_no_previously_imported_records
1818
when_i_navigate_to_the_session_page
1919
then_i_see_the_uploaded_vaccination_outcomes_reflected_in_the_session
2020

@@ -32,7 +32,7 @@
3232

3333
when_i_record_vaccination_outcomes_to_the_spreadsheet_and_export_it_to_csv
3434
and_i_upload_the_modified_csv_file
35-
then_i_see_there_are_previously_imported_records
35+
then_i_see_there_are_no_previously_imported_records
3636
when_i_navigate_to_the_clinic_page
3737
then_i_see_the_uploaded_vaccination_outcomes_reflected_in_the_session
3838
and_the_clinic_location_is_displayed
@@ -51,6 +51,9 @@
5151
and_i_upload_the_modified_csv_file
5252
then_i_see_a_duplicate_record_needs_review
5353

54+
when_i_review_the_duplicate_record
55+
then_i_should_see_the_changes
56+
5457
when_i_choose_to_keep_the_duplicate_record
5558
then_i_should_see_a_success_message
5659
and_the_vaccination_record_is_synced_to_nhs
@@ -189,7 +192,7 @@ def and_alter_an_existing_vaccination_record
189192
@sheet = @workbook["Vaccinations"]
190193
@headers = @sheet[0].cells.map(&:value)
191194

192-
array = @workbook[0].to_a[1..].map(&:cells).map { _1.map(&:value) }
195+
array = @workbook[0].to_a[1..].map(&:cells).map { it.map(&:value) }
193196
csv_table =
194197
CSV::Table.new(
195198
array.map do |row|
@@ -204,8 +207,21 @@ def and_alter_an_existing_vaccination_record
204207
File.write("tmp/modified.csv", csv_table.to_csv)
205208
end
206209

207-
def when_i_choose_to_keep_the_duplicate_record
210+
def when_i_review_the_duplicate_record
208211
click_on "Review"
212+
end
213+
214+
def then_i_should_see_the_changes
215+
expect(page).to have_css(
216+
".app-highlight",
217+
text: "Right arm (upper position)"
218+
)
219+
expect(page).to have_css(".app-highlight", text: "Second")
220+
expect(page).to have_css(".app-highlight", text: "1 January 2024")
221+
expect(page).to have_css(".app-highlight", text: "10:00am")
222+
end
223+
224+
def when_i_choose_to_keep_the_duplicate_record
209225
choose "Use duplicate record"
210226
click_on "Resolve duplicate"
211227
end
@@ -240,7 +256,7 @@ def when_i_record_vaccination_outcomes_to_the_spreadsheet_and_export_it_to_csv
240256
#
241257
# ideally we could drive Excel here (or similar) but the code below is better than nothing
242258

243-
array = @workbook[0].to_a[1..].map(&:cells).map { _1.map(&:value) }
259+
array = @workbook[0].to_a[1..].map(&:cells).map { it.map(&:value) }
244260
csv_table =
245261
CSV::Table.new(
246262
array.map do |row|
@@ -398,10 +414,10 @@ def and_a_text_is_sent_to_the_parent_confirming_the_vaccination
398414
)
399415
end
400416

401-
def then_i_see_there_are_previously_imported_records
417+
def then_i_see_there_are_no_previously_imported_records
402418
expect(page).to have_content("Completed")
403419
expect(page).not_to have_content("Invalid")
404-
expect(page).to have_content("2 previously imported records were omitted")
420+
expect(page).to have_content("0 previously imported records were omitted")
405421
end
406422

407423
def then_i_see_a_duplicate_record_needs_review

0 commit comments

Comments
 (0)