Class: BGS::DependentService

Inherits:
Object
  • Object
show all
Includes:
SentryLogging
Defined in:
app/services/bgs/dependent_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SentryLogging

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

Constructor Details

#initialize(user) ⇒ DependentService

Returns a new instance of DependentService.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/bgs/dependent_service.rb', line 18

def initialize(user)
  @first_name = user.first_name
  @middle_name = user.middle_name
  @last_name = user.last_name
  @ssn = user.ssn
  @uuid = user.uuid
  @birth_date = user.birth_date
  @common_name = user.common_name
  @email = user.email
  @icn = user.icn
  @participant_id = user.participant_id
  @va_profile_email = user.va_profile_email
end

Instance Attribute Details

#birth_dateObject (readonly)

Returns the value of attribute birth_date.



7
8
9
# File 'app/services/bgs/dependent_service.rb', line 7

def birth_date
  @birth_date
end

#common_nameObject (readonly)

Returns the value of attribute common_name.



7
8
9
# File 'app/services/bgs/dependent_service.rb', line 7

def common_name
  @common_name
end

#emailObject (readonly)

Returns the value of attribute email.



7
8
9
# File 'app/services/bgs/dependent_service.rb', line 7

def email
  @email
end

#first_nameObject (readonly)

Returns the value of attribute first_name.



7
8
9
# File 'app/services/bgs/dependent_service.rb', line 7

def first_name
  @first_name
end

#icnObject (readonly)

Returns the value of attribute icn.



7
8
9
# File 'app/services/bgs/dependent_service.rb', line 7

def icn
  @icn
end

#last_nameObject (readonly)

Returns the value of attribute last_name.



7
8
9
# File 'app/services/bgs/dependent_service.rb', line 7

def last_name
  @last_name
end

#middle_nameObject (readonly)

Returns the value of attribute middle_name.



7
8
9
# File 'app/services/bgs/dependent_service.rb', line 7

def middle_name
  @middle_name
end

#participant_idObject (readonly)

Returns the value of attribute participant_id.



7
8
9
# File 'app/services/bgs/dependent_service.rb', line 7

def participant_id
  @participant_id
end

#ssnObject (readonly)

Returns the value of attribute ssn.



7
8
9
# File 'app/services/bgs/dependent_service.rb', line 7

def ssn
  @ssn
end

#uuidObject (readonly)

Returns the value of attribute uuid.



7
8
9
# File 'app/services/bgs/dependent_service.rb', line 7

def uuid
  @uuid
end

Instance Method Details

#get_dependentsObject



32
33
34
35
36
# File 'app/services/bgs/dependent_service.rb', line 32

def get_dependents
  return { persons: [] } if participant_id.blank?

  service.claimant.find_dependents_by_participant_id(participant_id, ssn) || { persons: [] }
end

#submit_686c_form(claim) ⇒ Object

rubocop:disable Metrics/MethodLength



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/services/bgs/dependent_service.rb', line 39

def submit_686c_form(claim)
  Rails.logger.info('BGS::DependentService running!', { user_uuid: uuid, saved_claim_id: claim.id, icn: })
  bgs_person = service.people.find_person_by_ptcpnt_id(participant_id) || service.people.find_by_ssn(ssn) # rubocop:disable Rails/DynamicFindBy
  file_number = bgs_person[:file_nbr]
  # BGS's file number is supposed to be an eight or nine-digit string, and
  # our code is built upon the assumption that this is the case. However,
  # we've seen cases where BGS returns a file number with dashes
  # (e.g. XXX-XX-XXXX). In this case specifically, we can simply strip out
  # the dashes and proceed with form submission.
  file_number = file_number.delete('-') if file_number =~ /\A\d{3}-\d{2}-\d{4}\z/
  form_hash_686c = get_form_hash_686c(file_number:)
  # The `validate_*!` calls below will raise errors if we have an invalid
  # file number, or if the file number and SSN don't match. Even if this is
  # the case, we still want to submit a PDF to the veteran's VBMS eFolder.
  # This is because we are currently relying on the presence of a PDF and
  # absence of a BGS-established claim to identify cases where Form 686c-674
  # submission failed.

  if Flipper.enabled?(:dependents_encrypt_jobs)
    encrypted_vet_info = KmsEncrypted::Box.new.encrypt(form_hash_686c.to_json)
    VBMS::SubmitDependentsPdfEncryptedJob.perform_async(
      claim.id,
      encrypted_vet_info,
      claim.submittable_686?,
      claim.submittable_674?
    )
  else
    VBMS::SubmitDependentsPdfJob.perform_async(
      claim.id,
      form_hash_686c,
      claim.submittable_686?,
      claim.submittable_674?
    )
  end

  if claim.submittable_686? || claim.submittable_674?
    # Previously, we would wait until `BGS::Service#create_person`'s call to
    # BGS's `vnp_person_create` endpoint to fail due to an invalid file number
    # or file number / SSN mismatch. Unfortunately, BGS's error response is
    # so verbose that Sentry is unable to capture the portion of the message
    # detailing this specific file number / SSN error, and is therefore unable
    # to distinguish this error from others in our Sentry dashboards. That is
    # why I am deliberately raising these errors here.
    validate_file_number_format!(file_number:)
    validate_file_number_matches_ssn!(file_number:)
    if claim.submittable_686?
      if Flipper.enabled?(:dependents_encrypt_jobs)
        BGS::SubmitForm686cEncryptedJob.perform_async(
          uuid, @icn, claim.id, encrypted_vet_info
        )
      else
        BGS::SubmitForm686cJob.perform_async(
          uuid, @icn, claim.id, form_hash_686c
        )
      end
    else
      if Flipper.enabled?(:dependents_encrypt_jobs) # rubocop:disable Style/IfInsideElse
        BGS::SubmitForm674EncryptedJob.perform_async(
          uuid, @icn, claim.id, encrypted_vet_info
        )
      else
        BGS::SubmitForm674Job.perform_async(
          uuid, @icn, claim.id, form_hash_686c
        )
      end
    end
    Rails.logger.info('BGS::DependentService succeeded!', { user_uuid: uuid, saved_claim_id: claim.id, icn: })
  end
rescue => e
  Rails.logger.error('BGS::DependentService failed!', { user_uuid: uuid, saved_claim_id: claim.id, icn:, error: e.message }) # rubocop:disable Layout/LineLength
  log_exception_to_sentry(e, { icn:, uuid: }, { team: Constants::SENTRY_REPORTING_TEAM })
end