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

rebased hotfix/APPEALS-58200 changes to feature branch #23067

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions app/models/docket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def docket_type

# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# :reek:LongParameterList
def appeals(priority: nil, genpop: nil, ready: nil, judge: nil)
def appeals(priority: nil, genpop: nil, ready: nil, judge: nil, not_affinity: nil)
fail "'ready for distribution' value cannot be false" if ready == false

scope = docket_appeals
Expand All @@ -26,7 +26,7 @@ def appeals(priority: nil, genpop: nil, ready: nil, judge: nil)
if ready
scope = scope.ready_for_distribution
scope = adjust_for_genpop(scope, genpop, judge) if judge.present? && !use_by_docket_date?
scope = adjust_for_affinity(scope, judge) if judge.present? && FeatureToggle.enabled?(:acd_exclude_from_affinity)
scope = adjust_for_affinity(scope, not_affinity, judge) if FeatureToggle.enabled?(:acd_exclude_from_affinity)
end

return scoped_for_priority(scope) if priority == true
Expand All @@ -36,9 +36,9 @@ def appeals(priority: nil, genpop: nil, ready: nil, judge: nil)
scope.order("appeals.receipt_date")
end

def ready_priority_nonpriority_appeals(priority: false, ready: true, judge: nil, genpop: nil)
def ready_priority_nonpriority_appeals(priority: false, ready: true, judge: nil, genpop: nil, not_affinity: nil)
priority_status = priority ? PRIORITY : NON_PRIORITY
appeals = appeals(priority: priority, ready: ready, genpop: genpop, judge: judge)
appeals = appeals(priority: priority, ready: ready, genpop: genpop, judge: judge, not_affinity: not_affinity)
lever_item = "disable_ama_#{priority_status}_#{docket_type.downcase}"
docket_type_lever = CaseDistributionLever.find_by_item(lever_item)
docket_type_lever_value = docket_type_lever ? CaseDistributionLever.public_send(lever_item) : nil
Expand Down Expand Up @@ -98,9 +98,10 @@ def age_of_n_oldest_nonpriority_appeals_available_to_judge(judge, num)
def age_of_oldest_priority_appeal
@age_of_oldest_priority_appeal ||=
if use_by_docket_date?
ready_priority_nonpriority_appeals(priority: true, ready: true).limit(1).first&.receipt_date
ready_priority_nonpriority_appeals(priority: true, ready: true, not_affinity: true).limit(1).first&.receipt_date
else
ready_priority_nonpriority_appeals(priority: true, ready: true).limit(1).first&.ready_for_distribution_at
ready_priority_nonpriority_appeals(priority: true, ready: true, not_affinity: true)
.limit(1).first&.ready_for_distribution_at
end
end

Expand Down Expand Up @@ -209,8 +210,14 @@ def adjust_for_genpop(scope, genpop, judge)
(genpop == "not_genpop") ? scope.non_genpop_for_judge(judge) : scope.genpop
end

def adjust_for_affinity(scope, judge)
scope.genpop_with_case_distribution_lever.or(scope.non_genpop_with_case_distribution_lever(judge))
def adjust_for_affinity(scope, not_affinity, judge = nil)
if judge.present?
scope.genpop_with_case_distribution_lever.or(scope.non_genpop_with_case_distribution_lever(judge))
elsif not_affinity
scope
else
scope.genpop_with_case_distribution_lever
end
end

def scoped_for_priority(scope)
Expand Down
24 changes: 22 additions & 2 deletions app/models/vacols/aoj_case_docket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ def self.counts_by_priority_and_readiness
def self.genpop_priority_count
query = <<-SQL
#{SELECT_PRIORITY_APPEALS}
where (VLJ is null or #{ineligible_judges_sattyid_cache}) and (PREV_TYPE_ACTION = '7' or AOD = '1')
where (VLJ is null or VLJ != PREV_DECIDING_JUDGE or #{ineligible_judges_sattyid_cache}) and (PREV_TYPE_ACTION = '7' or AOD = '1')
SQL

connection.exec_query(query).to_a.size
filter_genpop_appeals_for_affinity(query).size
end

def self.not_genpop_priority_count
Expand Down Expand Up @@ -666,6 +666,26 @@ def self.generate_priority_case_distribution_lever_aoj_aod_query(aoj_aod_affinit
end
end

def self.filter_genpop_appeals_for_affinity(query)
aoj_cavc_affinity_lever_value = CaseDistributionLever.aoj_cavc_affinity_days
aoj_aod_affinity_lever_value = CaseDistributionLever.aoj_aod_affinity_days
aoj_affinity_lever_value = CaseDistributionLever.aoj_affinity_days
excluded_judges_attorney_ids = excluded_judges_sattyids

conn = connection

appeals = conn.exec_query(query).to_a

aoj_affinity_filter(appeals, nil, aoj_affinity_lever_value, excluded_judges_attorney_ids)

aoj_cavc_affinity_filter(appeals, nil, aoj_cavc_affinity_lever_value, excluded_judges_attorney_ids)

aoj_aod_affinity_filter(appeals, nil, aoj_aod_affinity_lever_value,
excluded_judges_attorney_ids)

appeals
end

# rubocop:disable Metrics/AbcSize
def self.aoj_affinity_filter(appeals, judge_sattyid, lever_value, excluded_judges_attorney_ids)
appeals.reject! do |appeal|
Expand Down
20 changes: 18 additions & 2 deletions app/models/vacols/case_docket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,10 @@ def self.counts_by_priority_and_readiness
def self.genpop_priority_count
query = <<-SQL
#{SELECT_PRIORITY_APPEALS}
where VLJ is null or #{ineligible_judges_sattyid_cache}
where VLJ is null or VLJ != PREV_DECIDING_JUDGE or #{ineligible_judges_sattyid_cache}
SQL

connection.exec_query(query).to_a.size
filter_genpop_appeals_for_affinity(query).size
end

def self.not_genpop_priority_count
Expand Down Expand Up @@ -785,6 +785,22 @@ def self.distribute_appeals(query, judge, limit, dry_run)
end
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/ParameterLists

def self.filter_genpop_appeals_for_affinity(query)
cavc_affinity_lever_value = CaseDistributionLever.cavc_affinity_days
cavc_aod_affinity_lever_value = CaseDistributionLever.cavc_aod_affinity_days
excluded_judges_attorney_ids = excluded_judges_sattyids

conn = connection

appeals = conn.exec_query(query).to_a

cavc_affinity_filter(appeals, nil, cavc_affinity_lever_value, excluded_judges_attorney_ids)
cavc_aod_affinity_filter(appeals, nil, cavc_aod_affinity_lever_value,
excluded_judges_attorney_ids)

appeals
end

def self.generate_priority_case_distribution_lever_query(cavc_affinity_lever_value)
if case_affinity_days_lever_value_is_selected?(cavc_affinity_lever_value) ||
cavc_affinity_lever_value == Constants.ACD_LEVERS.omit
Expand Down
2 changes: 1 addition & 1 deletion app/queries/appeals_non_priority_ready_for_distribution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def self.ready_appeals
# appeals = docket.ready_to_distribute_appeals.select { |appeal| appeal["aod"] == 0 }
# legacy_rows(appeals, docket, sym)
else
appeals = docket.ready_priority_nonpriority_appeals(priority: false, ready: true)
appeals = docket.ready_priority_nonpriority_appeals(priority: false, ready: true, not_affinity: true)
ama_rows(appeals, docket, sym)
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/models/docket_coordinator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
create(:case_distribution_lever, :ama_hearing_case_affinity_days)
create(:case_distribution_lever, :ama_direct_review_start_distribution_prior_to_goals)
create(:case_distribution_lever, :ama_direct_review_docket_time_goals)
create(:case_distribution_lever, :cavc_affinity_days)
create(:case_distribution_lever, :cavc_aod_affinity_days)
create(:case_distribution_lever, :aoj_affinity_days)
create(:case_distribution_lever, :aoj_aod_affinity_days)
create(:case_distribution_lever, :aoj_cavc_affinity_days)
create(:case_distribution_lever, :minimum_legacy_proportion)
create(:case_distribution_lever, :maximum_direct_review_proportion)
create(:case_distribution_lever, :nod_adjustment)
Expand Down
30 changes: 30 additions & 0 deletions spec/models/docket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
create(:case_distribution_lever, :ama_evidence_submission_docket_time_goals)
create(:case_distribution_lever, :ama_hearing_docket_time_goals)
create(:case_distribution_lever, :ama_hearing_start_distribution_prior_to_goals)
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, :ama_evidence_submission_review_start_distribution_prior_to_goals)
create(:case_distribution_lever, :cavc_affinity_days)
Expand Down Expand Up @@ -145,6 +147,7 @@

context "when acd_exclude_from_affinity flag is enabled" do
before { FeatureToggle.enable!(:acd_exclude_from_affinity) }
after { FeatureToggle.disable!(:acd_exclude_from_affinity) }

context "when called for ready is true and judge is passed" do
let(:judge) { judge_decision_review_task.assigned_to }
Expand Down Expand Up @@ -353,6 +356,33 @@
it "counts genpop priority appeals" do
expect(subject).to eq(3)
end

context "when acd_exclude_from_affinity flag is enabled" do
before { FeatureToggle.enable!(:acd_exclude_from_affinity) }
after { FeatureToggle.disable!(:acd_exclude_from_affinity) }
let(:docket) { HearingRequestDocket.new }
let!(:cavc_appeal2) do
create(:appeal,
:type_cavc_remand,
:cavc_ready_for_distribution,
:with_appeal_affinity,
docket_type: Constants.AMA_DOCKETS.hearing,
affinity_start_date: 2.days.ago)
end
let!(:cavc_appeal3) do
create(:appeal,
:type_cavc_remand,
:cavc_ready_for_distribution,
:with_appeal_affinity,
docket_type: Constants.AMA_DOCKETS.hearing,
affinity_start_date: 80.days.ago)
end
subject { docket.genpop_priority_count }

it "correctly filters out appeals within affinity window" do
expect(subject).to eq(1)
end
end
end

context "ready_priority_nonpriority_appeals" do
Expand Down
44 changes: 44 additions & 0 deletions spec/models/vacols/aoj_case_docket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
let(:inactive_judge) { create(:user, :inactive) }
let!(:inactive_vacols_judge) { create(:staff, :judge_role, svlj: "V", sdomainid: inactive_judge.css_id) }

let(:caseflow_attorney) { create(:user) }
let!(:vacols_attorney) { create(:staff, :attorney_role, sdomainid: caseflow_attorney.css_id) }

let(:nonpriority_ready_case_bfbox) { nil }
let(:nonpriority_ready_case_docket_number) { "1801001" }
let!(:nonpriority_ready_case) do
Expand Down Expand Up @@ -159,6 +162,47 @@
end
end

context ".genpop_priority_count" do
subject { VACOLS::AojCaseDocket.genpop_priority_count }
it "counts genpop priority appeals" do
expect(subject).to eq(2)
end

context "with affinitized appeals" do
let!(:aoj_aod_cavc_ready_case_within_affinity) do
create(:legacy_aoj_appeal,
:aod,
cavc: true,
judge: vacols_judge,
attorney: vacols_attorney,
tied_to: false,
affinity_start_date: 3.days.ago)
end

let!(:aoj_aod_ready_case_within_affinity) do
create(:legacy_aoj_appeal,
:aod,
judge: vacols_judge,
attorney: vacols_attorney,
tied_to: false,
affinity_start_date: 3.days.ago)
end

let!(:aoj_cavc_ready_case_within_affinity) do
create(:legacy_aoj_appeal,
cavc: true,
judge: vacols_judge,
attorney: vacols_attorney,
tied_to: false,
affinity_start_date: 3.days.ago)
end

it "correctly filters out appeals based on the lever filters" do
expect(subject).to eq(2)
end
end
end

context ".age_of_oldest_priority_appeal" do
subject { VACOLS::AojCaseDocket.age_of_oldest_priority_appeal }

Expand Down Expand Up @@ -302,7 +346,7 @@

context "when the docket number is pre-y2k", skip: "flaky" do
let(:another_nonpriority_ready_case_docket_number) { "9901002" }
it "correctly orders the docket", skip: "flaky" do

Check warning on line 349 in spec/models/vacols/aoj_case_docket_spec.rb

View workflow job for this annotation

GitHub Actions / caseflow_rspec_job (12, 7)

VACOLS::AojCaseDocket.distribute_nonpriority_appeals when range is specified when the docket number is pre-y2k correctly orders the docket Skipped: flaky
expect(subject.count).to eq(1)
expect(subject.first["bfkey"]).to eq another_nonpriority_ready_case.bfkey
expect(nonpriority_ready_case.reload.bfcurloc).to eq("81")
Expand Down Expand Up @@ -386,7 +430,7 @@
.and_return(VACOLS::AojCaseDocket::HEARING_BACKLOG_LIMIT + number_of_cases_over_backlog)
end

it "only distributes the one case to get back down to 30", skip: "flaky" do

Check warning on line 433 in spec/models/vacols/aoj_case_docket_spec.rb

View workflow job for this annotation

GitHub Actions / caseflow_rspec_job (12, 7)

VACOLS::AojCaseDocket.distribute_nonpriority_appeals when a case is tied to a judge by a hearing on a prior appeal when bust backlog is specified when the judge's backlog is full only distributes the one case to get back down to 30 Skipped: flaky
expect(subject.count).to eq(number_of_cases_over_backlog)
expect(subject.first["bfkey"]).to eq nonpriority_ready_case.bfkey
expect(nonpriority_ready_case.reload.bfcurloc).to eq(judge.vacols_uniq_id)
Expand Down
33 changes: 33 additions & 0 deletions spec/models/vacols/case_docket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
let(:inactive_judge) { create(:user, :inactive) }
let!(:inactive_vacols_judge) { create(:staff, :judge_role, svlj: "V", sdomainid: inactive_judge.css_id) }

let(:caseflow_attorney) { create(:user) }
let!(:vacols_attorney) { create(:staff, :attorney_role, sdomainid: caseflow_attorney.css_id) }

let(:nonpriority_ready_case_bfbox) { nil }
let(:nonpriority_ready_case_docket_number) { "1801001" }
let!(:nonpriority_ready_case) do
Expand Down Expand Up @@ -160,6 +163,36 @@
end
end

context ".genpop_priority_count" do
subject { VACOLS::CaseDocket.genpop_priority_count }
it "counts genpop priority appeals" do
expect(subject).to eq(2)
end

context "with affinitized appeals" do
let!(:aod_cavc_ready_case_within_affinity) do
create(:legacy_cavc_appeal,
judge: vacols_judge,
attorney: vacols_attorney,
aod: true,
tied_to: false,
affinity_start_date: 3.days.ago)
end

let!(:cavc_ready_case_within_affinity) do
create(:legacy_cavc_appeal,
judge: vacols_judge,
attorney: vacols_attorney,
tied_to: false,
affinity_start_date: 3.days.ago)
end

it "correctly filters out appeals based on the lever filters" do
expect(subject).to eq(2)
end
end
end

context ".age_of_n_oldest_genpop_priority_appeals" do
subject { VACOLS::CaseDocket.age_of_n_oldest_genpop_priority_appeals(2) }
it "returns the sorted ages of the n oldest priority appeals" do
Expand Down
Loading