Skip to content

Commit

Permalink
Feature/appeals 44915.release/fy24 q4.5.0 (#22845)
Browse files Browse the repository at this point in the history
* Add in appeals_tied_to_non_ssc_avljs methods and SQL

* Update case_docket.rb

* Update case_docket.rb

* APPEALS-51263 added the lever to the seeds file (#22149)

* Amybids/appeals 51263 (#22169)

* APPEALS-51263 added the lever to the seeds file

* APPEALS-51263 test cleanup for case_docket, case_distribution_levers_controller_spec and case_distribution_test_data_spec.rb

* APPEALS-51262 (#22176)

* creates trait in factory for non_ssc_avlj user

* updates user in user factory with new traits in staff factory

* adds randomized judge method

* replaces user create with a vacols staff create and limits css_id to 12 using slogid, adds judge_role for active smemgrp

* updates naming

---------

Co-authored-by: Michael Beard <michael.beard@va.gov>

* APPEALS-45232. Added table in the DB and added requested columns (#22223)

* APPEALS-45232. Added table in the DB and added requested columns

* APPEALS-45232. Fix lint issues

* APPEALS-45232. Fixed the class name

* APPEALS-45232. Updated the column names from feedback

---------

Co-authored-by: SHarshain <spoosa@razortalent.com>

* Sharsha/appeals 45200 (#22233)

* APPEALS-45200. create Return Appeals tied to non-SSC AVLJs job

* APPEALS-45200. WIP

---------

Co-authored-by: SHarshain <spoosa@razortalent.com>

* Chrisbdetlef/appeals 45208 (#22305)

* Framework for seeds

* Add comments and fill in further methods

* Further shared dev work

* Update names

* Expanded possible functions

* More functions for shared work

* Combine everyones work into main branch

* Combined work - testing

* Combined work - testing complete

* rubocop fix

---------

Co-authored-by: Christopher Detlef <>

* APPEALS-45202.Added button to trigger the job and return the appeals (#22375)

Co-authored-by: SHarshain <spoosa@razortalent.com>

* Updates slack_service.rb to include local/demo console printout message (#22343)

* APPEALS-51487 Location 63 Query (#22398)

* APPEALS-51487 Location 63 Query

* fix naming and change query

* Working code

* Add 2 day limit to query

* Remove commented out code

* Fix lint issues

* Remove binding.pry

---------

Co-authored-by: Christopher Detlef <>

* APPEALS-45248 ACD Controls Test Page Alerts for Run Seed Fils and Case Movement Section Buttons (#22386)

* APPEALS-45248 Add success banner alerts to Run seed files and case movement section buttons

* APPEALS-45248 add fail job button and refactored code

* Ricky/APPEALS-45204 (#22373)

* Added button, and initial csv generation of appeals tied to non ssc avljs

* WIP. APPEALS-45204 tweaks to Push data into CSV

* APPEALS-45204. fix the method error

* APPEALS-45204. Lint fix

* Updated query to fetch hearing and grab non ssc avlj names properly

* Fixed outstanding issues and cleaned up seeds

* implements new hearing_judge, separates assigned_avlj and signing_avlj

* Fixed linting issues and other clean up

---------

Co-authored-by: SHarshain <133917878+SHarshain@users.noreply.github.com>
Co-authored-by: SHarshain <spoosa@razortalent.com>
Co-authored-by: Michael Beard <michael.beard@va.gov>

* Ricky/APPEALS-45204 (#22452)

* Added button, and initial csv generation of appeals tied to non ssc avljs

* WIP. APPEALS-45204 tweaks to Push data into CSV

* APPEALS-45204. fix the method error

* APPEALS-45204. Lint fix

* Updated query to fetch hearing and grab non ssc avlj names properly

* Fixed outstanding issues and cleaned up seeds

* implements new hearing_judge, separates assigned_avlj and signing_avlj

* Fixed linting issues and other clean up

* Updated name of CSV download button

---------

Co-authored-by: SHarshain <133917878+SHarshain@users.noreply.github.com>
Co-authored-by: SHarshain <spoosa@razortalent.com>
Co-authored-by: Michael Beard <michael.beard@va.gov>

* Chrisbdetlef/appeals 54138 (#22460)

* APPEALS-51487 Location 63 Query

* fix naming and change query

* Working code

* Add 2 day limit to query

* Remove commented out code

* Fix lint issues

* Remove binding.pry

* APPEALS-54138 Add button to seed non-SSC AVLJs

---------

Co-authored-by: Christopher Detlef <>

* Fix for routing table (#22466)

Co-authored-by: Christopher Detlef <>

* Chrisbdetlef/appeals 54138.1 (#22486)

* Fix for routing table

* Randomly select docket id number

---------

Co-authored-by: Christopher Detlef <>

* Updated query to correctly grab seed data (#22489)

Co-authored-by: Amy Detwiler <133032208+amybids@users.noreply.github.com>

* Ricky/APPEALS-51260 (#22497)

* Updated query to correctly grab seed data

* Replaced AOD and CAVC fields with Priority, fixed csv file name

---------

Co-authored-by: Amy Detwiler <133032208+amybids@users.noreply.github.com>

* APPEALS-54884. spec fix push priority appeals to judges job (#22505)

Co-authored-by: SHarshain <spoosa@razortalent.com>

* exchanges spaces for hyphens, updates method to filter by unique veteran file numbers (#22524)

* updates seed file names to match AC and adds hyphens instead of spaces (#22530)

* Chrisbdetlef/appeals 54152 (#22531)

* APPEALS-54152 Move Appeals to loc 63

* Fix minor issues with the query and data displayed in the CSV

* APPEALS-54152 Move qualifying appeals to Loc 63

---------

Co-authored-by: Christopher Detlef <>

* APPEALS-54152.1 Fix issues with the process of making and moving appeals tied to nonSSC AVLJs (#22541)

Co-authored-by: Christopher Detlef <>

* Chrisbdetlef/appeals 54152.1 (#22544)

* APPEALS-54152.1 Fix issues with the process of making and moving appeals tied to nonSSC AVLJs

* TEST ONLY DO NOT MERGE

---------

Co-authored-by: Christopher Detlef <>

* Chrisbdetlef/appeals 54152.2 (#22554)

* APPEALS-54152.2 Change movement to loc 63 to 2 per AVLJ

* Fix lint issues and errors

* Remove artifact code

* Fix errors

---------

Co-authored-by: Christopher Detlef <>

* Code changes to account for duplicates from base query (#22582)

* Code changes to account for duplicates from base query

* Add warning to join constant

* Fix issue with empty array

---------

Co-authored-by: Christopher Detlef <>
Co-authored-by: Amy Detwiler <133032208+amybids@users.noreply.github.com>

* mbeard/APPEALS-45203 (#22565)

* refactored to include new move_qualifying_appeals method

* updated filtered methods and eligible appeals, moved appeals variables

* moves logic for eligible and moved appeals into new method

* cleaned up filter_method, simplified other methods

* updates to failing test

* ensures appeals isn't nil when job is complete

* Fix the last name issue on loc 63 CSV (#22591)

Co-authored-by: Christopher Detlef <>

* APPEALS-45248 v2 ACD Controls Test Page Alerts for Run Seed Fils and Case Movement Section Buttons (#22449)

* APPEALS-45248 Add success banner alerts to Run seed files and case movement section buttons

* APPEALS-45248 add fail job button and refactored code

* APPEALS-45248 address ac2 of the story and set timer for banner alerts

* APPEALS-45248-v2 update button verbiage

* APPEALS-54061 added collapsible table to see the 15 latest ReturnLegacyAppealsToBoard log on test page

* APPEALS-54061 refactor code to address modified AC in the story

* fixed linting issues

* some lint fixes

---------

Co-authored-by: 631966 <amy.detwiler@va.gov>
Co-authored-by: Amy Detwiler <133032208+amybids@users.noreply.github.com>

* APPEALS-APPEALS-55680 added nil checking to the return legacy to appe… (#22607)

* APPEALS-APPEALS-55680 added nil checking to the return legacy to appeals to board job

* APPEALS-55680 finish job if no moved appeals

* APPEALS-55680 made the no record slack message into an array

* APPEALS-55680 fixed rubocop issues

* mbeard/APPEALS-55179 (#22615)

* adds constants and updates method to use constant

* changes lever_group

* APPEALS-55179. Fix the query and update the Constant value

* updates method and puts constants to lowercase

* adds nonsscavlj_number_of_appeals_to_move to failing spec array

---------

Co-authored-by: SHarshain <spoosa@razortalent.com>

* mbeard/APPEALS-45203 (#22626)

* removes avljs from the slack message

* updates to slack messages

* APPEALS-54290 CSV for all tied VLJ cases (#22624)

Co-authored-by: Christopher Detlef <>

* APPEALS-56033 fixed duplicate, nil, and error handling

* APPEALS-56033 fixed duplicate, nil, and error handling (#22630)

* APPEALS-56033 fix job running on frontend

* APPEALS-56033 fixed linting error

* Amybids/appeals 56033 (#22635)

* APPEALS-56033 fixed duplicate, nil, and error handling

* APPEALS-56033 fix job running on frontend

* APPEALS-56033 fixed linting error

* Fix off by 1 error for returntoboard job (#22648)

* Fix off by 1 error for returntoboard job

* removed the extraneous space

* refactored the variables

* refactored variable names to fix rubocop issues

---------

Co-authored-by: Christopher Detlef <>
Co-authored-by: 631966 <amy.detwiler@va.gov>

* mbeard/APPEALS-55660 (#22653)

* Updates test coverage for full perform method

* fixed linting issues

* updates to receive and return a number of appeals moved

* updates value from 10 to 2 moved appeals

* adds trait to factory and lever to push priority spec

* APPEALS-56980 Fix for .perform_later functionality in higher environm… (#22671)

* APPEALS-56980 Fix for .perform_later functionality in higher environments

* Remove lines of code that aren't needed and add built in checker

* Fix 1 of 2 errors

* Move local variables out of intialize or callback methods

---------

Co-authored-by: Christopher Detlef <>

* APPEALS-55158 removed the skipped specs to make the test suite pass (#22651)

* Chrisbdetlef/appeals 54290 (#22647)

* APPEALS-54290 CSV for all tied VLJ cases

* Added support for AMA appeals

* Fix linting issues

---------

Co-authored-by: Christopher Detlef <>

* ricky/APPEALS-55123 (#22617)

* Added VLJ and Inactive Non-SSC AVLJ seeds

* Updated seeds to include signed and unsigned AMA appeals

* Fixed AMA hearing to not error on creation

---------

Co-authored-by: Amy Detwiler <133032208+amybids@users.noreply.github.com>

* Added docket back because sym doesn't provide the same information

* APPEALS-57322 Add logging for Not Ready to Distribute appeals (#22722)

* APPEALS-57322 Add logging for Not Ready to Distribute appeals

* Remove binding pry

---------

Co-authored-by: Christopher Detlef <>

* Change the button label (#22723)

* Change the button label

* Remove binding pry

---------

Co-authored-by: Christopher Detlef <>

* fix appeals ready to distribute

* Change the name of the SSC AVLJ (#22728)

* Change the name of the SSC AVLJ

* Remove binding pry

---------

Co-authored-by: Christopher Detlef <>

* APPEALS-57428. Update job log when job completes with no records (#22736)

* APPEALS-57428. Update job log when job completes with no records

* APPEALS-57428. Job stops if the returned appeals is nil

---------

Co-authored-by: SHarshain <spoosa@razortalent.com>

* reverted work so that the legacy rows show up as NA (#22744)

* Sharsha/tes branch master (#22772)

* APPEALS-57428.Update job log when job completes with no records

* Upmerge master

* spec fix

* fixed some bug errors

* fixed linting issue

---------

Co-authored-by: SHarshain <spoosa@razortalent.com>
Co-authored-by: 631966 <amy.detwiler@va.gov>

* APPEALS-57711. fix the ama_rows logc (#22775)

Co-authored-by: SHarshain <spoosa@razortalent.com>

* APPEALS-57801 Fix merging error (#22781)

* APPEALS-57801 Fix merging error

* rubocop fix

---------

Co-authored-by: Christopher Detlef <>

* APPEALS-57058. Automated Tests for the Queries (#22791)

* APPEALS-57058. WIP - check loc_63_appeals

* APPEALS-57058. more test coverage

---------

Co-authored-by: SHarshain <spoosa@razortalent.com>

* Ricky/APPEALS-57057 (#22801)

* Created outline for CSV test for appeals tied to non ssc avljs

* Updated rspec for appeals tied to non ssc avlj to have full coverage

* Created initial spec file for appeeals tied to avljs and vljs query

* Added testing support appeals_tied_to_avljs_and_vljs_query

* Updated testing on appeals_tied_to_avlj_and_vljs

* Updated framework on location 63 appeals CSV rspec testing

* Fixed base test for appeals in location 63 CSV

* Updated data structure to properly check test

* Updated location 63 CSV to have full coverage

* Fixed linting

* Chrisbdetlef/appeals 55660 (#22798)

* Psuedo code for specs

* Framework for tests

* Split work

* APPEALS-55660. Test expansion (#22714)

Co-authored-by: SHarshain <spoosa@razortalent.com>

* APPEALS-55660 Expanded test coverage for ReturnToBaordJob

* Combine work

* Fix linting and add some error handling

---------

Co-authored-by: Christopher Detlef <>
Co-authored-by: SHarshain <133917878+SHarshain@users.noreply.github.com>
Co-authored-by: SHarshain <spoosa@razortalent.com>

* Chrisbdetlef/appeals 58192 (#22832)

* APPEALS-58192 Fix location 63 query test

* Fix rubocop issues

---------

Co-authored-by: Christopher Detlef <>

* updated migration for rails 6

---------

Co-authored-by: Matthew Roth <roth_matthew@bah.com>
Co-authored-by: Blake Manus <33578594+Blake-Manus@users.noreply.github.com>
Co-authored-by: Michael Beard <michael.beard@va.gov>
Co-authored-by: SHarshain <133917878+SHarshain@users.noreply.github.com>
Co-authored-by: SHarshain <spoosa@razortalent.com>
Co-authored-by: cdetlefva <133903625+cdetlefva@users.noreply.github.com>
Co-authored-by: Michael Beard <131783726+mbeardy@users.noreply.github.com>
Co-authored-by: kristeja <112115264+kristeja@users.noreply.github.com>
  • Loading branch information
9 people authored and AdamShawBAH committed Sep 20, 2024
1 parent 3273a48 commit 215535f
Show file tree
Hide file tree
Showing 41 changed files with 3,126 additions and 124 deletions.
59 changes: 59 additions & 0 deletions app/controllers/case_distribution_levers_tests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class CaseDistributionLeversTestsController < ApplicationController
def acd_lever_index_test
@acd_levers = CaseDistributionLever.all
@acd_history = CaseDistributionAuditLeverEntry.lever_history
@returned_appeal_jobs = ReturnedAppealJob.all.order(created_at: :desc).limit(15)

render "case_distribution_levers/test"
end
Expand Down Expand Up @@ -40,6 +41,13 @@ def run_demo_docket_priority
head :ok
end

def run_demo_non_avlj_appeals
Rake::Task["db:seed:non_ssc_avlj_legacy_appeals"].reenable
Rake::Task["db:seed:non_ssc_avlj_legacy_appeals"].invoke

head :ok
end

def appeals_ready_to_distribute
csv_data = AppealsReadyForDistribution.process

Expand All @@ -66,6 +74,17 @@ def appeals_non_priority_ready_to_distribute
send_data csv_data, filename: filename
end

def run_return_legacy_appeals_to_board
result = ReturnLegacyAppealsToBoardJob.perform_now

unless result
render json: { error: "Job failed" }, status: :unprocessable_entity
return
end

head :ok
end

def appeals_distributed
# change this to the correct class
csv_data = AppealsDistributed.process
Expand All @@ -80,6 +99,20 @@ def appeals_distributed
send_data csv_data, filename: filename
end

def appeals_in_location_63_in_past_2_days
# change this to the correct class
csv_data = AppealsInLocation63InPast2Days.process

# Get the current date and time for dynamic filename
current_datetime = Time.zone.now.strftime("%Y%m%d-%H%M")

# Set dynamic filename with current date and time
filename = "appeals_in_location_63_past_2_days_#{current_datetime}.csv"

# Send CSV as a response with dynamic filename
send_data csv_data, filename: filename
end

def ineligible_judge_list
# change this to the correct class
csv_data = IneligibleJudgeList.process
Expand All @@ -94,6 +127,32 @@ def ineligible_judge_list
send_data csv_data, filename: filename
end

def appeals_tied_to_non_ssc_avlj
csv_data = AppealsTiedToNonSscAvljQuery.process

# Get the current date and time for dynamic filename
current_datetime = Time.zone.now.strftime("%Y%m%d-%H%M")

# Set dynamic filename with current date and time
filename = "appeals_tied_to_non_ssc_avljs_#{current_datetime}.csv"

# Send CSV as a response with dynamic filename
send_data csv_data, filename: filename
end

def appeals_tied_to_avljs_and_vljs
csv_data = AppealsTiedToAvljsAndVljsQuery.process

# Get the current date and time for dynamic filename
current_datetime = Time.zone.now.strftime("%Y%m%d-%H%M")

# Set dynamic filename with current date and time
filename = "appeals_tied_to_avljs_and_vljs#{current_datetime}.csv"

# Send CSV as a response with dynamic filename
send_data csv_data, filename: filename
end

private

def check_environment
Expand Down
1 change: 1 addition & 0 deletions app/jobs/push_priority_appeals_to_judges_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def perform
@genpop_distributions = distribute_genpop_priority_appeals

perform_later_or_now(UpdateAppealAffinityDatesJob)
perform_later_or_now(ReturnLegacyAppealsToBoardJob)

slack_service.send_notification(generate_report.join("\n"), self.class.name)
rescue StandardError => error
Expand Down
252 changes: 252 additions & 0 deletions app/jobs/return_legacy_appeals_to_board_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
# frozen_string_literal: true

class ReturnLegacyAppealsToBoardJob < CaseflowJob
# For time_ago_in_words()
include ActionView::Helpers::DateHelper

queue_with_priority :low_priority
application_attr :queue

NO_RECORDS_FOUND_MESSAGE = [Constants.DISTRIBUTION.no_records_moved_message].freeze

def perform
catch(:abort) do
begin
returned_appeal_job = create_returned_appeal_job

appeals, moved_appeals = eligible_and_moved_appeals

check_appeals_available(moved_appeals, returned_appeal_job)

complete_returned_appeal_job(returned_appeal_job, "Job completed successfully", moved_appeals)

# The rest of your code continues here
# Filter the appeals and send the filtered report
@filtered_appeals = filter_appeals(appeals, moved_appeals)
send_job_slack_report(slack_report)
rescue StandardError => error
handle_error(error, returned_appeal_job)
ensure
metrics_service_report_runtime(metric_group_name: "return_legacy_appeals_to_board_job")
end
end
end

def filter_appeals(appeals, moved_appeals)
priority_appeals_moved, non_priority_appeals_moved = separate_by_priority(moved_appeals)

remaining_priority_appeals,
remaining_non_priority_appeals = calculate_remaining_appeals(
appeals,
priority_appeals_moved,
non_priority_appeals_moved
)

{
priority_appeals_count: count_unique_bfkeys(priority_appeals_moved),
non_priority_appeals_count: count_unique_bfkeys(non_priority_appeals_moved),
remaining_priority_appeals_count: count_unique_bfkeys(remaining_priority_appeals),
remaining_non_priority_appeals_count: count_unique_bfkeys(remaining_non_priority_appeals),
grouped_by_avlj: grouped_by_avlj(moved_appeals)
}
end

def eligible_and_moved_appeals
appeals = LegacyDocket.new.appeals_tied_to_non_ssc_avljs
moved_appeals = move_qualifying_appeals(appeals)
[appeals, moved_appeals]
end

def grouped_by_avlj(moved_appeals)
return [] if moved_appeals.nil?

moved_appeals.group_by { |appeal| VACOLS::Staff.find_by(sattyid: appeal["vlj"])&.sattyid }.keys.compact
end

def count_unique_bfkeys(appeals)
appeals.map { |appeal| appeal["bfkey"] }.uniq.size
end

private

def move_qualifying_appeals(appeals)
qualifying_appeals_bfkeys = []

non_ssc_avljs.each do |non_ssc_avlj|
tied_appeals = appeals.select { |appeal| appeal["vlj"] == non_ssc_avlj.sattyid }
tied_appeals_bfkeys = get_tied_appeal_bfkeys(tied_appeals)
qualifying_appeals_bfkeys = update_qualifying_appeals_bfkeys(tied_appeals_bfkeys, qualifying_appeals_bfkeys)
end

unless qualifying_appeals_bfkeys.empty?
qualifying_appeals = appeals
.select { |q_appeal| qualifying_appeals_bfkeys.include? q_appeal["bfkey"] }
.flatten
.sort_by { |appeal| [-appeal["priority"], appeal["bfd19"]] }
VACOLS::Case.batch_update_vacols_location("63", qualifying_appeals.map { |q_appeal| q_appeal["bfkey"] })
end

qualifying_appeals || []
end

def get_tied_appeal_bfkeys(tied_appeals)
tied_appeals_bfkeys = []

unless tied_appeals.empty?
tied_appeals_bfkeys = tied_appeals
.sort_by { |t_appeal| [-t_appeal["priority"], t_appeal["bfd19"]] }
.map { |t_appeal| t_appeal["bfkey"] }
.uniq
.flatten
end

tied_appeals_bfkeys
end

def update_qualifying_appeals_bfkeys(tied_appeals_bfkeys, qualifying_appeals_bfkeys)
if nonsscavlj_number_of_appeals_limit < 0
fail StandardError, "CaseDistributionLever.nonsscavlj_number_of_appeals_to_move set below 0"
elsif nonsscavlj_number_of_appeals_limit == 0
return qualifying_appeals_bfkeys
end

if tied_appeals_bfkeys.any?
if tied_appeals_bfkeys.count < nonsscavlj_number_of_appeals_limit
qualifying_appeals_bfkeys.push(tied_appeals_bfkeys)
else
qualifying_appeals_bfkeys.push(tied_appeals_bfkeys[0..nonsscavlj_number_of_appeals_to_move_index])
end
end

qualifying_appeals_bfkeys.flatten
end

def non_ssc_avljs
VACOLS::Staff.where("sactive = 'A' AND svlj = 'A' AND sattyid <> smemgrp")
end

# Method to separate appeals by priority
def separate_by_priority(appeals)
return [] if appeals.nil?

priority_appeals = appeals.select { |appeal| appeal["priority"] == 1 } || []
non_priority_appeals = appeals.select { |appeal| appeal["priority"] == 0 } || []

[priority_appeals, non_priority_appeals]
end

# Method to calculate remaining eligible appeals
def calculate_remaining_appeals(all_appeals, moved_priority_appeals, moved_non_priority_appeals)
return [] if all_appeals.nil?

remaining_priority_appeals = calculate_remaining_priority_appeals(all_appeals, moved_priority_appeals)
remaining_non_priority_appeals = calculate_remaining_non_priority_appeals(all_appeals, moved_non_priority_appeals)

[remaining_priority_appeals, remaining_non_priority_appeals]
end

def calculate_remaining_priority_appeals(all_appeals, moved_priority_appeals)
starting_priority_appeals = all_appeals.select { |appeal| appeal["priority"] == 1 }

if (moved_priority_appeals - starting_priority_appeals).empty?
remaining_priority_appeals = (starting_priority_appeals - moved_priority_appeals) || []
else
fail StandardError, "An invalid priority appeal was detected in the list of moved appeals: "\
"#{moved_priority_appeals - starting_priority_appeals}"
end

remaining_priority_appeals
end

def calculate_remaining_non_priority_appeals(all_appeals, moved_non_priority_appeals)
starting_non_priority_appeals = all_appeals.select { |appeal| appeal["priority"] == 0 }

if (moved_non_priority_appeals - starting_non_priority_appeals).empty?
remaining_non_priority_appeals = (starting_non_priority_appeals - moved_non_priority_appeals) || []
else
fail StandardError, "An invalid non-priority appeal was detected in the list of moved appeals: "\
"#{moved_non_priority_appeals - starting_non_priority_appeals}"
end

remaining_non_priority_appeals
end

# Method to fetch non-SSC AVLJs SATTYIDS that appeals were moved to location '63'
def fetch_moved_sattyids(moved_appeals)
return [] if moved_appeals.nil?

moved_appeals.map { |appeal| VACOLS::Staff.find_by(sattyid: appeal["vlj"]) }
.compact
.uniq
.map(&:sattyid) || []
end

def nonsscavlj_number_of_appeals_limit
@nonsscavlj_number_of_appeals_limit ||= CaseDistributionLever.nonsscavlj_number_of_appeals_to_move || 0
end

def nonsscavlj_number_of_appeals_to_move_index
@nonsscavlj_number_of_appeals_to_move_index ||= nonsscavlj_number_of_appeals_limit - 1
end

def create_returned_appeal_job
ReturnedAppealJob.create!(
started_at: Time.zone.now,
stats: { message: "Job started" }.to_json
)
end

def check_appeals_available(moved_appeals, returned_appeal_job)
if moved_appeals.nil?
complete_returned_appeal_job(returned_appeal_job, Constants.DISTRIBUTION.no_records_moved_message, [])
send_job_slack_report(NO_RECORDS_FOUND_MESSAGE)
throw(:abort)
end
end

def handle_error(error, returned_appeal_job)
@start_time ||= Time.zone.now
message = "Job failed with error: #{error.message}"
errored_returned_appeal_job(returned_appeal_job, message)
duration = time_ago_in_words(@start_time)
slack_service.send_notification("<!here>\n [ERROR] after running for #{duration}: #{error.message}",
self.class.name)
log_error(error)
message
end

def complete_returned_appeal_job(returned_appeal_job, message, appeals)
appeals ||= []
returned_appeal_job.update!(
completed_at: Time.zone.now,
stats: { message: message }.to_json,
returned_appeals: appeals.map { |appeal| appeal["bfkey"] }.uniq
)
end

def errored_returned_appeal_job(returned_appeal_job, message)
returned_appeal_job.update!(
errored_at: Time.zone.now,
stats: { message: message }.to_json
)
end

def send_job_slack_report(slack_message)
if slack_message.blank?
fail StandardError, "Slack message cannot be empty or nil"
end

slack_service.send_notification(slack_message.join("\n"), self.class.name)
end

def slack_report
report = []
report << "Job performed successfully"
report << "Total Priority Appeals Moved: #{@filtered_appeals[:priority_appeals_count]}"
report << "Total Non-Priority Appeals Moved: #{@filtered_appeals[:non_priority_appeals_count]}"
report << "Total Remaining Priority Appeals: #{@filtered_appeals[:remaining_priority_appeals_count]}"
report << "Total Remaining Non-Priority Appeals: #{@filtered_appeals[:remaining_non_priority_appeals_count]}"
report << "SATTYIDs of Non-SSC AVLJs Moved: #{@filtered_appeals[:grouped_by_avlj].join(', ')}"
report
end
end
1 change: 1 addition & 0 deletions app/models/case_distribution_lever.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CaseDistributionLever < ApplicationRecord
#{Constants.DISTRIBUTION.ama_hearing_docket_time_goals}
#{Constants.DISTRIBUTION.ama_hearing_start_distribution_prior_to_goals}
#{Constants.DISTRIBUTION.ama_evidence_submission_start_distribution_prior_to_goals}
#{Constants.DISTRIBUTION.nonsscavlj_number_of_appeals_to_move}
).freeze

FLOAT_LEVERS = %W(
Expand Down
5 changes: 5 additions & 0 deletions app/models/concerns/distribution_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ def case_affinity_days_lever_value_is_selected?(lever_value)
true
end

def tied_to_judges(judge_ids)
with_appeal_affinities
.where(hearings: { judge_id: judge_ids })
end

def exclude_affinity_and_ineligible_judge_ids
judge_ids = JudgeTeam.judges_with_exclude_appeals_from_affinity

Expand Down
6 changes: 6 additions & 0 deletions app/models/docket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ def ready_priority_appeal_ids
appeals(priority: true, ready: true).pluck(:uuid)
end

def tied_to_vljs(judge_ids)
docket_appeals.ready_for_distribution
.most_recent_hearings
.tied_to_judges(judge_ids)
end

# rubocop:disable Metrics/MethodLength, Lint/UnusedMethodArgument, Metrics/PerceivedComplexity
# :reek:FeatureEnvy
def distribute_appeals(distribution, priority: false, genpop: nil, limit: 1, style: "push")
Expand Down
Loading

0 comments on commit 215535f

Please sign in to comment.