Class: FormProfiles::VA526ez

Inherits:
FormProfile
  • Object
show all
Defined in:
app/models/form_profiles/va_526ez.rb

Constant Summary collapse

FORM_ID =
'21-526EZ'

Instance Method Summary collapse

Instance Method Details

#convert_vets360_address(address) ⇒ Object (private)



218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'app/models/form_profiles/va_526ez.rb', line 218

def convert_vets360_address(address)
  return if address.blank?

  {
    address_line_1: address.address_line1,
    address_line_2: address.address_line2,
    address_line_3: address.address_line3,
    city: address.city,
    country: address.country_code_iso3,
    state: address.state_code || address.province,
    zip_code: address.zip_plus_four || address.international_postal_code
  }.compact
end

#get_common_addressObject (private)

Convert PCIU address to a Common address type



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'app/models/form_profiles/va_526ez.rb', line 233

def get_common_address
  service = EVSS::PCIUAddress::Service.new(user)
  response = service.get_address
  case response.address
  when EVSS::PCIUAddress::DomesticAddress
    prefill_domestic_address(response.address)
  when EVSS::PCIUAddress::InternationalAddress
    prefill_international_address(response.address)
  when EVSS::PCIUAddress::MilitaryAddress
    prefill_military_address(response.address)
  else
    {}
  end
rescue
  {}
end

#initialize_form526_prefillObject (private)



168
169
170
171
172
173
174
175
# File 'app/models/form_profiles/va_526ez.rb', line 168

def initialize_form526_prefill
  VA526ez::Form526Prefill.new(
    # any form that has a startedFormVersion (whether it is '2019' or '2022') will go through the Toxic Exposure flow
    # '2022' means the Toxic Exposure 1.0 flag.
    started_form_version: Flipper.enabled?(:disability_526_toxic_exposure, user) ? '2022' : nil,
    sync_modern_0781_flow: Flipper.enabled?(:disability_compensation_sync_modern_0781_flow, user)
  )
end

#initialize_payment_informationObject (private)



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'app/models/form_profiles/va_526ez.rb', line 284

def initialize_payment_information
  return {} unless user.authorize(:ppiu, :access?) && user.authorize(:evss, :access?)

  provider = ApiProviderFactory.call(type: ApiProviderFactory::FACTORIES[:ppiu],
                                     current_user: user,
                                     feature_toggle: ApiProviderFactory::FEATURE_TOGGLE_PPIU_DIRECT_DEPOSIT)
  response = provider.get_payment_information
   = response.responses.first&.

  if 
    VA526ez::FormPaymentAccountInformation.new(
      account_type: &.&.capitalize,
      account_number: mask(&.),
      routing_number: mask(&.financial_institution_routing_number),
      bank_name: &.financial_institution_name
    )
  else
    {}
  end
rescue => e
  log_ppiu_error(e, provider)
  {}
end

#initialize_rated_disabilities_informationObject



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

def initialize_rated_disabilities_information
  return {} unless user.authorize :evss, :access?

  api_provider = ApiProviderFactory.call(
    type: ApiProviderFactory::FACTORIES[:rated_disabilities],
    provider: nil,
    options: {
      icn: user.icn.to_s,
      auth_headers: EVSS::DisabilityCompensationAuthHeaders.new(user).add_headers(EVSS::AuthHeaders.new(user).to_h)
    },
    current_user: user,
    feature_toggle: ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES_FOREGROUND
  )
  invoker = 'FormProfiles::VA526ez#initialize_rated_disabilities_information'
  response = api_provider.get_rated_disabilities(nil, nil, { invoker: })
  ClaimFastTracking::MaxRatingAnnotator.annotate_disabilities(response)

  # Remap response object to schema fields
  VA526ez::FormRatedDisabilities.new(
    rated_disabilities: response.rated_disabilities
  )
end

#initialize_veteran_contact_informationObject (private)



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'app/models/form_profiles/va_526ez.rb', line 190

def initialize_veteran_contact_information
  return {} unless user.authorize :evss, :access?

  contact_info = if Flipper.enabled?(:disability_compensation_remove_pciu, user)
                   initialize_vets360_contact_info
                 else
                   # fill in blank values with PCIU data
                   initialize_vets360_contact_info.merge(
                     mailing_address: get_common_address,
                     email_address: extract_pciu_data(:pciu_email),
                     primary_phone: pciu_us_phone
                   ) { |_, old_val, new_val| old_val.presence || new_val }
                 end
  # Logging was added below to contrast/compare completeness of contact information returned
  # from VA Profile alone versus VA Profile + PCIU. This logging will be removed when the Flipper flag is.
  Rails.logger.info("disability_compensation_remove_pciu=#{Flipper.enabled?(:disability_compensation_remove_pciu,
                                                                            user)}," \
                      "mailing_address=#{contact_info[:mailing_address].present?}," \
                      "email_address=#{contact_info[:email_address].present?}," \
                      "primary_phone=#{contact_info[:primary_phone].present?}")

  contact_info = VA526ez::FormContactInformation.new(contact_info)

  VA526ez::FormVeteranContactInformation.new(
    veteran: contact_info
  )
end

#initialize_vets360_contact_infoObject (private)



177
178
179
180
181
182
183
184
185
186
187
188
# File 'app/models/form_profiles/va_526ez.rb', line 177

def initialize_vets360_contact_info
  return {} unless vet360_contact_info

  {
    mailing_address: convert_vets360_address(vet360_mailing_address),
    email_address: vet360_contact_info&.email&.email_address,
    primary_phone: [
      vet360_contact_info&.home_phone&.area_code,
      vet360_contact_info&.home_phone&.phone_number
    ].join
  }.compact
end

#log_ppiu_error(e, provider) ⇒ Object (private)



308
309
310
311
312
# File 'app/models/form_profiles/va_526ez.rb', line 308

def log_ppiu_error(e, provider)
  method_name = '#initialize_payment_information'
  error_message = "#{method_name} Failed to retrieve PPIU data from #{provider.class}: #{e.message}"
  Rails.logger.error(error_message)
end

#mask(number) ⇒ Object (private)



314
315
316
# File 'app/models/form_profiles/va_526ez.rb', line 314

def mask(number)
  number.gsub(/.(?=.{4})/, '*')
end

#metadataObject



115
116
117
118
119
120
121
# File 'app/models/form_profiles/va_526ez.rb', line 115

def 
  {
    version: 0,
    prefill: true,
    returnUrl: '/veteran-information'
  }
end

#prefillObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/models/form_profiles/va_526ez.rb', line 87

def prefill
  @prefill_526 = initialize_form526_prefill

  begin
    @rated_disabilities_information = initialize_rated_disabilities_information
  rescue => e
    Rails.logger.error("Form526 Prefill for rated disabilities failed. #{e.message}")
  end

  begin
    @veteran_contact_information = initialize_veteran_contact_information
  rescue => e
    Rails.logger.error("Form526 Prefill for veteran contact information failed. #{e.message}")
  end

  begin
    @payment_information = initialize_payment_information
  rescue => e
    Rails.logger.error("Form526 Prefill for payment information failed. #{e.message}")
  end

  prefill_base_class_methods

  mappings = self.class.mappings_for_form(form_id)
  form_data = generate_prefill(mappings)
  { form_data:, metadata: }
end

#prefill_base_class_methodsObject (private)



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'app/models/form_profiles/va_526ez.rb', line 148

def prefill_base_class_methods
  begin
    @identity_information = initialize_identity_information
  rescue => e
    Rails.logger.error("Form526 Prefill for identity information failed. #{e.message}")
  end

  begin
    @contact_information = initialize_contact_information
  rescue => e
    Rails.logger.error("Form526 Prefill for contact information failed. #{e.message}")
  end

  begin
    @military_information = initialize_military_information
  rescue => e
    Rails.logger.error("Form526 Prefill for military information failed. #{e.message}")
  end
end

#prefill_domestic_address(address) ⇒ Object (private)



250
251
252
253
254
255
256
257
258
259
260
# File 'app/models/form_profiles/va_526ez.rb', line 250

def prefill_domestic_address(address)
  {
    country: address&.country_name,
    city: address&.city,
    state: address&.state_code,
    zip_code: address&.zip_code,
    address_line_1: address&.address_one,
    address_line_2: address&.address_two,
    address_line_3: address&.address_three
  }.compact
end

#prefill_international_address(address) ⇒ Object (private)



262
263
264
265
266
267
268
269
270
# File 'app/models/form_profiles/va_526ez.rb', line 262

def prefill_international_address(address)
  {
    country: address&.country_name,
    city: address&.city,
    address_line_1: address&.address_one,
    address_line_2: address&.address_two,
    address_line_3: address&.address_three
  }.compact
end

#prefill_military_address(address) ⇒ Object (private)



272
273
274
275
276
277
278
279
280
281
282
# File 'app/models/form_profiles/va_526ez.rb', line 272

def prefill_military_address(address)
  {
    country: 'USA',
    city: address&.military_post_office_type_code,
    state: address&.military_state_code,
    zip_code: address&.zip_code,
    address_line_1: address&.address_one,
    address_line_2: address&.address_two,
    address_line_3: address&.address_three
  }.compact
end