Class: User
Constant Summary
collapse
- ID_CARD_ALLOWED_STATUSES =
%w[V1 V3 V6].freeze
Common::RedisStore::REQ_CLASS_INSTANCE_VARS
Instance Method Summary
collapse
#authorize
create, delete, #destroyed?, exists?, #expire, find, find_or_build, #initialize, #initialize_dup, keys, #persisted?, pop, redis_key, redis_store, redis_ttl, #save, #save!, #ttl, #update, #update!
Instance Method Details
#account_id ⇒ Object
47
48
49
|
# File 'app/models/user.rb', line 47
def account_id
@account_id ||= account&.id
end
|
#account_uuid ⇒ Object
43
44
45
|
# File 'app/models/user.rb', line 43
def account_uuid
@account_uuid ||= account&.uuid
end
|
#active_mhv_ids ⇒ Object
211
212
213
|
# File 'app/models/user.rb', line 211
def active_mhv_ids
mpi_profile&.active_mhv_ids
end
|
#address ⇒ Object
215
216
217
218
219
220
221
222
223
224
225
|
# File 'app/models/user.rb', line 215
def address
address = mpi_profile&.address || {}
{
street: address[:street],
street2: address[:street2],
city: address[:city],
state: address[:state],
country: address[:country],
postal_code: address[:postal_code]
}
end
|
#all_emails ⇒ Object
425
426
427
428
429
430
431
432
433
434
435
436
437
|
# File 'app/models/user.rb', line 425
def all_emails
the_va_profile_email =
begin
va_profile_email
rescue
nil
end
[the_va_profile_email, email]
.reject(&:blank?)
.map(&:downcase)
.uniq
end
|
#bgs_relationships ⇒ Object
#birth_date ⇒ Object
Returns a Date string in iso8601 format, eg. ‘year-month-day’
107
108
109
110
111
|
# File 'app/models/user.rb', line 107
def birth_date
birth_date = identity.birth_date || birth_date_mpi
Formatters::DateFormatter.format_date(birth_date)
end
|
#birth_date_mpi ⇒ Object
231
232
233
|
# File 'app/models/user.rb', line 231
def birth_date_mpi
mpi_profile&.birth_date
end
|
#can_access_id_card? ⇒ Boolean
357
358
359
360
361
362
|
# File 'app/models/user.rb', line 357
def can_access_id_card?
loa3? && edipi.present? &&
ID_CARD_ALLOWED_STATUSES.include?(veteran_status.title38_status)
rescue false
end
|
#can_access_user_profile? ⇒ Boolean
338
339
340
|
# File 'app/models/user.rb', line 338
def can_access_user_profile?
loa[:current].present?
end
|
#can_access_vet360? ⇒ Boolean
439
440
441
442
443
|
# File 'app/models/user.rb', line 439
def can_access_vet360?
loa3? && icn.present? && vet360_id.present?
rescue false
end
|
#can_create_mhv_account? ⇒ Boolean
473
474
475
476
477
|
# File 'app/models/user.rb', line 473
def can_create_mhv_account?
return false unless Flipper.enabled?(:mhv_account_creation_after_login, user_account)
loa3? && va_patient? && !needs_accepted_terms_of_use
end
|
#common_name ⇒ Object
117
118
119
|
# File 'app/models/user.rb', line 117
def common_name
[first_name, middle_name, last_name, suffix].compact.join(' ')
end
|
#create_mhv_account_async ⇒ Object
467
468
469
470
471
|
# File 'app/models/user.rb', line 467
def create_mhv_account_async
return unless can_create_mhv_account?
MHV::AccountCreatorJob.perform_async(user_verification_id)
end
|
#credential_lock ⇒ Object
55
56
57
58
59
|
# File 'app/models/user.rb', line 55
def credential_lock
return @credential_lock unless @credential_lock.nil?
@credential_lock = user_verification&.locked
end
|
#destroy ⇒ Object
destroy both UserIdentity and self
375
376
377
378
|
# File 'app/models/user.rb', line 375
def destroy
identity&.destroy
super
end
|
#edipi ⇒ Object
121
122
123
|
# File 'app/models/user.rb', line 121
def edipi
loa3? && identity.edipi.present? ? identity.edipi : edipi_mpi
end
|
#edipi_mpi ⇒ Object
235
236
237
|
# File 'app/models/user.rb', line 235
def edipi_mpi
mpi_profile&.edipi
end
|
#first_name ⇒ Object
113
114
115
|
# File 'app/models/user.rb', line 113
def first_name
identity.first_name.presence || first_name_mpi
end
|
#first_name_mpi ⇒ Object
239
240
241
|
# File 'app/models/user.rb', line 239
def first_name_mpi
given_names&.first
end
|
#flipper_id ⇒ Object
459
460
461
|
# File 'app/models/user.rb', line 459
def flipper_id
email&.downcase || account_uuid
end
|
#full_name_normalized ⇒ Object
125
126
127
128
129
130
131
132
|
# File 'app/models/user.rb', line 125
def full_name_normalized
{
first: first_name&.capitalize,
middle: middle_name&.capitalize,
last: last_name&.capitalize,
suffix: normalized_suffix
}
end
|
#gender ⇒ Object
138
139
140
|
# File 'app/models/user.rb', line 138
def gender
identity.gender.presence || gender_mpi
end
|
#gender_mpi ⇒ Object
251
252
253
|
# File 'app/models/user.rb', line 251
def gender_mpi
mpi_profile&.gender
end
|
#get_relationships_array ⇒ Object
508
509
510
511
512
|
# File 'app/models/user.rb', line 508
def get_relationships_array
return unless loa3?
mpi_profile_relationships || bgs_relationships
end
|
#get_user_verification ⇒ Object
Get user_verification based on login method Default is idme, if login method and login uuid are not available, fall back to idme
#given_names ⇒ Object
255
256
257
|
# File 'app/models/user.rb', line 255
def given_names
mpi_profile&.given_names
end
|
#home_phone ⇒ Object
259
260
261
|
# File 'app/models/user.rb', line 259
def home_phone
mpi_profile&.home_phone
end
|
#icn ⇒ Object
142
143
144
|
# File 'app/models/user.rb', line 142
def icn
identity&.icn || mpi&.icn
end
|
#identity ⇒ Object
396
397
398
|
# File 'app/models/user.rb', line 396
def identity
@identity ||= UserIdentity.find(uuid)
end
|
#initial_sign_in ⇒ Object
51
52
53
|
# File 'app/models/user.rb', line 51
def initial_sign_in
user_account.created_at
end
|
#invalidate_mpi_cache ⇒ Object
321
322
323
324
325
326
|
# File 'app/models/user.rb', line 321
def invalidate_mpi_cache
return unless loa3? && mpi.mpi_response_is_cached? && mpi.mvi_response
mpi.destroy
@mpi = nil
end
|
#last_name ⇒ Object
175
176
177
|
# File 'app/models/user.rb', line 175
def last_name
identity.last_name.presence || last_name_mpi
end
|
#last_name_mpi ⇒ Object
263
264
265
|
# File 'app/models/user.rb', line 263
def last_name_mpi
mpi_profile&.family_name
end
|
#loa ⇒ Object
146
147
148
|
# File 'app/models/user.rb', line 146
def loa
identity&.loa || {}
end
|
#log_mhv_user_account_error(error_message) ⇒ Object
531
532
533
|
# File 'app/models/user.rb', line 531
def log_mhv_user_account_error(error_message)
Rails.logger.info('[User] mhv_user_account error', error_message:, icn:)
end
|
#mhv_account_state ⇒ Object
267
268
269
270
271
272
273
|
# File 'app/models/user.rb', line 267
def mhv_account_state
return 'DEACTIVATED' if (mhv_ids.to_a - active_mhv_ids.to_a).any?
return 'MULTIPLE' if active_mhv_ids.to_a.size > 1
return 'NONE' if mhv_correlation_id.blank?
'OK'
end
|
#mhv_account_type ⇒ Object
#mhv_correlation_id ⇒ Object
154
155
156
|
# File 'app/models/user.rb', line 154
def mhv_correlation_id
identity.mhv_correlation_id || mpi_mhv_correlation_id
end
|
#mhv_ids ⇒ Object
275
276
277
|
# File 'app/models/user.rb', line 275
def mhv_ids
mpi_profile&.mhv_ids
end
|
#mhv_user_account ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'app/models/user.rb', line 158
def mhv_user_account
@mhv_user_account ||= if va_patient?
MHV::UserAccount::Creator.new(user_verification:).perform
else
log_mhv_user_account_error('User has no va_treatment_facility_ids')
nil
end
rescue MHV::UserAccount::Errors::UserAccountError => e
log_mhv_user_account_error(e.message)
raise
end
|
#middle_name ⇒ Object
171
172
173
|
# File 'app/models/user.rb', line 171
def middle_name
identity.middle_name.presence || middle_name_mpi
end
|
#middle_name_mpi ⇒ Object
247
248
249
|
# File 'app/models/user.rb', line 247
def middle_name_mpi
mpi&.profile&.given_names.to_a[1..]&.join(' ').presence
end
|
#mpi ⇒ Object
487
488
489
|
# File 'app/models/user.rb', line 487
def mpi
@mpi ||= MPIData.for_user(identity)
end
|
#mpi_gcids ⇒ Object
307
308
309
|
# File 'app/models/user.rb', line 307
def mpi_gcids
mpi_profile&.full_mvi_ids || []
end
|
#mpi_profile ⇒ Object
481
482
483
484
485
|
# File 'app/models/user.rb', line 481
def mpi_profile
return nil unless identity && mpi
mpi.profile
end
|
#mpi_profile? ⇒ Boolean
295
296
297
|
# File 'app/models/user.rb', line 295
def mpi_profile?
mpi_profile != nil
end
|
#mpi_profile_relationships ⇒ Object
514
515
516
517
518
|
# File 'app/models/user.rb', line 514
def mpi_profile_relationships
return unless mpi_profile && mpi_profile.relationships.presence
mpi_profile.relationships.map { |relationship| UserRelationship.from_mpi_relationship(relationship) }
end
|
#needs_accepted_terms_of_use ⇒ Object
61
62
63
64
65
|
# File 'app/models/user.rb', line 61
def needs_accepted_terms_of_use
return @needs_accepted_terms_of_use unless @needs_accepted_terms_of_use.nil?
@needs_accepted_terms_of_use = user_account&.needs_accepted_terms_of_use?
end
|
#normalized_suffix ⇒ Object
279
280
281
|
# File 'app/models/user.rb', line 279
def normalized_suffix
mpi_profile&.normalized_suffix
end
|
#pciu ⇒ Object
527
528
529
|
# File 'app/models/user.rb', line 527
def pciu
@pciu ||= EVSS::PCIU::Service.new self if loa3? && edipi.present?
end
|
#pciu_alternate_phone ⇒ Object
91
92
93
|
# File 'app/models/user.rb', line 91
def pciu_alternate_phone
pciu&.get_alternate_phone&.to_s
end
|
#pciu_email ⇒ Object
83
84
85
|
# File 'app/models/user.rb', line 83
def pciu_email
pciu&.get_email_address&.email
end
|
#pciu_primary_phone ⇒ Object
87
88
89
|
# File 'app/models/user.rb', line 87
def pciu_primary_phone
pciu&.get_primary_phone&.to_s
end
|
#postal_code ⇒ Object
283
284
285
|
# File 'app/models/user.rb', line 283
def postal_code
mpi&.profile&.address&.postal_code
end
|
#power_of_attorney ⇒ Object
#preferred_name ⇒ Object
134
135
136
|
# File 'app/models/user.rb', line 134
def preferred_name
preferred_name_mpi
end
|
#preferred_name_mpi ⇒ Object
243
244
245
|
# File 'app/models/user.rb', line 243
def preferred_name_mpi
mpi_profile&.preferred_names&.first
end
|
#recache ⇒ Object
Re-caches the MPI response. Use in response to any local changes that have been made.
370
371
372
|
# File 'app/models/user.rb', line 370
def recache
mpi.cache(uuid, mpi.mvi_response)
end
|
#relationships ⇒ Object
463
464
465
|
# File 'app/models/user.rb', line 463
def relationships
@relationships ||= get_relationships_array
end
|
#sec_id ⇒ Object
179
180
181
|
# File 'app/models/user.rb', line 179
def sec_id
identity&.sec_id || mpi_profile&.sec_id
end
|
#served_in_military? ⇒ Boolean
A user can have served in the military without being a veteran. For example, someone can be ex-military by having a discharge status higher than ‘Other Than Honorable’.
451
452
453
|
# File 'app/models/user.rb', line 451
def served_in_military?
edipi.present? && veteran? || military_person?
end
|
#set_mhv_ids(mhv_id) ⇒ Object
313
314
315
316
317
|
# File 'app/models/user.rb', line 313
def set_mhv_ids(mhv_id)
mpi_profile.mhv_ids = [mhv_id] + mhv_ids
mpi_profile.active_mhv_ids = [mhv_id] + active_mhv_ids
recache
end
|
#ssn ⇒ Object
183
184
185
|
# File 'app/models/user.rb', line 183
def ssn
identity&.ssn || ssn_mpi
end
|
#ssn_mismatch? ⇒ Boolean
332
333
334
335
336
|
# File 'app/models/user.rb', line 332
def ssn_mismatch?
return false unless loa3? && identity&.ssn && ssn_mpi
identity.ssn != ssn_mpi
end
|
#ssn_mpi ⇒ Object
287
288
289
|
# File 'app/models/user.rb', line 287
def ssn_mpi
mpi_profile&.ssn
end
|
#ssn_normalized ⇒ Object
187
188
189
|
# File 'app/models/user.rb', line 187
def ssn_normalized
ssn&.gsub(/[^\d]/, '')
end
|
#suffix ⇒ Object
291
292
293
|
# File 'app/models/user.rb', line 291
def suffix
mpi_profile&.suffix
end
|
#user_account ⇒ Object
71
72
73
|
# File 'app/models/user.rb', line 71
def user_account
@user_account ||= user_verification&.user_account
end
|
#user_account_uuid ⇒ Object
79
80
81
|
# File 'app/models/user.rb', line 79
def user_account_uuid
@user_account_uuid ||= user_account&.id
end
|
#user_verification ⇒ Object
67
68
69
|
# File 'app/models/user.rb', line 67
def user_verification
@user_verification ||= UserVerification.find_by(id: user_verification_id)
end
|
#user_verification_id ⇒ Object
75
76
77
|
# File 'app/models/user.rb', line 75
def user_verification_id
@user_verification_id ||= get_user_verification&.id
end
|
#va_patient? ⇒ Boolean
True if the user has 1 or more treatment facilities, false otherwise
343
344
345
|
# File 'app/models/user.rb', line 343
def va_patient?
va_treatment_facility_ids.any?
end
|
#va_profile_email ⇒ Object
413
414
415
|
# File 'app/models/user.rb', line 413
def va_profile_email
vet360_contact_info&.email&.email_address
end
|
#va_profile_v2_email ⇒ Object
421
422
423
|
# File 'app/models/user.rb', line 421
def va_profile_v2_email
vaprofile_contact_info&.email&.email_address
end
|
#va_treatment_facility_ids ⇒ Object
User’s profile contains a list of VHA facility-specific identifiers. Facilities in the defined range are treating facilities
349
350
351
352
353
354
355
|
# File 'app/models/user.rb', line 349
def va_treatment_facility_ids
facilities = vha_facility_ids
facilities.select do |f|
Settings.mhv.facility_range.any? { |range| f.to_i.between?(*range) } ||
Settings.mhv.facility_specific.include?(f)
end
end
|
#vha_facility_hash ⇒ Object
303
304
305
|
# File 'app/models/user.rb', line 303
def vha_facility_hash
mpi_profile&.vha_facility_hash || {}
end
|
#vha_facility_ids ⇒ Object
299
300
301
|
# File 'app/models/user.rb', line 299
def vha_facility_ids
mpi_profile&.vha_facility_ids || []
end
|