Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raymond/APPEALS-27362 #19334

Merged
merged 10 commits into from
Sep 27, 2023
111 changes: 111 additions & 0 deletions lib/helpers/pre_docket_ihp_tasks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# frozen_string_literal: true

# ************************
# Remediates IHP tasks that are generated prior to completion of Pre-Docket task
# If an InformalHearingPresentationTask is present prior to PreDocketTask being completed
# we create a new DistributionTask and set the InformalHearingPresentationTask as a child
# This will become a blocking task and allow the PreDocketTask to be completed prior to
# the InformalHearingPresentationTask being completed
# ************************
module WarRoom
class PreDocketIhpTasks
def run(appeal_uuid)
@appeal = Appeal.find_appeal_by_uuid_or_find_or_create_legacy_appeal_by_vacols_id(appeal_uuid)
if @appeal.appeal_state&.appeal_docketed
puts("Appeal has been docketed. Aborting...")
fail Interrupt
end

predocket_task.update!(parent_id: ihp_task.id)

ihp_task.update!(parent_id: distribution_task.id)
ihp_task.on_hold!
rescue ActiveRecord::RecordNotFound => _error
puts("Appeal was not found. Aborting...")
raise Interrupt
rescue StandardError => error
puts("Something went wrong. Requires manual remediation. Error: #{error} Aborting...")
raise Interrupt
end

private

def root_task
if @appeal.root_task
@root_task = @appeal.root_task
else
puts("No RootTask found. Aborting...")
fail Interrupt
end
end

def distribution_task
@distribution_task ||=
if (distribution_tasks = @appeal.tasks.where(type: "DistributionTask").all).count > 1
puts("Duplicate DistributionTask found. Remove the erroneous task and retry. Aborting...")
fail Interrupt
elsif distribution_tasks.count == 1
distribution_tasks[0].on_hold!
distribution_tasks[0]
elsif distribution_tasks.empty?
dt = DistributionTask.create!(appeal: @appeal, parent: root_task)
dt.on_hold!
dt
else
puts("DistributionTask failed to inflate. Aborting...")
fail Interrupt
end
end

# we look for only 1 PredocketTask.
# * If multiples are found we bail.
# * If none are found we bail.
def predocket_task
return @predocket_task unless @predocket_task.nil?

predocket_tasks = @appeal.tasks.where(type: "PreDocketTask").all
if predocket_tasks.count > 1
puts("Multiple PredocketTask found. Remove the erroneous task and retry. Aborting...")
fail Interrupt
elsif predocket_tasks.count < 1
puts("No PredocketTask found. This may already be fixed. Aborting...")
fail Interrupt
else
@predocket_task = predocket_tasks[0]
end
end

# we look for only 1 InformalHearingPresentationTask.
# * If multiples are found we bail.
# * If none are found we bail.
# The status of the InformalHearingPresentationTask must be
# * assigned
# * on_hold
# If the status is anything else we bail.
def ihp_task
return @ihp_task unless @ihp_task.nil?

ihp_tasks = @appeal.tasks.where(type: "InformalHearingPresentationTask").all
if ihp_tasks.count > 1
puts("Duplicate InformalHearingPresentationTask found. Remove the erroneous task and retry. Aborting...")
fail Interrupt
elsif ihp_tasks.count <= 0
puts("No InformalHearingPresentationTask found. Aborting...")
fail Interrupt
end

# TODO: Need to determine the branch for cancelled status'
# If the status is cancelled does the InformalHearingPresentationTask reopen after docketing the appeal?
possible_ihp_task = ihp_tasks[0]
if possible_ihp_task.status.include?([Constants.TASK_STATUSES.assigned, Constants.TASK_STATUSES.on_hold])
@ihp_task = possible_ihp_task
elsif possible_ihp_task.status.include?([Constants.TASK_STATUSES.cancelled])
puts("InformalHearingPresentationTask has a status of cancelled. This is not supported for automated remediation yet. Aborting...")
fail Interrupt
else
puts("InformalHearingPresentationTask is not in the correct status for remediation. Aborting...")
fail Interrupt
end
end
end
end
6 changes: 6 additions & 0 deletions lib/helpers/scripts/predocket-ihp-task-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash
cd /opt/caseflow-certification/src; bin/rails c << DONETOKEN
x = WarRoom::PreDocketIhpTasks.new
x.run("$1")
DONETOKEN

Loading