Skip to content

Commit

Permalink
Feature/appeals 44915.prodtest 4.4.0 (#22594)
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 <>

* empty commit to force rerun of test

* empty commit to force rerun of test

---------

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 Aug 23, 2024
1 parent 1477a15 commit eddfe22
Show file tree
Hide file tree
Showing 29 changed files with 1,450 additions and 19 deletions.
43 changes: 43 additions & 0 deletions app/controllers/case_distribution_levers_tests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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 +73,15 @@ 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(params[:fail_job])
if params[:fail_job] && result.include?("Job failed with error")
return render json: { error: result }, status: :unprocessable_entity
end

head :ok
end

def appeals_distributed
# change this to the correct class
csv_data = AppealsDistributed.process
Expand All @@ -80,6 +96,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 +124,19 @@ 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

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
194 changes: 194 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,194 @@
# frozen_string_literal: true

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

queue_as :low_priority
application_attr :queue

def perform(fail_job = false)
begin
returned_appeal_job = create_returned_appeal_job
fail if fail_job

appeals, moved_appeals = eligible_and_moved_appeals

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

# Filter the appeals and send the filtered report
@filtered_appeals = filter_appeals(appeals, moved_appeals)
send_job_slack_report
rescue StandardError => error
message = "Job failed with error: #{error.message}"
errored_returned_appeal_job(returned_appeal_job, message)
start_time ||= Time.zone.now # temporary fix to get this job to succeed
duration = time_ago_in_words(start_time)
slack_msg = "<!here>\n [ERROR] after running for #{duration}: #{error.message}"
slack_service.send_notification(slack_msg, self.class.name)
log_error(error)
message
ensure
@start_time ||= Time.zone.now
metrics_service_report_runtime(metric_group_name: "return_legacy_appeals_to_board_job")
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),
moved_avljs: fetch_moved_avljs(moved_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)
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 tied_appeals_bfkeys.any?
if tied_appeals_bfkeys.count < 2
qualifying_appeals_bfkeys.push(tied_appeals_bfkeys)
else
qualifying_appeals_bfkeys.push(tied_appeals_bfkeys[0..1])
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)
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)
remaining_priority_appeals = (
all_appeals.select { |appeal| appeal["priority"] == 1 } -
moved_priority_appeals
)
remaining_non_priority_appeals = (
all_appeals.select { |appeal| appeal["priority"] == 0 } -
moved_non_priority_appeals
)
[remaining_priority_appeals, remaining_non_priority_appeals]
end

# Method to fetch non-SSC AVLJs that appeals were moved to location '63'
def fetch_moved_avljs(moved_appeals)
moved_appeals.map { |appeal| VACOLS::Staff.find_by(sattyid: appeal["vlj"]) }
.compact
.uniq
.map { |record| get_name_from_record(record) }
end

def get_name_from_record(record)
FullName.new(record["snamef"], nil, record["snamel"]).to_s
end

def create_returned_appeal_job
ReturnedAppealJob.create!(
started_at: Time.zone.now,
stats: { message: "Job started" }.to_json
)
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"] }
)
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_service.send_notification(slack_report.join("\n"), self.class.name)
end

def slack_report
report = []
report << "Job performed successfully"
report << "Priority Appeals Moved: #{@filtered_appeals[:priority_appeals_count]}"
report << "Non-Priority Appeals Moved: #{@filtered_appeals[:non_priority_appeals_count]}"
report << "Remaining Priority Appeals: #{@filtered_appeals[:remaining_priority_appeals_count]}"
report << "Remaining Non-Priority Appeals: #{@filtered_appeals[:remaining_non_priority_appeals_count]}"
report << "Moved AVLJs: #{@filtered_appeals[:moved_avljs].join(', ')}"
report << "Grouped by AVLJ: #{@filtered_appeals[:grouped_by_avlj].join(', ')}"
report
end
end
8 changes: 8 additions & 0 deletions app/models/dockets/legacy_docket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ def ready_to_distribute_appeals
LegacyAppeal.repository.ready_to_distribute_appeals
end

def appeals_tied_to_non_ssc_avljs
LegacyAppeal.repository.appeals_tied_to_non_ssc_avljs
end

def loc_63_appeals
LegacyAppeal.repository.loc_63_appeals
end

# rubocop:disable Metrics/CyclomaticComplexity
def count(priority: nil, ready: nil)
counts_by_priority_and_readiness.inject(0) do |sum, row|
Expand Down
4 changes: 4 additions & 0 deletions app/models/returned_appeal_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class ReturnedAppealJob < ApplicationRecord
end
Loading

0 comments on commit eddfe22

Please sign in to comment.