From 6aad694cc261bdb43d1c1194219cba331283f9ef Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 22 May 2024 15:05:12 -0400 Subject: [PATCH 01/51] initial updates --- app/models/vacols/case_docket.rb | 48 +++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 1bf222daad0..e2f3aadcda9 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -454,12 +454,13 @@ def self.ready_to_distribute_appeals # {UPDATE} # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/ParameterLists, Metrics/MethodLength def self.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlog, dry_run = false) + non_priority_cdl_aod_query = generate_non_priority_case_distribution_lever_aod_query(judge) fail(DocketNumberCentennialLoop, COPY::MAX_LEGACY_DOCKET_NUMBER_ERROR_MESSAGE) if Time.zone.now.year >= 2030 if use_by_docket_date? query = <<-SQL #{SELECT_NONPRIORITY_APPEALS_ORDER_BY_BFD19} - where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?)) + where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) and #{non_priority_cdl_aod_query}) and (DOCKET_INDEX <= ? or 1 = ?) and rownum <= ? SQL @@ -479,7 +480,7 @@ def self.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlo query = <<-SQL #{SELECT_NONPRIORITY_APPEALS} - where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?)) + where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) and #{non_priority_cdl_aod_query}) and (DOCKET_INDEX <= ? or 1 = ?) and rownum <= ? SQL @@ -501,16 +502,17 @@ def self.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlo # {UPDATE} def self.distribute_priority_appeals(judge, genpop, limit, dry_run = false) + priority_cdl_aod_query = generate_priority_case_distribution_lever_aod_query(judge) query = if use_by_docket_date? <<-SQL #{SELECT_PRIORITY_APPEALS_ORDER_BY_BFD19} - where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?)) + where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) and #{priority_cdl_aod_query}) and (rownum <= ? or 1 = ?) SQL else <<-SQL #{SELECT_PRIORITY_APPEALS} - where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?)) + where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) and #{priority_cdl_aod_query}) and (rownum <= ? or 1 = ?) SQL end @@ -553,6 +555,38 @@ def self.distribute_appeals(query, judge, dry_run) end end + def self.generate_priority_case_distribution_lever_aod_query(_judge) + query = if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) + <<-SQL + #{VACOLS::Case::JOIN_AOD} + where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache} or VLJ is null) + and rownum <= ? + SQL + elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite + <<-SQL + #{VACOLS::Case::JOIN_AOD} + where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache} or VLJ is null) + and rownum <= ? + SQL + end + end + + def self.generate_nonpriority_case_distribution_lever_aod_query(_judge) + query = if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) + <<-SQL + #{VACOLS::Case::JOIN_AOD} + where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache} or VLJ is null) + and rownum <= ? + SQL + elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite + <<-SQL + #{VACOLS::Case::JOIN_AOD} + where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache} or VLJ is null) + and rownum <= ? + SQL + end + end + def self.use_by_docket_date? FeatureToggle.enabled?(:acd_distribute_by_docket_date, user: RequestStore.store[:current_user]) end @@ -585,5 +619,11 @@ def self.ineligible_judges_sattyid_cache end end # rubocop:enable Metrics/MethodLength + + def self.case_affinity_days_lever_value_is_selected?(lever_value) + return false if lever_value == "omit" || lever_value == "infinite" + + true + end end # rubocop:enable Metrics/ClassLength From ba18d18fdd79101ef113a16d07efb14113be3afa Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 22 May 2024 15:09:02 -0400 Subject: [PATCH 02/51] removing unnecessary variable --- app/models/vacols/case_docket.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index e2f3aadcda9..c51b64053c0 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -556,34 +556,34 @@ def self.distribute_appeals(query, judge, dry_run) end def self.generate_priority_case_distribution_lever_aod_query(_judge) - query = if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) - <<-SQL + if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) + <<-SQL #{VACOLS::Case::JOIN_AOD} where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache} or VLJ is null) and rownum <= ? - SQL - elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite - <<-SQL + SQL + elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite + <<-SQL #{VACOLS::Case::JOIN_AOD} where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache} or VLJ is null) and rownum <= ? - SQL + SQL end end def self.generate_nonpriority_case_distribution_lever_aod_query(_judge) - query = if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) - <<-SQL + if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) + <<-SQL #{VACOLS::Case::JOIN_AOD} where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache} or VLJ is null) and rownum <= ? - SQL - elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite - <<-SQL + SQL + elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite + <<-SQL #{VACOLS::Case::JOIN_AOD} where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache} or VLJ is null) and rownum <= ? - SQL + SQL end end From 91d0dd7c60b149a4a6ac250d0d53d855249b7eeb Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 22 May 2024 16:03:51 -0400 Subject: [PATCH 03/51] focused in on priority --- app/models/vacols/case_docket.rb | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index c51b64053c0..6b8d089c066 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -454,13 +454,12 @@ def self.ready_to_distribute_appeals # {UPDATE} # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/ParameterLists, Metrics/MethodLength def self.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlog, dry_run = false) - non_priority_cdl_aod_query = generate_non_priority_case_distribution_lever_aod_query(judge) fail(DocketNumberCentennialLoop, COPY::MAX_LEGACY_DOCKET_NUMBER_ERROR_MESSAGE) if Time.zone.now.year >= 2030 if use_by_docket_date? query = <<-SQL #{SELECT_NONPRIORITY_APPEALS_ORDER_BY_BFD19} - where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) and #{non_priority_cdl_aod_query}) + where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?)) and (DOCKET_INDEX <= ? or 1 = ?) and rownum <= ? SQL @@ -558,33 +557,15 @@ def self.distribute_appeals(query, judge, dry_run) def self.generate_priority_case_distribution_lever_aod_query(_judge) if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) <<-SQL - #{VACOLS::Case::JOIN_AOD} - where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache} or VLJ is null) - and rownum <= ? - SQL - elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite - <<-SQL - #{VACOLS::Case::JOIN_AOD} - where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache} or VLJ is null) - and rownum <= ? - SQL - end - end - - def self.generate_nonpriority_case_distribution_lever_aod_query(_judge) - if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) - <<-SQL - #{VACOLS::Case::JOIN_AOD} - where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache} or VLJ is null) + where (PREV_TYPE_ACTION = '7' and PREV_DECIDING_JUDGE = ?) and rownum <= ? SQL elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite <<-SQL - #{VACOLS::Case::JOIN_AOD} - where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache} or VLJ is null) + where (PREV_TYPE_ACTION = '7' and PREV_DECIDING_JUDGE = ?) and rownum <= ? SQL - end + end end def self.use_by_docket_date? From ecce1385fcd6dfb0a5b13a94e56f7624a6c9f7bb Mon Sep 17 00:00:00 2001 From: Calvin Date: Thu, 23 May 2024 10:13:58 -0400 Subject: [PATCH 04/51] removing non priority stuff --- app/models/vacols/case_docket.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 6b8d089c066..62fb31657d7 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -479,7 +479,7 @@ def self.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlo query = <<-SQL #{SELECT_NONPRIORITY_APPEALS} - where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) and #{non_priority_cdl_aod_query}) + where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?)) and (DOCKET_INDEX <= ? or 1 = ?) and rownum <= ? SQL @@ -500,29 +500,27 @@ def self.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlo # rubocop:enable Metrics/ParameterLists, Metrics/MethodLength # {UPDATE} - def self.distribute_priority_appeals(judge, genpop, limit, dry_run = false) + def self.distribute_priority_appeals(judge, genpop, _limit, dry_run = false) priority_cdl_aod_query = generate_priority_case_distribution_lever_aod_query(judge) query = if use_by_docket_date? <<-SQL #{SELECT_PRIORITY_APPEALS_ORDER_BY_BFD19} where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) and #{priority_cdl_aod_query}) - and (rownum <= ? or 1 = ?) SQL else <<-SQL #{SELECT_PRIORITY_APPEALS} where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) and #{priority_cdl_aod_query}) - and (rownum <= ? or 1 = ?) SQL end + # {Once we have the query we can run it through an affinity days filter + fmtd_query = sanitize_sql_array([ query, judge.vacols_attorney_id, (genpop == "any" || genpop == "not_genpop") ? 1 : 0, - (genpop == "any" || genpop == "only_genpop") ? 1 : 0, - limit, - limit.nil? ? 1 : 0 + (genpop == "any" || genpop == "only_genpop") ? 1 : 0 ]) distribute_appeals(fmtd_query, judge, dry_run) @@ -554,7 +552,7 @@ def self.distribute_appeals(query, judge, dry_run) end end - def self.generate_priority_case_distribution_lever_aod_query(_judge) + def self.generate_priority_case_distribution_lever_aod_query if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) <<-SQL where (PREV_TYPE_ACTION = '7' and PREV_DECIDING_JUDGE = ?) From efd102d075ed9edf2c5835e9e43b93fbb239e7cb Mon Sep 17 00:00:00 2001 From: Calvin Date: Thu, 23 May 2024 10:24:48 -0400 Subject: [PATCH 05/51] added general comments --- app/models/vacols/case_docket.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 62fb31657d7..bcf51b806e1 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -514,7 +514,7 @@ def self.distribute_priority_appeals(judge, genpop, _limit, dry_run = false) SQL end - # {Once we have the query we can run it through an affinity days filter + # {Once we have the query we can run it through an affinity days filter, reorder then add limit} fmtd_query = sanitize_sql_array([ query, @@ -554,11 +554,13 @@ def self.distribute_appeals(query, judge, dry_run) def self.generate_priority_case_distribution_lever_aod_query if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) + # {Need to check for affinity_start_date on AMA DB is less than CaseDistributionLever.cavc_aod_affinity_days.days.ago} <<-SQL where (PREV_TYPE_ACTION = '7' and PREV_DECIDING_JUDGE = ?) and rownum <= ? SQL elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite + # {Need to make sure PREV_DECIDING_JUDGE is equal to the VLJ since it is infinite} <<-SQL where (PREV_TYPE_ACTION = '7' and PREV_DECIDING_JUDGE = ?) and rownum <= ? From 6d3b556ed001c2ed79666f52e55700016b2dda41 Mon Sep 17 00:00:00 2001 From: Calvin Date: Thu, 23 May 2024 13:44:33 -0400 Subject: [PATCH 06/51] added BFAC and AOD to cavc aod lever query --- app/models/vacols/case_docket.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index bcf51b806e1..fb9baef6dcd 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -136,9 +136,9 @@ class DocketNumberCentennialLoop < StandardError; end " SELECT_PRIORITY_APPEALS_ORDER_BY_BFD19 = " - select BFKEY, BFD19, BFDLOOUT, VLJ, PREV_TYPE_ACTION, PREV_DECIDING_JUDGE + select BFKEY, BFD19, BFDLOOUT, BFAC, AOD, VLJ, PREV_TYPE_ACTION, PREV_DECIDING_JUDGE from ( - select BFKEY, BFD19, BFDLOOUT, + select BFKEY, BFD19, BFDLOOUT, BFAC, AOD, case when BFHINES is null or BFHINES <> 'GP' then VLJ_HEARINGS.VLJ end VLJ, PREV_APPEAL.PREV_TYPE_ACTION PREV_TYPE_ACTION, PREV_APPEAL.PREV_DECIDING_JUDGE PREV_DECIDING_JUDGE @@ -167,9 +167,9 @@ class DocketNumberCentennialLoop < StandardError; end " SELECT_NONPRIORITY_APPEALS_ORDER_BY_BFD19 = " - select BFKEY, BFD19, BFDLOOUT, VLJ, DOCKET_INDEX, PREV_TYPE_ACTION, PREV_DECIDING_JUDGE + select BFKEY, BFD19, BFDLOOUT, BFAC, AOD, VLJ, DOCKET_INDEX, PREV_TYPE_ACTION, PREV_DECIDING_JUDGE from ( - select BFKEY, BFD19, BFDLOOUT, rownum DOCKET_INDEX, + select BFKEY, BFD19, BFDLOOUT, BFAC, AOD, rownum DOCKET_INDEX, case when BFHINES is null or BFHINES <> 'GP' then VLJ_HEARINGS.VLJ end VLJ, PREV_APPEAL.PREV_TYPE_ACTION PREV_TYPE_ACTION, PREV_APPEAL.PREV_DECIDING_JUDGE PREV_DECIDING_JUDGE @@ -505,12 +505,12 @@ def self.distribute_priority_appeals(judge, genpop, _limit, dry_run = false) query = if use_by_docket_date? <<-SQL #{SELECT_PRIORITY_APPEALS_ORDER_BY_BFD19} - where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) and #{priority_cdl_aod_query}) + where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) and (#{priority_cdl_aod_query} or #{priority_cdl_query})) SQL else <<-SQL #{SELECT_PRIORITY_APPEALS} - where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) and #{priority_cdl_aod_query}) + where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) and #{priority_cdl_aod_query} or #{priority_cdl_query}) SQL end @@ -556,13 +556,13 @@ def self.generate_priority_case_distribution_lever_aod_query if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) # {Need to check for affinity_start_date on AMA DB is less than CaseDistributionLever.cavc_aod_affinity_days.days.ago} <<-SQL - where (PREV_TYPE_ACTION = '7' and PREV_DECIDING_JUDGE = ?) + where (PREV_DECIDING_JUDGE = ? and AOD = '1' and BFAC = '7' ) and rownum <= ? SQL elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite # {Need to make sure PREV_DECIDING_JUDGE is equal to the VLJ since it is infinite} <<-SQL - where (PREV_TYPE_ACTION = '7' and PREV_DECIDING_JUDGE = ?) + where (PREV_DECIDING_JUDGE = ? and AOD = '1' and BFAC = '7') and rownum <= ? SQL end From 217ea76eeaaa6f0841342102e5d54e65dd9c9f53 Mon Sep 17 00:00:00 2001 From: Calvin Date: Fri, 24 May 2024 11:26:28 -0400 Subject: [PATCH 07/51] adding judge vacols id to query --- app/models/vacols/case_docket.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index fb9baef6dcd..0ebe9507cc7 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -520,7 +520,8 @@ def self.distribute_priority_appeals(judge, genpop, _limit, dry_run = false) query, judge.vacols_attorney_id, (genpop == "any" || genpop == "not_genpop") ? 1 : 0, - (genpop == "any" || genpop == "only_genpop") ? 1 : 0 + (genpop == "any" || genpop == "only_genpop") ? 1 : 0, + judge.vacols_attorney_id ]) distribute_appeals(fmtd_query, judge, dry_run) From 272d01efe0db28f8063772876d3a46c63659e936 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 28 May 2024 16:21:08 -0400 Subject: [PATCH 08/51] aod affinity_start_date filter initial changes --- app/models/vacols/case_docket.rb | 50 +++++++++++++++++--------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 0ebe9507cc7..06097db6c49 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -# rubocop:disable Metrics/ClassLength class VACOLS::CaseDocket < VACOLS::Record # :nocov: self.table_name = "brieff" @@ -206,8 +205,6 @@ class DocketNumberCentennialLoop < StandardError; end left join STAFF on APPEALS.VLJ = STAFF.STAFKEY order by BFD19 " - - # rubocop:disable Metrics/MethodLength def self.counts_by_priority_and_readiness query = <<-SQL select count(*) N, PRIORITY, READY @@ -238,7 +235,6 @@ def self.counts_by_priority_and_readiness connection.exec_query(query).to_a end - # rubocop:enable Metrics/MethodLength def self.genpop_priority_count query = <<-SQL @@ -284,7 +280,6 @@ def self.docket_date_of_nth_appeal_in_case_storage(row_number) connection.exec_query(sanitize_sql_array([query, row_number])).first["bfd19"].to_date end - # rubocop:disable Metrics/MethodLength def self.docket_counts_by_month query = <<-SQL select YEAR, MONTH, @@ -325,7 +320,6 @@ def self.docket_counts_by_month connection.exec_query(query) end - # rubocop:enable Metrics/MethodLength def self.age_of_n_oldest_genpop_priority_appeals(num) conn = connection @@ -343,21 +337,29 @@ def self.age_of_n_oldest_genpop_priority_appeals(num) # {UPDATE} def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) + priority_cdl_aod_query = generate_priority_case_distribution_lever_aod_query conn = connection query = <<-SQL #{SELECT_PRIORITY_APPEALS_ORDER_BY_BFD19} - where (VLJ = ? or #{ineligible_judges_sattyid_cache} or VLJ is null) - and rownum <= ? + where (VLJ = ? or #{ineligible_judges_sattyid_cache} or VLJ is null and (#{priority_cdl_aod_query}) SQL fmtd_query = sanitize_sql_array([ query, - judge.vacols_attorney_id, - num + judge.vacols_attorney_id ]) appeals = conn.exec_query(fmtd_query).to_a + + if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) + appeals.select { |appeal| appeal.appeal_affinity.affinity_start_date <= CaseDistributionLever.cavc_aod_affinity_days } + end + + appeals.sort_by { |a, b| a.bfd19 < b.bfd19 } + + appeals.first(num) # {Reestablishes the limit} + appeals.map { |appeal| appeal["bfd19"] } end @@ -452,7 +454,6 @@ def self.ready_to_distribute_appeals end # {UPDATE} - # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/ParameterLists, Metrics/MethodLength def self.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlog, dry_run = false) fail(DocketNumberCentennialLoop, COPY::MAX_LEGACY_DOCKET_NUMBER_ERROR_MESSAGE) if Time.zone.now.year >= 2030 @@ -497,11 +498,11 @@ def self.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlo distribute_appeals(fmtd_query, judge, dry_run) end - # rubocop:enable Metrics/ParameterLists, Metrics/MethodLength + # rubocop:enable # {UPDATE} - def self.distribute_priority_appeals(judge, genpop, _limit, dry_run = false) - priority_cdl_aod_query = generate_priority_case_distribution_lever_aod_query(judge) + def self.distribute_priority_appeals(judge, genpop, limit, dry_run = false) + priority_cdl_aod_query = generate_priority_case_distribution_lever_aod_query query = if use_by_docket_date? <<-SQL #{SELECT_PRIORITY_APPEALS_ORDER_BY_BFD19} @@ -510,7 +511,7 @@ def self.distribute_priority_appeals(judge, genpop, _limit, dry_run = false) else <<-SQL #{SELECT_PRIORITY_APPEALS} - where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) and #{priority_cdl_aod_query} or #{priority_cdl_query}) + where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?)) SQL end @@ -524,12 +525,12 @@ def self.distribute_priority_appeals(judge, genpop, _limit, dry_run = false) judge.vacols_attorney_id ]) - distribute_appeals(fmtd_query, judge, dry_run) + distribute_appeals(fmtd_query, judge, limit, dry_run) end - # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity + # rubocop:enable # :nocov: - def self.distribute_appeals(query, judge, dry_run) + def self.distribute_appeals(query, judge, limit, dry_run) conn = connection conn.transaction do @@ -541,6 +542,14 @@ def self.distribute_appeals(query, judge, dry_run) appeals = conn.exec_query(query).to_a return appeals if appeals.empty? + if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) # {Filters out appeals with affinity days older than the lever} + appeals.select { |appeal| appeal.appeal_affinity.affinity_start_date <= CaseDistributionLever.cavc_aod_affinity_days } + end + + appeals.sort_by { |a, b| a.bfd19 < b.bfd19 } # {Sorts by bfd19 date} + + appeals.first(limit) # {Reestablishes the limit} + vacols_ids = appeals.map { |appeal| appeal["bfkey"] } location = if FeatureToggle.enabled?(:legacy_das_deprecation, user: RequestStore.store[:current_user]) LegacyAppeal::LOCATION_CODES[:caseflow] @@ -558,13 +567,11 @@ def self.generate_priority_case_distribution_lever_aod_query # {Need to check for affinity_start_date on AMA DB is less than CaseDistributionLever.cavc_aod_affinity_days.days.ago} <<-SQL where (PREV_DECIDING_JUDGE = ? and AOD = '1' and BFAC = '7' ) - and rownum <= ? SQL elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite # {Need to make sure PREV_DECIDING_JUDGE is equal to the VLJ since it is infinite} <<-SQL where (PREV_DECIDING_JUDGE = ? and AOD = '1' and BFAC = '7') - and rownum <= ? SQL end end @@ -573,7 +580,6 @@ def self.use_by_docket_date? FeatureToggle.enabled?(:acd_distribute_by_docket_date, user: RequestStore.store[:current_user]) end - # rubocop:disable Metrics/MethodLength def self.ineligible_judges_sattyid_cache if FeatureToggle.enabled?(:acd_cases_tied_to_judges_no_longer_with_board) && !Rails.cache.fetch("case_distribution_ineligible_judges")&.pluck(:sattyid)&.reject(&:blank?).blank? @@ -600,7 +606,6 @@ def self.ineligible_judges_sattyid_cache "VLJ = 'false'" end end - # rubocop:enable Metrics/MethodLength def self.case_affinity_days_lever_value_is_selected?(lever_value) return false if lever_value == "omit" || lever_value == "infinite" @@ -608,4 +613,3 @@ def self.case_affinity_days_lever_value_is_selected?(lever_value) true end end -# rubocop:enable Metrics/ClassLength From a66f998264d72c49df96ad18e366251fc9d4afe9 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 28 May 2024 16:41:30 -0400 Subject: [PATCH 09/51] fixed sorting --- app/models/vacols/case_docket.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 06097db6c49..9aaee4da03b 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -356,7 +356,7 @@ def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) appeals.select { |appeal| appeal.appeal_affinity.affinity_start_date <= CaseDistributionLever.cavc_aod_affinity_days } end - appeals.sort_by { |a, b| a.bfd19 < b.bfd19 } + appeals.sort_by { appeal[:bfd19] } appeals.first(num) # {Reestablishes the limit} @@ -546,7 +546,7 @@ def self.distribute_appeals(query, judge, limit, dry_run) appeals.select { |appeal| appeal.appeal_affinity.affinity_start_date <= CaseDistributionLever.cavc_aod_affinity_days } end - appeals.sort_by { |a, b| a.bfd19 < b.bfd19 } # {Sorts by bfd19 date} + appeals.sort_by { appeal[:bfd19] } # {Sorts by bfd19 date} appeals.first(limit) # {Reestablishes the limit} From 31e3a384d27f6cc22295d2c508c49fe1d7bc2205 Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 29 May 2024 09:49:07 -0400 Subject: [PATCH 10/51] fixed rubocop issues --- app/models/vacols/case_docket.rb | 34 ++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 9aaee4da03b..e326127438f 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# rubocop:disable Metrics/ClassLength class VACOLS::CaseDocket < VACOLS::Record # :nocov: self.table_name = "brieff" @@ -205,6 +206,7 @@ class DocketNumberCentennialLoop < StandardError; end left join STAFF on APPEALS.VLJ = STAFF.STAFKEY order by BFD19 " + # rubocop:disable Metrics/MethodLength def self.counts_by_priority_and_readiness query = <<-SQL select count(*) N, PRIORITY, READY @@ -235,6 +237,7 @@ def self.counts_by_priority_and_readiness connection.exec_query(query).to_a end + # rubocop:enable Metrics/MethodLength def self.genpop_priority_count query = <<-SQL @@ -280,6 +283,7 @@ def self.docket_date_of_nth_appeal_in_case_storage(row_number) connection.exec_query(sanitize_sql_array([query, row_number])).first["bfd19"].to_date end + # rubocop:disable Metrics/MethodLength def self.docket_counts_by_month query = <<-SQL select YEAR, MONTH, @@ -320,6 +324,7 @@ def self.docket_counts_by_month connection.exec_query(query) end + # rubocop:enable Metrics/MethodLength def self.age_of_n_oldest_genpop_priority_appeals(num) conn = connection @@ -353,17 +358,18 @@ def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) appeals = conn.exec_query(fmtd_query).to_a if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) - appeals.select { |appeal| appeal.appeal_affinity.affinity_start_date <= CaseDistributionLever.cavc_aod_affinity_days } + appeals.select do |appeal| + appeal.appeal_affinity.affinity_start_date <= CaseDistributionLever.cavc_aod_affinity_days + end end appeals.sort_by { appeal[:bfd19] } - appeals.first(num) # {Reestablishes the limit} + appeals.first(num) unless num.nil? # {Reestablishes the limit} appeals.map { |appeal| appeal["bfd19"] } end - # {UPDATE} def self.age_of_n_oldest_nonpriority_appeals_available_to_judge(judge, num) conn = connection @@ -453,7 +459,7 @@ def self.ready_to_distribute_appeals connection.exec_query(fmtd_query).to_a end - # {UPDATE} + # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity def self.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlog, dry_run = false) fail(DocketNumberCentennialLoop, COPY::MAX_LEGACY_DOCKET_NUMBER_ERROR_MESSAGE) if Time.zone.now.year >= 2030 @@ -498,7 +504,6 @@ def self.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlo distribute_appeals(fmtd_query, judge, dry_run) end - # rubocop:enable # {UPDATE} def self.distribute_priority_appeals(judge, genpop, limit, dry_run = false) @@ -527,7 +532,6 @@ def self.distribute_priority_appeals(judge, genpop, limit, dry_run = false) distribute_appeals(fmtd_query, judge, limit, dry_run) end - # rubocop:enable # :nocov: def self.distribute_appeals(query, judge, limit, dry_run) @@ -542,13 +546,16 @@ def self.distribute_appeals(query, judge, limit, dry_run) appeals = conn.exec_query(query).to_a return appeals if appeals.empty? - if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) # {Filters out appeals with affinity days older than the lever} - appeals.select { |appeal| appeal.appeal_affinity.affinity_start_date <= CaseDistributionLever.cavc_aod_affinity_days } + # {Filters out appeals with affinity days older than the lever} + if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) + appeals.select do |appeal| + appeal.appeal_affinity.affinity_start_date <= CaseDistributionLever.cavc_aod_affinity_days + end end appeals.sort_by { appeal[:bfd19] } # {Sorts by bfd19 date} - appeals.first(limit) # {Reestablishes the limit} + appeals.first(limit) unless limit.nil? # {Reestablishes the limit} vacols_ids = appeals.map { |appeal| appeal["bfkey"] } location = if FeatureToggle.enabled?(:legacy_das_deprecation, user: RequestStore.store[:current_user]) @@ -562,9 +569,11 @@ def self.distribute_appeals(query, judge, limit, dry_run) end end + # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/ParameterLists + def self.generate_priority_case_distribution_lever_aod_query if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) - # {Need to check for affinity_start_date on AMA DB is less than CaseDistributionLever.cavc_aod_affinity_days.days.ago} + # {Need to check for affinity_start_date on AMA DB is <= CaseDistributionLever.cavc_aod_affinity_days.days.ago} <<-SQL where (PREV_DECIDING_JUDGE = ? and AOD = '1' and BFAC = '7' ) SQL @@ -580,6 +589,8 @@ def self.use_by_docket_date? FeatureToggle.enabled?(:acd_distribute_by_docket_date, user: RequestStore.store[:current_user]) end + # rubocop:disable Metrics/MethodLength + def self.ineligible_judges_sattyid_cache if FeatureToggle.enabled?(:acd_cases_tied_to_judges_no_longer_with_board) && !Rails.cache.fetch("case_distribution_ineligible_judges")&.pluck(:sattyid)&.reject(&:blank?).blank? @@ -607,9 +618,12 @@ def self.ineligible_judges_sattyid_cache end end + # rubocop:enable Metrics/MethodLength + def self.case_affinity_days_lever_value_is_selected?(lever_value) return false if lever_value == "omit" || lever_value == "infinite" true end end +# rubocop:enable Metrics/ClassLength From a75ba509bfa090b417141b7ee11d06dbaaf77952 Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 29 May 2024 12:25:20 -0400 Subject: [PATCH 11/51] updated filter method --- app/models/vacols/case_docket.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index e326127438f..19ee96939df 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -358,8 +358,12 @@ def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) appeals = conn.exec_query(fmtd_query).to_a if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) - appeals.select do |appeal| - appeal.appeal_affinity.affinity_start_date <= CaseDistributionLever.cavc_aod_affinity_days + appeals.reject do |appeal| + next if appeal["bfac"] != "7" + + (VACOLS::Case.find_by(bfkey: appeal["bfkey"]) + .appeal_affinity + .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago) end end @@ -546,10 +550,13 @@ def self.distribute_appeals(query, judge, limit, dry_run) appeals = conn.exec_query(query).to_a return appeals if appeals.empty? - # {Filters out appeals with affinity days older than the lever} if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) - appeals.select do |appeal| - appeal.appeal_affinity.affinity_start_date <= CaseDistributionLever.cavc_aod_affinity_days + appeals.reject do |appeal| + next if appeal["bfac"] != "7" + + (VACOLS::Case.find_by(bfkey: appeal["bfkey"]) + .appeal_affinity + .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago) end end From fa9080910cd942d75b56a319c94bc7281b1d1678 Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 29 May 2024 13:40:26 -0400 Subject: [PATCH 12/51] error handling --- app/models/vacols/case_docket.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 19ee96939df..fae74a579b5 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -367,7 +367,7 @@ def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) end end - appeals.sort_by { appeal[:bfd19] } + appeals.sort_by { appeal[:bfd19] } if use_by_docket_date? appeals.first(num) unless num.nil? # {Reestablishes the limit} @@ -472,7 +472,6 @@ def self.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlo #{SELECT_NONPRIORITY_APPEALS_ORDER_BY_BFD19} where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?)) and (DOCKET_INDEX <= ? or 1 = ?) - and rownum <= ? SQL else # Docket numbers begin with the two digit year. The Board of Veterans Appeals was created in 1930. @@ -492,7 +491,6 @@ def self.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlo #{SELECT_NONPRIORITY_APPEALS} where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?)) and (DOCKET_INDEX <= ? or 1 = ?) - and rownum <= ? SQL end @@ -502,11 +500,10 @@ def self.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlo (genpop == "any" || genpop == "not_genpop") ? 1 : 0, (genpop == "any" || genpop == "only_genpop") ? 1 : 0, range, - range.nil? ? 1 : 0, - limit + range.nil? ? 1 : 0 ]) - distribute_appeals(fmtd_query, judge, dry_run) + distribute_appeals(fmtd_query, judge, limit, dry_run) end # {UPDATE} @@ -560,7 +557,7 @@ def self.distribute_appeals(query, judge, limit, dry_run) end end - appeals.sort_by { appeal[:bfd19] } # {Sorts by bfd19 date} + appeals.sort_by { appeal[:bfd19] } if use_by_docket_date? appeals.first(limit) unless limit.nil? # {Reestablishes the limit} From d1fb2110b35a1007759e9fdb680bffdb1b0dd7e0 Mon Sep 17 00:00:00 2001 From: Calvin Date: Mon, 3 Jun 2024 10:15:08 -0400 Subject: [PATCH 13/51] added ineligibility to queries for PREV_DECIDING_JUDGE --- app/models/vacols/case_docket.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index fae74a579b5..2f8c27ad24d 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -579,12 +579,12 @@ def self.generate_priority_case_distribution_lever_aod_query if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) # {Need to check for affinity_start_date on AMA DB is <= CaseDistributionLever.cavc_aod_affinity_days.days.ago} <<-SQL - where (PREV_DECIDING_JUDGE = ? and AOD = '1' and BFAC = '7' ) + where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} and AOD = '1' and BFAC = '7' ) SQL elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite # {Need to make sure PREV_DECIDING_JUDGE is equal to the VLJ since it is infinite} <<-SQL - where (PREV_DECIDING_JUDGE = ? and AOD = '1' and BFAC = '7') + where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} and AOD = '1' and BFAC = '7') SQL end end @@ -595,7 +595,7 @@ def self.use_by_docket_date? # rubocop:disable Metrics/MethodLength - def self.ineligible_judges_sattyid_cache + def self.ineligible_judges_sattyid_cache(prev_deciding_judge = false) if FeatureToggle.enabled?(:acd_cases_tied_to_judges_no_longer_with_board) && !Rails.cache.fetch("case_distribution_ineligible_judges")&.pluck(:sattyid)&.reject(&:blank?).blank? list = Rails.cache.fetch("case_distribution_ineligible_judges")&.pluck(:sattyid)&.reject(&:blank?) @@ -612,11 +612,22 @@ def self.ineligible_judges_sattyid_cache vljs_strings = split_lists.flat_map do |k, v| base = "(#{v.join(', ')})" - base += " or VLJ in " unless k == split_lists.keys.last + if prev_deciding_judge + base += " or PREV_DECIDING_JUDGE in " unless k == split_lists.keys.last + else + base += " or VLJ in " unless k == split_lists.keys.last + end base end - "VLJ in #{vljs_strings.join}" + if prev_deciding_judge + "PREV_DECIDING_JUDGE in #{vljs_strings.join}" + else + "VLJ in #{vljs_strings.join}" + end + + elsif prev_deciding_judge + "PREV_DECIDING_JUDGE = 'false'" else "VLJ = 'false'" end From 8891f34c2762d14ac6f49cc8ab1b6538d02cc7a9 Mon Sep 17 00:00:00 2001 From: Calvin Date: Mon, 3 Jun 2024 12:38:38 -0400 Subject: [PATCH 14/51] fixed SQL query + added comments --- app/models/vacols/case_docket.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 2f8c27ad24d..2d093957301 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -347,11 +347,12 @@ def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) query = <<-SQL #{SELECT_PRIORITY_APPEALS_ORDER_BY_BFD19} - where (VLJ = ? or #{ineligible_judges_sattyid_cache} or VLJ is null and (#{priority_cdl_aod_query}) + where (VLJ = ? or #{ineligible_judges_sattyid_cache} or VLJ is null or (#{priority_cdl_aod_query})) SQL fmtd_query = sanitize_sql_array([ query, + judge.vacols_attorney_id, judge.vacols_attorney_id ]) @@ -512,12 +513,12 @@ def self.distribute_priority_appeals(judge, genpop, limit, dry_run = false) query = if use_by_docket_date? <<-SQL #{SELECT_PRIORITY_APPEALS_ORDER_BY_BFD19} - where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) and (#{priority_cdl_aod_query} or #{priority_cdl_query})) + where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) or #{priority_cdl_aod_query}) SQL else <<-SQL #{SELECT_PRIORITY_APPEALS} - where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?)) + where (((VLJ = ? or #{ineligible_judges_sattyid_cache}) and 1 = ?) or (VLJ is null and 1 = ?) or #{priority_cdl_aod_query}) SQL end @@ -577,7 +578,8 @@ def self.distribute_appeals(query, judge, limit, dry_run) def self.generate_priority_case_distribution_lever_aod_query if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) - # {Need to check for affinity_start_date on AMA DB is <= CaseDistributionLever.cavc_aod_affinity_days.days.ago} + # {Test to see if we need to add an "or PREV_DECIDING_JUDGE IS NULL" to the query} + # {Need to add exclude affinity check to query} <<-SQL where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} and AOD = '1' and BFAC = '7' ) SQL From 0a3edc8ce691a32f622fcb50cbeb3dea01572e0a Mon Sep 17 00:00:00 2001 From: Calvin Date: Mon, 3 Jun 2024 14:47:18 -0400 Subject: [PATCH 15/51] added exclude from affinity check into the case docket queries --- app/models/vacols/case_docket.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 2d093957301..2d429bdf825 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -581,12 +581,12 @@ def self.generate_priority_case_distribution_lever_aod_query # {Test to see if we need to add an "or PREV_DECIDING_JUDGE IS NULL" to the query} # {Need to add exclude affinity check to query} <<-SQL - where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} and AOD = '1' and BFAC = '7' ) + where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity} and AOD = '1' and BFAC = '7' ) SQL elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite # {Need to make sure PREV_DECIDING_JUDGE is equal to the VLJ since it is infinite} <<-SQL - where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} and AOD = '1' and BFAC = '7') + where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity} and AOD = '1' and BFAC = '7') SQL end end @@ -635,6 +635,16 @@ def self.ineligible_judges_sattyid_cache(prev_deciding_judge = false) end end + def self.vacols_judges_with_exclude_appeals_from_affinity + return "PREV_DECIDING_JUDGE in []" unless FeatureToggle.enabled?(:acd_exclude_from_affinity) + + satty_ids = VACOLS::Staff.where(sdomainid: JudgeTeam.active + .where(exclude_appeals_from_affinity: true) + .flat_map(&:judge).compact.pluck(:css_id)).pluck(:sattyid) + + "PREV_DECIDING_JUDGE in #{satty_ids}" + end + # rubocop:enable Metrics/MethodLength def self.case_affinity_days_lever_value_is_selected?(lever_value) From 14a9d635b80ecff380ecfd31913eb96fc7458a8c Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 5 Jun 2024 11:04:18 -0400 Subject: [PATCH 16/51] error handling + fixing sql queries --- app/models/vacols/case_docket.rb | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 2d429bdf825..ee9e69d296c 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -358,7 +358,7 @@ def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) appeals = conn.exec_query(fmtd_query).to_a - if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) + if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) appeals.reject do |appeal| next if appeal["bfac"] != "7" @@ -548,9 +548,10 @@ def self.distribute_appeals(query, judge, limit, dry_run) appeals = conn.exec_query(query).to_a return appeals if appeals.empty? - if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) + if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) appeals.reject do |appeal| - next if appeal["bfac"] != "7" + next if appeal["bfac"] != "7" || + !VACOLS::Case.find_by(bfkey: appeal["bfkey"])&.appeal_affinity&.affinity_start_date.nil? (VACOLS::Case.find_by(bfkey: appeal["bfkey"]) .appeal_affinity @@ -577,17 +578,13 @@ def self.distribute_appeals(query, judge, limit, dry_run) # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/ParameterLists def self.generate_priority_case_distribution_lever_aod_query - if case_affinity_days_lever_value_is_selected(CaseDistributionLever.cavc_aod_affinity_days) + if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) # {Test to see if we need to add an "or PREV_DECIDING_JUDGE IS NULL" to the query} # {Need to add exclude affinity check to query} - <<-SQL - where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity} and AOD = '1' and BFAC = '7' ) - SQL + "((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite # {Need to make sure PREV_DECIDING_JUDGE is equal to the VLJ since it is infinite} - <<-SQL - where (PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity} and AOD = '1' and BFAC = '7') - SQL + "((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" end end @@ -636,13 +633,13 @@ def self.ineligible_judges_sattyid_cache(prev_deciding_judge = false) end def self.vacols_judges_with_exclude_appeals_from_affinity - return "PREV_DECIDING_JUDGE in []" unless FeatureToggle.enabled?(:acd_exclude_from_affinity) + return "PREV_DECIDING_JUDGE in ()" unless FeatureToggle.enabled?(:acd_exclude_from_affinity) satty_ids = VACOLS::Staff.where(sdomainid: JudgeTeam.active .where(exclude_appeals_from_affinity: true) .flat_map(&:judge).compact.pluck(:css_id)).pluck(:sattyid) - "PREV_DECIDING_JUDGE in #{satty_ids}" + "PREV_DECIDING_JUDGE in (#{satty_ids.join(', ')})" end # rubocop:enable Metrics/MethodLength From ab4483a9673db3662946deef7c785bf51c359973 Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 5 Jun 2024 12:02:28 -0400 Subject: [PATCH 17/51] rejects appeals without affinity_start_dates and nonmatching judges --- app/models/vacols/case_docket.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index ee9e69d296c..b0d40006706 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -550,12 +550,15 @@ def self.distribute_appeals(query, judge, limit, dry_run) if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) appeals.reject do |appeal| - next if appeal["bfac"] != "7" || - !VACOLS::Case.find_by(bfkey: appeal["bfkey"])&.appeal_affinity&.affinity_start_date.nil? + next if appeal["bfac"] != "7" - (VACOLS::Case.find_by(bfkey: appeal["bfkey"]) - .appeal_affinity - .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago) + if VACOLS::Case.find_by(bfkey: appeal["bfkey"])&.appeal_affinity&.affinity_start_date.nil? + appeal["prev_deciding_judge"] != judge.vacols_attorney_id + else + VACOLS::Case.find_by(bfkey: appeal["bfkey"]) + .appeal_affinity + .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago + end end end From b6feb0e561449058a21f201735bd0d6f4a24fdad Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 5 Jun 2024 12:29:56 -0400 Subject: [PATCH 18/51] fixing rubocop offenses --- app/models/vacols/case_docket.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index b0d40006706..07ba315c9ff 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -340,7 +340,7 @@ def self.age_of_n_oldest_genpop_priority_appeals(num) appeals.map { |appeal| appeal["bfdloout"] } end - # {UPDATE} + # rubocop:disable Metrics/MethodLength def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) priority_cdl_aod_query = generate_priority_case_distribution_lever_aod_query conn = connection @@ -374,6 +374,7 @@ def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) appeals.map { |appeal| appeal["bfd19"] } end + # rubocop:enable Metrics/MethodLength def self.age_of_n_oldest_nonpriority_appeals_available_to_judge(judge, num) conn = connection @@ -507,7 +508,6 @@ def self.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlo distribute_appeals(fmtd_query, judge, limit, dry_run) end - # {UPDATE} def self.distribute_priority_appeals(judge, genpop, limit, dry_run = false) priority_cdl_aod_query = generate_priority_case_distribution_lever_aod_query query = if use_by_docket_date? @@ -534,8 +534,9 @@ def self.distribute_priority_appeals(judge, genpop, limit, dry_run = false) distribute_appeals(fmtd_query, judge, limit, dry_run) end - # :nocov: + # :nocov: + # rubocop:disable Metrics/AbcSize def self.distribute_appeals(query, judge, limit, dry_run) conn = connection @@ -583,11 +584,10 @@ def self.distribute_appeals(query, judge, limit, dry_run) def self.generate_priority_case_distribution_lever_aod_query if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) # {Test to see if we need to add an "or PREV_DECIDING_JUDGE IS NULL" to the query} - # {Need to add exclude affinity check to query} - "((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" + "((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" # rubocop:disable Layout/LineLength elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite # {Need to make sure PREV_DECIDING_JUDGE is equal to the VLJ since it is infinite} - "((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" + "((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" # rubocop:disable Layout/LineLength end end @@ -595,7 +595,7 @@ def self.use_by_docket_date? FeatureToggle.enabled?(:acd_distribute_by_docket_date, user: RequestStore.store[:current_user]) end - # rubocop:disable Metrics/MethodLength + # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity def self.ineligible_judges_sattyid_cache(prev_deciding_judge = false) if FeatureToggle.enabled?(:acd_cases_tied_to_judges_no_longer_with_board) && @@ -645,7 +645,7 @@ def self.vacols_judges_with_exclude_appeals_from_affinity "PREV_DECIDING_JUDGE in (#{satty_ids.join(', ')})" end - # rubocop:enable Metrics/MethodLength + # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity def self.case_affinity_days_lever_value_is_selected?(lever_value) return false if lever_value == "omit" || lever_value == "infinite" From b4bac6cbb3ab42885fe39dfb2801f04faf595b61 Mon Sep 17 00:00:00 2001 From: Calvin Date: Thu, 6 Jun 2024 14:27:29 -0400 Subject: [PATCH 19/51] fixed inconsistencies between methods --- app/models/vacols/case_docket.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 07ba315c9ff..205dc5e1c6f 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -340,14 +340,14 @@ def self.age_of_n_oldest_genpop_priority_appeals(num) appeals.map { |appeal| appeal["bfdloout"] } end - # rubocop:disable Metrics/MethodLength + # rubocop:disable Metrics/MethodLength, Metrics/AbcSize def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) priority_cdl_aod_query = generate_priority_case_distribution_lever_aod_query conn = connection query = <<-SQL #{SELECT_PRIORITY_APPEALS_ORDER_BY_BFD19} - where (VLJ = ? or #{ineligible_judges_sattyid_cache} or VLJ is null or (#{priority_cdl_aod_query})) + where (VLJ = ? or #{ineligible_judges_sattyid_cache} or VLJ is null or #{priority_cdl_aod_query}) SQL fmtd_query = sanitize_sql_array([ @@ -362,9 +362,13 @@ def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) appeals.reject do |appeal| next if appeal["bfac"] != "7" - (VACOLS::Case.find_by(bfkey: appeal["bfkey"]) - .appeal_affinity - .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago) + if VACOLS::Case.find_by(bfkey: appeal["bfkey"])&.appeal_affinity&.affinity_start_date.nil? + appeal["prev_deciding_judge"] != judge.vacols_attorney_id + else + VACOLS::Case.find_by(bfkey: appeal["bfkey"]) + .appeal_affinity + .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago + end end end @@ -374,7 +378,7 @@ def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) appeals.map { |appeal| appeal["bfd19"] } end - # rubocop:enable Metrics/MethodLength + # rubocop:enable Metrics/MethodLength, Metrics/AbcSize def self.age_of_n_oldest_nonpriority_appeals_available_to_judge(judge, num) conn = connection From 8c46d91afffe5f4d5884c2355c410420c4b4739d Mon Sep 17 00:00:00 2001 From: Calvin Date: Fri, 7 Jun 2024 12:48:23 -0400 Subject: [PATCH 20/51] fixed conditions for rejecting appeals --- app/models/vacols/case_docket.rb | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 205dc5e1c6f..3245fd2948b 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -340,7 +340,7 @@ def self.age_of_n_oldest_genpop_priority_appeals(num) appeals.map { |appeal| appeal["bfdloout"] } end - # rubocop:disable Metrics/MethodLength, Metrics/AbcSize + # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) priority_cdl_aod_query = generate_priority_case_distribution_lever_aod_query conn = connection @@ -359,20 +359,21 @@ def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) appeals = conn.exec_query(fmtd_query).to_a if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) - appeals.reject do |appeal| - next if appeal["bfac"] != "7" + appeals.reject! do |appeal| + next if appeal["bfac"] != "7" || appeal["aod"] != 1 if VACOLS::Case.find_by(bfkey: appeal["bfkey"])&.appeal_affinity&.affinity_start_date.nil? appeal["prev_deciding_judge"] != judge.vacols_attorney_id else - VACOLS::Case.find_by(bfkey: appeal["bfkey"]) + ((VACOLS::Case.find_by(bfkey: appeal["bfkey"]) .appeal_affinity - .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago + .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago) && + (appeal["prev_deciding_judge"] != judge.vacols_attorney_id)) end end end - appeals.sort_by { appeal[:bfd19] } if use_by_docket_date? + appeals.sort_by { |appeal| appeal[:bfd19] } if use_by_docket_date? appeals.first(num) unless num.nil? # {Reestablishes the limit} @@ -469,7 +470,7 @@ def self.ready_to_distribute_appeals connection.exec_query(fmtd_query).to_a end - # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity + # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists def self.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlog, dry_run = false) fail(DocketNumberCentennialLoop, COPY::MAX_LEGACY_DOCKET_NUMBER_ERROR_MESSAGE) if Time.zone.now.year >= 2030 @@ -554,20 +555,21 @@ def self.distribute_appeals(query, judge, limit, dry_run) return appeals if appeals.empty? if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) - appeals.reject do |appeal| - next if appeal["bfac"] != "7" + appeals.reject! do |appeal| + next if appeal["bfac"] != "7" || appeal["aod"] != 1 if VACOLS::Case.find_by(bfkey: appeal["bfkey"])&.appeal_affinity&.affinity_start_date.nil? appeal["prev_deciding_judge"] != judge.vacols_attorney_id else - VACOLS::Case.find_by(bfkey: appeal["bfkey"]) + ((VACOLS::Case.find_by(bfkey: appeal["bfkey"]) .appeal_affinity - .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago + .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago) && + (appeal["prev_deciding_judge"] != judge.vacols_attorney_id)) end end end - appeals.sort_by { appeal[:bfd19] } if use_by_docket_date? + appeals.sort_by { |appeal| appeal[:bfd19] } if use_by_docket_date? appeals.first(limit) unless limit.nil? # {Reestablishes the limit} From 284ad9ac9b462c5be69533b48b9446d8fff04823 Mon Sep 17 00:00:00 2001 From: Calvin Date: Fri, 7 Jun 2024 14:04:10 -0400 Subject: [PATCH 21/51] refactored cavc aod affinity filter to make it much easier to read --- app/models/vacols/case_docket.rb | 50 ++++++++++++++------------------ 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 3245fd2948b..a4ddadb043f 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -358,20 +358,7 @@ def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) appeals = conn.exec_query(fmtd_query).to_a - if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) - appeals.reject! do |appeal| - next if appeal["bfac"] != "7" || appeal["aod"] != 1 - - if VACOLS::Case.find_by(bfkey: appeal["bfkey"])&.appeal_affinity&.affinity_start_date.nil? - appeal["prev_deciding_judge"] != judge.vacols_attorney_id - else - ((VACOLS::Case.find_by(bfkey: appeal["bfkey"]) - .appeal_affinity - .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago) && - (appeal["prev_deciding_judge"] != judge.vacols_attorney_id)) - end - end - end + cavc_aod_affinity_filter(appeals, judge) appeals.sort_by { |appeal| appeal[:bfd19] } if use_by_docket_date? @@ -554,20 +541,7 @@ def self.distribute_appeals(query, judge, limit, dry_run) appeals = conn.exec_query(query).to_a return appeals if appeals.empty? - if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) - appeals.reject! do |appeal| - next if appeal["bfac"] != "7" || appeal["aod"] != 1 - - if VACOLS::Case.find_by(bfkey: appeal["bfkey"])&.appeal_affinity&.affinity_start_date.nil? - appeal["prev_deciding_judge"] != judge.vacols_attorney_id - else - ((VACOLS::Case.find_by(bfkey: appeal["bfkey"]) - .appeal_affinity - .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago) && - (appeal["prev_deciding_judge"] != judge.vacols_attorney_id)) - end - end - end + cavc_aod_affinity_filter(appeals, judge) appeals.sort_by { |appeal| appeal[:bfd19] } if use_by_docket_date? @@ -601,7 +575,25 @@ def self.use_by_docket_date? FeatureToggle.enabled?(:acd_distribute_by_docket_date, user: RequestStore.store[:current_user]) end - # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity + def self.cavc_aod_affinity_filter(appeals, judge) + if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) + appeals.reject! do |appeal| + next if (appeal["bfac"] != "7" || appeal["aod"] != 1) || + (appeal["prev_deciding_judge"] == judge.vacols_attorney_id) + + VACOLS::Case.find_by(bfkey: appeal["bfkey"])&.appeal_affinity&.affinity_start_date.nil? || + (VACOLS::Case.find_by(bfkey: appeal["bfkey"]) + .appeal_affinity + .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago) + end + elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite + appeals.reject! do |appeal| + next if appeal["bfac"] != "7" || appeal["aod"] != 1 + + appeal["prev_deciding_judge"] != judge.vacols_attorney_id + end + end + end def self.ineligible_judges_sattyid_cache(prev_deciding_judge = false) if FeatureToggle.enabled?(:acd_cases_tied_to_judges_no_longer_with_board) && From bb8089d2682e77c76c87be18ddbd97cac7649ca2 Mon Sep 17 00:00:00 2001 From: Calvin Date: Mon, 10 Jun 2024 13:10:13 -0400 Subject: [PATCH 22/51] refactored code to account for AC6 --- app/models/vacols/case_docket.rb | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index a4ddadb043f..62f42331856 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -576,29 +576,36 @@ def self.use_by_docket_date? end def self.cavc_aod_affinity_filter(appeals, judge) - if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) - appeals.reject! do |appeal| - next if (appeal["bfac"] != "7" || appeal["aod"] != 1) || - (appeal["prev_deciding_judge"] == judge.vacols_attorney_id) + appeals.reject! do |appeal| + next if (appeal["bfac"] != "7" || appeal["aod"] != 1) && + ((appeal["vlj"] && appeal["vlj"] == appeal["prev_deciding_judge"] && appeal["vlj"] == judge.vacols_attorney_id) || + (appeal["vlj"].nil? && appeal["prev_deciding_judge"].nil?)) + + if (appeal["vlj"] == appeal["prev_deciding_judge"]) && (appeal["vlj"] != judge.vacols_attorney_id) + return false if ineligible_judges_sattyids.includes?(appeal["vlj"]) + return true + end + + if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) VACOLS::Case.find_by(bfkey: appeal["bfkey"])&.appeal_affinity&.affinity_start_date.nil? || (VACOLS::Case.find_by(bfkey: appeal["bfkey"]) .appeal_affinity .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago) - end - elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite - appeals.reject! do |appeal| - next if appeal["bfac"] != "7" || appeal["aod"] != 1 - + elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite appeal["prev_deciding_judge"] != judge.vacols_attorney_id end end end + def self.ineligible_judges_sattyids + Rails.cache.fetch("case_distribution_ineligible_judges")&.pluck(:sattyid)&.reject(&:blank?) + end + def self.ineligible_judges_sattyid_cache(prev_deciding_judge = false) if FeatureToggle.enabled?(:acd_cases_tied_to_judges_no_longer_with_board) && - !Rails.cache.fetch("case_distribution_ineligible_judges")&.pluck(:sattyid)&.reject(&:blank?).blank? - list = Rails.cache.fetch("case_distribution_ineligible_judges")&.pluck(:sattyid)&.reject(&:blank?) + !ineligible_judges_sattyids.blank? + list = ineligible_judges_sattyids split_lists = {} num_of_lists = (list.size.to_f / 999).ceil From 13234da3990774e35993c955c3f9697ed0d4d037 Mon Sep 17 00:00:00 2001 From: Calvin Date: Mon, 10 Jun 2024 15:35:22 -0400 Subject: [PATCH 23/51] error handling for empty exclude from affinity --- app/models/vacols/case_docket.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 62f42331856..756ddcbd9c3 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -582,7 +582,7 @@ def self.cavc_aod_affinity_filter(appeals, judge) (appeal["vlj"].nil? && appeal["prev_deciding_judge"].nil?)) if (appeal["vlj"] == appeal["prev_deciding_judge"]) && (appeal["vlj"] != judge.vacols_attorney_id) - return false if ineligible_judges_sattyids.includes?(appeal["vlj"]) + return false if ineligible_judges_sattyids.include?(appeal["vlj"]) return true end @@ -641,13 +641,17 @@ def self.ineligible_judges_sattyid_cache(prev_deciding_judge = false) end def self.vacols_judges_with_exclude_appeals_from_affinity - return "PREV_DECIDING_JUDGE in ()" unless FeatureToggle.enabled?(:acd_exclude_from_affinity) + return "PREV_DECIDING_JUDGE = 'false'" unless FeatureToggle.enabled?(:acd_exclude_from_affinity) satty_ids = VACOLS::Staff.where(sdomainid: JudgeTeam.active .where(exclude_appeals_from_affinity: true) .flat_map(&:judge).compact.pluck(:css_id)).pluck(:sattyid) - "PREV_DECIDING_JUDGE in (#{satty_ids.join(', ')})" + if satty_ids.blank? + "PREV_DECIDING_JUDGE = 'false'" + else + "PREV_DECIDING_JUDGE = '(#{satty_ids.join(', ')})'" + end end # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity From 76accdafa47e5bc7828414e37c95e33c7566f27f Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 11 Jun 2024 01:57:41 -0400 Subject: [PATCH 24/51] reverted next if block to old logic to ensure it works --- app/models/vacols/case_docket.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 756ddcbd9c3..79f2e27da3a 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -577,9 +577,12 @@ def self.use_by_docket_date? def self.cavc_aod_affinity_filter(appeals, judge) appeals.reject! do |appeal| - next if (appeal["bfac"] != "7" || appeal["aod"] != 1) && - ((appeal["vlj"] && appeal["vlj"] == appeal["prev_deciding_judge"] && appeal["vlj"] == judge.vacols_attorney_id) || - (appeal["vlj"].nil? && appeal["prev_deciding_judge"].nil?)) + next if (appeal["bfac"] != "7" || appeal["aod"] != 1) || + (appeal["bfac"] == "7" && appeal["aod"] == 1 && + !appeal["vlj"].blank? && + appeal["vlj"] == appeal["prev_deciding_judge"] && + appeal["vlj"] == judge.vacols_attorney_id) || + (appeal["vlj"].nil? && appeal["prev_deciding_judge"].nil?) if (appeal["vlj"] == appeal["prev_deciding_judge"]) && (appeal["vlj"] != judge.vacols_attorney_id) return false if ineligible_judges_sattyids.include?(appeal["vlj"]) From fb1f96b6793667634d684f1d45728e3079335a01 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 11 Jun 2024 08:09:34 -0400 Subject: [PATCH 25/51] added PREV_DEC_JUDGE is not null --- app/models/vacols/case_docket.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 79f2e27da3a..90d3bde5285 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -564,7 +564,7 @@ def self.distribute_appeals(query, judge, limit, dry_run) def self.generate_priority_case_distribution_lever_aod_query if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) # {Test to see if we need to add an "or PREV_DECIDING_JUDGE IS NULL" to the query} - "((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" # rubocop:disable Layout/LineLength + "((PREV_DECIDING_JUDGE = ? or PREV_DECIDING_JUDGE is not null or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" # rubocop:disable Layout/LineLength elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite # {Need to make sure PREV_DECIDING_JUDGE is equal to the VLJ since it is infinite} "((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" # rubocop:disable Layout/LineLength @@ -585,9 +585,7 @@ def self.cavc_aod_affinity_filter(appeals, judge) (appeal["vlj"].nil? && appeal["prev_deciding_judge"].nil?) if (appeal["vlj"] == appeal["prev_deciding_judge"]) && (appeal["vlj"] != judge.vacols_attorney_id) - return false if ineligible_judges_sattyids.include?(appeal["vlj"]) - - return true + return false if ineligible_judges_sattyids&.include?(appeal["vlj"]) end if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) @@ -602,7 +600,7 @@ def self.cavc_aod_affinity_filter(appeals, judge) end def self.ineligible_judges_sattyids - Rails.cache.fetch("case_distribution_ineligible_judges")&.pluck(:sattyid)&.reject(&:blank?) + Rails.cache.fetch("case_distribution_ineligible_judges")&.pluck(:sattyid)&.reject(&:blank?) || [] end def self.ineligible_judges_sattyid_cache(prev_deciding_judge = false) From caa75913b136745daa52625095feb2abde2fac24 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 11 Jun 2024 09:07:39 -0400 Subject: [PATCH 26/51] case.rb factory changes --- spec/factories/vacols/case.rb | 74 +++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/spec/factories/vacols/case.rb b/spec/factories/vacols/case.rb index 6e19348a475..5e23df6c3b5 100644 --- a/spec/factories/vacols/case.rb +++ b/spec/factories/vacols/case.rb @@ -201,6 +201,7 @@ transient do judge { nil } attorney { nil } + aod { false } end bfmpro { "HIS" } @@ -243,23 +244,46 @@ file_number: vacols_case.correspondent.ssn ) - create( - :case, - bfdpdcn: vacols_case.bfddec, - bfac: "7", - bfcurloc: "81", - bfcorkey: vacols_case.bfcorkey, - bfcorlid: vacols_case.bfcorlid, - bfdnod: vacols_case.bfdnod, - bfdsoc: vacols_case.bfdsoc, - bfd19: vacols_case.bfd19, - bfmpro: "ACT", - correspondent: vacols_case.correspondent, - folder_number_equal: true, - original_case: vacols_case, - case_issues_equal: true, - original_case_issues: vacols_case.case_issues - ) + if evaluator.aod + create( + :case, + :aod, + :tied_to_previous_judge, + previous_tied_judge: User.find_by_css_id(evaluator.judge.sdomainid), + bfdpdcn: vacols_case.bfddec, + bfac: "7", + bfcurloc: "81", + bfcorkey: vacols_case.bfcorkey, + bfcorlid: vacols_case.bfcorlid, + bfdnod: vacols_case.bfdnod, + bfdsoc: vacols_case.bfdsoc, + bfd19: vacols_case.bfd19, + bfmpro: "ACT", + correspondent: vacols_case.correspondent, + folder_number_equal: true, + original_case: vacols_case, + case_issues_equal: true, + original_case_issues: vacols_case.case_issues + ) + else + create( + :case, + bfdpdcn: vacols_case.bfddec, + bfac: "7", + bfcurloc: "81", + bfcorkey: vacols_case.bfcorkey, + bfcorlid: vacols_case.bfcorlid, + bfdnod: vacols_case.bfdnod, + bfdsoc: vacols_case.bfdsoc, + bfd19: vacols_case.bfd19, + bfmpro: "ACT", + correspondent: vacols_case.correspondent, + folder_number_equal: true, + original_case: vacols_case, + case_issues_equal: true, + original_case_issues: vacols_case.case_issues + ) + end end end end @@ -295,6 +319,22 @@ end end + trait :tied_to_previous_judge do + transient do + previous_tied_judge { nil } + end + + after(:create) do |vacols_case, evaluator| + create( + :case_hearing, + :disposition_held, + folder_nr: vacols_case.bfkey, + hearing_date: 5.days.ago.to_date, + user: evaluator.previous_tied_judge + ) + end + end + trait :type_original do bfac { "1" } end From 544f20dfa7d9a7d6c1faa2d09e4afa1ccc48a4c1 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 11 Jun 2024 09:25:05 -0400 Subject: [PATCH 27/51] added more options to legacy_cavc_appeal creation --- spec/factories/vacols/case.rb | 84 +++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/spec/factories/vacols/case.rb b/spec/factories/vacols/case.rb index 5e23df6c3b5..a3699e8dd8f 100644 --- a/spec/factories/vacols/case.rb +++ b/spec/factories/vacols/case.rb @@ -202,6 +202,8 @@ judge { nil } attorney { nil } aod { false } + appeal_affinity { true } + affinity_start_date { 1.month.ago } end bfmpro { "HIS" } @@ -244,45 +246,49 @@ file_number: vacols_case.correspondent.ssn ) - if evaluator.aod - create( - :case, - :aod, - :tied_to_previous_judge, - previous_tied_judge: User.find_by_css_id(evaluator.judge.sdomainid), - bfdpdcn: vacols_case.bfddec, - bfac: "7", - bfcurloc: "81", - bfcorkey: vacols_case.bfcorkey, - bfcorlid: vacols_case.bfcorlid, - bfdnod: vacols_case.bfdnod, - bfdsoc: vacols_case.bfdsoc, - bfd19: vacols_case.bfd19, - bfmpro: "ACT", - correspondent: vacols_case.correspondent, - folder_number_equal: true, - original_case: vacols_case, - case_issues_equal: true, - original_case_issues: vacols_case.case_issues - ) - else - create( - :case, - bfdpdcn: vacols_case.bfddec, - bfac: "7", - bfcurloc: "81", - bfcorkey: vacols_case.bfcorkey, - bfcorlid: vacols_case.bfcorlid, - bfdnod: vacols_case.bfdnod, - bfdsoc: vacols_case.bfdsoc, - bfd19: vacols_case.bfd19, - bfmpro: "ACT", - correspondent: vacols_case.correspondent, - folder_number_equal: true, - original_case: vacols_case, - case_issues_equal: true, - original_case_issues: vacols_case.case_issues - ) + cavc_appeal = if evaluator.aod + create( + :case, + :aod, + :tied_to_previous_judge, + previous_tied_judge: User.find_by_css_id(evaluator.judge.sdomainid), + bfdpdcn: vacols_case.bfddec, + bfac: "7", + bfcurloc: "81", + bfcorkey: vacols_case.bfcorkey, + bfcorlid: vacols_case.bfcorlid, + bfdnod: vacols_case.bfdnod, + bfdsoc: vacols_case.bfdsoc, + bfd19: vacols_case.bfd19, + bfmpro: "ACT", + correspondent: vacols_case.correspondent, + folder_number_equal: true, + original_case: vacols_case, + case_issues_equal: true, + original_case_issues: vacols_case.case_issues + ) + else + create( + :case, + bfdpdcn: vacols_case.bfddec, + bfac: "7", + bfcurloc: "81", + bfcorkey: vacols_case.bfcorkey, + bfcorlid: vacols_case.bfcorlid, + bfdnod: vacols_case.bfdnod, + bfdsoc: vacols_case.bfdsoc, + bfd19: vacols_case.bfd19, + bfmpro: "ACT", + correspondent: vacols_case.correspondent, + folder_number_equal: true, + original_case: vacols_case, + case_issues_equal: true, + original_case_issues: vacols_case.case_issues + ) + end + + if evaluator.appeal_affinity + create(:appeal_affinity, appeal: cavc_appeal, affinity_start_date: evaluator.affinity_start_date) end end end From 17668d6fb201a969032cea88a70bc27dca93ccd3 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 11 Jun 2024 09:57:04 -0400 Subject: [PATCH 28/51] cleaned up code for simpler reading --- spec/factories/vacols/case.rb | 55 ++++++++++++++++------------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/spec/factories/vacols/case.rb b/spec/factories/vacols/case.rb index a3699e8dd8f..b9d8c958176 100644 --- a/spec/factories/vacols/case.rb +++ b/spec/factories/vacols/case.rb @@ -197,6 +197,10 @@ end end + # You can change the judge, attorney, AOD status, and Appeal Affinity of your Legacy CAVC Appeal. + # The Appeal_Affinity is default but the AOD must be toggled on. Example: + # "FactoryBot.create(:legacy_cavc_appeal, judge: judge, aod: true, affinity_start_date: 2.weeks.ago)" + factory :legacy_cavc_appeal do transient do judge { nil } @@ -246,46 +250,37 @@ file_number: vacols_case.correspondent.ssn ) + params = { + bfdpdcn: vacols_case.bfddec, + bfac: "7", + bfcurloc: "81", + bfcorkey: vacols_case.bfcorkey, + bfcorlid: vacols_case.bfcorlid, + bfdnod: vacols_case.bfdnod, + bfdsoc: vacols_case.bfdsoc, + bfd19: vacols_case.bfd19, + bfmpro: "ACT", + correspondent: vacols_case.correspondent, + folder_number_equal: true, + original_case: vacols_case, + case_issues_equal: true, + original_case_issues: vacols_case.case_issues + } + cavc_appeal = if evaluator.aod create( :case, :aod, :tied_to_previous_judge, - previous_tied_judge: User.find_by_css_id(evaluator.judge.sdomainid), - bfdpdcn: vacols_case.bfddec, - bfac: "7", - bfcurloc: "81", - bfcorkey: vacols_case.bfcorkey, - bfcorlid: vacols_case.bfcorlid, - bfdnod: vacols_case.bfdnod, - bfdsoc: vacols_case.bfdsoc, - bfd19: vacols_case.bfd19, - bfmpro: "ACT", - correspondent: vacols_case.correspondent, - folder_number_equal: true, - original_case: vacols_case, - case_issues_equal: true, - original_case_issues: vacols_case.case_issues + params, + previous_tied_judge: User.find_by_css_id(evaluator.judge.sdomainid) ) else create( :case, - bfdpdcn: vacols_case.bfddec, - bfac: "7", - bfcurloc: "81", - bfcorkey: vacols_case.bfcorkey, - bfcorlid: vacols_case.bfcorlid, - bfdnod: vacols_case.bfdnod, - bfdsoc: vacols_case.bfdsoc, - bfd19: vacols_case.bfd19, - bfmpro: "ACT", - correspondent: vacols_case.correspondent, - folder_number_equal: true, - original_case: vacols_case, - case_issues_equal: true, - original_case_issues: vacols_case.case_issues + params ) - end + end if evaluator.appeal_affinity create(:appeal_affinity, appeal: cavc_appeal, affinity_start_date: evaluator.affinity_start_date) From fc145745377bdde5bc1e6124c4683dd0fd5cc533 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 11 Jun 2024 10:51:40 -0400 Subject: [PATCH 29/51] fix for aod legacy cavc creation --- spec/factories/vacols/case.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/factories/vacols/case.rb b/spec/factories/vacols/case.rb index b9d8c958176..a037181bede 100644 --- a/spec/factories/vacols/case.rb +++ b/spec/factories/vacols/case.rb @@ -272,8 +272,7 @@ :case, :aod, :tied_to_previous_judge, - params, - previous_tied_judge: User.find_by_css_id(evaluator.judge.sdomainid) + params.merge!({ previous_tied_judge: User.find_by_css_id(evaluator.judge.sdomainid) }) ) else create( From 2248bda7bb1cd3d747fa009ad739844afb296e0f Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 11 Jun 2024 11:07:09 -0400 Subject: [PATCH 30/51] added tied to option to legacy cavc appeal factory --- spec/factories/vacols/case.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/spec/factories/vacols/case.rb b/spec/factories/vacols/case.rb index a037181bede..2bbe3f79aae 100644 --- a/spec/factories/vacols/case.rb +++ b/spec/factories/vacols/case.rb @@ -208,6 +208,7 @@ aod { false } appeal_affinity { true } affinity_start_date { 1.month.ago } + tied_to { true } end bfmpro { "HIS" } @@ -267,13 +268,25 @@ original_case_issues: vacols_case.case_issues } - cavc_appeal = if evaluator.aod + cavc_appeal = if evaluator.aod && evaluator.tied_to create( :case, :aod, :tied_to_previous_judge, params.merge!({ previous_tied_judge: User.find_by_css_id(evaluator.judge.sdomainid) }) ) + elsif evaluator.aod + create( + :case, + :aod, + params + ) + elsif evaluator.tied_to + create( + :case, + :tied_to_previous_judge, + params.merge!({ previous_tied_judge: User.find_by_css_id(evaluator.judge.sdomainid) }) + ) else create( :case, From 8c2802ecf5eddc0438c25726d1cbe281a8a75223 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 11 Jun 2024 12:31:02 -0400 Subject: [PATCH 31/51] limits are now handled correctly in query --- app/models/vacols/case_docket.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 90d3bde5285..f1f5393559a 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -362,7 +362,7 @@ def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) appeals.sort_by { |appeal| appeal[:bfd19] } if use_by_docket_date? - appeals.first(num) unless num.nil? # {Reestablishes the limit} + appeals = appeals.first(num) unless num.nil? # {Reestablishes the limit} appeals.map { |appeal| appeal["bfd19"] } end @@ -545,7 +545,7 @@ def self.distribute_appeals(query, judge, limit, dry_run) appeals.sort_by { |appeal| appeal[:bfd19] } if use_by_docket_date? - appeals.first(limit) unless limit.nil? # {Reestablishes the limit} + appeals = appeals.first(limit) unless limit.nil? # {Reestablishes the limit} vacols_ids = appeals.map { |appeal| appeal["bfkey"] } location = if FeatureToggle.enabled?(:legacy_das_deprecation, user: RequestStore.store[:current_user]) From 1e3003405bd91e312e5e64d1dd11fd61f4b49296 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 11 Jun 2024 16:05:55 -0400 Subject: [PATCH 32/51] replaced return false to next if, as return false was causing unexpected behavior --- app/models/vacols/case_docket.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index f1f5393559a..ae49c7a6895 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -585,9 +585,11 @@ def self.cavc_aod_affinity_filter(appeals, judge) (appeal["vlj"].nil? && appeal["prev_deciding_judge"].nil?) if (appeal["vlj"] == appeal["prev_deciding_judge"]) && (appeal["vlj"] != judge.vacols_attorney_id) - return false if ineligible_judges_sattyids&.include?(appeal["vlj"]) + next if ineligible_judges_sattyids&.include?(appeal["vlj"]) end + next if ineligible_judges_sattyids&.include?(appeal["prev_deciding_judge"]) + if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) VACOLS::Case.find_by(bfkey: appeal["bfkey"])&.appeal_affinity&.affinity_start_date.nil? || (VACOLS::Case.find_by(bfkey: appeal["bfkey"]) From c3b605739403cd9ebfc71e2e550c10485b88dd56 Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 12 Jun 2024 09:44:06 -0400 Subject: [PATCH 33/51] fix rspecs + one edge case --- app/models/vacols/case_docket.rb | 6 ++++-- spec/models/concerns/by_docket_date_distribution_spec.rb | 1 + spec/models/dockets/legacy_docket_spec.rb | 1 + spec/models/vacols/case_docket_spec.rb | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index ae49c7a6895..c9a3450eacb 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -580,11 +580,13 @@ def self.cavc_aod_affinity_filter(appeals, judge) next if (appeal["bfac"] != "7" || appeal["aod"] != 1) || (appeal["bfac"] == "7" && appeal["aod"] == 1 && !appeal["vlj"].blank? && - appeal["vlj"] == appeal["prev_deciding_judge"] && + (appeal["vlj"] == appeal["prev_deciding_judge"] || appeal["prev_deciding_judge"].nil?) && appeal["vlj"] == judge.vacols_attorney_id) || (appeal["vlj"].nil? && appeal["prev_deciding_judge"].nil?) - if (appeal["vlj"] == appeal["prev_deciding_judge"]) && (appeal["vlj"] != judge.vacols_attorney_id) + if !appeal["vlj"].blank? && + (appeal["vlj"] == appeal["prev_deciding_judge"] || appeal["prev_deciding_judge"].nil?) && + (appeal["vlj"] != judge.vacols_attorney_id) next if ineligible_judges_sattyids&.include?(appeal["vlj"]) end diff --git a/spec/models/concerns/by_docket_date_distribution_spec.rb b/spec/models/concerns/by_docket_date_distribution_spec.rb index e32a7807d18..3770faa79aa 100644 --- a/spec/models/concerns/by_docket_date_distribution_spec.rb +++ b/spec/models/concerns/by_docket_date_distribution_spec.rb @@ -20,6 +20,7 @@ def batch_size create(:case_distribution_lever, :batch_size_per_attorney) create(:case_distribution_lever, :ama_hearing_case_affinity_days) create(:case_distribution_lever, :ama_hearing_case_aod_affinity_days) + create(:case_distribution_lever, :cavc_aod_affinity_days) end # used to put {num} ambiguous objects into an array to mock the return array from requested_distribution diff --git a/spec/models/dockets/legacy_docket_spec.rb b/spec/models/dockets/legacy_docket_spec.rb index a3be1b7732f..9d550f2b82d 100644 --- a/spec/models/dockets/legacy_docket_spec.rb +++ b/spec/models/dockets/legacy_docket_spec.rb @@ -4,6 +4,7 @@ before do create(:case_distribution_lever, :request_more_cases_minimum) create(:case_distribution_lever, :nod_adjustment) + create(:case_distribution_lever, :cavc_aod_affinity_days) end let(:docket) do diff --git a/spec/models/vacols/case_docket_spec.rb b/spec/models/vacols/case_docket_spec.rb index 7ec250ed32e..82c89c54dc8 100644 --- a/spec/models/vacols/case_docket_spec.rb +++ b/spec/models/vacols/case_docket_spec.rb @@ -5,6 +5,7 @@ FeatureToggle.enable!(:test_facols) FeatureToggle.enable!(:acd_disable_legacy_lock_ready_appeals) FeatureToggle.enable!(:acd_distribute_by_docket_date) + create(:case_distribution_lever, :cavc_aod_affinity_days) end after do From 552423fa03cbe5159e84165212189a6afed81ee5 Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 12 Jun 2024 10:51:38 -0400 Subject: [PATCH 34/51] added cavc aod lever creation to rspecs --- spec/jobs/incomplete_distributions_job_spec.rb | 1 + spec/models/distribution_spec.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/spec/jobs/incomplete_distributions_job_spec.rb b/spec/jobs/incomplete_distributions_job_spec.rb index 5a027852712..a08a3b88792 100644 --- a/spec/jobs/incomplete_distributions_job_spec.rb +++ b/spec/jobs/incomplete_distributions_job_spec.rb @@ -11,6 +11,7 @@ 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, :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) diff --git a/spec/models/distribution_spec.rb b/spec/models/distribution_spec.rb index 7cd8f481721..5ed23a3e24e 100644 --- a/spec/models/distribution_spec.rb +++ b/spec/models/distribution_spec.rb @@ -15,6 +15,7 @@ create(:case_distribution_lever, :alternative_batch_size) create(:case_distribution_lever, :nod_adjustment) create(:case_distribution_lever, :cavc_affinity_days) + create(:case_distribution_lever, :cavc_aod_affinity_days) create(:case_distribution_lever, :ama_hearing_case_affinity_days) create(:case_distribution_lever, :ama_hearing_case_aod_affinity_days) end From 848a2e4bd1c2a60d707468bdae3cb78a8be47899 Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 12 Jun 2024 10:58:51 -0400 Subject: [PATCH 35/51] removed bfac and aod from nonpriority query --- app/models/vacols/case_docket.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index c9a3450eacb..8f496650f66 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -167,9 +167,9 @@ class DocketNumberCentennialLoop < StandardError; end " SELECT_NONPRIORITY_APPEALS_ORDER_BY_BFD19 = " - select BFKEY, BFD19, BFDLOOUT, BFAC, AOD, VLJ, DOCKET_INDEX, PREV_TYPE_ACTION, PREV_DECIDING_JUDGE + select BFKEY, BFD19, BFDLOOUT, VLJ, DOCKET_INDEX, PREV_TYPE_ACTION, PREV_DECIDING_JUDGE from ( - select BFKEY, BFD19, BFDLOOUT, BFAC, AOD, rownum DOCKET_INDEX, + select BFKEY, BFD19, BFDLOOUT, rownum DOCKET_INDEX, case when BFHINES is null or BFHINES <> 'GP' then VLJ_HEARINGS.VLJ end VLJ, PREV_APPEAL.PREV_TYPE_ACTION PREV_TYPE_ACTION, PREV_APPEAL.PREV_DECIDING_JUDGE PREV_DECIDING_JUDGE From d84f33df8b79c65184f7d0291ad60b647c18df8e Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 12 Jun 2024 14:22:40 -0400 Subject: [PATCH 36/51] cavc aod appeals w/excluded judges are now properly being filtered --- app/models/vacols/case_docket.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 8f496650f66..14f14d7b94e 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -577,6 +577,7 @@ def self.use_by_docket_date? def self.cavc_aod_affinity_filter(appeals, judge) appeals.reject! do |appeal| + # {will skip if not CAVC AOD || if CAVC AOD being distributed to tied_to judge || if not tied to any judge} next if (appeal["bfac"] != "7" || appeal["aod"] != 1) || (appeal["bfac"] == "7" && appeal["aod"] == 1 && !appeal["vlj"].blank? && @@ -584,15 +585,20 @@ def self.cavc_aod_affinity_filter(appeals, judge) appeal["vlj"] == judge.vacols_attorney_id) || (appeal["vlj"].nil? && appeal["prev_deciding_judge"].nil?) + # {if tied_to judge != judge being distributed to, we will skip if the judge is ineligible } if !appeal["vlj"].blank? && (appeal["vlj"] == appeal["prev_deciding_judge"] || appeal["prev_deciding_judge"].nil?) && (appeal["vlj"] != judge.vacols_attorney_id) next if ineligible_judges_sattyids&.include?(appeal["vlj"]) end - next if ineligible_judges_sattyids&.include?(appeal["prev_deciding_judge"]) + # {if deciding_judge is ineligible or excluded, we will skip} + next if ineligible_judges_sattyids&.include?(appeal["prev_deciding_judge"]) || + excluded_judges_sattyids&.include?(appeal["prev_deciding_judge"]) if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) + next if appeal["prev_deciding_judge"] == judge.vacols_attorney_id + VACOLS::Case.find_by(bfkey: appeal["bfkey"])&.appeal_affinity&.affinity_start_date.nil? || (VACOLS::Case.find_by(bfkey: appeal["bfkey"]) .appeal_affinity @@ -607,6 +613,12 @@ def self.ineligible_judges_sattyids Rails.cache.fetch("case_distribution_ineligible_judges")&.pluck(:sattyid)&.reject(&:blank?) || [] end + def self.excluded_judges_sattyids + VACOLS::Staff.where(sdomainid: JudgeTeam.active + .where(exclude_appeals_from_affinity: true) + .flat_map(&:judge).compact.pluck(:css_id))&.pluck(:sattyid) + end + def self.ineligible_judges_sattyid_cache(prev_deciding_judge = false) if FeatureToggle.enabled?(:acd_cases_tied_to_judges_no_longer_with_board) && !ineligible_judges_sattyids.blank? @@ -648,9 +660,7 @@ def self.ineligible_judges_sattyid_cache(prev_deciding_judge = false) def self.vacols_judges_with_exclude_appeals_from_affinity return "PREV_DECIDING_JUDGE = 'false'" unless FeatureToggle.enabled?(:acd_exclude_from_affinity) - satty_ids = VACOLS::Staff.where(sdomainid: JudgeTeam.active - .where(exclude_appeals_from_affinity: true) - .flat_map(&:judge).compact.pluck(:css_id)).pluck(:sattyid) + satty_ids = excluded_judges_sattyids if satty_ids.blank? "PREV_DECIDING_JUDGE = 'false'" From 84826c8bcc00f3d17f113a08737fe06f4002f7d5 Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 12 Jun 2024 14:42:37 -0400 Subject: [PATCH 37/51] refactored excluded judges check --- app/models/vacols/case_docket.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 14f14d7b94e..f562ce6d1ad 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -592,9 +592,10 @@ def self.cavc_aod_affinity_filter(appeals, judge) next if ineligible_judges_sattyids&.include?(appeal["vlj"]) end - # {if deciding_judge is ineligible or excluded, we will skip} + # {if deciding_judge is ineligible or excluded, we will skip, unless excluded deciding_judge = VLJ} next if ineligible_judges_sattyids&.include?(appeal["prev_deciding_judge"]) || - excluded_judges_sattyids&.include?(appeal["prev_deciding_judge"]) + (appeal["vlj"] != appeal["prev_deciding_judge"] && + excluded_judges_sattyids&.include?(appeal["prev_deciding_judge"])) if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) next if appeal["prev_deciding_judge"] == judge.vacols_attorney_id From 63dd83455ddd9c01d87d8aefcc0265e88793832b Mon Sep 17 00:00:00 2001 From: Calvin Date: Thu, 13 Jun 2024 00:42:15 -0400 Subject: [PATCH 38/51] added to old query to fix rspec errors --- app/models/vacols/case_docket.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index f562ce6d1ad..cae8c1f7697 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -122,16 +122,19 @@ class DocketNumberCentennialLoop < StandardError; end " SELECT_PRIORITY_APPEALS = " - select BFKEY, BFDLOOUT, VLJ + select BFKEY, BFDLOOUT, BFAC, AOD, VLJ, PREV_TYPE_ACTION, PREV_DECIDING_JUDGE from ( - select BFKEY, BFDLOOUT, - case when BFHINES is null or BFHINES <> 'GP' then VLJ_HEARINGS.VLJ end VLJ + select BFKEY, BFDLOOUT, BFAC, AOD, + case when BFHINES is null or BFHINES <> 'GP' then VLJ_HEARINGS.VLJ end VLJ, + PREV_APPEAL.PREV_TYPE_ACTION PREV_TYPE_ACTION, + PREV_APPEAL.PREV_DECIDING_JUDGE PREV_DECIDING_JUDGE from ( #{SELECT_READY_APPEALS} and (BFAC = '7' or AOD = '1') order by BFDLOOUT ) BRIEFF #{JOIN_ASSOCIATED_VLJS_BY_HEARINGS} + #{JOIN_PREVIOUS_APPEALS} ) " From a6f8397cd193c24664659608ff734221df30270b Mon Sep 17 00:00:00 2001 From: Calvin Date: Thu, 13 Jun 2024 11:16:00 -0400 Subject: [PATCH 39/51] modified case factory bot --- app/models/vacols/case_docket.rb | 11 ++++++++--- spec/factories/vacols/case.rb | 11 +++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index cae8c1f7697..b9b57186a33 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -584,15 +584,20 @@ def self.cavc_aod_affinity_filter(appeals, judge) next if (appeal["bfac"] != "7" || appeal["aod"] != 1) || (appeal["bfac"] == "7" && appeal["aod"] == 1 && !appeal["vlj"].blank? && - (appeal["vlj"] == appeal["prev_deciding_judge"] || appeal["prev_deciding_judge"].nil?) && + (appeal["vlj"] == appeal["prev_deciding_judge"]) && appeal["vlj"] == judge.vacols_attorney_id) || (appeal["vlj"].nil? && appeal["prev_deciding_judge"].nil?) # {if tied_to judge != judge being distributed to, we will skip if the judge is ineligible } if !appeal["vlj"].blank? && - (appeal["vlj"] == appeal["prev_deciding_judge"] || appeal["prev_deciding_judge"].nil?) && + (appeal["vlj"] == appeal["prev_deciding_judge"]) && (appeal["vlj"] != judge.vacols_attorney_id) - next if ineligible_judges_sattyids&.include?(appeal["vlj"]) + + if ineligible_judges_sattyids&.include?(appeal["vlj"]) + next + else + return true + end end # {if deciding_judge is ineligible or excluded, we will skip, unless excluded deciding_judge = VLJ} diff --git a/spec/factories/vacols/case.rb b/spec/factories/vacols/case.rb index 2bbe3f79aae..28fdd96b162 100644 --- a/spec/factories/vacols/case.rb +++ b/spec/factories/vacols/case.rb @@ -251,6 +251,17 @@ file_number: vacols_case.correspondent.ssn ) + if evaluator.tied_to + + create( + :case_hearing, + :disposition_held, + folder_nr: vacols_case.bfkey, + hearing_date: 5.days.ago.to_date, + user: User.find_by_css_id(evaluator.judge.sdomainid) + ) + end + params = { bfdpdcn: vacols_case.bfddec, bfac: "7", From a6eabb8e0e29075090ea17a5b0c2582589e713a0 Mon Sep 17 00:00:00 2001 From: Calvin Date: Thu, 13 Jun 2024 11:22:14 -0400 Subject: [PATCH 40/51] query now handles when prev_deciding_judge is nil --- app/models/vacols/case_docket.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index b9b57186a33..e3aca29ae83 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -584,13 +584,13 @@ def self.cavc_aod_affinity_filter(appeals, judge) next if (appeal["bfac"] != "7" || appeal["aod"] != 1) || (appeal["bfac"] == "7" && appeal["aod"] == 1 && !appeal["vlj"].blank? && - (appeal["vlj"] == appeal["prev_deciding_judge"]) && + (appeal["vlj"] == appeal["prev_deciding_judge"] || appeal["prev_deciding_judge"].nil?) && appeal["vlj"] == judge.vacols_attorney_id) || (appeal["vlj"].nil? && appeal["prev_deciding_judge"].nil?) # {if tied_to judge != judge being distributed to, we will skip if the judge is ineligible } if !appeal["vlj"].blank? && - (appeal["vlj"] == appeal["prev_deciding_judge"]) && + (appeal["vlj"] == appeal["prev_deciding_judge"] || appeal["prev_deciding_judge"].nil?) && (appeal["vlj"] != judge.vacols_attorney_id) if ineligible_judges_sattyids&.include?(appeal["vlj"]) From b1cf9f1c9a35697856ebd82693349222e1f1772e Mon Sep 17 00:00:00 2001 From: Calvin Date: Thu, 13 Jun 2024 11:43:46 -0400 Subject: [PATCH 41/51] removed unnecessary condition --- app/models/vacols/case_docket.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index e3aca29ae83..0222389795d 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -588,9 +588,9 @@ def self.cavc_aod_affinity_filter(appeals, judge) appeal["vlj"] == judge.vacols_attorney_id) || (appeal["vlj"].nil? && appeal["prev_deciding_judge"].nil?) - # {if tied_to judge != judge being distributed to, we will skip if the judge is ineligible } + # {if tied_to judge != judge being distributed to, we will skip if the judge is ineligible, reject if not} if !appeal["vlj"].blank? && - (appeal["vlj"] == appeal["prev_deciding_judge"] || appeal["prev_deciding_judge"].nil?) && + (appeal["vlj"] == appeal["prev_deciding_judge"]) && (appeal["vlj"] != judge.vacols_attorney_id) if ineligible_judges_sattyids&.include?(appeal["vlj"]) From 197dc505886e2bcd7f72e6b2effa6a9a4926f8a4 Mon Sep 17 00:00:00 2001 From: Calvin Date: Thu, 13 Jun 2024 12:19:48 -0400 Subject: [PATCH 42/51] fixed case factory to now have tied_to attatched to orig appeal --- spec/factories/vacols/case.rb | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/spec/factories/vacols/case.rb b/spec/factories/vacols/case.rb index 28fdd96b162..cf113bd6c0d 100644 --- a/spec/factories/vacols/case.rb +++ b/spec/factories/vacols/case.rb @@ -279,25 +279,12 @@ original_case_issues: vacols_case.case_issues } - cavc_appeal = if evaluator.aod && evaluator.tied_to - create( - :case, - :aod, - :tied_to_previous_judge, - params.merge!({ previous_tied_judge: User.find_by_css_id(evaluator.judge.sdomainid) }) - ) - elsif evaluator.aod + cavc_appeal = if evaluator.aod create( :case, :aod, params ) - elsif evaluator.tied_to - create( - :case, - :tied_to_previous_judge, - params.merge!({ previous_tied_judge: User.find_by_css_id(evaluator.judge.sdomainid) }) - ) else create( :case, From 9230db1b648d863fa3f3edac2f14bc5708268626 Mon Sep 17 00:00:00 2001 From: Calvin Date: Thu, 13 Jun 2024 14:03:29 -0400 Subject: [PATCH 43/51] fixed next if block within filter --- app/models/vacols/case_docket.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 0222389795d..61029d974f8 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -595,9 +595,9 @@ def self.cavc_aod_affinity_filter(appeals, judge) if ineligible_judges_sattyids&.include?(appeal["vlj"]) next - else - return true end + + (appeal["vlj"] != judge.vacols_attorney_id) end # {if deciding_judge is ineligible or excluded, we will skip, unless excluded deciding_judge = VLJ} From 072f511f8b2cc1589ed047f9db385ba163d84621 Mon Sep 17 00:00:00 2001 From: Calvin Date: Fri, 14 Jun 2024 06:06:37 -0400 Subject: [PATCH 44/51] handles omit scenarios + correctly rejects with next --- app/models/vacols/case_docket.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 61029d974f8..0fc506e6ecf 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -571,6 +571,8 @@ def self.generate_priority_case_distribution_lever_aod_query elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite # {Need to make sure PREV_DECIDING_JUDGE is equal to the VLJ since it is infinite} "((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" # rubocop:disable Layout/LineLength + else + "VLJ = ?" end end @@ -597,7 +599,7 @@ def self.cavc_aod_affinity_filter(appeals, judge) next end - (appeal["vlj"] != judge.vacols_attorney_id) + next (appeal["vlj"] != judge.vacols_attorney_id) end # {if deciding_judge is ineligible or excluded, we will skip, unless excluded deciding_judge = VLJ} From dd200decc71ac97a5b1dc12150c82ea1beebb254 Mon Sep 17 00:00:00 2001 From: Calvin Date: Fri, 14 Jun 2024 15:55:48 -0400 Subject: [PATCH 45/51] working on rspec (still failing) --- spec/factories/user.rb | 12 +++ spec/models/vacols/case_docket_spec.rb | 140 +++++++++++++++++++++++++ 2 files changed, 152 insertions(+) diff --git a/spec/factories/user.rb b/spec/factories/user.rb index ecb31b8b087..d8d4037d39b 100644 --- a/spec/factories/user.rb +++ b/spec/factories/user.rb @@ -56,6 +56,11 @@ roles { ["Hearing Prep"] } end + trait :judge_with_appeals_excluded_from_affinity do + with_appeals_excluded_from_affinity_judge_team + roles { ["Hearing Prep"] } + end + trait :ama_only_judge do after(:create) do |judge| JudgeTeam.for_judge(judge)&.update(ama_only_push: true, ama_only_request: true) || @@ -95,6 +100,13 @@ end end + trait :with_appeals_excluded_from_affinity_judge_team do + after(:create) do |judge| + judge_team = JudgeTeam.for_judge(judge) || JudgeTeam.create_for_judge(judge) + judge_team.update!(exclude_appeals_from_affinity: true) + end + end + trait :with_vacols_attorney_record do after(:create) do |user| create(:staff, :attorney_role, user: user) diff --git a/spec/models/vacols/case_docket_spec.rb b/spec/models/vacols/case_docket_spec.rb index 82c89c54dc8..aa6611cd14f 100644 --- a/spec/models/vacols/case_docket_spec.rb +++ b/spec/models/vacols/case_docket_spec.rb @@ -5,6 +5,8 @@ FeatureToggle.enable!(:test_facols) FeatureToggle.enable!(:acd_disable_legacy_lock_ready_appeals) FeatureToggle.enable!(:acd_distribute_by_docket_date) + FeatureToggle.enable!(:acd_cases_tied_to_judges_no_longer_with_board) + FeatureToggle.enable!(:acd_exclude_from_affinity) create(:case_distribution_lever, :cavc_aod_affinity_days) end @@ -721,6 +723,144 @@ end end end + + context "when CaseDistributionLever.cavc_affinity_days or CaseDistributionLever.cavc_aod_affinity_days lever is enabled" do + let(:limit) { 10 } + + let(:aff_judge_caseflow) { create(:user) } + let!(:aff_judge) { create(:staff, :judge_role, sdomainid: aff_judge_caseflow.css_id) } + + let(:other_judge_caseflow) { create(:user) } + let!(:other_judge) { create(:staff, :judge_role, sdomainid: other_judge_caseflow.css_id) } + + let(:tied_judge_caseflow) { create(:user) } + let!(:tied_judge) { create(:staff, :judge_role, sdomainid: tied_judge_caseflow.css_id) } + + let(:inel_judge_caseflow) { create(:user, :inactive) } + let!(:inel_judge) { create(:staff, :judge_role, svlj: "V", sdomainid: inel_judge_caseflow.css_id) } + + let(:excl_judge_caseflow) { create(:user, :judge_with_appeals_excluded_from_affinity) } + let!(:excl_judge) { create(:staff, :judge_role, sdomainid: excl_judge_caseflow.css_id) } + + let(:attorney_caseflow) { create(:user) } + let!(:attorney) { create(:staff, :attorney_role, sdomainid: attorney_caseflow.css_id) } + + # cavc affinity cases: + # no hearing held but has previous decision + let(:ca1) { create(:legacy_cavc_appeal, judge: aff_judge, attorney: attorney, aod: true, tied_to: false) } + let(:ca2) { create(:legacy_cavc_appeal, judge: aff_judge, attorney: attorney, aod: true, tied_to: false, affinity_start_date: 3.days.ago) } + let(:ca3) { create(:legacy_cavc_appeal, judge: aff_judge, attorney: attorney, aod: true, tied_to: false, appeal_affinity: false) } + # hearing held with previous decision where judge is not the same + let(:ca4) do + ca4 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true) + ca4.update!(bfmemid: aff_judge.sattyid) + ca4 + end + let(:ca5) do + ca5 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true, affinity_start_date: 3.days.ago) + ca5.update!(bfmemid: aff_judge.sattyid) + ca5 + end + let(:ca6) do + ca6 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true, appeal_affinity: false) + ca6.update!(bfmemid: aff_judge.sattyid) + ca6 + end + # hearing held with previous decision where judge is same (THIS IS TIED TO) + let(:ca7) { create(:legacy_cavc_appeal, judge: tied_judge, attorney: attorney, aod: true) } + let(:ca8) { create(:legacy_cavc_appeal, judge: tied_judge, attorney: attorney, aod: true, affinity_start_date: 3.days.ago) } + let(:ca9) { create(:legacy_cavc_appeal, judge: tied_judge, attorney: attorney, aod: true, appeal_affinity: false) } + # hearing held but no previous deciding judge + let(:ca10) do + ca10 = create(:legacy_cavc_appeal, judge: tied_judge, attorney: attorney, aod: true) + ca10.update!(bfmemid: nil) + ca10 + end + # no hearing held, no previous deciding judge + let(:ca11) do + ca11 = create(:legacy_cavc_appeal, judge: aff_judge, attorney: attorney, aod: true, tied_to: false) + ca11.update!(bfmemid: nil) + ca11 + end + # excluded judge cases: + # no hearing held but has previous decision + let(:ca12) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true, tied_to: false) } + let(:ca13) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true, tied_to: false, affinity_start_date: 3.days.ago) } + let(:ca14) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true, tied_to: false, appeal_affinity: false) } + # hearing held with previous decision where judge is not the same + let(:ca15) do + ca15 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true) + ca15.update!(bfmemid: excl_judge.sattyid) + ca15 + end + let(:ca16) do + ca16 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true, affinity_start_date: 3.days.ago) + ca16.update!(bfmemid: excl_judge.sattyid) + ca16 + end + let(:ca17) do + ca17 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true, appeal_affinity: false) + ca17.update!(bfmemid: excl_judge.sattyid) + ca17 + end + # hearing held with previous decision where judge is same (THIS IS TIED TO) + let(:ca18) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true) } + let(:ca19) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true, affinity_start_date: 3.days.ago) } + let(:ca20) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true, appeal_affinity: false) } + # ineligible judge cases: + # no hearing held but has previous decision + let(:ca21) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true, tied_to: false) } + let(:ca22) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true, tied_to: false, affinity_start_date: 3.days.ago) } + let(:ca23) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true, tied_to: false, appeal_affinity: false) } + # hearing held with previous decision where judge is not the same + let(:ca24) do + ca24 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true) + ca24.update!(bfmemid: inel_judge.sattyid) + ca24 + end + let(:ca25) do + ca25 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true, affinity_start_date: 3.days.ago) + ca25.update!(bfmemid: inel_judge.sattyid) + ca25 + end + let(:ca26) do + ca26 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true, appeal_affinity: false) + ca26.update!(bfmemid: inel_judge.sattyid) + ca26 + end + # hearing held with previous decision where judge is same (THIS IS TIED TO) + let(:ca27) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true) } + let(:ca28) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true, affinity_start_date: 3.days.ago) } + let(:ca29) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true, appeal_affinity: false) } + # hearing held but no previous deciding judge + let(:ca30) do + ca30 = create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true) + ca30.update!(bfmemid: nil) + ca30 + end + + it "distributes CAVC && CAVC AOD cases correctly based on lever value", :aggregate_failures do + IneligibleJudgesJob.new.perform_now + byebug + # {FOR LEVER HAVING A VALUE:} + CaseDistributionLever.find_by_item(Constants.DISTRIBUTION.cavc_aod_affinity_days).update!(value: 14) + VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true) + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca1, ca4, ca10, ca11].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca1, ca4, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca1, ca4, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + # {FOR LEVER BEING INFINITE:} + CaseDistributionLever.find_by_item(Constants.DISTRIBUTION.cavc_aod_affinity_days).update!(value: "infinite") + byebug + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca11].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca11, ca12, ca13, ca14, ca15, ca16, ca17].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + # {FOR LEVER BEING OMIT:} + CaseDistributionLever.find_by_item(Constants.DISTRIBUTION.cavc_aod_affinity_days).update!(value: "omit") + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca1, ca2, ca3, ca4, ca5, ca6, ca10, ca11].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca1, ca2, ca3, ca4, ca5, ca6, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca1, ca2, ca3, ca4, ca5, ca6, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + end + end end context "legacy_das_deprecation FeatureToggle enabled" do From cb049eb3ec6f4b18d81a3d053b0d8567d6bed839 Mon Sep 17 00:00:00 2001 From: Calvin Date: Mon, 17 Jun 2024 12:17:03 -0400 Subject: [PATCH 46/51] fix for ineligble VLJ when infinite --- app/models/vacols/case_docket.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 0fc506e6ecf..e8d18972a26 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -615,6 +615,8 @@ def self.cavc_aod_affinity_filter(appeals, judge) .appeal_affinity .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago) elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite + next if ineligible_judges_sattyids&.include?(appeal["vlj"]) + appeal["prev_deciding_judge"] != judge.vacols_attorney_id end end From ae9d32f0feb580d7db6c269f0322e265449bfeee Mon Sep 17 00:00:00 2001 From: Calvin Date: Mon, 17 Jun 2024 13:56:22 -0400 Subject: [PATCH 47/51] fixed rspec suite for cavc aod filters --- spec/models/vacols/case_docket_spec.rb | 81 ++++++++++++-------------- 1 file changed, 37 insertions(+), 44 deletions(-) diff --git a/spec/models/vacols/case_docket_spec.rb b/spec/models/vacols/case_docket_spec.rb index aa6611cd14f..bb8f7f9ece8 100644 --- a/spec/models/vacols/case_docket_spec.rb +++ b/spec/models/vacols/case_docket_spec.rb @@ -725,7 +725,9 @@ end context "when CaseDistributionLever.cavc_affinity_days or CaseDistributionLever.cavc_aod_affinity_days lever is enabled" do - let(:limit) { 10 } + before do + VACOLS::Case.where(bfcurloc: %w[81 83]).map { |c| c.update!(bfcurloc: "testing") } + end let(:aff_judge_caseflow) { create(:user) } let!(:aff_judge) { create(:staff, :judge_role, sdomainid: aff_judge_caseflow.css_id) } @@ -736,7 +738,7 @@ let(:tied_judge_caseflow) { create(:user) } let!(:tied_judge) { create(:staff, :judge_role, sdomainid: tied_judge_caseflow.css_id) } - let(:inel_judge_caseflow) { create(:user, :inactive) } + let(:inel_judge_caseflow) { create(:user) } let!(:inel_judge) { create(:staff, :judge_role, svlj: "V", sdomainid: inel_judge_caseflow.css_id) } let(:excl_judge_caseflow) { create(:user, :judge_with_appeals_excluded_from_affinity) } @@ -747,93 +749,93 @@ # cavc affinity cases: # no hearing held but has previous decision - let(:ca1) { create(:legacy_cavc_appeal, judge: aff_judge, attorney: attorney, aod: true, tied_to: false) } - let(:ca2) { create(:legacy_cavc_appeal, judge: aff_judge, attorney: attorney, aod: true, tied_to: false, affinity_start_date: 3.days.ago) } - let(:ca3) { create(:legacy_cavc_appeal, judge: aff_judge, attorney: attorney, aod: true, tied_to: false, appeal_affinity: false) } + let!(:ca1) { create(:legacy_cavc_appeal, judge: aff_judge, attorney: attorney, aod: true, tied_to: false) } + let!(:ca2) { create(:legacy_cavc_appeal, judge: aff_judge, attorney: attorney, aod: true, tied_to: false, affinity_start_date: 3.days.ago) } + let!(:ca3) { create(:legacy_cavc_appeal, judge: aff_judge, attorney: attorney, aod: true, tied_to: false, appeal_affinity: false) } # hearing held with previous decision where judge is not the same - let(:ca4) do + let!(:ca4) do ca4 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true) ca4.update!(bfmemid: aff_judge.sattyid) ca4 end - let(:ca5) do + let!(:ca5) do ca5 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true, affinity_start_date: 3.days.ago) ca5.update!(bfmemid: aff_judge.sattyid) ca5 end - let(:ca6) do + let!(:ca6) do ca6 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true, appeal_affinity: false) ca6.update!(bfmemid: aff_judge.sattyid) ca6 end # hearing held with previous decision where judge is same (THIS IS TIED TO) - let(:ca7) { create(:legacy_cavc_appeal, judge: tied_judge, attorney: attorney, aod: true) } - let(:ca8) { create(:legacy_cavc_appeal, judge: tied_judge, attorney: attorney, aod: true, affinity_start_date: 3.days.ago) } - let(:ca9) { create(:legacy_cavc_appeal, judge: tied_judge, attorney: attorney, aod: true, appeal_affinity: false) } + let!(:ca7) { create(:legacy_cavc_appeal, judge: tied_judge, attorney: attorney, aod: true) } + let!(:ca8) { create(:legacy_cavc_appeal, judge: tied_judge, attorney: attorney, aod: true, affinity_start_date: 3.days.ago) } + let!(:ca9) { create(:legacy_cavc_appeal, judge: tied_judge, attorney: attorney, aod: true, appeal_affinity: false) } # hearing held but no previous deciding judge - let(:ca10) do + let!(:ca10) do ca10 = create(:legacy_cavc_appeal, judge: tied_judge, attorney: attorney, aod: true) ca10.update!(bfmemid: nil) ca10 end # no hearing held, no previous deciding judge - let(:ca11) do + let!(:ca11) do ca11 = create(:legacy_cavc_appeal, judge: aff_judge, attorney: attorney, aod: true, tied_to: false) ca11.update!(bfmemid: nil) ca11 end # excluded judge cases: # no hearing held but has previous decision - let(:ca12) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true, tied_to: false) } - let(:ca13) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true, tied_to: false, affinity_start_date: 3.days.ago) } - let(:ca14) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true, tied_to: false, appeal_affinity: false) } + let!(:ca12) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true, tied_to: false) } + let!(:ca13) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true, tied_to: false, affinity_start_date: 3.days.ago) } + let!(:ca14) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true, tied_to: false, appeal_affinity: false) } # hearing held with previous decision where judge is not the same - let(:ca15) do + let!(:ca15) do ca15 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true) ca15.update!(bfmemid: excl_judge.sattyid) ca15 end - let(:ca16) do + let!(:ca16) do ca16 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true, affinity_start_date: 3.days.ago) ca16.update!(bfmemid: excl_judge.sattyid) ca16 end - let(:ca17) do + let!(:ca17) do ca17 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true, appeal_affinity: false) ca17.update!(bfmemid: excl_judge.sattyid) ca17 end # hearing held with previous decision where judge is same (THIS IS TIED TO) - let(:ca18) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true) } - let(:ca19) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true, affinity_start_date: 3.days.ago) } - let(:ca20) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true, appeal_affinity: false) } + let!(:ca18) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true) } + let!(:ca19) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true, affinity_start_date: 3.days.ago) } + let!(:ca20) { create(:legacy_cavc_appeal, judge: excl_judge, attorney: attorney, aod: true, appeal_affinity: false) } # ineligible judge cases: # no hearing held but has previous decision - let(:ca21) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true, tied_to: false) } - let(:ca22) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true, tied_to: false, affinity_start_date: 3.days.ago) } - let(:ca23) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true, tied_to: false, appeal_affinity: false) } + let!(:ca21) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true, tied_to: false) } + let!(:ca22) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true, tied_to: false, affinity_start_date: 3.days.ago) } + let!(:ca23) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true, tied_to: false, appeal_affinity: false) } # hearing held with previous decision where judge is not the same - let(:ca24) do + let!(:ca24) do ca24 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true) ca24.update!(bfmemid: inel_judge.sattyid) ca24 end - let(:ca25) do + let!(:ca25) do ca25 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true, affinity_start_date: 3.days.ago) ca25.update!(bfmemid: inel_judge.sattyid) ca25 end - let(:ca26) do + let!(:ca26) do ca26 = create(:legacy_cavc_appeal, judge: other_judge, attorney: attorney, aod: true, appeal_affinity: false) ca26.update!(bfmemid: inel_judge.sattyid) ca26 end # hearing held with previous decision where judge is same (THIS IS TIED TO) - let(:ca27) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true) } - let(:ca28) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true, affinity_start_date: 3.days.ago) } - let(:ca29) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true, appeal_affinity: false) } + let!(:ca27) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true) } + let!(:ca28) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true, affinity_start_date: 3.days.ago) } + let!(:ca29) { create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true, appeal_affinity: false) } # hearing held but no previous deciding judge - let(:ca30) do + let!(:ca30) do ca30 = create(:legacy_cavc_appeal, judge: inel_judge, attorney: attorney, aod: true) ca30.update!(bfmemid: nil) ca30 @@ -841,24 +843,15 @@ it "distributes CAVC && CAVC AOD cases correctly based on lever value", :aggregate_failures do IneligibleJudgesJob.new.perform_now - byebug # {FOR LEVER HAVING A VALUE:} CaseDistributionLever.find_by_item(Constants.DISTRIBUTION.cavc_aod_affinity_days).update!(value: 14) - VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true) - expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca1, ca4, ca10, ca11].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) - expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca1, ca4, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) - expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca1, ca4, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to match_array([ca1, ca4, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) # {FOR LEVER BEING INFINITE:} CaseDistributionLever.find_by_item(Constants.DISTRIBUTION.cavc_aod_affinity_days).update!(value: "infinite") - byebug - expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca11].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) - expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca11, ca12, ca13, ca14, ca15, ca16, ca17].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) - expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to match_array([ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) # {FOR LEVER BEING OMIT:} CaseDistributionLever.find_by_item(Constants.DISTRIBUTION.cavc_aod_affinity_days).update!(value: "omit") - expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca1, ca2, ca3, ca4, ca5, ca6, ca10, ca11].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) - expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca1, ca2, ca3, ca4, ca5, ca6, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) - expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to eq([ca1, ca2, ca3, ca4, ca5, ca6, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to match_array([ca1, ca2, ca3, ca4, ca5, ca6, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) end end end From e61bcec8169c9f23ca22b0a964dd3fffe20c9268 Mon Sep 17 00:00:00 2001 From: Calvin Date: Mon, 17 Jun 2024 13:58:03 -0400 Subject: [PATCH 48/51] fixed omit scenario in cavc aod affinity filter --- app/models/vacols/case_docket.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index e8d18972a26..f5ac496b3f3 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -537,7 +537,11 @@ def self.distribute_appeals(query, judge, limit, dry_run) conn.transaction do if dry_run - conn.exec_query(query).to_a + appeals = conn.exec_query(query).to_a + + cavc_aod_affinity_filter(appeals, judge) + + appeals else conn.execute(LOCK_READY_APPEALS) unless FeatureToggle.enabled?(:acd_disable_legacy_lock_ready_appeals) @@ -565,12 +569,12 @@ def self.distribute_appeals(query, judge, limit, dry_run) # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/ParameterLists def self.generate_priority_case_distribution_lever_aod_query - if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) + if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) || CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.omit # {Test to see if we need to add an "or PREV_DECIDING_JUDGE IS NULL" to the query} - "((PREV_DECIDING_JUDGE = ? or PREV_DECIDING_JUDGE is not null or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" # rubocop:disable Layout/LineLength + "((PREV_DECIDING_JUDGE = ? or PREV_DECIDING_JUDGE is null or PREV_DECIDING_JUDGE is not null or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite # {Need to make sure PREV_DECIDING_JUDGE is equal to the VLJ since it is infinite} - "((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" # rubocop:disable Layout/LineLength + "((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" else "VLJ = ?" end @@ -618,6 +622,8 @@ def self.cavc_aod_affinity_filter(appeals, judge) next if ineligible_judges_sattyids&.include?(appeal["vlj"]) appeal["prev_deciding_judge"] != judge.vacols_attorney_id + elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.omit + appeal["prev_deciding_judge"] == appeal["vlj"] end end end @@ -678,7 +684,7 @@ def self.vacols_judges_with_exclude_appeals_from_affinity if satty_ids.blank? "PREV_DECIDING_JUDGE = 'false'" else - "PREV_DECIDING_JUDGE = '(#{satty_ids.join(', ')})'" + "PREV_DECIDING_JUDGE in (#{satty_ids.join(', ')})" end end From 897a3e04537e4ca7cfe7065bff7dc8f9202ef263 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 18 Jun 2024 11:30:24 -0400 Subject: [PATCH 49/51] consolidation & readability refactor --- app/models/vacols/case_docket.rb | 83 +++++++++++++++++++------------- 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index f5ac496b3f3..6bd6cd4b6d2 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -343,7 +343,7 @@ def self.age_of_n_oldest_genpop_priority_appeals(num) appeals.map { |appeal| appeal["bfdloout"] } end - # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity + # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) priority_cdl_aod_query = generate_priority_case_distribution_lever_aod_query conn = connection @@ -369,7 +369,7 @@ def self.age_of_n_oldest_priority_appeals_available_to_judge(judge, num) appeals.map { |appeal| appeal["bfd19"] } end - # rubocop:enable Metrics/MethodLength, Metrics/AbcSize + # rubocop:enable def self.age_of_n_oldest_nonpriority_appeals_available_to_judge(judge, num) conn = connection @@ -569,12 +569,13 @@ def self.distribute_appeals(query, judge, limit, dry_run) # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/ParameterLists def self.generate_priority_case_distribution_lever_aod_query - if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) || CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.omit - # {Test to see if we need to add an "or PREV_DECIDING_JUDGE IS NULL" to the query} - "((PREV_DECIDING_JUDGE = ? or PREV_DECIDING_JUDGE is null or PREV_DECIDING_JUDGE is not null or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" + if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) || + CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.omit + "((PREV_DECIDING_JUDGE = ? or PREV_DECIDING_JUDGE is null or PREV_DECIDING_JUDGE is not null) + and AOD = '1' and BFAC = '7' )" elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite - # {Need to make sure PREV_DECIDING_JUDGE is equal to the VLJ since it is infinite} - "((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" + "((PREV_DECIDING_JUDGE = ? or #{ineligible_judges_sattyid_cache(true)} or + #{vacols_judges_with_exclude_appeals_from_affinity}) and AOD = '1' and BFAC = '7' )" else "VLJ = ?" end @@ -584,40 +585,24 @@ def self.use_by_docket_date? FeatureToggle.enabled?(:acd_distribute_by_docket_date, user: RequestStore.store[:current_user]) end + # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity def self.cavc_aod_affinity_filter(appeals, judge) appeals.reject! do |appeal| # {will skip if not CAVC AOD || if CAVC AOD being distributed to tied_to judge || if not tied to any judge} - next if (appeal["bfac"] != "7" || appeal["aod"] != 1) || - (appeal["bfac"] == "7" && appeal["aod"] == 1 && - !appeal["vlj"].blank? && - (appeal["vlj"] == appeal["prev_deciding_judge"] || appeal["prev_deciding_judge"].nil?) && - appeal["vlj"] == judge.vacols_attorney_id) || - (appeal["vlj"].nil? && appeal["prev_deciding_judge"].nil?) - - # {if tied_to judge != judge being distributed to, we will skip if the judge is ineligible, reject if not} - if !appeal["vlj"].blank? && - (appeal["vlj"] == appeal["prev_deciding_judge"]) && - (appeal["vlj"] != judge.vacols_attorney_id) - - if ineligible_judges_sattyids&.include?(appeal["vlj"]) - next - end + next if tied_to_or_not_cavc_aod?(appeal, judge) + + if not_distributing_to_tied_judge?(appeal, judge) + next if ineligible_judges_sattyids&.include?(appeal["vlj"]) next (appeal["vlj"] != judge.vacols_attorney_id) end - # {if deciding_judge is ineligible or excluded, we will skip, unless excluded deciding_judge = VLJ} - next if ineligible_judges_sattyids&.include?(appeal["prev_deciding_judge"]) || - (appeal["vlj"] != appeal["prev_deciding_judge"] && - excluded_judges_sattyids&.include?(appeal["prev_deciding_judge"])) + next if ineligible_or_excluded_deciding_judge?(appeal) if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days) next if appeal["prev_deciding_judge"] == judge.vacols_attorney_id - VACOLS::Case.find_by(bfkey: appeal["bfkey"])&.appeal_affinity&.affinity_start_date.nil? || - (VACOLS::Case.find_by(bfkey: appeal["bfkey"]) - .appeal_affinity - .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago) + reject_due_to_affinity?(appeal) elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite next if ineligible_judges_sattyids&.include?(appeal["vlj"]) @@ -628,6 +613,37 @@ def self.cavc_aod_affinity_filter(appeals, judge) end end + def self.tied_to_or_not_cavc_aod?(appeal, judge) + (appeal["bfac"] != "7" || appeal["aod"] != 1) || + (appeal["bfac"] == "7" && appeal["aod"] == 1 && + !appeal["vlj"].blank? && + (appeal["vlj"] == appeal["prev_deciding_judge"] || appeal["prev_deciding_judge"].nil?) && + appeal["vlj"] == judge.vacols_attorney_id) || + (appeal["vlj"].nil? && appeal["prev_deciding_judge"].nil?) + end + + # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity + + def self.not_distributing_to_tied_judge?(appeal, judge) + !appeal["vlj"].blank? && + (appeal["vlj"] == appeal["prev_deciding_judge"]) && + (appeal["vlj"] != judge.vacols_attorney_id) + end + + def self.ineligible_or_excluded_deciding_judge?(appeal) + # {if deciding_judge is ineligible or excluded, we will skip, unless excluded deciding_judge = VLJ} + ineligible_judges_sattyids&.include?(appeal["prev_deciding_judge"]) || + (appeal["vlj"] != appeal["prev_deciding_judge"] && + excluded_judges_sattyids&.include?(appeal["prev_deciding_judge"])) + end + + def self.reject_due_to_affinity?(appeal) + VACOLS::Case.find_by(bfkey: appeal["bfkey"])&.appeal_affinity&.affinity_start_date.nil? || + (VACOLS::Case.find_by(bfkey: appeal["bfkey"]) + .appeal_affinity + .affinity_start_date > CaseDistributionLever.cavc_aod_affinity_days.to_i.days.ago) + end + def self.ineligible_judges_sattyids Rails.cache.fetch("case_distribution_ineligible_judges")&.pluck(:sattyid)&.reject(&:blank?) || [] end @@ -638,6 +654,7 @@ def self.excluded_judges_sattyids .flat_map(&:judge).compact.pluck(:css_id))&.pluck(:sattyid) end + # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength def self.ineligible_judges_sattyid_cache(prev_deciding_judge = false) if FeatureToggle.enabled?(:acd_cases_tied_to_judges_no_longer_with_board) && !ineligible_judges_sattyids.blank? @@ -676,6 +693,8 @@ def self.ineligible_judges_sattyid_cache(prev_deciding_judge = false) end end + # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength + def self.vacols_judges_with_exclude_appeals_from_affinity return "PREV_DECIDING_JUDGE = 'false'" unless FeatureToggle.enabled?(:acd_exclude_from_affinity) @@ -688,12 +707,10 @@ def self.vacols_judges_with_exclude_appeals_from_affinity end end - # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity - def self.case_affinity_days_lever_value_is_selected?(lever_value) return false if lever_value == "omit" || lever_value == "infinite" true end end -# rubocop:enable Metrics/ClassLength +# rubocop:enable Metrics/ClassLength, Metrics/AbcSize From e4f19e841be56a5158a9387d3e336221747e59ab Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 18 Jun 2024 11:57:38 -0400 Subject: [PATCH 50/51] rubocop fixes --- app/models/vacols/case_docket.rb | 8 +++----- spec/models/vacols/case_docket_spec.rb | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index 6bd6cd4b6d2..58b9721689a 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -517,8 +517,6 @@ def self.distribute_priority_appeals(judge, genpop, limit, dry_run = false) SQL end - # {Once we have the query we can run it through an affinity days filter, reorder then add limit} - fmtd_query = sanitize_sql_array([ query, judge.vacols_attorney_id, @@ -537,11 +535,11 @@ def self.distribute_appeals(query, judge, limit, dry_run) conn.transaction do if dry_run - appeals = conn.exec_query(query).to_a + dry_appeals = conn.exec_query(query).to_a - cavc_aod_affinity_filter(appeals, judge) + cavc_aod_affinity_filter(dry_appeals, judge) - appeals + dry_appeals else conn.execute(LOCK_READY_APPEALS) unless FeatureToggle.enabled?(:acd_disable_legacy_lock_ready_appeals) diff --git a/spec/models/vacols/case_docket_spec.rb b/spec/models/vacols/case_docket_spec.rb index bb8f7f9ece8..9bbe8d25d4b 100644 --- a/spec/models/vacols/case_docket_spec.rb +++ b/spec/models/vacols/case_docket_spec.rb @@ -724,6 +724,7 @@ end end + # rubocop:disable Layout/LineLength context "when CaseDistributionLever.cavc_affinity_days or CaseDistributionLever.cavc_aod_affinity_days lever is enabled" do before do VACOLS::Case.where(bfcurloc: %w[81 83]).map { |c| c.update!(bfcurloc: "testing") } @@ -845,17 +846,25 @@ IneligibleJudgesJob.new.perform_now # {FOR LEVER HAVING A VALUE:} CaseDistributionLever.find_by_item(Constants.DISTRIBUTION.cavc_aod_affinity_days).update!(value: 14) - expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to match_array([ca1, ca4, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to + match_array([ca1, ca4, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30] + .map { |c| (c["bfkey"].to_i + 1).to_s }.sort) # {FOR LEVER BEING INFINITE:} CaseDistributionLever.find_by_item(Constants.DISTRIBUTION.cavc_aod_affinity_days).update!(value: "infinite") - expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to match_array([ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to + match_array([ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30] + .map { |c| (c["bfkey"].to_i + 1).to_s }.sort) # {FOR LEVER BEING OMIT:} CaseDistributionLever.find_by_item(Constants.DISTRIBUTION.cavc_aod_affinity_days).update!(value: "omit") - expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to match_array([ca1, ca2, ca3, ca4, ca5, ca6, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30].map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to + match_array([ca1, ca2, ca3, ca4, ca5, ca6, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30] + .map { |c| (c["bfkey"].to_i + 1).to_s }.sort) end end end + # rubocop:enable Layout/LineLength + context "legacy_das_deprecation FeatureToggle enabled" do before do FeatureToggle.enable!(:legacy_das_deprecation) From 7a61e22a9539b405f4f42e6a08c61a789b84991b Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 18 Jun 2024 12:32:38 -0400 Subject: [PATCH 51/51] fixed spec error --- spec/models/vacols/case_docket_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/models/vacols/case_docket_spec.rb b/spec/models/vacols/case_docket_spec.rb index 9bbe8d25d4b..26adf4170a6 100644 --- a/spec/models/vacols/case_docket_spec.rb +++ b/spec/models/vacols/case_docket_spec.rb @@ -846,19 +846,19 @@ IneligibleJudgesJob.new.perform_now # {FOR LEVER HAVING A VALUE:} CaseDistributionLever.find_by_item(Constants.DISTRIBUTION.cavc_aod_affinity_days).update!(value: 14) - expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to - match_array([ca1, ca4, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30] - .map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort) + .to match_array([ca1, ca4, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30] + .map { |c| (c["bfkey"].to_i + 1).to_s }.sort) # {FOR LEVER BEING INFINITE:} CaseDistributionLever.find_by_item(Constants.DISTRIBUTION.cavc_aod_affinity_days).update!(value: "infinite") - expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to - match_array([ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30] - .map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort) + .to match_array([ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30] + .map { |c| (c["bfkey"].to_i + 1).to_s }.sort) # {FOR LEVER BEING OMIT:} CaseDistributionLever.find_by_item(Constants.DISTRIBUTION.cavc_aod_affinity_days).update!(value: "omit") - expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort).to - match_array([ca1, ca2, ca3, ca4, ca5, ca6, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30] - .map { |c| (c["bfkey"].to_i + 1).to_s }.sort) + expect(VACOLS::CaseDocket.distribute_priority_appeals(judge, "any", 100, true).map { |c| c["bfkey"] }.sort) + .to match_array([ca1, ca2, ca3, ca4, ca5, ca6, ca10, ca11, ca12, ca13, ca14, ca15, ca16, ca17, ca21, ca22, ca23, ca24, ca25, ca26, ca27, ca28, ca29, ca30] + .map { |c| (c["bfkey"].to_i + 1).to_s }.sort) end end end