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'
EXPOSURE_MAPPINGS =
{
  'exposureToAirPollutants' => 'Air Pollutants',
  'exposureToChemicals' => 'Chemicals',
  'exposureToContaminatedWater' => 'Contaminated Water at Camp Lejeune',
  'exposureToRadiation' => 'Radiation',
  'exposureToShad' => 'SHAD',
  'exposureToOccupationalHazards' => 'Occupational Hazards',
  'exposureToAsbestos' => 'Asbestos',
  'exposureToMustardGas' => 'Mustard Gas',
  'exposureToWarfareAgents' => 'Warfare Agents',
  'exposureToOther' => 'Other'
}.freeze
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

Instance Method Summary collapse

Class Method Details

.add_attachment(file, id, is_dd214) ⇒ Object



856
857
858
859
860
861
862
863
864
865
# File 'lib/hca/enrollment_system.rb', line 856

def add_attachment(file, id, is_dd214)
  {
    'va:document' => {
      'va:name' => "Attachment_#{id}",
      '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



687
688
689
690
691
692
693
694
695
696
697
698
699
700
# File 'lib/hca/enrollment_system.rb', line 687

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



806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
# File 'lib/hca/enrollment_system.rb', line 806

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



462
463
464
465
466
467
468
# File 'lib/hca/enrollment_system.rb', line 462

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

.convert_full_name(full_name) ⇒ Object



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/hca/enrollment_system.rb', line 402

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



425
426
427
428
429
430
431
432
# File 'lib/hca/enrollment_system.rb', line 425

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



784
785
786
787
788
789
# File 'lib/hca/enrollment_system.rb', line 784

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



434
435
436
437
438
439
440
# File 'lib/hca/enrollment_system.rb', line 434

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

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

.convert_value!(value) ⇒ Object



769
770
771
772
773
774
775
776
777
778
779
780
781
782
# File 'lib/hca/enrollment_system.rb', line 769

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



823
824
825
826
# File 'lib/hca/enrollment_system.rb', line 823

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

.demographic_no?(veteran) ⇒ Boolean

Returns:

  • (Boolean)


216
217
218
# File 'lib/hca/enrollment_system.rb', line 216

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

.dependent_financials_info(dependent) ⇒ Object



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

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



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

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



324
325
326
# File 'lib/hca/enrollment_system.rb', line 324

def dependent_relationship_to_sds_code(dependent_relationship)
  DEPENDENT_RELATIONSHIP_CODES[dependent_relationship]
end

.dependent_to_association(dependent) ⇒ Object



635
636
637
638
639
640
# File 'lib/hca/enrollment_system.rb', line 635

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



478
479
480
481
482
483
484
485
486
# File 'lib/hca/enrollment_system.rb', line 478

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



474
475
476
# File 'lib/hca/enrollment_system.rb', line 474

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

.email_from_veteran(veteran) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/hca/enrollment_system.rb', line 202

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

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

.financial_flag?(veteran) ⇒ Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/hca/enrollment_system.rb', line 117

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)


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/hca/enrollment_system.rb', line 95

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



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/hca/enrollment_system.rb', line 121

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



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

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



791
792
793
794
795
796
797
798
799
800
801
802
803
804
# File 'lib/hca/enrollment_system.rb', line 791

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



841
842
843
844
845
846
847
848
849
850
851
852
853
854
# File 'lib/hca/enrollment_system.rb', line 841

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



251
252
253
254
255
256
257
# File 'lib/hca/enrollment_system.rb', line 251

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



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/hca/enrollment_system.rb', line 156

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



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/hca/enrollment_system.rb', line 184

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



756
757
758
759
760
761
762
763
764
765
766
767
# File 'lib/hca/enrollment_system.rb', line 756

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



386
387
388
389
390
391
392
393
394
# File 'lib/hca/enrollment_system.rb', line 386

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



631
632
633
# File 'lib/hca/enrollment_system.rb', line 631

def relationship_to_contact_type(relationship)
  RELATIONSHIP_CODES[relationship]
end

.remove_ctrl_chars!(value) ⇒ Object



828
829
830
831
832
833
834
835
836
837
838
839
# File 'lib/hca/enrollment_system.rb', line 828

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



285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/hca/enrollment_system.rb', line 285

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



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/hca/enrollment_system.rb', line 259

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



470
471
472
# File 'lib/hca/enrollment_system.rb', line 470

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



173
174
175
176
177
178
179
180
181
182
# File 'lib/hca/enrollment_system.rb', line 173

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)


363
364
365
# File 'lib/hca/enrollment_system.rb', line 363

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

.spouse_to_association(veteran) ⇒ Object



642
643
644
645
646
647
648
649
650
# File 'lib/hca/enrollment_system.rb', line 642

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



396
397
398
399
400
# File 'lib/hca/enrollment_system.rb', line 396

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

.veteran_contacts_to_association(contact) ⇒ Object



652
653
654
655
656
657
658
659
660
# File 'lib/hca/enrollment_system.rb', line 652

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



662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# File 'lib/hca/enrollment_system.rb', line 662

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



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

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



353
354
355
356
357
358
359
360
361
# File 'lib/hca/enrollment_system.rb', line 353

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



536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/hca/enrollment_system.rb', line 536

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? || veteran['exposedToAgentOrange'].present?,
      'envContaminantsInd' => veteran['swAsiaCombat'].present?,
      'campLejeuneInd' => veteran['campLejeune'].present?,
      'radiationExposureInd' =>
        veteran['exposedToRadiation'].present? || veteran['radiationCleanupEfforts'].present?
    }.merge(veteran_to_tera(veteran))
  }
end

.veteran_to_ethnicity(veteran) ⇒ Object



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

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



597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
# File 'lib/hca/enrollment_system.rb', line 597

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



514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
# File 'lib/hca/enrollment_system.rb', line 514

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



488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
# File 'lib/hca/enrollment_system.rb', line 488

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



442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/hca/enrollment_system.rb', line 442

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



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

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)


870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
# File 'lib/hca/enrollment_system.rb', line 870

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_with_index do |attachment, i|
    guid = attachment['confirmationCode']
    form_attachment = HCAAttachment.find_by(guid:) || Form1010EzrAttachment.find_by(guid:)

    next if form_attachment.nil?

    request['va:form']['va:attachments'] ||= []
    request['va:form']['va:attachments'] << add_attachment(form_attachment.get_file, i + 1, 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



367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/hca/enrollment_system.rb', line 367

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



236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/hca/enrollment_system.rb', line 236

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



732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
# File 'lib/hca/enrollment_system.rb', line 732

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

.veteran_to_tera(veteran) ⇒ Object



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 555

def veteran_to_tera(veteran)
  return {} unless veteran['hasTeraResponse']

  {
    'supportOperationsInd' => veteran['combatOperationService'].present?
  }.merge(
    if veteran['gulfWarService'].present?
      {
        'gulfWarHazard' => {
          'gulfWarHazardInd' => veteran['gulfWarService'].present?,
          'fromDate' => Validations.parse_short_date(veteran['gulfWarStartDate']),
          'toDate' => Validations.parse_short_date(veteran['gulfWarEndDate'])
        }
      }
    else
      {}
    end
  ).merge(veteran_to_toxic_exposure(veteran))
end

.veteran_to_toxic_exposure(veteran) ⇒ Object



575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
# File 'lib/hca/enrollment_system.rb', line 575

def veteran_to_toxic_exposure(veteran)
  categories = []

  EXPOSURE_MAPPINGS.each do |k, v|
    categories << v if veteran[k].present?
  end

  return {} if categories.blank?

  {
    'toxicExposure' => {
      'exposureCategories' => {
        'exposureCategory' => categories
      },
      'otherText' => veteran['otherToxicExposure'],
      'fromDate' => Validations.parse_short_date(veteran['toxicExposureStartDate']),
      'toDate' => Validations.parse_short_date(veteran['toxicExposureEndDate'])
    }
  }
end

Instance Method Details

#add_attachment(file, id, is_dd214) ⇒ Object (private)



856
857
858
859
860
861
862
863
864
865
# File 'lib/hca/enrollment_system.rb', line 856

def add_attachment(file, id, is_dd214)
  {
    'va:document' => {
      'va:name' => "Attachment_#{id}",
      '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 (private)



687
688
689
690
691
692
693
694
695
696
697
698
699
700
# File 'lib/hca/enrollment_system.rb', line 687

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 (private)



806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
# File 'lib/hca/enrollment_system.rb', line 806

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 (private)



462
463
464
465
466
467
468
# File 'lib/hca/enrollment_system.rb', line 462

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

#convert_full_name(full_name) ⇒ Object (private)



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/hca/enrollment_system.rb', line 402

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 (private)



425
426
427
428
429
430
431
432
# File 'lib/hca/enrollment_system.rb', line 425

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 (private)



784
785
786
787
788
789
# File 'lib/hca/enrollment_system.rb', line 784

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 (private)



434
435
436
437
438
439
440
# File 'lib/hca/enrollment_system.rb', line 434

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

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

#convert_value!(value) ⇒ Object (private)



769
770
771
772
773
774
775
776
777
778
779
780
781
782
# File 'lib/hca/enrollment_system.rb', line 769

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 (private)



823
824
825
826
# File 'lib/hca/enrollment_system.rb', line 823

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

#demographic_no?(veteran) ⇒ Object (private)



216
217
218
# File 'lib/hca/enrollment_system.rb', line 216

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

#dependent_financials_info(dependent) ⇒ Object (private)



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

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 (private)



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

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 (private)

rubocop:enable Metrics/MethodLength



324
325
326
# File 'lib/hca/enrollment_system.rb', line 324

def dependent_relationship_to_sds_code(dependent_relationship)
  DEPENDENT_RELATIONSHIP_CODES[dependent_relationship]
end

#dependent_to_association(dependent) ⇒ Object (private)



635
636
637
638
639
640
# File 'lib/hca/enrollment_system.rb', line 635

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 (private)



478
479
480
481
482
483
484
485
486
# File 'lib/hca/enrollment_system.rb', line 478

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 (private)



474
475
476
# File 'lib/hca/enrollment_system.rb', line 474

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

#email_from_veteran(veteran) ⇒ Object (private)



202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/hca/enrollment_system.rb', line 202

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

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

#financial_flag?(veteran) ⇒ Object (private)



117
118
119
# File 'lib/hca/enrollment_system.rb', line 117

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

#form_template(form_id) ⇒ Object (private)

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)


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/hca/enrollment_system.rb', line 95

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 (private)



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/hca/enrollment_system.rb', line 121

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 (private)



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

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 (private)



791
792
793
794
795
796
797
798
799
800
801
802
803
804
# File 'lib/hca/enrollment_system.rb', line 791

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 (private)



841
842
843
844
845
846
847
848
849
850
851
852
853
854
# File 'lib/hca/enrollment_system.rb', line 841

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 (private)



251
252
253
254
255
256
257
# File 'lib/hca/enrollment_system.rb', line 251

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 (private)



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/hca/enrollment_system.rb', line 156

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 (private)



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/hca/enrollment_system.rb', line 184

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 (private)



756
757
758
759
760
761
762
763
764
765
766
767
# File 'lib/hca/enrollment_system.rb', line 756

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 (private)



386
387
388
389
390
391
392
393
394
# File 'lib/hca/enrollment_system.rb', line 386

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 (private)

rubocop:enable Metrics/MethodLength



631
632
633
# File 'lib/hca/enrollment_system.rb', line 631

def relationship_to_contact_type(relationship)
  RELATIONSHIP_CODES[relationship]
end

#remove_ctrl_chars!(value) ⇒ Object (private)



828
829
830
831
832
833
834
835
836
837
838
839
# File 'lib/hca/enrollment_system.rb', line 828

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 (private)

rubocop:disable Metrics/MethodLength



285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/hca/enrollment_system.rb', line 285

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 (private)



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/hca/enrollment_system.rb', line 259

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 (private)



470
471
472
# File 'lib/hca/enrollment_system.rb', line 470

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 (private)



173
174
175
176
177
178
179
180
181
182
# File 'lib/hca/enrollment_system.rb', line 173

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



363
364
365
# File 'lib/hca/enrollment_system.rb', line 363

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

#spouse_to_association(veteran) ⇒ Object (private)



642
643
644
645
646
647
648
649
650
# File 'lib/hca/enrollment_system.rb', line 642

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 (private)



396
397
398
399
400
# File 'lib/hca/enrollment_system.rb', line 396

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

#veteran_contacts_to_association(contact) ⇒ Object (private)



652
653
654
655
656
657
658
659
660
# File 'lib/hca/enrollment_system.rb', line 652

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 (private)



662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# File 'lib/hca/enrollment_system.rb', line 662

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 (private)



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

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 (private)



353
354
355
356
357
358
359
360
361
# File 'lib/hca/enrollment_system.rb', line 353

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 (private)



536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/hca/enrollment_system.rb', line 536

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? || veteran['exposedToAgentOrange'].present?,
      'envContaminantsInd' => veteran['swAsiaCombat'].present?,
      'campLejeuneInd' => veteran['campLejeune'].present?,
      'radiationExposureInd' =>
        veteran['exposedToRadiation'].present? || veteran['radiationCleanupEfforts'].present?
    }.merge(veteran_to_tera(veteran))
  }
end

#veteran_to_ethnicity(veteran) ⇒ Object (private)



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

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 (private)

rubocop:disable Metrics/MethodLength



597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
# File 'lib/hca/enrollment_system.rb', line 597

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 (private)



514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
# File 'lib/hca/enrollment_system.rb', line 514

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 (private)



488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
# File 'lib/hca/enrollment_system.rb', line 488

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 (private)



442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/hca/enrollment_system.rb', line 442

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 (private)



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

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 (private)

Parameters:

  • veteran (Hash)

    data in JSON format

  • current_user (Account)
  • form_id (String)


870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
# File 'lib/hca/enrollment_system.rb', line 870

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_with_index do |attachment, i|
    guid = attachment['confirmationCode']
    form_attachment = HCAAttachment.find_by(guid:) || Form1010EzrAttachment.find_by(guid:)

    next if form_attachment.nil?

    request['va:form']['va:attachments'] ||= []
    request['va:form']['va:attachments'] << add_attachment(form_attachment.get_file, i + 1, 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 (private)



367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/hca/enrollment_system.rb', line 367

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 (private)



236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/hca/enrollment_system.rb', line 236

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 (private)



732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
# File 'lib/hca/enrollment_system.rb', line 732

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

#veteran_to_tera(veteran) ⇒ Object (private)



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 555

def veteran_to_tera(veteran)
  return {} unless veteran['hasTeraResponse']

  {
    'supportOperationsInd' => veteran['combatOperationService'].present?
  }.merge(
    if veteran['gulfWarService'].present?
      {
        'gulfWarHazard' => {
          'gulfWarHazardInd' => veteran['gulfWarService'].present?,
          'fromDate' => Validations.parse_short_date(veteran['gulfWarStartDate']),
          'toDate' => Validations.parse_short_date(veteran['gulfWarEndDate'])
        }
      }
    else
      {}
    end
  ).merge(veteran_to_toxic_exposure(veteran))
end

#veteran_to_toxic_exposure(veteran) ⇒ Object (private)



575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
# File 'lib/hca/enrollment_system.rb', line 575

def veteran_to_toxic_exposure(veteran)
  categories = []

  EXPOSURE_MAPPINGS.each do |k, v|
    categories << v if veteran[k].present?
  end

  return {} if categories.blank?

  {
    'toxicExposure' => {
      'exposureCategories' => {
        'exposureCategory' => categories
      },
      'otherText' => veteran['otherToxicExposure'],
      'fromDate' => Validations.parse_short_date(veteran['toxicExposureStartDate']),
      'toDate' => Validations.parse_short_date(veteran['toxicExposureEndDate'])
    }
  }
end