Skip to content

Commit f6d353f

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 6bf5adc commit f6d353f

File tree

10 files changed

+189
-8
lines changed

10 files changed

+189
-8
lines changed

app/components/app_child_summary_component.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ def call
8080
row.with_value do
8181
helpers.format_parent_with_relationship(parent_relationship)
8282
end
83+
84+
if (
85+
href =
86+
@change_links.dig(:parent, parent_relationship.parent_id)
87+
)
88+
row.with_action(
89+
text: "Change",
90+
href:,
91+
visually_hidden_text: parent_relationship.ordinal_label
92+
)
93+
end
94+
8395
if (
8496
href =
8597
@remove_links.dig(:parent, parent_relationship.parent_id)

app/components/app_patient_card_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class AppPatientCardComponent < ViewComponent::Base
44
erb_template <<-ERB
55
<%= render AppCardComponent.new do |card| %>
6-
<% card.with_heading { "Child record" } %>
6+
<% card.with_heading { "Child’s details" } %>
77
88
<% if patient.date_of_death.present? %>
99
<%= render AppStatusComponent.new(

app/controllers/parent_relationships_controller.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ class ParentRelationshipsController < ApplicationController
55
before_action :set_parent_relationship
66
before_action :set_parent
77

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+
819
def confirm_destroy = render :destroy
920

1021
def destroy
@@ -33,4 +44,14 @@ def set_parent_relationship
3344
def set_parent
3445
@parent = @parent_relationship.parent
3546
end
47+
48+
def parent_relationship_params
49+
params.expect(
50+
parent_relationship: [
51+
:type,
52+
:other_name,
53+
{ parent_attributes: %i[id full_name email phone] }
54+
]
55+
)
56+
end
3657
end

app/controllers/patients_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def log
2828
end
2929

3030
def edit
31+
render layout: "full"
3132
end
3233

3334
def update

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
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_relationship_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: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
<%= render AppBacklinkComponent.new(patient_path(@patient), name: @patient.full_name) %>
33
<% end %>
44

5-
<% page_title = "Edit child record" %>
6-
7-
<%= h1 page_title: do %>
8-
<span class="nhsuk-caption-l"><%= @patient.full_name %></span>
9-
<%= page_title %>
10-
<% end %>
5+
<%= h1 "Edit child record" %>
116

127
<% change_links = {
138
nhs_number: edit_nhs_number_patient_path(@patient),
9+
parent: @patient.parent_relationships.each_with_object({}) do |parent_relationship, memo|
10+
memo[parent_relationship.parent_id] = edit_patient_parent_relationship_path(@patient, parent_relationship.parent_id)
11+
end,
1412
} %>
1513

1614
<% remove_links = {

config/locales/en.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ en:
359359
contact_method_other_details:
360360
blank: Enter details about how to contact you
361361
too_long: Enter details that are less than 300 characters long
362+
email:
363+
blank: Enter an email address
364+
phone:
365+
blank: Enter a phone number
362366
patient:
363367
attributes:
364368
nhs_number:

config/routes.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@
150150
resources :patients, only: %i[index show edit update] do
151151
post "", action: :index, on: :collection
152152

153-
resources :parent_relationships, path: "parents", only: %i[destroy] do
153+
resources :parent_relationships,
154+
path: "parents",
155+
only: %i[edit update destroy] do
154156
get "destroy", action: :confirm_destroy, on: :member, as: "destroy"
155157
end
156158

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)