Class: EducationBenefitsClaim
Constant Summary
collapse
- FORM_TYPES =
%w[1990 1995 1990e 5490 5495 1990n 0993 0994 10203 1990s].freeze
- APPLICATION_TYPES =
%w[
chapter33
chapter1607
chapter1606
chapter32
chapter35
transfer_of_entitlement
vettec
chapter30
vrrap
].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?
Class Method Details
133
134
135
|
# File 'app/models/education_benefits_claim.rb', line 133
def self.(form_types = FORM_TYPES)
form_types.map { |t| "22-#{t}" }.freeze
end
|
.unprocessed ⇒ Object
97
98
99
|
# File 'app/models/education_benefits_claim.rb', line 97
def self.unprocessed
where(processed_at: nil)
end
|
Instance Method Details
#confirmation_number ⇒ Object
42
43
44
|
# File 'app/models/education_benefits_claim.rb', line 42
def confirmation_number
"V-EBC-#{id}"
end
|
#copy_from_previous_benefits ⇒ Object
75
76
77
78
79
80
81
82
83
|
# File 'app/models/education_benefits_claim.rb', line 75
def copy_from_previous_benefits
if @application.currentSameAsPrevious
previous_benefits = @application.previousBenefits
%w[veteranFullName vaFileNumber veteranSocialSecurityNumber].each do |attr|
@application.public_send("#{attr}=", previous_benefits.public_send(attr))
end
end
end
|
#create_education_benefits_submission ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
|
# File 'app/models/education_benefits_claim.rb', line 139
def create_education_benefits_submission
opt = selected_benefits
EducationBenefitsSubmission.create!(
opt.merge(
region:,
form_type:,
education_benefits_claim: self
)
)
end
|
52
53
54
|
# File 'app/models/education_benefits_claim.rb', line 52
def form_type
saved_claim.form_id.gsub('22-', '').downcase
end
|
#generate_benefits_to_apply_to ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
|
# File 'app/models/education_benefits_claim.rb', line 85
def generate_benefits_to_apply_to
selected_benefits = []
APPLICATION_TYPES.each do |application_type|
selected_benefits << application_type if @application.public_send(application_type)
end
selected_benefits = selected_benefits.join(', ')
@application.toursOfDuty&.each do |tour|
tour.benefitsToApplyTo = selected_benefits if tour.applyPeriodToSelected
end
end
|
This converts the form data into an OpenStruct object so that the template rendering can be cleaner. Piping it through the JSON serializer was a quick and easy way to deeply transform the object.
59
60
61
62
63
64
65
66
67
68
|
# File 'app/models/education_benefits_claim.rb', line 59
def open_struct_form
@application ||= lambda do
@application = saved_claim.open_struct_form
@application.confirmation_number = confirmation_number
transform_form
@application
end.call
end
|
#regional_office ⇒ Object
#reprocess_at(region) ⇒ Object
For console access only, right now.
#selected_benefits ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'app/models/education_benefits_claim.rb', line 109
def selected_benefits
benefits = {}
case form_type
when '1990'
benefits = parsed_form.slice(*APPLICATION_TYPES)
when '1990n'
return benefits
when '0994'
benefits['vettec'] = true
when '1990s'
benefits['vrrap'] = true
when '1995'
benefit = parsed_form['benefit']&.underscore
benefits['chapter33'] = true if benefit.present? && benefit.start_with?('chapter33')
benefits[benefit] = true if benefit.present? && !benefit.start_with?('chapter33')
else
benefit = parsed_form['benefit']&.underscore
benefits[benefit] = true if benefit.present?
end
benefits
end
|
#set_region ⇒ Object
158
159
160
|
# File 'app/models/education_benefits_claim.rb', line 158
def set_region
self.regional_processing_office ||= region.to_s
end
|
70
71
72
73
|
# File 'app/models/education_benefits_claim.rb', line 70
def transform_form
generate_benefits_to_apply_to if is_1990?
copy_from_previous_benefits if is_5490?
end
|
#update_education_benefits_submission_status ⇒ Object
151
152
153
154
155
156
|
# File 'app/models/education_benefits_claim.rb', line 151
def update_education_benefits_submission_status
if processed_at.present? && attribute_before_last_save(:processed).nil?
education_benefits_submission&.update!(status: 'processed')
end
end
|