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

Methods inherited from SavedClaim

add_form_and_validation, #confirmation_number, #form_is_string, #form_matches_schema, #form_must_be_string, #open_struct_form, #parsed_form, #submit_to_structured_data_services!, #submitted_at, #to_pdf, #update_form

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.



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

def initialize(args)
  @sent_to_cmp = false
  super
end

Instance Method Details

#add_claimant_info(user) ⇒ Object



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

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



105
106
107
108
109
110
111
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 105

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}" })
end

#add_veteran_info(updated_form, user) ⇒ Object



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

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

#process_attachments!Object



221
222
223
224
225
226
227
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 221

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) }

  CentralMail::SubmitSavedClaimJob.new.perform(id)
end

#regional_officeObject

SavedClaims require regional_office to be defined



191
192
193
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 191

def regional_office
  []
end

#send_central_mail_confirmation_email(user) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 208

def send_central_mail_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_central_mail!(user) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 151

def send_to_central_mail!(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)

  log_message_to_sentry(guid, :warn, { attachment_id: guid }, { team: 'vfs-ebenefits' })
  @sent_to_cmp = true
  log_to_statsd('cmp') do
    process_attachments!
  end

  send_central_mail_confirmation_email(user)
end

#send_to_vre(user) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 113

def send_to_vre(user)
  if user&.participant_id.blank?
    log_message_to_sentry('Participant id is blank when submitting VRE claim', :warn)
    send_to_central_mail!(user)
  else
    begin
      upload_to_vbms
      send_vbms_confirmation_email(user)
    rescue => e
      log_message_to_sentry('Error uploading VRE claim to VBMS', :warn, { uuid: user.uuid })
      log_exception_to_sentry(e, { uuid: user.uuid })
      begin
        send_to_central_mail!(user)
      rescue => e
        log_message_to_sentry('Error uploading VRE claim to central mail after failure uploading claim to vbms',
                              :warn, { uuid: user.uuid })
        log_exception_to_sentry(e, { uuid: user.uuid })
      end
    end
  end

  send_vre_email_form(user)
end

#send_vbms_confirmation_email(user) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 195

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_email_form(user) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 169

def send_vre_email_form(user)
  @office_location = check_office_location[0] if @office_location.nil?

  log_message_to_sentry("VRE claim office location: #{@office_location}",
                        :info, { uuid: user.uuid })

  email_addr = REGIONAL_OFFICE_EMAILS[@office_location] || '[email protected]'

  log_message_to_sentry("VRE claim email: #{email_addr}, sent to cmp: #{@sent_to_cmp} #{user.present?}",
                        :info, { uuid: user.uuid })

  VeteranReadinessEmploymentMailer.build(user.participant_id, email_addr, @sent_to_cmp).deliver_later if 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

#upload_to_vbms(doc_type: '1167') ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'app/models/saved_claim/veteran_readiness_employment_claim.rb', line 137

def upload_to_vbms(doc_type: '1167')
  form_path = PdfFill::Filler.fill_form(self)

  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
    uploader.upload!
  end
end