Skip to content

Commit

Permalink
Api 41362 dependent poa file upload. (v1 & v2) (#19165)
Browse files Browse the repository at this point in the history
* WIP

* WIP

* API-41362-v2-dependent-poa-file-upload

* Updates dependent headers setting for POA V1
* Updates relevant tests
	modified:   modules/claims_api/app/controllers/claims_api/v1/forms/power_of_attorney_controller.rb
	modified:   modules/claims_api/spec/requests/v1/forms/2122_spec.rb

* API-41362-v2-dependent-poa-file-upload

* fxes the workflow so when a dependent is on the claim it does not call POAUpdater job which end up updating for the veteran not the dependent
	modified:   modules/claims_api/app/controllers/claims_api/v1/forms/power_of_attorney_controller.rb
	modified:   modules/claims_api/app/controllers/claims_api/v2/veterans/power_of_attorney/base_controller.rb
	modified:   modules/claims_api/app/services/claims_api/document_service_base.rb
	modified:   modules/claims_api/app/services/claims_api/evidence_waiver_document_service.rb
	modified:   modules/claims_api/app/services/claims_api/poa_document_service.rb
	modified:   modules/claims_api/app/sidekiq/claims_api/poa_assign_dependent_claimant_job.rb
	modified:   modules/claims_api/app/sidekiq/claims_api/poa_updater.rb
	modified:   modules/claims_api/app/sidekiq/claims_api/service_base.rb
	modified:   modules/claims_api/app/sidekiq/claims_api/v1/poa_form_builder_job.rb
	modified:   modules/claims_api/app/sidekiq/claims_api/v2/poa_form_builder_job.rb
	modified:   modules/claims_api/spec/requests/v1/forms/2122_spec.rb
	modified:   modules/claims_api/spec/sidekiq/poa_assign_dependent_claimant_job_spec.rb

* Reverts Gemfile.lock change

* Removes comment that landed in wrong spot

* API-41362-v2-dependent-poa-file-upload

* Updates handling the assignment service n the job
	* Reverts back to returning `nil` for bang method
* Fixes typo
* Cleans up file name setting methods/workflow

	modified:   modules/claims_api/app/services/claims_api/dependent_claimant_poa_assignment_service.rb
	modified:   modules/claims_api/app/services/claims_api/disability_compensation/disability_document_service.rb
	modified:   modules/claims_api/app/services/claims_api/document_service_base.rb
	modified:   modules/claims_api/app/services/claims_api/evidence_waiver_document_service.rb
	modified:   modules/claims_api/app/services/claims_api/poa_document_service.rb
	modified:   modules/claims_api/app/sidekiq/claims_api/poa_assign_dependent_claimant_job.rb
	modified:   modules/claims_api/app/sidekiq/claims_api/service_base.rb

* Updates POA after depedent assignment and logs outcome at that point

* Adjusts broken test, refactors one small settings check in controler, fixes value check
  • Loading branch information
rockwellwindsor-va authored Nov 4, 2024
1 parent d56fc68 commit deb41e2
Show file tree
Hide file tree
Showing 15 changed files with 368 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def submit_form_2122 # rubocop:disable Metrics/MethodLength
validate_poa_code!(poa_code)
validate_poa_code_for_current_user!(poa_code) if header_request? && !token.client_credentials_token?
file_number = check_file_number_exists!
dependent_participant_id, claimant_ssn = validate_dependent_claimant!(poa_code:)
claimant_information = validate_dependent_claimant!(poa_code:)

power_of_attorney = ClaimsApi::PowerOfAttorney.find_using_identifier_and_source(header_md5:,
source_name:)
Expand All @@ -48,18 +48,22 @@ def submit_form_2122 # rubocop:disable Metrics/MethodLength
unless power_of_attorney.persisted?
power_of_attorney = ClaimsApi::PowerOfAttorney.find_by(md5: power_of_attorney.md5)
end

if feature_enabled_and_claimant_present?
update_auth_headers_for_dependent(
power_of_attorney,
claimant_information
)
end

power_of_attorney.auth_headers['participant_id'] = target_veteran.participant_id
power_of_attorney.auth_headers['file_number'] = file_number
power_of_attorney.save!
end

data = power_of_attorney.form_data

if feature_enabled_and_claimant_present?
ClaimsApi::PoaAssignDependentClaimantJob.perform_async(
dependent_claimant_poa_assignment_service(poa_code:, file_number:, dependent_participant_id:,
claimant_ssn:)
)
elsif data.dig('signatures', 'veteran').present? && data.dig('signatures', 'representative').present?
if data.dig('signatures', 'veteran').present? && data.dig('signatures', 'representative').present?
# Autogenerate a 21-22 form from the request body and upload it to VBMS.
# If upload is successful, then the PoaUpater job is also called to update the code in BGS.
ClaimsApi::V1::PoaFormBuilderJob.perform_async(power_of_attorney.id, 'post')
Expand Down Expand Up @@ -153,6 +157,19 @@ def validate

private

def update_auth_headers_for_dependent(poa, claimant_information)
auth_headers = poa.auth_headers

auth_headers.merge!({
dependent: {
first_name: claimant_information['claimant_first_name'],
last_name: claimant_information['claimant_last_name'],
participant_id: claimant_information['claimant_participant_id'],
ssn: claimant_information['claimant_ssn']
}
})
end

def feature_enabled_and_claimant_present?
Flipper.enabled?(:lighthouse_claims_api_poa_dependent_claimants) &&
form_attributes['claimant'].present?
Expand All @@ -172,19 +189,12 @@ def validate_dependent_claimant!(poa_code:)
service.validate_poa_code_exists!
service.validate_dependent_by_participant_id!

[service.claimant_participant_id, service.claimant_ssn]
end

def dependent_claimant_poa_assignment_service(poa_code:, file_number:, dependent_participant_id:, claimant_ssn:)
ClaimsApi::DependentClaimantPoaAssignmentService.new(
poa_code:,
veteran_participant_id: target_veteran.participant_id,
dependent_participant_id:,
veteran_file_number: file_number,
allow_poa_access: form_attributes[:recordConsent].present? ? 'Y' : nil,
allow_poa_cadd: form_attributes[:consentAddressChange].present? ? 'Y' : nil,
claimant_ssn:
)
{
'claimant_participant_id' => service.claimant_participant_id,
'claimant_first_name' => claimant_first_name,
'claimant_last_name' => claimant_last_name,
'claimant_ssn' => service.claimant_ssn
}
end

def current_poa_begin_date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,6 @@ def feature_enabled_and_claimant_present?
Flipper.enabled?(:lighthouse_claims_api_poa_dependent_claimants) && form_attributes['claimant'].present?
end

def dependent_claimant_poa_assignment_service(poa_code:)
# Assign the veteranʼs file number
file_number_check

claimant = user_profile.profile

ClaimsApi::DependentClaimantPoaAssignmentService.new(
poa_code:,
veteran_participant_id: target_veteran.participant_id,
dependent_participant_id: claimant.participant_id,
veteran_file_number: @file_number,
allow_poa_access: form_attributes[:recordConsent].present? ? 'Y' : nil,
allow_poa_cadd: form_attributes[:consentAddressChange].present? ? 'Y' : nil,
claimant_ssn: claimant.ssn
)
end

def validate_registration_number!(base, poa_code)
rn = form_attributes.dig(base, 'registrationNumber')
rep = ::Veteran::Service::Representative.where('? = ANY(poa_codes) AND representative_id = ?',
Expand All @@ -102,7 +85,7 @@ def validate_registration_number!(base, poa_code)
def attributes
{
status: ClaimsApi::PowerOfAttorney::PENDING,
auth_headers: auth_headers.merge!({ VA_NOTIFY_KEY => icn_for_vanotify }),
auth_headers: set_auth_headers,
form_data: form_attributes,
current_poa: current_poa_code,
header_md5:
Expand All @@ -114,14 +97,8 @@ def submit_power_of_attorney(poa_code, form_number)

power_of_attorney = ClaimsApi::PowerOfAttorney.create!(attributes)

unless Settings.claims_api&.poa_v2&.disable_jobs
if feature_enabled_and_claimant_present?
ClaimsApi::PoaAssignDependentClaimantJob.perform_async(
dependent_claimant_poa_assignment_service(poa_code:)
)
else
ClaimsApi::V2::PoaFormBuilderJob.perform_async(power_of_attorney.id, form_number, @rep_id, 'post')
end
unless disable_jobs?
ClaimsApi::V2::PoaFormBuilderJob.perform_async(power_of_attorney.id, form_number, @rep_id, 'post')
end

render json: ClaimsApi::V2::Blueprints::PowerOfAttorneyBlueprint.render(
Expand All @@ -132,6 +109,29 @@ def submit_power_of_attorney(poa_code, form_number)
)
end

def set_auth_headers
headers = auth_headers.merge!({ VA_NOTIFY_KEY => icn_for_vanotify })

if feature_enabled_and_claimant_present?
add_dependent_to_auth_headers(headers)
else
auth_headers
end
end

def add_dependent_to_auth_headers(headers)
claimant = user_profile.profile

headers.merge!({
dependent: {
participant_id: claimant.participant_id,
ssn: claimant.ssn,
first_name: claimant.given_names[0],
last_name: claimant.family_name
}
})
end

def validation_success(form_number)
{
data: {
Expand Down Expand Up @@ -242,6 +242,10 @@ def fetch_claimant
mpi_profile
end

def disable_jobs?
Settings.claims_api&.poa_v2&.disable_jobs
end

def add_claimant_data_to_form
if user_profile&.status == :ok
first_name = user_profile.profile.given_names.first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def create_upload(claim:, pdf_path:, doc_type: 'L122', original_filename: nil)
# @return {parameters, file}
def generate_body(claim:, doc_type:, pdf_path:, original_filename: nil)
auth_headers = claim.auth_headers
veteran_name = compact_veteran_name(auth_headers['va_eauth_firstName'],
auth_headers['va_eauth_lastName'])
veteran_name = compact_name_for_file(auth_headers['va_eauth_firstName'],
auth_headers['va_eauth_lastName'])
birls_file_number = auth_headers['va_eauth_birlsfilenumber']
claim_id = claim.evss_id
form_name = doc_type == 'L122' ? '526EZ' : 'supporting'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def generate_upload_body(claim_id:, system_name:, doc_type:, pdf_path:, file_nam
end
# rubocop:enable Metrics/ParameterLists

def compact_veteran_name(first_name, last_name)
def compact_name_for_file(first_name, last_name)
[first_name, last_name].compact_blank.join('_')
end

Expand All @@ -37,6 +37,19 @@ def find_ptcpnt_vet_id(auth_headers, ptcpnt_vet_id)
ptcpnt_vet_id.presence || auth_headers['va_eauth_pid']
end

def file_name(record, veteran_name, form_suffix)
build_file_name(
veteran_name:,
identifier: record.id,
suffix: form_suffix,
dependent: dependent_filing?(record)
)
end

def dependent_filing?(record)
record.auth_headers['dependent']
end

private

def build_body(options = {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,13 @@ def create_upload(claim:, pdf_path:, doc_type:, ptcpnt_vet_id:)
# @return {parameters, file}
def generate_body(claim:, doc_type:, pdf_path:, ptcpnt_vet_id:)
auth_headers = claim.auth_headers
veteran_name = compact_veteran_name(auth_headers['va_eauth_firstName'],
auth_headers['va_eauth_lastName'])
veteran_name = compact_name_for_file(auth_headers['va_eauth_firstName'],
auth_headers['va_eauth_lastName'])
tracked_item_ids = claim.tracked_items&.map(&:to_i) if claim&.has_attribute?(:tracked_items)

generate_upload_body(claim_id: claim.claim_id, system_name: 'VA.gov', doc_type:, pdf_path:,
file_name: file_name(claim, veteran_name), birls_file_number: nil,
file_name: file_name(claim, veteran_name, FORM_SUFFIX), birls_file_number: nil,
participant_id: ptcpnt_vet_id, tracked_item_ids:)
end

def dependent_filing?(claim)
claim.auth_headers['dependent']
end

def file_name(claim, veteran_name)
build_file_name(
veteran_name:,
identifier: claim.id,
suffix: FORM_SUFFIX,
dependent: dependent_filing?(claim)
)
end
end
end
25 changes: 18 additions & 7 deletions modules/claims_api/app/services/claims_api/poa_document_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,29 @@ def create_upload(poa:, pdf_path:, doc_type:, action:)
# @return {parameters, file}
def generate_body(poa:, doc_type:, pdf_path:, action:)
auth_headers = poa.auth_headers
veteran_name = compact_veteran_name(auth_headers['va_eauth_firstName'],
auth_headers['va_eauth_lastName'])
name_on_file = build_name_for_file(poa)

ptcpnt_vet_id = auth_headers['va_eauth_pid']
participant_id = find_ptcpnt_vet_id(auth_headers, ptcpnt_vet_id)
form_name = get_form_name(action:, doc_type:)
file_name = build_file_name(veteran_name:, identifier: nil, suffix: form_name)
form_suffix = get_form_suffix(action:, doc_type:)

generate_upload_body(claim_id: nil, system_name: 'Lighthouse', doc_type:, pdf_path:,
file_name: file_name(poa, name_on_file, form_suffix), birls_file_number: nil,
participant_id:, tracked_item_ids: nil)
end

def build_name_for_file(poa)
first_name, last_name = if dependent_filing?(poa)
[poa.auth_headers['dependent']['first_name'],
poa.auth_headers['dependent']['last_name']]
else
[poa.auth_headers['va_eauth_firstName'], poa.auth_headers['va_eauth_lastName']]
end

generate_upload_body(claim_id: nil, system_name: 'Lighthouse', doc_type:, pdf_path:, file_name:,
birls_file_number: nil, participant_id:, tracked_item_ids: nil)
compact_name_for_file(first_name, last_name)
end

def get_form_name(action:, doc_type:)
def get_form_suffix(action:, doc_type:)
doc_type_form_names = {
'put' => {
'L075' => 'representative',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,63 @@

module ClaimsApi
class PoaAssignDependentClaimantJob < ClaimsApi::ServiceBase
def perform(dependent_claimant_poa_assignment_service)
dependent_claimant_poa_assignment_service.assign_poa_to_dependent!
LOG_TAG = 'poa_assign_dependent_claimant_job'

def perform(poa_id)
poa = ClaimsApi::PowerOfAttorney.find(poa_id)

service = dependent_claimant_poa_assignment_service(
poa.form_data,
poa.auth_headers
)

begin
service.assign_poa_to_dependent!
rescue => e
handle_error(poa, e)
end

poa.status = ClaimsApi::PowerOfAttorney::UPDATED
# Clear out the error message if there were previous failures
poa.vbms_error_message = nil if poa.vbms_error_message.present?

poa.save

log_job_progress(
poa.id,
'POA assigned for dependent'
)

ClaimsApi::PoaVBMSUpdater.perform_async(poa.id) if enable_vbms_access?(poa_form: poa)
end

private

def handle_error(poa, e)
save_poa_errored_state(poa)
set_vbms_error_message(poa, e)
log_job_progress(
poa.id,
'Dependent Assignment failed'
)
raise e
end

def dependent_claimant_poa_assignment_service(data, auth_headers)
ClaimsApi::DependentClaimantPoaAssignmentService.new(
poa_code: find_poa_code(data),
veteran_participant_id: auth_headers['va_eauth_pid'],
dependent_participant_id: auth_headers.dig('dependent', 'participant_id'),
veteran_file_number: auth_headers['file_number'],
allow_poa_access: data['recordConsent'].present? ? 'Y' : nil,
allow_poa_cadd: data['consentAddressChange'].present? ? 'Y' : nil,
claimant_ssn: auth_headers.dig('dependent', 'ssn')
)
end

def find_poa_code(data)
base = data.key?('serviceOrganization') ? 'serviceOrganization' : 'representative'
data.dig(base, 'poaCode')
end
end
end
4 changes: 0 additions & 4 deletions modules/claims_api/app/sidekiq/claims_api/poa_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ def perform(power_of_attorney_id, rep = nil) # rubocop:disable Metrics/MethodLen

private

def enable_vbms_access?(poa_form:)
poa_form.form_data['recordConsent'] && poa_form.form_data['consentLimits'].blank?
end

def vanotify?(auth_headers, rep)
if Flipper.enabled?(:lighthouse_claims_api_v2_poa_va_notify)
auth_headers.key?(ClaimsApi::V2::Veterans::PowerOfAttorney::BaseController::VA_NOTIFY_KEY) && rep.present?
Expand Down
Loading

0 comments on commit deb41e2

Please sign in to comment.