Class: V0::HealthCareApplicationsController

Inherits:
ApplicationController show all
Includes:
IgnoreNotFound
Defined in:
app/controllers/v0/health_care_applications_controller.rb

Constant Summary collapse

FORM_ID =
'1010ez'

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?

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_facilities(lighthouse_facilities) ⇒ Object (private)



88
89
90
91
# File 'app/controllers/v0/health_care_applications_controller.rb', line 88

def active_facilities(lighthouse_facilities)
  active_ids = active_ves_facility_ids
  lighthouse_facilities.select { |facility| active_ids.include?(facility.unique_id) }
end

#active_ves_facility_idsObject (private)



93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/v0/health_care_applications_controller.rb', line 93

def active_ves_facility_ids
  ids = cached_ves_facility_ids

  return ids if ids.any?
  return ids if Flipper.enabled?(:hca_retrieve_facilities_without_repopulating)

  HCA::StdInstitutionImportJob.new.perform

  cached_ves_facility_ids
end

#cached_ves_facility_idsObject (private)



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

def cached_ves_facility_ids
  StdInstitutionFacility.active.pluck(:station_number).compact
end

#createObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/v0/health_care_applications_controller.rb', line 35

def create
  health_care_application.async_compatible = params[:async_all]
  health_care_application.google_analytics_client_id = params[:ga_client_id]
  health_care_application.user = current_user

  begin
    result = health_care_application.process!
  rescue HCA::SOAPParser::ValidationError
    raise Common::Exceptions::BackendServiceException.new('HCA422', status: 422)
  end

  clear_saved_form(FORM_ID)

  if result[:id]
    render json: HealthCareApplicationSerializer.new(result)
  else
    render json: result
  end
end

#enrollment_statusObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/v0/health_care_applications_controller.rb', line 60

def enrollment_status
  loa3 = current_user&.loa3?

  icn =
    if loa3
      current_user.icn
    else
      Sentry.set_extras(user_loa: current_user&.loa)
      HealthCareApplication.user_icn(HealthCareApplication.user_attributes(params[:userAttributes]))
    end

  raise Common::Exceptions::RecordNotFound, nil if icn.blank?

  render(json: HealthCareApplication.enrollment_status(icn, loa3))
end

#facilitiesObject



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

def facilities
  lighthouse_facilities = lighthouse_facilities_service.get_facilities(lighthouse_facilities_params)

  render(json: active_facilities(lighthouse_facilities))
end

#health_care_applicationObject (private)



108
109
110
# File 'app/controllers/v0/health_care_applications_controller.rb', line 108

def health_care_application
  @health_care_application ||= HealthCareApplication.new(params.permit(:form))
end

#healthcheckObject



76
77
78
# File 'app/controllers/v0/health_care_applications_controller.rb', line 76

def healthcheck
  render(json: HCA::Service.new.health_check)
end

#lighthouse_facilities_paramsObject (private)



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'app/controllers/v0/health_care_applications_controller.rb', line 116

def lighthouse_facilities_params
  params.except(:format).permit(
    :zip,
    :state,
    :lat,
    :long,
    :radius,
    :bbox,
    :visn,
    :type,
    :services,
    :mobile,
    :page,
    :per_page,
    facilityIds: []
  )
end

#lighthouse_facilities_serviceObject (private)



112
113
114
# File 'app/controllers/v0/health_care_applications_controller.rb', line 112

def lighthouse_facilities_service
  @lighthouse_facilities_service ||= Lighthouse::Facilities::V1::Client.new
end

#rating_infoObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/v0/health_care_applications_controller.rb', line 21

def rating_info
  if Flipper.enabled?(:hca_disable_bgs_service)
    # Return 0 when not calling the actual BGS::Service
    render json: HCARatingInfoSerializer.new({ user_percent_of_disability: 0 })
    return
  end

  service = BGS::Service.new(current_user)
  disability_rating = service.find_rating_data[:disability_rating_record][:service_connected_combined_degree]

  hca_rating_info = { user_percent_of_disability: disability_rating }
  render json: HCARatingInfoSerializer.new(hca_rating_info)
end

#record_submission_attemptObject (private)



134
135
136
137
138
139
# File 'app/controllers/v0/health_care_applications_controller.rb', line 134

def record_submission_attempt
  StatsD.increment("#{HCA::Service::STATSD_KEY_PREFIX}.submission_attempt")
  if health_care_application.short_form?
    StatsD.increment("#{HCA::Service::STATSD_KEY_PREFIX}.submission_attempt_short_form")
  end
end

#showObject



55
56
57
58
# File 'app/controllers/v0/health_care_applications_controller.rb', line 55

def show
  application = HealthCareApplication.find(params[:id])
  render json: HealthCareApplicationSerializer.new(application)
end

#skip_sentry_exception_typesObject (private)



141
142
143
# File 'app/controllers/v0/health_care_applications_controller.rb', line 141

def skip_sentry_exception_types
  super + [Common::Exceptions::BackendServiceException]
end