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
Methods included from RedisForm
#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
rubocop:enable Metrics/MethodLength
238
239
240
241
242
|
# File 'app/models/dependents_application.rb', line 238
def self.separate_previous_marriages(marriages)
marriages&.find_all do |marriage|
marriage['dateOfSeparation'].present?
end
end
|
.set_child_attrs!(dependent, home_address, child = {}) ⇒ Object
rubocop:disable Metrics/MethodLength
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
# File 'app/models/dependents_application.rb', line 143
def self.set_child_attrs!(dependent, home_address, child = {})
child.merge!(convert_name(dependent['fullName']))
if dependent['childInHousehold']
child.merge!(home_address)
else
child.merge!(convert_address(dependent['childAddress']))
end
dependent['childPlaceOfBirth'].tap do |place_of_birth|
next 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
(dependent['personWhoLivesWithChild'] || {}).tap do |guardian|
child['guardianFirstName'] = guardian['first']
child['guardianMiddleName'] = guardian['middle']
child['guardianLastName'] = guardian['last']
end
child.merge!(convert_no_ssn(dependent['childHasNoSsn'], dependent['childHasNoSsnReason']))
child.merge!(convert_ssn(dependent['childSocialSecurityNumber']))
child['childRelationshipType'] = dependent['childRelationship']&.upcase
[
%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
[
%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
child
end
|
rubocop:enable Metrics/MethodLength rubocop:disable Metrics/MethodLength
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
# File 'app/models/dependents_application.rb', line 196
def self.transform_form(parsed_form, evss_form)
dependents = parsed_form['dependents'] || []
transformed = {}
transformed['spouse'] = convert_marriage(
parsed_form['currentMarriage'],
parsed_form['marriages']&.last,
parsed_form['spouseMarriages']
)
home_address = evss_form['submitProcess']['veteran'].slice('address')
transformed['spouse'].merge!(home_address) if parsed_form['currentMarriage'].try(:[], 'liveWithSpouse')
children = filter_children(
dependents,
evss_form['submitProcess']['veteran']['children']
)
parsed_form['dependents'].each do |dependent|
child = children.find do |c|
c['ssn'] == dependent['childSocialSecurityNumber']
end
if child
set_child_attrs!(dependent, home_address, child)
else
children << set_child_attrs!(dependent, home_address)
end
end
transformed['children'] = children
transformed['marriageType'] = parsed_form['maritalStatus']
transformed['previousMarriages'] = convert_previous_marriages(
separate_previous_marriages(parsed_form['marriages'])
)
evss_form['submitProcess']['veteran'].merge!(transformed)
Common::HashHelpers.deep_compact(evss_form)
end
|