Skip to content

Commit

Permalink
Prevent double-vaccination by navigating back (#2737)
Browse files Browse the repository at this point in the history
When using the vaccinate flow it's possible to inadvertently 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.
  • Loading branch information
tvararu authored Dec 17, 2024
2 parents 3d53255 + b14ca1f commit f44aae1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
10 changes: 7 additions & 3 deletions app/controllers/draft_vaccination_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions spec/features/edit_vaccination_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def and_an_hpv_programme_is_underway
@session =
create(
:session,
:completed,
organisation: @organisation,
programme: @programme,
location:
Expand Down
13 changes: 12 additions & 1 deletion spec/features/hpv_vaccination_administered_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f44aae1

Please sign in to comment.