|
13 | 13 | # response :integer not null
|
14 | 14 | # route :integer not null
|
15 | 15 | # submitted_at :datetime not null
|
| 16 | +# vaccine_method :integer |
16 | 17 | # withdrawn_at :datetime
|
17 | 18 | # created_at :datetime not null
|
18 | 19 | # updated_at :datetime not null
|
@@ -69,6 +70,7 @@ class Consent < ApplicationRecord
|
69 | 70 | { website: 0, phone: 1, paper: 2, in_person: 3, self_consent: 4 },
|
70 | 71 | prefix: "via",
|
71 | 72 | validate: true
|
| 73 | + enum :vaccine_method, { injection: 0, nasal: 1 }, prefix: true |
72 | 74 |
|
73 | 75 | enum :reason_for_refusal,
|
74 | 76 | {
|
@@ -158,42 +160,44 @@ def self.from_consent_form!(consent_form, patient:, current_user:)
|
158 | 160 | parent =
|
159 | 161 | consent_form.find_or_create_parent_with_relationship_to!(patient:)
|
160 | 162 |
|
161 |
| - consent_given = |
162 |
| - consent_form.given_programmes.map do |programme| |
163 |
| - patient.consents.create!( |
164 |
| - consent_form:, |
165 |
| - organisation: consent_form.organisation, |
166 |
| - programme:, |
167 |
| - parent:, |
168 |
| - notes: "", |
169 |
| - response: "given", |
170 |
| - route: "website", |
171 |
| - health_answers: consent_form.health_answers, |
172 |
| - recorded_by: current_user, |
173 |
| - submitted_at: consent_form.recorded_at |
174 |
| - ) |
175 |
| - end |
176 |
| - |
177 |
| - consent_refused = |
178 |
| - consent_form.refused_programmes.map do |programme| |
179 |
| - patient.consents.create!( |
180 |
| - consent_form:, |
181 |
| - organisation: consent_form.organisation, |
182 |
| - programme:, |
183 |
| - parent:, |
184 |
| - reason_for_refusal: consent_form.reason, |
185 |
| - notes: consent_form.reason_notes.presence || "", |
186 |
| - response: "refused", |
187 |
| - route: "website", |
188 |
| - health_answers: consent_form.health_answers, |
189 |
| - recorded_by: current_user, |
190 |
| - submitted_at: consent_form.recorded_at |
191 |
| - ) |
192 |
| - end |
| 163 | + consents = |
| 164 | + consent_form |
| 165 | + .consent_form_programmes |
| 166 | + .includes(:programme) |
| 167 | + .map do |consent_form_programme| |
| 168 | + patient.consents.create!( |
| 169 | + consent_form:, |
| 170 | + health_answers: consent_form.health_answers, |
| 171 | + notes: |
| 172 | + ( |
| 173 | + if consent_form_programme.response_given? |
| 174 | + "" |
| 175 | + else |
| 176 | + consent_form.reason_notes.presence || "" |
| 177 | + end |
| 178 | + ), |
| 179 | + organisation: consent_form.organisation, |
| 180 | + parent:, |
| 181 | + programme: consent_form_programme.programme, |
| 182 | + reason_for_refusal: |
| 183 | + ( |
| 184 | + if consent_form_programme.response_given? |
| 185 | + nil |
| 186 | + else |
| 187 | + consent_form.reason |
| 188 | + end |
| 189 | + ), |
| 190 | + recorded_by: current_user, |
| 191 | + response: consent_form_programme.response, |
| 192 | + route: "website", |
| 193 | + submitted_at: consent_form.recorded_at, |
| 194 | + vaccine_method: consent_form_programme.vaccine_method |
| 195 | + ) |
| 196 | + end |
193 | 197 |
|
194 | 198 | StatusUpdater.call(patient:)
|
195 | 199 |
|
196 |
| - consent_given + consent_refused |
| 200 | + consents |
197 | 201 | end
|
198 | 202 | end
|
199 | 203 |
|
|
0 commit comments