Class: V0::DisabilityCompensationFormsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/v0/disability_compensation_forms_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

#auth_headersObject (private)



156
157
158
# File 'app/controllers/v0/disability_compensation_forms_controller.rb', line 156

def auth_headers
  EVSS::DisabilityCompensationAuthHeaders.new(@current_user).add_headers(EVSS::AuthHeaders.new(@current_user).to_h)
end

#auth_rating_infoObject (private)



104
105
106
107
# File 'app/controllers/v0/disability_compensation_forms_controller.rb', line 104

def auth_rating_info
  api = lighthouse? ? :lighthouse : :evss
  authorize(api, :rating_info_access?)
end

#create_submission(saved_claim) ⇒ Object (private)



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'app/controllers/v0/disability_compensation_forms_controller.rb', line 117

def create_submission(saved_claim)
  Rails.logger.info('Creating 526 submission', user_uuid: @current_user&.uuid, saved_claim_id: saved_claim&.id)
  submission = Form526Submission.new(
    user_uuid: @current_user.uuid,
    user_account: @current_user.,
    saved_claim_id: saved_claim.id,
    auth_headers_json: auth_headers.to_json,
    form_json: saved_claim.to_submission_data(@current_user),
    submit_endpoint: includes_toxic_exposure? ? 'claims_api' : 'evss'
  ) { |sub| sub.add_birls_ids @current_user.birls_id }

  if missing_disabilities?(submission)
    raise Common::Exceptions::UnprocessableEntity.new(
      detail: 'no new or increased disabilities were submitted', source: 'DisabilityCompensationFormsController'
    )
  end

  submission.save! && submission
rescue PG::NotNullViolation => e
  Rails.logger.error(
    'Creating 526 submission: PG::NotNullViolation', user_uuid: @current_user&.uuid, saved_claim_id: saved_claim&.id
  )
  raise e
end

#form_contentObject (private)



109
110
111
# File 'app/controllers/v0/disability_compensation_forms_controller.rb', line 109

def form_content
  @form_content ||= JSON.parse(request.body.string)
end

#includes_toxic_exposure?Boolean (private)

Returns:

  • (Boolean)


164
165
166
167
# File 'app/controllers/v0/disability_compensation_forms_controller.rb', line 164

def includes_toxic_exposure?
  # any form that has a startedFormVersion (whether it is '2019' or '2022') will go through the Toxic Exposure flow
  form_content['form526']['startedFormVersion']
end

#lighthouse?Boolean (private)

Returns:

  • (Boolean)


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

def lighthouse?
  Flipper.enabled?(:profile_lighthouse_rating_info, @current_user)
end

#log_failure(claim) ⇒ Object (private)



142
143
144
145
# File 'app/controllers/v0/disability_compensation_forms_controller.rb', line 142

def log_failure(claim)
  StatsD.increment("#{stats_key}.failure")
  raise Common::Exceptions::ValidationErrors, claim
end

#log_success(claim) ⇒ Object (private)



147
148
149
150
# File 'app/controllers/v0/disability_compensation_forms_controller.rb', line 147

def log_success(claim)
  StatsD.increment("#{stats_key}.success")
  Rails.logger.info "ClaimID=#{claim.confirmation_number} Form=#{claim.class::FORM}"
end

#missing_disabilities?(submission) ⇒ Boolean (private)

Returns:

  • (Boolean)


169
170
171
172
173
174
175
176
177
178
# File 'app/controllers/v0/disability_compensation_forms_controller.rb', line 169

def missing_disabilities?(submission)
  if submission.form['form526']['form526']['disabilities'].none?
    StatsD.increment("#{stats_key}.failure")
    Rails.logger.error(
      'Creating 526 submission: no new or increased disabilities were submitted', user_uuid: @current_user&.uuid
    )
    return true
  end
  false
end

#rated_disabilitiesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/v0/disability_compensation_forms_controller.rb', line 18

def rated_disabilities
  invoker = 'V0::DisabilityCompensationFormsController#rated_disabilities'
  api_provider = ApiProviderFactory.call(
    type: ApiProviderFactory::FACTORIES[:rated_disabilities],
    provider: nil,
    options: { icn: @current_user.icn.to_s, auth_headers: },
    current_user: @current_user,
    feature_toggle: ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES_FOREGROUND
  )

  response = api_provider.get_rated_disabilities(nil, nil, { invoker: })

  render json: RatedDisabilitiesSerializer.new(response)
end

#rating_infoObject



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

def rating_info
  if lighthouse?
    service = LighthouseRatedDisabilitiesProvider.new(@current_user.icn)

    disability_rating = service.get_combined_disability_rating

    rating_info = { user_percent_of_disability: disability_rating }
    render json: LighthouseRatingInfoSerializer.new(rating_info)
  else
    rating_info_service = EVSS::CommonService.new(auth_headers)
    response = rating_info_service.get_rating_info

    render json: RatingInfoSerializer.new(response)
  end
end

#separation_locationsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/v0/disability_compensation_forms_controller.rb', line 33

def separation_locations
  response = EVSS::ReferenceData::ResponseStrategy.new.cache_by_user_and_type(
    :all_users,
    :get_separation_locations
  ) do
    api_provider = ApiProviderFactory.call(
      type: ApiProviderFactory::FACTORIES[:brd],
      provider: nil,
      options: {},
      current_user: @current_user,
      feature_toggle: ApiProviderFactory::FEATURE_TOGGLE_BRD
    )
    api_provider.get_separation_locations
  end
  render json: EVSSSeparationLocationSerializer.new(response)
end

#stats_keyObject (private)



160
161
162
# File 'app/controllers/v0/disability_compensation_forms_controller.rb', line 160

def stats_key
  'api.disability_compensation'
end

#submission_statusObject



79
80
81
82
83
84
# File 'app/controllers/v0/disability_compensation_forms_controller.rb', line 79

def submission_status
  job_status = Form526JobStatus.where(job_id: params[:job_id]).first
  raise Common::Exceptions::RecordNotFound, params[:job_id] unless job_status

  render json: Form526JobStatusSerializer.new(job_status)
end

#submit_all_claimObject



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/controllers/v0/disability_compensation_forms_controller.rb', line 55

def submit_all_claim
  temp_separation_location_fix if Flipper.enabled?(:disability_compensation_temp_separation_location_code_string,
                                                   @current_user)

  saved_claim = SavedClaim::DisabilityCompensation::Form526AllClaim.from_hash(form_content)
  saved_claim.save ? log_success(saved_claim) : log_failure(saved_claim)
  submission = create_submission(saved_claim)
  # if jid = 0 then the submission was prevented from going any further in the process
  jid = 0

  # Feature flag to stop submission from being submitted to third-party service
  # With this on, the submission will NOT be processed by EVSS or Lighthouse,
  # nor will it go to VBMS,
  # but the line of code before this one creates the submission in the vets-api database
  if Flipper.enabled?(:disability_compensation_prevent_submission_job, @current_user)
    Rails.logger.info("Submission ID: #{submission.id} prevented from sending to third party service.")
  else
    jid = submission.start
  end

  render json: { data: { attributes: { job_id: jid } } },
         status: :ok
end

#suggested_conditionsObject



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

def suggested_conditions
  results = DisabilityContention.suggested(params[:name_part])
  render json: DisabilityContentionSerializer.new(results)
end

#temp_separation_location_fixObject (private)

TEMPORARY Turn separation location into string 11/18/2024 BRD EVSS -> Lighthouse migration caused separation location to turn into an integer, while SavedClaim (vets-json-schema) is expecting a string



184
185
186
187
188
189
190
191
192
193
# File 'app/controllers/v0/disability_compensation_forms_controller.rb', line 184

def temp_separation_location_fix
  if form_content.is_a?(Hash) && form_content['form526'].is_a?(Hash)
    separation_location_code = form_content.dig('form526', 'serviceInformation', 'separationLocation',
                                                'separationLocationCode')
    unless separation_location_code.nil?
      form_content['form526']['serviceInformation']['separationLocation']['separationLocationCode'] =
        separation_location_code.to_s
    end
  end
end

#validate_name_partObject (private)



152
153
154
# File 'app/controllers/v0/disability_compensation_forms_controller.rb', line 152

def validate_name_part
  raise Common::Exceptions::ParameterMissing, 'name_part' if params[:name_part].blank?
end