Skip to content

Commit

Permalink
Feature/appeals 43179 (#21665)
Browse files Browse the repository at this point in the history
* Calvin/APPEALS-43852-cavc-levers (#21441)

* enabled cavc affinity levers in UI

* updated rspec

* [APPEALS-43849]Update CAVC Affinity Implementation for AMA Dockets to… (#21456)

* [APPEALS-43849]Update CAVC Affinity Implementation for AMA Dockets to Account for Omit/Infinity

* Affinity rules applied to non genpop

* Addressed comments

* Addressed comments

* fixed rubocop issues + added clarity to where clause

---------

Co-authored-by: Calvin <Calvin.Costa@va.gov>

* APPEALS-44956: Add AppealAffinity model and database table (#21526)

* add migration for appeal_affinities

* add AppealAffinity model and associations, update migration for new column

* update index to be unique

* add factory, add tests

* add factory traits to appeal and case for appeal affinities

* add combination trait to appeal factory

* add appeal_affinity to skipped associations in ETL reporting

* add a validation, test

* Craig/appeals 44958 (#21564)

* add new job, update affinity model validation and after save hook

* add update from push job

* fix job extending distribution scopes

* add with appeal affinities to distribution scopes

* typo

* add error handling, add test file

* add distributed case factory, refactor naming in job

* fix factories, added tests

* fix migration for null affinity start date column

* fixes, added tests

* more test updates

* add return in job if no query results, tests for no query results

* add test for after_save hook adding dist task instructions

* set start dist job to queue affinity job after running

* fix update job and start dist job spec

* queue affinity update job from push job

* code clarity

* fix judge in seed file

* remove comment, fix hearing factory, disable some seeds for testing

* add more tests

* test refactor

* update appeals for dist query to add affinity start, add seed file, fix hearing factory, add stat to dist factory

* disable new seed on reset

* update seed file with vet names, add another seed category

* fix distirbuted case factory?

* actually fix GHA runs

* lint, test fixes

* change constants in new job

* [Appeals 43850] Update Legacy Docket Queries to Account for the Previous Decision Judge and Type Action  (#21556)

* test changes for seans ticket

* test changes

* added joins to all required methods

* fixed lint

* fixed column ambiguity errors

* cleaned up naming scheme

* Documentation for JOIN_PREVIOUS_APPEALS constant

---------

Co-authored-by: Calvin <Calvin.Costa@va.gov>

* APPEALS-44959: Modify affinity date checks to use appeal_affinity (#21611)

* swap distribution queries from distribution_task to appeal_affinities

* update seed files to use appeal affinities instead of distribution task

* clean up seed file method names

* add missing Timecop.return in ama affinity case seed

* fix name of a method in a seed file

* remove references to distribution task in distribution scopes

* fix push priority job tests

* fix naming of args in one of the seed files

* fix user seed, fix date format in distribution task instructions

* fix tests for date format update

* APPEALS-44187: Factory Bot Additions (#21438)

* AC1: values for bfddec and bfmpro

* AC2: case issues updated to '3'

* AC3-4: attorney and judge additions

* ac 5: bfdpdcn addition

* AC6: case type action addition

* ac7: new folder match to original

* ac8: case issues set to original

* AC 3/4: added associations to original

* ac3/4: updated logic to handle no args

* ac3/4: return sattyid

* ac7:updating folder assignment

* ac7: added bfkey to except block

* ac7/8: update to case issue list and validations dismissed

* removed byebug

* ac7: added 'ticknum' to except

* lint fixes

* lint fixes

* lint fixes

* lint fixes

* nested trait into form_9 factory

* new addtions

* added .save to case issues

* resolving correspondent and titrnum associations

* fixed bfdc typo

* factory additions

* added ssn to associated corr.

* removed transient and added .save

* added after create to corr factory

* veteran lookup check prior to create

* committing missed 'end'

* moved over veteran create to case fact.

* move corr. association field to case fact.

* lint issues + corres. save

* Calvin/APPEALS-44957-rake-affinity (#21577)

* grabbed receipt dates from distributed cases

* refactored for functionality + added method to grab appeals that match

* using receipt date, get all related appeals

* added update/creation plus cleaned prior imple.

* gets most recent distributed case receipt_date

* skips if receipt_date is nil for performance

* if appeal affinity is nil, it will now be updated

* created spec file

* fixed non ready appeals

* updated query to match new AC

* removing comment

* testing for each docket

* updated spec file

* added new tests to rspec

* updated start date to receipt date instead of Time.now

* fixed date/time rspec errors

* added rails logger to know when rake task has finished

* added tag for rails log

* removed nonpriority dockets for direct_review and evidence_submission

* fixed lint issue

* fixed flaky spec test

* limits distributed cases query to within the last week

* APPEALS-46016: Add Affinity Start Date to the Explain Page (#21660)

* add affinity start date to explain page

* add feature test to verify dates display

* Sudhir/appeals 43851 (#21613)

* Implement CAVC + AOD Affinity Lever for AMA Dockets

* addressed comments

* addressed comments

* Addressed comments

* added cavc_aod_affinity in case distribution lever model

* addressed comments

* addressed comments

* updated specs

* Updated specs

* specs changes reverted

* ama_aod and ama_non_aod queries updated

* change the assertion in docket spec

* Craig/appeals 46196 (#21689)

* fix query, tested locally

* add basic test to verify csv downloads aren't broken

* APPEALS-43851: Add test to validate CAVC+AOD behavior on hearing docket appeals affinities (#21678)

* add test to validate cavc+aod on hearing docket appeals

* lint, test case_docket_spec fix

* modify case_docket_spec again

* more test fix testing

* attempt to fix test again

* test removing prev appeals from nonpriority queries

* more test tests

* feature toggle change in test

* reorder new portions of query

* remove unused portions of queries in case_docket

* revert unneeded change to query order

* revert unneeded change to query order

* update rake task and spec (#21731)

* APPEALS-46325: Add Seeds for AOD Appeals and Update Dates to Match CAVC (#21730)

* add aod hearing cases to ama affinity cases seed

* fix lever spec

* APPEALS-45148: Hook to clear saved affinity date (#21623)

* initial imp. idea

* AC1: check for affinity_start_date on assignment

* AC2/3: update affinity start date  w/ instr.

* updates to naming, instructions, and hook logic

* updates after review

* rspec coverage and addtional condition

* removed unused identifier

* removed reduntant 'self's

* added update on actual AA record

* updated to save aa record and addtional rspec

* added change to assignment on no record test

* check for assignment

* addd update to 'on_hold' status

* public method to handle legacy affinity appeals

* added .reload to :with_affinity_appeal

* added .reload to :ready_for_distribution

* updates to pass explain_spec

* switched boolean values

* typo

* readujsted order on :create for affinity appeal

* removed after(:create)

* testing rspec by readding after :create

* reloading in assertation

* addressing lint errors

* fix seeds/users_spec

* add case dist lever to new tests (#21776)

* fix tests, add lever to factory, fix dist scopes (#21779)

* fix rubocop warning

* Acd/appeals 43853 43854 (#21971)

* Calvin/appeals 43853 (#21723)

* initial updates

* removing unnecessary variable

* focused in on priority

* removing non priority stuff

* added general comments

* added BFAC and AOD to cavc aod lever query

* adding judge vacols id to query

* aod affinity_start_date filter initial changes

* fixed sorting

* fixed rubocop issues

* updated filter method

* error handling

* added ineligibility to queries for PREV_DECIDING_JUDGE

* fixed SQL query + added comments

* added exclude from affinity check into the case docket queries

* error handling + fixing sql queries

* rejects appeals without affinity_start_dates and nonmatching judges

* fixing rubocop offenses

* fixed inconsistencies between methods

* fixed conditions for rejecting appeals

* refactored cavc aod affinity filter to make it much easier to read

* refactored code to account for AC6

* error handling for empty exclude from affinity

* reverted next if block to old logic to ensure it works

* added PREV_DEC_JUDGE is not null

* case.rb factory changes

* added more options to legacy_cavc_appeal creation

* cleaned up code for simpler reading

* fix for aod legacy cavc creation

* added tied to option to legacy cavc appeal factory

* limits are now handled correctly in query

* replaced return false to next if, as return false was causing unexpected behavior

* fix rspecs + one edge case

* added cavc aod lever creation to rspecs

* removed bfac and aod from nonpriority query

* cavc aod appeals w/excluded judges are now properly being filtered

* refactored excluded judges check

* added to old query to fix rspec errors

* modified case factory bot

* query now handles when prev_deciding_judge is nil

* removed unnecessary condition

* fixed case factory to now have tied_to attatched to orig appeal

* fixed next if block within filter

* handles omit scenarios + correctly rejects with next

* working on rspec (still failing)

* fix for ineligble VLJ when infinite

* fixed rspec suite for cavc aod filters

* fixed omit scenario in cavc aod affinity filter

* consolidation & readability refactor

* rubocop fixes

* fixed spec error

* Implement CAVC Affinity for Legacy Docket (#21706)

* Implement CAVC Affinity for Legacy Docket

* addressed comments

* Added BFAC in the query

* code changes for affinitty date

* Added affinity code

* code refactor and removed non priority code changes

* fixed syntax change

* Addressed comments

* refactor cavc affinity filter

* refactored code

* code refactor

* code refactor

* Updated existing specs

* code refactor

* Added new rspecs

* code refactor and added test  cases

* code refactor

* added test cases

* fixes push_priority_spec

* fixed rubocop issues

* rubocop issue fixed

* refactored code to make it easier to understand

* refactored + fixed rspec and lint errors

---------

Co-authored-by: Calvin <Calvin.Costa@va.gov>
Co-authored-by: calvincostaBAH <108481161+calvincostaBAH@users.noreply.github.com>

* basic creation of legacy affinity cases seed data

* bug fixes, added bfcorlid with veterans, fully runs now

* added new appeals for affinity_and_tied_to_judge

* made data have realistic bfcorlids

* changes document sequence to use less digits

* added new file numbers for tied_to cases to make them easier to identify

---------

Co-authored-by: samasudhirreddy <108430298+samasudhirreddy@users.noreply.github.com>

* APPEALS-50692: Update Appeals Ready to Distribute CSV to include CAVC remand original judge (#22070)

* CSV download functional

* add tests, fix CSV query in CaseDocket

* fix lint

* Calvin/appeals 44313 (#22119)

* initial seed data file

* added legacy cavc and cavc aod affinity cases

* update

* fixed tied to for legacy appeals

* added AOD versions of appeals

* small lint fixes

* ensured AOD cases for legacy hearings with exluded or ineligible judge

* added vacols staff record creation for users without it

* APPEALS-47741: Update the UpdateAppealAffinityDatesJob to add appeal_affinity records for Legacy Appeals (#22023)

* AC1: changes and respective tests

* adjustements after refactoring

* identifier mismatch

* name update

* name update

* added appeal affinity filter

* updated comment

* remove byebug

* update rspec to handle hash input

* added no start date test case

* updated process method test

* removed 'todo' comment

* dried up query string

* aligned conditions

* update to hash quotations

* update to hash quotations

* added legacy to priority receipt dates from dist.

* moved append to resulting list

* added legacy receipt date to push job hash

* uncomment call to legacy

* updated dist.id to @dist_id

* uncomment call to process legacy appeals

* handling update to legacy docket type

* current rspec status

* fixed typo

* fix rspec

* legacy spec additions

* legacy spec additions

* added legacy dist. case factory

* removed vacols_judge ref

* updates for spec

* final review

* removed comment

* rubocop fixes

* fix rubocop warnings (#22225)

* Fix rubocop and tests (#22231)

* Calvin/appeals 52551 (#22293)

* age_of_n_oldest_priority_appeals_available_to_judge time out changes

* fixed timeout issue for distribute_priority_appeals

* fixed lint errors

* Craig/case docket optimization (#22294)

* age_of_n_oldest_priority_appeals_available_to_judge time out changes

* fixed timeout issue for distribute_priority_appeals

* optimize case docket priority distribution methods

* fix das deprecation distribution spec

---------

Co-authored-by: Calvin <Calvin.Costa@va.gov>

* Update admin_ui_spec.rb for CAVC levers being enabled

---------

Co-authored-by: calvincostaBAH <108481161+calvincostaBAH@users.noreply.github.com>
Co-authored-by: samasudhirreddy <108430298+samasudhirreddy@users.noreply.github.com>
Co-authored-by: Calvin <Calvin.Costa@va.gov>
Co-authored-by: seanrpa <155660052+seanrpa@users.noreply.github.com>
Co-authored-by: Isaiah Saucedo <irsaucedo5@gmail.com>
  • Loading branch information
6 people authored and Rnmarshall93 committed Aug 21, 2024
1 parent fdf7b4d commit 182ea0a
Show file tree
Hide file tree
Showing 29 changed files with 2,657 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def ineligible_judge_list

def check_environment
return true if Rails.env.development?
return true if Rails.env.test?
return true if Rails.deploy_env?(:demo)

redirect_to "/unauthorized"
Expand Down
89 changes: 74 additions & 15 deletions app/jobs/update_appeal_affinity_dates_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@ def update_from_requested_distribution
return if receipt_date_hashes_array.empty?

process_ama_appeals_which_need_affinity_updates(receipt_date_hashes_array)
# Uncomment this while implementing legacy appeal affinities
# process_legacy_appeals_which_need_affinity_updates(receipt_date_hashes_array)
process_legacy_appeals_which_need_affinity_updates(receipt_date_hashes_array)
end

def update_from_push_priority_appeals_job
receipt_date_hashes_array = latest_receipt_dates_from_push_job
return if receipt_date_hashes_array.empty?

process_ama_appeals_which_need_affinity_updates(receipt_date_hashes_array)
# Uncomment this while implementing legacy appeal affinities
# process_legacy_appeals_which_need_affinity_updates(receipt_date_hashes_array)
process_legacy_appeals_which_need_affinity_updates(receipt_date_hashes_array)
end

def latest_receipt_dates_from_distribution
Expand All @@ -50,9 +48,24 @@ def latest_receipt_dates_from_distribution
.group("docket", "priority")
.maximum("receipt_date")

format_distributed_case_hash(distributed_cases_hash)
legacy_nonpriority_receipt_date =
DistributedCase.where(docket: "legacy", priority: false, distribution_id: @distribution_id)
.map { |c| VACOLS::Case.find_by(bfkey: c.case_id).bfd19 }.max

legacy_priority_receipt_date =
DistributedCase.where(docket: "legacy", priority: true, distribution_id: @distribution_id)
.map { |c| VACOLS::Case.find_by(bfkey: c.case_id).bfd19 }.max

legacy_nonpriority_hash = { docket: "legacy", priority: false, receipt_date: legacy_nonpriority_receipt_date }
legacy_priority_hash = { docket: "legacy", priority: true, receipt_date: legacy_priority_receipt_date }

result = format_distributed_case_hash(distributed_cases_hash)
result << legacy_nonpriority_hash unless legacy_nonpriority_receipt_date.nil?
result << legacy_priority_hash unless legacy_priority_receipt_date.nil?
result
end

# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def latest_receipt_dates_from_push_job
distributed_cases_hash =
DistributedCase
Expand All @@ -62,8 +75,31 @@ def latest_receipt_dates_from_push_job
.group("docket", "priority")
.maximum("receipt_date")

format_distributed_case_hash(distributed_cases_hash)
legacy_nonpriority_receipt_date =
DistributedCase
.includes(:distribution)
.where(docket: "legacy",
priority: false,
distributions: { priority_push: true, completed_at: Time.zone.today.midnight..Time.zone.now })
.map { |c| VACOLS::Case.find_by(bfkey: c.case_id).bfd19 }.max

legacy_priority_receipt_date =
DistributedCase
.includes(:distribution)
.where(docket: "legacy",
priority: true,
distributions: { priority_push: true, completed_at: Time.zone.today.midnight..Time.zone.now })
.map { |c| VACOLS::Case.find_by(bfkey: c.case_id).bfd19 }.max

legacy_nonpriority_hash = { docket: "legacy", priority: false, receipt_date: legacy_nonpriority_receipt_date }
legacy_priority_hash = { docket: "legacy", priority: true, receipt_date: legacy_priority_receipt_date }

result = format_distributed_case_hash(distributed_cases_hash)
result << legacy_nonpriority_hash unless legacy_nonpriority_receipt_date.nil?
result << legacy_priority_hash unless legacy_priority_receipt_date.nil?
result
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength

def format_distributed_case_hash(distributed_cases_hash)
# If there isn't a held hearing and it isn't a CAVC remand (priority), then there will never be an affinity
Expand Down Expand Up @@ -94,13 +130,37 @@ def process_ama_appeals_which_need_affinity_updates(receipt_date_hashes_array)
else
base_appeals_to_update.nonpriority
end

create_or_update_appeal_affinities(appeals_to_update_adjusted_for_priority, receipt_date_hash[:priority])
end
end

# To be implemented in future work
def process_legacy_appeals_which_need_affinity_updates(receipt_date_hashes_array); end
# Returns only legacy appeals with no affinity record or affinity start date
def legacy_appeals_with_no_appeal_affinities(appeals_hash)
appeals_with_no_affinities = []

appeals_hash.each do |appeal|
key = appeal["bfkey"]
appeal_record = VACOLS::Case.find_by(bfkey: key)

if appeal_record &&
(appeal_record.appeal_affinity.blank? || appeal_record.appeal_affinity.affinity_start_date.blank?)
appeals_with_no_affinities << appeal_record
end
end

appeals_with_no_affinities
end

def process_legacy_appeals_which_need_affinity_updates(receipt_date_hashes_array)
receipt_date_hashes_array.map do |receipt_date_hash|
next unless receipt_date_hash[:docket] == LegacyDocket.docket_type

legacy_appeals_hash = VACOLS::CaseDocket.update_appeal_affinity_dates_query(receipt_date_hash[:priority],
receipt_date_hash[:receipt_date])
legacy_appeals_to_update_adjusted_for_affinity = legacy_appeals_with_no_appeal_affinities(legacy_appeals_hash)
create_or_update_appeal_affinities(legacy_appeals_to_update_adjusted_for_affinity, receipt_date_hash[:priority])
end
end

# The appeals arg can be an array of VACOLS::Case objects, they have the same affinity associations as Appeal objects
def create_or_update_appeal_affinities(appeals, priority)
Expand All @@ -110,13 +170,12 @@ def create_or_update_appeal_affinities(appeals, priority)
if existing_affinity
existing_affinity.update!(affinity_start_date: Time.zone.now, distribution_id: @distribution_id)
existing_affinity
elsif appeal.is_a?(VACOLS::Case)
appeal.create_appeal_affinity!(docket: LegacyDocket.docket_type, priority: priority,
affinity_start_date: Time.zone.now, distribution_id: @distribution_id)
else
appeal.create_appeal_affinity!(
docket: appeal.docket_type,
priority: priority,
affinity_start_date: Time.zone.now,
distribution_id: @distribution_id
)
appeal.create_appeal_affinity!(docket: appeal.docket_type, priority: priority,
affinity_start_date: Time.zone.now, distribution_id: @distribution_id)
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/case_distribution_lever.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class CaseDistributionLever < ApplicationRecord
#{Constants.DISTRIBUTION.ama_hearing_case_affinity_days}
#{Constants.DISTRIBUTION.ama_hearing_case_aod_affinity_days}
#{Constants.DISTRIBUTION.cavc_affinity_days}
#{Constants.DISTRIBUTION.cavc_aod_affinity_days}
#{Constants.DISTRIBUTION.ama_hearing_case_aod_affinity_days}
#{Constants.DISTRIBUTION.ama_evidence_submission_docket_time_goals}
#{Constants.DISTRIBUTION.ama_hearing_docket_time_goals}
#{Constants.DISTRIBUTION.ama_hearing_start_distribution_prior_to_goals}
Expand Down
135 changes: 125 additions & 10 deletions app/models/concerns/distribution_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,112 @@ def ready_for_distribution
.where(tasks: { type: DistributionTask.name, status: Constants.TASK_STATUSES.assigned })
end

def genpop
def genpop_base_query
with_appeal_affinities
.with_original_appeal_and_judge_task
.include_aod_motions
end

def genpop_with_case_distribution_lever
genpop_cavc_affinity_days_query = generate_genpop_cavc_affinity_days_lever_query
genpop_cavc_aod_affinity_days_query = generate_genpop_cavc_aod_affinity_days_lever_query.group("appeals.id")

result = genpop_cavc_affinity_days_query.or(genpop_cavc_aod_affinity_days_query)

if FeatureToggle.enabled?(:acd_cases_tied_to_judges_no_longer_with_board)
result = result.or(
genpop_base_query
.where("original_judge_task.assigned_to_id in (?)", HearingRequestDistributionQuery.ineligible_judges_id_cache)
.group("appeals.id")
)
end

if FeatureToggle.enabled?(:acd_exclude_from_affinity)
result = result.or(
genpop_base_query
.where("original_judge_task.assigned_to_id in (?)", JudgeTeam.judges_with_exclude_appeals_from_affinity)
.group("appeals.id")
)
end

result
end

def generate_genpop_cavc_affinity_days_lever_query
if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_affinity_days)
genpop_base_query
.ama_non_aod_appeals
.where(
"appeals.stream_type != ? OR appeal_affinities.affinity_start_date <= ?",
Constants.AMA_STREAM_TYPES.court_remand,
CaseDistributionLever.cavc_affinity_days.days.ago
)
elsif CaseDistributionLever.cavc_affinity_days == Constants.ACD_LEVERS.infinite
genpop_base_query
.ama_non_aod_appeals
.where("appeals.stream_type != ?", Constants.AMA_STREAM_TYPES.court_remand)
elsif CaseDistributionLever.cavc_affinity_days == Constants.ACD_LEVERS.omit
genpop_base_query
.ama_non_aod_appeals
end
end

def generate_genpop_cavc_aod_affinity_days_lever_query
if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days)
genpop_base_query
.ama_aod_appeals
.where(
"appeals.stream_type != ? OR appeal_affinities.affinity_start_date < ?",
Constants.AMA_STREAM_TYPES.court_remand,
CaseDistributionLever.cavc_aod_affinity_days.days.ago
)
elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite
genpop_base_query
.ama_aod_appeals
.where("appeals.stream_type != ?", Constants.AMA_STREAM_TYPES.court_remand)
elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.omit
genpop_base_query
.ama_aod_appeals
end
end

def non_genpop_with_case_distribution_lever(judge)
non_genpop_cavc_affinity_days_query = generate_non_genpop_cavc_affinity_days_lever_query(judge)
non_genpop_cavc_aod_affinity_days_query = generate_non_genpop_cavc_aod_affinity_days_lever_query(judge)

non_genpop_cavc_affinity_days_query.or(non_genpop_cavc_aod_affinity_days_query)
end

def generate_non_genpop_cavc_affinity_days_lever_query(judge)
if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_affinity_days)
non_genpop_for_judge(judge)
.ama_non_aod_appeals
elsif CaseDistributionLever.cavc_affinity_days == Constants.ACD_LEVERS.infinite
genpop_base_query
.ama_non_aod_appeals
.where(original_judge_task: { assigned_to_id: judge&.id },
appeals: { stream_type: Constants.AMA_STREAM_TYPES.court_remand })
elsif CaseDistributionLever.cavc_affinity_days == Constants.ACD_LEVERS.omit
genpop_base_query.ama_non_aod_appeals.none
end
end

def generate_non_genpop_cavc_aod_affinity_days_lever_query(judge)
if case_affinity_days_lever_value_is_selected?(CaseDistributionLever.cavc_aod_affinity_days)
non_genpop_for_judge(judge, CaseDistributionLever.cavc_aod_affinity_days)
.ama_non_aod_appeals
elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.infinite
genpop_base_query
.ama_non_aod_appeals
.where(original_judge_task: { assigned_to_id: judge&.id },
appeals: { stream_type: Constants.AMA_STREAM_TYPES.court_remand })
elsif CaseDistributionLever.cavc_aod_affinity_days == Constants.ACD_LEVERS.omit
genpop_base_query.ama_non_aod_appeals.none
end
end

def genpop
genpop_base_query
.where(
"appeals.stream_type != ?
OR appeal_affinities.affinity_start_date <= ?
Expand All @@ -58,13 +161,16 @@ def genpop
)
end

def ama_non_aod_hearing_appeals
where("advance_on_docket_motions.person_id IS NULL")
.where("people.date_of_birth > ?", 75.years.ago)
def ama_non_aod_appeals
where("people.date_of_birth > ? or people.date_of_birth is null", 75.years.ago)
.group("appeals.id")
.having("count(case when advance_on_docket_motions.granted "\
"\n and advance_on_docket_motions.created_at > appeals.established_at then 1 end) = ?", 0)
end

def ama_aod_hearing_appeals
where("advance_on_docket_motions.person_id IS NOT NULL")
def ama_aod_appeals
where("advance_on_docket_motions.created_at > appeals.established_at")
.where("advance_on_docket_motions.granted = ?", true)
.or(where("people.date_of_birth <= ?", 75.years.ago))
end

Expand All @@ -81,11 +187,10 @@ def with_original_appeal_and_judge_task

# docket.rb
# Within the first 21 days, the appeal should be distributed only to the issuing judge.
def non_genpop_for_judge(judge)
with_appeal_affinities
.with_original_appeal_and_judge_task
def non_genpop_for_judge(judge, lever_days = CaseDistributionLever.cavc_affinity_days)
genpop_base_query
.where("appeal_affinities.affinity_start_date > ? or appeal_affinities.affinity_start_date is null",
CaseDistributionLever.cavc_affinity_days.days.ago)
lever_days.days.ago)
.where(original_judge_task: { assigned_to_id: judge&.id })
end

Expand Down Expand Up @@ -176,4 +281,14 @@ def case_affinity_days_lever_value_is_selected?(lever_value)

true
end

def exclude_affinity_and_ineligible_judge_ids
judge_ids = JudgeTeam.judges_with_exclude_appeals_from_affinity

if FeatureToggle.enabled?(:acd_cases_tied_to_judges_no_longer_with_board)
judge_ids.push(*HearingRequestDistributionQuery.ineligible_judges_id_cache)
end

judge_ids
end
end
2 changes: 1 addition & 1 deletion app/models/docket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def adjust_for_genpop(scope, genpop, judge)
end

def adjust_for_affinity(scope, judge)
scope.genpop.or(scope.non_genpop_for_judge(judge))
scope.genpop_with_case_distribution_lever.or(scope.non_genpop_with_case_distribution_lever(judge))
end

def scoped_for_priority(scope)
Expand Down
Loading

0 comments on commit 182ea0a

Please sign in to comment.