Class: FormProfiles::VA21686c

Inherits:
FormProfile
  • Object
show all
Defined in:
app/models/form_profiles/va_21686c.rb

Instance Method Summary collapse

Instance Method Details

#convert_date(date) ⇒ Object (private)



221
222
223
224
225
# File 'app/models/form_profiles/va_21686c.rb', line 221

def convert_date(date)
  return unless date

  Time.strptime(date.to_s, '%Q').utc.to_date.to_s
end

#convert_phone(phone) ⇒ Object (private)



166
167
168
169
170
# File 'app/models/form_profiles/va_21686c.rb', line 166

def convert_phone(phone)
  return unless phone

  "#{phone['areaNbr']}#{phone['phoneNbr']}".tr('^0-9', '')
end

#convert_ssn(ssn) ⇒ Object (private)



160
161
162
163
164
# File 'app/models/form_profiles/va_21686c.rb', line 160

def convert_ssn(ssn)
  return unless ssn

  ssn.tr('^0-9', '')
end

#detect_file_number(file_number) ⇒ Object (private)



188
189
190
191
192
# File 'app/models/form_profiles/va_21686c.rb', line 188

def detect_file_number(file_number)
  return if file_number.nil? || file_number.match(/^\d{3}-\d{2}-\d{4}$/)

  file_number
end

#initialize_veteran_informationObject (private)



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'app/models/form_profiles/va_21686c.rb', line 119

def initialize_veteran_information
  res = EVSS::Dependents::RetrievedInfo.for_user(user)
  veteran = res.body['submitProcess']['veteran']
  spouse = veteran['spouse']

  VA21686c::FormContactInformation.new(
    {
      veteran_address: prefill_address(veteran['address']),
      veteran_full_name: prefill_name(veteran),
      veteran_email: veteran['emailAddress'],
      va_file_number: detect_file_number(veteran['vaFileNumber']),
      marital_status: veteran['marriageType'],
      day_phone: convert_phone(veteran['primaryPhone']),
      night_phone: convert_phone(veteran['secondaryPhone']),
      veteran_social_security_number: convert_ssn(veteran['ssn']),
      current_marriage: prefill_current_marriage(spouse),
      spouse_marriages: spouse.try(:[], 'previousMarriages')&.map { |m| prefill_marriage(m) },
      marriages: prefill_marriages(spouse, veteran['previousMarriages']),
      dependents: prefill_dependents(veteran['children'])
    }.compact
  )
end

#metadataObject



102
103
104
105
106
107
108
# File 'app/models/form_profiles/va_21686c.rb', line 102

def 
  {
    version: 0,
    prefill: true,
    returnUrl: '/veteran-information'
  }
end

#prefillObject



110
111
112
113
114
115
# File 'app/models/form_profiles/va_21686c.rb', line 110

def prefill
  return {} unless user.authorize :evss, :access?

  @veteran_information = initialize_veteran_information
  super
end

#prefill_address(address) ⇒ Object (private)



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'app/models/form_profiles/va_21686c.rb', line 260

def prefill_address(address)
  return unless address

  address = VA21686c::FormAddress.new(
    {
      address_type: address['addressLocality'],
      street: address['addressLine1'],
      street2: address['addressLine2'],
      street3: address['addressLine3'],
      city: address['city'],
      state: address['state'],
      postal_code: "#{address['zipCode']}#{"-#{address['zipLastFour']}" if address['zipLastFour'].present?}",
      country_dropdown: address.dig('country', 'dropDownCountry'),
      country_text: address.dig('country', 'textCountry'),
      post_office: address['postOffice'],
      postal_type: address['postalType']
    }.compact
  )
  return if address.attributes.values.uniq.all? { |x| ['DOMESTIC', ''].include? x }

  address
end

#prefill_current_marriage(spouse) ⇒ Object (private)



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'app/models/form_profiles/va_21686c.rb', line 172

def prefill_current_marriage(spouse)
  return unless spouse

  VA21686c::FormCurrentMarriage.new(
    {
      spouse_social_security_number: convert_ssn(spouse['ssn']),
      spouse_has_no_ssn: spouse['hasNoSsn'],
      spouse_has_no_ssn_reason: spouse['noSsnReasonType'],
      spouse_address: prefill_address(spouse['address']),
      spouse_is_veteran: spouse['veteran'],
      live_with_spouse: spouse['sameResidency'],
      spouse_date_of_birth: convert_date(spouse['dateOfBirth'])
    }.compact
  )
end

#prefill_dependents(children) ⇒ Object (private)



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'app/models/form_profiles/va_21686c.rb', line 227

def prefill_dependents(children)
  return [] if children.blank?

  children.map do |child|
    VA21686c::FormDependent.new(
      {
        full_name: prefill_name(child),
        child_date_of_birth: convert_date(child['dateOfBirth']),
        child_in_household: child['sameResidency'],
        child_address: prefill_address(child['address']),
        child_social_security_number: convert_ssn(child['ssn']),
        child_has_no_ssn: child['hasNoSsn'],
        child_has_no_ssn_reason: child['noSsnReasonType'],
        attending_college: child['attendedSchool'],
        disabled: child['disabled'],
        married: child['married'],
        child_place_of_birth: prefill_location(child['countryOfBirth'], child['cityOfBirth'], child['stateOfBirth']),
        child_relationship_type: child['childRelationshipType']
      }.compact
    )
  end
end

#prefill_location(country, city, state) ⇒ Object (private)



209
210
211
212
213
214
215
216
217
218
219
# File 'app/models/form_profiles/va_21686c.rb', line 209

def prefill_location(country, city, state)
  country ||= {}
  VA21686c::FormLocation.new(
    {
      country_dropdown: country['dropDownCountry'],
      country_text: country['textCountry'],
      city:,
      state:
    }.compact
  )
end

#prefill_marriage(marriage) ⇒ Object (private)



194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'app/models/form_profiles/va_21686c.rb', line 194

def prefill_marriage(marriage)
  return unless marriage

  VA21686c::FormMarriage.new(
    {
      date_of_marriage: convert_date(marriage['marriageDate']),
      location_of_marriage: prefill_location(marriage['country'], marriage['city'], marriage['state']),
      spouse_full_name: prefill_name(marriage),
      reason_for_separation: marriage['marriageTerminationReasonType'],
      date_of_separation: convert_date(marriage['terminatedDate']),
      location_of_separation: prefill_location(marriage['endCountry'], marriage['endCity'], marriage['endState'])
    }.compact
  )
end

#prefill_marriages(spouse, previous_marriages) ⇒ Object (private)



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'app/models/form_profiles/va_21686c.rb', line 142

def prefill_marriages(spouse, previous_marriages)
  marriages = previous_marriages.map { |m| prefill_marriage(m) }

  if spouse.present?
    marriage = spouse['currentMarriage']

    marriages << VA21686c::FormMarriage.new(
      {
        date_of_marriage: convert_date(marriage['marriageDate']),
        location_of_marriage: prefill_location(marriage['country'], marriage['city'], marriage['state']),
        spouse_full_name: prefill_name(spouse)
      }.compact
    )
  end

  marriages
end

#prefill_name(person) ⇒ Object (private)



250
251
252
253
254
255
256
257
258
# File 'app/models/form_profiles/va_21686c.rb', line 250

def prefill_name(person)
  VA21686c::FormFullName.new(
    {
      first: person['firstName'],
      last: person['lastName'],
      middle: person['middleName']
    }.compact
  )
end