Class: BGS::DependentService
- Inherits:
-
Object
- Object
- BGS::DependentService
- Includes:
- SentryLogging
- Defined in:
- app/services/bgs/dependent_service.rb
Instance Attribute Summary collapse
-
#birth_date ⇒ Object
readonly
Returns the value of attribute birth_date.
-
#common_name ⇒ Object
readonly
Returns the value of attribute common_name.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#file_number ⇒ Object
readonly
Returns the value of attribute file_number.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#icn ⇒ Object
readonly
Returns the value of attribute icn.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#middle_name ⇒ Object
readonly
Returns the value of attribute middle_name.
-
#participant_id ⇒ Object
readonly
Returns the value of attribute participant_id.
-
#ssn ⇒ Object
readonly
Returns the value of attribute ssn.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Instance Method Summary collapse
- #external_key ⇒ Object private
- #generate_hash_from_details ⇒ Object private
- #get_dependents ⇒ Object
- #get_form_hash_686c ⇒ Object private
-
#initialize(user) ⇒ DependentService
constructor
A new instance of DependentService.
- #service ⇒ Object private
- #submit_686c_form(claim) ⇒ Object
- #submit_pdf_job(claim:, encrypted_vet_info:) ⇒ Object private
- #submit_to_central_service(claim:) ⇒ Object private
- #submit_to_standard_service(claim:, encrypted_vet_info:) ⇒ Object private
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Constructor Details
#initialize(user) ⇒ DependentService
Returns a new instance of DependentService.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/services/bgs/dependent_service.rb', line 19 def initialize(user) @first_name = user.first_name @middle_name = user.middle_name @last_name = user.last_name @ssn = user.ssn @uuid = user.uuid @birth_date = user.birth_date @common_name = user.common_name @email = user.email @icn = user.icn @participant_id = user.participant_id @va_profile_email = user.va_profile_email end |
Instance Attribute Details
#birth_date ⇒ Object (readonly)
Returns the value of attribute birth_date.
7 8 9 |
# File 'app/services/bgs/dependent_service.rb', line 7 def birth_date @birth_date end |
#common_name ⇒ Object (readonly)
Returns the value of attribute common_name.
7 8 9 |
# File 'app/services/bgs/dependent_service.rb', line 7 def common_name @common_name end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
7 8 9 |
# File 'app/services/bgs/dependent_service.rb', line 7 def email @email end |
#file_number ⇒ Object (readonly)
Returns the value of attribute file_number.
7 8 9 |
# File 'app/services/bgs/dependent_service.rb', line 7 def file_number @file_number end |
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
7 8 9 |
# File 'app/services/bgs/dependent_service.rb', line 7 def first_name @first_name end |
#icn ⇒ Object (readonly)
Returns the value of attribute icn.
7 8 9 |
# File 'app/services/bgs/dependent_service.rb', line 7 def icn @icn end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
7 8 9 |
# File 'app/services/bgs/dependent_service.rb', line 7 def last_name @last_name end |
#middle_name ⇒ Object (readonly)
Returns the value of attribute middle_name.
7 8 9 |
# File 'app/services/bgs/dependent_service.rb', line 7 def middle_name @middle_name end |
#participant_id ⇒ Object (readonly)
Returns the value of attribute participant_id.
7 8 9 |
# File 'app/services/bgs/dependent_service.rb', line 7 def participant_id @participant_id end |
#ssn ⇒ Object (readonly)
Returns the value of attribute ssn.
7 8 9 |
# File 'app/services/bgs/dependent_service.rb', line 7 def ssn @ssn end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
7 8 9 |
# File 'app/services/bgs/dependent_service.rb', line 7 def uuid @uuid end |
Instance Method Details
#external_key ⇒ Object (private)
107 108 109 110 111 112 |
# File 'app/services/bgs/dependent_service.rb', line 107 def external_key @external_key ||= begin key = common_name.presence || email key.first(Constants::EXTERNAL_KEY_MAX_LENGTH) end end |
#generate_hash_from_details ⇒ Object (private)
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/services/bgs/dependent_service.rb', line 134 def generate_hash_from_details { 'veteran_information' => { 'full_name' => { 'first' => first_name, 'middle' => middle_name, 'last' => last_name }, 'common_name' => common_name, 'va_profile_email' => @va_profile_email, 'email' => email, 'participant_id' => participant_id, 'ssn' => ssn, 'va_file_number' => file_number, 'birth_date' => birth_date, 'uuid' => uuid, 'icn' => icn } } end |
#get_dependents ⇒ Object
33 34 35 36 37 |
# File 'app/services/bgs/dependent_service.rb', line 33 def get_dependents return { persons: [] } if participant_id.blank? service.claimant.find_dependents_by_participant_id(participant_id, ssn) || { persons: [] } end |
#get_form_hash_686c ⇒ Object (private)
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/services/bgs/dependent_service.rb', line 114 def get_form_hash_686c bgs_person = service.people.find_person_by_ptcpnt_id(participant_id) || service.people.find_by_ssn(ssn) # rubocop:disable Rails/DynamicFindBy @file_number = bgs_person[:file_nbr] # BGS's file number is supposed to be an eight or nine-digit string, and # our code is built upon the assumption that this is the case. However, # we've seen cases where BGS returns a file number with dashes # (e.g. XXX-XX-XXXX). In this case specifically, we can simply strip out # the dashes and proceed with form submission. @file_number = file_number.delete('-') if file_number =~ /\A\d{3}-\d{2}-\d{4}\z/ # The `validate_*!` calls below will raise errors if we have an invalid # file number, or if the file number and SSN don't match. Even if this is # the case, we still want to submit a PDF to the veteran's VBMS eFolder. # This is because we are currently relying on the presence of a PDF and # absence of a BGS-established claim to identify cases where Form 686c-674 # submission failed. generate_hash_from_details end |
#service ⇒ Object (private)
64 65 66 |
# File 'app/services/bgs/dependent_service.rb', line 64 def service @service ||= BGS::Services.new(external_uid: icn, external_key:) end |
#submit_686c_form(claim) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/services/bgs/dependent_service.rb', line 39 def submit_686c_form(claim) Rails.logger.info('BGS::DependentService running!', { user_uuid: uuid, saved_claim_id: claim.id, icn: }) InProgressForm.find_by(form_id: BGS::SubmitForm686cJob::FORM_ID, user_uuid: uuid)&.submission_processing! encrypted_vet_info = KmsEncrypted::Box.new.encrypt(get_form_hash_686c.to_json) submit_pdf_job(claim:, encrypted_vet_info:) if claim.submittable_686? || claim.submittable_674? submit_form_job_id = submit_to_standard_service(claim:, encrypted_vet_info:) Rails.logger.info('BGS::DependentService succeeded!', { user_uuid: uuid, saved_claim_id: claim.id, icn: }) end { submit_form_job_id: } rescue => e Rails.logger.warn('BGS::DependentService#submit_686c_form method failed!', { user_uuid: uuid, saved_claim_id: claim.id, icn:, error: e. }) # rubocop:disable Layout/LineLength log_exception_to_sentry(e, { icn:, uuid: }, { team: Constants::SENTRY_REPORTING_TEAM }) raise e end |
#submit_pdf_job(claim:, encrypted_vet_info:) ⇒ Object (private)
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/services/bgs/dependent_service.rb', line 68 def submit_pdf_job(claim:, encrypted_vet_info:) Rails.logger.debug('BGS::DependentService#submit_pdf_job called to begin VBMS::SubmitDependentsPdfJob', { claim_id: claim.id }) VBMS::SubmitDependentsPdfJob.perform_sync( claim.id, encrypted_vet_info, claim.submittable_686?, claim.submittable_674? ) # This is now set to perform sync to catch errors and proceed to CentralForm submission in case of failure rescue => e # This indicated the method failed in this job method call, so we submit to Lighthouse Benefits Intake Rails.logger.warn('DependentService#submit_pdf_job method failed, submitting to Lighthouse Benefits Intake', { saved_claim_id: claim.id, icn:, error: e }) # rubocop:disable Layout/LineLength submit_to_central_service(claim:) raise e end |
#submit_to_central_service(claim:) ⇒ Object (private)
98 99 100 101 102 103 104 105 |
# File 'app/services/bgs/dependent_service.rb', line 98 def submit_to_central_service(claim:) vet_info = JSON.parse(claim.form)['dependents_application'] user = BGS::SubmitForm686cJob.generate_user_struct(vet_info) CentralMail::SubmitCentralForm686cJob.perform_async(claim.id, KmsEncrypted::Box.new.encrypt(vet_info.to_json), KmsEncrypted::Box.new.encrypt(user.to_h.to_json)) end |
#submit_to_standard_service(claim:, encrypted_vet_info:) ⇒ Object (private)
86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/services/bgs/dependent_service.rb', line 86 def submit_to_standard_service(claim:, encrypted_vet_info:) if claim.submittable_686? BGS::SubmitForm686cJob.perform_async( uuid, icn, claim.id, encrypted_vet_info ) else BGS::SubmitForm674Job.perform_async( uuid, icn, claim.id, encrypted_vet_info ) end end |