Class: SavedClaim::CaregiversAssistanceClaim
- Inherits:
-
SavedClaim
show all
- Defined in:
- app/models/saved_claim/caregivers_assistance_claim.rb
Constant Summary
collapse
- FORM =
'10-10CG'
Instance Method Summary
collapse
Methods inherited from SavedClaim
add_form_and_validation, #after_create_metrics, #after_destroy_metrics, #attachment_keys, #business_line, #confirmation_number, #email, #form_is_string, #form_must_be_string, #insert_notification, #open_struct_form, #parsed_form, #submitted_at, #update_form, #va_notification?, #validate_form, #validate_schema
descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?
Instance Method Details
#destroy_attachment ⇒ Object
91
92
93
94
95
|
# File 'app/models/saved_claim/caregivers_assistance_claim.rb', line 91
def destroy_attachment
return if form.blank?
Form1010cg::Attachment.find_by(guid: parsed_form['poaAttachmentId'])&.destroy!
end
|
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'app/models/saved_claim/caregivers_assistance_claim.rb', line 36
def form_matches_schema
super unless Flipper.enabled?(:caregiver_retry_form_validation)
return unless form_is_string
schema = VetsJsonSchema::SCHEMAS[self.class::FORM]
validation_errors = validate_form_with_retries(schema)
validation_errors.each do |e|
errors.add(e[:fragment], e[:message])
e[:errors]&.flatten(2)&.each { |nested| errors.add(nested[:fragment], nested[:message]) if nested.is_a? Hash }
end
unless validation_errors.empty?
Rails.logger.error('SavedClaim form did not pass validation', { guid:, errors: validation_errors })
end
end
|
63
64
65
66
67
68
69
70
71
|
# File 'app/models/saved_claim/caregivers_assistance_claim.rb', line 63
def form_subjects
if form.nil?
[]
else
parsed_form.keys.find_all do |k|
%w[veteran primaryCaregiver secondaryCaregiverOne secondaryCaregiverTwo].include?(k)
end
end
end
|
#primary_caregiver_data ⇒ Object
77
78
79
|
# File 'app/models/saved_claim/caregivers_assistance_claim.rb', line 77
def primary_caregiver_data
parsed_form['primaryCaregiver'] unless form.nil?
end
|
#process_attachments! ⇒ Object
19
20
21
22
|
# File 'app/models/saved_claim/caregivers_assistance_claim.rb', line 19
def process_attachments!
raise NotImplementedError, 'Not Implemented for Form 10-10CG'
end
|
#regional_office ⇒ Object
SavedClaims require regional_office to be defined, CaregiversAssistanceClaim has no purpose for it.
CaregiversAssistanceClaims are not processed regional VA offices. The claim’s form will contain a “Planned Clinic” (a VA facility that the end-user provided in the form). This facility is where the end-user’s point of contact will be for post-submission processing.
59
60
61
|
# File 'app/models/saved_claim/caregivers_assistance_claim.rb', line 59
def regional_office
[]
end
|
#secondary_caregiver_one_data ⇒ Object
81
82
83
|
# File 'app/models/saved_claim/caregivers_assistance_claim.rb', line 81
def secondary_caregiver_one_data
parsed_form['secondaryCaregiverOne'] unless form.nil?
end
|
#secondary_caregiver_two_data ⇒ Object
85
86
87
|
# File 'app/models/saved_claim/caregivers_assistance_claim.rb', line 85
def secondary_caregiver_two_data
parsed_form['secondaryCaregiverTwo'] unless form.nil?
end
|
#to_pdf(filename = nil) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/models/saved_claim/caregivers_assistance_claim.rb', line 24
def to_pdf(filename = nil, **)
name = filename || guid
PdfFill::Filler.fill_form(self, name, **)
rescue => e
Rails.logger.error("Failed to generate PDF: #{e.message}")
PersonalInformationLog.create(data: { form: parsed_form, file_name: name },
error_class: '1010CGPdfGenerationError')
raise
end
|
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'app/models/saved_claim/caregivers_assistance_claim.rb', line 97
def validate_form_with_retries(schema)
attempts = 0
max_attempts = 3
begin
attempts += 1
errors_array = JSON::Validator.fully_validate(schema, parsed_form, { errors_as_objects: true })
Rails.logger.info("Form validation succeeded on attempt #{attempts}/#{max_attempts}") if attempts > 1
errors_array
rescue => e
if attempts <= max_attempts
Rails.logger.warn("Retrying form validation due to error: #{e.message} (Attempt #{attempts}/#{max_attempts})")
sleep(1) retry
else
PersonalInformationLog.create(data: { schema:, parsed_form:, params: { errors_as_objects: true } },
error_class: 'SavedClaim FormValidationError')
Rails.logger.error('Error during form validation after maximimum retries',
{ error: e.message, backtrace: e.backtrace, schema: })
raise
end
end
end
|
#veteran_data ⇒ Object
73
74
75
|
# File 'app/models/saved_claim/caregivers_assistance_claim.rb', line 73
def veteran_data
parsed_form['veteran'] unless form.nil?
end
|