Skip to content

Commit

Permalink
Merge pull request #18472 from department-of-veterans-affairs/feature…
Browse files Browse the repository at this point in the history
…/APPEALS-17497

Feature/APPEALS-17497 MST/PACT Act Special Identification
  • Loading branch information
kristeja authored Jul 19, 2023
2 parents 5c725dc + 1a8d0fb commit b058136
Show file tree
Hide file tree
Showing 192 changed files with 12,899 additions and 393 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ gem "acts_as_tree"
gem "amoeba"
# BGS

gem "bgs", git: "https://github.com/department-of-veterans-affairs/ruby-bgs.git", ref: "7d7c67f7bad5e5aa03e257f0d8e57a4aa1a6cbbf"
gem "bgs", git: "https://github.com/department-of-veterans-affairs/ruby-bgs.git", ref: "5f47e7b2656ef347d314ef43c93d38a9f20816ec"
# Bootsnap speeds up app boot (and started to be a default gem in 5.2).
gem "bootsnap", require: false
gem "browser"
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ GIT

GIT
remote: https://github.com/department-of-veterans-affairs/ruby-bgs.git
revision: 7d7c67f7bad5e5aa03e257f0d8e57a4aa1a6cbbf
ref: 7d7c67f7bad5e5aa03e257f0d8e57a4aa1a6cbbf
revision: 5f47e7b2656ef347d314ef43c93d38a9f20816ec
ref: 5f47e7b2656ef347d314ef43c93d38a9f20816ec
specs:
bgs (0.2)
bgs (0.3)
httpclient
nokogiri (>= 1.11.0.rc4)
savon (~> 2.12)
Expand Down
250 changes: 237 additions & 13 deletions app/controllers/appeals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def show

def edit
# only AMA appeals may call /edit
return not_found if appeal.is_a?(LegacyAppeal)
# this was removed for MST/PACT initiative to edit MST/PACT for legacy issues
return not_found if appeal.is_a?(LegacyAppeal) && !FeatureToggle.enabled?(:legacy_mst_pact_identification)
end

helper_method :appeal, :url_appeal_uuid
Expand All @@ -178,18 +179,11 @@ def url_appeal_uuid
end

def update
if request_issues_update.perform!
# if cc appeal, create SendInitialNotificationLetterTask
if appeal.contested_claim? && FeatureToggle.enabled?(:cc_appeal_workflow)
# check if an existing letter task is open
existing_letter_task_open = appeal.tasks.any? do |task|
task.class == SendInitialNotificationLetterTask && task.status == "assigned"
end
# create SendInitialNotificationLetterTask unless one is open
send_initial_notification_letter unless existing_letter_task_open
end

if appeal.is_a?(LegacyAppeal) && FeatureToggle.enabled?(:legacy_mst_pact_identification)
legacy_mst_pact_updates
elsif request_issues_update.perform!
set_flash_success_message
create_subtasks!

render json: {
beforeIssues: request_issues_update.before_issues.map(&:serialize),
Expand All @@ -203,6 +197,18 @@ def update

private

def create_subtasks!
# if cc appeal, create SendInitialNotificationLetterTask
if appeal.contested_claim? && FeatureToggle.enabled?(:cc_appeal_workflow)
# check if an existing letter task is open
existing_letter_task_open = appeal.tasks.any? do |task|
task.class == SendInitialNotificationLetterTask && task.status == "assigned"
end
# create SendInitialNotificationLetterTask unless one is open
send_initial_notification_letter unless existing_letter_task_open
end
end

# :reek:DuplicateMethodCall { allow_calls: ['result.extra'] }
# :reek:FeatureEnvy
def render_search_results_as_json(result)
Expand Down Expand Up @@ -270,7 +276,226 @@ def review_edited_message
"You have successfully " + [added_issues, removed_issues, withdrawn_issues].compact.to_sentence + "."
end

# check if changes in params
def mst_pact_changes?
request_issues_update.mst_edited_issues.any? || request_issues_update.pact_edited_issues.any?
end

# format MST/PACT edit success banner message
def mst_and_pact_edited_issues
# list of edit counts
mst_added = 0
mst_removed = 0
pact_added = 0
pact_removed = 0
# get edited issues from params and reject new issues without id
if !appeal.is_a?(LegacyAppeal)
existing_issues = params[:request_issues].reject { |i| i[:request_issue_id].nil? }

# get added issues
new_issues = request_issues_update.after_issues - request_issues_update.before_issues
# get removed issues
removed_issues = request_issues_update.before_issues - request_issues_update.after_issues

# calculate edits
existing_issues.each do |issue_edit|
# find the original issue and compare MST/PACT changes
before_issue = request_issues_update.before_issues.find { |i| i.id == issue_edit[:request_issue_id].to_i }

# increment edit counts if they meet the criteria for added/removed
mst_added += 1 if issue_edit[:mst_status] != before_issue.mst_status && issue_edit[:mst_status]
mst_removed += 1 if issue_edit[:mst_status] != before_issue.mst_status && !issue_edit[:mst_status]
pact_added += 1 if issue_edit[:pact_status] != before_issue.pact_status && issue_edit[:pact_status]
pact_removed += 1 if issue_edit[:pact_status] != before_issue.pact_status && !issue_edit[:pact_status]
end
else
existing_issues = legacy_issue_params[:request_issues]
existing_issues.each do |issue_edit|
mst_added += 1 if legacy_issues_with_updated_mst_pact_status[:mst_edited].include?(issue_edit) && issue_edit[:mst_status]
mst_removed += 1 if legacy_issues_with_updated_mst_pact_status[:mst_edited].include?(issue_edit) && !issue_edit[:mst_status]
pact_added += 1 if legacy_issues_with_updated_mst_pact_status[:pact_edited].include?(issue_edit) && issue_edit[:pact_status]
pact_removed += 1 if legacy_issues_with_updated_mst_pact_status[:pact_edited].include?(issue_edit) && !issue_edit[:pact_status]
new_issues = []
removed_issues = []
end
end

# return if no edits, removals, or additions
return if (mst_added + mst_removed + pact_added + pact_removed == 0) && removed_issues.empty? && new_issues.empty?

message = []

message << "#{pact_removed} #{'issue'.pluralize(pact_removed)} unmarked as PACT" unless pact_removed == 0
message << "#{mst_removed} #{'issue'.pluralize(mst_removed)} unmarked as MST" unless mst_removed == 0
message << "#{mst_added} #{'issue'.pluralize(mst_added)} marked as MST" unless mst_added == 0
message << "#{pact_added} #{'issue'.pluralize(pact_added)} marked as PACT" unless pact_added == 0

# add in removed message and added message, if any
message << create_mst_pact_message_for_new_and_removed_issues(new_issues, "added") unless new_issues.empty?
message << create_mst_pact_message_for_new_and_removed_issues(removed_issues, "removed") unless removed_issues.empty?

message.flatten
end

# create MST/PACT message for added/removed issues
def create_mst_pact_message_for_new_and_removed_issues(issues, type)
special_issue_message = []
# check if any added/removed issues have MST/PACT and get the count
mst_count = issues.count { |issue| issue.mst_status && !issue.pact_status }
pact_count = issues.count { |issue| issue.pact_status && !issue.mst_status }
both_count = issues.count { |issue| issue.pact_status && issue.mst_status }
none_count = issues.count { |issue| !issue.pact_status && !issue.mst_status }

special_issue_message << "#{mst_count} #{'issue'.pluralize(mst_count)} with MST #{type}" unless mst_count == 0
special_issue_message << "#{pact_count} #{'issue'.pluralize(pact_count)} with PACT #{type}" unless pact_count == 0
special_issue_message << "#{both_count} #{'issue'.pluralize(both_count)} with MST and PACT #{type}" unless both_count == 0
special_issue_message << "#{none_count} #{'issue'.pluralize(none_count)} #{type}" unless none_count == 0

special_issue_message
end

# check if there is a change in mst/pact on legacy issue
# if there is a change, creat an issue update task
def legacy_mst_pact_updates
legacy_issue_params[:request_issues].each do |current_issue|
issue = appeal.issues.find { |i| i.vacols_sequence_id == current_issue[:vacols_sequence_id].to_i }

# Check for changes in mst/pact status
if issue.mst_status != current_issue[:mst_status] || issue.pact_status != current_issue[:pact_status]
# If there is a change :
# Create issue_update_task to populate casetimeline if there is a change
create_legacy_issue_update_task(issue, current_issue)

# Grab record from Vacols database to issue.
# When updating an Issue, method in IssueMapper and IssueRepo requires the attrs show below in issue_attrs:{}
record = VACOLS::CaseIssue.find_by(isskey: appeal.vacols_id, issseq: current_issue[:vacols_sequence_id])
Issue.update_in_vacols!(
vacols_id: appeal.vacols_id,
vacols_sequence_id: current_issue[:vacols_sequence_id],
issue_attrs: {
mst_status: current_issue[:mst_status] ? "Y" : "N",
pact_status: current_issue[:pact_status] ? "Y" : "N",
program: record[:issprog],
issue: record[:isscode],
level_1: record[:isslev1],
level_2: record[:isslev2],
level_3: record[:isslev3]
}
)
end
end
set_flash_mst_edit_message
render json: { issues: json_issues }, status: :ok
end

def json_issues
appeal.issues.map do |issue|
::WorkQueue::LegacyIssueSerializer.new(issue).serializable_hash[:data][:attributes]
end
end

def legacy_issues_with_updated_mst_pact_status
mst_edited = legacy_issue_params[:request_issues].find_all do |current_issue|
issue = appeal.issues.find { |i| i.vacols_sequence_id == current_issue[:vacols_sequence_id].to_i }
issue.mst_status != current_issue[:mst_status]
end
pact_edited = legacy_issue_params[:request_issues].find_all do |current_issue|
issue = appeal.issues.find { |i| i.vacols_sequence_id == current_issue[:vacols_sequence_id].to_i }
issue.pact_status != current_issue[:pact_status]
end
{mst_edited: mst_edited, pact_edited: pact_edited}
end

def legacy_issue_params
# Checks the keys for each object in request_issues array
request_issue_params = params.require("request_issues").each do |current_param|
current_param.permit(:request_issue_id,
:withdrawal_date,
:vacols_sequence_id,
:mst_status,
:pact_status,
:mst_status_update_reason_notes,
:pact_status_update_reason_notes).to_h
end

# After check, recreate safe_params object and include vacols_uniq_id
safe_params = {
request_issues: request_issue_params,
vacols_user_id: current_user.vacols_uniq_id
}
safe_params
end

def create_params
legacy_issue_params.merge(vacols_id: appeal.vacols_id)
end

def create_legacy_issue_update_task(before_issue, current_issue)
user = RequestStore[:current_user]

# close out any tasks that might be open
open_issue_task = Task.where(
assigned_to: SpecialIssueEditTeam.singleton
).where(status: "assigned").where(appeal: appeal)
open_issue_task[0].delete unless open_issue_task.empty?

task = IssuesUpdateTask.create!(
appeal: appeal,
parent: appeal.root_task,
assigned_to: SpecialIssueEditTeam.singleton,
assigned_by: user,
completed_by: user
)
# format the task instructions and close out
task.format_instructions(
"Edited Issue",
[
"Benefit Type: #{before_issue.labels[0]}\n",
"Issue: #{before_issue.labels[1..-2].join("\n")}\n",
"Code: #{[before_issue.codes[-1], before_issue.labels[-1]].join(" - ")}\n",
"Note: #{before_issue.note}\n",
"Disposition: #{before_issue.readable_disposition}\n"
].compact.join("\r\n"),
"",
before_issue.mst_status,
before_issue.pact_status,
current_issue[:mst_status],
current_issue[:pact_status]
)
task.completed!

# create SpecialIssueChange record to log the changes
SpecialIssueChange.create!(
issue_id: before_issue.id,
appeal_id: appeal.id,
appeal_type: "LegacyAppeal",
task_id: task.id,
created_at: Time.zone.now.utc,
created_by_id: RequestStore[:current_user].id,
created_by_css_id: RequestStore[:current_user].css_id,
original_mst_status: before_issue.mst_status,
original_pact_status: before_issue.pact_status,
updated_mst_status: current_issue[:mst_status],
updated_pact_status: current_issue[:pact_status],
change_category: "Edited Issue"
)
end

# updated flash message to show mst/pact message if mst/pact changes (not to legacy)
def set_flash_success_message
return set_flash_mst_edit_message if mst_pact_changes? &&
(FeatureToggle.enabled?(:mst_identification) ||
FeatureToggle.enabled?(:pact_identification))

set_flash_edit_message
end

# create success message with added and removed issues
def set_flash_mst_edit_message
flash[:mst_pact_edited] = mst_and_pact_edited_issues
end

def set_flash_edit_message
flash[:edited] = if request_issues_update.after_issues.empty?
review_removed_message
elsif (request_issues_update.after_issues - request_issues_update.withdrawn_issues).empty?
Expand Down Expand Up @@ -395,4 +620,3 @@ def get_appeal_object(appeals_id)
end
end
end

7 changes: 5 additions & 2 deletions app/controllers/case_reviews_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def set_application
end

def complete
result = CompleteCaseReview.new(case_review_class: case_review_class, params: complete_params).call

new_complete_case_review = CompleteCaseReview.new(case_review_class: case_review_class, params: complete_params)
result = new_complete_case_review.call
if result.success?
case_review = result.extra[:case_review]
render json: {
Expand Down Expand Up @@ -74,13 +74,16 @@ def judge_case_review_params

def issues_params
# This is a combined list of params for ama and legacy appeals
# Reprsents the information the front end is sending to create a decision issue object
[
:id,
:disposition,
:description,
:readjudication,
:benefit_type,
:diagnostic_code,
:mst_status,
:pact_status,
request_issue_ids: [],
remand_reasons: [
:code,
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/intakes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class IntakesController < ApplicationController

def index
no_cache

respond_to do |format|
format.html { render(:index) }
end
Expand Down Expand Up @@ -43,6 +42,7 @@ def destroy
def review
if intake.review!(params)
render json: intake.ui_hash

else
render json: { error_codes: intake.review_errors }, status: :unprocessable_entity
end
Expand Down Expand Up @@ -97,6 +97,7 @@ def index_props
{
userDisplayName: current_user.display_name,
userCanIntakeAppeals: current_user.can_intake_appeals?,
userCanEditIntakeIssues: current_user.can_edit_intake_issues?,
serverIntake: intake_ui_hash,
dropdownUrls: dropdown_urls,
applicationUrls: application_urls,
Expand Down Expand Up @@ -150,6 +151,10 @@ def feature_toggle_ui_hash
filedByVaGovHlr: FeatureToggle.enabled?(:filed_by_va_gov_hlr, user: current_user),
updatedIntakeForms: FeatureToggle.enabled?(:updated_intake_forms, user: current_user),
eduPreDocketAppeals: FeatureToggle.enabled?(:edu_predocket_appeals, user: current_user),
mstIdentification: FeatureToggle.enabled?(:mst_identification, user: current_user),
pactIdentification: FeatureToggle.enabled?(:pact_identification, user: current_user),
legacyMstPactIdentification: FeatureToggle.enabled?(:legacy_mst_pact_identification, user: current_user),
justificationReason: FeatureToggle.enabled?(:justification_reason, user: current_user),
updatedAppealForm: FeatureToggle.enabled?(:updated_appeal_form, user: current_user),
hlrScUnrecognizedClaimants: FeatureToggle.enabled?(:hlr_sc_unrecognized_claimants, user: current_user),
vhaClaimReviewEstablishment: FeatureToggle.enabled?(:vha_claim_review_establishment, user: current_user)
Expand Down
Loading

0 comments on commit b058136

Please sign in to comment.