Class: EVSS::DisabilityCompensationForm::DataTranslationAllClaim

Inherits:
Object
  • Object
show all
Defined in:
lib/evss/disability_compensation_form/data_translation_all_claim.rb

Overview

Transforms a client submission into the format expected by the EVSS 526 service

Constant Summary collapse

HOMELESS_SITUATION_TYPE =

rubocop:disable Metrics/ClassLength

{
  'shelter' => 'LIVING_IN_A_HOMELESS_SHELTER',
  'notShelter' => 'NOT_CURRENTLY_IN_A_SHELTERED_ENVIRONMENT',
  'anotherPerson' => 'STAYING_WITH_ANOTHER_PERSON',
  'fleeing' => 'FLEEING_CURRENT_RESIDENCE',
  'other' => 'OTHER'
}.freeze
HOMELESS_RISK_SITUATION_TYPE =
{
  'losingHousing' => 'HOUSING_WILL_BE_LOST_IN_30_DAYS',
  'leavingShelter' => 'LEAVING_PUBLICLY_FUNDED_SYSTEM_OF_CARE',
  'other' => 'OTHER'
}.freeze
TERMILL_OVERFLOW_TEXT =
"Corporate Flash Details\n" \
"This applicant has indicated that they're terminally ill.\n"
FORM4142_OVERFLOW_TEXT =
'VA Form 21-4142/4142a has been completed by the applicant and sent to the ' \
'PMR contractor for processing in accordance with M21-1 III.iii.1.D.2.'
FORM0781_OVERFLOW_TEXT =
"VA Form 0781/a has been completed by the applicant and sent to the VBMS eFolder\n"
OVERFLOW_TEXT_THRESHOLD =
4000
VETERAN_FILE_LIST_STATSD_PREFIX =
'api.form_526.overflow_text.veteran_file_list'
EVSS_TZ =

EVSS validates this date using CST, at some point this may change to EST.

'Central Time (US & Canada)'

Instance Method Summary collapse

Constructor Details

#initialize(user, form_content, has_form4142) ⇒ DataTranslationAllClaim

Returns a new instance of DataTranslationAllClaim.



42
43
44
45
46
47
48
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 42

def initialize(user, form_content, has_form4142)
  @form_submission_date = Time.now.in_time_zone(EVSS_TZ).to_date
  @user = user
  @form_content = form_content
  @has_form4142 = has_form4142
  @translated_form = { 'form526' => {} }
end

Instance Method Details

#add_toxic_exposureObject (private)

Toxic Exposure



709
710
711
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 709

def add_toxic_exposure
  { 'toxicExposure' => input_form['toxicExposure'] }
end

#application_expiration_dateObject (private)



713
714
715
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 713

def application_expiration_date
  1.year.from_now.iso8601
end

#approximate_date(date) ⇒ Object (private)



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 521

def approximate_date(date)
  return nil if date.blank?

  year, month, day = date.split('-')
  return nil if year == 'XXXX'

  # month/day are optional and can be XXed out
  month = nil if month == 'XX'
  day = nil if day == 'XX'

  {
    'year' => year,
    'month' => month,
    'day' => day
  }.compact
end

#at_riskObject (private)



482
483
484
485
486
487
488
489
490
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 482

def at_risk
  {
    'pointOfContact' => point_of_contact,
    'homelessnessRisk' => {
      'homelessnessRiskSituationType' => HOMELESS_RISK_SITUATION_TYPE[input_form['atRiskHousingSituation']],
      'otherLivingSituation' => input_form['otherAtRiskHousing']
    }.compact
  }
end

#bdd_qualified?Boolean (private)

Returns:

  • (Boolean)


743
744
745
746
747
748
749
750
751
752
753
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 743

def bdd_qualified?
  # To be bdd_qualified application should be submitted 180-90 days prior to Release from Active Duty (RAD) date.
  # Applications < 90 days prior to release can be submitted but only with value as false.
  if days_until_release > 180
    raise Common::Exceptions::UnprocessableEntity.new(
      detail: 'User may not submit BDD more than 180 days prior to RAD date',
      source: 'DataTranslationAllClaim'
    )
  end
  days_until_release >= 90
end

#can_set_direct_deposit?(account) ⇒ Boolean (private)

Direct Deposit cannot be set unless all these fields are set

Returns:

  • (Boolean)


208
209
210
211
212
213
214
215
216
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 208

def can_set_direct_deposit?()
  return unless 
  return if ..blank?
  return if ..blank?
  return if .financial_institution_routing_number.blank?
  return if .financial_institution_name.blank?

  true
end

#days_until_releaseObject (private)



737
738
739
740
741
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 737

def days_until_release
  return 0 unless user_supplied_rad_date

  @days_until_release ||= user_supplied_rad_date - @form_submission_date
end

#direct_deposit(type, account_number, routing_number, bank_name) ⇒ Object (private)



218
219
220
221
222
223
224
225
226
227
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 218

def direct_deposit(type, , routing_number, bank_name)
  {
    'directDeposit' => {
      'accountType' => type.upcase,
      'accountNumber' => ,
      'routingNumber' => routing_number,
      'bankName' => bank_name
    }
  }
end

#get_address_type(address) ⇒ Object (private)



414
415
416
417
418
419
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 414

def get_address_type(address)
  return 'MILITARY' if %w[AA AE AP].include?(address['state'])
  return 'DOMESTIC' if address['country'] == 'USA'

  'INTERNATIONAL'
end

#get_banking_infoObject (private)



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 171

def get_banking_info
  return {} unless @user.authorize :ppiu, :access?

  # Call to either EVSS or Lighthouse PPIU/Direct Deposit data provider
  service = ApiProviderFactory.call(
    type: ApiProviderFactory::FACTORIES[:ppiu],
    provider: nil,
    options: {},
    current_user: @user,
    feature_toggle: ApiProviderFactory::FEATURE_TOGGLE_PPIU_DIRECT_DEPOSIT
  )

  response = service.get_payment_information

  begin
    (response)
  rescue => e
    method_name = '#get_banking_info'
    Rails.logger.error "#{method_name} Failed to retrieve PPIU data from #{service.class}: #{e.message}"
    raise Common::Exceptions::BadRequest.new(errors: [e.message])
  end
end

#homelessObject (private)



470
471
472
473
474
475
476
477
478
479
480
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 470

def homeless
  # The form separates the `fleeing` key from the rest and needs to be checked
  situation = input_form['needToLeaveHousing'].present? ? 'fleeing' : input_form['homelessHousingSituation']
  {
    'pointOfContact' => point_of_contact,
    'currentlyHomeless' => {
      'homelessSituationType' => HOMELESS_SITUATION_TYPE[situation],
      'otherLivingSituation' => input_form['otherHomelessHousing']
    }.compact
  }
end

#input_formObject (private)



86
87
88
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 86

def input_form
  @form_content['form526']
end

#list_attachment_filenames(attachments) ⇒ Object (private)



144
145
146
147
148
149
150
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 144

def list_attachment_filenames(attachments)
  sorted_filenames = attachments.map(&:original_filename).sort

  sorted_filenames.inject('') do |list, filename|
    list + "#{filename}\n"
  end
end

#map_disability(input_disability) ⇒ Object (private)



589
590
591
592
593
594
595
596
597
598
599
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 589

def map_disability(input_disability)
  case input_disability['cause']
  when 'NEW'
    append_input_disability = map_new(input_disability)
  when 'WORSENED'
    append_input_disability = map_worsened(input_disability)
  when 'VA'
    append_input_disability = map_va(input_disability)
  end
  append_input_disability
end

#map_new(input_disability) ⇒ Hash (private)

Map ‘NEW’ type disability to EVSS required disability fields

Parameters:

  • input_disability (Hash)

    The newly submitted disability

Options Hash (input_disability):

  • :condition (String)

    The name of the disability

  • :classificationCode (String)

    Optional classification code

  • :specialIssues (Array<String>)

    Optional list of associated special issues

  • :primaryDescription (String)

    The disabilities description

Returns:

  • (Hash)

    Transformed disability to match EVSS’s validation



624
625
626
627
628
629
630
631
632
633
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 624

def map_new(input_disability)
  {
    'name' => input_disability['condition'],
    'classificationCode' => input_disability['classificationCode'],
    'disabilityActionType' => 'NEW',
    'specialIssues' => input_disability['specialIssues'].presence,
    'serviceRelevance' => "Caused by an in-service event, injury, or exposure\n"\
                          "#{input_disability['primaryDescription']}"
  }.compact
end

#map_secondary(input_disability, disabilities) ⇒ Hash (private)

Map ‘SECONDARY’ type disability to EVSS required disability fields and attach it to preexisting disability

Parameters:

  • input_disability (Hash)

    The newly submitted disability

Options Hash (input_disability):

  • :condition (String)

    The name of the disability

  • :classificationCode (String)

    Optional classification code

  • :specialIssues (Array<String>)

    Optional list of associated special issues

  • :causedByDisabilityDescription (String)

    The disabilities description

Returns:

  • (Hash)

    Transformed disability to match EVSS’s validation



687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 687

def map_secondary(input_disability, disabilities)
  disability = {
    'name' => input_disability['condition'],
    'classificationCode' => input_disability['classificationCode'],
    'disabilityActionType' => 'SECONDARY',
    'specialIssues' => input_disability['specialIssues'].presence,
    'serviceRelevance' => "Caused by a service-connected disability\n"\
                          "#{input_disability['causedByDisabilityDescription']}"
  }.compact

  disabilities.each do |output_disability|
    if output_disability['name'].casecmp(input_disability['causedByDisability']).zero?
      output_disability['secondaryDisabilities'] = [] if output_disability['secondaryDisabilities'].blank?
      output_disability['secondaryDisabilities'].append(disability)
    end
  end
end

#map_va(input_disability) ⇒ Hash (private)

Map ‘VA’ type disability to EVSS required disability fields

Parameters:

  • input_disability (Hash)

    The newly submitted disability

Options Hash (input_disability):

  • :condition (String)

    The name of the disability

  • :classificationCode (String)

    Optional classification code

  • :specialIssues (Array<String>)

    Optional list of associated special issues

  • :vaMistreatmentDescription (String)

    The disabilities description

  • :vaMistreatmentLocation (String)

    The location the disability occurred

  • :vaMistreatmentDate (String)

    The Date the disability occurred

Returns:

  • (Hash)

    Transformed disability to match EVSS’s validation



665
666
667
668
669
670
671
672
673
674
675
676
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 665

def map_va(input_disability)
  {
    'name' => input_disability['condition'],
    'classificationCode' => input_disability['classificationCode'],
    'disabilityActionType' => 'NEW',
    'specialIssues' => input_disability['specialIssues'].presence,
    'serviceRelevance' => "Caused by VA care\n"\
                          "Event: #{input_disability['vaMistreatmentDescription']}\n"\
                          "Location: #{input_disability['vaMistreatmentLocation']}\n"\
                          "TimeFrame: #{input_disability['vaMistreatmentDate']}"
  }.compact
end

#map_worsened(input_disability) ⇒ Hash (private)

Map ‘WORSENED’ type disability to EVSS required disability fields

Parameters:

  • input_disability (Hash)

    The newly submitted disability

Options Hash (input_disability):

  • :condition (String)

    The name of the disability

  • :classificationCode (String)

    Optional classification code

  • :specialIssues (Array<String>)

    Optional list of associated special issues

  • :worsenedDescription (String)

    The disabilities description

  • :worsenedEffects (String)

    The disabilities effects

Returns:

  • (Hash)

    Transformed disability to match EVSS’s validation



644
645
646
647
648
649
650
651
652
653
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 644

def map_worsened(input_disability)
  {
    'name' => input_disability['condition'],
    'classificationCode' => input_disability['classificationCode'],
    'disabilityActionType' => 'NEW',
    'specialIssues' => input_disability['specialIssues'].presence,
    'serviceRelevance' => "Worsened because of military service\n"\
                          "#{input_disability['worsenedDescription']}: #{input_disability['worsenedEffects']}"
  }.compact
end

#military_retired_payObject (private)



244
245
246
247
248
249
250
251
252
253
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 244

def military_retired_pay
  return nil if input_form['militaryRetiredPayBranch'].blank?

  {
    'receiving' => true,
    'payment' => {
      'serviceBranch' => service_branch(input_form['militaryRetiredPayBranch'])
    }
  }
end

#output_formObject (private)



94
95
96
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 94

def output_form
  @translated_form['form526']
end

#overflow_textObject (private)



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 98

def overflow_text
  overflow = ''
  overflow += TERMILL_OVERFLOW_TEXT if input_form['isTerminallyIll'].present?
  overflow += FORM4142_OVERFLOW_TEXT if @has_form4142

  if Flipper.enabled?(:form526_include_document_upload_list_in_overflow_text)
    overflow += FORM0781_OVERFLOW_TEXT if input_form['form0781'].present?

    if input_form['attachments'].present?
      file_guids = input_form['attachments'].pluck('confirmationCode')
      attachments = SupportingEvidenceAttachment.where(guid: file_guids)

      overflow += veteran_attached_files_text(attachments, overflow.length) if attachments.present?
    end
  end

  overflow
end

#payment(branch) ⇒ Object (private)



265
266
267
268
269
270
271
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 265

def payment(branch)
  return nil if branch.blank?

  {
    'serviceBranch' => service_branch(branch)
  }
end

#point_of_contactObject (private)



492
493
494
495
496
497
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 492

def point_of_contact
  {
    'pointOfContactName' => input_form['homelessnessContact']['name'],
    'primaryPhone' => split_phone_number(input_form['homelessnessContact']['phoneNumber'])
  }
end

#redacted(account_number, routing_number) ⇒ Object (private)



82
83
84
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 82

def redacted(, routing_number)
  &.include?('*') || routing_number&.include?('*')
end

#scrub_disability_condition(condition) ⇒ Object (private)



601
602
603
604
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 601

def scrub_disability_condition(condition)
  re = %r{([a-zA-Z0-9\-'.,/() ]+)}
  condition.scan(re).join.squish
end

#separation_payObject (private)



255
256
257
258
259
260
261
262
263
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 255

def separation_pay
  return nil if input_form['hasSeparationPay'].blank?

  {
    'received' => true,
    'payment' => payment(input_form['separationPayBranch']),
    'receivedDate' => approximate_date(input_form['separationPayDate'])
  }.compact
end

#service_branch(service_branch) ⇒ Object (private)



349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 349

def service_branch(service_branch)
  branch_map = {
    'Air Force Reserve' => 'Air Force Reserves',
    'Army Reserve' => 'Army Reserves',
    'Coast Guard Reserve' => 'Coast Guard Reserves',
    'Marine Corps Reserve' => 'Marine Corps Reserves',
    'Navy Reserve' => 'Navy Reserves',
    'NOAA' => 'National Oceanic & Atmospheric Administration'
  }
  return branch_map[service_branch] if branch_map.key? service_branch

  service_branch
end

#service_infoObject (private)



90
91
92
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 90

def service_info
  input_form['serviceInformation']
end

#set_account(response) ⇒ Object (private)



194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 194

def (response)
   = response.responses.first.

  if can_set_direct_deposit?()
    direct_deposit(
      ., .,
      .financial_institution_routing_number, .financial_institution_name
    )
  else
    {}
  end
end

#set_domestic_address(address, zip_code) ⇒ Object (private)



421
422
423
424
425
426
427
428
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 421

def set_domestic_address(address, zip_code)
  {
    'city' => address['city'],
    'state' => address['state'],
    'zipFirstFive' => zip_code.first,
    'zipLastFour' => zip_code.last
  }
end

#set_international_address(address) ⇒ Object (private)



439
440
441
442
443
444
445
446
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 439

def set_international_address(address)
  postal_codes = JSON.parse(File.read(Settings.evss.international_postal_codes))

  {
    'internationalPostalCode' => postal_codes[address['country']],
    'city' => address['city']
  }
end

#set_military_address(address, zip_code) ⇒ Object (private)



430
431
432
433
434
435
436
437
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 430

def set_military_address(address, zip_code)
  {
    'militaryPostOfficeTypeCode' => address['city']&.strip&.upcase,
    'militaryStateCode' => address['state'],
    'zipFirstFive' => zip_code.first,
    'zipLastFour' => zip_code.last
  }
end

#split_phone_number(phone_number) ⇒ Object (private)



452
453
454
455
456
457
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 452

def split_phone_number(phone_number)
  return nil if phone_number.blank?

  area_code, number = phone_number.match(/(\d{3})(\d{7})/).captures
  { 'areaCode' => area_code, 'phoneNumber' => number }
end

#split_zip_code(zip_code) ⇒ Object (private)



448
449
450
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 448

def split_zip_code(zip_code)
  zip_code.match(/(^\d{5})(?:([-\s]?)(\d{4})?$)/).captures
end

#translateHash

Performs the translation by merging system user data and data fetched from upstream services

Returns:

  • (Hash)

    The translated form ready for submission



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 54

def translate
  output_form['claimantCertification'] = true
  output_form['standardClaim'] = input_form['standardClaim']
  output_form['autoCestPDFGenerationDisabled'] = input_form['autoCestPDFGenerationDisabled'] || false
  output_form['applicationExpirationDate'] = application_expiration_date
  output_form['overflowText'] = overflow_text
  output_form['bddQualified'] = bdd_qualified?
  output_form['claimSubmissionSource'] = 'VA.gov'
  # any form that has a startedFormVersion (whether it is '2019' or '2022')
  # will go through the Toxic Exposure flow
  output_form['startedFormVersion'] = input_form['startedFormVersion'] || nil
  output_form.compact!

  output_form.update(translate_banking_info)
  output_form.update(translate_service_pay)
  output_form.update(translate_service_info)
  output_form.update(translate_veteran)
  output_form.update(translate_treatments)
  output_form.update(translate_disabilities)
  # any form that has a startedFormVersion (whether it is '2019' or '2022')
  # will go through the Toxic Exposure flow
  output_form.update(add_toxic_exposure) if output_form['startedFormVersion']

  @translated_form
end

#translate_banking_infoObject (private)

Banking info



156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 156

def translate_banking_info
  populated = input_form['bankName'].present? && input_form['bankAccountType'].present? &&
              input_form['bankAccountNumber'].present? && input_form['bankRoutingNumber'].present?
  # if banking data is not included then it has not changed and will be retrieved
  # from the PPIU service
  if !populated || redacted(input_form['bankAccountNumber'], input_form['bankRoutingNumber'])
    get_banking_info
  else
    direct_deposit(
      input_form['bankAccountType'], input_form['bankAccountNumber'],
      input_form['bankRoutingNumber'], input_form['bankName']
    )
  end
end

#translate_change_of_address(address) ⇒ Object (private)



380
381
382
383
384
385
386
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 380

def translate_change_of_address(address)
  return nil if address.blank?

  forwarding_address = translate_mailing_address(address)
  forwarding_address['addressChangeType'] = address['effectiveDate']['to'].blank? ? 'PERMANENT' : 'TEMPORARY'
  forwarding_address
end

#translate_confinementsObject (private)



308
309
310
311
312
313
314
315
316
317
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 308

def translate_confinements
  return nil if input_form['confinements'].blank?

  input_form['confinements'].map do |ci|
    {
      'confinementBeginDate' => ci['from'],
      'confinementEndDate' => ci['to']
    }
  end
end

#translate_disabilitiesObject (private)

Disabilities



542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 542

def translate_disabilities
  rated_disabilities = input_form['ratedDisabilities'].deep_dup.presence || []

  # New primary disabilities need to be added first before handling secondary
  # disabilities because a new secondary disability can be added to a new
  # primary disability
  primary_disabilities = translate_new_primary_disabilities(rated_disabilities)

  # NOTE: currently (4/29/24), the submit transformer in vets-website removes
  # the structured relationship between a secondary disability and its primary.
  # These always come in with cause="NEW", and their relationship reduced to
  # having "Secondary to..." in the primaryDescription. Consequentially, the
  # call to translate_new_secondary_disabilities() is always short-circuited
  disabilities = translate_new_secondary_disabilities(primary_disabilities)

  # Strip out disabilities with ActionType eq to `None` that do not have any
  # secondary disabilities to avoid sending extraneous data
  disabilities.delete_if do |disability|
    disability['disabilityActionType'] == 'NONE' && disability['secondaryDisabilities'].blank?
  end

  { 'disabilities' => disabilities }
end

#translate_homelessnessObject (private)



459
460
461
462
463
464
465
466
467
468
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 459

def translate_homelessness
  case input_form['homelessOrAtRisk']
  when 'no' || nil
    nil
  when 'homeless'
    homeless
  when 'atRisk'
    at_risk
  end
end

#translate_mailing_address(address) ⇒ Object (private)



388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 388

def translate_mailing_address(address)
  pciu_address = {
    'country' => address['country'],
    'addressLine1' => address['addressLine1'],
    'addressLine2' => address['addressLine2'],
    'addressLine3' => address['addressLine3'],
    'beginningDate' => address.dig('effectiveDate', 'from'),
    'endingDate' => address.dig('effectiveDate', 'to')
  }

  pciu_address['type'] = get_address_type(address)

  zip_code = split_zip_code(address['zipCode']) if address['zipCode']

  case pciu_address['type']
  when 'DOMESTIC'
    pciu_address.merge!(set_domestic_address(address, zip_code))
  when 'MILITARY'
    pciu_address.merge!(set_military_address(address, zip_code))
  when 'INTERNATIONAL'
    pciu_address.merge!(set_international_address(address))
  end

  pciu_address.compact
end

#translate_namesObject (private)

Personal info



337
338
339
340
341
342
343
344
345
346
347
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 337

def translate_names
  return nil if input_form['alternateNames'].blank?

  input_form['alternateNames'].map do |an|
    {
      'firstName' => an['first'],
      'middleName' => an['middle'],
      'lastName' => an['last']
    }.compact
  end.uniq
end

#translate_national_guard_serviceObject (private)



319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 319

def translate_national_guard_service
  return nil if service_info['reservesNationalGuardService'].blank?

  reserves_service_info = service_info['reservesNationalGuardService']
  {
    'title10Activation' => reserves_service_info['title10Activation'],
    'obligationTermOfServiceFromDate' => reserves_service_info['obligationTermOfServiceDateRange']['from'],
    'obligationTermOfServiceToDate' => reserves_service_info['obligationTermOfServiceDateRange']['to'],
    'unitName' => reserves_service_info['unitName'],
    'unitPhone' => split_phone_number(reserves_service_info['unitPhone']),
    'receivingInactiveDutyTrainingPay' => input_form['hasTrainingPay']
  }.compact
end

#translate_new_primary_disabilities(disabilities) ⇒ Object (private)



566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 566

def translate_new_primary_disabilities(disabilities)
  return disabilities if input_form['newPrimaryDisabilities'].blank?

  input_form['newPrimaryDisabilities'].each do |input_disability|
    # Disabilities that do not exist in the mapped list (disabilities without
    # a classification code) need to be scrubbed of characters not allowed by
    # EVSS's validation.
    if input_disability['classificationCode'].blank?
      input_disability['condition'] = scrub_disability_condition(input_disability['condition'])
    end
    append_input_disability = map_disability(input_disability)

    next if append_input_disability.blank?

    if Flipper.enabled?(:disability_526_toxic_exposure, @user)
      append_input_disability['cause'] = input_disability['cause']
    end
    disabilities.append(append_input_disability)
  end

  disabilities
end

#translate_new_secondary_disabilities(disabilities) ⇒ Object (private)



606
607
608
609
610
611
612
613
614
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 606

def translate_new_secondary_disabilities(disabilities)
  return disabilities if input_form['newSecondaryDisabilities'].blank?

  input_form['newSecondaryDisabilities'].each do |input_disability|
    disabilities = map_secondary(input_disability, disabilities)
  end

  disabilities
end

#translate_service_infoObject (private)

Service info



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 277

def translate_service_info
  service_info = {
    'serviceInformation' => {
      'servicePeriods' => translate_service_periods,
      'confinements' => translate_confinements,
      'reservesNationalGuardService' => translate_national_guard_service,
      'alternateNames' => translate_names
    }.compact
  }

  if days_until_release.positive?
    service_info['serviceInformation']['separationLocationName'] = input_form.dig('serviceInformation',
                                                                                  'separationLocation',
                                                                                  'separationLocationName')
    service_info['serviceInformation']['separationLocationCode'] = input_form.dig('serviceInformation',
                                                                                  'separationLocation',
                                                                                  'separationLocationCode')
  end
  service_info
end

#translate_service_payObject (private)

Service pay



233
234
235
236
237
238
239
240
241
242
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 233

def translate_service_pay
  service_pay = {
    'waiveVABenefitsToRetainTrainingPay' => input_form['waiveTrainingPay'],
    'waiveVABenefitsToRetainRetiredPay' => input_form['waiveRetirementPay'],
    'militaryRetiredPay' => military_retired_pay,
    'separationPay' => separation_pay
  }.compact

  service_pay.present? ? { 'servicePay' => service_pay } : {}
end

#translate_service_periodsObject (private)



298
299
300
301
302
303
304
305
306
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 298

def translate_service_periods
  service_info['servicePeriods'].map do |si|
    {
      'serviceBranch' => service_branch(si['serviceBranch']),
      'activeDutyBeginDate' => si['dateRange']['from'],
      'activeDutyEndDate' => si['dateRange']['to']
    }
  end
end

#translate_treatmentsObject (private)

Treatments



503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 503

def translate_treatments
  return {} if input_form['vaTreatmentFacilities'].blank?

  # treatmentCenterName clean up is an approximation of evss regex
  # validation ([a-zA-Z0-9"\/&\(\)\-'.#]([a-zA-Z0-9(\)\-'.# ])?)+$
  treatments = input_form['vaTreatmentFacilities'].map do |treatment|
    {
      'startDate' => approximate_date(treatment.dig('treatmentDateRange', 'from')),
      'treatedDisabilityNames' => treatment['treatedDisabilityNames'],
      'center' => {
        'name' => treatment['treatmentCenterName'].gsub(/[^a-zA-Z0-9 .()#&'"-]+/, '').gsub(/\s\s+/, ' ').strip
      }.merge(treatment['treatmentCenterAddress'])
    }.compact
  end

  { 'treatments' => treatments }
end

#translate_veteranObject (private)

Veteran info



367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 367

def translate_veteran
  {
    'veteran' => {
      'emailAddress' => input_form.dig('phoneAndEmail', 'emailAddress'),
      'currentMailingAddress' => translate_mailing_address(input_form['mailingAddress']),
      'changeOfAddress' => translate_change_of_address(input_form['forwardingAddress']),
      'daytimePhone' => split_phone_number(input_form.dig('phoneAndEmail', 'primaryPhone')),
      'homelessness' => translate_homelessness,
      'currentlyVAEmployee' => input_form['isVaEmployee']
    }.compact
  }
end

#user_supplied_rad_dateObject (private)

Benefits Delivery at Discharge (BDD)



721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 721

def user_supplied_rad_date
  # Retrieve the most recent Release from Active Duty (RAD) date from user supplied service periods
  # Exclude Reserve and Guard unless activated on federal orders
  recent_service_periods_end_dates = translate_service_periods.collect do |episode|
    unless episode['serviceBranch'].include?('Reserve') || episode['serviceBranch'].include?('National Guard')
      episode['activeDutyEndDate']
    end
  end
  recent_service_periods_end_dates << service_info.dig('reservesNationalGuardService', 'title10Activation',
                                                       'anticipatedSeparationDate')
  recent_service_periods_end_dates.compact!
  return nil if recent_service_periods_end_dates.blank?

  recent_service_periods_end_dates.max.in_time_zone(EVSS_TZ).to_date
end

#veteran_attached_files_text(attachments, current_overflow_length) ⇒ Object (private)



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/evss/disability_compensation_form/data_translation_all_claim.rb', line 117

def veteran_attached_files_text(attachments, current_overflow_length)
  attached_files_note = "The veteran uploaded #{attachments.count} documents along with this claim. " \
                        "Please verify in VBMS eFolder.\n"
  filenames_list = list_attachment_filenames(attachments)

  # Display above note only if listing all file names would make notes exceed EVSS overflowText limits
  if (current_overflow_length + attached_files_note.length + filenames_list.length) < OVERFLOW_TEXT_THRESHOLD
    attached_files_note += filenames_list

    StatsD.increment("#{VETERAN_FILE_LIST_STATSD_PREFIX}.included_in_overflow_text")

    Rails.logger.info(
      'Form526 Veteran-attached file names included in overflowText',
      { file_count: attachments.count, user_uuid: @user.uuid, timestamp: Time.now.utc }
    )
  else
    StatsD.increment("#{VETERAN_FILE_LIST_STATSD_PREFIX}.excluded_from_overflow_text")

    Rails.logger.info(
      'Form526 Veteran-attached file names truncated from overflowText',
      { file_count: attachments.count, user_uuid: @user.uuid, timestamp: Time.now.utc }
    )
  end

  attached_files_note
end