Class: Participant
Overview
A person enrolled in the intervention.
Constant Summary
ThinkFeelDoEngine::Concerns::ValidatePassword::WEAK_PASSWORD_MESSAGE
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.active ⇒ Object
70
71
72
|
# File 'app/models/participant.rb', line 70
def self.active
joins(:memberships).merge(Membership.active)
end
|
.inactive ⇒ Object
74
75
76
|
# File 'app/models/participant.rb', line 74
def self.inactive
joins(:memberships).merge(Membership.inactive)
end
|
Instance Method Details
#active_group_is_social? ⇒ Boolean
104
105
106
|
# File 'app/models/participant.rb', line 104
def active_group_is_social?
active_group && active_group.arm.social?
end
|
#build_data_record(association, attributes) ⇒ Object
156
157
158
|
# File 'app/models/participant.rb', line 156
def build_data_record(association, attributes)
send(association).build(attributes)
end
|
#build_phq_assessment(attributes) ⇒ Object
160
161
162
|
# File 'app/models/participant.rb', line 160
def build_phq_assessment(attributes)
phq_assessments.build(attributes)
end
|
247
248
249
|
# File 'app/models/participant.rb', line 247
def contact_status_enum
%w(sms email)
end
|
#count_all_incomplete(tool) ⇒ Object
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'app/models/participant.rb', line 176
def count_all_incomplete(tool)
@count_all_incomplete ||= {}
@count_all_incomplete[tool.id] ||= (
if tool.is_a?(Tools::Messages)
count_unread_messages
else
content_module_ids = tool.content_modules.where(is_viz: false)
if content_module_ids
active_membership.incomplete_tasks
.for_content_module_ids(content_module_ids)
.count
else
false
end
end
)
end
|
#count_unread_messages ⇒ Object
172
173
174
|
# File 'app/models/participant.rb', line 172
def count_unread_messages
received_messages.where(is_read: false).count
end
|
#current_group ⇒ Object
164
165
166
|
# File 'app/models/participant.rb', line 164
def current_group
active_membership.try(:group)
end
|
#duration_of_last_session ⇒ Object
108
109
110
111
112
|
# File 'app/models/participant.rb', line 108
def duration_of_last_session
if latest_action_at && current_sign_in_at
latest_action_at - current_sign_in_at
end
end
|
#fetch_data_record(association, id) ⇒ Object
168
169
170
|
# File 'app/models/participant.rb', line 168
def fetch_data_record(association, id)
send(association).find(id)
end
|
#flag_inactivity ⇒ Object
227
228
229
230
231
232
|
# File 'app/models/participant.rb', line 227
def flag_inactivity
participant_login_events
.order(:created_at)
.last
.try(:update_attribute, :inactive_log_out, true)
end
|
#in_study? ⇒ Boolean
277
278
279
280
281
282
283
284
|
# File 'app/models/participant.rb', line 277
def in_study?
if active_membership.start_date <= Time.zone.today &&
active_membership.end_date >= Time.zone.today
true
else
false
end
end
|
#latest_action_at ⇒ Object
114
115
116
117
118
119
|
# File 'app/models/participant.rb', line 114
def latest_action_at
events
.order(recorded_at: :desc)
.first
.try(:recorded_at)
end
|
#learning_tasks(content_modules) ⇒ Object
196
197
198
199
|
# File 'app/models/participant.rb', line 196
def learning_tasks(content_modules)
active_membership.task_statuses
.for_content_module_ids(content_modules.map(&:id))
end
|
#most_recent_membership ⇒ Object
273
274
275
|
# File 'app/models/participant.rb', line 273
def most_recent_membership
memberships.order(end_date: :desc).first
end
|
#most_recent_unfinished_awake_period ⇒ Object
152
153
154
|
# File 'app/models/participant.rb', line 152
def most_recent_unfinished_awake_period
unfinished_awake_periods.order("awake_periods.start_time DESC").first
end
|
#navigation_status ⇒ Object
211
212
213
|
# File 'app/models/participant.rb', line 211
def navigation_status
participant_status || build_participant_status
end
|
#negative_emotions(emotion_array) ⇒ Object
265
266
267
268
269
270
271
|
# File 'app/models/participant.rb', line 265
def negative_emotions(emotion_array)
emotion_array.collect do |emotion|
unless emotion.is_positive
[emotion.rating, emotion.created_at, emotion.name]
end
end.compact
end
|
#not_allowed_in_site? ⇒ Boolean
98
99
100
101
102
|
# File 'app/models/participant.rb', line 98
def not_allowed_in_site?
active_membership.nil? && !memberships.where(is_complete: true).exists?
end
|
#notify_by_email? ⇒ Boolean
251
252
253
|
# File 'app/models/participant.rb', line 251
def notify_by_email?
"email" == contact_preference
end
|
#notify_by_sms? ⇒ Boolean
255
256
257
|
# File 'app/models/participant.rb', line 255
def notify_by_sms?
"sms" == contact_preference || "phone" == contact_preference
end
|
#populate_emotions ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'app/models/participant.rb', line 121
def populate_emotions
emotions_array = %w(
Anxious
Enthusiastic
Grateful
Happy
Irritable
Upset
Sad
Guilty
Calm
Concentrated
Relaxed
)
emotions_array.each do |e|
emotions.find_or_create_by(name: e)
end
emotions
end
|
#positive_emotions(emotion_array) ⇒ Object
259
260
261
262
263
|
# File 'app/models/participant.rb', line 259
def positive_emotions(emotion_array)
emotion_array.collect do |emotion|
[emotion.rating, emotion.created_at, emotion.name] if emotion.is_positive
end.compact
end
|
#recent_accomplished_activities ⇒ Object
215
216
217
|
# File 'app/models/participant.rb', line 215
def recent_accomplished_activities
recent_activities.accomplished
end
|
#recent_activities ⇒ Object
219
220
221
|
# File 'app/models/participant.rb', line 219
def recent_activities
activities.during(recent_period[:start_time], recent_period[:end_time])
end
|
#recent_pleasurable_activities ⇒ Object
223
224
225
|
# File 'app/models/participant.rb', line 223
def recent_pleasurable_activities
recent_activities.pleasurable
end
|
#stepping_suggestion ⇒ Object
201
202
203
204
205
206
207
208
209
|
# File 'app/models/participant.rb', line 201
def stepping_suggestion
data = phq_assessments.map do |x|
[x.release_date, x] if x.number_answered > 0
end
assessment_data = Hash[data]
PhqStepping.new(assessment_data,
active_membership.start_date)
end
|
#timedout?(last_access) ⇒ Boolean
Checks whether the user session has expired based on configured time. Overridden devise method.
236
237
238
239
240
241
|
# File 'app/models/participant.rb', line 236
def timedout?(last_access)
timedout = super
flag_inactivity if timedout
timedout
end
|
#unfinished_awake_periods ⇒ Object
142
143
144
145
146
147
148
149
150
|
# File 'app/models/participant.rb', line 142
def unfinished_awake_periods
join_sql = <<-SQL
LEFT JOIN activities
ON activities.participant_id = awake_periods.participant_id
AND activities.start_time = awake_periods.start_time
SQL
awake_periods.joins(join_sql).where("activities.start_time IS NULL")
end
|
#unplanned_activities ⇒ Object
243
244
245
|
# File 'app/models/participant.rb', line 243
def unplanned_activities
UnplannedActivities.new(self)
end
|