Class: V0::RatedDisabilitiesDiscrepanciesController

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

Constant Summary collapse

DECISION_ALLOWLIST =
['1151 Denied', '1151 Granted', 'Not Service Connected', 'Service Connected'].freeze

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

#active?(rating) ⇒ Boolean (private)

Returns:

  • (Boolean)


76
77
78
79
80
81
82
# File 'app/controllers/v0/rated_disabilities_discrepancies_controller.rb', line 76

def active?(rating)
  date = rating['rating_end_date']

  # In order for the rating to be considered active,
  # the date should be either nil or in the future
  date.nil? || Date.parse(date).future?
end

#evss_serviceObject (private)

EVSS



42
43
44
45
# File 'app/controllers/v0/rated_disabilities_discrepancies_controller.rb', line 42

def evss_service
  auth_headers = get_auth_headers
  @evss_service ||= EVSS::DisabilityCompensationForm::Service.new(auth_headers)
end

#filter_ratings_by_decision!(ratings) ⇒ Object (private)



68
69
70
# File 'app/controllers/v0/rated_disabilities_discrepancies_controller.rb', line 68

def filter_ratings_by_decision!(ratings)
  ratings.select! { |rating| DECISION_ALLOWLIST.include?(rating['decision']) }
end

#get_auth_headersObject (private)



47
48
49
# File 'app/controllers/v0/rated_disabilities_discrepancies_controller.rb', line 47

def get_auth_headers
  EVSS::AuthHeaders.new(@current_user).to_h
end

#get_evss_rated_disabilitiesObject (private)



51
52
53
# File 'app/controllers/v0/rated_disabilities_discrepancies_controller.rb', line 51

def get_evss_rated_disabilities
  evss_service.get_rated_disabilities
end

#get_lh_rated_disabilitiesObject (private)

Lighthouse



56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/v0/rated_disabilities_discrepancies_controller.rb', line 56

def get_lh_rated_disabilities
  response = service.get_rated_disabilities(@current_user.icn)

  # We only want active ratings
  if response.dig('data', 'attributes', 'individual_ratings')
    filter_ratings_by_decision!(response['data']['attributes']['individual_ratings'])
    reject_inactive_ratings!(response['data']['attributes']['individual_ratings'])
  end

  response
end

#log_length_discrepancy(evss_ratings, lh_ratings) ⇒ Object (private)



28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/v0/rated_disabilities_discrepancies_controller.rb', line 28

def log_length_discrepancy(evss_ratings, lh_ratings)
  message = 'Discrepancy between Lighthouse and EVSS disability ratings'

  ::Rails.logger.info(message, {
                        message_type: 'lh.rated_disabilities.length_discrepancy',
                        evss_length: evss_ratings.length,
                        evss_rating_ids: evss_ratings.pluck('rated_disability_id'),
                        lighthouse_length: lh_ratings.length,
                        lighthouse_rating_ids: lh_ratings.pluck('disability_rating_id'),
                        revision: 5
                      })
end

#reject_inactive_ratings!(ratings) ⇒ Object (private)



72
73
74
# File 'app/controllers/v0/rated_disabilities_discrepancies_controller.rb', line 72

def reject_inactive_ratings!(ratings)
  ratings.select! { |rating| active?(rating) }
end

#serviceObject (private)



84
85
86
# File 'app/controllers/v0/rated_disabilities_discrepancies_controller.rb', line 84

def service
  @service ||= VeteranVerification::Service.new
end

#showObject



14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/v0/rated_disabilities_discrepancies_controller.rb', line 14

def show
  lh_response = get_lh_rated_disabilities
  evss_response = get_evss_rated_disabilities

  lh_ratings = lh_response.dig('data', 'attributes', 'individual_ratings')
  evss_ratings = evss_response.rated_disabilities
  log_length_discrepancy(evss_ratings, lh_ratings) if lh_ratings.length != evss_ratings.length

  # This doesn't need to return anything at the moment
  render json: nil
end