Class: BGS::DependencyVerificationService
- Inherits:
-
Object
- Object
- BGS::DependencyVerificationService
- Includes:
- SentryLogging
- Defined in:
- app/services/bgs/dependency_verification_service.rb
Instance Attribute Summary collapse
-
#common_name ⇒ Object
readonly
Returns the value of attribute common_name.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#icn ⇒ Object
readonly
Returns the value of attribute icn.
-
#participant_id ⇒ Object
readonly
Returns the value of attribute participant_id.
-
#ssn ⇒ Object
readonly
Returns the value of attribute ssn.
-
#user_uuid ⇒ Object
readonly
Returns the value of attribute user_uuid.
Instance Method Summary collapse
- #empty_response(diaries) ⇒ Object private
- #external_key ⇒ Object private
-
#initialize(user) ⇒ DependencyVerificationService
constructor
A new instance of DependencyVerificationService.
- #invalid_dependency_decision?(dependency_decision) ⇒ Boolean private
- #normalize_dependency_decisions(dependency_decisions) ⇒ Object private
- #read_diaries ⇒ Object
- #service ⇒ Object private
- #standard_response(diaries) ⇒ Object private
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Constructor Details
#initialize(user) ⇒ DependencyVerificationService
Returns a new instance of DependencyVerificationService.
9 10 11 12 13 14 15 16 |
# File 'app/services/bgs/dependency_verification_service.rb', line 9 def initialize(user) @participant_id = user.participant_id @ssn = user.ssn @common_name = user.common_name @email = user.email @icn = user.icn @user_uuid = user.uuid end |
Instance Attribute Details
#common_name ⇒ Object (readonly)
Returns the value of attribute common_name.
7 8 9 |
# File 'app/services/bgs/dependency_verification_service.rb', line 7 def common_name @common_name end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
7 8 9 |
# File 'app/services/bgs/dependency_verification_service.rb', line 7 def email @email end |
#icn ⇒ Object (readonly)
Returns the value of attribute icn.
7 8 9 |
# File 'app/services/bgs/dependency_verification_service.rb', line 7 def icn @icn end |
#participant_id ⇒ Object (readonly)
Returns the value of attribute participant_id.
7 8 9 |
# File 'app/services/bgs/dependency_verification_service.rb', line 7 def participant_id @participant_id end |
#ssn ⇒ Object (readonly)
Returns the value of attribute ssn.
7 8 9 |
# File 'app/services/bgs/dependency_verification_service.rb', line 7 def ssn @ssn end |
#user_uuid ⇒ Object (readonly)
Returns the value of attribute user_uuid.
7 8 9 |
# File 'app/services/bgs/dependency_verification_service.rb', line 7 def user_uuid @user_uuid end |
Instance Method Details
#empty_response(diaries) ⇒ Object (private)
44 45 46 47 48 49 |
# File 'app/services/bgs/dependency_verification_service.rb', line 44 def empty_response(diaries) { dependency_decs: diaries.dig(:dependency_decs, :dependency_dec), diaries: [] } end |
#external_key ⇒ Object (private)
80 81 82 83 84 85 |
# File 'app/services/bgs/dependency_verification_service.rb', line 80 def external_key @external_key ||= begin key = common_name.presence || email key.first(Constants::EXTERNAL_KEY_MAX_LENGTH) end end |
#invalid_dependency_decision?(dependency_decision) ⇒ Boolean (private)
87 88 89 90 91 |
# File 'app/services/bgs/dependency_verification_service.rb', line 87 def invalid_dependency_decision?(dependency_decision) !dependency_decision.is_a?(Hash) || !dependency_decision.key?(:award_effective_date) || dependency_decision[:award_effective_date].future? end |
#normalize_dependency_decisions(dependency_decisions) ⇒ Object (private)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/services/bgs/dependency_verification_service.rb', line 58 def normalize_dependency_decisions(dependency_decisions) set1 = dependency_decisions.delete_if do |dependency_decision| invalid_dependency_decision?(dependency_decision) end final = [] return final if set1.blank? set2 = set1.group_by { |dependency_decision| dependency_decision[:person_id] } set2.each_value do |array| latest = array.max_by { |dd| dd[:award_effective_date] } final << latest if latest[:dependency_status_type] != 'NAWDDEP' end final end |
#read_diaries ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/services/bgs/dependency_verification_service.rb', line 18 def read_diaries if participant_id.blank? Rails.logger.warn('read_diaries: participant_id is blank', { icn:, user_uuid: }) return { dependency_decs: nil, diaries: [] } end diaries = service.diaries.read_diaries( { beneficiary_id: participant_id, participant_id:, ssn:, award_type: 'CPL' } ) return empty_response(diaries) if diaries[:diaries].blank? dependency_decisions = diaries[:dependency_decs][:dependency_dec] diaries[:dependency_decs][:dependency_dec] = normalize_dependency_decisions(dependency_decisions) standard_response(diaries) rescue => e log_exception_to_sentry(e, { icn: }, { team: Constants::SENTRY_REPORTING_TEAM }) end |
#service ⇒ Object (private)
76 77 78 |
# File 'app/services/bgs/dependency_verification_service.rb', line 76 def service @service ||= BGS::Services.new(external_uid: icn, external_key:) end |
#standard_response(diaries) ⇒ Object (private)
51 52 53 54 55 56 |
# File 'app/services/bgs/dependency_verification_service.rb', line 51 def standard_response(diaries) { dependency_decs: diaries.dig(:dependency_decs, :dependency_dec), diaries: diaries.dig(:diaries, :diary) } end |