Skip to content

Commit 46c2fa5

Browse files
committed
Save parent relationship when editing consent
When going through the consent journey, if we're changing the details of an existing parent, we should make sure that the parent relationship is also saved. This follows on from #3253 which mostly implemented this behaviour except for the parent relationships. Jira-Issue: MAV-790
1 parent e639e7a commit 46c2fa5

4 files changed

Lines changed: 30 additions & 12 deletions

File tree

app/controllers/draft_consents_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ def handle_confirm
5757
ActiveRecord::Base.transaction do
5858
@triage&.save! if @draft_consent.response_given?
5959

60-
@consent.parent&.save!
60+
if (parent = @consent.parent)
61+
parent.save! if parent.changed?
62+
parent.parent_relationships.select(&:changed?).each(&:save!)
63+
end
64+
6165
@consent.save!
6266

6367
StatusUpdater.call(patient: @patient)

app/models/consent.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def triage_needed?
132132
end
133133

134134
def parent_relationship
135-
patient.parent_relationships.find { _1.parent_id == parent_id }
135+
patient.parent_relationships.find { it.parent_id == parent_id }
136136
end
137137

138138
def health_answers_require_follow_up?

app/models/draft_consent.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,12 @@ def consent_form
297297
def parent_relationship
298298
parent
299299
&.parent_relationships
300-
&.find { _1.patient_id == patient_id }
301-
.tap { _1&.patient = patient } # acts as preload
300+
&.find { it.patient_id == patient_id }
301+
&.tap do
302+
it.patient = patient # acts as preload
303+
it.type = parent_relationship_type
304+
it.other_name = parent_relationship_other_name
305+
end
302306
end
303307

304308
private

spec/features/verbal_consent_change_answers_spec.rb

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66

77
when_i_get_consent_for_the_patient
88
and_i_choose_the_parent
9-
and_i_fill_out_the_consent_details(parent_name: @parent.full_name)
9+
and_i_fill_out_the_consent_details(
10+
parent_name: @parent.full_name,
11+
relationship: "Mum"
12+
)
1013
then_i_see_the_confirmation_page
1114

1215
when_i_click_on_change_name
13-
and_i_fill_out_the_consent_details(parent_name: "New parent name")
16+
and_i_fill_out_the_consent_details(
17+
parent_name: "New parent name",
18+
relationship: "Dad"
19+
)
1420
then_i_see_the_confirmation_page
1521
end
1622

@@ -23,7 +29,10 @@ def given_a_patient_is_in_an_hpv_programme
2329
@session = create(:session, organisation:, programmes:)
2430

2531
@parent = create(:parent)
26-
@patient = create(:patient, session: @session, parents: [@parent])
32+
@patient = create(:patient, session: @session)
33+
34+
@parent_relationship =
35+
create(:parent_relationship, :mother, patient: @patient, parent: @parent)
2736
end
2837

2938
def when_i_get_consent_for_the_patient
@@ -39,16 +48,15 @@ def and_i_choose_the_parent
3948
"Choose who you are trying to get consent from"
4049
)
4150

42-
choose "#{@parent.full_name} (#{@patient.parent_relationships.first.label})"
51+
choose "#{@parent.full_name} (Mum)"
4352
click_button "Continue"
4453
end
4554

46-
def and_i_fill_out_the_consent_details(parent_name:)
47-
expect(page).to have_content(
48-
"Details for #{parent_name} (#{@patient.parent_relationships.first.label})"
49-
)
55+
def and_i_fill_out_the_consent_details(parent_name:, relationship:)
56+
expect(page).to have_content("Details for #{parent_name} (#{relationship})")
5057

5158
fill_in "Full name", with: "New parent name"
59+
choose "Dad"
5260
click_button "Continue"
5361

5462
choose "By phone"
@@ -69,6 +77,8 @@ def and_i_fill_out_the_consent_details(parent_name:)
6977

7078
def then_i_see_the_confirmation_page
7179
expect(page).to have_content("Check and confirm answers")
80+
expect(page).to have_content("New parent name")
81+
expect(page).to have_content("Dad")
7282
end
7383

7484
def when_i_click_on_change_name

0 commit comments

Comments
 (0)