From b14ca1fffe113f313baea754fc25aaff177b1a8a Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Fri, 13 Dec 2024 09:45:22 +0000 Subject: [PATCH] Prevent double-vaccination by navigating back When using the vaccinate flow it's possible to inadvertantly record two vaccinations for the same patient by navigating back to the confirmation after submitting it and then submitting it again. Instead, once recorded, we associate the draft vaccination record with the saved one so this changes to the edit vaccination record flow. --- .../draft_vaccination_records_controller.rb | 10 +++++++--- spec/features/edit_vaccination_record_spec.rb | 1 + spec/features/hpv_vaccination_administered_spec.rb | 13 ++++++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/controllers/draft_vaccination_records_controller.rb b/app/controllers/draft_vaccination_records_controller.rb index 9ba6bbc85..e03cdc192 100644 --- a/app/controllers/draft_vaccination_records_controller.rb +++ b/app/controllers/draft_vaccination_records_controller.rb @@ -97,6 +97,10 @@ def handle_confirm send_vaccination_confirmation(@vaccination_record) if should_notify_parents + # In case the user navigates back to try and edit the newly created + # vaccination record. + @draft_vaccination_record.update!(editing_id: @vaccination_record.id) + heading = if @vaccination_record.administered? t("vaccinations.flash.given") @@ -122,10 +126,10 @@ def handle_confirm end def finish_wizard_path - if @draft_vaccination_record.editing? - programme_vaccination_record_path(@programme, @vaccination_record) - else + if @session.today? session_vaccinations_path(@session) + else + programme_vaccination_record_path(@programme, @vaccination_record) end end diff --git a/spec/features/edit_vaccination_record_spec.rb b/spec/features/edit_vaccination_record_spec.rb index 80805589c..35c96c2bf 100644 --- a/spec/features/edit_vaccination_record_spec.rb +++ b/spec/features/edit_vaccination_record_spec.rb @@ -260,6 +260,7 @@ def and_an_hpv_programme_is_underway @session = create( :session, + :completed, organisation: @organisation, programme: @programme, location: diff --git a/spec/features/hpv_vaccination_administered_spec.rb b/spec/features/hpv_vaccination_administered_spec.rb index 9bb40c99c..021caa4d8 100644 --- a/spec/features/hpv_vaccination_administered_spec.rb +++ b/spec/features/hpv_vaccination_administered_spec.rb @@ -46,6 +46,9 @@ then_i_see_the_record_vaccinations_page and_a_success_message + when_i_go_back + and_i_save_changes + when_i_go_to_the_patient then_i_see_that_the_status_is_vaccinated and_i_see_the_vaccination_details @@ -180,6 +183,14 @@ def and_a_success_message ) end + def when_i_go_back + visit draft_vaccination_record_path("confirm") + end + + def and_i_save_changes + click_button "Save changes" + end + def when_i_go_to_the_patient click_link @patient.full_name end @@ -189,7 +200,7 @@ def then_i_see_that_the_status_is_vaccinated end def and_i_see_the_vaccination_details - expect(page).to have_content("Vaccination details") + expect(page).to have_content("Vaccination details").once end def when_vaccination_confirmations_are_sent