Skip to content

Commit

Permalink
Use FullNameFormatter
Browse files Browse the repository at this point in the history
This updates the various places in the service where a name is rendered
to use the new `FullNameFormatter` class to ensure that it's formatted
correctly.
  • Loading branch information
thomasleese committed Mar 4, 2025
1 parent 8712b8c commit 290b664
Show file tree
Hide file tree
Showing 48 changed files with 206 additions and 171 deletions.
7 changes: 5 additions & 2 deletions app/components/app_consent_confirmation_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ def title

private

delegate :full_name,
:chosen_programmes,
delegate :chosen_programmes,
:not_chosen_programmes,
:response,
:parent_email,
to: :@consent_form

def full_name
@consent_form.full_name(context: :parents)
end

def panel_text
case response
when "given", "given_one"
Expand Down
2 changes: 1 addition & 1 deletion app/components/app_simple_status_banner_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def call
delegate :patient, :session, to: :patient_session

def status
@status ||= @patient_session.status(programme:)
@status ||= patient_session.status(programme:)
end

def colour
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 @@ -123,10 +123,10 @@ def full_and_preferred_patient_name
patient_or_consent_form = consent_form || patient

if patient_or_consent_form.has_preferred_name?
patient_or_consent_form.full_name +
" (known as #{patient_or_consent_form.preferred_full_name})"
patient_or_consent_form.full_name(context: :parents) +
" (known as #{patient_or_consent_form.preferred_full_name(context: :parents)})"
else
patient_or_consent_form.full_name
patient_or_consent_form.full_name(context: :parents)
end
end

Expand Down
11 changes: 4 additions & 7 deletions app/models/concerns/full_name_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ module FullNameConcern
-> { order("LOWER(family_name)", "LOWER(given_name)") }
end

def full_name
[given_name, family_name].join(" ")
def full_name(context: :internal)
FullNameFormatter.call(self, context:)
end

def has_preferred_name?
preferred_given_name.present? || preferred_family_name.present?
end

def preferred_full_name
[
preferred_given_name.presence || given_name,
preferred_family_name.presence || family_name
].join(" ")
def preferred_full_name(context: :internal)
FullNameFormatter.call(self, context:, parts_prefix: :preferred)
end

def preferred_full_name_changed?
Expand Down
15 changes: 9 additions & 6 deletions app/models/concerns/vaccination_record_performed_by_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ module VaccinationRecordPerformedByConcern
}
end

PerformedBy =
Struct.new(:given_name, :family_name) do
def full_name
FullNameFormatter.call(self, context: :internal)
end
end

def performed_by
return performed_by_user if performed_by_user

if performed_by_given_name.present? || performed_by_family_name.present?
OpenStruct.new(
PerformedBy.new(
given_name: performed_by_given_name,
family_name: performed_by_family_name,
full_name: [
performed_by_given_name,
performed_by_family_name
].compact_blank.join(" ")
family_name: performed_by_family_name
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/parent_interface/consent_forms/confirm.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<%= govuk_summary_list do |summary_list|
summary_list.with_row do |row|
row.with_key { "Child’s name" }
row.with_value { @consent_form.full_name }
row.with_value { @consent_form.full_name(context: :parents) }
row.with_action(text: "Change",
href: change_link[:name],
visually_hidden_text: "child’s name")
Expand All @@ -148,7 +148,7 @@
if @consent_form.use_preferred_name
summary_list.with_row do |row|
row.with_key { "Also known as" }
row.with_value { @consent_form.preferred_full_name }
row.with_value { @consent_form.preferred_full_name(context: :parents) }
row.with_action(text: "Change",
href: change_link[:name],
visually_hidden_text: "common name")
Expand Down
24 changes: 12 additions & 12 deletions spec/components/app_activity_log_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
title: "Vaccinated with Gardasil 9",
date: "31 May 2024 at 12:00pm",
notes: "Some notes",
by: "Nurse Joy",
by: "JOY, Nurse",
programme: "HPV"

include_examples "card",
Expand All @@ -155,14 +155,14 @@
include_examples "card",
title: "Triaged decision: Safe to vaccinate",
date: "30 May 2024 at 2:30pm",
by: "Nurse Joy",
by: "JOY, Nurse",
programme: "HPV"

include_examples "card",
title: "Triaged decision: Keep in triage",
date: "30 May 2024 at 2:00pm",
notes: "Some notes",
by: "Nurse Joy",
by: "JOY, Nurse",
programme: "HPV"

include_examples "card",
Expand All @@ -173,7 +173,7 @@
include_examples "card",
title: "Consent given by Jane Doe (Mum)",
date: "30 May 2024 at 12:00pm",
by: "Nurse Joy",
by: "JOY, Nurse",
programme: "HPV"

include_examples "card",
Expand All @@ -184,7 +184,7 @@
title: "Consent school request hpv sent",
date: "10 May 2024 at 12:00am",
notes: "[email protected]",
by: "Nurse Joy",
by: "JOY, Nurse",
programme: "HPV"
end

Expand All @@ -207,7 +207,7 @@
title: "Vaccination not given: Unwell",
date: "31 May 2024 at 1:00pm",
notes: "Some notes.",
by: "Nurse Joy",
by: "JOY, Nurse",
programme: "HPV"
end

Expand All @@ -228,7 +228,7 @@
include_examples "card",
title: "Vaccinated with Gardasil 9",
date: "31 May 2024 at 1:00pm",
by: "Nurse Joy",
by: "JOY, Nurse",
programme: "HPV"

include_examples "card",
Expand All @@ -251,7 +251,7 @@

include_examples "card",
title:
"Consent given by Sarah Doe (Child (Gillick competent))",
"Consent given by DOE, Sarah (Child (Gillick competent))",
date: "30 May 2024 at 12:00pm",
programme: "HPV"
end
Expand Down Expand Up @@ -290,7 +290,7 @@
title:
"Consent response manually matched with child record",
date: "30 May 2024 at 1:00pm",
by: "Nurse Joy"
by: "JOY, Nurse"
end

describe "withdrawn consent" do
Expand Down Expand Up @@ -370,15 +370,15 @@
title: "Completed Gillick assessment as Gillick competent",
notes: "First notes",
date: "1 June 2024 at 12:00pm",
by: "Nurse Joy",
by: "JOY, Nurse",
programme: "Td/IPV"

include_examples "card",
title:
"Updated Gillick assessment as not Gillick competent",
notes: "Second notes",
date: "1 June 2024 at 1:00pm",
by: "Nurse Joy",
by: "JOY, Nurse",
programme: "Td/IPV"
end

Expand All @@ -400,6 +400,6 @@
title: "Completed pre-screening checks",
notes: "Some notes",
date: "1 June 2024 at 12:00pm",
by: "Nurse Joy"
by: "JOY, Nurse"
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
end

it "displays the key consent form details without anything being highlighted as unmatched" do
expect(rendered).to have_text("Full name\nJohn Doe\nJohn Doe")
expect(rendered).to have_text("Full name\nDOE, John\nDOE, John")
expect(rendered).to have_text(
"Date of birth\n1 January 2000\n1 January 2000"
)
Expand Down Expand Up @@ -67,7 +67,7 @@
end

it "displays the key consent form details with the unmatched details highlighted" do
expect(rendered).to have_text("Full name\nJohn Doe\nJane Doe")
expect(rendered).to have_text("Full name\nDOE, John\nDOE, Jane")
expect(rendered).to have_text(
"Date of birth\n1 January 2000\n2 January 2000"
)
Expand Down
4 changes: 2 additions & 2 deletions spec/components/app_consent_patient_summary_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
end

it { should have_content("Full name") }
it { should have_content("John Doe") }
it { should have_content("DOE, John") }

it { should have_content("Date of birth") }
it { should have_content("1 January 2000") }
Expand All @@ -57,7 +57,7 @@
end

it { should have_content("Full name") }
it { should have_content("John Doe") }
it { should have_content("DOE, John") }

it { should have_content("Date of birth") }
it { should have_content("1 January 2000") }
Expand Down
6 changes: 3 additions & 3 deletions spec/components/app_outcome_banner_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

it { should have_css(".app-card--red") }
it { should have_css(".nhsuk-card__heading", text: "Could not vaccinate") }
it { should have_text("Alya Merton has already had the vaccine") }
it { should have_text("MERTON, Alya has already had the vaccine") }
it { should have_text("Location\n#{location_name}") }
end

Expand All @@ -44,7 +44,7 @@

it { should have_css(".app-card--red") }
it { should have_css(".nhsuk-card__heading", text: "Could not vaccinate") }
it { should have_text("Reason\nAlya Merton has already had the vaccine") }
it { should have_text("Reason\nMERTON, Alya has already had the vaccine") }
end

context "not triaged, not possible to vaccinate" do
Expand All @@ -54,7 +54,7 @@

it { should have_css(".app-card--red") }
it { should have_css(".nhsuk-card__heading", text: "Could not vaccinate") }
it { should have_text("Reason\nAlya Merton has already had the vaccine") }
it { should have_text("Reason\nMERTON, Alya has already had the vaccine") }
end

context "state is vaccinated" do
Expand Down
6 changes: 3 additions & 3 deletions spec/components/app_patient_summary_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
it { should have_content("123\u00A0\u200D456\u00A0\u200D7890") }

it { should have_content("Full name") }
it { should have_content("John Doe") }
it { should have_content("DOE, John") }

it { should have_content("Known as") }
it { should have_content("Johnny Doe") }
it { should have_content("DOE, Johnny") }

it { should have_content("Date of birth") }
it { should have_content("1 January 2000") }
Expand Down Expand Up @@ -82,7 +82,7 @@
context "with pending changes" do
let(:component) { described_class.new(patient.with_pending_changes) }

it { should have_css(".app-highlight", text: "Jane Doe") }
it { should have_css(".app-highlight", text: "DOE, Jane") }
it { should have_css(".app-highlight", text: "1 January 2001") }
it { should have_css(".app-highlight", text: "SW1A 2AA") }
it { should_not have_css(".app-highlight", text: "Male") }
Expand Down
6 changes: 3 additions & 3 deletions spec/components/app_patient_table_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
".nhsuk-table__body .nhsuk-table__row",
count: 10
)
expect(rendered).to have_css(".nhsuk-table__cell", text: "John Smith")
expect(rendered).to have_css(".nhsuk-table__cell", text: "SMITH, John")
expect(rendered).to have_css(
".nhsuk-table__cell",
text: "999\u00A0\u200D999\u00A0\u200D9999"
Expand All @@ -64,14 +64,14 @@
end

it "renders links" do
expect(rendered).to have_link("John Smith")
expect(rendered).to have_link("SMITH, John")
end

context "with a patient not in the cohort" do
before { patients.first.update!(organisation: nil) }

it "doesn't render a link" do
expect(rendered).not_to have_link("John Smith")
expect(rendered).not_to have_link("SMITH, John")
expect(rendered).to have_content("Child has moved out of the area")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/components/app_timestamped_entry_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
)
end

it { should have_link("Test User", href: "mailto:[email protected]") }
it { should have_link("USER, Test", href: "mailto:[email protected]") }
end
end
4 changes: 2 additions & 2 deletions spec/components/app_triage_notes_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
it { should have_css("h3", text: "Triaged decision: Safe to vaccinate") }
it { should have_css("p", text: "Some notes") }
it { should have_css("p", text: "4 December 2023 at 10:04am") }
it { should have_css("p", text: "Joe Gear") }
it { should have_css("p", text: "GEAR, Joe") }
it { should_not have_css("hr") }
end

Expand Down Expand Up @@ -84,7 +84,7 @@
it { should have_css("h3", text: "Completed pre-screening checks") }
it { should have_css("p", text: "Some notes") }
it { should have_css("p", text: "4 December 2023 at 10:04am") }
it { should have_css("p", text: "Joe Gear") }
it { should have_css("p", text: "GEAR, Joe") }
it { should_not have_css("hr") }
end
end
13 changes: 10 additions & 3 deletions spec/components/app_vaccination_record_summary_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,17 @@

describe "vaccinator row" do
context "when the user is present" do
let(:vaccination_record) do
create(
:vaccination_record,
performed_by: create(:user, given_name: "Test", family_name: "Nurse")
)
end

it do
expect(rendered).to have_css(
".nhsuk-summary-list__row",
text: "Vaccinator\nTest User"
text: "Vaccinator\nNURSE, Test"
)
end
end
Expand All @@ -229,14 +236,14 @@
:vaccination_record,
performed_by: nil,
performed_by_given_name: "Test",
performed_by_family_name: "User"
performed_by_family_name: "Nurse"
)
end

it do
expect(rendered).to have_css(
".nhsuk-summary-list__row",
text: "Vaccinator\nTest User"
text: "Vaccinator\nNURSE, Test"
)
end
end
Expand Down
Loading

0 comments on commit 290b664

Please sign in to comment.