Class: VRE::Ch31Form

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

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.vre'
SENTRY_TAG =
{ team: 'vfs-ebenefits' }.freeze

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, #get_token, #request_headers, #send_to_vre

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.



15
16
17
18
# File 'lib/vre/ch31_form.rb', line 15

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

Instance Method Details

#adjusted_veteran_informationObject (private)



94
95
96
97
98
99
100
# File 'lib/vre/ch31_form.rb', line 94

def adjusted_veteran_information
  vet_info = claim_form_hash['veteranInformation']

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

  vet_info
end

#claim_form_hashObject (private)



90
91
92
# File 'lib/vre/ch31_form.rb', line 90

def claim_form_hash
  @claim.parsed_form
end

#format_payload_for_vreObject (private)



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/vre/ch31_form.rb', line 49

def format_payload_for_vre
  form_data = claim_form_hash

  vre_payload = {
    data: {
      educationLevel: form_data['yearsOfEducation'],
      useEva: form_data['useEva'],
      useTelecounseling: form_data['useTelecounseling'],
      meetingTime: form_data['appointmentTimePreferences'],
      isMoving: form_data['isMoving'],
      mainPhone: form_data['mainPhone'],
      cellPhone: form_data['cellPhone'],
      emailAddress: form_data['email']
    }
  }

  vre_payload[:data].merge!(veteran_address(form_data))
  vre_payload[:data].merge!({ veteranInformation: adjusted_veteran_information })
  vre_payload[:data].merge!(new_address) if claim_form_hash['newAddress'].present?

  vre_payload.to_json
end

#mapped_address_hash(client_hash) ⇒ Object (private)



118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/vre/ch31_form.rb', line 118

def mapped_address_hash(client_hash)
  {
    isForeign: client_hash['country'] != 'USA',
    isMilitary: client_hash['isMilitary'] || false,
    countryName: client_hash['country'],
    addressLine1: client_hash['street'],
    addressLine2: client_hash['street2'],
    addressLine3: client_hash['street3'],
    city: client_hash['city'],
    stateCode: client_hash['state'],
    zipCode: client_hash['postalCode']
  }
end

#new_addressObject (private)



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

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]

  # VRE/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)



132
133
134
135
136
137
138
139
140
141
# File 'lib/vre/ch31_form.rb', line 132

def process_ch_31_error(e, response_body)
  log_exception_to_sentry(
    e,
    {
      intake_id: response_body['ApplicationIntake'],
      error_message: response_body['ErrorMessage']
    },
    SENTRY_TAG
  )
end

#process_nil_claim_error(e) ⇒ Object (private)



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

def process_nil_claim_error(e)
  log_exception_to_sentry(
    e,
    {
      icn: @user.icn
    },
    SENTRY_TAG
  )

  { 'error_occurred' => true, 'error_message' => 'Claim cannot be null' }
end

#submitHash

Submits prepared data derived from VeteranReadinessEmploymentClaim#form

Returns:

  • (Hash)

    the student’s address



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vre/ch31_form.rb', line 24

def submit
  raise Ch31NilClaimError if @claim.nil?

  response = send_to_vre(payload: format_payload_for_vre)
  response_body = response.body

  raise Ch31Error if response_body['error_occurred'] == true

  log_message_to_sentry(
    'Temp message for testing',
    :warn,
    { application_intake_id: response_body['application_intake'] },
    SENTRY_TAG
  )
  response_body
rescue Ch31Error => e
  process_ch_31_error(e, response_body)

  response_body
rescue Ch31NilClaimError => e
  process_nil_claim_error(e)
end

#veteran_address(form_data) ⇒ Object (private)



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/vre/ch31_form.rb', line 72

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

  # VRE/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