Class: DebtManagementCenter::StatementIdentifierService

Inherits:
Object
  • Object
show all
Includes:
SentryLogging
Defined in:
lib/debt_management_center/statement_identifier_service.rb

Defined Under Namespace

Classes: MalformedMCPStatement, RetryableError, Vet360IdNotFound

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.copay_notifications.new_statement'
RETRYABLE_ERRORS =
[
  Common::Exceptions::GatewayTimeout,
  Breakers::OutageException,
  Faraday::ConnectionFailed,
  Common::Exceptions::BackendServiceException
].freeze

Instance Method Summary collapse

Methods included from SentryLogging

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

Constructor Details

#initialize(statement) ⇒ StatementIdentifierService

Returns a new instance of StatementIdentifierService.



32
33
34
35
36
37
38
39
40
# File 'lib/debt_management_center/statement_identifier_service.rb', line 32

def initialize(statement)
  @statement = statement
  raise MalformedMCPStatement, statement unless legal_statement

  @identifier = @statement['veteranIdentifier']
  @identifier_type = @statement['identifierType']
  @facility_id = @statement['facilityNum']
  @identifier_key = nil
end

Instance Method Details

#get_mpi_dataObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/debt_management_center/statement_identifier_service.rb', line 42

def get_mpi_data
  mpi_response = get_mpi_profile
  if mpi_response.ok?
    StatsD.increment("#{STATSD_KEY_PREFIX}.mpi.success")
    profile = mpi_response.profile
    {
      icn: profile.icn,
      first_name: profile.given_names.first
    }
  else
    StatsD.increment("#{STATSD_KEY_PREFIX}.mpi.failure")
    raise mpi_response.error
  end
rescue *RETRYABLE_ERRORS => e
  raise RetryableError, e
end

#get_mpi_profileObject (private)



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/debt_management_center/statement_identifier_service.rb', line 67

def get_mpi_profile
  if @identifier_type == 'edipi'
    StatsD.increment("#{STATSD_KEY_PREFIX}.edipi")
    MPI::Service.new.find_profile_by_edipi(edipi: @identifier)
  else
    StatsD.increment("#{STATSD_KEY_PREFIX}.vista")
    MPI::Service.new.find_profile_by_facility(
      facility_id: @facility_id,
      vista_id: @identifier
    )
  end
end


80
81
82
83
84
# File 'lib/debt_management_center/statement_identifier_service.rb', line 80

def legal_statement
  @statement['veteranIdentifier'] &&
    @statement['identifierType'] &&
    @statement['facilityNum']
end

#vista_account_idObject



59
60
61
62
63
# File 'lib/debt_management_center/statement_identifier_service.rb', line 59

def 
  offset = 16 - (@facility_id + @identifier).length
  padding = '0' * offset if offset >= 0
  "#{@facility_id}#{padding}#{@identifier}"
end