Class: VAProfile::MilitaryPersonnel::Service

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

Constant Summary collapse

STATSD_KEY_PREFIX =
"#{VAProfile::Service::STATSD_KEY_PREFIX}.military_personnel".freeze
OID =
'2.16.840.1.113883.3.42.10001.100001.12'
AAID =
'^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)



75
76
77
# File 'lib/va_profile/military_personnel/service.rb', line 75

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

#edipi_idObject (private)



71
72
73
# File 'lib/va_profile/military_personnel/service.rb', line 71

def edipi_id
  @user&.edipi.presence
end

#edipi_present!Object (private)



63
64
65
# File 'lib/va_profile/military_personnel/service.rb', line 63

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

#edipi_with_aaidObject (private)



67
68
69
# File 'lib/va_profile/military_personnel/service.rb', line 67

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

#get_service_historyVAProfile::MilitaryPersonnel::ServiceHistoryResponse

GET’s a user’s military service history from the VAProfile API If a user is not found in VAProfile, an empty ServiceHistoryResponse with a 404 status will be returned

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/va_profile/military_personnel/service.rb', line 28

def get_service_history
  with_monitoring do
    edipi_present!

    response = perform(:post, identity_path, VAProfile::Models::ServiceHistory.in_json)

    ServiceHistoryResponse.from(@current_user, response)
  end
rescue Common::Client::Errors::ClientError => e
  error_status = e.status
  if error_status == 404
    log_exception_to_sentry(
      e, { edipi: @user.edipi }, { va_profile: :service_history_not_found }, :warning
    )

    return ServiceHistoryResponse.new(404, episodes: nil)
  elsif error_status && error_status >= 400 && error_status < 500
    return ServiceHistoryResponse.new(error_status, episodes: nil)
  end

  # Sometimes e.status is nil. Why?
  Rails.logger.info('Miscellaneous service history error', error: e)
  handle_error(e)
rescue => e
  handle_error(e)
end

#identity_pathObject

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



57
58
59
# File 'lib/va_profile/military_personnel/service.rb', line 57

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