Class: RES::Ch31Form

Inherits:
Service show all
Includes:
SentryLogging
Defined in:
lib/res/ch31_form.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.res'

Instance Method Summary collapse

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Methods inherited from Service

#end_point, #request_headers, #send_to_res

Methods included from Common::Client::Concerns::Monitoring

#increment, #increment_failure, #increment_total, #with_monitoring

Methods inherited from Common::Client::Base

#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name

Constructor Details

#initialize(user:, claim:) ⇒ Ch31Form

Returns a new instance of Ch31Form.



13
14
15
16
17
# File 'lib/res/ch31_form.rb', line 13

def initialize(user:, claim:)
  super()
  @user = user
  @claim = claim
end

Instance Method Details

#adjusted_veteran_informationObject (private)



91
92
93
94
95
96
97
98
99
# File 'lib/res/ch31_form.rb', line 91

def adjusted_veteran_information
  vet_info = claim_form_hash['veteranInformation']

  vet_info['VAFileNumber'] = vet_info.delete('vaFileNumber') if vet_info.key?('vaFileNumber')
  vet_info['regionalOffice'] = vet_info['regionalOfficeName']
  vet_info.delete(:regionalOfficeName)

  vet_info
end

#claim_form_hashObject (private)



87
88
89
# File 'lib/res/ch31_form.rb', line 87

def claim_form_hash
  @claim.parsed_form
end

#format_payload_for_resObject (private)



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/res/ch31_form.rb', line 43

def format_payload_for_res
  form_data = claim_form_hash

  res_payload = {
    useEva: form_data['useEva'],
    receiveElectronicCommunication: form_data['receiveElectronicCommunication'],
    useTelecounseling: form_data['useTelecounseling'],
    appointmentTimePreferences: form_data['appointmentTimePreferences'],
    yearsOfEducation: form_data['yearsOfEducation'],
    isMoving: form_data['isMoving'],
    mainPhone: form_data['mainPhone'],
    cellNumber: form_data['cellPhone'],
    internationalNumber: form_data['internationalNumber'],
    email: form_data['email'],
    documentId: form_data['documentId'],
    receivedDate: @claim.created_at.iso8601, # e.g. "2024-12-02T17:36:52Z"
    veteranAddress: mapped_address_hash(form_data['veteranAddress'])
  }

  res_payload.merge!({ veteranInformation: adjusted_veteran_information })
  res_payload.merge!(new_address) if form_data['newAddress'].present?

  res_payload.to_json
end

#mapped_address_hash(client_hash) ⇒ Object (private)



117
118
119
120
121
122
123
124
125
# File 'lib/res/ch31_form.rb', line 117

def mapped_address_hash(client_hash)
  {
    country: client_hash['country'],
    street: client_hash['street'],
    city: client_hash['city'],
    state: client_hash['state'],
    postalCode: client_hash['postalCode']
  }
end

#new_addressObject (private)



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/res/ch31_form.rb', line 101

def new_address
  new_address = mapped_address_hash(claim_form_hash['newAddress'])

  adjusted_new_address = {
    newAddress: new_address
  }

  return adjusted_new_address unless new_address[:isForeign]

  # RES/CMSA expects different keys for postal and state for foreign addresses
  new_address[:internationalPostalCode] = new_address.delete(:zipCode)
  new_address[:province] = new_address.delete(:stateCode)

  adjusted_new_address
end

#process_ch_31_error(e, response_body) ⇒ Object (private)



127
128
129
130
131
132
133
# File 'lib/res/ch31_form.rb', line 127

def process_ch_31_error(e, response_body)
  Rails.logger.error(e)
  Rails.logger.error({
                       intake_id: response_body['ApplicationIntake'],
                       error_message: response_body['ErrorMessage']
                     })
end

#submitHash

Submits prepared data derived from VeteranReadinessEmploymentClaim#form

Returns:

  • (Hash)

    the student’s address



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/res/ch31_form.rb', line 23

def submit
  if @claim.nil?
    Rails.logger.error('Ch31NilClaimError. user icn:', @user.icn)
    raise Ch31NilClaimError
  end

  response = send_to_res(payload: format_payload_for_res)
  response_body = response.body

  raise Ch31Error if response_body['success_message'].blank?

  response_body
rescue Ch31Error => e
  process_ch_31_error(e, response_body)

  raise
end

#veteran_address(form_data) ⇒ Object (private)

TODO: determine need



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/res/ch31_form.rb', line 69

def veteran_address(form_data)
  vet_address = mapped_address_hash(form_data['veteranAddress'])

  adjusted_address = {
    veteranAddress: vet_address
  }

  return adjusted_address if adjusted_address.dig(:veteranAddress, :isForeign) == false

  # RES/CMSA expects different keys for postal and state for foreign addresses
  # internationPostalCode misspelling is correct
  international_address = adjusted_address[:veteranAddress]
  international_address[:internationPostalCode] = international_address.delete(:zipCode)
  international_address[:province] = international_address.delete(:stateCode)

  adjusted_address
end