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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ gem "stackprof"
gem "activerecord-import"
gem "activerecord-session_store"
gem "amazing_print"
gem "array_enum"
gem "audited", git: "https://github.com/tvararu/audited", branch: "encryption"
gem "caxlsx"
gem "charlock_holmes"
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ GEM
aes_key_wrap (1.1.0)
amazing_print (1.7.2)
annotaterb (4.14.0)
array_enum (1.6.0)
activemodel
asciidoctor (2.0.23)
asciidoctor-diagram (3.0.0)
asciidoctor (>= 1.5.7, < 3.x)
Expand Down Expand Up @@ -713,6 +715,7 @@ DEPENDENCIES
activerecord-session_store
amazing_print
annotaterb
array_enum
asciidoctor
asciidoctor-diagram
audited!
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/patient_sessions/consents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def create_params
{
patient_session: @patient_session,
programme: @programme,
recorded_by: current_user
recorded_by: current_user,
vaccine_methods: %w[injection]
}
end

Expand Down
13 changes: 13 additions & 0 deletions app/models/concerns/has_vaccine_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module HasVaccineMethods
extend ActiveSupport::Concern

included do
extend ArrayEnum

array_enum vaccine_methods: { injection: 0, nasal: 1 }

validates :vaccine_methods, subset: %w[injection nasal]
end
end
71 changes: 38 additions & 33 deletions app/models/consent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# response :integer not null
# route :integer not null
# submitted_at :datetime not null
# vaccine_methods :integer default([]), not null, is an Array
# withdrawn_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
Expand Down Expand Up @@ -42,6 +43,7 @@
class Consent < ApplicationRecord
include Invalidatable
include HasHealthAnswers
include HasVaccineMethods

audited associated_with: :patient

Expand Down Expand Up @@ -99,6 +101,8 @@ class Consent < ApplicationRecord
presence: true,
unless: -> { via_self_consent? || via_website? }

validates :vaccine_methods, presence: true, if: :response_given?

def self.verbal_routes = routes.except("website", "self_consent")

def name
Expand Down Expand Up @@ -158,42 +162,43 @@ def self.from_consent_form!(consent_form, patient:, current_user:)
parent =
consent_form.find_or_create_parent_with_relationship_to!(patient:)

consent_given =
consent_form.given_programmes.map do |programme|
patient.consents.create!(
consent_form:,
organisation: consent_form.organisation,
programme:,
parent:,
notes: "",
response: "given",
route: "website",
health_answers: consent_form.health_answers,
recorded_by: current_user,
submitted_at: consent_form.recorded_at
)
end

consent_refused =
consent_form.refused_programmes.map do |programme|
patient.consents.create!(
consent_form:,
organisation: consent_form.organisation,
programme:,
parent:,
reason_for_refusal: consent_form.reason,
notes: consent_form.reason_notes.presence || "",
response: "refused",
route: "website",
health_answers: consent_form.health_answers,
recorded_by: current_user,
submitted_at: consent_form.recorded_at
)
end
consents =
consent_form
.consent_form_programmes
.includes(:programme)
.map do |consent_form_programme|
notes =
if consent_form_programme.response_given?
""
else
consent_form.reason_notes.presence || ""
end
reason_for_refusal =
if consent_form_programme.response_given?
nil
else
consent_form.reason
end

patient.consents.create!(
consent_form:,
health_answers: consent_form.health_answers,
notes:,
organisation: consent_form.organisation,
parent:,
programme: consent_form_programme.programme,
reason_for_refusal:,
recorded_by: current_user,
response: consent_form_programme.response,
route: "website",
submitted_at: consent_form.recorded_at,
vaccine_methods: consent_form_programme.vaccine_methods
)
end

StatusUpdater.call(patient:)

consent_given + consent_refused
consents
end
end

Expand Down
6 changes: 5 additions & 1 deletion app/models/consent_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ def home_educated_changed?
def update_programme_responses
case response
when "given"
consent_form_programmes.each { it.response = "given" }
consent_form_programmes.each do
it.response = "given"
it.vaccine_methods = %w[injection]
end
when "given_one"
consent_form_programmes.each do |consent_form_programme|
consent_form_programme.response =
Expand All @@ -463,6 +466,7 @@ def update_programme_responses
else
"refused"
end
consent_form_programme.vaccine_methods = %w[injection]
end
when "refused"
consent_form_programmes.each { it.response = "refused" }
Expand Down
3 changes: 3 additions & 0 deletions app/models/consent_form_programme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#
# id :bigint not null, primary key
# response :integer
# vaccine_methods :integer default([]), not null, is an Array
# consent_form_id :bigint not null
# programme_id :bigint not null
#
Expand All @@ -20,6 +21,8 @@
# fk_rails_... (programme_id => programmes.id)
#
class ConsentFormProgramme < ApplicationRecord
include HasVaccineMethods

belongs_to :consent_form
belongs_to :programme

Expand Down
2 changes: 2 additions & 0 deletions app/models/draft_consent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def self.request_session_key
attribute :route, :string
attribute :triage_notes, :string
attribute :triage_status, :string
attribute :vaccine_methods, array: true, default: []

def wizard_steps
[
Expand Down Expand Up @@ -333,6 +334,7 @@ def writable_attribute_names
response
route
organisation_id
vaccine_methods
]
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

class AddVaccineMethodsToConsentAndConsentForms < ActiveRecord::Migration[8.0]
def change
add_column :consent_form_programmes,
:vaccine_methods,
:integer,
null: false,
array: true,
default: []

add_column :consents,
:vaccine_methods,
:integer,
null: false,
array: true,
default: []

# We don't support getting consent for nasal spray yet.
reversible do |dir|
dir.up do
ConsentFormProgramme.response_given.update_all(
vaccine_methods: %w[injection]
)
Consent.response_given.update_all(vaccine_methods: %w[injection])
end
end
end
end
2 changes: 2 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
t.bigint "programme_id", null: false
t.bigint "consent_form_id", null: false
t.integer "response"
t.integer "vaccine_methods", default: [], null: false, array: true
t.index ["consent_form_id"], name: "index_consent_form_programmes_on_consent_form_id"
t.index ["programme_id", "consent_form_id"], name: "idx_on_programme_id_consent_form_id_2113cb7f37", unique: true
end
Expand Down Expand Up @@ -236,6 +237,7 @@
t.datetime "invalidated_at"
t.boolean "notify_parents"
t.datetime "submitted_at", null: false
t.integer "vaccine_methods", default: [], null: false, array: true
t.index ["organisation_id"], name: "index_consents_on_organisation_id"
t.index ["parent_id"], name: "index_consents_on_parent_id"
t.index ["patient_id"], name: "index_consents_on_patient_id"
Expand Down
11 changes: 10 additions & 1 deletion spec/factories/consent_form_programmes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#
# id :bigint not null, primary key
# response :integer
# vaccine_methods :integer default([]), not null, is an Array
# consent_form_id :bigint not null
# programme_id :bigint not null
#
Expand All @@ -24,6 +25,14 @@
consent_form
programme

traits_for_enum :response
trait :given do
response { "given" }
vaccine_methods { %w[injection] }
end

trait :refused do
response { "refused" }
vaccine_methods { [] }
end
end
end
5 changes: 4 additions & 1 deletion spec/factories/consent_forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@
end

after(:create) do |consent_form, evaluator|
vaccine_methods = evaluator.response == "given" ? %w[injection] : []

consent_form.consent_form_programmes.update_all(
response: evaluator.response
response: evaluator.response,
vaccine_methods:
)
end

Expand Down
14 changes: 10 additions & 4 deletions spec/factories/consents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# response :integer not null
# route :integer not null
# submitted_at :datetime not null
# vaccine_methods :integer default([]), not null, is an Array
# withdrawn_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
Expand Down Expand Up @@ -64,6 +65,7 @@
end

response { "given" }
vaccine_methods { %w[injection] }
route { "website" }

health_answers do
Expand All @@ -74,8 +76,6 @@

submitted_at { consent_form&.recorded_at || Time.current }

traits_for_enum :response

trait :given_verbally do
given
route { "phone" }
Expand All @@ -93,10 +93,16 @@
end

trait :refused do
response { :refused }
reason_for_refusal { :personal_choice }
response { "refused" }
reason_for_refusal { "personal_choice" }
health_answers { [] }
notes { "Refused." }
vaccine_methods { [] }
end

trait :not_provided do
response { "not_provided" }
vaccine_methods { [] }
end

trait :from_mum do
Expand Down
Loading