department-of-veterans-affairs / caseflow

Caseflow is a web application that enables the tracking and processing of appealed claims at the Board of Veterans' Appeals.
Other
54 stars 19 forks source link

DuplicateEP data cleanup #11081

Closed leikkisa closed 1 year ago

leikkisa commented 5 years ago

This is an open ticket for handling data cleanup until a longer term solution is identified. This ticket is specifically for handling when this error is caused by:

  1. PIF not unlocked: The EP was manually closed, and the PIF wasn't synced to be unlocked

Two other reasons we might see this error:

  1. Sync timing: An EP using the same modifier was closed within the last day, and the PIF hasn't synced yet (resolved by https://github.com/department-of-veterans-affairs/caseflow/issues/11043)
  2. Invalid POA: The veteran has an invalid Power of Attorney, and the claim establishment locks the pif, but doesn't ultimately succeed. (see https://github.com/department-of-veterans-affairs/caseflow/issues/12254)

PIF cleanup request

To see reviews that we've gotten errors for, and whether a cleanup has been requested for them, please see this PIF cleanup spreadsheet

Technical notes

# set a current user
RequestStore[:current_user] = OpenStruct.new(
  ip_address: "127.0.0.1",
  station_id: "283",
  css_id: "CSFLOW",
  regional_office: "DSUSER"
)
# finding reviews that potentially need resolution
hlrs = HigherLevelReview.where("establishment_error ILIKE '%duplicateep%'")
problem_hlrs = hlrs.select{ |hlr| hlr.veteran.end_products.select{ |ep| ep.claim_type_code.include?("030") && ["CAN", "CLR"].include?(ep.status_type_code) && [Date.today, 1.day.ago.to_date].include?(ep.last_action_date) }.empty? }

scs = SupplementalClaim.where("establishment_error ILIKE '%duplicateep%'")
problem_scs = scs.select{ |sc| sc.veteran.end_products.select{ |ep| ep.claim_type_code.include?("040") && ["CAN", "CLR"].include?(ep.status_type_code) && [Date.today, 1.day.ago.to_date].include?(ep.last_action_date) }.empty? }

problem_reviews = problem_scs + problem_hlrs

Code for establishing with another modifier. If this does not succeed for any modifiers, the problem may be due to invalid POA data (see other ticket referenced above).

def resolve_duplicate_eps(reviews)
  # veterans with invalid POAs
  skip_pids = ["10262339", "2906402", "580061"]
  output = ""

  reviews.each do |r|
    if skip_pids.include? r.veteran.participant_id
      output = "#{r.class.name} #{r.id} has a veteran with a bad pid!\n#{output}"
      next
    end

    v = r.veteran
    verb = "cleared"
    r.end_product_establishments.each do |epe|
      next if epe.reference_id.present?

      # Check if active duplicate exists
      dupes = eps.select{ |ep| ep.claim_type_code == epe.code && ep.claim_date.to_date == epe.claim_date && EndProductEstablishment.where(reference_id: ep.claim_id).none? }
      next if dupes.any?

      verb = "established"
      ep2e = epe.send(:end_product_to_establish)
      epmf = EndProductModifierFinder.new(epe, v)
      taken = epmf.send(:taken_modifiers).compact
      epmf.instance_variable_set(:@taken_modifiers, taken.push(ep2e.modifier))
      ep2e.modifier = epmf.find
      epe.instance_variable_set(:@end_product_to_establish, ep2e)
    end

    output_line = "| #{v.participant_id} | #{r.class.name} | #{r.id}"

    begin
      DecisionReviewProcessJob.new.perform(r)
    rescue Caseflow::Error::DuplicateEp => error
      output_line = "| DuplicateEp error #{output_line}"
    else
      output_line = "| #{verb} #{output_line}"
    ensure
      output = "#{output_line}\n#{output}"
    end
  end

  puts output
end
pkarman commented 5 years ago

thread in https://dsva.slack.com/archives/CK466V65V/p1559858057012300

leikkisa commented 5 years ago

I asked Dwight about submitting ESCP tickets for these, since the guidance to use YourIT was misguided (BGS is not in YourIT). I am waiting to hear back, but that's the next course of action.

jcq commented 4 years ago

Code for handling a single stuck EP:

  review=epe.source
  veteran = epe.veteran
  ep2e = epe.send(:end_product_to_establish)
  epmf = EndProductModifierFinder.new(epe, veteran)
  taken = epmf.send(:taken_modifiers)

  # Mark place to start retrying
  epmf.instance_variable_set(:@taken_modifiers, taken.push(ep2e.modifier))
  ep2e.modifier = epmf.find

  epe.instance_variable_set(:@end_product_to_establish, ep2e)
  epe.establish!
  review.end_product_establishments.each{|epe| epe.reload}
  DecisionReviewProcessJob.new.perform(review)