Module: HCA::EnrollmentSystem

Defined in:
lib/hca/enrollment_system.rb

Overview

rubocop:disable Metrics/ModuleLength

Constant Summary collapse

RACE_CODES =
{
  'isAmericanIndianOrAlaskanNative' => '1002-5',
  'isAsian' => '2028-9',
  'isBlackOrAfricanAmerican' => '2054-5',
  'isNativeHawaiianOrOtherPacificIslander' => '2076-8',
  'isWhite' => '2106-3'
}.freeze
NO_RACE =
'0000-0'
SIGI_CODES =
{
  'M' => 'M',
  'F' => 'F',
  'TF' => 'TF',
  'TM' => 'TM',
  'O' => 'O',
  'NA' => 'N',
  'NB' => 'B'
}.freeze
SERVICE_BRANCH_CODES =
{
  'army' => 1,
  'air force' => 2,
  'navy' => 3,
  'marine corps' => 4,
  'coast guard' => 5,
  'merchant seaman' => 7,
  'noaa' => 10,
  'space force' => 15,
  'usphs' => 9,
  'f.commonwealth' => 11,
  'f.guerilla' => 12,
  'f.scouts new' => 13,
  'f.scouts old' => 14
}.freeze
DISCHARGE_CODES =
{
  'honorable' => 1,
  'general' => 3,
  'bad-conduct' => 6,
  'dishonorable' => 2,
  'undesirable' => 5
}.freeze
RELATIONSHIP_CODES =
{
  'Primary Next of Kin' => 1,
  'Other Next of Kin' => 2,
  'Emergency Contact' => 3,
  'Other emergency contact' => 4,
  'Designee' => 5,
  'Beneficiary Representative' => 6,
  'Power of Attorney' => 7,
  'Guardian VA' => 8,
  'Guardian Civil' => 9,
  'Spouse' => 10,
  'Dependent' => 11
}.freeze
DEPENDENT_RELATIONSHIP_CODES =
{
  'Spouse' => 2,
  'Son' => 3,
  'Daughter' => 4,
  'Stepson' => 5,
  'Stepdaughter' => 6,
  'Father' => 17,
  'Mother' => 18,
  'Other' => 99
}.freeze

Class Method Summary collapse

Class Method Details

.add_attachment(file, is_dd214) ⇒ Object



801
802
803
804
805
806
807
808
809
810
# File 'lib/hca/enrollment_system.rb', line 801

def add_attachment(file, is_dd214)
  {
    'va:document' => {
      'va:name' => 'Attachment',
      'va:format' => get_va_format(file.content_type),
      'va:type' => is_dd214 ? '1' : '5',
      'va:content' => Base64.encode64(file.read)
    }
  }
end

.address_from_veteran(veteran) ⇒ Object



632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/hca/enrollment_system.rb', line 632

def address_from_veteran(veteran)
  veteran_address = veteran['veteranAddress']
  home_address    = veteran['veteranHomeAddress']
  address         = if home_address
                      [
                        format_address(veteran_address, type: 'P'),
                        format_address(home_address, type: 'R')
                      ]
                    else
                      format_address(veteran_address, type: 'P')
                    end

  { 'address' => address }
end

.build_form_for_user(user_identifier, form_id) ⇒ Object



751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
# File 'lib/hca/enrollment_system.rb', line 751

def build_form_for_user(user_identifier, form_id)
  form = form_template(form_id).deep_dup

  (user_id, id_type) = get_user_variables(user_identifier)
  return form if user_id.nil?

  authentication_level = form['va:identity']['va:authenticationLevel']
  authentication_level['va:type'] = '102'
  authentication_level['va:value'] = 'Assurance Level 2'

  form['va:identity']['va:veteranIdentifier'] = {
    'va:type' => id_type,
    'va:value' => user_id.to_s
  }
  form
end

.convert_birth_state(birth_state) ⇒ Object



449
450
451
452
453
454
455
# File 'lib/hca/enrollment_system.rb', line 449

def convert_birth_state(birth_state)
  if birth_state == 'Other'
    'FG'
  else
    birth_state
  end
end

.convert_full_name(full_name) ⇒ Object



389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/hca/enrollment_system.rb', line 389

def convert_full_name(full_name)
  return {} if full_name.blank?

  {
    'firstName' => Validations.validate_name(
      data: full_name['first'],
      count: 30
    ),
    'middleName' => Validations.validate_name(
      data: full_name['middle'],
      count: 30,
      nullable: true
    ),
    'lastName' => Validations.validate_name(
      data: full_name['last'],
      count: 30
    ),
    'suffix' => Validations.validate_name(
      data: full_name['suffix']
    )
  }
end

.convert_full_name_alt(full_name) ⇒ Object



412
413
414
415
416
417
418
419
# File 'lib/hca/enrollment_system.rb', line 412

def convert_full_name_alt(full_name)
  {
    'givenName' => Validations.validate_name(data: full_name['first']),
    'middleName' => Validations.validate_name(data: full_name['middle']),
    'familyName' => Validations.validate_name(data: full_name['last']),
    'suffix' => Validations.validate_name(data: full_name['suffix'])
  }
end

.convert_hash_values!(hash) ⇒ Object



729
730
731
732
733
734
# File 'lib/hca/enrollment_system.rb', line 729

def convert_hash_values!(hash)
  hash.each do |k, v|
    hash[k] = convert_value!(v)
  end
  hash.delete_if { |_k, v| v.blank? }
end

.convert_sigi(sigi_genders) ⇒ Object



421
422
423
424
425
426
427
# File 'lib/hca/enrollment_system.rb', line 421

def convert_sigi(sigi_genders)
  return {} if sigi_genders.blank?

  {
    'selfIdentifiedGenderIdentity' => SIGI_CODES[sigi_genders]
  }
end

.convert_value!(value) ⇒ Object



714
715
716
717
718
719
720
721
722
723
724
725
726
727
# File 'lib/hca/enrollment_system.rb', line 714

def convert_value!(value)
  if value.is_a?(Hash)
    convert_hash_values!(value)
  elsif value.is_a?(Array)
    result = value.map do |item|
      convert_value!(item)
    end
    result.delete_if(&:blank?)
  elsif value.in?([true, false]) || value.is_a?(Numeric)
    value.to_s
  else
    value
  end
end

.copy_spouse_address!(veteran) ⇒ Object



768
769
770
771
# File 'lib/hca/enrollment_system.rb', line 768

def copy_spouse_address!(veteran)
  veteran['spouseAddress'] = veteran['veteranAddress'] if veteran['spouseAddress'].blank?
  veteran
end

.demographic_no?(veteran) ⇒ Boolean

Returns:

  • (Boolean)


203
204
205
# File 'lib/hca/enrollment_system.rb', line 203

def demographic_no?(veteran)
  veteran['hasDemographicNoAnswer'] == true
end

.dependent_financials_info(dependent) ⇒ Object



326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/hca/enrollment_system.rb', line 326

def dependent_financials_info(dependent)
  incomes = resource_to_income_collection(dependent)

  {
    'incomes' => incomes,
    'expenses' => resource_to_expense_collection(dependent, income_collection_total(incomes)),
    'dependentInfo' => dependent_info(dependent),
    'livedWithPatient' => dependent['cohabitedLastYear'].present?,
    'incapableOfSelfSupport' => dependent['disabledBefore18'].present?,
    'attendedSchool' => dependent['attendedSchoolLastYear'].present?,
    'contributedToSupport' => dependent['receivedSupportLastYear'].present?
  }
end

.dependent_info(dependent) ⇒ Object



315
316
317
318
319
320
321
322
323
324
# File 'lib/hca/enrollment_system.rb', line 315

def dependent_info(dependent)
  {
    'dob' => Validations.date_of_birth(dependent['dateOfBirth']),
    'relationship' => dependent_relationship_to_sds_code(dependent['dependentRelation']),
    'ssns' => {
      'ssn' => ssn_to_ssntext(dependent['socialSecurityNumber'])
    },
    'startDate' => Validations.date_of_birth(dependent['becameDependent'])
  }.merge(convert_full_name_alt(dependent['fullName']))
end

.dependent_relationship_to_sds_code(dependent_relationship) ⇒ Object

rubocop:enable Metrics/MethodLength



311
312
313
# File 'lib/hca/enrollment_system.rb', line 311

def dependent_relationship_to_sds_code(dependent_relationship)
  DEPENDENT_RELATIONSHIP_CODES[dependent_relationship]
end

.dependent_to_association(dependent) ⇒ Object



580
581
582
583
584
585
# File 'lib/hca/enrollment_system.rb', line 580

def dependent_to_association(dependent)
  {
    'contactType' => relationship_to_contact_type('Dependent'),
    'relationship' => dependent['dependentRelation']
  }.merge(convert_full_name_alt(dependent['fullName']))
end

.discharge_type(veteran) ⇒ Object



465
466
467
468
469
470
471
472
473
# File 'lib/hca/enrollment_system.rb', line 465

def discharge_type(veteran)
  discharge_date = Validations.parse_date(veteran['lastDischargeDate'])

  if discharge_date.present? && (discharge_date > Time.zone.now.in_time_zone('Central Time (US & Canada)').to_date)
    return ''
  end

  discharge_type_to_sds_code(veteran['dischargeType'])
end

.discharge_type_to_sds_code(discharge_type) ⇒ Object



461
462
463
# File 'lib/hca/enrollment_system.rb', line 461

def discharge_type_to_sds_code(discharge_type)
  DISCHARGE_CODES[discharge_type] || 4
end

.email_from_veteran(veteran) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/hca/enrollment_system.rb', line 189

def email_from_veteran(veteran)
  email = veteran['email']
  return if email.blank?

  [
    {
      'email' => {
        'address' => email,
        'type' => '1'
      }
    }
  ]
end

.financial_flag?(veteran) ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/hca/enrollment_system.rb', line 104

def financial_flag?(veteran)
  veteran['understandsFinancialDisclosure'] || veteran['discloseFinancialInformation']
end

.form_template(form_id) ⇒ Object

Depending on the type of submission, EZ or EZR, we need to set specific form identifiers Per Enrollment System staff (12/21/23)

Parameters:

  • form_id (String)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/hca/enrollment_system.rb', line 82

def form_template(form_id)
  is_ezr_submission = form_id == '10-10EZR'

  IceNine.deep_freeze(
    'va:form' => {
      '@xmlns:va' => 'http://va.gov/schema/esr/voa/v1',
      'va:formIdentifier' => {
        'va:type' => is_ezr_submission ? '101' : '100',
        'va:value' => is_ezr_submission ? '1010EZR' : '1010EZ',
        'va:version' => 2_986_360_436
      }
    },
    'va:identity' => {
      '@xmlns:va' => 'http://va.gov/schema/esr/voa/v1',
      'va:authenticationLevel' => {
        'va:type' => '100',
        'va:value' => 'anonymous'
      }
    }
  )
end

.format_address(address, type: nil) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/hca/enrollment_system.rb', line 108

def format_address(address, type: nil)
  return {} if address.blank?

  formatted = address.slice('city', 'country')
  formatted['line1'] = address['street']

  (2..3).each do |i|
    formatted["line#{i}"] = address["street#{i}"] if address["street#{i}"].present?
  end

  if address['country'] == 'USA'
    formatted['state'] = address['state']
    formatted.merge!(format_zipcode(address['postalCode']))
  else
    formatted['provinceCode'] = address['state'] || address['provinceCode']
    formatted['postalCode'] = address['postalCode']
  end

  formatted['addressTypeCode'] = type if type
  formatted
end

.format_zipcode(postal_code) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/hca/enrollment_system.rb', line 130

def format_zipcode(postal_code)
  return {} if postal_code.blank?

  numeric_zip = postal_code.gsub(/\D/, '')
  zip_plus_4 = numeric_zip[5..8]
  zip_plus_4 = nil if !zip_plus_4.nil? && zip_plus_4.size != 4

  {
    'zipCode' => numeric_zip[0..4],
    'zipPlus4' => zip_plus_4
  }
end

.get_user_variables(user_identifier) ⇒ Object



736
737
738
739
740
741
742
743
744
745
746
747
748
749
# File 'lib/hca/enrollment_system.rb', line 736

def get_user_variables(user_identifier)
  return [nil, nil] if user_identifier.blank?

  icn = user_identifier['icn']
  edipi = user_identifier['edipi']

  if icn
    [icn, 1]
  elsif edipi
    [edipi, 2]
  else
    [nil, nil]
  end
end

.get_va_format(content_type) ⇒ Object



786
787
788
789
790
791
792
793
794
795
796
797
798
799
# File 'lib/hca/enrollment_system.rb', line 786

def get_va_format(content_type)
  # ES only accepts these strings for 'va:format': PDF,WORD,JPG,RTF
  extension = MIME::Types[content_type].first.extensions.first

  if extension.include?('doc')
    'WORD'
  elsif extension == 'jpeg'
    'JPG'
  elsif extension == 'rtf'
    'RTF'
  else
    'PDF'
  end
end

.income_collection_total(income_collection) ⇒ Object



238
239
240
241
242
243
244
# File 'lib/hca/enrollment_system.rb', line 238

def income_collection_total(income_collection)
  return 0 if income_collection.blank?

  income_collection['income'].reduce(BigDecimal(0)) do |sum, collection|
    sum + BigDecimal(collection['amount'].to_s)
  end
end

.marital_status_to_sds_code(marital_status) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/hca/enrollment_system.rb', line 143

def marital_status_to_sds_code(marital_status)
  case marital_status
  when 'Married'
    'M'
  when 'Never Married'
    'S'
  when 'Separated'
    'A'
  when 'Widowed'
    'W'
  when 'Divorced'
    'D'
  else
    'U'
  end
end

.phone_number_from_veteran(veteran) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/hca/enrollment_system.rb', line 171

def phone_number_from_veteran(veteran)
  return if veteran['homePhone'].blank? && veteran['mobilePhone'].blank?

  phone = []
  %w[homePhone mobilePhone].each do |type|
    number = veteran[type]

    if number.present?
      phone << {
        'phoneNumber' => number,
        'type' => (type == 'homePhone' ? '1' : '4')
      }
    end
  end

  { 'phone' => phone }
end

.prepend_namespace(data) ⇒ Object



701
702
703
704
705
706
707
708
709
710
711
712
# File 'lib/hca/enrollment_system.rb', line 701

def prepend_namespace(data)
  case data
  when Hash
    data.each_with_object({}) do |(k, v), memo|
      memo["eeSummary:#{k}"] = prepend_namespace(v)
    end
  when Array
    data.map { |i| prepend_namespace(i) }
  else
    data
  end
end

.provider_to_insurance_info(provider) ⇒ Object



373
374
375
376
377
378
379
380
381
# File 'lib/hca/enrollment_system.rb', line 373

def provider_to_insurance_info(provider)
  {
    'companyName' => provider['insuranceName'],
    'policyHolderName' => provider['insurancePolicyHolderName'],
    'policyNumber' => provider['insurancePolicyNumber'],
    'groupNumber' => provider['insuranceGroupCode'],
    'insuranceMappingTypeName' => 'PI'
  }
end

.relationship_to_contact_type(relationship) ⇒ Object

rubocop:enable Metrics/MethodLength



576
577
578
# File 'lib/hca/enrollment_system.rb', line 576

def relationship_to_contact_type(relationship)
  RELATIONSHIP_CODES[relationship]
end

.remove_ctrl_chars!(value) ⇒ Object



773
774
775
776
777
778
779
780
781
782
783
784
# File 'lib/hca/enrollment_system.rb', line 773

def remove_ctrl_chars!(value)
  case value
  when Hash
    value.each do |k, v|
      value[k] = remove_ctrl_chars!(v)
    end
  when Array
    value.map! { |i| remove_ctrl_chars!(i) }
  when String
    value.tr("\u0000-\u001f\u007f\u2028", '')
  end
end

.resource_to_expense_collection(resource, income_total) ⇒ Object

rubocop:disable Metrics/MethodLength



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/hca/enrollment_system.rb', line 272

def resource_to_expense_collection(resource, income_total)
  expense_collection = []
  expense_total = BigDecimal(0)

  [
    %w[educationExpense 3],
    %w[dependentEducationExpenses 16],
    %w[funeralExpense 19],
    %w[medicalExpense 18]
  ].each do |expense_type|
    expense = resource[expense_type[0]]

    if expense.present?
      new_expense_total = expense_total + BigDecimal(expense.to_s)
      expenses_exceeded = new_expense_total > income_total

      if expenses_exceeded
        expense = (income_total - expense_total).to_f
      else
        expense_total = new_expense_total
      end

      expense_collection << {
        'amount' => expense,
        'expenseType' => expense_type[1]
      }

      break if expenses_exceeded
    end
  end

  return if expense_collection.size.zero?

  {
    'expense' => expense_collection
  }
end

.resource_to_income_collection(resource) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/hca/enrollment_system.rb', line 246

def resource_to_income_collection(resource)
  income_collection = []

  [
    ['grossIncome', 7],
    ['netIncome', 13],
    ['otherIncome', 10]
  ].each do |income_type|
    income = resource[income_type[0]]

    if income.present?
      income_collection << {
        'amount' => income,
        'type' => income_type[1]
      }
    end
  end

  return if income_collection.size.zero?

  {
    'income' => income_collection
  }
end

.service_branch_to_sds_code(service_branch) ⇒ Object



457
458
459
# File 'lib/hca/enrollment_system.rb', line 457

def service_branch_to_sds_code(service_branch)
  SERVICE_BRANCH_CODES[service_branch] || 6
end

.spanish_hispanic_to_sds_code(is_spanish_hispanic_latino) ⇒ Object



160
161
162
163
164
165
166
167
168
169
# File 'lib/hca/enrollment_system.rb', line 160

def spanish_hispanic_to_sds_code(is_spanish_hispanic_latino)
  case is_spanish_hispanic_latino
  when true
    '2135-2'
  when false
    '2186-5'
  else
    '0000-0'
  end
end

.spouse?(veteran) ⇒ Boolean

Returns:

  • (Boolean)


350
351
352
# File 'lib/hca/enrollment_system.rb', line 350

def spouse?(veteran)
  %w[Married Separated].include?(veteran['maritalStatus'])
end

.spouse_to_association(veteran) ⇒ Object



587
588
589
590
591
592
593
594
595
# File 'lib/hca/enrollment_system.rb', line 587

def spouse_to_association(veteran)
  if spouse?(veteran) && financial_flag?(veteran)
    {
      'address' => format_address(veteran['spouseAddress']),
      'contactType' => relationship_to_contact_type('Spouse'),
      'relationship' => 'SPOUSE'
    }.merge(convert_full_name_alt(veteran['spouseFullName']))
  end
end

.ssn_to_ssntext(ssn) ⇒ Object



383
384
385
386
387
# File 'lib/hca/enrollment_system.rb', line 383

def ssn_to_ssntext(ssn)
  {
    'ssnText' => Validations.validate_ssn(ssn)
  }
end

.veteran_contacts_to_association(contact) ⇒ Object



597
598
599
600
601
602
603
604
605
# File 'lib/hca/enrollment_system.rb', line 597

def veteran_contacts_to_association(contact)
  {
    'contactType' => relationship_to_contact_type(contact['contactType']),
    'relationship' => contact['relationship'],
    'address' => format_address(contact['address']),
    'primaryPhone' => contact['primaryPhone'],
    'alternatePhone' => contact['alternatePhone']
  }.merge(convert_full_name_alt(contact['fullName']))
end

.veteran_to_association_collection(veteran) ⇒ Object



607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
# File 'lib/hca/enrollment_system.rb', line 607

def veteran_to_association_collection(veteran)
  associations = []

  dependents_list = veteran['dependents'] || []

  dependents = dependents_list.map do |dependent|
    dependent_to_association(dependent)
  end.compact

  spouse = spouse_to_association(veteran)

  # Next of kin and emergency contacts
  contacts_list = veteran['veteranContacts'] || []
  contacts = contacts_list.map do |contact|
    veteran_contacts_to_association(contact)
  end.compact

  associations += dependents.concat(contacts)
  associations << spouse if spouse.present?

  return if associations.blank?

  { 'association' => associations }
end

.veteran_to_demographics_info(veteran) ⇒ Object



657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
# File 'lib/hca/enrollment_system.rb', line 657

def veteran_to_demographics_info(veteran)
  return_val = {
    'appointmentRequestResponse' => veteran['wantsInitialVaContact'].present?,
    'contactInfo' => {
      'addresses' => address_from_veteran(veteran),
      'emails' => email_from_veteran(veteran),
      'phones' => phone_number_from_veteran(veteran)
    },
    'ethnicity' => veteran_to_ethnicity(veteran),
    'maritalStatus' => marital_status_to_sds_code(veteran['maritalStatus']),
    'preferredFacility' => veteran['vaMedicalFacility'],
    'races' => veteran_to_races(veteran),
    'acaIndicator' => veteran['isEssentialAcaCoverage'].present?
  }

  return_val.delete('ethnicity') if return_val['ethnicity'].nil?

  return_val
end

.veteran_to_dependent_financials_collection(veteran) ⇒ Object



340
341
342
343
344
345
346
347
348
# File 'lib/hca/enrollment_system.rb', line 340

def veteran_to_dependent_financials_collection(veteran)
  dependents = veteran['dependents']

  if dependents.present?
    {
      'dependentFinancials' => dependents.map { |d| dependent_financials_info(d) }
    }
  end
end

.veteran_to_enrollment_determination_info(veteran) ⇒ Object



523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File 'lib/hca/enrollment_system.rb', line 523

def veteran_to_enrollment_determination_info(veteran)
  {
    'eligibleForMedicaid' => veteran['isMedicaidEligible'].present?,
    'noseThroatRadiumInfo' => {
      'receivingTreatment' => veteran['radiumTreatments'].present?
    },
    'serviceConnectionAward' => {
      'serviceConnectedIndicator' => veteran['vaCompensationType'] == 'highDisability'
    },
    'specialFactors' => {
      'agentOrangeInd' => veteran['vietnamService'].present?,
      'envContaminantsInd' => veteran['swAsiaCombat'].present?,
      'campLejeuneInd' => veteran['campLejeune'].present?,
      'radiationExposureInd' => veteran['exposedToRadiation'].present?
    }
  }
end

.veteran_to_ethnicity(veteran) ⇒ Object



647
648
649
650
651
652
653
654
655
# File 'lib/hca/enrollment_system.rb', line 647

def veteran_to_ethnicity(veteran)
  if veteran.key?('hasDemographicNoAnswer') || veteran.key?('isSpanishHispanicLatino')
    if demographic_no?(veteran)
      NO_RACE
    else
      spanish_hispanic_to_sds_code(veteran['isSpanishHispanicLatino'])
    end
  end
end

.veteran_to_financials_info(veteran) ⇒ Object

rubocop:disable Metrics/MethodLength



542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
# File 'lib/hca/enrollment_system.rb', line 542

def veteran_to_financials_info(veteran)
  if financial_flag?(veteran)
    incomes = resource_to_income_collection(
      'grossIncome' => veteran['veteranGrossIncome'],
      'netIncome' => veteran['veteranNetIncome'],
      'otherIncome' => veteran['veteranOtherIncome']
    )

    {
      'incomeTest' => { 'discloseFinancialInformation' => true },
      'financialStatement' => {
        'expenses' => resource_to_expense_collection(
          {
            'educationExpense' => veteran['deductibleEducationExpenses'],
            'funeralExpense' => veteran['deductibleFuneralExpenses'],
            'medicalExpense' => veteran['deductibleMedicalExpenses']
          },
          income_collection_total(incomes)
        ),
        'incomes' => incomes,
        'spouseFinancialsList' => veteran_to_spouse_financials(veteran),
        'marriedLastCalendarYear' => veteran['maritalStatus'] == 'Married',
        'dependentFinancialsList' => veteran_to_dependent_financials_collection(veteran),
        'numberOfDependentChildren' => veteran['dependents']&.size
      }
    }
  else
    {
      'incomeTest' => { 'discloseFinancialInformation' => false }
    }
  end
end

.veteran_to_insurance_collection(veteran) ⇒ Object



501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
# File 'lib/hca/enrollment_system.rb', line 501

def veteran_to_insurance_collection(veteran)
  insurance_collection = (veteran['providers'] || []).map do |provider|
    provider_to_insurance_info(provider)
  end

  if veteran['isEnrolledMedicarePartA']
    insurance_collection << {
      'companyName' => 'Medicare',
      'enrolledInPartA' => veteran['isEnrolledMedicarePartA'],
      'insuranceMappingTypeName' => 'MDCR',
      'policyNumber' => veteran['medicareClaimNumber'],
      'partAEffectiveDate' => Validations.date_of_birth(veteran['medicarePartAEffectiveDate'])
    }.compact
  end

  return if insurance_collection.blank?

  {
    'insurance' => insurance_collection
  }
end

.veteran_to_military_service_info(veteran) ⇒ Object



475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
# File 'lib/hca/enrollment_system.rb', line 475

def veteran_to_military_service_info(veteran)
  if veteran['lastDischargeDate'].present? && !Validations.valid_discharge_date?(veteran['lastDischargeDate'])
    raise Common::Exceptions::InvalidFieldValue.new('lastDischargeDate', veteran['lastDischargeDate'])
  end

  return_val = {
    'dischargeDueToDisability' => veteran['disabledInLineOfDuty'].present?,
    'militaryServiceSiteRecords' => { 'militaryServiceSiteRecord' => {} }
  }

  if veteran['lastServiceBranch'].present?
    return_val['militaryServiceSiteRecords']['militaryServiceSiteRecord']['militaryServiceEpisodes'] = {
      'militaryServiceEpisode' => {
        'dischargeType' => discharge_type(veteran),
        'startDate' => Validations.date_of_birth(veteran['lastEntryDate']),
        'endDate' => Validations.discharge_date(veteran['lastDischargeDate']),
        'serviceBranch' => service_branch_to_sds_code(veteran['lastServiceBranch'])
      }
    }
  end

  return_val['militaryServiceSiteRecords']['militaryServiceSiteRecord']['site'] = veteran['vaMedicalFacility']

  return_val
end

.veteran_to_person_info(veteran) ⇒ Object



429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# File 'lib/hca/enrollment_system.rb', line 429

def veteran_to_person_info(veteran)
  convert_full_name(veteran['veteranFullName']).merge({
    'gender' => veteran['gender'],
    'dob' => Validations.date_of_birth(veteran['veteranDateOfBirth']),
    'mothersMaidenName' => Validations.validate_string(
      data: veteran['mothersMaidenName'],
      count: 35,
      nullable: true
    ),
    'placeOfBirthCity' => Validations.validate_string(
      data: veteran['cityOfBirth'],
      count: 20,
      nullable: true
    ),
    'placeOfBirthState' => convert_birth_state(veteran['stateOfBirth'])
  }.merge(ssn_to_ssntext(veteran['veteranSocialSecurityNumber']))).merge(
    convert_sigi(veteran['sigiGenders'])
  )
end

.veteran_to_races(veteran) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/hca/enrollment_system.rb', line 207

def veteran_to_races(veteran)
  races = []

  if demographic_no?(veteran)
    races << NO_RACE
  else
    RACE_CODES.each do |race_key, code|
      races << code if veteran[race_key]
    end
  end

  return if races.size.zero?

  { 'race' => races }
end

.veteran_to_save_submit_form(veteran, current_user, form_id) ⇒ Object

Parameters:

  • veteran (Hash)

    data in JSON format

  • current_user (Account)
  • form_id (String)


815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
# File 'lib/hca/enrollment_system.rb', line 815

def veteran_to_save_submit_form(
  veteran,
  current_user,
  form_id
)
  return {} if veteran.blank?

  copy_spouse_address!(veteran)

  request = build_form_for_user(current_user, form_id)

  veteran['attachments']&.each do |attachment|
    hca_attachment = HCAAttachment.find_by(guid: attachment['confirmationCode'])
    request['va:form']['va:attachments'] ||= []
    request['va:form']['va:attachments'] << add_attachment(hca_attachment.get_file, attachment['dd214'])
  end

  request['va:form']['va:summary'] = veteran_to_summary(veteran)
  request['va:form']['va:applications'] = {
    'va:applicationInfo' => [{
      'va:appDate' => Time.now.in_time_zone('Central Time (US & Canada)').strftime('%Y-%m-%d'),
      'va:appMethod' => '1'
    }]
  }

  convert_hash_values!(request)
  remove_ctrl_chars!(request)
  request
end

.veteran_to_spouse_financials(veteran) ⇒ Object



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/hca/enrollment_system.rb', line 354

def veteran_to_spouse_financials(veteran)
  return if !spouse?(veteran) || !financial_flag?(veteran)

  spouse_income = resource_to_income_collection(
    'grossIncome' => veteran['spouseGrossIncome'],
    'netIncome' => veteran['spouseNetIncome'],
    'otherIncome' => veteran['spouseOtherIncome']
  )

  {
    'spouseFinancials' => {
      'incomes' => spouse_income,
      'spouse' => veteran_to_spouse_info(veteran),
      'contributedToSpousalSupport' => veteran['provideSupportLastYear'].present?,
      'livedWithPatient' => veteran['cohabitedLastYear'].present?
    }
  }
end

.veteran_to_spouse_info(veteran) ⇒ Object



223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/hca/enrollment_system.rb', line 223

def veteran_to_spouse_info(veteran)
  address = format_address(veteran['spouseAddress'])
  address['phoneNumber'] = veteran['spousePhone']

  {
    'dob' => Validations.date_of_birth(veteran['spouseDateOfBirth']),
    'relationship' => 2,
    'startDate' => Validations.date_of_birth(veteran['dateOfMarriage']),
    'ssns' => {
      'ssn' => ssn_to_ssntext(veteran['spouseSocialSecurityNumber'])
    },
    'address' => address
  }.merge(convert_full_name_alt(veteran['spouseFullName']))
end

.veteran_to_summary(veteran) ⇒ Object



677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
# File 'lib/hca/enrollment_system.rb', line 677

def veteran_to_summary(veteran)
  data = {
    'associations' => veteran_to_association_collection(veteran),
    'demographics' => veteran_to_demographics_info(veteran),
    'enrollmentDeterminationInfo' => veteran_to_enrollment_determination_info(veteran),
    'financialsInfo' => veteran_to_financials_info(veteran),
    'insuranceList' => veteran_to_insurance_collection(veteran),
    'militaryServiceInfo' => veteran_to_military_service_info(veteran),
    'prisonerOfWarInfo' => {
      'powIndicator' => veteran['isFormerPow'].present?
    },
    'purpleHeart' => {
      'indicator' => veteran['purpleHeartRecipient'].present?
    },
    'personInfo' => veteran_to_person_info(veteran)
  }
  data = prepend_namespace(data)
  # This *must* be a symbol. It's a special flag for the Goyuko library.
  data[:attributes!] = data.keys.index_with do |_attribute|
    { 'xmlns:eeSummary' => 'http://jaxws.webservices.esr.med.va.gov/schemas' }
  end
  data
end