Class: VAProfile::VeteranStatus::Service

Inherits:
Service show all
Includes:
Common::Client::Concerns::Monitoring
Defined in:
lib/va_profile/veteran_status/service.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
"#{VAProfile::Service::STATSD_KEY_PREFIX}.veteran_status".freeze
OID =

double check swagger

'2.16.840.1.113883.3.42.10001.100001.12'
AAID =

double check swagger.

'^NI^200DOD^USDOD'

Instance Method Summary collapse

Methods included from Common::Client::Concerns::Monitoring

#increment, #increment_failure, #increment_total, #with_monitoring

Methods inherited from Service

breakers_service, #final_failure?, #handle_error, #initialize, #log_dates, #parse_messages, #perform, #person_transaction?, #person_transaction_failure?, #raise_backend_exception, #raise_invalid_body, #report_stats_on, #save_error_details

Methods inherited from Common::Client::Base

#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Constructor Details

This class inherits a constructor from VAProfile::Service

Instance Method Details

#aaidObject (private)



98
99
100
# File 'lib/va_profile/veteran_status/service.rb', line 98

def aaid
  AAID if @user&.edipi.present?
end

#edipi_idObject (private)



94
95
96
# File 'lib/va_profile/veteran_status/service.rb', line 94

def edipi_id
  @user&.edipi.presence
end

#edipi_present!Object (private)



86
87
88
# File 'lib/va_profile/veteran_status/service.rb', line 86

def edipi_present!
  raise 'User does not have a valid edipi' if @user&.edipi.blank?
end

#edipi_with_aaidObject (private)



90
91
92
# File 'lib/va_profile/veteran_status/service.rb', line 90

def edipi_with_aaid
  "#{edipi_id}#{aaid}"
end

#get_veteran_statusVAProfile::VeteranStatus::VeteranStatusResponse

GET’s a user’s veteran status info from the VAProfile API If a user is not found in VAProfile, an empty VeteranStatusResponse with a 404 status will be returned

Returns:



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/va_profile/veteran_status/service.rb', line 26

def get_veteran_status
  with_monitoring do
    edipi_present!
    response = perform(:post, identity_path, VAProfile::Models::VeteranStatus.in_json)
    VeteranStatusResponse.from(@current_user, response)
  end
rescue Common::Client::Errors::ClientError => e
  handle_client_error(e)
rescue => e
  handle_error(e)
end

#handle_client_error(e) ⇒ Object (private)



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/va_profile/veteran_status/service.rb', line 67

def handle_client_error(e)
  additional_params = { edipi: @user&.edipi }
  if e.status == 404
    log_exception_to_sentry(
      e,
      additional_params,
      { va_profile: :veteran_status_title_not_found },
      :warning
    )
    raise VAProfile::VeteranStatus::VAProfileError.new(status: 404)
  elsif e.status >= 400 && e.status < 500
    log_exception_to_sentry(
      e, additional_params, { va_profile: :client_error_related_to_title38 }, :warning
    )
    raise VAProfile::VeteranStatus::VAProfileError.new(status: e.status)
  end
  handle_error(e)
end

#identity_pathObject

VA Profile endpoints use the OID (Organizational Identifier), the EDIPI, and the Assigning Authority ID to identify which person will be updated/retrieved.



61
62
63
# File 'lib/va_profile/veteran_status/service.rb', line 61

def identity_path
  "#{OID}/#{ERB::Util.url_encode(edipi_with_aaid.to_s)}"
end

#military_person?Boolean

Returns boolean for user being/not being considered a military person based on their Title 38 Status Code.

Returns:

  • (Boolean)


55
56
57
# File 'lib/va_profile/veteran_status/service.rb', line 55

def military_person?
  title38_status == 'V3' || title38_status == 'V6'
end

#title38_statusString

Returns Title 38 status code.

Returns:

  • (String)

    Title 38 status code



44
45
46
47
48
# File 'lib/va_profile/veteran_status/service.rb', line 44

def title38_status
  result = get_veteran_status&.title38_status_code&.title38_status_code
  Rails.logger.info "VaProfile title38: #{result}"
  result
end

#veteran?Boolean

Returns true if user is a title 38 veteran.

Returns:

  • (Boolean)

    true if user is a title 38 veteran



39
40
41
# File 'lib/va_profile/veteran_status/service.rb', line 39

def veteran?
  title38_status == 'V1'
end