Skip to content

Commit

Permalink
Create ConsentNotification
Browse files Browse the repository at this point in the history
This is a model which will track when consent emails/texts are sent
(either the first consent request, or the subsequent reminders). This is
necessary to support sending multiple reminders, and tracking these
notifications across different teams with the same programme.
  • Loading branch information
thomasleese committed Oct 1, 2024
1 parent 07bce41 commit aeeb0fe
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 0 deletions.
27 changes: 27 additions & 0 deletions app/models/consent_notification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: consent_notifications
#
# id :bigint not null, primary key
# reminder :boolean not null
# sent_at :datetime not null
# patient_id :bigint not null
# programme_id :bigint not null
#
# Indexes
#
# index_consent_notifications_on_patient_id (patient_id)
# index_consent_notifications_on_patient_id_and_programme_id (patient_id,programme_id)
# index_consent_notifications_on_programme_id (programme_id)
#
# Foreign Keys
#
# fk_rails_... (patient_id => patients.id)
# fk_rails_... (programme_id => programmes.id)
#
class ConsentNotification < ApplicationRecord
belongs_to :patient
belongs_to :programme
end
1 change: 1 addition & 0 deletions app/models/patient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Patient < ApplicationRecord
belongs_to :cohort
belongs_to :school, class_name: "Location", optional: true

has_many :consent_notifications
has_many :consents
has_many :parent_relationships
has_many :patient_sessions
Expand Down
1 change: 1 addition & 0 deletions app/models/programme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Programme < ApplicationRecord
has_and_belongs_to_many :sessions

has_many :consent_forms
has_many :consent_notifications
has_many :consents
has_many :dps_exports
has_many :immunisation_imports
Expand Down
16 changes: 16 additions & 0 deletions db/migrate/20240930190813_create_consent_notifications.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

class CreateConsentNotifications < ActiveRecord::Migration[7.2]
def change
# rubocop:disable Rails/CreateTableWithTimestamps
create_table :consent_notifications do |t|
t.references :patient, null: false, foreign_key: true
t.references :programme, null: false, foreign_key: true
t.boolean :reminder, null: false
t.datetime :sent_at, null: false, default: -> { "CURRENT_TIMESTAMP" }

t.index %i[patient_id programme_id]
end
# rubocop:enable Rails/CreateTableWithTimestamps
end
end
12 changes: 12 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@
t.index ["session_id"], name: "index_consent_forms_on_session_id"
end

create_table "consent_notifications", force: :cascade do |t|
t.bigint "patient_id", null: false
t.bigint "programme_id", null: false
t.boolean "reminder", null: false
t.datetime "sent_at", default: -> { "CURRENT_TIMESTAMP" }, null: false
t.index ["patient_id", "programme_id"], name: "index_consent_notifications_on_patient_id_and_programme_id"
t.index ["patient_id"], name: "index_consent_notifications_on_patient_id"
t.index ["programme_id"], name: "index_consent_notifications_on_programme_id"
end

create_table "consents", force: :cascade do |t|
t.bigint "patient_id", null: false
t.bigint "programme_id", null: false
Expand Down Expand Up @@ -618,6 +628,8 @@
add_foreign_key "consent_forms", "locations"
add_foreign_key "consent_forms", "programmes"
add_foreign_key "consent_forms", "sessions"
add_foreign_key "consent_notifications", "patients"
add_foreign_key "consent_notifications", "programmes"
add_foreign_key "consents", "parents"
add_foreign_key "consents", "patients"
add_foreign_key "consents", "programmes"
Expand Down
Binary file modified erd.pdf
Binary file not shown.
39 changes: 39 additions & 0 deletions spec/factories/consent_notifications.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: consent_notifications
#
# id :bigint not null, primary key
# reminder :boolean not null
# sent_at :datetime not null
# patient_id :bigint not null
# programme_id :bigint not null
#
# Indexes
#
# index_consent_notifications_on_patient_id (patient_id)
# index_consent_notifications_on_patient_id_and_programme_id (patient_id,programme_id)
# index_consent_notifications_on_programme_id (programme_id)
#
# Foreign Keys
#
# fk_rails_... (patient_id => patients.id)
# fk_rails_... (programme_id => programmes.id)
#
FactoryBot.define do
factory :consent_notification do
patient
programme

reminder { [true, false].sample }

trait :request do
reminder { false }
end

trait :reminder do
reminder { false }
end
end
end
28 changes: 28 additions & 0 deletions spec/models/consent_notification_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: consent_notifications
#
# id :bigint not null, primary key
# reminder :boolean not null
# sent_at :datetime not null
# patient_id :bigint not null
# programme_id :bigint not null
#
# Indexes
#
# index_consent_notifications_on_patient_id (patient_id)
# index_consent_notifications_on_patient_id_and_programme_id (patient_id,programme_id)
# index_consent_notifications_on_programme_id (programme_id)
#
# Foreign Keys
#
# fk_rails_... (patient_id => patients.id)
# fk_rails_... (programme_id => programmes.id)
#
describe ConsentNotification do
subject(:consent_notification) { build(:consent_notification) }

it { should be_valid }
end

0 comments on commit aeeb0fe

Please sign in to comment.