From dfb507277c63bf84bbc4b28ed8f530972dd661bc Mon Sep 17 00:00:00 2001 From: Mike McDonald <865014+michelpmcdonald@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:46:35 -0500 Subject: [PATCH] Added BGS\MPI ICn lookup via fileNumber (#19862) * Added BGS\MPI ICn lookup via fileNumber --- .../sidekiq/vba_documents/upload_processor.rb | 34 +++++++++++++++ .../spec/sidekiq/upload_processor_spec.rb | 42 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/modules/vba_documents/app/sidekiq/vba_documents/upload_processor.rb b/modules/vba_documents/app/sidekiq/vba_documents/upload_processor.rb index 46c7bbee60b..876eff3ba72 100644 --- a/modules/vba_documents/app/sidekiq/vba_documents/upload_processor.rb +++ b/modules/vba_documents/app/sidekiq/vba_documents/upload_processor.rb @@ -64,6 +64,10 @@ def download_and_process pdf_validator_options = VBADocuments::DocumentRequestValidator.pdf_validator_options validate_documents(parts, pdf_validator_options) + # attempt to use consumer's file number field to look up the claiments ICN + icn = find_icn(metadata['fileNumber']) + metadata['ICN'] = icn if icn.present? + response = submit(metadata, parts) process_response(response) @@ -90,6 +94,36 @@ def original_file_metadata(tempfile) } end + def find_icn(file_number) + bgss = BGS::Services.new(external_uid: file_number, external_key: file_number) + + # File Number is ssn, file number, or participant id. Call BGS to get the + # veterans birthdate + # rubocop:disable Rails/DynamicFindBy + bgs_vet = bgss.people.find_by_ssn(file_number) || # rubocop:disable Rails/DynamicFindBy + bgss.people.find_by_file_number(file_number) || + bgss.people.find_person_by_ptcpnt_id(file_number) + # rubocop:enable Rails/DynamicFindBy + return nil if bgs_vet.blank? + + # Go after ICN in MPI + mpi = MPI::Service.new + r = mpi.find_profile_by_attributes(first_name: bgs_vet[:first_nm].to_s, + last_name: bgs_vet[:last_nm].to_s, + ssn: bgs_vet[:ssn_nbr].to_s, + birth_date: bgs_vet[:brthdy_dt].strftime('%Y-%m-%d')) + return nil if r.blank? || r.profile.blank? + + r.profile.icn + + # at this point ICN is not required when submitting to EMMS, so have wide + # exception handling, log and move on, any errors trying to get ICN should not stop us from submitting + rescue => e + Rails.logger.error("Benefits Intake UploadProcessor find_icn failed. Guid: #{@upload.guid}, " \ + "Exception: #{e.message}") + nil + end + def validate_payload_size(tempfile) unless tempfile.size.positive? raise VBADocuments::UploadError.new(code: 'DOC107', detail: VBADocuments::UploadError::DOC107) diff --git a/modules/vba_documents/spec/sidekiq/upload_processor_spec.rb b/modules/vba_documents/spec/sidekiq/upload_processor_spec.rb index 8718dd4f676..33d0262ace5 100644 --- a/modules/vba_documents/spec/sidekiq/upload_processor_spec.rb +++ b/modules/vba_documents/spec/sidekiq/upload_processor_spec.rb @@ -83,6 +83,24 @@ allow(bucket).to receive(:object).and_return(obj) allow(obj).to receive(:exists?).and_return(true) allow(version).to receive(:last_modified).and_return(DateTime.now.utc) + + # Stub BGS(part of ICN lookup) + people_double = double + allow(people_double).to receive(:find_by_ssn).and_return({ first_nm: 'JOE', last_nm: 'SMITH', + ssn_nbr: '555-55-5555', + brthdy_dt: Date.parse('1970-01-01') }) + bgs_double = instance_double('BGS::Services') + allow(bgs_double).to receive(:people).and_return(people_double) + allow(BGS::Services).to receive(:new).and_return(bgs_double) + + # Stub MPI(part of ICN lookup) + profile_double = double + allow(profile_double).to receive(:icn).and_return('2112') + mpi_result = double + allow(mpi_result).to receive(:profile).and_return(profile_double) + mpi_double = instance_double('MPI::Service') + allow(mpi_double).to receive(:find_profile_by_attributes).and_return(mpi_result) + allow(MPI::Service).to receive(:new).and_return(mpi_double) end describe '#perform' do @@ -195,6 +213,29 @@ expect(updated.status).to eq('received') end + it 'parses and uploads a valid multipart payload when ICN lookup throws exception' do + allow(BGS::Services).to receive(:new).and_raise('Worst day ever') + expect(Rails.logger).to receive(:error).with( + "Benefits Intake UploadProcessor find_icn failed. Guid: #{upload.guid}, Exception: Worst day ever" + ) + allow(VBADocuments::MultipartParser).to receive(:parse) { valid_parts } + allow(CentralMail::Service).to receive(:new) { client_stub } + allow(faraday_response).to receive_messages(status: 200, body: '', success?: true) + capture_body = nil + expect(client_stub).to receive(:upload) { |arg| + capture_body = arg + faraday_response + } + described_class.new.perform(upload.guid, test_caller) + expect(capture_body).to be_a(Hash) + expect(capture_body).to have_key('metadata') + expect(capture_body).to have_key('document') + metadata = JSON.parse(capture_body['metadata']) + expect(metadata['uuid']).to eq(upload.guid) + updated = VBADocuments::UploadSubmission.find_by(guid: upload.guid) + expect(updated.status).to eq('received') + end + it 'parses and uploads a valid multipart payload with attachments' do allow(VBADocuments::MultipartParser).to receive(:parse) { valid_parts_attachment } allow(CentralMail::Service).to receive(:new) { client_stub } @@ -213,6 +254,7 @@ expect(metadata['uuid']).to eq(upload.guid) expect(metadata['source']).to eq('test consumer via VA API') expect(metadata['numberAttachments']).to eq(1) + expect(metadata['ICN']).to eq('2112') updated = VBADocuments::UploadSubmission.find_by(guid: upload.guid) expect(updated.status).to eq('received') end