Class: V0::BenefitsClaimsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/v0/benefits_claims_controller.rb

Constant Summary

Constants inherited from ApplicationController

ApplicationController::VERSION_STATUS

Constants included from SignIn::Authentication

SignIn::Authentication::BEARER_PATTERN

Constants included from ExceptionHandling

ExceptionHandling::SKIP_SENTRY_EXCEPTION_TYPES

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_user

Instance Method Summary collapse

Methods inherited from ApplicationController

#clear_saved_form, #cors_preflight, #pagination_params, #render_job_id, #routing_error, #set_csrf_header

Methods included from Traceable

#set_trace_tags

Methods included from SentryControllerLogging

#set_tags_and_extra_context, #tags_context, #user_context

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 Instrumentation

#append_info_to_payload

Methods included from SignIn::Authentication

#access_token, #access_token_authenticate, #authenticate, #authenticate_access_token, #bearer_token, #cookie_access_token, #handle_authenticate_error, #load_user, #load_user_object, #scrub_bearer_token, #validate_request_ip

Methods included from Headers

#set_app_info_headers

Methods included from ExceptionHandling

#render_errors, #report_mapped_exception, #report_original_exception, #skip_sentry_exception?, #skip_sentry_exception_types

Methods included from AuthenticationAndSSOConcerns

#authenticate, #clear_session, #extend_session!, #load_user, #log_sso_info, #render_unauthorized, #reset_session, #set_api_cookie!, #set_current_user, #set_session_expiration_header, #set_session_object, #sign_in_service_exp_time, #sign_in_service_session, #sso_cookie_content, #sso_logging_info, #validate_inbound_login_params, #validate_session

Methods included from SignIn::AudienceValidator

#authenticate, #validate_audience!

Instance Method Details

#check_for_birls_idObject (private)



75
76
77
# File 'app/controllers/v0/benefits_claims_controller.rb', line 75

def check_for_birls_id
  ::Rails.logger.info('[BenefitsClaims#index] No birls id') if current_user.birls_id.nil?
end

#check_for_file_numberObject (private)



79
80
81
82
# File 'app/controllers/v0/benefits_claims_controller.rb', line 79

def check_for_file_number
  bgs_file_number = BGS::People::Request.new.find_person_by_participant_id(user: current_user).file_number
  ::Rails.logger.info('[BenefitsClaims#index] No file number') if bgs_file_number.blank?
end

#claims_scopeObject (private)



67
68
69
# File 'app/controllers/v0/benefits_claims_controller.rb', line 67

def claims_scope
  EVSSClaim.for_user(@current_user)
end

#indexObject



10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/v0/benefits_claims_controller.rb', line 10

def index
  claims = service.get_claims

  check_for_birls_id
  check_for_file_number

  tap_claims(claims['data'])

  render json: claims
end

#log_evidence_requests(claim_id, claim_info) ⇒ Object (private)



103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/controllers/v0/benefits_claims_controller.rb', line 103

def log_evidence_requests(claim_id, claim_info)
  tracked_items = claim_info['trackedItems']

  tracked_items.each do |ti|
    ::Rails.logger.info('Evidence Request Types',
                        { message_type: 'lh.cst.evidence_requests',
                          claim_id:,
                          tracked_item_id: ti['id'],
                          tracked_item_type: ti['displayName'],
                          tracked_item_status: ti['status'] })
  end
end

#serviceObject (private)



71
72
73
# File 'app/controllers/v0/benefits_claims_controller.rb', line 71

def service
  @service ||= BenefitsClaims::Service.new(@current_user.icn)
end

#showObject



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 'app/controllers/v0/benefits_claims_controller.rb', line 21

def show
  claim = service.get_claim(params[:id])

  # Document uploads to EVSS require a birls_id; This restriction should
  # be removed when we move to Lighthouse Benefits Documents for document uploads
  claim['data']['attributes']['canUpload'] = !@current_user.birls_id.nil?

  # We want to log some details about claim type patterns to track in DataDog
  claim_info = claim['data']['attributes']
  ::Rails.logger.info('Claim Type Details',
                      { message_type: 'lh.cst.claim_types',
                        claim_type: claim_info['claimType'],
                        claim_type_code: claim_info['claimTypeCode'],
                        num_contentions: claim_info['contentions'].count,
                        ep_code: claim_info['endProductCode'],
                        current_phase_back: claim_info['claimPhaseDates']['currentPhaseBack'],
                        latest_phase_type: claim_info['claimPhaseDates']['latestPhaseType'],
                        decision_letter_sent: claim_info['decisionLetterSent'],
                        development_letter_sent: claim_info['developmentLetterSent'],
                        claim_id: params[:id] })
  log_evidence_requests(params[:id], claim_info)

  tap_claims([claim['data']])

  render json: claim
end

#submit5103Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/v0/benefits_claims_controller.rb', line 48

def submit5103
  # Log if the user doesn't have a file number
  # NOTE: We are treating the BIRLS ID as a substitute
  # for file number here
  ::Rails.logger.info('[5103 Submission] No file number') if @current_user.birls_id.nil?

  json_payload = request.body.read

  data = JSON.parse(json_payload)

  tracked_item_id = data['trackedItemId'] || nil

  res = service.submit5103(params[:id], tracked_item_id)

  render json: res
end

#tap_claims(claims) ⇒ Object (private)



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/v0/benefits_claims_controller.rb', line 84

def tap_claims(claims)
  claims.each do |claim|
    record = claims_scope.where(evss_id: claim['id']).first

    if record.blank?
      EVSSClaim.create(
        user_uuid: @current_user.uuid,
        user_account: @current_user.,
        evss_id: claim['id'],
        data: {}
      )
    else
      # If there is a record, we want to set the updated_at field
      # to Time.zone.now
      record.touch # rubocop:disable Rails/SkipsModelValidations
    end
  end
end