Skip to content

Commit

Permalink
Add location_confirmed field to consent forms
Browse files Browse the repository at this point in the history
If parents choose that the location of the session doesn't match their
child's school, we have to show a follow-up page that asks the user to
confirm the child's school. In order to enable this, we should first
track the value of the confirm_school form using an actual boolean field
instead of a temporary attr_accessor one.
  • Loading branch information
tvararu committed Sep 26, 2024
1 parent 6c5759b commit 040423b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def update
model.assign_attributes(update_params)
end

if current_step == :confirm_school &&
@consent_form.is_this_their_school == "no"
if current_step == :confirm_school && !@consent_form.location_confirmed
redirect_to session_parent_interface_consent_form_cannot_consent_school_path(
@session,
@consent_form
Expand Down Expand Up @@ -73,7 +72,7 @@ def update_params
date_of_birth(2i)
date_of_birth(1i)
],
confirm_school: %i[is_this_their_school],
confirm_school: %i[location_confirmed],
parent: %i[
parent_email
parent_name
Expand Down
10 changes: 6 additions & 4 deletions app/models/consent_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# gp_response :integer
# health_answers :jsonb not null
# last_name :text
# location_confirmed :boolean
# parent_contact_method_other_details :string
# parent_contact_method_type :string
# parent_email :string
Expand All @@ -33,18 +34,21 @@
# created_at :datetime not null
# updated_at :datetime not null
# consent_id :bigint
# location_id :bigint
# programme_id :bigint not null
# session_id :bigint not null
#
# Indexes
#
# index_consent_forms_on_consent_id (consent_id)
# index_consent_forms_on_location_id (location_id)
# index_consent_forms_on_programme_id (programme_id)
# index_consent_forms_on_session_id (session_id)
#
# Foreign Keys
#
# fk_rails_... (consent_id => consents.id)
# fk_rails_... (location_id => locations.id)
# fk_rails_... (programme_id => programmes.id)
# fk_rails_... (session_id => sessions.id)
#
Expand All @@ -59,9 +63,7 @@ class ConsentForm < ApplicationRecord
scope :unmatched, -> { where(consent_id: nil) }
scope :recorded, -> { where.not(recorded_at: nil) }

attr_accessor :health_question_number,
:is_this_their_school,
:parental_responsibility
attr_accessor :health_question_number, :parental_responsibility

audited

Expand Down Expand Up @@ -172,7 +174,7 @@ class ConsentForm < ApplicationRecord
end

on_wizard_step :confirm_school, exact: true do
validates :is_this_their_school, inclusion: { in: %w[yes no] }
validates :location_confirmed, inclusion: { in: [true, false] }
end

on_wizard_step :parent do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
<%= form_with model: @consent_form, url: wizard_path, method: :put do |f| %>
<% content_for(:before_content) { f.govuk_error_summary } %>
<%= f.govuk_radio_buttons_fieldset(:is_this_their_school,
<%= f.govuk_radio_buttons_fieldset(:location_confirmed,
legend: { size: "s", text: "Is this their school?" }) do %>
<%= f.govuk_radio_button :is_this_their_school, "yes",
<%= f.govuk_radio_button :location_confirmed, true,
link_errors: true,
label: { text: "Yes, they go to this school" } %>
<%= f.govuk_radio_button :is_this_their_school, "no",
<%= f.govuk_radio_button :location_confirmed, false,
label: { text: "No, they go to a different school" } %>
<% end %>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class AddLocationFieldsToConsentForm < ActiveRecord::Migration[7.2]
def change
add_column :consent_forms, :location_confirmed, :boolean
add_reference :consent_forms, :location, foreign_key: true
end
end
6 changes: 5 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.2].define(version: 2024_09_26_104802) do
ActiveRecord::Schema[7.2].define(version: 2024_09_26_110216) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -126,7 +126,10 @@
t.string "parent_relationship_type"
t.boolean "parent_phone_receive_updates", default: false, null: false
t.bigint "programme_id", null: false
t.boolean "location_confirmed"
t.bigint "location_id"
t.index ["consent_id"], name: "index_consent_forms_on_consent_id"
t.index ["location_id"], name: "index_consent_forms_on_location_id"
t.index ["programme_id"], name: "index_consent_forms_on_programme_id"
t.index ["session_id"], name: "index_consent_forms_on_session_id"
end
Expand Down Expand Up @@ -600,6 +603,7 @@
add_foreign_key "cohort_imports_patients", "patients"
add_foreign_key "cohorts", "teams"
add_foreign_key "consent_forms", "consents"
add_foreign_key "consent_forms", "locations"
add_foreign_key "consent_forms", "programmes"
add_foreign_key "consent_forms", "sessions"
add_foreign_key "consents", "parents"
Expand Down
Binary file modified erd.pdf
Binary file not shown.
4 changes: 4 additions & 0 deletions spec/factories/consent_forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# gp_response :integer
# health_answers :jsonb not null
# last_name :text
# location_confirmed :boolean
# parent_contact_method_other_details :string
# parent_contact_method_type :string
# parent_email :string
Expand All @@ -33,18 +34,21 @@
# created_at :datetime not null
# updated_at :datetime not null
# consent_id :bigint
# location_id :bigint
# programme_id :bigint not null
# session_id :bigint not null
#
# Indexes
#
# index_consent_forms_on_consent_id (consent_id)
# index_consent_forms_on_location_id (location_id)
# index_consent_forms_on_programme_id (programme_id)
# index_consent_forms_on_session_id (session_id)
#
# Foreign Keys
#
# fk_rails_... (consent_id => consents.id)
# fk_rails_... (location_id => locations.id)
# fk_rails_... (programme_id => programmes.id)
# fk_rails_... (session_id => sessions.id)
#
Expand Down
4 changes: 4 additions & 0 deletions spec/models/consent_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# gp_response :integer
# health_answers :jsonb not null
# last_name :text
# location_confirmed :boolean
# parent_contact_method_other_details :string
# parent_contact_method_type :string
# parent_email :string
Expand All @@ -33,18 +34,21 @@
# created_at :datetime not null
# updated_at :datetime not null
# consent_id :bigint
# location_id :bigint
# programme_id :bigint not null
# session_id :bigint not null
#
# Indexes
#
# index_consent_forms_on_consent_id (consent_id)
# index_consent_forms_on_location_id (location_id)
# index_consent_forms_on_programme_id (programme_id)
# index_consent_forms_on_session_id (session_id)
#
# Foreign Keys
#
# fk_rails_... (consent_id => consents.id)
# fk_rails_... (location_id => locations.id)
# fk_rails_... (programme_id => programmes.id)
# fk_rails_... (session_id => sessions.id)
#
Expand Down

0 comments on commit 040423b

Please sign in to comment.