Skip to content

Commit

Permalink
Rename parent name
Browse files Browse the repository at this point in the history
This renames the name column to `full_name` for consistent with the
other name-able models which have a similar `full_name` method (taken
from a given name and a family name).
  • Loading branch information
thomasleese committed Oct 15, 2024
1 parent 6f647ab commit bdf2276
Show file tree
Hide file tree
Showing 53 changed files with 130 additions and 100 deletions.
2 changes: 1 addition & 1 deletion app/components/app_activity_log_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def consent_events
@patient_session.patient.consents.recorded.map do
{
title:
"Consent #{_1.response} by #{_1.parent.name} (#{_1.who_responded})",
"Consent #{_1.response} by #{_1.parent.full_name} (#{_1.who_responded})",
time: _1.recorded_at
}
end
Expand Down
2 changes: 1 addition & 1 deletion app/components/app_consent_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<% consents.each do |consent| %>
<%= body.with_row do |row| %>
<%= row.with_cell do %>
<%= govuk_link_to consent&.parent&.name || consent.patient.full_name, details_session_patient_manage_consents_path(consent, session_id: session.id, patient_id: patient.id, section:, tab:) %>
<%= govuk_link_to consent&.parent&.full_name || consent.patient.full_name, details_session_patient_manage_consents_path(consent, session_id: session.id, patient_id: patient.id, section:, tab:) %>
<br>
<span class="nhsuk-u-font-size-16"><%= consent.who_responded %></span>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/components/app_matching_criteria_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

summary_list.with_row do |row|
row.with_key { parent_guardian_or_other.capitalize }
row.with_value { parent_name }
row.with_value { parent_full_name }
end

if date_of_birth.present?
Expand Down
4 changes: 2 additions & 2 deletions app/components/app_matching_criteria_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def initialize(consent_form:)
@consent_form = consent_form
end

def parent_name
@consent_form.parent_name
def parent_full_name
@consent_form.parent_full_name
end

def child_full_name
Expand Down
2 changes: 1 addition & 1 deletion app/components/app_patient_summary_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def format_parent_or_guardians
@patient.parent_relationships.map do |parent_relationship|
tag.li do
[
"#{parent_relationship.parent.name} (#{parent_relationship.label})",
"#{parent_relationship.parent.full_name} (#{parent_relationship.label})",
if (phone = parent_relationship.parent.phone).present?
tag.span(phone, class: "nhsuk-u-secondary-text-color")
end
Expand Down
Empty file.
6 changes: 3 additions & 3 deletions app/controllers/manage_consents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def set_parent_options
(
@patient.parents +
@patient_session.consents.recorded.includes(:parent).map(&:parent)
).compact.uniq.sort_by(&:name)
).compact.uniq.sort_by(&:full_name)
end

def set_parent
Expand All @@ -206,7 +206,7 @@ def set_parent_details_form
parent: @parent,
patient: @patient,
email: @parent.email,
name: @parent.name,
full_name: @parent.full_name,
phone: @parent.phone,
phone_receive_updates: @parent.phone_receive_updates,
relationship_type: @parent_relationship&.type,
Expand Down Expand Up @@ -265,7 +265,7 @@ def update_params

def parent_details_params
params.require(:parent_details_form).permit(
:name,
:full_name,
:email,
:parental_responsibility,
:phone,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def update_params
school: %i[school_id],
parent: %i[
parent_email
parent_name
parent_full_name
parent_phone
parent_phone_receive_updates
parent_relationship_other_name
Expand Down
6 changes: 3 additions & 3 deletions app/forms/parent_details_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ParentDetailsForm
attr_accessor :parent, :patient

attribute :email, :string
attribute :name, :string
attribute :full_name, :string
attribute :phone, :string
attribute :phone_receive_updates, :boolean
attribute :parental_responsibility, :boolean
Expand All @@ -24,7 +24,7 @@ class ParentDetailsForm
}

with_options if: :can_change_name_or_relationship? do
validates :name, presence: true
validates :full_name, presence: true
validates :relationship_type,
inclusion: {
in: ParentRelationship.types.keys
Expand All @@ -41,7 +41,7 @@ def save

ActiveRecord::Base.transaction do
parent.email = email
parent.name = name if can_change_name_or_relationship?
parent.full_name = full_name if can_change_name_or_relationship?
parent.phone = phone
parent.phone_receive_updates = phone_receive_updates || false
parent.save!
Expand Down
6 changes: 3 additions & 3 deletions app/lib/govuk_notify_personalisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def call
next_session_date:,
next_session_dates:,
next_session_dates_or:,
parent_name:,
parent_full_name:,
programme_name:,
reason_did_not_vaccinate:,
reason_for_refusal:,
Expand Down Expand Up @@ -135,8 +135,8 @@ def next_session_dates_or
.to_sentence(last_word_connector: ", or ", two_words_connector: " or ")
end

def parent_name
consent_form&.parent_name || parent&.name
def parent_full_name
consent_form&.parent_full_name || parent&.full_name
end

def programme_name
Expand Down
2 changes: 1 addition & 1 deletion app/models/consent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def wizard_steps
end

def name
via_self_consent? ? patient.full_name : parent.name
via_self_consent? ? patient.full_name : parent.full_name
end

def triage_needed?
Expand Down
10 changes: 5 additions & 5 deletions app/models/consent_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# parent_contact_method_other_details :string
# parent_contact_method_type :string
# parent_email :string
# parent_name :string
# parent_full_name :string
# parent_phone :string
# parent_phone_receive_updates :boolean default(FALSE), not null
# parent_relationship_other_name :string
Expand Down Expand Up @@ -117,7 +117,7 @@ class ConsentForm < ApplicationRecord
:health_answers,
:parent_contact_method_other_details,
:parent_email,
:parent_name,
:parent_full_name,
:parent_phone,
:parent_relationship_other_name,
:reason_notes
Expand All @@ -137,7 +137,7 @@ class ConsentForm < ApplicationRecord
:given_name,
:gp_name,
:parent_contact_method_other_details,
:parent_name,
:parent_full_name,
:parent_relationship_other_name,
length: {
maximum: 300
Expand Down Expand Up @@ -190,7 +190,7 @@ class ConsentForm < ApplicationRecord
end

on_wizard_step :parent do
validates :parent_name, presence: true
validates :parent_full_name, presence: true
validates :parent_email, notify_safe_email: true
validates :parent_relationship_type, presence: true
end
Expand Down Expand Up @@ -314,7 +314,7 @@ def scheduled_session
def find_or_create_parent_with_relationship_to(patient:)
Parent
.create_with(recorded_at: Time.zone.now)
.find_or_initialize_by(name: parent_name, email: parent_email)
.find_or_initialize_by(full_name: parent_full_name, email: parent_email)
.tap do |parent|
parent.update!(
phone: parent_phone,
Expand Down
8 changes: 4 additions & 4 deletions app/models/parent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# contact_method_other_details :text
# contact_method_type :string
# email :string
# name :string
# full_name :string
# phone :string
# phone_receive_updates :boolean default(FALSE), not null
# recorded_at :datetime
Expand Down Expand Up @@ -39,13 +39,13 @@ class Parent < ApplicationRecord
allow_nil: true
}

encrypts :email, :name, :phone, :relationship_other, deterministic: true
encrypts :email, :full_name, :phone, :relationship_other, deterministic: true
encrypts :contact_method_other_details

normalizes :phone, with: -> { _1.blank? ? nil : _1.to_s.gsub(/\s/, "") }
normalizes :email, with: -> { _1.blank? ? nil : _1.to_s.downcase.strip }

validates :name, presence: true
validates :full_name, presence: true
validates :phone,
presence: {
if: :phone_receive_updates
Expand All @@ -56,7 +56,7 @@ class Parent < ApplicationRecord
validates :email, presence: true, notify_safe_email: true
validates :contact_method_other_details,
:email,
:name,
:full_name,
:phone,
length: {
maximum: 300
Expand Down
14 changes: 11 additions & 3 deletions app/models/patient_import_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,25 @@ def to_parents

parents = [
if parent_1_exists?
{ email: parent_1_email, name: parent_1_name, phone: parent_1_phone }
{
email: parent_1_email,
full_name: parent_1_name,
phone: parent_1_phone
}
end,
if parent_2_exists?
{ email: parent_2_email, name: parent_2_name, phone: parent_2_phone }
{
email: parent_2_email,
full_name: parent_2_name,
phone: parent_2_phone
}
end
].compact

parents.map do |attributes|
Parent
.create_with(recorded_at: Time.zone.now)
.find_or_initialize_by(attributes.slice(:email, :name))
.find_or_initialize_by(attributes.slice(:email, :full_name))
.tap do |parent|
parent.assign_attributes(
phone: attributes[:phone],
Expand Down
4 changes: 2 additions & 2 deletions app/views/consent_forms/review_match.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="nhsuk-grid-column-two-thirds">
<%= h1 page_title: do %>
<span class="nhsuk-caption-l nhsuk-u-margin-top-2">
Consent response from <%= @consent_form.parent_name %>
Consent response from <%= @consent_form.parent_full_name %>
</span>
<%= page_title %>
<% end %>
Expand All @@ -24,7 +24,7 @@
<%= render AppCardComponent.new do |c|
c.with_heading { "Consent response" }
render AppConsentSummaryComponent.new(
name: @consent_form.parent_name,
name: @consent_form.parent_full_name,
relationship: @consent_form.parent_relationship_label,
contact: {
phone: @consent_form.parent_phone,
Expand Down
2 changes: 1 addition & 1 deletion app/views/consent_forms/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<% page_title = "Search for a child record" %>
<%= h1 page_title: do %>
<span class="nhsuk-caption-l nhsuk-u-margin-top-2">
Consent response from <%= @consent_form.parent_name %>
Consent response from <%= @consent_form.parent_full_name %>
</span>
<%= page_title %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/consent_forms/unmatched_responses.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
body.with_row do |row|
row.with_cell(text: consent_form.recorded_at&.to_date&.to_fs(:long))
row.with_cell(text: consent_form.full_name)
row.with_cell(text: consent_form.parent_name)
row.with_cell(text: consent_form.parent_full_name)
row.with_cell(text: govuk_link_to("Find match", consent_form))
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/consents/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
) do |summary_list|
summary_list.with_row do |row|
row.with_key { "Name" }
row.with_value { @consent.parent.name }
row.with_value { @consent.parent.full_name }
end

summary_list.with_row do |row|
Expand Down
2 changes: 1 addition & 1 deletion app/views/manage_consents/confirm.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
) do |summary_list|
summary_list.with_row do |row|
row.with_key { "Name" }
row.with_value { @parent.name }
row.with_value { @parent.full_name }
row.with_action(text: "Change", href: wizard_path(:who), visually_hidden_text: "parent name")
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/manage_consents/parent_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<% end %>
<% page_title = if @parent.recorded?
"Details for #{@parent.name} (#{@parent.relationship_to(patient: @patient).label})"
"Details for #{@parent.full_name} (#{@parent.relationship_to(patient: @patient).label})"
else
"Details for parent or guardian"
end %>
Expand All @@ -22,7 +22,7 @@
<% content_for(:before_content) { f.govuk_error_summary } %>
<% if @parent_details_form.can_change_name_or_relationship? %>
<%= f.govuk_text_field :name, label: { text: "Full name" } %>
<%= f.govuk_text_field :full_name, label: { text: "Full name" } %>
<%= f.govuk_radio_buttons_fieldset(:relationship_type,
legend: { size: "s",
Expand Down
2 changes: 1 addition & 1 deletion app/views/manage_consents/who.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<%= f.govuk_radio_buttons_fieldset(:new_or_existing_parent, legend: nil) do %>
<% @parent_options.each.with_index do |parent, i| %>
<%= f.govuk_radio_button :new_or_existing_parent, parent.id,
label: { text: "#{parent.name} (#{parent.relationship_to(patient: @patient).label})" },
label: { text: "#{parent.full_name} (#{parent.relationship_to(patient: @patient).label})" },
hint: { text: parent.phone },
link_errors: i == 0 %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/parent_interface/consent_forms/confirm.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
<%= govuk_summary_list classes: "app-summary-list--no-bottom-border" do |summary_list|
summary_list.with_row do |row|
row.with_key { "Your name" }
row.with_value { @consent_form.parent_name }
row.with_value { @consent_form.parent_full_name }
row.with_action(text: "Change",
href: change_link[:parent],
visually_hidden_text: "your name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<%= h1 "About you" %>
<%= f.govuk_text_field :parent_name, label: { text: "Your name" } %>
<%= f.govuk_text_field :parent_full_name, label: { text: "Your name" } %>
<%= f.govuk_radio_buttons_fieldset(:parent_relationship_type,
legend: { size: "s",
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ en:
blank: Enter your email address
invalid: Enter a valid email address, such as [email protected]
too_long: Enter an email address that is less than 300 characters long
parent_name:
parent_full_name:
blank: Enter your name
too_long: Enter a name that is less than 300 characters long
parent_phone:
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20241015104614_rename_parent_name_to_full_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class RenameParentNameToFullName < ActiveRecord::Migration[7.2]
def change
rename_column :parents, :name, :full_name
rename_column :consent_forms, :parent_full_name, :parent_full_name
end
end
6 changes: 3 additions & 3 deletions 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_10_15_102323) do
ActiveRecord::Schema[7.2].define(version: 2024_10_15_104614) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -165,7 +165,7 @@
t.string "parent_contact_method_other_details"
t.string "parent_contact_method_type"
t.string "parent_email"
t.string "parent_name"
t.string "parent_full_name"
t.string "parent_phone"
t.string "parent_relationship_other_name"
t.string "parent_relationship_type"
Expand Down Expand Up @@ -451,7 +451,7 @@
end

create_table "parents", force: :cascade do |t|
t.string "name"
t.string "full_name"
t.string "email"
t.string "phone"
t.text "contact_method_other_details"
Expand Down
Binary file modified erd.pdf
Binary file not shown.
Loading

0 comments on commit bdf2276

Please sign in to comment.