Skip to content

Commit

Permalink
Vaccs recording: make the back links work as expected
Browse files Browse the repository at this point in the history
This requires pre-populating the VaccinationRecord with "delivery_site_other" value out of the session, and "todays_batch", otherwise the form steps aren't derived correctly.
  • Loading branch information
benilovj committed Jul 22, 2024
1 parent ba7baeb commit a008e46
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 10 deletions.
9 changes: 9 additions & 0 deletions app/controllers/vaccinations/edit_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def handle_confirm
send_vaccination_mail(@draft_vaccination_record)
@patient_session.do_vaccination!

session.delete(:delivery_site_other)

heading =
if @draft_vaccination_record.administered?
t("vaccinations.flash.given")
Expand Down Expand Up @@ -87,6 +89,13 @@ def set_steps

def set_draft_vaccination_record
@draft_vaccination_record = @patient_session.draft_vaccination_record
if (session[:delivery_site_other] = "true")
@draft_vaccination_record.delivery_site_other = true
end
if todays_batch_id.present?
@draft_vaccination_record.todays_batch =
policy_scope(Batch).find(todays_batch_id)
end
end

def set_batches
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/vaccinations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def index

def create
if @draft_vaccination_record.update create_params.merge(user: current_user)
session[:delivery_site_other] = "true" if delivery_site_param_other?
@draft_vaccination_record.todays_batch =
todays_batch_id if todays_batch_id.present?

redirect_to session_patient_vaccinations_edit_path(
@session,
patient_id: @patient.id,
Expand Down
10 changes: 10 additions & 0 deletions app/helpers/vaccinations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,14 @@ def in_tab_vaccinated?(_action, outcome)
def in_tab_not_vaccinated?(_action, outcome)
outcome.in? %i[do_not_vaccinate not_vaccinated]
end

# rubocop:disable Rails/HelperInstanceVariable
def vaccinations_back_link_path
if current_step?(@draft_vaccination_record.form_steps.first.to_s)
session_patient_path(@session, id: @patient.id)
else
previous_wizard_path
end
end
# rubocop:enable Rails/HelperInstanceVariable
end
9 changes: 3 additions & 6 deletions app/models/vaccination_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ class VaccinationRecord < ApplicationRecord
end

on_wizard_step :reason, exact: true do
validates :reason,
inclusion: {
in: VaccinationRecord.reasons.keys
}
validates :reason, inclusion: { in: VaccinationRecord.reasons.keys }
end

on_wizard_step :batch, exact: true do
Expand All @@ -154,8 +151,8 @@ def recorded?

def form_steps
[
("delivery-site" if administered? && delivery_site.nil?),
(:batch if administered? && batch_id.nil?),
("delivery-site" if administered? && delivery_site_other),
(:batch if administered? && todays_batch.nil?),
(:reason if not_administered?),
:confirm
].compact
Expand Down
2 changes: 1 addition & 1 deletion app/views/vaccinations/edit/batch.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% content_for :before_main do %>
<%= render AppBacklinkComponent.new(
href: previous_wizard_path,
href: vaccinations_back_link_path,
name: "vaccination page",
) %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/vaccinations/edit/confirm.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% content_for :before_main do %>
<%= render AppBacklinkComponent.new(
href: previous_wizard_path,
href: vaccinations_back_link_path,
name: "vaccination page",
) %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/vaccinations/edit/delivery-site.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% content_for :before_main do %>
<%= render AppBacklinkComponent.new(
href: session_patient_vaccinations_path(@session, @patient),
href: vaccinations_back_link_path,
name: "vaccination page",
) %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/vaccinations/edit/reason.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% content_for :before_main do %>
<%= render AppBacklinkComponent.new(
href: previous_wizard_path,
href: vaccinations_back_link_path,
name: "vaccination page",
) %>
<% end %>
Expand Down

0 comments on commit a008e46

Please sign in to comment.