Class: BGS::Form686c

Inherits:
Object
  • Object
show all
Includes:
SentryLogging
Defined in:
lib/bgs/form686c.rb

Constant Summary collapse

REMOVE_CHILD_OPTIONS =
%w[report_child18_or_older_is_not_attending_school
report_stepchild_not_in_household
report_marriage_of_child_under18].freeze
MARRIAGE_TYPES =
%w[COMMON-LAW TRIBAL PROXY OTHER].freeze
RELATIONSHIPS =
%w[CHILD DEPENDENT_PARENT].freeze

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, #set_sentry_metadata

Constructor Details

#initialize(user, saved_claim) ⇒ Form686c

Returns a new instance of Form686c.



26
27
28
29
30
31
32
33
# File 'lib/bgs/form686c.rb', line 26

def initialize(user, saved_claim)
  @user = user
  @saved_claim = saved_claim
  @end_product_name = '130 - Automated Dependency 686c'
  @end_product_code = '130DPNEBNADJ'
  @proc_state = 'Ready'
  @note_text = nil
end

Instance Attribute Details

#saved_claimObject (readonly)

Returns the value of attribute saved_claim.



18
19
20
# File 'lib/bgs/form686c.rb', line 18

def saved_claim
  @saved_claim
end

#userObject (readonly)

Returns the value of attribute user.



18
19
20
# File 'lib/bgs/form686c.rb', line 18

def user
  @user
end

Instance Method Details

#bgs_serviceObject (private)

rubocop:enable Metrics/MethodLength



186
187
188
# File 'lib/bgs/form686c.rb', line 186

def bgs_service
  BGS::Service.new(@user)
end

#bid_serviceObject (private)



190
191
192
# File 'lib/bgs/form686c.rb', line 190

def bid_service
  BID::Awards::Service.new(@user)
end

#create_proc_id_and_form(vnp_proc_state_type_cd) ⇒ Object (private)



100
101
102
103
104
105
106
107
108
# File 'lib/bgs/form686c.rb', line 100

def create_proc_id_and_form(vnp_proc_state_type_cd)
  vnp_response = bgs_service.create_proc(proc_state: vnp_proc_state_type_cd)
  bgs_service.create_proc_form(
    vnp_response[:vnp_proc_id],
    '21-686c'
  )

  vnp_response[:vnp_proc_id]
end

#get_state_type(payload) ⇒ Object (private)



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/bgs/form686c.rb', line 110

def get_state_type(payload)
  selectable_options = payload['view:selectable686_options']
  dependents_app = payload['dependents_application']

  # search through the "selectable_options" hash and check if any of the "REMOVE_CHILD_OPTIONS" are set to true
  if REMOVE_CHILD_OPTIONS.any? { |child_option| selectable_options[child_option] }
    # find which one of the remove child options is selected, and set the manual_vagov reason for that option
    selectable_options.each do |remove_option, is_selected|
      return set_to_manual_vagov(remove_option) if REMOVE_CHILD_OPTIONS.any?(remove_option) && is_selected
    end
  end

  # if the user is adding a spouse and the marriage type is anything other than CEREMONIAL, set the status to manual
  if selectable_options['add_spouse'] && MARRIAGE_TYPES.any? do |m|
       m == dependents_app['current_marriage_information']['type']
     end
    return set_to_manual_vagov('add_spouse')
  end

  # search through the array of "deaths" and check if the dependent_type = "CHILD" or "DEPENDENT_PARENT"
  if selectable_options['report_death'] && dependents_app['deaths'].any? do |h|
       RELATIONSHIPS.include?(h['dependent_type'])
     end
    return set_to_manual_vagov('report_death')
  end

  return set_to_manual_vagov('report674') if selectable_options['report674']

  'Started'
end

#prep_manual_claim(benefit_claim_id) ⇒ Object (private)



194
195
196
197
198
# File 'lib/bgs/form686c.rb', line 194

def prep_manual_claim(benefit_claim_id)
  @proc_state = 'MANUAL_VAGOV'

  bgs_service.create_note(benefit_claim_id, @note_text)
end

#process_relationships(proc_id, veteran, payload) ⇒ Object (private)



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/bgs/form686c.rb', line 84

def process_relationships(proc_id, veteran, payload)
  dependents = Dependents.new(proc_id:, payload:, user: @user).create_all
  marriages = Marriages.new(proc_id:, payload:, user: @user).create_all
  children = Children.new(proc_id:, payload:, user: @user).create_all

  veteran_dependents = dependents + marriages + children[:dependents]

  VnpRelationships.new(
    proc_id:,
    veteran:,
    dependents: veteran_dependents,
    step_children: children[:step_children],
    user: @user
  ).create_all
end

#set_claim_type(proc_state, selectable_options) ⇒ Object (private)

rubocop:disable Metrics/MethodLength the default claim type is 130DPNEBNADJ (eBenefits Dependency Adjustment)



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/bgs/form686c.rb', line 143

def set_claim_type(proc_state, selectable_options)
  # selectable_options is a hash of boolean values (ex. 'report_divorce' => false)
  # if any of the dependent_removal_options in selectable_options is set to true, we are removing a dependent
  removing_dependent = false
  if Flipper.enabled?(:dependents_removal_check)
    dependent_removal_options = REMOVE_CHILD_OPTIONS.dup << ('report_death') << ('report_divorce')
    removing_dependent = dependent_removal_options.any? { |option| selectable_options[option] }
  end

  # we only need to do a pension check if we are removing a dependent or we have set the status to manual
  receiving_pension = false
  if Flipper.enabled?(:dependents_pension_check) && (removing_dependent || proc_state == 'MANUAL_VAGOV')
    pension_response = bid_service.get_awards_pension
    receiving_pension = pension_response.body['awards_pension']['is_in_receipt_of_pension']
  end

  # if we are setting the claim to be manually reviewed, then exception/rejection labels should be used
  if proc_state == 'MANUAL_VAGOV'
    if removing_dependent && receiving_pension
      @end_product_name = 'PMC - Self Service - Removal of Dependent Exceptn'
      @end_product_code = '130SSRDPMCE'
    elsif removing_dependent
      @end_product_name = 'Self Service - Removal of Dependent Exception'
      @end_product_code = '130SSRDE'
    elsif receiving_pension
      @end_product_name = 'PMC eBenefits Dependency Adjustment Reject'
      @end_product_code = '130DAEBNPMCR'
    else
      @end_product_name = 'eBenefits Dependency Adjustment Reject'
      @end_product_code = '130DPEBNAJRE'
    end
  elsif removing_dependent
    if receiving_pension
      @end_product_name = 'PMC - Self Service - Removal of Dependent'
      @end_product_code = '130SSRDPMC'
    else
      @end_product_name = 'Self Service - Removal of Dependent'
      @end_product_code = '130SSRD'
    end
  end
end

#set_to_manual_vagov(reason_code) ⇒ Object (private)



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/bgs/form686c.rb', line 200

def set_to_manual_vagov(reason_code)
  @note_text = 'Claim set to manual by VA.gov: This application needs manual review because a 686 was submitted '

  case reason_code
  when 'report_death'
    @note_text += 'for removal of a child/dependent parent due to death.'
  when 'add_spouse'
    @note_text += 'to add a spouse due to civic/non-ceremonial marriage.'
  when 'report_stepchild_not_in_household'
    @note_text += 'for removal of a step-child that has left household.'
  when 'report_marriage_of_child_under18'
    @note_text += 'for removal of a married minor child.'
  when 'report_child18_or_older_is_not_attending_school'
    @note_text += 'for removal of a schoolchild over 18 who has stopped attending school.'
  when 'report674'
    @note_text += 'along with a 674.'
  end

  'MANUAL_VAGOV'
end

#submit(payload) ⇒ Object

rubocop:disable Metrics/MethodLength



36
37
38
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
# File 'lib/bgs/form686c.rb', line 36

def submit(payload)
  vnp_proc_state_type_cd = get_state_type(payload)
  proc_id = create_proc_id_and_form(vnp_proc_state_type_cd)
  veteran = VnpVeteran.new(proc_id:, payload:, user:, claim_type: '130DPNEBNADJ').create

  process_relationships(proc_id, veteran, payload)

  vnp_benefit_claim = VnpBenefitClaim.new(proc_id:, veteran:, user:)
  vnp_benefit_claim_record = vnp_benefit_claim.create

  set_claim_type(vnp_proc_state_type_cd, payload['view:selectable686_options'])

  # temporary logging to troubleshoot
  log_message_to_sentry("#{proc_id} - #{@end_product_code}", :warn, '', { team: 'vfs-ebenefits' })

  benefit_claim_record = BenefitClaim.new(
    args: {
      vnp_benefit_claim: vnp_benefit_claim_record,
      veteran:,
      user:,
      proc_id:,
      end_product_name: @end_product_name,
      end_product_code: @end_product_code
    }
  ).create

  begin
    benefit_claim_id = benefit_claim_record[:benefit_claim_id]
    # temporary logging to troubleshoot
    log_message_to_sentry("#{proc_id} - #{benefit_claim_id}", :warn, '', { team: 'vfs-ebenefits' })

    vnp_benefit_claim.update(benefit_claim_record, vnp_benefit_claim_record)
    prep_manual_claim(benefit_claim_id) if vnp_proc_state_type_cd == 'MANUAL_VAGOV'
    bgs_service.update_proc(proc_id, proc_state: @proc_state)
  rescue => e
    Rails.logger.warning('BGS::Form686c.submit failed after creating benefit claim in BGS',
                         {
                           user_uuid: user.uuid,
                           saved_claim_id: saved_claim.id,
                           icn: user.icn,
                           error: e.message
                         })
  end
end