Class: BipClaims::Service

Inherits:
Common::Client::Base show all
Includes:
Common::Client::Concerns::Monitoring
Defined in:
lib/bip_claims/service.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.bip_claims'

Instance Method Summary collapse

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

#with_monitoring

Methods inherited from Common::Client::Base

configuration, #raise_backend_exception

Methods included from SentryLogging

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

Instance Method Details

#lookup_veteran_from_mpi(claim) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bip_claims/service.rb', line 35

def lookup_veteran_from_mpi(claim)
  attributes_hash = veteran_attributes(claim)
  veteran = MPI::Service.new.find_profile_by_attributes(first_name: attributes_hash[:first_name],
                                                        last_name: attributes_hash[:last_name],
                                                        birth_date: attributes_hash[:birth_date],
                                                        ssn: attributes_hash[:ssn])
  if veteran.profile&.participant_id
    StatsD.increment("#{STATSD_KEY_PREFIX}.mvi_lookup_hit")
    veteran.profile
  else
    StatsD.increment("#{STATSD_KEY_PREFIX}.mvi_lookup_miss")
    nil
  end
end

#veteran_attributes(claim) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bip_claims/service.rb', line 15

def veteran_attributes(claim)
  case claim.form_id
  when '21P-530'
    ssn, full_name, bday = claim.parsed_form.values_at(
      'veteranSocialSecurityNumber',
      'veteranFullName',
      'veteranDateOfBirth'
    )
  else
    raise ArgumentError, "Unsupported form id: #{claim.form_id}"
  end

  {
    ssn: ssn&.gsub(/\D/, ''),
    first_name: full_name['first'],
    last_name: full_name['last'],
    birth_date: bday
  }
end