Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show error message if no radio button for vaccine selected #2500

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions app/controllers/vaccinations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ def create
&:reset!
)

@draft_vaccination_record.assign_attributes(create_params)
@draft_vaccination_record.patient_session = @patient_session

if @draft_vaccination_record.save
if create_params.nil?
@draft_vaccination_record.errors.add(:administered, :blank)
render "patient_sessions/show", status: :unprocessable_entity
elsif @draft_vaccination_record.update(create_params)
steps = @draft_vaccination_record.wizard_steps

steps.delete(:date_and_time)
Expand Down Expand Up @@ -130,17 +133,16 @@ def vaccination_record_params
:programme_id,
:vaccine_id
)
.merge(
patient_session: @patient_session,
performed_at: Time.current,
performed_by_user: current_user
)
.merge(performed_at: Time.current, performed_by_user: current_user)
end

def create_params
if vaccination_record_params[:administered] == "true"
administered = vaccination_record_params[:administered]
return if administered.blank?

if administered == "true"
create_params =
if delivery_site_param_other?
if vaccination_record_params[:delivery_site] == "other"
vaccination_record_params.except(:delivery_site, :delivery_method)
else
vaccination_record_params
Expand All @@ -155,10 +157,6 @@ def create_params
end
end

def delivery_site_param_other?
vaccination_record_params[:delivery_site] == "other"
end

def set_session
@session =
policy_scope(Session).includes(:location).find_by!(
Expand Down
4 changes: 4 additions & 0 deletions app/models/draft_vaccination_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ def wizard_steps
end

def administered?
return nil if outcome.nil?
outcome == "administered"
end

# So that a form error matches to a field in this model
alias_method :administered, :administered?

def batch
BatchPolicy::Scope.new(@current_user, Batch).resolve.find_by(id: batch_id)
end
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ en:
draft_vaccination_record:
attributes:
administered:
inclusion: Choose if they got the vaccine
blank: Choose if they got the vaccine
batch_id:
blank: Choose a batch
incorrect_vaccine: Choose a batch of the %{vaccine_brand} vaccine
Expand Down
Loading