Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/components/app_child_summary_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ def call
row.with_value do
helpers.format_parent_with_relationship(parent_relationship)
end

if (
href =
@change_links.dig(:parent, parent_relationship.parent_id)
)
row.with_action(
text: "Change",
href:,
visually_hidden_text: parent_relationship.ordinal_label
)
end

if (
href =
@remove_links.dig(:parent, parent_relationship.parent_id)
Expand Down
2 changes: 1 addition & 1 deletion app/components/app_patient_card_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class AppPatientCardComponent < ViewComponent::Base
erb_template <<-ERB
<%= render AppCardComponent.new do |card| %>
<% card.with_heading { "Child record" } %>
<% card.with_heading { "Child’s details" } %>

<% if patient.date_of_death.present? %>
<%= render AppStatusComponent.new(
Expand Down
21 changes: 21 additions & 0 deletions app/controllers/parent_relationships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ class ParentRelationshipsController < ApplicationController
before_action :set_parent_relationship
before_action :set_parent

def edit
end

def update
if @parent_relationship.update(parent_relationship_params)
redirect_to edit_patient_path(@patient)
else
render :edit, status: :unprocessable_entity
end
end

def confirm_destroy = render :destroy

def destroy
Expand Down Expand Up @@ -33,4 +44,14 @@ def set_parent_relationship
def set_parent
@parent = @parent_relationship.parent
end

def parent_relationship_params
params.expect(
parent_relationship: [
:type,
:other_name,
{ parent_attributes: %i[id full_name email phone] }
]
)
end
end
1 change: 1 addition & 0 deletions app/controllers/patients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def log
end

def edit
render layout: "full"
end

def update
Expand Down
2 changes: 2 additions & 0 deletions app/models/parent_relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class ParentRelationship < ApplicationRecord

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

accepts_nested_attributes_for :parent, update_only: true

def label
(other? ? other_name : human_enum_name(:type)).capitalize
end
Expand Down
33 changes: 33 additions & 0 deletions app/views/parent_relationships/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<% content_for :before_main do %>
<%= render AppBacklinkComponent.new(edit_patient_path(@patient), name: "patient") %>
<% end %>

<%= form_with model: @parent_relationship, url: patient_parent_relationship_path(@patient, @parent), method: :put do |f| %>
<%= f.govuk_error_summary %>

<% page_title = "Details for #{@parent_relationship.ordinal_label}" %>
<%= h1 page_title: do %>
<span class="nhsuk-caption-l"><%= @patient.full_name %></span>
<%= page_title %>
<% end %>

<%= f.fields_for :parent do |parent_f| %>
<%= parent_f.govuk_text_field :full_name, label: { text: "Name" } %>
<% end %>

<%= f.govuk_radio_buttons_fieldset :type, legend: { text: "Relationship to child", size: "s" } do %>
<%= f.govuk_radio_button :type, :mother, label: { text: "Mum" }, link_errors: true %>
<%= f.govuk_radio_button :type, :father, label: { text: "Dad" } %>
<%= f.govuk_radio_button :type, :guardian, label: { text: "Guardian" } %>
<%= f.govuk_radio_button :type, :other, label: { text: "Other" } do %>
<%= f.govuk_text_field :other_name, label: { text: "Relationship to the child" }, hint: { text: "For example, carer" } %>
<% end %>
<% end %>

<%= f.fields_for :parent do |parent_f| %>
<%= parent_f.govuk_text_field :email, label: { text: "Email address" } %>
<%= parent_f.govuk_text_field :phone, label: { text: "Phone number" } %>
<% end %>

<%= f.govuk_submit "Continue" %>
<% end %>
10 changes: 4 additions & 6 deletions app/views/patients/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
<%= render AppBacklinkComponent.new(patient_path(@patient), name: @patient.full_name) %>
<% end %>

<% page_title = "Edit child record" %>

<%= h1 page_title: do %>
<span class="nhsuk-caption-l"><%= @patient.full_name %></span>
<%= page_title %>
<% end %>
<%= h1 "Edit child record" %>

<% change_links = {
nhs_number: edit_nhs_number_patient_path(@patient),
parent: @patient.parent_relationships.each_with_object({}) do |parent_relationship, memo|
memo[parent_relationship.parent_id] = edit_patient_parent_relationship_path(@patient, parent_relationship.parent_id)
end,
} %>

<% remove_links = {
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ en:
contact_method_other_details:
blank: Enter details about how to contact you
too_long: Enter details that are less than 300 characters long
email:
blank: Enter an email address
phone:
blank: Enter a phone number
patient:
attributes:
nhs_number:
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@
resources :patients, only: %i[index show edit update] do
post "", action: :index, on: :collection

resources :parent_relationships, path: "parents", only: %i[destroy] do
resources :parent_relationships,
path: "parents",
only: %i[edit update destroy] do
get "destroy", action: :confirm_destroy, on: :member, as: "destroy"
end

Expand Down
108 changes: 108 additions & 0 deletions spec/features/edit_parent_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# frozen_string_literal: true

describe "Edit parent" do
before { given_a_patient_with_a_parent_exists }

scenario "User edits the name of a parent" do
when_i_visit_the_patient_page
and_i_click_on_edit_child_record
and_i_click_on_change_parent
then_i_see_the_edit_parent_page

when_i_change_the_name_of_the_parent
then_i_see_the_new_name_of_the_parent
end

scenario "User edits the relationship of a parent" do
when_i_visit_the_patient_page
and_i_click_on_edit_child_record
and_i_click_on_change_parent
then_i_see_the_edit_parent_page

when_i_change_the_relationship_of_the_parent_to_mother
then_i_see_the_new_relationship_of_the_parent_of_mother

when_i_click_on_change_parent
and_i_change_the_relationship_of_the_parent_to_other
then_i_see_the_new_relationship_of_the_parent_of_other
end

scenario "User edits the contact details of a parent" do
when_i_visit_the_patient_page
and_i_click_on_edit_child_record
and_i_click_on_change_parent
then_i_see_the_edit_parent_page

when_i_change_the_contact_details_of_the_parent
then_i_see_the_new_contact_details_of_the_parent
end

def given_a_patient_with_a_parent_exists
organisation = create(:organisation)
@nurse = create(:nurse, organisation:)

@patient = create(:patient, organisation:)

@parent = create(:parent)

create(:parent_relationship, patient: @patient, parent: @parent)
end

def when_i_visit_the_patient_page
sign_in @nurse
visit patient_path(@patient)
end

def and_i_click_on_edit_child_record
click_on "Edit child record"
end

def when_i_click_on_change_parent
click_on "Change first parent or guardian"
end

alias_method :and_i_click_on_change_parent, :when_i_click_on_change_parent

def then_i_see_the_edit_parent_page
expect(page).to have_content("Details for first parent or guardian")
end

def when_i_change_the_name_of_the_parent
fill_in "Name", with: "Selina Meyer"
click_on "Continue"
end

def then_i_see_the_new_name_of_the_parent
expect(page).to have_content("Selina Meyer")
end

def when_i_change_the_relationship_of_the_parent_to_mother
choose "Mum"
click_on "Continue"
end

def then_i_see_the_new_relationship_of_the_parent_of_mother
expect(page).to have_content("Mum")
end

def and_i_change_the_relationship_of_the_parent_to_other
choose "Other"
fill_in "Relationship to the child", with: "Someone"
click_on "Continue"
end

def then_i_see_the_new_relationship_of_the_parent_of_other
expect(page).to have_content("Someone")
end

def when_i_change_the_contact_details_of_the_parent
fill_in "Email address", with: "selina@meyer.com"
fill_in "Phone number", with: "07700 900 000"
click_on "Continue"
end

def then_i_see_the_new_contact_details_of_the_parent
expect(page).to have_content("selina@meyer.com")
expect(page).to have_content("07700 900000")
end
end