Class: SavedClaim::VeteranReadinessEmploymentClaim

Inherits:
SavedClaim show all
Includes:
SentryLogging
Defined in:
app/models/saved_claim/veteran_readiness_employment_claim.rb

Constant Summary collapse

FORM =
'28-1900'
PERMITTED_OFFICE_LOCATIONS =

We will be adding numbers here and eventually completeley removing this and the caller to open up VRE submissions to all vets

%w[].freeze
REGIONAL_OFFICE_EMAILS =
{
  '301' => '[email protected]',
  '304' => '[email protected]',
  '306' => '[email protected]',
  '307' => '[email protected]',
  '308' => '[email protected]',
  '309' => '[email protected]',
  '310' => '[email protected]',
  '311' => '[email protected]',
  '313' => '[email protected]',
  '314' => '[email protected]',
  '315' => '[email protected]',
  '316' => '[email protected]',
  '317' => '[email protected]',
  '318' => '[email protected]',
  '319' => '[email protected]',
  '320' => '[email protected]',
  '321' => '[email protected]',
  '322' => '[email protected]',
  '323' => '[email protected]',
  '325' => '[email protected]',
  '326' => '[email protected]',
  '327' => '[email protected]',
  '328' => '[email protected]',
  '329' => '[email protected]',
  '330' => '[email protected]',
  '331' => '[email protected]',
  '333' => '[email protected]',
  '334' => '[email protected]',
  '335' => '[email protected]',
  '339' => '[email protected]',
  '340' => '[email protected]',
  '341' => '[email protected]',
  '343' => '[email protected]',
  '344' => '[email protected]',
  '345' => '[email protected]',
  '346' => '[email protected]',
  '347' => '[email protected]',
  '348' => '[email protected]',
  '349' => '[email protected]',
  '350' => '[email protected]',
  '351' => '[email protected]',
  '354' => '[email protected]',
  '355' => '[email protected]',
  '358' => '[email protected]',
  '362' => '[email protected]',
  '372' => '[email protected]',
  '373' => '[email protected]',
  '377' => '[email protected]',
  '402' => '[email protected]',
  '405' => '[email protected]',
  '436' => '[email protected]',
  '437' => '[email protected]',
  '438' => '[email protected]',
  '442' => '[email protected]',
  '452' => '[email protected]',
  '459' => '[email protected]',
  '460' => 'VAVBA/WIM/RO/VR&[email protected]',
  '463' => '[email protected]',
  '000' => '[email protected]'
}.freeze

Instance Method Summary collapse

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Methods inherited from SavedClaim

add_form_and_validation, #after_create_metrics, #after_destroy_metrics, #attachment_keys, #confirmation_number, #email, #form_is_string, #form_matches_schema, #form_must_be_string, #insert_notification, #open_struct_form, #parsed_form, #submitted_at, #update_form, #va_notification?, #validate_form, #validate_schema

Methods inherited from ApplicationRecord

descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?

Constructor Details

#initialize(args) ⇒ VeteranReadinessEmploymentClaim

Returns a new instance of VeteranReadinessEmploymentClaim.



77
78
79
80
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 77

def initialize(args)
  @sent_to_lighthouse = false
  super
end

Instance Method Details

#add_claimant_info(user) ⇒ Object



82
83
84
85
86
87
88
89
90
91
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 82

def add_claimant_info(user)
  return if form.blank?

  updated_form = parsed_form

  add_veteran_info(updated_form, user) if user&.loa3?
  add_office_location(updated_form) if updated_form['veteranInformation'].present?

  update!(form: updated_form.to_json)
end

#add_office_location(updated_form) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 106

def add_office_location(updated_form)
  regional_office = check_office_location
  @office_location = regional_office[0]
  office_name = regional_office[1]

  updated_form['veteranInformation']&.merge!({
                                               'regionalOffice' => "#{@office_location} - #{office_name}",
                                               'regionalOfficeName' => office_name,
                                               'stationId' => @office_location
                                             })
end

#add_veteran_info(updated_form, user) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 93

def add_veteran_info(updated_form, user)
  updated_form['veteranInformation'].merge!(
    {
      'VAFileNumber' => veteran_va_file_number(user),
      'pid' => user.participant_id,
      'edipi' => user.edipi,
      'vet360ID' => user.vet360_id,
      'dob' => user.birth_date,
      'ssn' => user.ssn
    }
  ).except!('vaFileNumber')
end

#bgs_clientObject (private)



316
317
318
319
320
321
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 316

def bgs_client
  @service ||= BGS::Services.new(
    external_uid: parsed_form['email'],
    external_key:
  )
end

#business_lineObject



275
276
277
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 275

def business_line
  'VRE'
end

#check_office_locationObject (private)



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 299

def check_office_location
  service = bgs_client
  vet_info = parsed_form['veteranAddress']

  regional_office_response = service.routing.get_regional_office_by_zip_code(
    vet_info['postalCode'], vet_info['country'], vet_info['state'], 'VRE', parsed_form['veteranInformation']['ssn']
  )

  [
    regional_office_response[:regional_office][:number],
    regional_office_response[:regional_office][:name]
  ]
rescue => e
  Rails.logger.warn(e.message)
  ['000', 'Not Found']
end

#external_keyObject (private)



323
324
325
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 323

def external_key
  parsed_form.dig('veteranInformation', 'fullName', 'first') || parsed_form['email']
end

#log_to_statsd(service) ⇒ Object (private)



338
339
340
341
342
343
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 338

def log_to_statsd(service)
  start_time = Time.current
  yield
  elapsed_time = Time.current - start_time
  StatsD.measure("api.1900.#{service}.response_time", elapsed_time, tags: {})
end

#process_attachments!Object



267
268
269
270
271
272
273
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 267

def process_attachments!
  refs = attachment_keys.map { |key| Array(open_struct_form.send(key)) }.flatten
  files = PersistentAttachment.where(guid: refs.map(&:confirmationCode))
  files.find_each { |f| f.update(saved_claim_id: id) }

  Lighthouse::SubmitBenefitsIntakeClaim.new.perform(id)
end

#regional_officeObject

SavedClaims require regional_office to be defined



237
238
239
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 237

def regional_office
  []
end

#send_failure_email(email) ⇒ Object

this failure email is not the ideal way to handle the Notification Emails as part of the ZSF work, but with the initial timeline it handles the email as intended. Future work will be integrating into the Va Notify common lib: github.com/department-of-veterans-affairs/vets-api/blob/master/lib/va_notify/notification_email.rb



283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 283

def send_failure_email(email)
  if email.present?
    VANotify::EmailJob.perform_async(
      email,
      Settings.vanotify.services.va_gov.template_id.form1900_action_needed_email,
      {
        'first_name' => parsed_form.dig('veteranInformation', 'fullName', 'first'),
        'date_submitted' => Time.zone.today.strftime('%B %d, %Y'),
        'confirmation_number' => confirmation_number
      }
    )
  end
end

#send_lighthouse_confirmation_email(user) ⇒ Object



254
255
256
257
258
259
260
261
262
263
264
265
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 254

def send_lighthouse_confirmation_email(user)
  return if user.va_profile_email.blank?

  VANotify::EmailJob.perform_async(
    user.va_profile_email,
    Settings.vanotify.services.va_gov.template_id.ch31_central_mail_form_confirmation_email,
    {
      'first_name' => user&.first_name&.upcase.presence,
      'date' => Time.zone.today.strftime('%B %d, %Y')
    }
  )
end

#send_to_lighthouse!(user) ⇒ Object

Submit claim into lighthouse service, adds veteran info to top level of form, and sends confirmation email to user

Parameters:

  • user (User)

    user account of submitting user

Returns:

  • None



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 185

def send_to_lighthouse!(user)
  form_copy = parsed_form.clone

  form_copy['veteranSocialSecurityNumber'] = parsed_form.dig('veteranInformation', 'ssn')
  form_copy['veteranFullName'] = parsed_form.dig('veteranInformation', 'fullName')
  form_copy['vaFileNumber'] = parsed_form.dig('veteranInformation', 'VAFileNumber')

  update!(form: form_copy.to_json)

  process_attachments!
  @sent_to_lighthouse = true

  send_lighthouse_confirmation_email(user)
rescue => e
  Rails.logger.error('Error uploading VRE claim to Benefits Intake API', { user_uuid: user&.uuid, e: })
end

#send_to_res(user) ⇒ Hash

Send claim via RES service

Parameters:

  • user (User)

    user account of submitting user

Returns:

  • (Hash)

    Response payload of RES service



205
206
207
208
209
210
211
212
213
214
215
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 205

def send_to_res(user)
  Rails.logger.info('VRE claim sending to RES service',
                    {
                      user_uuid: user.uuid,
                      was_sent: @sent_to_lighthouse,
                      user_present: user.present?
                    })

  service = RES::Ch31Form.new(user:, claim: self)
  service.submit
end

#send_to_vre(user) ⇒ Hash

Common method for VRE form submission:

  • Adds information from user to payload

  • Submits to VBMS if participant ID is there, to Lighthouse if not.

  • Sends email if user is present

  • Sends to RES or VRE service based on flipper status

Parameters:

  • user (User)

    user account of submitting user

Returns:

  • (Hash)

    Response payload of service that was used (RES or VRE)



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 125

def send_to_vre(user)
  add_claimant_info(user)

  if user&.participant_id
    upload_to_vbms(user:)
  else
    Rails.logger.warn('Participant id is blank when submitting VRE claim')
    send_to_lighthouse!(user)
  end

  email_addr = REGIONAL_OFFICE_EMAILS[@office_location] || '[email protected]'
  Rails.logger.info('VRE claim sending email:', { email: email_addr, user_uuid: user.uuid })
  VeteranReadinessEmploymentMailer.build(user.participant_id, email_addr,
                                         @sent_to_lighthouse).deliver_later

  if Flipper.enabled?(:veteran_readiness_employment_to_res)
    send_to_res(user)
  else
    send_vre_form(user)
  end
end

#send_vbms_confirmation_email(user) ⇒ Object



241
242
243
244
245
246
247
248
249
250
251
252
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 241

def send_vbms_confirmation_email(user)
  return if user.va_profile_email.blank?

  VANotify::EmailJob.perform_async(
    user.va_profile_email,
    Settings.vanotify.services.va_gov.template_id.ch31_vbms_form_confirmation_email,
    {
      'first_name' => user&.first_name&.upcase.presence,
      'date' => Time.zone.today.strftime('%B %d, %Y')
    }
  )
end

#send_vre_form(user) ⇒ Hash

Send claim via VRE service, does not submit if office location is not permitted

Parameters:

  • user (User)

    user account of submitting user

Returns:

  • (Hash)

    Response payload of VRE service



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 220

def send_vre_form(user)
  Rails.logger.info('VRE claim sending to VRE service',
                    {
                      user_uuid: user.uuid,
                      was_sent: @sent_to_lighthouse,
                      user_present: user.present?
                    })

  # During Roll out our partners ask that we check vet location and if within proximity to specific offices,
  # send the data to them. We always send a pdf to VBMS
  return unless PERMITTED_OFFICE_LOCATIONS.include?(@office_location)

  service = VRE::Ch31Form.new(user:, claim: self)
  service.submit
end

#to_pdf(file_name = nil) ⇒ Object



177
178
179
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 177

def to_pdf(file_name = nil)
  PdfFill::Filler.fill_form(self, file_name, { created_at: })
end

#upload_to_vbms(user:, doc_type: '1167') ⇒ Object

Submit claim into VBMS service, uploading document directly to VBMS, adds document ID from VBMS to form info, and sends confirmation email to user Submits to Lighthouse on failure

Parameters:

  • user (User)

    user account of submitting user

Returns:

  • None



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 152

def upload_to_vbms(user:, doc_type: '1167')
  form_path = PdfFill::Filler.fill_form(self, nil, { created_at: })

  uploader = ClaimsApi::VBMSUploader.new(
    filepath: Rails.root.join(form_path),
    file_number: parsed_form['veteranInformation']['VAFileNumber'] || parsed_form['veteranInformation']['ssn'],
    doc_type:
  )

  log_to_statsd('vbms') do
    response = uploader.upload!

    if response[:vbms_document_series_ref_id].present?
      updated_form = parsed_form
      updated_form['documentId'] = response[:vbms_document_series_ref_id]
      update!(form: updated_form.to_json)
    end
  end

  send_vbms_confirmation_email(user)
rescue
  Rails.logger.error('Error uploading VRE claim to VBMS.', { user_uuid: user.uuid })
  send_to_lighthouse!(user)
end

#veteran_informationObject (private)



327
328
329
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 327

def veteran_information
  errors.add(:form, 'Veteran Information is missing from form') if parsed_form['veteranInformation'].blank?
end

#veteran_va_file_number(user) ⇒ Object (private)



331
332
333
334
335
336
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 331

def veteran_va_file_number(user)
  response = BGS::People::Request.new.find_person_by_participant_id(user:)
  response.file_number
rescue
  nil
end