Class: DependentsApplication
Constant Summary
collapse
- FORM_ID =
'21-686C'
- SEPARATION_TYPES =
{
'Death' => 'DEATH',
'Divorce' => 'DIVORCED',
'Other' => 'OTHER'
}.freeze
- MILITARY_STATES =
%w[AA AE AP].freeze
Common::RedisStore::REQ_CLASS_INSTANCE_VARS
Class Method Summary
collapse
-
.convert_address(address) ⇒ Object
-
.convert_country(location) ⇒ Object
-
.convert_evss_date(date) ⇒ Object
-
.convert_marriage(current_marriage, last_marriage, spouse_marriages) ⇒ Object
-
.convert_name(full_name) ⇒ Object
-
.convert_no_ssn(no_ssn, reason_type) ⇒ Object
-
.convert_previous_marriages(previous_marriages) ⇒ Object
-
.convert_ssn(ssn) ⇒ Object
-
.filter_children(dependents, evss_children) ⇒ Object
-
.get_address_locality(address) ⇒ Object
-
.separate_previous_marriages(marriages) ⇒ Object
-
.set_boolean_attrs!(dependent, child) ⇒ Object
-
.set_child_address!(dependent, home_address, child) ⇒ Object
-
.set_child_attrs!(dependent, home_address, child = {}) ⇒ Object
-
.set_date_attrs!(dependent, child) ⇒ Object
-
.set_guardian!(guardian, child) ⇒ Object
-
.set_place_of_birth!(place_of_birth, child) ⇒ Object
-
.set_relationship_type!(dependent, child) ⇒ Object
-
.set_ssn_info!(dependent, child) ⇒ Object
-
.transform_children(parsed_form, evss_form) ⇒ Object
-
.transform_form(parsed_form, evss_form) ⇒ Object
-
.transform_spouse(parsed_form, evss_form) ⇒ Object
Instance Method Summary
collapse
Methods included from RedisForm
#form_matches_schema, #parsed_form, #parsed_response, #save
create, delete, #destroy, #destroyed?, exists?, #expire, find, find_or_build, #initialize, #initialize_dup, keys, #persisted?, pop, redis_key, redis_store, redis_ttl, #save, #save!, #ttl, #update, #update!
Class Method Details
.convert_address(address) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'app/models/dependents_application.rb', line 58
def self.convert_address(address)
converted = {}
return converted if address.blank?
converted['address'] = {
'addressLine1' => address['street'],
'addressLine2' => address['street2'],
'addressLine3' => address['street3'],
'addressLocality' => get_address_locality(address),
'city' => address['city'],
'country' => convert_country(address),
'postOffice' => address['postOffice'],
'postalType' => address['postalType'],
'state' => address['state'],
'zipCode' => address['postalCode']
}
converted
end
|
.convert_country(location) ⇒ Object
78
79
80
81
82
83
84
85
|
# File 'app/models/dependents_application.rb', line 78
def self.convert_country(location)
return {} if location.blank?
{
'dropDownCountry' => location['countryDropdown'],
'textCountry' => location['countryText']
}
end
|
.convert_evss_date(date) ⇒ Object
31
32
33
|
# File 'app/models/dependents_application.rb', line 31
def self.convert_evss_date(date)
Date.parse(date).to_time(:utc).iso8601
end
|
.convert_marriage(current_marriage, last_marriage, spouse_marriages) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'app/models/dependents_application.rb', line 110
def self.convert_marriage(current_marriage, last_marriage, spouse_marriages)
converted = {}
return converted if current_marriage.blank?
converted.merge!(convert_address(current_marriage['spouseAddress']))
converted.merge!(convert_name(last_marriage['spouseFullName']))
converted.merge!(convert_no_ssn(current_marriage['spouseHasNoSsn'], current_marriage['spouseHasNoSsnReason']))
converted.merge!(convert_ssn(current_marriage['spouseSocialSecurityNumber']))
converted['dateOfBirth'] = convert_evss_date(current_marriage['spouseDateOfBirth'])
converted['currentMarriage'] = {
'marriageDate' => convert_evss_date(last_marriage['dateOfMarriage']),
'city' => last_marriage['locationOfMarriage']['city'],
'country' => convert_country(last_marriage['locationOfMarriage']),
'state' => last_marriage['locationOfMarriage']['state']
}
converted['vaFileNumber'] = convert_ssn(current_marriage['spouseVaFileNumber'])['ssn']
converted['veteran'] = current_marriage['spouseIsVeteran']
converted['previousMarriages'] = convert_previous_marriages(spouse_marriages)
converted
end
|
.convert_name(full_name) ⇒ Object
35
36
37
38
|
# File 'app/models/dependents_application.rb', line 35
def self.convert_name(full_name)
full_name ||= {}
full_name.transform_keys { |k| "#{k}Name" }
end
|
.convert_no_ssn(no_ssn, reason_type) ⇒ Object
135
136
137
138
139
140
|
# File 'app/models/dependents_application.rb', line 135
def self.convert_no_ssn(no_ssn, reason_type)
{
'hasNoSsn' => no_ssn,
'noSsnReasonType' => reason_type
}
end
|
.convert_previous_marriages(previous_marriages) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'app/models/dependents_application.rb', line 87
def self.convert_previous_marriages(previous_marriages)
return [] if previous_marriages.blank?
previous_marriages.map do |previous_marriage|
location_separation = previous_marriage['locationOfSeparation'] || {}
{
'marriageDate' => convert_evss_date(previous_marriage['dateOfMarriage']),
'endCity' => location_separation['city'],
'city' => previous_marriage['locationOfMarriage']['city'],
'endCountry' => convert_country(location_separation),
'country' => convert_country(previous_marriage['locationOfMarriage']),
'terminatedDate' => convert_evss_date(previous_marriage['dateOfSeparation']),
'marriageTerminationReasonType' => SEPARATION_TYPES[previous_marriage['reasonForSeparation']],
'explainTermination' => previous_marriage['explainSeparation'],
'endState' => location_separation['state'],
'state' => previous_marriage['locationOfMarriage']['state']
}.merge(
convert_name(previous_marriage['spouseFullName'])
)
end
end
|
.convert_ssn(ssn) ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'app/models/dependents_application.rb', line 40
def self.convert_ssn(ssn)
return {} if ssn.blank?
{
'ssn' => StringHelpers.hyphenated_ssn(ssn),
'hasNoSsn' => false,
'noSsnReasonType' => nil
}
end
|
.filter_children(dependents, evss_children) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'app/models/dependents_application.rb', line 19
def self.filter_children(dependents, evss_children)
return [] if evss_children.blank? || dependents.blank?
evss_children.find_all do |child|
ssn = child['ssn'].delete('-')
dependents.find do |dependent|
dependent['childSocialSecurityNumber'] == ssn
end
end
end
|
.get_address_locality(address) ⇒ Object
50
51
52
53
54
55
56
|
# File 'app/models/dependents_application.rb', line 50
def self.get_address_locality(address)
if address['country'] == 'USA'
MILITARY_STATES.include?(address['state']) ? 'MILITARY' : 'DOMESTIC'
else
'INTERNATIONAL'
end
end
|
.separate_previous_marriages(marriages) ⇒ Object
261
262
263
264
265
|
# File 'app/models/dependents_application.rb', line 261
def self.separate_previous_marriages(marriages)
marriages&.find_all do |marriage|
marriage['dateOfSeparation'].present?
end
end
|
.set_boolean_attrs!(dependent, child) ⇒ Object
188
189
190
191
192
193
194
195
196
197
198
199
|
# File 'app/models/dependents_application.rb', line 188
def self.set_boolean_attrs!(dependent, child)
[
%w[attendedSchool attendingCollege],
%w[disabled disabled],
%w[married previouslyMarried]
].each do |attrs|
val = dependent[attrs[1]]
next if val.nil?
child[attrs[0]] = val
end
end
|
.set_child_address!(dependent, home_address, child) ⇒ Object
156
157
158
159
160
161
162
|
# File 'app/models/dependents_application.rb', line 156
def self.set_child_address!(dependent, home_address, child)
if dependent['childInHousehold']
child.merge!(home_address)
else
child.merge!(convert_address(dependent['childAddress']))
end
end
|
.set_child_attrs!(dependent, home_address, child = {}) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'app/models/dependents_application.rb', line 142
def self.set_child_attrs!(dependent, home_address, child = {})
child.merge!(convert_name(dependent['fullName']))
set_child_address!(dependent, home_address, child)
set_place_of_birth!(dependent['childPlaceOfBirth'], child)
set_guardian!(dependent['personWhoLivesWithChild'], child)
set_ssn_info!(dependent, child)
set_relationship_type!(dependent, child)
set_boolean_attrs!(dependent, child)
set_date_attrs!(dependent, child)
child
end
|
.set_date_attrs!(dependent, child) ⇒ Object
201
202
203
204
205
206
207
208
209
210
211
|
# File 'app/models/dependents_application.rb', line 201
def self.set_date_attrs!(dependent, child)
[
%w[dateOfBirth childDateOfBirth],
%w[marriedDate marriedDate]
].each do |attrs|
val = dependent[attrs[1]]
next if val.blank?
child[attrs[0]] = convert_evss_date(val)
end
end
|
.set_guardian!(guardian, child) ⇒ Object
172
173
174
175
176
177
|
# File 'app/models/dependents_application.rb', line 172
def self.set_guardian!(guardian, child)
guardian ||= {}
child['guardianFirstName'] = guardian['first']
child['guardianMiddleName'] = guardian['middle']
child['guardianLastName'] = guardian['last']
end
|
.set_place_of_birth!(place_of_birth, child) ⇒ Object
164
165
166
167
168
169
170
|
# File 'app/models/dependents_application.rb', line 164
def self.set_place_of_birth!(place_of_birth, child)
return if place_of_birth.blank?
child['countryOfBirth'] = convert_country(place_of_birth)
child['cityOfBirth'] = place_of_birth['city']
child['stateOfBirth'] = place_of_birth['state']
end
|
.set_relationship_type!(dependent, child) ⇒ Object
184
185
186
|
# File 'app/models/dependents_application.rb', line 184
def self.set_relationship_type!(dependent, child)
child['childRelationshipType'] = dependent['childRelationship']&.upcase
end
|
.set_ssn_info!(dependent, child) ⇒ Object
179
180
181
182
|
# File 'app/models/dependents_application.rb', line 179
def self.set_ssn_info!(dependent, child)
child.merge!(convert_no_ssn(dependent['childHasNoSsn'], dependent['childHasNoSsnReason']))
child.merge!(convert_ssn(dependent['childSocialSecurityNumber']))
end
|
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
# File 'app/models/dependents_application.rb', line 240
def self.transform_children(parsed_form, evss_form)
dependents = parsed_form['dependents'] || []
home_address = evss_form['submitProcess']['veteran'].slice('address')
children = filter_children(
dependents,
evss_form['submitProcess']['veteran']['children']
)
dependents.each do |dependent|
child = children.find { |c| c['ssn'] == dependent['childSocialSecurityNumber'] }
if child
set_child_attrs!(dependent, home_address, child)
else
children << set_child_attrs!(dependent, home_address)
end
end
children
end
|
213
214
215
216
217
218
219
220
221
222
223
224
225
|
# File 'app/models/dependents_application.rb', line 213
def self.transform_form(parsed_form, evss_form)
transformed = {}
transformed['spouse'] = transform_spouse(parsed_form, evss_form)
transformed['children'] = transform_children(parsed_form, evss_form)
transformed['marriageType'] = parsed_form['maritalStatus']
previous_marriages = separate_previous_marriages(parsed_form['marriages'])
transformed['previousMarriages'] = convert_previous_marriages(previous_marriages)
evss_form['submitProcess']['veteran'].merge!(transformed)
Common::HashHelpers.deep_compact(evss_form)
end
|
227
228
229
230
231
232
233
234
235
236
237
238
|
# File 'app/models/dependents_application.rb', line 227
def self.transform_spouse(parsed_form, evss_form)
spouse = convert_marriage(
parsed_form['currentMarriage'],
parsed_form['marriages']&.last,
parsed_form['spouseMarriages']
)
home_address = evss_form['submitProcess']['veteran'].slice('address')
spouse.merge!(home_address) if parsed_form['currentMarriage']&.dig('liveWithSpouse')
spouse
end
|
Instance Method Details
#create_submission_job ⇒ Object
273
274
275
|
# File 'app/models/dependents_application.rb', line 273
def create_submission_job
EVSS::DependentsApplicationJob.perform_async(id, KmsEncrypted::Box.new.encrypt(parsed_form.to_json), user.uuid)
end
|
#user_can_access_evss ⇒ Object
269
270
271
|
# File 'app/models/dependents_application.rb', line 269
def user_can_access_evss
errors.add(:user, 'must have evss access') unless user.authorize(:evss, :access?)
end
|