Skip to content
Draft
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
22 changes: 11 additions & 11 deletions app/controllers/draft_consents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,6 @@ def set_steps
self.steps = @draft_consent.wizard_steps
end

def set_back_link_path
@back_link_path =
if @draft_consent.editing?
wizard_path("confirm")
elsif current_step == @draft_consent.wizard_steps.first
session_patient_programme_path(@session, @patient, @programme)
else
previous_wizard_path
end
end

def is_who_step? = current_step == :who

NewOrExistingContactOption = Struct.new(:value, :label, :hint)
Expand Down Expand Up @@ -287,6 +276,17 @@ def set_triage_form
end
end

def set_back_link_path
@back_link_path =
if @draft_consent.editing?
wizard_path("confirm")
elsif current_step == @draft_consent.wizard_steps.first
session_patient_programme_path(@session, @patient, @programme)
else
previous_wizard_path
end
end

# Returns:
# {
# question_0: %i[notes response],
Expand Down
24 changes: 18 additions & 6 deletions app/models/draft_consent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ def parent
parent.email = parent_email
parent.full_name = parent_full_name
parent.phone = parent_phone
parent.phone_receive_updates = parent_phone_receive_updates
parent.phone_receive_updates =
parent_phone_receive_updates.presence || false

# We can't use find_or_initialize_by here because we need the object to
# remain attached to the parent so we can save the parent with its
Expand All @@ -260,7 +261,11 @@ def parent
parent_relationship.assign_attributes(
patient:, # acts as preload
type: parent_relationship_type,
other_name: parent_relationship_other_name
other_name: parent_relationship_other_name,
phone: parent_phone,
full_name: parent_full_name,
email: parent_email,
phone_receive_updates: parent_phone_receive_updates
)

if parent_relationship.new_record?
Expand All @@ -275,10 +280,13 @@ def parent=(value)

parent_relationship = value&.parent_relationships&.find_by(patient_id:)

self.parent_email = patient.restricted? ? "" : value&.email
self.parent_full_name = value&.full_name
self.parent_phone = patient.restricted? ? "" : value&.phone
self.parent_phone_receive_updates = value&.phone_receive_updates
self.parent_email =
patient.restricted? ? "" : parent_relationship&.email || value&.email
self.parent_full_name = parent_relationship&.full_name || value&.full_name
self.parent_phone =
patient.restricted? ? "" : parent_relationship&.phone || value&.phone
self.parent_phone_receive_updates =
parent_relationship&.phone_receive_updates || value&.phone_receive_updates
self.parent_relationship_type = parent_relationship&.type
self.parent_relationship_other_name = parent_relationship&.other_name
self.parent_responsibility = value ? true : nil
Expand Down Expand Up @@ -375,6 +383,10 @@ def parent_relationship
it.patient = patient # acts as preload
it.type = parent_relationship_type
it.other_name = parent_relationship_other_name
it.full_name = parent_full_name
it.email = parent_email
it.phone = parent_phone
it.phone_receive_updates = parent_phone_receive_updates
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/patient_sessions/consents/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<%= render AppConsentPatientSummaryComponent.new(@consent) %>
<% end %>

<% if @consent.parent_relationship.present? %>
<% if @consent.parent_relationship.present? || @consent.parent.present? %>
<%= render AppParentCardComponent.new(@consent) %>
<% end %>

Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ en:
other: Other
text: Can only receive text messages
voice: Can only receive voice calls
types:
father: dad
mother: mum
parent_relationship:
types:
father: dad
Expand Down
12 changes: 11 additions & 1 deletion spec/factories/patients.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,17 @@

parent_relationships do
parents.map do |parent|
association(:parent_relationship, patient: instance, parent:)
association(
:parent_relationship,
patient: instance,
parent:,
email: parent.email,
full_name: parent.full_name,
phone: parent.phone,
phone_receive_updates: parent.phone_receive_updates,
contact_method_type: parent.contact_method_type,
contact_method_other_details: parent.contact_method_other_details
)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
describe "Verbal consent" do
around { |example| travel_to(Date.new(2025, 7, 31)) { example.run } }

before { given_i_am_signed_in }
before do
Flipper.enable(:one_patient_per_parent)
given_i_am_signed_in
end

scenario "Given by a new mother parent contact" do
when_i_start_recording_consent_from_a_new_parental_contact
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# frozen_string_literal: true

describe "Verbal consent" do
around { |example| travel_to(Date.new(2025, 7, 31)) { example.run } }

before do
Flipper.disable(:one_patient_per_parent)
given_i_am_signed_in
end

scenario "Given by a new mother parent contact" do
when_i_start_recording_consent_from_a_new_parental_contact
and_i_enter_a_mum_relationship
and_i_record_that_verbal_consent_was_given
then_an_email_is_sent_to_the_parent_confirming_their_consent
and_i_can_see_the_parents_details_on_the_consent_response(
relationship: "Mum"
)
end

scenario "Given by a new other parent contact" do
when_i_start_recording_consent_from_a_new_parental_contact
and_i_enter_an_other_relationship
and_i_record_that_verbal_consent_was_given
then_an_email_is_sent_to_the_parent_confirming_their_consent
and_i_can_see_the_parents_details_on_the_consent_response(
relationship: "Other – Carer"
)
end

def given_i_am_signed_in
programmes = [Programme.hpv]
team = create(:team, :with_one_nurse, programmes:)
@session = create(:session, team:, programmes:)
@patient = create(:patient, session: @session)

PatientStatusUpdater.call

sign_in team.users.first
end

def when_i_start_recording_consent_from_a_new_parental_contact
visit session_patients_path(@session)
click_link @patient.full_name
click_button "Record a new consent response"

# Who are you trying to get consent from?
choose "Add a new parental contact"
click_button "Continue"
end

def and_i_enter_a_mum_relationship
fill_in "Full name", with: "Jane Smith"
choose "Mum"
fill_in "Email address", with: "jsmith@example.com"
fill_in "Phone number", with: "07987654321"
check "Get updates by text"
click_button "Continue"
end

def and_i_enter_an_other_relationship
fill_in "Full name", with: "Jane Smith"
choose "Other"

click_button "Continue"
expect(page).to have_content("Enter a relationship")
expect(page).to have_content(
"Choose whether there is parental responsibility"
)

fill_in "Relationship to the child", with: "Carer"
choose "Yes"

fill_in "Email address", with: "jsmith@example.com"
fill_in "Phone number", with: "07987654321"
check "Get updates by text"
click_button "Continue"
end

def and_i_record_that_verbal_consent_was_given
# How was the response given?
choose "By phone"
click_button "Continue"

# Do they agree?
choose "Yes, they agree"
click_button "Continue"

# Health questions
find_all(".nhsuk-fieldset")[0].choose "No"
find_all(".nhsuk-fieldset")[1].choose "No"
find_all(".nhsuk-fieldset")[2].choose "No"
find_all(".nhsuk-fieldset")[3].choose "No"
click_button "Continue"

# Confirm
expect(page).to have_content("Check and confirm answers")
expect(page).to have_content(["Method", "By phone"].join)
click_button "Confirm"

# Back on the consent responses page
expect(page).to have_content("Consent recorded for #{@patient.full_name}")
end

def and_i_can_see_the_parents_details_on_the_consent_response(relationship:)
click_link @patient.full_name, match: :first
click_link "Jane Smith"

expect(page).to have_content("Consent response from Jane Smith")

expect(page).to have_content(["Name", "Jane Smith"].join)
expect(page).to have_content(["Relationship", relationship].join)
expect(page).to have_content(
["Email address", "jsmith@example.com"].join("\n")
)
expect(page).to have_content(["Phone number", "07987 654321"].join("\n"))
end

def then_an_email_is_sent_to_the_parent_confirming_their_consent
expect_email_to("jsmith@example.com", :consent_confirmation_given)
end

def and_i_a_text_is_sent_to_the_parent_confirming_their_consent
expect_sms_to("07987 654321", :consent_confirmation_given)
end
end
50 changes: 28 additions & 22 deletions spec/features/verbal_consent_given_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

describe "Verbal consent" do
before { Flipper.enable(:one_patient_per_parent) }

scenario "Given HPV" do
given_an_hpv_programme_is_underway
and_i_am_signed_in
Expand Down Expand Up @@ -123,6 +125,7 @@ def create_programme(programme)
parents: [@parent],
date_of_birth: Programme::MIN_MMRV_ELIGIBILITY_DATE - 1.year
)
@parent_relationship = @patient.parent_relationships.first

PatientStatusUpdater.call
end
Expand Down Expand Up @@ -201,12 +204,10 @@ def record_that_verbal_consent_was_given(
"Choose who you are trying to get consent from"
)

parent_label =
@patient
.parent_relationships
.includes(:parent)
.find_by(patient: @patient)
.label_with_parent
parent_relationship =
@patient.parent_relationships.find_by(patient: @patient)
parent_relationship.strict_loading!(false)
parent_label = parent_relationship.label_with_parent

choose parent_label
click_button "Continue"
Expand Down Expand Up @@ -273,26 +274,27 @@ def when_i_confirm_the_consent_response

def then_the_parent_details_are_saved_to_the_consent
consent = @patient.consents.last
parent_relationship = @patient.parent_relationships.first

expect(consent).to have_attributes(
parent_full_name: @parent.full_name,
parent_email: @parent.email,
parent_phone: @parent.phone,
parent_phone_receive_updates: @parent.phone_receive_updates,
parent_relationship_type: parent_relationship.type
parent_full_name: @parent_relationship.full_name,
parent_email: @parent_relationship.email,
parent_phone: @parent_relationship.phone,
parent_phone_receive_updates: @parent_relationship.phone_receive_updates,
parent_relationship_type: @parent_relationship.type
)

expect(consent.parent_relationship_other_name.to_s).to eq(
parent_relationship.other_name.to_s
@parent_relationship.other_name.to_s
)
end

def and_i_can_see_the_consent_response_details(number_of_health_questions:)
click_link @patient.full_name, match: :first
click_link @parent.full_name
click_link @parent_relationship.full_name

expect(page).to have_content("Consent response from #{@parent.full_name}")
expect(page).to have_content(
"Consent response from #{@parent_relationship.full_name}"
)
expect(page).to have_content(["Date", Date.current.to_fs(:long)].join)
expect(page).to have_content(["Response", "Consent given"].join)
expect(page).to have_content(["Method", "By phone"].join)
Expand All @@ -303,12 +305,16 @@ def and_i_can_see_the_consent_response_details(number_of_health_questions:)
)
expect(page).to have_content(["School", @patient.school.name].join)

expect(page).to have_content(["Name", @parent.full_name].join)
expect(page).to have_content(["Name", @parent_relationship.full_name].join)
expect(page).to have_content(
["Relationship", @patient.parent_relationships.first.label].join
)
expect(page).to have_content(["Email address", @parent.email].join("\n"))
expect(page).to have_content(["Phone number", @parent.phone].join("\n"))
expect(page).to have_content(
["Email address", @parent_relationship.email].join("\n")
)
expect(page).to have_content(
["Phone number", @parent_relationship.phone].join("\n")
)

expect(page).to have_content("Answers to health questions")
expect(page).to have_content(
Expand All @@ -320,7 +326,7 @@ def and_i_can_see_the_consent_response_details(number_of_health_questions:)
def then_an_email_is_sent_to_the_parent_confirming_their_consent
expect(email_deliveries).to include(
matching_notify_email(
to: @parent.email,
to: @parent_relationship.email,
template: :consent_confirmation_given
).with_content_including("You’ve given consent", "withdraw your consent")
)
Expand All @@ -329,7 +335,7 @@ def then_an_email_is_sent_to_the_parent_confirming_their_consent
def and_a_text_is_sent_to_the_parent_confirming_their_consent
expect(sms_deliveries).to include(
matching_notify_sms(
phone_number: @parent.phone,
phone_number: @parent_relationship.phone,
template: :consent_confirmation_given
).with_content_including(
"You've given consent for Alex",
Expand All @@ -346,7 +352,7 @@ def and_i_can_see_the_log_entries_for_the_email_and_sms
click_on "Back"
click_on "Session activity and notes"
expect(page).to have_content("Consent confirmation given", count: 2)
expect(page).to have_content(@parent.email)
expect(page).to have_content(@parent.phone)
expect(page).to have_content(@parent_relationship.email)
expect(page).to have_content(@parent_relationship.phone)
end
end
Loading
Loading