@@ -13,6 +13,8 @@ class VaccinateForm
13
13
attribute :pre_screening_confirmed , :boolean
14
14
attribute :pre_screening_notes , :string
15
15
16
+ attribute :supplied_by_user_id , :integer
17
+
16
18
attribute :vaccine_method , :string
17
19
attribute :delivery_site , :string
18
20
attribute :dose_sequence , :integer
@@ -31,10 +33,16 @@ class VaccinateForm
31
33
maximum : 300
32
34
}
33
35
34
- validates :vaccine_method , inclusion : { in : :vaccine_method_options }
35
36
validates :pre_screening_notes , length : { maximum : 1000 }
36
-
37
37
validates :pre_screening_confirmed , presence : true , if : :administered?
38
+
39
+ validates :supplied_by_user_id ,
40
+ inclusion : {
41
+ in : :supplied_by_user_id_values
42
+ } ,
43
+ if : :requires_supplied_by_user_id?
44
+
45
+ validates :vaccine_method , inclusion : { in : :vaccine_method_options }
38
46
validates :delivery_site ,
39
47
inclusion : {
40
48
in : :delivery_site_options
@@ -59,6 +67,10 @@ def delivery_site
59
67
super
60
68
end
61
69
70
+ def supplied_by_users = current_user . selected_team . users . show_in_suppliers
71
+
72
+ def requires_supplied_by_user_id? = !current_user . show_in_suppliers
73
+
62
74
def save ( draft_vaccination_record :)
63
75
return nil if invalid?
64
76
@@ -93,6 +105,7 @@ def save(draft_vaccination_record:)
93
105
draft_vaccination_record . patient_id = patient_session . patient_id
94
106
draft_vaccination_record . performed_at = Time . current
95
107
draft_vaccination_record . performed_by_user = current_user
108
+ draft_vaccination_record . supplied_by_user_id = supplied_by_user_id
96
109
draft_vaccination_record . performed_ods_code = organisation . ods_code
97
110
draft_vaccination_record . programme = programme
98
111
draft_vaccination_record . session_id = patient_session . session_id
@@ -106,6 +119,8 @@ def save(draft_vaccination_record:)
106
119
107
120
def administered? = vaccine_method != "none"
108
121
122
+ def supplied_by_user_id_values = supplied_by_users . pluck ( :id )
123
+
109
124
def vaccine_method_options
110
125
programme . vaccine_methods + [ "none" ]
111
126
end
0 commit comments