Skip to content

Commit 5b4269e

Browse files
committed
Add ability to edit parent details
This adds a new page which allows the nurses to edit the parent details of a patient, including the name, relationship, phone number and email address.
1 parent dfaf3ca commit 5b4269e

File tree

8 files changed

+213
-3
lines changed

8 files changed

+213
-3
lines changed

app/components/app_child_summary_component.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ def call
7777
row.with_value do
7878
helpers.format_parent_with_relationship(parent_relationship)
7979
end
80+
if (
81+
href =
82+
@change_links.dig(:parent, parent_relationship.parent_id)
83+
)
84+
row.with_action(
85+
text: "Change",
86+
href:,
87+
visually_hidden_text: parent_relationship.ordinal_label
88+
)
89+
end
8090
end
8191
end
8292
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
class ParentsController < ApplicationController
4+
before_action :set_patient
5+
before_action :set_parent_relationship
6+
before_action :set_parent
7+
8+
def edit
9+
end
10+
11+
def update
12+
if @parent_relationship.update(parent_relationship_params)
13+
redirect_to edit_patient_path(@patient)
14+
else
15+
render :edit, status: :unprocessable_entity
16+
end
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+
37+
def parent_relationship_params
38+
params.expect(
39+
parent_relationship: [
40+
:type,
41+
:other_name,
42+
{ parent_attributes: %i[id full_name email phone] }
43+
]
44+
)
45+
end
46+
end

app/models/parent_relationship.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class ParentRelationship < ApplicationRecord
4949

5050
before_validation -> { self.other_name = nil unless other? }
5151

52+
accepts_nested_attributes_for :parent, update_only: true
53+
5254
def label
5355
(other? ? other_name : human_enum_name(:type)).capitalize
5456
end

app/views/parents/edit.html.erb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<% content_for :before_main do %>
2+
<%= render AppBacklinkComponent.new(edit_patient_path(@patient), name: "patient") %>
3+
<% end %>
4+
5+
<%= form_with model: @parent_relationship, url: patient_parent_path(@patient, @parent), method: :put do |f| %>
6+
<%= f.govuk_error_summary %>
7+
8+
<% page_title = "Details for #{@parent_relationship.ordinal_label}" %>
9+
<%= h1 page_title: do %>
10+
<span class="nhsuk-caption-l"><%= @patient.full_name %></span>
11+
<%= page_title %>
12+
<% end %>
13+
14+
<%= f.fields_for :parent do |parent_f| %>
15+
<%= parent_f.govuk_text_field :full_name, label: { text: "Name" } %>
16+
<% end %>
17+
18+
<%= f.govuk_radio_buttons_fieldset :type, legend: { text: "Relationship to child", size: "s" } do %>
19+
<%= f.govuk_radio_button :type, :mother, label: { text: "Mum" }, link_errors: true %>
20+
<%= f.govuk_radio_button :type, :father, label: { text: "Dad" } %>
21+
<%= f.govuk_radio_button :type, :guardian, label: { text: "Guardian" } %>
22+
<%= f.govuk_radio_button :type, :other, label: { text: "Other" } do %>
23+
<%= f.govuk_text_field :other_name, label: { text: "Relationship to the child" }, hint: { text: "For example, carer" } %>
24+
<% end %>
25+
<% end %>
26+
27+
<%= f.fields_for :parent do |parent_f| %>
28+
<%= parent_f.govuk_text_field :email, label: { text: "Email address" } %>
29+
<%= parent_f.govuk_text_field :phone, label: { text: "Phone number" } %>
30+
<% end %>
31+
32+
<%= f.govuk_submit "Continue" %>
33+
<% end %>

app/views/patients/edit.html.erb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
<%= page_title %>
1010
<% end %>
1111

12-
<%= render AppPatientCardComponent.new(@patient, change_links: {
13-
nhs_number: edit_nhs_number_patient_path(@patient),
14-
}) %>
12+
<% change_links = {
13+
nhs_number: edit_nhs_number_patient_path(@patient),
14+
parent: @patient.parent_relationships.each_with_object({}) do |parent_relationship, memo|
15+
memo[parent_relationship.parent_id] = edit_patient_parent_path(@patient, parent_relationship.parent_id)
16+
end,
17+
} %>
18+
19+
<%= render AppPatientCardComponent.new(@patient, change_links:) %>
1520

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

config/locales/en.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ en:
342342
contact_method_other_details:
343343
blank: Enter details about how to contact you
344344
too_long: Enter details that are less than 300 characters long
345+
email:
346+
blank: Enter an email address
347+
phone:
348+
blank: Enter a phone number
345349
patient:
346350
attributes:
347351
nhs_number:

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@
146146
resources :patients, only: %i[index show edit update] do
147147
post "", action: :index, on: :collection
148148

149+
resources :parents, only: %i[edit update]
150+
149151
member do
150152
get "log"
151153

spec/features/edit_parent_spec.rb

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# frozen_string_literal: true
2+
3+
describe "Edit parent" do
4+
before { given_a_patient_with_a_parent_exists }
5+
6+
scenario "User edits the name of a parent" do
7+
when_i_visit_the_patient_page
8+
and_i_click_on_edit_child_record
9+
and_i_click_on_change_parent
10+
then_i_see_the_edit_parent_page
11+
12+
when_i_change_the_name_of_the_parent
13+
then_i_see_the_new_name_of_the_parent
14+
end
15+
16+
scenario "User edits the relationship of a parent" do
17+
when_i_visit_the_patient_page
18+
and_i_click_on_edit_child_record
19+
and_i_click_on_change_parent
20+
then_i_see_the_edit_parent_page
21+
22+
when_i_change_the_relationship_of_the_parent_to_mother
23+
then_i_see_the_new_relationship_of_the_parent_of_mother
24+
25+
when_i_click_on_change_parent
26+
and_i_change_the_relationship_of_the_parent_to_other
27+
then_i_see_the_new_relationship_of_the_parent_of_other
28+
end
29+
30+
scenario "User edits the contact details of a parent" do
31+
when_i_visit_the_patient_page
32+
and_i_click_on_edit_child_record
33+
and_i_click_on_change_parent
34+
then_i_see_the_edit_parent_page
35+
36+
when_i_change_the_contact_details_of_the_parent
37+
then_i_see_the_new_contact_details_of_the_parent
38+
end
39+
40+
def given_a_patient_with_a_parent_exists
41+
organisation = create(:organisation)
42+
@nurse = create(:nurse, organisation:)
43+
44+
@patient = create(:patient, organisation:)
45+
46+
@parent = create(:parent)
47+
48+
create(:parent_relationship, patient: @patient, parent: @parent)
49+
end
50+
51+
def when_i_visit_the_patient_page
52+
sign_in @nurse
53+
visit patient_path(@patient)
54+
end
55+
56+
def and_i_click_on_edit_child_record
57+
click_on "Edit child record"
58+
end
59+
60+
def when_i_click_on_change_parent
61+
click_on "Change first parent or guardian"
62+
end
63+
64+
alias_method :and_i_click_on_change_parent, :when_i_click_on_change_parent
65+
66+
def then_i_see_the_edit_parent_page
67+
expect(page).to have_content("Details for first parent or guardian")
68+
end
69+
70+
def when_i_change_the_name_of_the_parent
71+
fill_in "Name", with: "Selina Meyer"
72+
click_on "Continue"
73+
end
74+
75+
def then_i_see_the_new_name_of_the_parent
76+
expect(page).to have_content("Selina Meyer")
77+
end
78+
79+
def when_i_change_the_relationship_of_the_parent_to_mother
80+
choose "Mum"
81+
click_on "Continue"
82+
end
83+
84+
def then_i_see_the_new_relationship_of_the_parent_of_mother
85+
expect(page).to have_content("Mum")
86+
end
87+
88+
def and_i_change_the_relationship_of_the_parent_to_other
89+
choose "Other"
90+
fill_in "Relationship to the child", with: "Someone"
91+
click_on "Continue"
92+
end
93+
94+
def then_i_see_the_new_relationship_of_the_parent_of_other
95+
expect(page).to have_content("Someone")
96+
end
97+
98+
def when_i_change_the_contact_details_of_the_parent
99+
fill_in "Email address", with: "selina@meyer.com"
100+
fill_in "Phone number", with: "07700 900 000"
101+
click_on "Continue"
102+
end
103+
104+
def then_i_see_the_new_contact_details_of_the_parent
105+
expect(page).to have_content("selina@meyer.com")
106+
expect(page).to have_content("07700 900000")
107+
end
108+
end

0 commit comments

Comments
 (0)