Skip to content

Commit 6e55e35

Browse files
authored
Add ability to remove parent relationships (#3486)
This adds a new page which allows the anyone to remove a parent relationship from a patient while retaining any consents submitted against this patient by the parent. This is based on the latest designs in the prototype. [Jira Issue](https://nhsd-jira.digital.nhs.uk/browse/MAV-1088) ## Screenshots <img width="783" alt="Screenshot 2025-05-01 at 16 16 31" src="https://github.com/user-attachments/assets/9913a531-8e99-499e-b39d-bafb3d925cb9" /> <img width="728" alt="Screenshot 2025-05-01 at 16 16 35" src="https://github.com/user-attachments/assets/772f5b5b-b56b-401e-ac60-3b86fe57c374" /> <img width="1152" alt="Screenshot 2025-05-01 at 16 16 39" src="https://github.com/user-attachments/assets/1c895fa6-56b4-4f85-9044-27bc9c5bc90a" />
2 parents 49fc960 + 577ecaf commit 6e55e35

15 files changed

+241
-113
lines changed

app/components/app_child_summary_component.rb

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
# frozen_string_literal: true
22

33
class AppChildSummaryComponent < ViewComponent::Base
4-
def initialize(child, change_links: {})
4+
def initialize(child, show_parents: false, change_links: {}, remove_links: {})
55
super
66

77
@child = child
8+
@show_parents = show_parents
89
@change_links = change_links
10+
@remove_links = remove_links
911
end
1012

1113
def call
12-
govuk_summary_list(actions: @change_links.present?) do |summary_list|
14+
govuk_summary_list(
15+
actions: @change_links.present? || @remove_links.present?
16+
) do |summary_list|
1317
summary_list.with_row do |row|
1418
row.with_key { "NHS number" }
1519
row.with_value { format_nhs_number }
@@ -69,6 +73,26 @@ def call
6973
row.with_value { gp_practice.name }
7074
end
7175
end
76+
if @show_parents && !@child.restricted?
77+
@child.parent_relationships.each do |parent_relationship|
78+
summary_list.with_row do |row|
79+
row.with_key { parent_relationship.ordinal_label.upcase_first }
80+
row.with_value do
81+
helpers.format_parent_with_relationship(parent_relationship)
82+
end
83+
if (
84+
href =
85+
@remove_links.dig(:parent, parent_relationship.parent_id)
86+
)
87+
row.with_action(
88+
text: "Remove",
89+
href:,
90+
visually_hidden_text: parent_relationship.ordinal_label
91+
)
92+
end
93+
end
94+
end
95+
end
7296
end
7397
end
7498

app/components/app_parent_card_component.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ def initialize(parent_relationship:, change_links: {})
1111
def call
1212
render AppCardComponent.new do |card|
1313
card.with_heading { "Parent or guardian" }
14-
render AppParentSummaryComponent.new(
15-
parent_relationship:,
16-
change_links:,
17-
show_name_and_relationship: true
18-
)
14+
render AppParentSummaryComponent.new(parent_relationship:, change_links:)
1915
end
2016
end
2117

app/components/app_parent_summary_component.rb

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,42 @@
11
# frozen_string_literal: true
22

33
class AppParentSummaryComponent < ViewComponent::Base
4-
def initialize(
5-
parent_relationship:,
6-
change_links: {},
7-
show_name_and_relationship: false
8-
)
4+
def initialize(parent_relationship:, change_links: {})
95
super
106

117
@parent_relationship = parent_relationship
128
@parent = parent_relationship.parent
139
@patient = parent_relationship.patient
1410

1511
@change_links = change_links
16-
17-
@show_name_and_relationship = show_name_and_relationship
1812
end
1913

2014
def call
2115
govuk_summary_list do |summary_list|
22-
if @show_name_and_relationship
23-
summary_list.with_row do |row|
24-
row.with_key { "Name" }
16+
summary_list.with_row do |row|
17+
row.with_key { "Name" }
2518

26-
if @parent.full_name.present?
27-
row.with_value { @parent.full_name }
28-
if (href = @change_links[:name])
29-
row.with_action(
30-
text: "Change",
31-
href:,
32-
visually_hidden_text: "name"
33-
)
34-
end
35-
elsif (href = @change_links[:name])
36-
row.with_value { govuk_link_to("Add name", href) }
37-
else
38-
row.with_value { "Not provided" }
19+
if @parent.full_name.present?
20+
row.with_value { @parent.full_name }
21+
if (href = @change_links[:name])
22+
row.with_action(text: "Change", href:, visually_hidden_text: "name")
3923
end
24+
elsif (href = @change_links[:name])
25+
row.with_value { govuk_link_to("Add name", href) }
26+
else
27+
row.with_value { "Not provided" }
4028
end
29+
end
4130

42-
summary_list.with_row do |row|
43-
row.with_key { "Relationship" }
44-
row.with_value { @parent_relationship.label }
45-
if (href = @change_links[:relationship])
46-
row.with_action(
47-
text: "Change",
48-
href:,
49-
visually_hidden_text: "relationship"
50-
)
51-
end
31+
summary_list.with_row do |row|
32+
row.with_key { "Relationship" }
33+
row.with_value { @parent_relationship.label }
34+
if (href = @change_links[:relationship])
35+
row.with_action(
36+
text: "Change",
37+
href:,
38+
visually_hidden_text: "relationship"
39+
)
5240
end
5341
end
5442

app/components/app_patient_card_component.rb

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,21 @@ class AppPatientCardComponent < ViewComponent::Base
2323
) %>
2424
<% end %>
2525
26-
<%= render AppChildSummaryComponent.new(patient) %>
27-
28-
<% unless patient.restricted? %>
29-
<% parent_relationships.each do |parent_relationship| %>
30-
<h3 class="nhsuk-heading-s nhsuk-u-margin-bottom-2">
31-
<%= parent_relationship.label_with_parent %>
32-
</h3>
33-
34-
<%= render AppParentSummaryComponent.new(parent_relationship:) %>
35-
<% end %>
36-
<% end %>
26+
<%= render AppChildSummaryComponent.new(patient, show_parents: true, change_links:, remove_links:) %>
3727
3828
<%= content %>
3929
<% end %>
4030
ERB
4131

42-
def initialize(patient)
32+
def initialize(patient, change_links: {}, remove_links: {})
4333
super
4434

4535
@patient = patient
36+
@change_links = change_links
37+
@remove_links = remove_links
4638
end
4739

4840
private
4941

50-
attr_reader :patient
51-
52-
delegate :parent_relationships, to: :patient
42+
attr_reader :patient, :change_links, :remove_links
5343
end

app/components/app_vaccination_record_summary_component.rb

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -320,24 +320,14 @@ def dose_number_value
320320
def dose_number
321321
return nil if @vaccine&.seasonal?
322322

323-
return "Unknown" if @vaccination_record.dose_sequence.nil?
324-
325-
numbers_to_words = {
326-
1 => "First",
327-
2 => "Second",
328-
3 => "Third",
329-
4 => "Fourth",
330-
5 => "Fifth",
331-
6 => "Sixth",
332-
7 => "Seventh",
333-
8 => "Eighth",
334-
9 => "Ninth"
335-
}.freeze
336-
337-
if @vaccination_record.dose_sequence <= 9
338-
numbers_to_words[@vaccination_record.dose_sequence]
323+
dose_sequence = @vaccination_record.dose_sequence
324+
325+
if dose_sequence.nil?
326+
"Unknown"
327+
elsif dose_sequence <= 10
328+
I18n.t(dose_sequence, scope: :ordinal_number).upcase_first
339329
else
340-
@vaccination_record.dose_sequence.ordinalize
330+
dose_sequence.ordinalize
341331
end
342332
end
343333

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
class ParentRelationshipsController < ApplicationController
4+
before_action :set_patient
5+
before_action :set_parent_relationship
6+
before_action :set_parent
7+
8+
def confirm_destroy = render :destroy
9+
10+
def destroy
11+
@parent_relationship.destroy!
12+
13+
redirect_to edit_patient_path(@patient),
14+
flash: {
15+
success: "Parent relationship removed"
16+
}
17+
end
18+
19+
private
20+
21+
def set_patient
22+
@patient = policy_scope(Patient).find(params[:patient_id])
23+
end
24+
25+
def set_parent_relationship
26+
@parent_relationship =
27+
@patient
28+
.parent_relationships
29+
.includes(:parent)
30+
.find_by!(parent_id: params[:id])
31+
end
32+
33+
def set_parent
34+
@parent = @parent_relationship.parent
35+
end
36+
end

app/models/parent_relationship.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,16 @@ def label
5656
def label_with_parent
5757
unknown? ? parent.label : "#{parent.label} (#{label})"
5858
end
59+
60+
def ordinal_label
61+
index = patient.parent_relationships.find_index(self)
62+
63+
if index.nil?
64+
"parent or guardian"
65+
elsif index <= 10
66+
"#{I18n.t(index + 1, scope: :ordinal_number)} parent or guardian"
67+
else
68+
"#{index.ordinalize} parent or guardian"
69+
end
70+
end
5971
end

app/models/patient.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Patient < ApplicationRecord
6767
has_many :consent_statuses
6868
has_many :consents
6969
has_many :notify_log_entries
70-
has_many :parent_relationships
70+
has_many :parent_relationships, -> { order(:created_at) }
7171
has_many :patient_sessions
7272
has_many :school_move_log_entries
7373
has_many :school_moves
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<% content_for :before_main do %>
2+
<%= render AppBacklinkComponent.new(edit_patient_path(@patient), name: "patient") %>
3+
<% end %>
4+
5+
<% page_title = "Are you sure you want to remove the relationship between #{@parent_relationship.label_with_parent} and #{@patient.full_name(context: :parents)}?" %>
6+
7+
<%= h1 page_title do %>
8+
<span class="nhsuk-caption-l">
9+
<%= @patient.full_name %>
10+
</span>
11+
<%= page_title %>
12+
<% end %>
13+
14+
<% if @patient.consents.not_invalidated.exists?(parent: @parent) %>
15+
<div class="nhsuk-inset-text">
16+
<span class="nhsuk-u-visually-hidden">Information: </span>
17+
<p><%= @parent.label %> has submitted the following consent responses for this child:</p>
18+
<ul class="govuk-list govuk-list--bullet">
19+
<% @patient.consents.includes(:programme).not_invalidated.where(parent: @parent).find_each do |consent| %>
20+
<li><%= consent.human_enum_name(:response).upcase_first %> (<%= consent.created_at.to_date.to_fs(:long) %> for <%= consent.programme.name %>)</li>
21+
<% end %>
22+
</ul>
23+
<p>You should review these before continuing.</p>
24+
</div>
25+
<% end %>
26+
27+
<%= form_with url: patient_parent_relationship_path, method: :delete do |f| %>
28+
<div class="app-button-group">
29+
<%= f.govuk_submit "Yes, remove this relationship", warning: true %>
30+
<%= govuk_link_to "No, return to child record", edit_patient_path(@patient) %>
31+
</div>
32+
<% end %>

app/views/patients/edit.html.erb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99
<%= page_title %>
1010
<% end %>
1111

12-
<% change_links = { nhs_number: edit_nhs_number_patient_path(@patient) } %>
12+
<% change_links = {
13+
nhs_number: edit_nhs_number_patient_path(@patient),
14+
} %>
1315

14-
<%= render AppCardComponent.new do |card| %>
15-
<% card.with_heading { "Record details" } %>
16-
<%= render AppChildSummaryComponent.new(@patient, change_links:) %>
17-
<% end %>
16+
<% remove_links = {
17+
parent: @patient.parent_relationships.each_with_object({}) do |parent_relationship, memo|
18+
memo[parent_relationship.parent_id] = destroy_patient_parent_relationship_path(@patient, parent_relationship.parent_id)
19+
end,
20+
} %>
21+
22+
<%= render AppPatientCardComponent.new(@patient, change_links:, remove_links:) %>
1823

1924
<%= govuk_button_link_to "Continue", patient_path(@patient) %>

0 commit comments

Comments
 (0)