Skip to content

Commit 3cdca9e

Browse files
committed
Remove draft parents
We no longer need the concept of draft parents as we record consent in the browser session and only commit to the database after the confirm step. This helps to clean up the data in our database and avoid draft records accidentally being exposed or simply existing with no purpose.
1 parent ff12ec7 commit 3cdca9e

22 files changed

+35
-53
lines changed

app/models/consent.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,7 @@ class Consent < ApplicationRecord
5050
belongs_to :organisation
5151

5252
has_one :consent_form
53-
belongs_to :parent, -> { recorded }, optional: true
54-
belongs_to :draft_parent,
55-
-> { draft },
56-
class_name: "Parent",
57-
optional: true,
58-
foreign_key: :parent_id
53+
belongs_to :parent, optional: true
5954
belongs_to :recorded_by,
6055
class_name: "User",
6156
optional: true,
@@ -133,7 +128,7 @@ def triage_needed?
133128
end
134129

135130
def parent_relationship
136-
(parent || draft_parent)&.relationship_to(patient:)
131+
parent&.relationship_to(patient:)
137132
end
138133

139134
def who_responded
@@ -181,8 +176,6 @@ def notes_required?
181176
private
182177

183178
def parent_present_unless_self_consent
184-
if draft? && !via_self_consent? && draft_parent.nil? && parent.nil?
185-
errors.add(:draft_parent, :blank)
186-
end
179+
errors.add(:parent, :blank) if parent.nil? && !via_self_consent?
187180
end
188181
end

app/models/consent_form.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,6 @@ def find_or_create_parent_with_relationship_to!(patient:)
370370
full_name: parent_full_name
371371
) || Parent.new
372372

373-
parent.recorded_at = Time.current unless parent.recorded?
374-
375373
parent.update!(
376374
email: parent_email,
377375
full_name: parent_full_name,

app/models/draft_consent.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ def parent
159159
parent.full_name = parent_full_name
160160
parent.phone = parent_phone
161161
parent.phone_receive_updates = parent_phone_receive_updates
162-
parent.recorded_at = Time.current
163162

164163
parent
165164
.parent_relationships

app/models/parent.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# full_name :string
1212
# phone :string
1313
# phone_receive_updates :boolean default(FALSE), not null
14-
# recorded_at :datetime
1514
# created_at :datetime not null
1615
# updated_at :datetime not null
1716
#
@@ -20,8 +19,6 @@
2019
# index_parents_on_email (email)
2120
#
2221
class Parent < ApplicationRecord
23-
include Recordable
24-
2522
audited
2623

2724
before_save :reset_unused_fields

app/models/patient_import_row.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ def to_parents
111111
full_name:
112112
) || Parent.new
113113

114-
parent.recorded_at = Time.current unless parent.recorded?
115-
116114
parent.email = attributes[:email] if attributes[:email]
117115
parent.full_name = attributes[:full_name] if attributes[:full_name]
118116
parent.phone = attributes[:phone] if attributes[:phone]

app/views/draft_consents/parent_details.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
) %>
66
<% end %>
77

8-
<% page_title = if @parent.recorded?
8+
<% page_title = if @parent.persisted?
99
"Details for #{@parent.label_to(patient: @patient)}"
1010
else
1111
"Details for parent or guardian"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
class RemoveRecordedAtFromParents < ActiveRecord::Migration[7.2]
4+
def change
5+
reversible do |dir|
6+
dir.up do
7+
Parent
8+
.where(recorded_at: nil)
9+
.find_each do |parent|
10+
parent.parent_relationships.destroy_all
11+
parent.destroy!
12+
end
13+
end
14+
end
15+
16+
remove_column :parents, :recorded_at, :datetime
17+
end
18+
end

db/schema.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.2].define(version: 2024_11_18_094122) do
13+
ActiveRecord::Schema[7.2].define(version: 2024_11_18_111318) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pg_trgm"
1616
enable_extension "plpgsql"
@@ -519,7 +519,6 @@
519519
t.text "contact_method_other_details"
520520
t.datetime "created_at", null: false
521521
t.datetime "updated_at", null: false
522-
t.datetime "recorded_at"
523522
t.string "contact_method_type"
524523
t.boolean "phone_receive_updates", default: false, null: false
525524
t.index ["email"], name: "index_parents_on_email"

erd.pdf

-223 Bytes
Binary file not shown.

spec/components/app_activity_log_component_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
create(:patient, school: location, given_name: "Sarah", family_name: "Doe")
2525
end
2626

27-
let(:mum) { create(:parent, :recorded, full_name: "Jane Doe") }
28-
let(:dad) { create(:parent, :recorded, full_name: "John Doe") }
27+
let(:mum) { create(:parent, full_name: "Jane Doe") }
28+
let(:dad) { create(:parent, full_name: "John Doe") }
2929

3030
before do
3131
create(:parent_relationship, :mother, parent: mum, patient:)

0 commit comments

Comments
 (0)