Class: EVSSClaimService

Inherits:
Object
  • Object
show all
Includes:
SentryLogging
Defined in:
app/services/evss_claim_service.rb

Overview

EVSS Claims Status Tool

Constant Summary collapse

EVSS_CLAIM_KEYS =
%w[open_claims historical_claims].freeze

Instance Method Summary collapse

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) ⇒ EVSSClaimService

Returns a new instance of EVSSClaimService.



12
13
14
# File 'app/services/evss_claim_service.rb', line 12

def initialize(user)
  @user = user
end

Instance Method Details

#allObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/evss_claim_service.rb', line 16

def all
  raw_claims = client.all_claims.body
  claims = EVSS_CLAIM_KEYS.each_with_object([]) do |key, claim_accum|
    next unless raw_claims[key]

    claim_accum << raw_claims[key].map do |raw_claim|
      create_or_update_claim(raw_claim)
    end
  end.flatten
  [claims, true]
rescue Breakers::OutageException, EVSS::ErrorMiddleware::EVSSBackendServiceError
  [claims_scope.all, false]
end

#auth_headersObject (private)



96
97
98
# File 'app/services/evss_claim_service.rb', line 96

def auth_headers
  @auth_headers ||= EVSS::AuthHeaders.new(@user).to_h
end

#bgs_serviceObject (private)



81
82
83
84
# File 'app/services/evss_claim_service.rb', line 81

def bgs_service
  @bgs ||= BGS::Services.new(external_uid: @user.participant_id,
                             external_key: @user.participant_id)
end

#claims_scopeObject (private)



127
128
129
# File 'app/services/evss_claim_service.rb', line 127

def claims_scope
  EVSSClaim.for_user(@user)
end

#clientObject (private)



92
93
94
# File 'app/services/evss_claim_service.rb', line 92

def client
  @client ||= EVSS::ClaimsService.new(auth_headers)
end

#create_or_update_claim(raw_claim) ⇒ Object (private)



131
132
133
134
135
136
137
138
139
140
141
# File 'app/services/evss_claim_service.rb', line 131

def create_or_update_claim(raw_claim)
  claim = claims_scope.where(evss_id: raw_claim['id']).first
  if claim.blank?
    claim = EVSSClaim.new(user_uuid: @user.uuid,
                          user_account: @user.,
                          evss_id: raw_claim['id'],
                          data: {})
  end
  claim.update(list_data: raw_claim)
  claim
end

#get_claim(claim_id) ⇒ Object (private)



86
87
88
89
90
# File 'app/services/evss_claim_service.rb', line 86

def get_claim(claim_id)
  bgs_service.ebenefits_benefit_claims_status.find_benefit_claim_details_by_benefit_claim_id(
    benefit_claim_id: claim_id
  )
end

#record_workaround(task, claim_id, job_id) ⇒ Object (private)



118
119
120
121
122
123
124
125
# File 'app/services/evss_claim_service.rb', line 118

def record_workaround(task, claim_id, job_id)
  ::Rails.logger.info('Supplementing EVSS headers', {
                        message_type: "evss.#{task}.no_birls_id",
                        claim_id:,
                        job_id:,
                        revision: 2
                      })
end

#request_decision(claim) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'app/services/evss_claim_service.rb', line 41

def request_decision(claim)
  # Workaround for non-Veteran users
  headers = auth_headers.clone
  headers_supplemented = supplement_auth_headers(claim.evss_id, headers)

  job_id = EVSS::RequestDecision.perform_async(headers, claim.evss_id)

  record_workaround('request_decision', claim.evss_id, job_id) if headers_supplemented

  job_id
end

#supplement_auth_headers(claim_id, headers) ⇒ Object (private)



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/services/evss_claim_service.rb', line 100

def supplement_auth_headers(claim_id, headers)
  # Assuming this header has a value of "", we want to get the Veteran
  # associated with the claims' participant ID. We can get this by fetching
  # the claim details from BGS and looking at the Participant ID of the
  # Veteran associated with the claim
  blank_header = headers['va_eauth_birlsfilenumber'].blank?
  if blank_header
    claim = get_claim(claim_id)
    veteran_participant_id = claim[:benefit_claim_details_dto][:ptcpnt_vet_id]
    headers['va_eauth_pid'] = veteran_participant_id
    # va_eauth_pnid maps to the users SSN. Using this here so that the header
    # has a value
    headers['va_eauth_birlsfilenumber'] = headers['va_eauth_pnid']
  end

  blank_header
end

#update_from_remote(claim) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'app/services/evss_claim_service.rb', line 30

def update_from_remote(claim)
  begin
    raw_claim = client.find_claim_by_id(claim.evss_id).body.fetch('claim', {})
    claim.update(data: raw_claim)
    successful_sync = true
  rescue Breakers::OutageException, EVSS::ErrorMiddleware::EVSSBackendServiceError
    successful_sync = false
  end
  [claim, successful_sync]
end

#upload_document(evss_claim_document) ⇒ Object

upload file to s3 and enqueue job to upload to EVSS, used by Claim Status Tool EVSS::DocumentsService is where the uploading of documents actually happens



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/services/evss_claim_service.rb', line 55

def upload_document(evss_claim_document)
  uploader = EVSSClaimDocumentUploader.new(@user., evss_claim_document.uploader_ids)
  uploader.store!(evss_claim_document.file_obj)

  # the uploader sanitizes the filename before storing, so set our doc to match
  evss_claim_document.file_name = uploader.final_filename

  # Workaround for non-Veteran users
  headers = auth_headers.clone
  headers_supplemented = supplement_auth_headers(evss_claim_document.evss_claim_id, headers)

  job_id = EVSS::DocumentUpload.perform_async(headers, @user.,
                                              evss_claim_document.to_serializable_hash)

  record_workaround('document_upload', evss_claim_document.evss_claim_id, job_id) if headers_supplemented

  job_id
rescue CarrierWave::IntegrityError => e
  log_exception_to_sentry(e, nil, nil, 'warn')
  raise Common::Exceptions::UnprocessableEntity.new(
    detail: e.message, source: 'EVSSClaimService.upload_document'
  )
end