Class: SavedClaim
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- SavedClaim
- Includes:
- SetGuid
- Defined in:
- app/models/saved_claim.rb
Overview
Base class to hold common functionality for Claim submissions. Subclasses need to several constants and methods defined:
-
‘FORM` should align with the identifier of the form as found in
the vets-json-schema struct so that validations can be run on submit
-
‘CONFIRMATION` should be a small ident used as part of the confirmation
number to quickly determine the form/product type
-
‘regional_office()`, which returns an array or string of the location of the claim processing facility
-
‘attachment_keys()` returns a list of symbols corresponding to the keys in the JSON submission of file upload references. These are iterated over in the `process_attachments!` method to associate the previously unmoored files to the submitted claim, and to begin processing them.
Direct Known Subclasses
CentralMailClaim, Ask, CaregiversAssistanceClaim, CoeClaim, DisabilityCompensation, EducationBenefits, Pension, VeteranReadinessEmploymentClaim
Defined Under Namespace
Classes: Ask, Burial, CaregiversAssistanceClaim, CoeClaim, DependencyClaim, DependencyVerificationClaim, DisabilityCompensation, EducationBenefits, EducationCareerCounselingClaim, Pension, VeteranReadinessEmploymentClaim
Class Method Summary collapse
Instance Method Summary collapse
- #confirmation_number ⇒ Object
- #form_is_string ⇒ Object
- #form_matches_schema ⇒ Object
- #form_must_be_string ⇒ Object
-
#open_struct_form ⇒ Object
Convert the json into an OStruct.
- #parsed_form ⇒ Object
-
#process_attachments! ⇒ Object
Run after a claim is saved, this processes any files and workflows that are present and sends them to our internal partners for processing.
- #submit_to_structured_data_services! ⇒ Object
- #submitted_at ⇒ Object
- #to_pdf(file_name = nil) ⇒ Object
- #update_form(key, value) ⇒ Object
Methods inherited from ApplicationRecord
descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?
Class Method Details
.add_form_and_validation(form_id) ⇒ Object
37 38 39 40 |
# File 'app/models/saved_claim.rb', line 37 def self.add_form_and_validation(form_id) const_set('FORM', form_id) validates(:form_id, inclusion: [form_id]) end |
Instance Method Details
#confirmation_number ⇒ Object
62 63 64 |
# File 'app/models/saved_claim.rb', line 62 def confirmation_number guid end |
#form_is_string ⇒ Object
79 80 81 |
# File 'app/models/saved_claim.rb', line 79 def form_is_string form.is_a?(String) end |
#form_matches_schema ⇒ Object
87 88 89 90 91 92 93 |
# File 'app/models/saved_claim.rb', line 87 def form_matches_schema return unless form_is_string JSON::Validator.fully_validate(VetsJsonSchema::SCHEMAS[self.class::FORM], parsed_form).each do |v| errors.add(:form, v.to_s) end end |
#form_must_be_string ⇒ Object
83 84 85 |
# File 'app/models/saved_claim.rb', line 83 def form_must_be_string errors.add(:form, :invalid_format, message: 'must be a json string') unless form_is_string end |
#open_struct_form ⇒ Object
Convert the json into an OStruct
67 68 69 |
# File 'app/models/saved_claim.rb', line 67 def open_struct_form @application ||= JSON.parse(form, object_class: OpenStruct) end |
#parsed_form ⇒ Object
71 72 73 |
# File 'app/models/saved_claim.rb', line 71 def parsed_form @parsed_form ||= JSON.parse(form) end |
#process_attachments! ⇒ Object
Run after a claim is saved, this processes any files and workflows that are present and sends them to our internal partners for processing.
44 45 46 47 48 49 50 |
# File 'app/models/saved_claim.rb', line 44 def refs = .map { |key| Array(open_struct_form.send(key)) }.flatten files = PersistentAttachment.where(guid: refs.map(&:confirmationCode)) files.find_each { |f| f.update(saved_claim_id: id) } CentralMail::SubmitSavedClaimJob.perform_async(id) end |
#submit_to_structured_data_services! ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'app/models/saved_claim.rb', line 52 def submit_to_structured_data_services! # Only 21P-530 burial forms are supported at this time if form_id != '21P-530' = "Unsupported form id: #{form_id}" raise Common::Exceptions::UnprocessableEntity.new(detail: ), end StructuredData::ProcessDataJob.perform_async(id) end |
#submitted_at ⇒ Object
75 76 77 |
# File 'app/models/saved_claim.rb', line 75 def submitted_at created_at end |
#to_pdf(file_name = nil) ⇒ Object
95 96 97 |
# File 'app/models/saved_claim.rb', line 95 def to_pdf(file_name = nil) PdfFill::Filler.fill_form(self, file_name) end |
#update_form(key, value) ⇒ Object
99 100 101 102 103 |
# File 'app/models/saved_claim.rb', line 99 def update_form(key, value) application = parsed_form application[key] = value self.form = JSON.generate(application) end |