@@ -79,6 +79,19 @@ class ConsentForm < ApplicationRecord
79
79
prefix : "refused_because"
80
80
enum :gp_response , %w[ yes no dont_know ] , prefix : true
81
81
82
+ enum :parent_contact_method_type ,
83
+ Parent . contact_method_types ,
84
+ prefix : :parent_contact_method ,
85
+ validate : {
86
+ allow_nil : true
87
+ }
88
+ enum :parent_relationship_type ,
89
+ ParentRelationship . types ,
90
+ prefix : :parent_relationship ,
91
+ validate : {
92
+ allow_nil : true
93
+ }
94
+
82
95
serialize :health_answers , coder : HealthAnswer ::ArraySerializer
83
96
84
97
encrypts :address_line_1 ,
@@ -90,6 +103,11 @@ class ConsentForm < ApplicationRecord
90
103
:gp_name ,
91
104
:health_answers ,
92
105
:last_name ,
106
+ :parent_contact_method_other_details ,
107
+ :parent_email ,
108
+ :parent_name ,
109
+ :parent_phone ,
110
+ :parent_relationship_other_name ,
93
111
:reason_notes
94
112
95
113
validates :address_line_1 ,
@@ -99,10 +117,23 @@ class ConsentForm < ApplicationRecord
99
117
:first_name ,
100
118
:gp_name ,
101
119
:last_name ,
120
+ :parent_contact_method_other_details ,
121
+ :parent_name ,
122
+ :parent_relationship_other_name ,
102
123
length : {
103
124
maximum : 300
104
125
}
105
126
127
+ validates :parent_contact_method_other_details ,
128
+ presence : true ,
129
+ if : :parent_contact_method_other?
130
+
131
+ validates :parent_phone , phone : { allow_blank : true }
132
+
133
+ validates :parent_relationship_other_name ,
134
+ presence : true ,
135
+ if : :parent_relationship_other?
136
+
106
137
validates :reason_notes , length : { maximum : 1000 }
107
138
108
139
on_wizard_step :name do
@@ -126,6 +157,24 @@ class ConsentForm < ApplicationRecord
126
157
validates :is_this_their_school , inclusion : { in : %w[ yes no ] }
127
158
end
128
159
160
+ on_wizard_step :parent do
161
+ validates :parent_name , presence : true
162
+ validates :parent_email , notify_safe_email : true
163
+ validates :parent_relationship_type , presence : true
164
+ end
165
+
166
+ validates :parental_responsibility ,
167
+ inclusion : {
168
+ in : [ "yes" ]
169
+ } ,
170
+ if : -> ( object ) do
171
+ object . parent_relationship_other? && object . wizard_step == :parent
172
+ end
173
+
174
+ on_wizard_step :contact_method do
175
+ validates :parent_contact_method_type , presence : true
176
+ end
177
+
129
178
on_wizard_step :consent do
130
179
validates :response , presence : true
131
180
end
@@ -209,10 +258,6 @@ def any_health_answers_truthy?
209
258
health_answers . any? { _1 . response == "yes" }
210
259
end
211
260
212
- def who_responded
213
- parent &.relationship_label
214
- end
215
-
216
261
def gelatine_content_status_in_vaccines
217
262
# we don't YET track the vaccine type that the user is agreeing to in the consent form,
218
263
# so we have to check all vaccines
@@ -278,6 +323,20 @@ def summary_with_route
278
323
"#{ human_enum_name ( :response ) . capitalize } (online)"
279
324
end
280
325
326
+ def parent_contact_method_description
327
+ Parent . new (
328
+ contact_method_type : parent_contact_method_type ,
329
+ contact_method_other_details : parent_contact_method_other_details
330
+ ) . contact_method_description
331
+ end
332
+
333
+ def parent_relationship_label
334
+ ParentRelationship . new (
335
+ type : parent_relationship_type ,
336
+ other_name : parent_relationship_other_name
337
+ ) . label
338
+ end
339
+
281
340
private
282
341
283
342
def refused_and_not_had_it_already?
@@ -320,7 +379,7 @@ def health_answers_valid?
320
379
end
321
380
322
381
def ask_for_contact_method?
323
- Flipper . enabled? ( :parent_contact_method ) && draft_parent &. phone . present?
382
+ Flipper . enabled? ( :parent_contact_method ) && parent_phone . present?
324
383
end
325
384
326
385
# Because there are branching paths in the consent form journey, fields
@@ -340,6 +399,12 @@ def reset_unused_fields
340
399
self . health_answers = [ ]
341
400
end
342
401
402
+ self . parent_contact_method_type = nil if parent_phone . blank?
403
+ self . parent_contact_method_other_details =
404
+ nil unless parent_contact_method_other?
405
+
406
+ self . parent_relationship_other_name = nil unless parent_relationship_other?
407
+
343
408
if consent_given?
344
409
self . contact_injection = nil
345
410
0 commit comments