@@ -53,6 +53,7 @@ class Consent < ApplicationRecord
5353 include HasVaccineMethods
5454 include Invalidatable
5555 include Notable
56+ include Refusable
5657
5758 audited associated_with : :patient
5859
@@ -83,20 +84,6 @@ class Consent < ApplicationRecord
8384 prefix : "via" ,
8485 validate : true
8586
86- enum :reason_for_refusal ,
87- {
88- contains_gelatine : 0 ,
89- already_vaccinated : 1 ,
90- will_be_vaccinated_elsewhere : 2 ,
91- medical_reasons : 3 ,
92- personal_choice : 4 ,
93- other : 5
94- } ,
95- prefix : true ,
96- validate : {
97- if : -> { response_refused? || withdrawn? }
98- }
99-
10087 validates :parent , presence : true , unless : :via_self_consent?
10188 validates :recorded_by ,
10289 presence : true ,
@@ -132,6 +119,10 @@ def responded_at
132119 invalidated_at || withdrawn_at || submitted_at
133120 end
134121
122+ def requires_reason_for_refusal? = super || withdrawn?
123+
124+ def requires_notes? = super || invalidated?
125+
135126 def requires_triage?
136127 response_given? && health_answers_require_triage?
137128 end
@@ -156,27 +147,14 @@ def self.from_consent_form!(consent_form, patient:, current_user:)
156147 . consent_form_programmes
157148 . includes ( :programme )
158149 . map do |consent_form_programme |
159- notes =
160- if consent_form_programme . response_given?
161- ""
162- else
163- consent_form . reason_notes . presence || ""
164- end
165- reason_for_refusal =
166- if consent_form_programme . response_given?
167- nil
168- else
169- consent_form . reason
170- end
171-
172150 patient . consents . create! (
173151 consent_form :,
174152 health_answers : consent_form . health_answers ,
175- notes :,
153+ notes : consent_form_programme . notes ,
176154 team : consent_form . team ,
177155 parent :,
178156 programme : consent_form_programme . programme ,
179- reason_for_refusal :,
157+ reason_for_refusal : consent_form_programme . reason_for_refusal ,
180158 recorded_by : current_user ,
181159 response : consent_form_programme . response ,
182160 route : "website" ,
@@ -192,21 +170,6 @@ def self.from_consent_form!(consent_form, patient:, current_user:)
192170 end
193171 end
194172
195- REASON_FOR_REFUSAL_REQUIRES_NOTES = %w[
196- other
197- will_be_vaccinated_elsewhere
198- medical_reasons
199- already_vaccinated
200- ] . freeze
201-
202- def requires_notes?
203- withdrawn? || invalidated? ||
204- (
205- response_refused? &&
206- reason_for_refusal . in? ( REASON_FOR_REFUSAL_REQUIRES_NOTES )
207- )
208- end
209-
210173 def update_vaccination_records_no_notify!
211174 vaccination_records = VaccinationRecord . where ( patient :, programme :)
212175
0 commit comments