Class: V0::VirtualAgent::VirtualAgentAppealController

Inherits:
AppealsBaseController show all
Defined in:
app/controllers/v0/virtual_agent/virtual_agent_appeal_controller.rb

Constant Summary collapse

APPEAL_DESCRIPTIONS =
{
  'pending_soc' => 'A Decision Review Officer is reviewing your appeal',
  'pending_form9' => 'Please review your Statement of the Case',
  'pending_certification' => 'The Decision Review Officer is finishing their review of your appeal',
  'pending_certification_ssoc' => 'Please review your Supplemental Statement of the Case',
  'remand_ssoc' => 'Please review your Supplemental Statement of the Case',
  'pending_hearing_scheduling' => 'You’re waiting for your hearing to be scheduled',
  'scheduled_hearing' => 'Your hearing has been scheduled',
  'on_docket' => 'Your appeal is waiting to be sent to a judge',
  'at_vso' => 'Your appeal is with your Veterans Service Organization',
  'decision_in_progress' => 'A judge is reviewing your appeal',
  'bva_development' => 'The judge is seeking more information before making a decision',
  'stayed' => 'The Board is waiting until a higher court makes a decision',
  'remand' => 'The Board made a decision on your appeal',
  'ama_remand' => 'The Board made a decision on your appeal',
  'bva_decision' => 'The Board made a decision on your appeal',
  'field_grant' => 'The {aoj_desc} granted your appeal',
  'withdrawn' => 'You withdrew your appeal',
  'ftr' => 'Your appeal was closed',
  'ramp' => 'You opted in to the Rapid Appeals Modernization Program (RAMP)',
  'reconsideration' => 'Your Motion for Reconsideration was denied',
  'death' => 'The appeal was closed',
  'other_close' => 'Your appeal was closed',
  'merged' => 'Your appeal was merged',
  'statutory_opt_in' => 'You requested a decision review under the Appeals Modernization Act',
  'evidentiary_period' => 'Your appeals file is open for new evidence',
  'post_bva_dta_decision' => 'The {aoj_desc} corrected an error',
  'bva_decision_effectuation' => 'The {aoj_desc} corrected an error',
  'sc_received' => 'A reviewer is examining your new evidence',
  'sc_recieved' => 'A reviewer is examining your new evidence',
  'hlr_received' => 'A senior reviewer is taking a new look at your case',
  'sc_decision' => 'The {aoj_desc} made a decision',
  'hlr_decision' => 'The {aoj_desc} made a decision',
  'hlr_dta_error' => 'The {aoj_desc} is correcting an error',
  'sc_closed' => 'Your Supplemental Claim was closed',
  'hlr_closed' => 'Your Higher-Level Review was closed',
  'remand_return' => 'Your appeal was returned to the Board of Veterans’ Appeals'
}.freeze
AOJ_DESCRIPTIONS =
{ 'vba' => 'Veterans Benefits Administration',
'vha' => 'Veterans Health Administration',
'nca' => 'National Cemetery Administration',
'other' => 'Agency of Original Jurisdiction' }.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 AppealsBaseController

#appeals_service, #decision_review_service, #get_hash_from_request_body, #request_body_debug_data, #request_body_hash, #request_body_is_not_a_hash_error

Methods included from FailedRequestLoggable

#current_user_hash, #log_exception_to_personal_information_log

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

#data_for_first_comp_appeal(appeals) ⇒ Object



50
51
52
53
54
55
56
# File 'app/controllers/v0/virtual_agent/virtual_agent_appeal_controller.rb', line 50

def data_for_first_comp_appeal(appeals)
  open_comp_appeals = first_five_open_comp_appeals(appeals)

  return [] if open_comp_appeals.nil?

  transform_appeals_to_response(open_comp_appeals)
end

#first_five_open_comp_appeals(appeals) ⇒ Object



74
75
76
77
78
79
80
# File 'app/controllers/v0/virtual_agent/virtual_agent_appeal_controller.rb', line 74

def first_five_open_comp_appeals(appeals)
  appeals
    .sort_by { |appeal| get_last_updated_date appeal }
    .reverse
    .select { |appeal| open_compensation? appeal }
    .take(5)
end

#get_appeal_or_review(appeal) ⇒ Object



82
83
84
85
86
87
88
89
# File 'app/controllers/v0/virtual_agent/virtual_agent_appeal_controller.rb', line 82

def get_appeal_or_review(appeal)
  case appeal['type']
  when 'legacyAppeal', 'appeal'
    'appeal'
  when 'higherLevelReview', 'supplementalClaim'
    'review'
  end
end

#get_last_updated_date(appeal) ⇒ Object



107
108
109
110
111
# File 'app/controllers/v0/virtual_agent/virtual_agent_appeal_controller.rb', line 107

def get_last_updated_date(appeal)
  events = appeal['attributes']['events']
  DateTime.parse events
    .max_by { |event| DateTime.parse event['date'] }['date']
end

#get_staging_appeals_from_lighthouse(ssan, user_name) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/v0/virtual_agent/virtual_agent_appeal_controller.rb', line 29

def get_staging_appeals_from_lighthouse(ssan, user_name)
  uri = URI(Settings.virtual_agent.lighthouse_api_uri)

  req = Net::HTTP::Get.new(uri)
  req['apikey'] = Settings.virtual_agent.lighthouse_api_key
  req['X-VA-SSN'] = ssan
  req['X-VA-User'] = user_name

  http = Net::HTTP.new(uri.hostname, uri.port)

  http.use_ssl = true

  response = http.request(req)
  if response.code != '200'
    Rails.logger.error "Lighthouse API returned #{response.code}: #{response.body}"
    raise "#{response.code}: #{response.body}" if Settings.vsp_environment == 'staging'
  end

  JSON.parse(response.body)
end

#get_status_type_text(appeal_status, aoj) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'app/controllers/v0/virtual_agent/virtual_agent_appeal_controller.rb', line 161

def get_status_type_text(appeal_status, aoj)
  appeal_status_description = APPEAL_DESCRIPTIONS[appeal_status]

  if appeal_status_description.nil?
    appeal_status_description = 'Unknown Status'
    unknown_status_error = StandardError.new("Unknown status: #{appeal_status} with AOJ: #{aoj}")
    log_exception_to_sentry(unknown_status_error, { appeal_status => appeal_status, aoj => aoj })
  end

  if appeal_status_description.include? '{aoj_desc}'
    appeal_status_description.gsub('{aoj_desc}', AOJ_DESCRIPTIONS[aoj])
  else
    appeal_status_description
  end
end

#get_submission_date(appeal) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/controllers/v0/virtual_agent/virtual_agent_appeal_controller.rb', line 91

def get_submission_date(appeal)
  events = appeal['attributes']['events']
  submission_event = {}
  case appeal['type']
  when 'legacyAppeal'
    submission_event = events.detect { |event| event['type'] == 'nod' }
  when 'appeal'
    submission_event = events.detect { |event| event['type'] == 'ama_nod' }
  when 'higherLevelReview'
    submission_event = events.detect { |event| event['type'] == 'hlr_request' }
  when 'supplementalClaim'
    submission_event = events.detect { |event| event['type'] == 'sc_request' }
  end
  DateTime.parse submission_event['date']
end

#indexObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/v0/virtual_agent/virtual_agent_appeal_controller.rb', line 10

def index
  if Settings.vsp_environment == 'staging'
    Rails.logger.info 'Getting appeals from Lighthouse for staging environment'
    @user_ssan, @user_name = set_user_credentials
    appeals_response = get_staging_appeals_from_lighthouse(@user_ssan, @user_name)
    appeals_data_array = appeals_response['data']
    Rails.logger.info "Retrieved #{appeals_data_array.count} appeals from Lighthouse for staging environment"
  else
    appeals_response = appeals_service.get_appeals(current_user)
    appeals_data_array = appeals_response.body['data']
  end
  data = data_for_first_comp_appeal(appeals_data_array)
  render json: {
    data:
  }
rescue => e
  service_exception_handler(e)
end

#open_compensation?(appeal) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
# File 'app/controllers/v0/virtual_agent/virtual_agent_appeal_controller.rb', line 113

def open_compensation?(appeal)
  appeal['attributes']['programArea'] == 'compensation' and appeal['attributes']['active']
end

#service_exception_handler(exception) ⇒ Object (private)



192
193
194
195
196
# File 'app/controllers/v0/virtual_agent/virtual_agent_appeal_controller.rb', line 192

def service_exception_handler(exception)
  context = 'An error occurred while attempting to retrieve the appeal(s)'
  log_exception_to_sentry(exception, 'context' => context)
  render nothing: true, status: :internal_server_error
end

#set_user_credentialsObject



177
178
179
180
181
182
183
184
185
186
187
188
# File 'app/controllers/v0/virtual_agent/virtual_agent_appeal_controller.rb', line 177

def set_user_credentials
  case @current_user.email
  when '[email protected]'
    ['796104437', '[email protected]']
  when '[email protected]'
    ['796378881', '[email protected]']
  when '[email protected]'
    ['796043735', '[email protected]']
  else
    [@current_user.ssn, @current_user.email]
  end
end

#transform_appeals_to_response(appeals) ⇒ Object



58
59
60
# File 'app/controllers/v0/virtual_agent/virtual_agent_appeal_controller.rb', line 58

def transform_appeals_to_response(appeals)
  appeals.map { |appeal| transform_single_appeal_to_response(appeal) }
end

#transform_single_appeal_to_response(appeal) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/v0/virtual_agent/virtual_agent_appeal_controller.rb', line 62

def transform_single_appeal_to_response(appeal)
  aoj = appeal['attributes']['aoj']
  {
    appeal_type: appeal['attributes']['programArea'].capitalize,
    filing_date: get_submission_date(appeal).strftime('%m/%d/%Y'),
    appeal_status: get_status_type_text(appeal['attributes']['status']['type'], aoj),
    updated_date: get_last_updated_date(appeal).strftime('%m/%d/%Y'),
    description: appeal['attributes']['description'] == '' ? ' ' : " (#{appeal['attributes']['description']}) ",
    appeal_or_review: get_appeal_or_review(appeal)
  }
end