Skip to content

Commit

Permalink
Added BGS\MPI ICn lookup via fileNumber (#19862)
Browse files Browse the repository at this point in the history
* Added BGS\MPI ICn lookup via fileNumber
  • Loading branch information
michelpmcdonald authored Dec 17, 2024
1 parent ef3c028 commit dfb5072
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
42 changes: 42 additions & 0 deletions modules/vba_documents/spec/sidekiq/upload_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand All @@ -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
Expand Down

0 comments on commit dfb5072

Please sign in to comment.