Class: BGS::Service

Inherits:
Object
  • Object
show all
Includes:
Exceptions::BGSErrors, Common::Client::Concerns::Monitoring, SentryLogging
Defined in:
lib/bgs/service.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.bgs'
JOURNAL_STATUS_TYPE_CODE =

Journal Status Type Code The alphabetic character representing the last action taken on the record (I = Input, U = Update, D = Delete)

'U'

Constants included from Exceptions::BGSErrors

Exceptions::BGSErrors::MAX_ATTEMPTS

Instance Method Summary collapse

Methods included from Common::Client::Concerns::Monitoring

#increment, #increment_failure, #increment_total, #with_monitoring

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Methods included from Exceptions::BGSErrors

#log_oracle_errors!, #notify_of_service_exception, #raise_backend_exception, #with_multiple_attempts_enabled

Constructor Details

#initialize(user) ⇒ Service

Returns a new instance of Service.



19
20
21
# File 'lib/bgs/service.rb', line 19

def initialize(user)
  @user = user
end

Instance Method Details

#bgs_authObject



166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/bgs/service.rb', line 166

def bgs_auth
  auth_params = {
    jrn_dt: Time.current.iso8601,
    jrn_lctn_id: Settings.bgs.client_station_id,
    jrn_status_type_cd: 'U',
    jrn_user_id: Settings.bgs.client_username,
    jrn_obj_id: Settings.bgs.application
  }

  auth_params.merge!(user_ssn) if Settings.bgs.mock_response == true

  auth_params
end

#create_address(address_params) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/bgs/service.rb', line 89

def create_address(address_params)
  with_multiple_attempts_enabled do
    service.vnp_ptcpnt_addrs.vnp_ptcpnt_addrs_create(
      address_params.merge(bgs_auth)
    )
  end
end

#create_child_school(child_school_params) ⇒ Object



111
112
113
114
115
# File 'lib/bgs/service.rb', line 111

def create_child_school(child_school_params)
  with_multiple_attempts_enabled do
    service.vnp_child_school.child_school_create(child_school_params.merge(bgs_auth))
  end
end

#create_child_student(child_student_params) ⇒ Object



117
118
119
120
121
# File 'lib/bgs/service.rb', line 117

def create_child_student(child_student_params)
  with_multiple_attempts_enabled do
    service.vnp_child_student.child_student_create(child_student_params.merge(bgs_auth))
  end
end

#create_note(claim_id, note_text) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/bgs/service.rb', line 200

def create_note(claim_id, note_text)
  option_hash = {
    jrn_stt_tc: 'I',
    name: 'Claim rejected by VA.gov',
    bnft_clm_note_tc: 'CLMDVLNOTE',
    clm_id: claim_id,
    ptcpnt_id: @user.participant_id,
    txt: note_text
  }.merge!(bgs_auth).except!(:jrn_status_type_cd)

  service.notes.create_note(option_hash)
rescue => e
  notify_of_service_exception(e, __method__, 1, :warn)
end

#create_participant(proc_id, corp_ptcpnt_id = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/bgs/service.rb', line 70

def create_participant(proc_id, corp_ptcpnt_id = nil)
  with_multiple_attempts_enabled do
    service.vnp_ptcpnt.vnp_ptcpnt_create(
      {
        vnp_proc_id: proc_id,
        ptcpnt_type_nm: 'Person',
        corp_ptcpnt_id:,
        ssn: @user.ssn
      }.merge(bgs_auth)
    )
  end
end

#create_person(person_params) ⇒ Object



83
84
85
86
87
# File 'lib/bgs/service.rb', line 83

def create_person(person_params)
  with_multiple_attempts_enabled do
    service.vnp_person.vnp_person_create(person_params.merge(bgs_auth))
  end
end

#create_phone(proc_id, participant_id, payload) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/bgs/service.rb', line 97

def create_phone(proc_id, participant_id, payload)
  with_multiple_attempts_enabled do
    service.vnp_ptcpnt_phone.vnp_ptcpnt_phone_create(
      {
        vnp_proc_id: proc_id,
        vnp_ptcpnt_id: participant_id,
        phone_type_nm: 'Daytime',
        phone_nbr: payload['phone_number'],
        efctv_dt: Time.current.iso8601
      }.merge(bgs_auth)
    )
  end
end

#create_proc(proc_state: 'Started') ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bgs/service.rb', line 23

def create_proc(proc_state: 'Started')
  with_multiple_attempts_enabled do
    service.vnp_proc_v2.vnp_proc_create(
      {
        vnp_proc_type_cd: 'DEPCHG',
        vnp_proc_state_type_cd: proc_state,
        creatd_dt: Time.current.iso8601,
        last_modifd_dt: Time.current.iso8601,
        submtd_dt: Time.current.iso8601
      }.merge(bgs_auth)
    )
  end
end

#create_proc_form(vnp_proc_id, form_type_code) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/bgs/service.rb', line 45

def create_proc_form(vnp_proc_id, form_type_code)
  # Temporary log proc_id to sentry
  log_message_to_sentry(vnp_proc_id, :warn, '', { team: 'vfs-ebenefits' })
  with_multiple_attempts_enabled do
    service.vnp_proc_form.vnp_proc_form_create(
      { vnp_proc_id:, form_type_cd: form_type_code }.merge(bgs_auth)
    )
  end
end

#create_relationship(relationship_params) ⇒ Object



123
124
125
126
127
# File 'lib/bgs/service.rb', line 123

def create_relationship(relationship_params)
  with_multiple_attempts_enabled do
    service.vnp_ptcpnt_rlnshp.vnp_ptcpnt_rlnshp_create(relationship_params.merge(bgs_auth))
  end
end

#find_benefit_claim_type_increment(claim_type_cd) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/bgs/service.rb', line 129

def find_benefit_claim_type_increment(claim_type_cd)
  increment_params = {
    ptcpnt_id: @user.participant_id,
    bnft_claim_type_cd: claim_type_cd,
    pgm_type_cd: 'CPL'
  }

  increment_params.merge!(user_ssn) if Settings.bgs.mock_response == true
  with_multiple_attempts_enabled do
    service.share_data.find_benefit_claim_type_increment(**increment_params)
  end
end

#find_rating_dataObject



37
38
39
40
41
42
43
# File 'lib/bgs/service.rb', line 37

def find_rating_data
  service.rating.find_rating_data(@user.ssn)
rescue BGS::ShareError => e
  raise Common::Exceptions::RecordNotFound, @user. if e.message =~ /No record found for/

  raise e
end

#find_regional_officesObject



194
195
196
197
198
# File 'lib/bgs/service.rb', line 194

def find_regional_offices
  service.share_data.find_regional_offices[:return]
rescue => e
  notify_of_service_exception(e, __method__, 1, :warn)
end

#get_regional_office_by_zip_code(zip_code, country, province, lob, ssn) ⇒ Object



184
185
186
187
188
189
190
191
192
# File 'lib/bgs/service.rb', line 184

def get_regional_office_by_zip_code(zip_code, country, province, lob, ssn)
  regional_office_response = service.routing.get_regional_office_by_zip_code(
    zip_code, country, province, lob, ssn
  )
  regional_office_response[:regional_office][:number]
rescue => e
  notify_of_service_exception(e, __method__, 1, :warn)
  '347' # return default location id
end

#insert_benefit_claim(benefit_claim_params) ⇒ Object



162
163
164
# File 'lib/bgs/service.rb', line 162

def insert_benefit_claim(benefit_claim_params)
  service.claims.insert_benefit_claim(benefit_claim_params)
end

#serviceObject (private)



217
218
219
220
221
222
# File 'lib/bgs/service.rb', line 217

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

#update_manual_proc(proc_id) ⇒ Object



154
155
156
157
158
159
160
# File 'lib/bgs/service.rb', line 154

def update_manual_proc(proc_id)
  service.vnp_proc_v2.vnp_proc_update(
    { vnp_proc_id: proc_id, vnp_proc_state_type_cd: 'MANUAL_VAGOV', vnp_proc_type_cd: 'DEPCHG' }.merge(bgs_auth)
  )
rescue => e
  notify_of_service_exception(e, __method__)
end

#update_proc(proc_id, proc_state: 'Ready') ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/bgs/service.rb', line 55

def update_proc(proc_id, proc_state: 'Ready')
  with_multiple_attempts_enabled do
    service.vnp_proc_v2.vnp_proc_update(
      {
        vnp_proc_id: proc_id,
        vnp_proc_type_cd: 'DEPCHG',
        vnp_proc_state_type_cd: proc_state,
        creatd_dt: Time.current.iso8601,
        last_modifd_dt: Time.current.iso8601,
        submtd_dt: Time.current.iso8601
      }.merge(bgs_auth)
    )
  end
end

#user_ssnObject



180
181
182
# File 'lib/bgs/service.rb', line 180

def user_ssn
  { ssn: @user.ssn }
end

#vnp_benefit_claim_update(vnp_benefit_params) ⇒ Object



148
149
150
151
152
# File 'lib/bgs/service.rb', line 148

def vnp_benefit_claim_update(vnp_benefit_params)
  with_multiple_attempts_enabled do
    service.vnp_bnft_claim.vnp_bnft_claim_update(vnp_benefit_params.merge(bgs_auth))
  end
end

#vnp_create_benefit_claim(vnp_benefit_params) ⇒ Object



142
143
144
145
146
# File 'lib/bgs/service.rb', line 142

def vnp_create_benefit_claim(vnp_benefit_params)
  with_multiple_attempts_enabled do
    service.vnp_bnft_claim.vnp_bnft_claim_create(vnp_benefit_params.merge(bgs_auth))
  end
end