Skip to content

Commit

Permalink
Merge branch 'master' of github.com:department-of-veterans-affairs/ve…
Browse files Browse the repository at this point in the history
…ts-api into dh-btsss-78812
  • Loading branch information
hinzed1127 committed Sep 5, 2024
2 parents a2d0e5a + a42c775 commit 36f6532
Show file tree
Hide file tree
Showing 23 changed files with 268 additions and 509 deletions.
30 changes: 10 additions & 20 deletions app/models/saved_claim/coe_claim.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
# frozen_string_literal: true

require 'sentry_logging'

class SavedClaim::CoeClaim < SavedClaim
include SentryLogging

FORM = '26-1880'

def send_to_lgy(edipi:, icn:)
@edipi = edipi
@icn = icn

# If the EDIPI is blank, throw an error
if @edipi.blank?
log_message_to_sentry(
'COE application cannot be submitted without an edipi!',
:error,
{},
{ team: 'vfs-ebenefits' }
)
Rails.logger.error('COE application cannot be submitted without an edipi!')
# Otherwise, submit the claim to the LGY API
else
Rails.logger.info('Begin COE claim submission to LGY API', guid:)
response = lgy_service.put_application(payload: prepare_form_data)
Rails.logger.info('COE claim submitted to LGY API', guid:)

process_attachments!
response['reference_number']
end

response = lgy_service.put_application(payload: prepare_form_data)
log_message_to_sentry(
"COE claim submitted to LGY: #{guid}",
:warn,
{ attachment_id: guid },
{ team: 'vfs-ebenefits' }
)
process_attachments!
response['reference_number']
end

def regional_office
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddCiphertextFieldsToFormSubmissionAttempts < ActiveRecord::Migration[7.1]
def change
add_column :form_submission_attempts, :error_message_ciphertext, :text
add_column :form_submission_attempts, :response_ciphertext, :jsonb
end
end
4 changes: 3 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions lib/bgs/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,7 @@ def create_note(claim_id, note_text)
txt: note_text
}.merge!(bgs_auth).except!(:jrn_status_type_cd)

response = service.notes.create_note(option_hash)
message = if response[:note]
response[:note].slice(:clm_id, :txt)
else
response
end
log_message_to_sentry(message, :info, {}, { team: 'vfs-ebenefits' })
response
service.notes.create_note(option_hash)
rescue => e
notify_of_service_exception(e, __method__, 1, :warn)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def upload
@power_of_attorney.reload

# If upload is successful, then the PoaUpater job is also called to update the code in BGS.
ClaimsApi::PoaVBMSUploadJob.perform_async(@power_of_attorney.id)
ClaimsApi::PoaVBMSUploadJob.perform_async(@power_of_attorney.id, action: 'put')

render json: ClaimsApi::PowerOfAttorneySerializer.new(@power_of_attorney)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def validate_form_526_change_of_address_country

collect_error_messages(
source: '/changeOfAddress/country',
detail: 'The country provided is not a valid.'
detail: 'The country provided is not valid.'
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class PoaVBMSUploadJob < ClaimsApi::ServiceBase
# If successfully uploaded, it queues a job to update the POA code in BGS, as well.
#
# @param power_of_attorney_id [String] Unique identifier of the submitted POA
def perform(power_of_attorney_id)
def perform(power_of_attorney_id, action: 'post')
power_of_attorney = ClaimsApi::PowerOfAttorney.find(power_of_attorney_id)
uploader = ClaimsApi::PowerOfAttorneyUploader.new(power_of_attorney_id)
uploader.retrieve_from_store!(power_of_attorney.file_data['filename'])
file_path = fetch_file_path(uploader)

if Flipper.enabled?(:lighthouse_claims_api_poa_use_bd)
benefits_doc_api.upload(claim: power_of_attorney, pdf_path: file_path, doc_type: 'L075')
benefits_doc_api.upload(claim: power_of_attorney, pdf_path: file_path, action:, doc_type: 'L075')
else
upload_to_vbms(power_of_attorney, file_path)
end
Expand Down
29 changes: 17 additions & 12 deletions modules/claims_api/lib/bd/bd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def search(claim_id, file_number)
# Upload document of mapped claim
#
# @return success or failure
def upload(claim:, pdf_path:, doc_type: 'L122', file_number: nil, original_filename: nil, # rubocop:disable Metrics/ParameterLists
def upload(claim:, pdf_path:, doc_type: 'L122', action: 'post', file_number: nil, original_filename: nil, # rubocop:disable Metrics/ParameterLists
pctpnt_vet_id: nil)
unless File.exist? pdf_path
ClaimsApi::Logger.log('benefits_documents', detail: "Error uploading doc to BD: #{pdf_path} doesn't exist,
Expand All @@ -46,7 +46,7 @@ def upload(claim:, pdf_path:, doc_type: 'L122', file_number: nil, original_filen
end

@multipart = true
body = generate_upload_body(claim:, doc_type:, pdf_path:, file_number:, original_filename:,
body = generate_upload_body(claim:, doc_type:, pdf_path:, action:, file_number:, original_filename:,
pctpnt_vet_id:)
res = client.post('documents', body)&.body

Expand Down Expand Up @@ -100,18 +100,17 @@ def get_claim_id(doc_type, claim)
#
# @return {parameters, file}
# rubocop:disable Metrics/ParameterLists
def generate_upload_body(claim:, doc_type:, pdf_path:, file_number: nil, original_filename: nil,
def generate_upload_body(claim:, doc_type:, pdf_path:, action:, file_number: nil, original_filename: nil,
pctpnt_vet_id: nil)
payload = {}
auth_headers = claim.auth_headers
veteran_name = compact_veteran_name(auth_headers['va_eauth_firstName'], auth_headers['va_eauth_lastName'])
birls_file_num = auth_headers['va_eauth_birlsfilenumber'] || file_number if doc_type != 'L705'
claim_id = get_claim_id(doc_type, claim)
file_name = generate_file_name(doc_type:, veteran_name:, claim_id:, original_filename:)
file_name = generate_file_name(doc_type:, veteran_name:, claim_id:, original_filename:, action:)
participant_id = pctpnt_vet_id if %w[L075 L190 L705].include?(doc_type)
system_name = 'Lighthouse' if %w[L075 L190].include?(doc_type)
tracked_item_ids = claim.tracked_items&.map(&:to_i) if claim&.has_attribute?(:tracked_items)

data = build_body(doc_type:, file_name:, participant_id:, claim_id:,
file_number: birls_file_num, system_name:, tracked_item_ids:)

Expand All @@ -123,16 +122,22 @@ def generate_upload_body(claim:, doc_type:, pdf_path:, file_number: nil, origina
end
# rubocop:enable Metrics/ParameterLists

def generate_file_name(doc_type:, veteran_name:, claim_id:, original_filename:)
def generate_file_name(doc_type:, veteran_name:, claim_id:, original_filename:, action:)
# https://confluence.devops.va.gov/display/VAExternal/Document+Types
doc_type_to_form_name = {
'L075' => '21-22a',
'L122' => '526EZ',
'L190' => '21-22',
'L705' => '5103'
doc_type_names = {
'put' => {
'L075' => 'representative',
'L190' => 'representative'
},
'post' => {
'L075' => '21-22a',
'L122' => '526EZ',
'L190' => '21-22',
'L705' => '5103'
}
}

form_name = doc_type_to_form_name[doc_type]
form_name = doc_type_names[action][doc_type]

if form_name
"#{[veteran_name, claim_id, form_name].compact_blank.join('_')}.pdf"
Expand Down
84 changes: 59 additions & 25 deletions modules/claims_api/spec/lib/claims_api/bd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
end

it 'uploads an attachment to BD for L023' do
result = subject.send(:generate_upload_body, claim:, doc_type: 'L023', pdf_path:,
result = subject.send(:generate_upload_body, claim:, doc_type: 'L023', pdf_path:, action: 'post',
original_filename: 'stuff.pdf')
js = JSON.parse(result[:parameters].read)
expect(js['data']['docType']).to eq 'L023'
Expand All @@ -42,7 +42,7 @@

it 'uploads an attachment to BD for L122' do
result = subject.send(:generate_upload_body, claim:, doc_type: 'L122', original_filename: '21-526EZ.pdf',
pdf_path:)
pdf_path:, action: 'post')
js = JSON.parse(result[:parameters].read)
expect(js['data']['docType']).to eq 'L122'
expect(js['data']['claimId']).to eq claim.evss_id
Expand Down Expand Up @@ -87,7 +87,7 @@
context 'when the doctype is L190' do
let(:pdf_path) { 'modules/claims_api/spec/fixtures/21-22/signed_filled_final.pdf' }
let(:json_body) do
res = subject.send(:generate_upload_body, claim: power_of_attorney, pdf_path:,
res = subject.send(:generate_upload_body, claim: power_of_attorney, pdf_path:, action: 'post',
doc_type: 'L190')
temp_io = res[:parameters].instance_variable_get(:@io).path
temp_io_contents = File.read(temp_io)
Expand All @@ -112,29 +112,63 @@
end

context 'when the doctype is L075' do
let(:pdf_path) { 'modules/claims_api/spec/fixtures/21-22A/signed_filled_final.pdf' }
let(:json_body) do
res = subject.send(:generate_upload_body, claim: power_of_attorney, pdf_path:,
doc_type: 'L075')
temp_io = res[:parameters].instance_variable_get(:@io).path
temp_io_contents = File.read(temp_io)
JSON.parse(temp_io_contents)
end

it 'the systemName is Lighthouse' do
expect(json_body['data']['systemName']).to eq('Lighthouse')
end

it 'the docType is L075' do
expect(json_body['data']['docType']).to eq('L075')
context 'when the api version is v2' do
let(:pdf_path) { 'modules/claims_api/spec/fixtures/21-22A/signed_filled_final.pdf' }
let(:json_body) do
res = subject.send(:generate_upload_body, claim: power_of_attorney, pdf_path:, action: 'post',
doc_type: 'L075')
temp_io = res[:parameters].instance_variable_get(:@io).path
temp_io_contents = File.read(temp_io)
JSON.parse(temp_io_contents)
end

it 'the systemName is Lighthouse' do
expect(json_body['data']['systemName']).to eq('Lighthouse')
end

it 'the docType is L075' do
expect(json_body['data']['docType']).to eq('L075')
end

it 'the fileName ends in 21-22a.pdf' do
expect(json_body['data']['fileName']).to end_with('21-22a.pdf')
end

it 'the claimId is not present' do
expect(json_body['data']).not_to have_key('claimId')
end
end

it 'the fileName ends in 21-22a.pdf' do
expect(json_body['data']['fileName']).to end_with('21-22a.pdf')
end

it 'the claimId is not present' do
expect(json_body['data']).not_to have_key('claimId')
context 'when the api version is v1' do
context 'the doc type is 21-22a' do
let(:pdf_path) { 'modules/claims_api/spec/fixtures/21-22A/signed_filled_final.pdf' }
let(:json_body) do
res = subject.send(:generate_upload_body, claim: power_of_attorney, pdf_path:, action: 'put',
doc_type: 'L075')
temp_io = res[:parameters].instance_variable_get(:@io).path
temp_io_contents = File.read(temp_io)
JSON.parse(temp_io_contents)
end

it 'the fileName ends in representative.pdf' do
expect(json_body['data']['fileName']).to end_with('_representative.pdf')
end
end

context 'the doc type is 21-22' do
let(:pdf_path) { 'modules/claims_api/spec/fixtures/21-22/signed_filled_final.pdf' }
let(:json_body) do
res = subject.send(:generate_upload_body, claim: power_of_attorney, pdf_path:, action: 'put',
doc_type: 'L190')
temp_io = res[:parameters].instance_variable_get(:@io).path
temp_io_contents = File.read(temp_io)
JSON.parse(temp_io_contents)
end

it 'the fileName ends in representative.pdf' do
expect(json_body['data']['fileName']).to end_with('_representative.pdf')
end
end
end
end
end
Expand Down Expand Up @@ -162,7 +196,7 @@
describe '#generate_upload_body' do
it 'uploads an attachment to BD for L705' do
result = subject.send(:generate_upload_body, claim: ews, doc_type: 'L705', original_filename: '5103.pdf',
pdf_path:)
pdf_path:, action: 'post')
js = JSON.parse(result[:parameters].read)
expect(js['data']['docType']).to eq 'L705'
expect(js['data']['claimId']).to eq ews.claim_id
Expand Down
Loading

0 comments on commit 36f6532

Please sign in to comment.