diff --git a/app/models/appeal.rb b/app/models/appeal.rb index 349e6f47976..8be3f861ed3 100644 --- a/app/models/appeal.rb +++ b/app/models/appeal.rb @@ -488,6 +488,23 @@ def eligible_for_death_dismissal?(_user) false end + # We are ready for BVA dispatch if + # - the appeal is not at Quality Review + # - the appeal has not already completed BVA Dispatch + # - the appeal is not already at BVA Dispatch + # - the appeal is not at Judge Decision Review + # - the appeal has a finished Judge Decision Review + def ready_for_bva_dispatch? + return false if Task.open.where(appeal: self).where("type IN (?, ?, ?)", + JudgeDecisionReviewTask.name, + QualityReviewTask.name, + BvaDispatchTask.name).any? + return false if BvaDispatchTask.completed.find_by(appeal: self) + return true if JudgeDecisionReviewTask.completed.find_by(appeal: self) + + false + end + private def business_lines_needing_assignment diff --git a/app/models/legacy_appeal.rb b/app/models/legacy_appeal.rb index 6428cc0a94d..3375d21ce68 100644 --- a/app/models/legacy_appeal.rb +++ b/app/models/legacy_appeal.rb @@ -892,6 +892,11 @@ def location_history VACOLS::Priorloc.where(lockey: vacols_id).order(:locdout) end + # Only AMA Appeals go to BVA Dispatch in Caseflow + def ready_for_bva_dispatch? + false + end + private def soc_eligible_for_opt_in?(receipt_date:, covid_flag: false) diff --git a/spec/models/appeal_spec.rb b/spec/models/appeal_spec.rb index 45b6e00ca22..41e2a0d485f 100644 --- a/spec/models/appeal_spec.rb +++ b/spec/models/appeal_spec.rb @@ -1034,6 +1034,116 @@ end end + shared_examples "existing BvaDispatchTask" do |status, result| + let(:user) { create(:user) } + + before do + BvaDispatch.singleton.add_user(user) + dispatch_task = BvaDispatchTask.create_from_root_task(appeal.root_task) + dispatch_task.descendants.each { |task| task.update_column(:status, status) } + end + + it "should return #{result}" do + expect(subject).to eq(result) + end + end + + shared_examples "depends on existing BvaDispatchTask" do + context "no existing BvaDispatchTask" do + it "should return true" do + expect(subject).to eq(true) + end + end + + context "existing open BvaDispatchTask" do + include_examples "existing BvaDispatchTask", + Constants.TASK_STATUSES.in_progress, + false + end + + context "existing complete BvaDispatchTask" do + include_examples "existing BvaDispatchTask", + Constants.TASK_STATUSES.completed, + false + end + + context "existing cancelled BvaDispatchTask" do + include_examples "existing BvaDispatchTask", + Constants.TASK_STATUSES.cancelled, + true + + context "and existing open BvaDispatchTask" do + include_examples "existing BvaDispatchTask", + Constants.TASK_STATUSES.assigned, + false + end + + context "and existing completed BvaDispatchTask" do + include_examples "existing BvaDispatchTask", + Constants.TASK_STATUSES.completed, + false + end + end + end + + describe ".ready_for_bva_dispatch?" do + subject { appeal.ready_for_bva_dispatch? } + + context "no complete JudgeDecisionReviewTask" do + it "should return false" do + expect(subject).to eq(false) + end + end + + context "has complete JudgeDecisionReviewTask" do + let(:appeal) do + create(:appeal, + :at_judge_review, + docket_type: Constants.AMA_DOCKETS.direct_review) + end + before do + JudgeDecisionReviewTask.find_by(appeal: appeal) + .update_column(:status, Constants.TASK_STATUSES.completed) + end + + context "and an open JudgeDecisionReviewTask" do + before do + JudgeDecisionReviewTask.create!(appeal: appeal, assigned_to: create(:user), parent: appeal.root_task) + end + + it "should return false" do + expect(subject).to eq(false) + end + end + + context "no QualityReviewTask" do + include_examples "depends on existing BvaDispatchTask" + end + + context "existing open QualityReviewTask" do + let(:user) { create(:user) } + before do + BvaDispatch.singleton.add_user(user) + QualityReviewTask.create_from_root_task(appeal.root_task) + end + + it "should return false" do + expect(subject).to eq(false) + end + end + + context "existing closed QualityReviewTask" do + let(:user) { create(:user) } + before do + qr_task = QualityReviewTask.create_from_root_task(appeal.root_task) + qr_task.descendants.each { |task| task.update_column(:status, Constants.TASK_STATUSES.completed) } + end + + include_examples "depends on existing BvaDispatchTask" + end + end + end + describe ".ready_for_distribution?" do let(:appeal) { create(:appeal) } let(:distribution_task) { create(:distribution_task, appeal: appeal, assigned_to: Bva.singleton) } diff --git a/spec/models/legacy_appeal_spec.rb b/spec/models/legacy_appeal_spec.rb index 67ceb805c34..d2924257aa4 100644 --- a/spec/models/legacy_appeal_spec.rb +++ b/spec/models/legacy_appeal_spec.rb @@ -2836,4 +2836,16 @@ end end end + + describe ".ready_for_bva_dispatch?" do + let(:appeal) { create(:legacy_appeal, vacols_case: create(:case)) } + + subject { appeal.ready_for_bva_dispatch? } + + context "Legacy appeals do not go to BVA Dispatch via Caseflow" do + it "should return false" do + expect(subject).to eq(false) + end + end + end end