From 07f77f4d29a6dbfbe9968ed14413f2ab97d84d6d Mon Sep 17 00:00:00 2001 From: samasudhirreddy <108430298+samasudhirreddy@users.noreply.github.com> Date: Thu, 14 Nov 2024 11:25:19 -0600 Subject: [PATCH 1/8] Update 'by docket date distribution' to distribute non-genpop priority appeals from each docket when the passed limit is nil --- .../concerns/by_docket_date_distribution.rb | 15 +++++++++-- .../by_docket_date_distribution_spec.rb | 25 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/by_docket_date_distribution.rb b/app/models/concerns/by_docket_date_distribution.rb index 3f89ef4b903..22b62fb70b1 100644 --- a/app/models/concerns/by_docket_date_distribution.rb +++ b/app/models/concerns/by_docket_date_distribution.rb @@ -17,8 +17,19 @@ def priority_push_distribution(limit) @push_priority_target = limit @rem = 0 @appeals = [] - # Distribute number of cases, regardless of docket type, oldest first. - distribute_priority_appeals_from_all_dockets_by_age_to_limit(limit, style: "push") + + if limit.nil? + # Distribute priority appeals that are tied to judges (not genpop) with no limit. + args = { priority: true, genpop: "not_genpop", style: "push", limit: limit } + dockets.each_key do |docket| + collect_appeals do + dockets[docket].distribute_appeals(self, args) + end + end + else + # Distribute number of cases, regardless of docket type, oldest first. + distribute_priority_appeals_from_all_dockets_by_age_to_limit(limit, style: "push") + end @appeals end diff --git a/spec/models/concerns/by_docket_date_distribution_spec.rb b/spec/models/concerns/by_docket_date_distribution_spec.rb index 5f0246dc385..bc2b0c6f21a 100644 --- a/spec/models/concerns/by_docket_date_distribution_spec.rb +++ b/spec/models/concerns/by_docket_date_distribution_spec.rb @@ -94,6 +94,31 @@ def add_dates_to_date_array(num) # priority_push_distribution is private so .send is used to directly call it @new_acd.send :priority_push_distribution, 12 end + + it "calls distribute_appeals method for all the dockets and returns the array of objects received from each method" do + # distribute all priority appeals from all dockets + expect_any_instance_of(LegacyDocket).to receive(:distribute_appeals) + .with(@new_acd, priority: true, style: "push", limit: nil, genpop: 'not_genpop') + .and_return(add_object_to_return_array(priority_count_hash[:legacy])) + + expect_any_instance_of(DirectReviewDocket).to receive(:distribute_appeals) + .with(@new_acd, priority: true, style: "push", limit: nil, genpop: 'not_genpop') + .and_return(add_object_to_return_array(priority_count_hash[:direct_review])) + + expect_any_instance_of(EvidenceSubmissionDocket).to receive(:distribute_appeals) + .with(@new_acd, priority: true, style: "push", limit: nil, genpop: 'not_genpop') + .and_return(add_object_to_return_array(priority_count_hash[:evidence_submission])) + + expect_any_instance_of(HearingRequestDocket).to receive(:distribute_appeals) + .with(@new_acd, priority: true, style: "push", limit: nil, genpop: 'not_genpop') + .and_return(add_object_to_return_array(priority_count_hash[:hearing])) + + expect_any_instance_of(AojLegacyDocket).to receive(:distribute_appeals) + .with(@new_acd, priority: true, style: "push", limit: nil, genpop: 'not_genpop') + .and_return(add_object_to_return_array(3)) + + @new_acd.send :priority_push_distribution, nil + end end let(:nonpriority_count_hash) { { legacy: 3, direct_review: 3, evidence_submission: 3, hearing: 3 } } From 51ac28f79e3c1668991a42377c8234bfc5feb612 Mon Sep 17 00:00:00 2001 From: samasudhirreddy <108430298+samasudhirreddy@users.noreply.github.com> Date: Thu, 14 Nov 2024 11:55:32 -0600 Subject: [PATCH 2/8] Fixed lint issue --- .../concerns/by_docket_date_distribution_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/models/concerns/by_docket_date_distribution_spec.rb b/spec/models/concerns/by_docket_date_distribution_spec.rb index bc2b0c6f21a..789db08aab0 100644 --- a/spec/models/concerns/by_docket_date_distribution_spec.rb +++ b/spec/models/concerns/by_docket_date_distribution_spec.rb @@ -95,26 +95,26 @@ def add_dates_to_date_array(num) @new_acd.send :priority_push_distribution, 12 end - it "calls distribute_appeals method for all the dockets and returns the array of objects received from each method" do + it "calls distribute_appeals for all the dockets and returns the array of objects received from each method" do # distribute all priority appeals from all dockets expect_any_instance_of(LegacyDocket).to receive(:distribute_appeals) - .with(@new_acd, priority: true, style: "push", limit: nil, genpop: 'not_genpop') + .with(@new_acd, priority: true, style: "push", limit: nil, genpop: "not_genpop") .and_return(add_object_to_return_array(priority_count_hash[:legacy])) expect_any_instance_of(DirectReviewDocket).to receive(:distribute_appeals) - .with(@new_acd, priority: true, style: "push", limit: nil, genpop: 'not_genpop') + .with(@new_acd, priority: true, style: "push", limit: nil, genpop: "not_genpop") .and_return(add_object_to_return_array(priority_count_hash[:direct_review])) expect_any_instance_of(EvidenceSubmissionDocket).to receive(:distribute_appeals) - .with(@new_acd, priority: true, style: "push", limit: nil, genpop: 'not_genpop') + .with(@new_acd, priority: true, style: "push", limit: nil, genpop: "not_genpop") .and_return(add_object_to_return_array(priority_count_hash[:evidence_submission])) expect_any_instance_of(HearingRequestDocket).to receive(:distribute_appeals) - .with(@new_acd, priority: true, style: "push", limit: nil, genpop: 'not_genpop') + .with(@new_acd, priority: true, style: "push", limit: nil, genpop: "not_genpop") .and_return(add_object_to_return_array(priority_count_hash[:hearing])) expect_any_instance_of(AojLegacyDocket).to receive(:distribute_appeals) - .with(@new_acd, priority: true, style: "push", limit: nil, genpop: 'not_genpop') + .with(@new_acd, priority: true, style: "push", limit: nil, genpop: "not_genpop") .and_return(add_object_to_return_array(3)) @new_acd.send :priority_push_distribution, nil From 7181ae7646a34a6605300087accf7aaeec9fb15c Mon Sep 17 00:00:00 2001 From: Craig Reese <109101548+craigrva@users.noreply.github.com> Date: Fri, 15 Nov 2024 07:15:43 -0600 Subject: [PATCH 3/8] fix bug on legacy dockets for levers infinite with no prev deciding judge --- app/models/vacols/case_docket.rb | 4 +++- spec/models/vacols/aoj_case_docket_spec.rb | 11 +++++++++++ spec/models/vacols/case_docket_spec.rb | 11 +++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 5698aaf5ded..0d1f80d5f91 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -925,7 +925,9 @@ def self.common_affinity_filter_logic( genpop == "not_genpop" || reject_due_to_affinity?(appeal_affinities[appeal["bfkey"]], lever_value) elsif lever_value == Constants.ACD_LEVERS.infinite - return if deciding_judge_ineligible_with_no_hearings_after_decision(appeal) || appeal["prev_deciding_judge"].nil? + return if + (deciding_judge_ineligible_with_no_hearings_after_decision(appeal) || appeal["prev_deciding_judge"].nil?) && + genpop != "not_genpop" appeal["prev_deciding_judge"] != judge_sattyid elsif lever_value == Constants.ACD_LEVERS.omit diff --git a/spec/models/vacols/aoj_case_docket_spec.rb b/spec/models/vacols/aoj_case_docket_spec.rb index 483cdb3095c..f7c2cd9fdc9 100644 --- a/spec/models/vacols/aoj_case_docket_spec.rb +++ b/spec/models/vacols/aoj_case_docket_spec.rb @@ -1532,6 +1532,17 @@ def create_case_hearing(appeal, hearing_judge) # appeals where prev deciding judge ineligible and hearing before decision (genpop) let!(:aoj_aod_inel_5) { create(:legacy_aoj_appeal, :aod, judge: inel_judge, attorney: attorney) } let!(:aoj_cavc_inel_5) { create(:legacy_aoj_appeal, judge: inel_judge, attorney: attorney, cavc: true) } + # appeals where the hearing and deciding judge are different, and the deciding judge is ineligible + let!(:aoj_aod_inel_10) do + c = create(:legacy_aoj_appeal, :aod, judge: inel_judge, attorney: attorney) + VACOLS::CaseHearing.find_by(folder_nr: c.bfkey.to_i + 1).update!(board_member: other_judge.sattyid) + c + end + let!(:aoj_cavc_inel_10) do + c = create(:legacy_aoj_appeal, judge: inel_judge, attorney: attorney, cavc: true) + VACOLS::CaseHearing.find_by(folder_nr: c.bfkey.to_i + 1).update!(board_member: other_judge.sattyid) + c + end # appeals where prev deciding judge excluded and is not the hearing vlj and hearing before decision (genpop) let!(:aoj_aod_excl_6) do c = create(:legacy_aoj_appeal, :aod, judge: other_judge, attorney: attorney) diff --git a/spec/models/vacols/case_docket_spec.rb b/spec/models/vacols/case_docket_spec.rb index ab7dc018a32..ec321e6bece 100644 --- a/spec/models/vacols/case_docket_spec.rb +++ b/spec/models/vacols/case_docket_spec.rb @@ -1374,6 +1374,17 @@ # appeals where prev deciding judge ineligible and hearing before decision (genpop) let!(:cavc_inel_5) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney) } let!(:aod_cavc_inel_5) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true) } + # appeals where the hearing and deciding judge are different, and the deciding judge is ineligible + let!(:cavc_inel_10) do + c = create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney) + c.case_hearings.first.update!(board_member: other_judge.sattyid) + c + end + let!(:aod_cavc_inel_10) do + c = create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true) + c.case_hearings.first.update!(board_member: other_judge.sattyid) + c + end # appeals where prev deciding judge excluded and is not the hearing vlj and hearing before decision (genpop) let!(:cavc_excl_6) do c = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney) From 981e5da89fef5c930456659314b951e81e72e126 Mon Sep 17 00:00:00 2001 From: Craig Reese <109101548+craigrva@users.noreply.github.com> Date: Fri, 15 Nov 2024 08:48:09 -0600 Subject: [PATCH 4/8] update job to distribute not genpop if feature toggle enabled, update tests --- .../push_priority_appeals_to_judges_job.rb | 2 +- ...ush_priority_appeals_to_judges_job_spec.rb | 114 +++++++----------- 2 files changed, 44 insertions(+), 72 deletions(-) diff --git a/app/jobs/push_priority_appeals_to_judges_job.rb b/app/jobs/push_priority_appeals_to_judges_job.rb index 8a1e8cfff68..9e2e9254df6 100644 --- a/app/jobs/push_priority_appeals_to_judges_job.rb +++ b/app/jobs/push_priority_appeals_to_judges_job.rb @@ -13,7 +13,7 @@ class PushPriorityAppealsToJudgesJob < CaseflowJob application_attr :queue def perform - unless use_by_docket_date? + if FeatureToggle.enabled?(:acd_ppj_distribute_not_genpop) @tied_distributions = distribute_non_genpop_priority_appeals end diff --git a/spec/jobs/push_priority_appeals_to_judges_job_spec.rb b/spec/jobs/push_priority_appeals_to_judges_job_spec.rb index 94d2a50364c..1c376a889a6 100644 --- a/spec/jobs/push_priority_appeals_to_judges_job_spec.rb +++ b/spec/jobs/push_priority_appeals_to_judges_job_spec.rb @@ -33,22 +33,32 @@ def to_judge_hash(arr) subject { described_class.perform_now } - it "using Automatic Case Distribution module", skip: "Automatic Case Distribution is deprecated" do - expect_any_instance_of(PushPriorityAppealsToJudgesJob) - .to receive(:distribute_non_genpop_priority_appeals).and_return([]) + context "acd_ppj_distribute_not_genpop feature toggle" do + context "with feature toggle disabled" do + it "does not distribute not_genpop appeals" do + expect_any_instance_of(PushPriorityAppealsToJudgesJob) + .to_not receive(:distribute_non_genpop_priority_appeals).and_return([]) - subject - end + subject + end + end - it "using By Docket Date Distribution module" do - expect_any_instance_of(PushPriorityAppealsToJudgesJob) - .to_not receive(:distribute_non_genpop_priority_appeals).and_return([]) + context "with feature toggle enabled" do + before { FeatureToggle.enable!(:acd_ppj_distribute_not_genpop) } + after { FeatureToggle.disable!(:acd_ppj_distribute_not_genpop) } - subject + it "does distribute not_genpop appeals if the feature toggle is enabled" do + expect_any_instance_of(PushPriorityAppealsToJudgesJob) + .to receive(:distribute_non_genpop_priority_appeals).and_return([]) + + subject + end + end end - it "queues the UpdateAppealAffinityDatesJob" do + it "queues the UpdateAppealAffinityDatesJob and ReturnLegacyAppealsToBoardJob" do expect_any_instance_of(UpdateAppealAffinityDatesJob).to receive(:perform).with(no_args) + expect_any_instance_of(ReturnLegacyAppealsToBoardJob).to receive(:perform).with(no_args) subject end @@ -355,73 +365,35 @@ def to_judge_hash(arr) ready_priority_evidence_cases.each { |appeal| appeal.update(receipt_date: 1.month.ago) } end - context "using Automatic Case Distribution module", skip: "Automatic Case Distribution is deprecated" do - it "should distribute ready priority appeals to the judges" do - expect(subject.count).to eq judges.count - - # Ensure we distributed all available ready cases from any docket that are not tied to a judge - distributed_cases = DistributedCase.where(distribution: subject) - expect(distributed_cases.count).to eq priority_count - expect(distributed_cases.map(&:priority).uniq.compact).to match_array [true] - expect(distributed_cases.map(&:genpop).uniq.compact).to match_array [true] - expect(distributed_cases.pluck(:docket).uniq).to match_array(Constants::AMA_DOCKETS.keys.unshift("legacy")) - - expect(distributed_cases.group(:docket).count.values.uniq).to match_array [4] - end + it "should distribute ready priority appeals to the judges" do + expect(subject.count).to eq judges.count - it "distributes cases to each judge based on their priority target" do - judges.each_with_index do |judge, i| - target_distributions = priority_target - judge_distributions_this_month[i] - distribution = subject.detect { |dist| dist.judge_id == judge.id } - expect(distribution.statistics["batch_size"]).to eq target_distributions - distributed_cases = DistributedCase.where(distribution: distribution) - expect(distributed_cases.count).to eq target_distributions - end - end + # Ensure we distributed all available ready cases from any docket that are not tied to a judge + distributed_cases = DistributedCase.where(distribution: subject) + expect(distributed_cases.count).to eq priority_count + expect(distributed_cases.map(&:priority).uniq.compact).to match_array [true] + expect(distributed_cases.map(&:genpop).uniq.compact).to match_array [true] + expect(distributed_cases.pluck(:docket).uniq).to match_array(Constants::AMA_DOCKETS.keys.unshift("legacy")) + expect(distributed_cases.group(:docket).count.values.uniq).to match_array [4, 8] + end - context "where there is an ama-only judge" do - let!(:ama_only_judge) { create(:user, :judge, :ama_only_judge, :with_vacols_judge_record) } - let(:judges) { [ama_only_judge] } - it "only distributes ama cases to ama-only judge" do - distributed_cases = DistributedCase.where(distribution: subject) - distributed_cases.each do |distributed_case| - expect(distributed_case.docket).not_to eq("legacy") - end - end + it "distributes cases to each judge based on their priority target" do + judges.each_with_index do |judge, i| + target_distributions = priority_target - judge_distributions_this_month[i] + distribution = subject.detect { |dist| dist.judge_id == judge.id } + expect(distribution.statistics["batch_size"]).to eq target_distributions + distributed_cases = DistributedCase.where(distribution: distribution) + expect(distributed_cases.count).to eq target_distributions end end - context "using By Docket Date Distribution module" do - it "should distribute ready priority appeals to the judges" do - expect(subject.count).to eq judges.count - - # Ensure we distributed all available ready cases from any docket that are not tied to a judge + context "where there is an ama-only judge" do + let!(:ama_only_judge) { create(:user, :judge, :ama_only_judge, :with_vacols_judge_record) } + let(:judges) { [ama_only_judge] } + it "only distributes ama cases to ama-only judge" do distributed_cases = DistributedCase.where(distribution: subject) - expect(distributed_cases.count).to eq priority_count - expect(distributed_cases.map(&:priority).uniq.compact).to match_array [true] - expect(distributed_cases.map(&:genpop).uniq.compact).to match_array [true] - expect(distributed_cases.pluck(:docket).uniq).to match_array(Constants::AMA_DOCKETS.keys.unshift("legacy")) - expect(distributed_cases.group(:docket).count.values.uniq).to match_array [4, 8] - end - - it "distributes cases to each judge based on their priority target" do - judges.each_with_index do |judge, i| - target_distributions = priority_target - judge_distributions_this_month[i] - distribution = subject.detect { |dist| dist.judge_id == judge.id } - expect(distribution.statistics["batch_size"]).to eq target_distributions - distributed_cases = DistributedCase.where(distribution: distribution) - expect(distributed_cases.count).to eq target_distributions - end - end - - context "where there is an ama-only judge" do - let!(:ama_only_judge) { create(:user, :judge, :ama_only_judge, :with_vacols_judge_record) } - let(:judges) { [ama_only_judge] } - it "only distributes ama cases to ama-only judge" do - distributed_cases = DistributedCase.where(distribution: subject) - distributed_cases.each do |distributed_case| - expect(distributed_case.docket).not_to eq("legacy") - end + distributed_cases.each do |distributed_case| + expect(distributed_case.docket).not_to eq("legacy") end end end From 7a7f831c8ad0f728652826f5f06891ccafda3aa4 Mon Sep 17 00:00:00 2001 From: Craig Reese <109101548+craigrva@users.noreply.github.com> Date: Fri, 15 Nov 2024 12:15:17 -0600 Subject: [PATCH 5/8] fix seed data distribution statistics --- .../appeals_for_push_priority_job_distribution.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/db/seeds/appeals_for_push_priority_job_distribution.rb b/db/seeds/appeals_for_push_priority_job_distribution.rb index c399cca83d9..8fb9e6bf006 100644 --- a/db/seeds/appeals_for_push_priority_job_distribution.rb +++ b/db/seeds/appeals_for_push_priority_job_distribution.rb @@ -181,13 +181,17 @@ def create_aoj_legacy_cases def create_previous_distribtions statistics = { batch_size: 10, info: "See related row in distribution_stats for additional stats" } 4.times do |n| - create(:distribution, :completed, :priority, - judge: judge_many_previous_distributions, completed_at: n.weeks.ago, statistics: statistics) + d = create(:distribution, :completed, :priority, + judge: judge_many_previous_distributions, completed_at: n.weeks.ago) + + d.update!(statistics: statistics) end statistics = { batch_size: 100, info: "See related row in distribution_stats for additional stats" } - create(:distribution, :completed, :priority, :this_month, - judge: judge_one_large_previous_distribution, statistics: statistics) + d = create(:distribution, :completed, :priority, :this_month, + judge: judge_one_large_previous_distribution, statistics: statistics) + + d.update!(statistics: statistics) end def create_direct_review_priority_not_genpop_cases From b6fd86f83ee727bdb4f13fbc319e2a781de4fc04 Mon Sep 17 00:00:00 2001 From: Craig Reese <109101548+craigrva@users.noreply.github.com> Date: Fri, 15 Nov 2024 13:29:06 -0600 Subject: [PATCH 6/8] fix issue with seed data and comments in seed data --- db/seeds/appeals_for_push_priority_job_distribution.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/seeds/appeals_for_push_priority_job_distribution.rb b/db/seeds/appeals_for_push_priority_job_distribution.rb index 8fb9e6bf006..3a46788510f 100644 --- a/db/seeds/appeals_for_push_priority_job_distribution.rb +++ b/db/seeds/appeals_for_push_priority_job_distribution.rb @@ -411,7 +411,7 @@ def create_legacy_priority_not_genpop_cases def create_legacy_priority_genpop_cases # no hearing type original AOD - create(:case, :type_original, :ready_for_distribution) + create(:case, :type_original, :aod, :ready_for_distribution) tied_or_affinity_judges.each do |judge| judge_staff = judge.vacols_staff From d6e6756542999ac24dfdec4c5ce43e3ca7b9f2c1 Mon Sep 17 00:00:00 2001 From: Craig Reese <109101548+craigrva@users.noreply.github.com> Date: Fri, 15 Nov 2024 13:38:00 -0600 Subject: [PATCH 7/8] add tests, disabled slack message output in rspec tests --- app/services/slack_service.rb | 2 +- ...eals_for_push_priority_job_distribution.rb | 4 +- ...ush_priority_appeals_to_judges_job_spec.rb | 325 ++++++++---------- 3 files changed, 139 insertions(+), 192 deletions(-) diff --git a/app/services/slack_service.rb b/app/services/slack_service.rb index ba61aa1f07d..b1aa97034e0 100644 --- a/app/services/slack_service.rb +++ b/app/services/slack_service.rb @@ -28,7 +28,7 @@ def send_notification(msg, title = "", channel = DEFAULT_CHANNEL) if url && (Rails.deploy_env?(:uat) || Rails.deploy_env?(:prodtest) || Rails.deploy_env?(:prod)) params = { body: slack_msg.to_json, headers: { "Content-Type" => "application/json" } } http_service.post(url, params) - else + elsif Rails.deploy_env != :test # rubocop:disable Rails/Output Rails.logger.info(pp(slack_msg)) # rubocop:enable Rails/Output diff --git a/db/seeds/appeals_for_push_priority_job_distribution.rb b/db/seeds/appeals_for_push_priority_job_distribution.rb index 3a46788510f..386851126cc 100644 --- a/db/seeds/appeals_for_push_priority_job_distribution.rb +++ b/db/seeds/appeals_for_push_priority_job_distribution.rb @@ -471,9 +471,9 @@ def create_aoj_legacy_priority_not_genpop_cases # hearing before decision different deciding judge AOJ CAVC AOD affinity in window create(:legacy_aoj_appeal, :aod, judge: other_judge_staff_record, attorney: attorney_staff_record, affinity_start_date: 3.days.ago, cavc: true, original_dec_judge_sattyid: judge_staff.sattyid) - # no hearings AOJ CAVC affinity in window - create(:legacy_aoj_appeal, :aod, judge: judge_staff, attorney: attorney_staff_record, tied_to: false, affinity_start_date: 3.days.ago) # no hearings AOJ AOD affinity in window + create(:legacy_aoj_appeal, :aod, judge: judge_staff, attorney: attorney_staff_record, tied_to: false, affinity_start_date: 3.days.ago) + # no hearings AOJ CAVC affinity in window create(:legacy_aoj_appeal, judge: judge_staff, attorney: attorney_staff_record, tied_to: false, affinity_start_date: 3.days.ago, cavc: true) # no hearings AOJ CAVC AOD affinity in window create(:legacy_aoj_appeal, :aod, judge: judge_staff, attorney: attorney_staff_record, tied_to: false, affinity_start_date: 3.days.ago, cavc: true) diff --git a/spec/jobs/push_priority_appeals_to_judges_job_spec.rb b/spec/jobs/push_priority_appeals_to_judges_job_spec.rb index 1c376a889a6..531de5aa38b 100644 --- a/spec/jobs/push_priority_appeals_to_judges_job_spec.rb +++ b/spec/jobs/push_priority_appeals_to_judges_job_spec.rb @@ -5,20 +5,7 @@ FeatureToggle.enable!(:acd_distribute_by_docket_date) allow_any_instance_of(Docket).to receive(:calculate_days_for_time_goal_with_prior_to_goal).and_return(20) - create(:case_distribution_lever, :request_more_cases_minimum) - create(:case_distribution_lever, :alternative_batch_size) - create(:case_distribution_lever, :nod_adjustment) - create(:case_distribution_lever, :batch_size_per_attorney) - create(:case_distribution_lever, :cavc_affinity_days) - create(:case_distribution_lever, :cavc_aod_affinity_days) - create(:case_distribution_lever, :aoj_cavc_affinity_days) - create(:case_distribution_lever, :aoj_aod_affinity_days) - create(:case_distribution_lever, :aoj_affinity_days) - create(:case_distribution_lever, :ama_hearing_case_affinity_days) - create(:case_distribution_lever, :ama_hearing_case_aod_affinity_days) - create(:case_distribution_lever, :ama_direct_review_start_distribution_prior_to_goals) - create(:case_distribution_lever, :disable_legacy_non_priority) - create(:case_distribution_lever, :nonsscavlj_number_of_appeals_to_move) + Seeds::CaseDistributionLevers.new.seed! end def to_judge_hash(arr) @@ -33,6 +20,20 @@ def to_judge_hash(arr) subject { described_class.perform_now } + it "queues the UpdateAppealAffinityDatesJob and ReturnLegacyAppealsToBoardJob" do + expect_any_instance_of(UpdateAppealAffinityDatesJob).to receive(:perform).with(no_args) + expect_any_instance_of(ReturnLegacyAppealsToBoardJob).to receive(:perform).with(no_args) + + subject + end + + it "calls send_job_report method" do + expect_any_instance_of(PushPriorityAppealsToJudgesJob) + .to receive(:generate_report).and_return([]) + + subject + end + context "acd_ppj_distribute_not_genpop feature toggle" do context "with feature toggle disabled" do it "does not distribute not_genpop appeals" do @@ -53,200 +54,146 @@ def to_judge_hash(arr) subject end - end - end - it "queues the UpdateAppealAffinityDatesJob and ReturnLegacyAppealsToBoardJob" do - expect_any_instance_of(UpdateAppealAffinityDatesJob).to receive(:perform).with(no_args) - expect_any_instance_of(ReturnLegacyAppealsToBoardJob).to receive(:perform).with(no_args) + context "distributing appeals" do + let!(:judge_with_cases) { create(:user, :judge, :with_vacols_judge_record) } + let!(:judge_with_no_affinity_cases) { create(:user, :judge, :with_vacols_judge_record) } - subject - end + let!(:direct_review_cavc_affinity) do + create(:appeal, :direct_review_docket, :type_cavc_remand, :cavc_ready_for_distribution, + judge: judge_with_cases) + end + let!(:hearing_affinity) do + create(:appeal, :hearing_docket, :advanced_on_docket_due_to_age, :held_hearing_and_ready_to_distribute, + tied_judge: judge_with_cases) + end + let!(:direct_review_aod) do + create(:appeal, :direct_review_docket, :advanced_on_docket_due_to_age, :ready_for_distribution) + end - it "calls send_job_report method" do - expect_any_instance_of(PushPriorityAppealsToJudgesJob) - .to receive(:generate_report).and_return([]) + it "distributes non-genpop before calculating priority target" do + job = PushPriorityAppealsToJudgesJob.new + job.perform_now - subject + expect(job.send(:priority_distributions_this_month_for_eligible_judges)) + .to eq({ judge_with_cases.id => 2, judge_with_no_affinity_cases.id => 0 }) + expect(job.send(:ready_genpop_priority_appeals_count)).to eq(1) + expect(job.send(:priority_target)).to eq(1) + end + end + end end end context ".distribute_non_genpop_priority_appeals" do - let(:ready_priority_bfkey) { "12345" } - let(:ready_priority_bfkey2) { "12346" } - let(:ready_priority_uuid) { "bece6907-3b6f-4c49-a580-6d5f2e1ca65c" } - let(:ready_priority_uuid2) { "bece6907-3b6f-4c49-a580-6d5f2e1ca65d" } - let(:receipt_date) { 30.days.ago } - let!(:judge_with_ready_priority_cases) do - create(:user, :judge, :with_vacols_judge_record).tap do |judge| - vacols_case = create( - :case, - :aod, - bfkey: ready_priority_bfkey, - bfd19: 1.year.ago, - bfac: "1", - bfmpro: "ACT", - bfcurloc: "81", - bfdloout: 3.days.ago, - bfbox: nil, - folder: build(:folder, tinum: "1801003", titrnum: "123456789S") - ) - create( - :case_hearing, - :disposition_held, - folder_nr: vacols_case.bfkey, - hearing_date: 5.days.ago.to_date, - board_member: judge.vacols_attorney_id - ) - - appeal = create( - :appeal, - :ready_for_distribution, - :advanced_on_docket_due_to_age, - :with_appeal_affinity, - uuid: ready_priority_uuid, - docket_type: Constants.AMA_DOCKETS.hearing, - receipt_date: receipt_date - ) - most_recent = create(:hearing_day, scheduled_for: 1.day.ago) - hearing = create(:hearing, judge: nil, disposition: "held", appeal: appeal, hearing_day: most_recent) - hearing.update!(judge: judge) - end + before { FeatureToggle.enable!(:acd_ppj_distribute_not_genpop) } + after { FeatureToggle.disable!(:acd_ppj_distribute_not_genpop) } + + # judges with non-genpop cases who should receive those cases + let!(:judge_with_cases_1) { create(:user, :judge, :with_vacols_judge_record) } + let(:judge_with_cases_1_staff) { judge_with_cases_1.vacols_staff } + let!(:judge_with_cases_2) { create(:user, :judge, :with_vacols_judge_record) } + let!(:judge_with_cases_2_staff) { judge_with_cases_2.vacols_staff } + + # judges without non-genpop cases who should receive nothing + let!(:judge_with_no_affinity_cases) { create(:user, :judge, :with_vacols_judge_record) } + + # judge who is not eligible to be distribute cases in the push job + let!(:judge_cannot_receive_push_cases) do + user = create(:user, :judge, :with_vacols_judge_record) + JudgeTeam.for_judge(user).update!(accepts_priority_pushed_cases: false) + user end - let!(:judge_with_ready_nonpriority_cases) do - create(:user, :judge, :with_vacols_judge_record).tap do |judge| - vacols_case = create( - :case, - bfd19: 1.year.ago, - bfac: "1", - bfmpro: "ACT", - bfcurloc: "81", - bfdloout: 3.days.ago, - bfbox: nil, - folder: build(:folder, tinum: "1801002", titrnum: "123456782S") - ) - create( - :case_hearing, - :disposition_held, - folder_nr: vacols_case.bfkey, - hearing_date: 5.days.ago.to_date, - board_member: judge.vacols_attorney_id - ) - - appeal = create( - :appeal, - :ready_for_distribution, - :with_appeal_affinity, - docket_type: Constants.AMA_DOCKETS.hearing, - receipt_date: receipt_date - ) - most_recent = create(:hearing_day, scheduled_for: 1.day.ago) - hearing = create(:hearing, judge: nil, disposition: "held", appeal: appeal, hearing_day: most_recent) - hearing.update!(judge: judge) - end + # genpop cases that shouldn't distribute + let!(:direct_review_aod) do + create(:appeal, :direct_review_docket, :advanced_on_docket_due_to_age, :ready_for_distribution) end - - let!(:judge_with_nonready_priority_cases) do - create(:user, :judge).tap do |judge| - create(:staff, :judge_role, user: judge) - vacols_case = create( - :case, - :aod, - bfd19: 1.year.ago, - bfac: "1", - bfmpro: "ACT", - bfcurloc: "not ready", - bfdloout: 3.days.ago, - bfbox: nil, - folder: build(:folder, tinum: "1801003", titrnum: "123456783S") - ) - create( - :case_hearing, - :disposition_held, - folder_nr: vacols_case.bfkey, - hearing_date: 5.days.ago.to_date, - board_member: judge.vacols_attorney_id - ) - - appeal = create( - :appeal, - :advanced_on_docket_due_to_age, - docket_type: Constants.AMA_DOCKETS.hearing, - receipt_date: receipt_date - ) - most_recent = create(:hearing_day, scheduled_for: 1.day.ago) - hearing = create(:hearing, judge: nil, disposition: "held", appeal: appeal, hearing_day: most_recent) - hearing.update!(judge: judge) - end + let!(:direct_review_out_of_window) do + create(:appeal, :direct_review_docket, :type_cavc_remand, :cavc_ready_for_distribution, :with_appeal_affinity, + judge: judge_with_cases_1, affinity_start_date: 3.months.ago) + end + let!(:evidence_aod) do + create(:appeal, :evidence_submission_docket, :advanced_on_docket_due_to_age, :ready_for_distribution) + end + let!(:evidence_out_of_window) do + create(:appeal, :evidence_submission_docket, :type_cavc_remand, :cavc_ready_for_distribution, + :with_appeal_affinity, judge: judge_with_cases_2, affinity_start_date: 3.months.ago) + end + let!(:hearing_aod_cancelled_hearing) do + create(:appeal, :hearing_docket, :advanced_on_docket_due_to_age, :with_post_intake_tasks, + :cancelled_hearing_and_ready_to_distribute) + end + let!(:hearing_out_of_window) do + create(:appeal, :hearing_docket, :advanced_on_docket_due_to_age, :held_hearing_and_ready_to_distribute, + :with_appeal_affinity, tied_judge: judge_with_cases_1, affinity_start_date: 3.months.ago) + end + let!(:legacy_aod) do + create(:case, :type_original, :aod, :ready_for_distribution) + end + let!(:legacy_out_of_window) do + create(:legacy_cavc_appeal, judge: judge_with_cases_2_staff, tied_to: false, affinity_start_date: 2.months.ago) + end + let!(:aoj_out_of_window) do + create(:legacy_aoj_appeal, :aod, + judge: judge_with_cases_1_staff, tied_to: false, affinity_start_date: 2.months.ago) end - let!(:ama_only_judge_with_ready_priority_cases) do - create(:user, :ama_only_judge, :with_vacols_judge_record).tap do |judge| - vacols_case = create( - :case, - :aod, - bfkey: ready_priority_bfkey2, - bfd19: 1.year.ago, - bfac: "1", - bfmpro: "ACT", - bfcurloc: "81", - bfdloout: 3.days.ago, - bfbox: nil, - folder: build(:folder, tinum: "1801005", titrnum: "923456790S") - ) - create( - :case_hearing, - :disposition_held, - folder_nr: vacols_case.bfkey, - hearing_date: 5.days.ago.to_date, - board_member: judge.vacols_attorney_id - ) - appeal = create( - :appeal, - :ready_for_distribution, - :advanced_on_docket_due_to_age, - :with_appeal_affinity, - uuid: ready_priority_uuid2, - docket_type: Constants.AMA_DOCKETS.hearing, - receipt_date: receipt_date - ) - most_recent = create(:hearing_day, scheduled_for: 1.day.ago) - hearing = create(:hearing, judge: nil, disposition: "held", appeal: appeal, hearing_day: most_recent) - hearing.update!(judge: judge) - end + # not genpop cases which should all distribute + let!(:direct_review_cavc_affinity) do + create(:appeal, :direct_review_docket, :type_cavc_remand, :cavc_ready_for_distribution, + judge: judge_with_cases_2) end - let(:eligible_judges) do - [ - judge_with_ready_priority_cases, - judge_with_ready_nonpriority_cases, - judge_with_nonready_priority_cases, - ama_only_judge_with_ready_priority_cases - ] + let!(:evidence_cavc_affinity) do + create(:appeal, :evidence_submission_docket, :advanced_on_docket_due_to_age, :type_cavc_remand, + :cavc_ready_for_distribution, judge: judge_with_cases_1) + end + let!(:hearing_affinity) do + create(:appeal, :hearing_docket, :advanced_on_docket_due_to_age, :held_hearing_and_ready_to_distribute, + tied_judge: judge_with_cases_2) + end + let!(:legacy_cavc_affinity) do + create(:legacy_cavc_appeal, judge: judge_with_cases_1_staff, tied_to: false, affinity_start_date: 3.days.ago) + end + let!(:aoj_cavc_affinity) do + create(:legacy_aoj_appeal, :aod, judge: judge_with_cases_2_staff, tied_to: false, affinity_start_date: 3.days.ago) + end + let!(:legacy_aod_tied) do + create(:case, :type_original, :aod, :tied_to_judge, :ready_for_distribution, tied_judge: judge_with_cases_1) + end + let!(:aoj_aod_tied) do + create(:legacy_aoj_appeal, :aod, judge: judge_with_cases_2_staff) end - before do - allow_any_instance_of(DirectReviewDocket) - .to receive(:nonpriority_receipts_per_year) - .and_return(100) + subject { PushPriorityAppealsToJudgesJob.new.send(:distribute_non_genpop_priority_appeals) } - allow(Docket) - .to receive(:nonpriority_decisions_per_year) - .and_return(1000) - end + it "distributes only non-genpop appeals and doesn't calculate priority target" do + # assert that the job will not try to calculate the priority target when this method is run + expect_any_instance_of(PushPriorityAppealsToJudgesJob) + .to_not receive(:priority_distributions_this_month_for_eligible_judges) + + subject - subject { PushPriorityAppealsToJudgesJob.new.distribute_non_genpop_priority_appeals } + distributed_judges = Distribution.all.map(&:judge) + distributed_case_ids = DistributedCase.all.map(&:case_id) + not_distributed_ama_appeals = DistributionTask.assigned.map(&:appeal) + not_distributed_legacy_appeals = VACOLS::Case.where(bfcurloc: %w[81 83]) - context "using By Docket Date Distribution module" do - before do - FeatureToggle.enable!(:acd_distribute_by_docket_date) - FeatureToggle.enable!(:acd_exclude_from_affinity) - allow_any_instance_of(PushPriorityAppealsToJudgesJob).to receive(:eligible_judges).and_return(eligible_judges) - end - after do - FeatureToggle.disable!(:acd_distribute_by_docket_date) - FeatureToggle.disable!(:acd_exclude_from_affinity) - end + expect(distributed_judges).to_not include(judge_cannot_receive_push_cases) + expect(Distribution.find_by(judge: judge_with_no_affinity_cases).distributed_cases.count).to eq(0) + + expect(not_distributed_ama_appeals).to match_array( + [direct_review_aod, direct_review_out_of_window, evidence_aod, evidence_out_of_window, + hearing_aod_cancelled_hearing, hearing_out_of_window] + ) + # correct the legacy_out_of_window and legacy_cavc_affinity bfkeys because of factory behavior + expect(not_distributed_legacy_appeals.map(&:bfkey)).to match_array( + [legacy_aod.bfkey, (legacy_out_of_window.bfkey.to_i + 1).to_s, aoj_out_of_window.bfkey] + ) + expect(distributed_case_ids).to match_array( + [direct_review_cavc_affinity.uuid, evidence_cavc_affinity.uuid, hearing_affinity.uuid, + (legacy_cavc_affinity.bfkey.to_i + 1).to_s, aoj_cavc_affinity.bfkey, legacy_aod_tied.bfkey, aoj_aod_tied.bfkey] + ) end end From a4c192be22b50081e4f2c1c1a5f3c908df0df3e7 Mon Sep 17 00:00:00 2001 From: Craig Reese <109101548+craigrva@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:47:48 -0600 Subject: [PATCH 8/8] remove bvaawakefield from push job distributions --- db/seeds/appeals_for_push_priority_job_distribution.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/seeds/appeals_for_push_priority_job_distribution.rb b/db/seeds/appeals_for_push_priority_job_distribution.rb index 386851126cc..c881cf6d364 100644 --- a/db/seeds/appeals_for_push_priority_job_distribution.rb +++ b/db/seeds/appeals_for_push_priority_job_distribution.rb @@ -136,6 +136,9 @@ def instantiate_judges judge_one_large_previous_distribution excluded_judge ineligible_judge + + # This user is not a judge in VACOLS in the seed data, so don't allow them to get cases in the PPJ + JudgeTeam.find_by(name: "BVAAWAKEFIELD")&.update!(accepts_priority_pushed_cases: false) end def tied_or_affinity_judges