Class: BGS::VnpVeteran
- Inherits:
-
Object
- Object
- BGS::VnpVeteran
- Includes:
- SentryLogging
- Defined in:
- lib/bgs/vnp_veteran.rb
Instance Method Summary collapse
- #bgs_service ⇒ Object private
-
#create ⇒ Object
rubocop:disable Metrics/MethodLength.
- #create_address(participant) ⇒ Object private
- #create_person(participant) ⇒ Object private
- #get_location_id(regional_office_number) ⇒ Object private
- #get_regional_office(zip, country, province) ⇒ Object private
-
#initialize(proc_id:, payload:, user:, claim_type:) ⇒ VnpVeteran
constructor
A new instance of VnpVeteran.
- #veteran ⇒ 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(proc_id:, payload:, user:, claim_type:) ⇒ VnpVeteran
Returns a new instance of VnpVeteran.
9 10 11 12 13 14 15 16 |
# File 'lib/bgs/vnp_veteran.rb', line 9 def initialize(proc_id:, payload:, user:, claim_type:) @user = user @proc_id = proc_id @payload = payload.with_indifferent_access @veteran_info = veteran.formatted_params(@payload) @claim_type = claim_type @va_file_number = @payload['veteran_information']['va_file_number'] end |
Instance Method Details
#bgs_service ⇒ Object (private)
105 106 107 |
# File 'lib/bgs/vnp_veteran.rb', line 105 def bgs_service BGS::Service.new(@user) end |
#create ⇒ Object
rubocop:disable Metrics/MethodLength
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bgs/vnp_veteran.rb', line 19 def create participant = bgs_service.create_participant(@proc_id, @user.participant_id) claim_type_end_product = bgs_service.find_benefit_claim_type_increment(@claim_type) # This conditional makes it easier to write specs asserting that # log_message_to_sentry is called in #create_person. Though, we may # consider removing :warn logs like this from Sentry. unless Rails.env.test? ("#{@proc_id}-#{claim_type_end_product}", :warn, '', { team: 'vfs-ebenefits' }) end address = create_address(participant) regional_office_number = get_regional_office(address[:zip_prefix_nbr], address[:cntry_nm], '') location_id = get_location_id(regional_office_number) create_person(participant) bgs_service.create_phone(@proc_id, participant[:vnp_ptcpnt_id], @veteran_info) veteran.veteran_response( participant, address, { va_file_number: @va_file_number, claim_type_end_product:, regional_office_number:, location_id:, net_worth_over_limit_ind: veteran.formatted_boolean(@payload['dependents_application']['household_income']) } ) end |
#create_address(participant) ⇒ Object (private)
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bgs/vnp_veteran.rb', line 68 def create_address(participant) address_params = veteran.create_address_params(@proc_id, participant[:vnp_ptcpnt_id], @veteran_info) address = bgs_service.create_address(address_params) address[:address_type] = 'OVR' if address[:mlty_post_office_type_cd].present? if address[:frgn_postal_cd].present? address[:foreign_mail_code] = address.delete('frgn_postal_cd') address[:address_type] = 'INT' end address end |
#create_person(participant) ⇒ Object (private)
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/bgs/vnp_veteran.rb', line 51 def create_person(participant) sentry_params = [:error, {}, { team: 'vfs-ebenefits' }] if @veteran_info['ssn']&.length != 9 Rails.logger.info('Malformed SSN! Reassigning to User#ssn.') @veteran_info['ssn'] = @user.ssn end ssn = @veteran_info['ssn'] if ssn == '********' ('SSN is redacted!', *sentry_params) elsif ssn.present? && ssn.length != 9 ("SSN has #{ssn.length} digits!", *sentry_params) end person_params = veteran.create_person_params(@proc_id, participant[:vnp_ptcpnt_id], @veteran_info) bgs_service.create_person(person_params) end |
#get_location_id(regional_office_number) ⇒ Object (private)
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/bgs/vnp_veteran.rb', line 89 def get_location_id(regional_office_number) # retrieve the list of all regional offices # match the regional number to find the corresponding location id regional_offices = bgs_service.find_regional_offices return '347' if regional_offices.nil? # return default value 347 if regional office is not found regional_office = regional_offices.find { |ro| ro[:station_number] == regional_office_number } return '347' if regional_office.nil? # return default value 347 if regional office is not found regional_office[:lctn_id] end |
#get_regional_office(zip, country, province) ⇒ Object (private)
82 83 84 85 86 87 |
# File 'lib/bgs/vnp_veteran.rb', line 82 def get_regional_office(zip, country, province) # find the regional office number closest to the Veteran's zip code bgs_service.get_regional_office_by_zip_code( zip, country, province, 'CP', @user.ssn ) end |
#veteran ⇒ Object (private)
101 102 103 |
# File 'lib/bgs/vnp_veteran.rb', line 101 def veteran @veteran ||= BGSDependents::Veteran.new(@proc_id, @user) end |