Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if the user is the judge or attorney on a case review to determine what actions they see in LegacyTasks #15591

Merged
merged 15 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions app/models/legacy_appeal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -928,14 +928,14 @@ def paper_case?
end

def attorney_case_review
# # Created at date will be nil if there is no decass record created for this appeal yet
hschallhorn marked this conversation as resolved.
Show resolved Hide resolved
return unless vacols_case_review&.created_at
task_id = "#{vacols_id}-#{VacolsHelper.day_only_str(vacols_case_review&.created_at)}"

AttorneyCaseReview.find_by(task_id: "#{vacols_id}-#{VacolsHelper.day_only_str(vacols_case_review.created_at)}")
@attorney_case_review ||= AttorneyCaseReview.find_by(task_id: task_id)
end
lomky marked this conversation as resolved.
Show resolved Hide resolved


def vacols_case_review
VACOLS::CaseAssignment.latest_task_for_appeal(vacols_id)
@vacols_case_review ||= VACOLS::CaseAssignment.latest_task_for_appeal(vacols_id)
lomky marked this conversation as resolved.
Show resolved Hide resolved
end

def death_dismissal!
Expand Down Expand Up @@ -975,6 +975,24 @@ def latest_appeal_event
TaskEvent.new(version: versions.last) if versions.any?
end

# Hacky logic to determine if an acting judge should see judge actions or attorney actions on a case assigne to them
hschallhorn marked this conversation as resolved.
Show resolved Hide resolved
# See https://github.com/department-of-veterans-affairs/caseflow/issues/14886 for details
def assigned_to_acting_judge_as_judge?(acting_judge)
if attorney_case_review.present?
# If the acting judge was the attorney on this review, this case is very likely assigned to them to redraft the
# decision.
hschallhorn marked this conversation as resolved.
Show resolved Hide resolved
return false if attorney_case_review.attorney_id == acting_judge.id

# if the acting judge was the judge on this review, this case is very likely assigned to them to sign the decision
return true if attorney_case_review.reviewing_judge_id == acting_judge.id
hschallhorn marked this conversation as resolved.
Show resolved Hide resolved
end

# In case an attorney case review does not exist in caseflow or if this acting judge was neither the judge or
# attorney listed in the review, check to see if a decision has already been written for the appeal. If so, assume
# this appeal is assigned to the acting judge as a judge task
hschallhorn marked this conversation as resolved.
Show resolved Hide resolved
vacols_case_review.valid_document_id?
end

private

def soc_eligible_for_opt_in?(receipt_date:, covid_flag: false)
Expand Down
2 changes: 1 addition & 1 deletion app/models/queues/legacy_work_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def tasks_from_vacols_tasks(vacols_tasks, user = nil)
# If the user is a judge they are only assigned JudgeLegacyTasks
# If the user is an acting judge, assume any case that already has a decision doc is assigned to them as a judge
if user&.vacols_roles&.first&.downcase == "judge" ||
(user&.acting_judge_in_vacols? && appeal.vacols_case_review.valid_document_id?)
(user&.acting_judge_in_vacols? && appeal.assigned_to_acting_judge_as_judge?(user))
task_class = JudgeLegacyTask
end

Expand Down
59 changes: 59 additions & 0 deletions spec/models/legacy_appeal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2993,4 +2993,63 @@

it_behaves_like "latest informal hearing presentation task"
end

describe "#assigned_to_acting_judge_as_judge?" do
shared_examples "assumes the case assigned to the user to draft the decision" do
hschallhorn marked this conversation as resolved.
Show resolved Hide resolved
it { is_expected.to be false }
end

shared_examples "assumes the case assigned to the user to sign the decision" do
hschallhorn marked this conversation as resolved.
Show resolved Hide resolved
it { is_expected.to be true }
end

let(:acting_judge) { create(:user, :with_vacols_acting_judge_record) }
let!(:appeal) { create(:legacy_appeal, vacols_case: create(:case, :assigned, user: acting_judge)) }

subject { appeal.assigned_to_acting_judge_as_judge?(acting_judge) }

context "when the attorney review process has happened outside of caseflow" do
context "a decision has not been written for the case" do
hschallhorn marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: I think this belongs at the sibling level to when the attorney review process has happened outside of caseflow, rather than under it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set up these examples as "when there is an attorney_case_review" and "when there is not an attorney_case_review", but gave them more "real world" descriptions. So I agree that if the attorney has not reviewed the case, the attorney review process hasn't actually happened, inside or outside of caseflow. But thought this grouped a bit nicer

it_behaves_like "assumes the case assigned to the user to draft the decision"
end

context "a decision has been written for the case" do
hschallhorn marked this conversation as resolved.
Show resolved Hide resolved
before { VACOLS::Decass.where(defolder: appeal.vacols_id).update_all(dedocid: "02255-00000002") }

it_behaves_like "assumes the case assigned to the user to sign the decision"
end
end

context "when the attorney review process has happened within caseflow" do
let(:created_at) { VACOLS::Decass.where(defolder: appeal.vacols_id).first.deadtim }
let!(:case_review) { create(:attorney_case_review, task_id: "#{appeal.vacols_id}-#{created_at}") }

context "when the user does not match the judge or attorney on the case review" do
it_behaves_like "assumes the case assigned to the user to draft the decision"

it "falls back to check the presence of a decision document" do
expect_any_instance_of(VACOLS::CaseAssignment).to receive(:valid_document_id?).once
subject
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion/Question: aren't these redundant? I don't think we need the shared example here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is indeed! Removing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

juuuust kidding
the first set of tests checks when no attorney case review is present
this test checks when an attorney case review is present but not associated with the user.
Gotta hit all those conditional branches!

end

context "when the user matches the attorney on the case review" do
before do
case_review.update!(attorney: acting_judge)
expect_any_instance_of(VACOLS::CaseAssignment).not_to receive(:valid_document_id?)
end

it_behaves_like "assumes the case assigned to the user to draft the decision"
end

context "when the user matches the judge on the case review" do
before do
case_review.update!(reviewing_judge: acting_judge)
expect_any_instance_of(VACOLS::CaseAssignment).not_to receive(:valid_document_id?)
end

it_behaves_like "assumes the case assigned to the user to sign the decision"
end
end
end
end