-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[12331] Refactor BGS Services to more clearly show what User model fi…
…elds are being leveraged (#12332) Co-authored-by: Trevor Bosaw <trevor.bosaw@oddball.io>
- Loading branch information
Showing
13 changed files
with
214 additions
and
179 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.