Skip to content

Commit

Permalink
[12331] Refactor BGS Services to more clearly show what User model fi…
Browse files Browse the repository at this point in the history
…elds are being leveraged (#12332)

Co-authored-by: Trevor Bosaw <trevor.bosaw@oddball.io>
  • Loading branch information
bosawt and Trevor Bosaw authored Apr 14, 2023
1 parent a57550d commit 926b2c3
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 179 deletions.
23 changes: 0 additions & 23 deletions app/models/vet_info.rb

This file was deleted.

45 changes: 26 additions & 19 deletions app/services/bgs/awards_service.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
# frozen_string_literal: true

module BGS
##
# Allows retrieval of composite monetary award amounts that veterans are entitled
#
class AwardsService < BaseService
##
# Gets composite monetary awards that veterans are entitled along with relevant metadata
#
# @return [Hash]
#
class AwardsService
include SentryLogging

attr_reader :participant_id, :ssn, :common_name, :email, :icn

def initialize(user)
@participant_id = user.participant_id
@ssn = user.ssn
@common_name = user.common_name
@email = user.email
@icn = user.icn
end

def get_awards
@service.awards.find_award_by_participant_id(@user.participant_id, @user.ssn) ||
@service.awards.find_award_by_ssn(@user.ssn)
service.awards.find_award_by_participant_id(participant_id, ssn) || service.awards.find_award_by_ssn(ssn)
rescue => e
report_error(e)
log_exception_to_sentry(e, { icn: }, { team: Constants::SENTRY_REPORTING_TEAM })
end

private

def service
@service ||= BGS::Services.new(external_uid: icn, external_key:)
end

##
# Returns gross amount of composite monetary awards veteran is entitled to
#
# @return [String]
#
def gross_amount
get_awards[:gross_amt]
def external_key
@external_key ||= begin
key = common_name.presence || email
key.first(Constants::EXTERNAL_KEY_MAX_LENGTH)
end
end
end
end
39 changes: 0 additions & 39 deletions app/services/bgs/base_service.rb

This file was deleted.

8 changes: 8 additions & 0 deletions app/services/bgs/constants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

module BGS
module Constants
EXTERNAL_KEY_MAX_LENGTH = 39
SENTRY_REPORTING_TEAM = 'vfs-ebenefits'
end
end
35 changes: 29 additions & 6 deletions app/services/bgs/dependency_verification_service.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
# frozen_string_literal: true

module BGS
class DependencyVerificationService < BaseService
class DependencyVerificationService
include SentryLogging

attr_reader :participant_id, :ssn, :common_name, :email, :icn

def initialize(user)
@participant_id = user.participant_id
@ssn = user.ssn
@common_name = user.common_name
@email = user.email
@icn = user.icn
end

def read_diaries
diaries = @service.diaries.read_diaries(
diaries = service.diaries.read_diaries(
{
beneficiary_id: @user.participant_id,
participant_id: @user.participant_id,
ssn: @user.ssn,
beneficiary_id: participant_id,
participant_id:,
ssn:,
award_type: 'CPL'
}
)
Expand All @@ -18,7 +30,7 @@ def read_diaries

standard_response(diaries)
rescue => e
report_error(e)
log_exception_to_sentry(e, { icn: }, { team: Constants::SENTRY_REPORTING_TEAM })
end

private
Expand Down Expand Up @@ -54,5 +66,16 @@ def normalize_dependency_decisions(dependency_decisions)

final
end

def service
@service ||= BGS::Services.new(external_uid: icn, external_key:)
end

def external_key
@external_key ||= begin
key = common_name.presence || email
key.first(Constants::EXTERNAL_KEY_MAX_LENGTH)
end
end
end
end
74 changes: 62 additions & 12 deletions app/services/bgs/dependent_service.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,82 @@
# frozen_string_literal: true

module BGS
class DependentService < BaseService
class DependentService
include SentryLogging

attr_reader :first_name,
:middle_name,
:last_name,
:ssn,
:birth_date,
:common_name,
:email,
:icn,
:participant_id,
:uuid

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
end

def get_dependents
@service.claimant.find_dependents_by_participant_id(@user.participant_id, @user.ssn) || { persons: [] }
service.claimant.find_dependents_by_participant_id(participant_id, ssn) || { persons: [] }
end

def submit_686c_form(claim)
bgs_person = @service.people.find_person_by_ptcpnt_id(@user.participant_id)

# rubocop:disable Rails/DynamicFindBy
bgs_person = @service.people.find_by_ssn(@user.ssn) if bgs_person.nil?
# rubocop:enable Rails/DynamicFindBy
bgs_person = service.people.find_person_by_ptcpnt_id(participant_id)

vet_info = VetInfo.new(@user, bgs_person)
bgs_person = service.people.find_by_ssn(ssn) if bgs_person.nil? # rubocop:disable Rails/DynamicFindBy

vet_info_686c_form_hash = vet_info.to_686c_form_hash
form_hash_686c = get_form_hash_686c(file_number: bgs_person[:file_nbr].to_s)

BGS::SubmitForm686cJob.perform_async(@user.uuid, claim.id, vet_info_686c_form_hash) if claim.submittable_686?
BGS::SubmitForm686cJob.perform_async(uuid, claim.id, form_hash_686c) if claim.submittable_686?

VBMS::SubmitDependentsPdfJob.perform_async(
claim.id,
vet_info_686c_form_hash,
form_hash_686c,
claim.submittable_686?,
claim.submittable_674?
)
rescue => e
report_error(e)
log_exception_to_sentry(e, { icn: }, { team: Constants::SENTRY_REPORTING_TEAM })
end

private

def service
@service ||= BGS::Services.new(external_uid: icn, external_key:)
end

def external_key
@external_key ||= begin
key = common_name.presence || email
key.first(Constants::EXTERNAL_KEY_MAX_LENGTH)
end
end

def get_form_hash_686c(file_number:)
{
'veteran_information' => {
'full_name' => {
'first' => first_name,
'middle' => middle_name,
'last' => last_name
},
'ssn' => ssn,
'va_file_number' => file_number,
'birth_date' => birth_date
}
}
end
end
end
7 changes: 0 additions & 7 deletions app/services/bgs/errors.rb

This file was deleted.

27 changes: 24 additions & 3 deletions app/services/bgs/payment_service.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# frozen_string_literal: true

module BGS
class PaymentService < BaseService
class PaymentService
include SentryLogging

attr_reader :common_name, :email, :icn

def initialize(user)
@common_name = user.common_name
@email = user.email
@icn = user.icn
end

def payment_history(person)
response = @service.payment_information.retrieve_payment_summary_with_bdn(
response = service.payment_information.retrieve_payment_summary_with_bdn(
person.participant_id,
person.file_number,
'00', # payee code
Expand All @@ -13,12 +23,23 @@ def payment_history(person)

response
rescue => e
report_error(e)
log_exception_to_sentry(e, { icn: }, { team: Constants::SENTRY_REPORTING_TEAM })
empty_response if e.message.include?('No Data Found')
end

private

def service
@service ||= BGS::Services.new(external_uid: icn, external_key:)
end

def external_key
@external_key ||= begin
key = common_name.presence || email
key.first(Constants::EXTERNAL_KEY_MAX_LENGTH)
end
end

def empty_response
{ payments: { payment: [] } }
end
Expand Down
39 changes: 35 additions & 4 deletions app/services/bgs/people/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,48 @@

module BGS
module People
class Service < BaseService
class Service
class VAFileNumberNotFound < StandardError; end

include SentryLogging

attr_reader :ssn,
:participant_id,
:common_name,
:email,
:icn

def initialize(user)
@ssn = user.ssn
@participant_id = user.participant_id
@common_name = user.common_name
@email = user.email
@icn = user.icn
end

def find_person_by_participant_id
raw_response = @service.people.find_person_by_ptcpnt_id(@user.participant_id, @user.ssn)
report_error(VAFileNumberNotFound.new) if raw_response.blank?
raw_response = service.people.find_person_by_ptcpnt_id(participant_id, ssn)
if raw_response.blank?
log_exception_to_sentry(VAFileNumberNotFound.new, { icn: }, { team: Constants::SENTRY_REPORTING_TEAM })
end
BGS::People::Response.new(raw_response, status: :ok)
rescue => e
report_error(e)
log_exception_to_sentry(e, { icn: }, { team: Constants::SENTRY_REPORTING_TEAM })
BGS::People::Response.new(nil, status: :error)
end

private

def service
@service ||= BGS::Services.new(external_uid: icn, external_key:)
end

def external_key
@external_key ||= begin
key = common_name.presence || email
key.first(Constants::EXTERNAL_KEY_MAX_LENGTH)
end
end
end
end
end
Loading

0 comments on commit 926b2c3

Please sign in to comment.