Skip to content

Commit

Permalink
Merge branch 'feature/APPEALS-24914' into piedram/APPEALS-30712
Browse files Browse the repository at this point in the history
  • Loading branch information
cacevesva authored Sep 22, 2023
2 parents a1cc12d + b659eca commit 77969be
Show file tree
Hide file tree
Showing 124 changed files with 3,425 additions and 734 deletions.
1 change: 1 addition & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,4 @@ exclude_patterns:
- 'tmp/**/*'
- 'app/assets/**/*'
- 'client/test/data/camoQueueConfigData.js'
- 'client/app/intake/components/mockData/issueListProps.js'
2 changes: 1 addition & 1 deletion app/controllers/appeals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def review_removed_message
end

def review_withdrawn_message
"You have successfully withdrawn a review."
COPY::CLAIM_REVIEW_WITHDRAWN_MESSAGE
end

def withdrawn_issues
Expand Down
38 changes: 35 additions & 3 deletions app/controllers/claim_review_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def render_success
if claim_review.processed_in_caseflow?
set_flash_success_message

render json: { redirect_to: claim_review.business_line.tasks_url,
render json: { redirect_to: claim_review.redirect_url,
beforeIssues: request_issues_update.before_issues.map(&:serialize),
afterIssues: request_issues_update.after_issues.map(&:serialize),
withdrawnIssues: request_issues_update.withdrawn_issues.map(&:serialize) }
Expand Down Expand Up @@ -136,24 +136,56 @@ def review_edited_message
"You have successfully " + [added_issues, removed_issues, withdrawn_issues].compact.to_sentence + "."
end

def vha_edited_decision_date_message
COPY::VHA_ADD_DECISION_DATE_TO_ISSUE_SUCCESS_MESSAGE
end

def vha_established_message
"You have successfully established #{claimant_name}'s #{claim_review.class.review_title}"
end

def claimant_name
if claim_review.veteran_is_not_claimant
claim_review.claimant.try(:name)
else
claim_review.veteran_full_name
end
end

def vha_flash_message
issues_without_decision_date = (request_issues_update.after_issues -
request_issues_update.edited_issues -
request_issues_update.removed_or_withdrawn_issues)
.select { |issue| issue.decision_date.blank? && !issue.withdrawn? }

if issues_without_decision_date.empty?
vha_established_message
elsif request_issues_update.edited_issues.any?
vha_edited_decision_date_message
else
review_edited_message
end
end

def set_flash_success_message
flash[:edited] = if request_issues_update.after_issues.empty?
decisions_removed_message
elsif (request_issues_update.after_issues - request_issues_update.withdrawn_issues).empty?
review_withdrawn_message
elsif claim_review.benefit_type == "vha"
vha_flash_message
else
review_edited_message
end
end

def decisions_removed_message
claimant_name = claim_review.veteran_full_name
"You have successfully removed #{claim_review.class.review_title} for #{claimant_name}
(ID: #{claim_review.veteran.ssn})."
end

def review_withdrawn_message
"You have successfully withdrawn a review."
COPY::CLAIM_REVIEW_WITHDRAWN_MESSAGE
end

def claim_label_edit_params
Expand Down
38 changes: 30 additions & 8 deletions app/controllers/decision_reviews_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ class DecisionReviewsController < ApplicationController
before_action :verify_access, :react_routed, :set_application
before_action :verify_veteran_record_access, only: [:show]

delegate :in_progress_tasks,
delegate :incomplete_tasks,
:incomplete_tasks_type_counts,
:incomplete_tasks_issue_type_counts,
:in_progress_tasks,
:in_progress_tasks_type_counts,
:in_progress_tasks_issue_type_counts,
:completed_tasks,
:completed_tasks_type_counts,
:completed_tasks_issue_type_counts,
:included_tabs,
to: :business_line

SORT_COLUMN_MAPPINGS = {
Expand Down Expand Up @@ -82,11 +86,28 @@ def business_line
end

def task_filter_details
task_filter_hash = {}
included_tabs.each do |tab_name|
case tab_name
when :incomplete
task_filter_hash[:incomplete] = incomplete_tasks_type_counts
task_filter_hash[:incomplete_issue_types] = incomplete_tasks_issue_type_counts
when :in_progress
task_filter_hash[:in_progress] = in_progress_tasks_type_counts
task_filter_hash[:in_progress_issue_types] = in_progress_tasks_issue_type_counts
when :completed
task_filter_hash[:completed] = completed_tasks_type_counts
task_filter_hash[:completed_issue_types] = completed_tasks_issue_type_counts
else
fail NotImplementedError "Tab name type not implemented for this business line: #{business_line}"
end
end
task_filter_hash
end

def business_line_config_options
{
in_progress: in_progress_tasks_type_counts,
completed: completed_tasks_type_counts,
in_progress_issue_types: in_progress_tasks_issue_type_counts,
completed_issue_types: completed_tasks_issue_type_counts
tabs: included_tabs
}
end

Expand All @@ -101,7 +122,7 @@ def update_power_of_attorney
render_error(error)
end

helper_method :task_filter_details, :business_line, :task
helper_method :task_filter_details, :business_line, :task, :business_line_config_options

private

Expand All @@ -122,13 +143,14 @@ def decision_issue_params
def queue_tasks
tab_name = allowed_params[Constants.QUEUE_CONFIG.TAB_NAME_REQUEST_PARAM.to_sym]

return missing_tab_parameter_error unless tab_name

sort_by_column = SORT_COLUMN_MAPPINGS[allowed_params[Constants.QUEUE_CONFIG.SORT_COLUMN_REQUEST_PARAM.to_sym]]

tasks = case tab_name
when "incomplete" then incomplete_tasks(pagination_query_params(sort_by_column))
when "in_progress" then in_progress_tasks(pagination_query_params(sort_by_column))
when "completed" then completed_tasks(pagination_query_params(sort_by_column))
when nil
return missing_tab_parameter_error
else
return unrecognized_tab_name_error
end
Expand Down
23 changes: 19 additions & 4 deletions app/controllers/intakes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ def review

def complete
intake.complete!(params)

if !detail.is_a?(Appeal) && detail.try(:processed_in_caseflow?)
flash[:success] = success_message
render json: { serverIntake: { redirect_to: detail.business_line.tasks_url } }
flash[:success] = (detail.benefit_type == "vha") ? vha_success_message : success_message
render json: { serverIntake: { redirect_to: detail.try(:redirect_url) || business_line.tasks_url } }
else
render json: intake.ui_hash
end
Expand Down Expand Up @@ -188,9 +189,23 @@ def detail
@detail ||= intake&.detail
end

def claimant_name
if detail.veteran_is_not_claimant
detail.claimant.try(:name)
else
detail.veteran_full_name
end
end

def success_message
claimant_name = detail.veteran_full_name
claimant_name = detail.claimant.try(:name) if detail.veteran_is_not_claimant
"#{claimant_name} (Veteran SSN: #{detail.veteran.ssn}) #{detail.class.review_title} has been processed."
end

def vha_success_message
if detail.request_issues_without_decision_dates?
"You have successfully saved #{claimant_name}'s #{detail.class.review_title}"
else
"You have successfully established #{claimant_name}'s #{detail.class.review_title}"
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def create
tasks << valid_task_classes[task_type.to_sym].create_many_from_params(param_group, current_user)
end
# This should be the JudgeDecisionReviewTask
parent_task = Task.find_by(id: params[:tasks].first[:parent_id]) if params[:tasks].first[:type] == "AttorneyRewriteTask"
parent_task = Task.find_by(id: params[:tasks]&.first[:parent_id]) if params[:tasks]&.first[:type] == "AttorneyRewriteTask"
if parent_task&.appeal&.is_a?(LegacyAppeal)
QueueRepository.reassign_decass_to_attorney!(
judge: parent_task.assigned_to,
Expand Down
3 changes: 0 additions & 3 deletions app/jobs/decision_review_process_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ class DecisionReviewProcessJob < CaseflowJob
application_attr :intake

def perform(thing_to_establish)
# Temporarily stop establishing claims due to VBMS bug
return if FeatureToggle.enabled?(:disable_claim_establishment, user: RequestStore.store[:current_user])

@decision_review = thing_to_establish

# If establishment is for a RequestIssuesUpdate, use the user on the update
Expand Down
41 changes: 27 additions & 14 deletions app/jobs/populate_end_product_sync_queue_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,40 @@ def perform

attr_accessor :job_expected_end_time, :should_stop_job

# rubocop:disable Metrics/MethodLength
def find_priority_end_product_establishments_to_sync
get_batch = <<-SQL
select id
from end_product_establishments
inner join vbms_ext_claim
on end_product_establishments.reference_id = vbms_ext_claim."CLAIM_ID"::varchar
where (end_product_establishments.synced_status <> vbms_ext_claim."LEVEL_STATUS_CODE" or end_product_establishments.synced_status is null)
and vbms_ext_claim."LEVEL_STATUS_CODE" in ('CLR','CAN')
and end_product_establishments.id not in (select end_product_establishment_id from priority_end_product_sync_queue)
limit #{BATCH_LIMIT};
get_sql = <<-SQL
WITH priority_eps AS (
SELECT vec."CLAIM_ID"::varchar, vec."LEVEL_STATUS_CODE"
FROM vbms_ext_claim vec
WHERE vec."LEVEL_STATUS_CODE" in ('CLR', 'CAN')
AND (vec."EP_CODE" LIKE '04%' OR vec."EP_CODE" LIKE '03%' OR vec."EP_CODE" LIKE '93%' OR vec."EP_CODE" LIKE '68%')
),
priority_queued_epe_ids AS (
SELECT end_product_establishment_id
FROM priority_end_product_sync_queue)
SELECT id
FROM end_product_establishments epe
INNER JOIN priority_eps
ON epe.reference_id = priority_eps."CLAIM_ID"
WHERE (epe.synced_status is null or epe.synced_status <> priority_eps."LEVEL_STATUS_CODE")
AND NOT EXISTS (SELECT end_product_establishment_id
FROM priority_queued_epe_ids
WHERE priority_queued_epe_ids.end_product_establishment_id = epe.id)
LIMIT #{BATCH_LIMIT};
SQL

ActiveRecord::Base.connection.exec_query(ActiveRecord::Base.sanitize_sql(get_batch)).rows.flatten
ActiveRecord::Base.connection.exec_query(ActiveRecord::Base.sanitize_sql(get_sql)).rows.flatten
end
# rubocop:enable Metrics/MethodLength

def insert_into_priority_sync_queue(batch)
batch.each do |ep_id|
PriorityEndProductSyncQueue.create!(
end_product_establishment_id: ep_id
)
priority_end_product_sync_queue_records = batch.map do |ep_id|
PriorityEndProductSyncQueue.new(end_product_establishment_id: ep_id)
end

# Bulk insert PriorityEndProductSyncQueue records in a single SQL statement
PriorityEndProductSyncQueue.import(priority_end_product_sync_queue_records)
Rails.logger.info("PopulateEndProductSyncQueueJob EPEs processed: #{batch} - Time: #{Time.zone.now}")
end

Expand Down
13 changes: 13 additions & 0 deletions app/models/batch_processes/priority_ep_sync_batch_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def process_batch!
end

batch_complete!
destroy_synced_records_from_queue!
end
# rubocop:enable Metrics/MethodLength

Expand All @@ -82,4 +83,16 @@ def assign_batch_to_queued_records!(records)
last_batched_at: Time.zone.now)
end
end

private

# Purpose: Destroys "SYNCED" PEPSQ records to limit the growing number of table records.
# This functionality is needed for the PopulateEndProductSyncQueueJob query to be performant.
#
# Params: None
#
# Response: Log message stating newly destroyed PEPSQ records
def destroy_synced_records_from_queue!
PriorityEndProductSyncQueue.destroy_batch_process_pepsq_records!(self)
end
end
29 changes: 29 additions & 0 deletions app/models/claim_review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,37 @@ def add_user_to_business_line!
business_line.add_user(RequestStore.store[:current_user])
end

def handle_issues_with_no_decision_date!
# Guard clause to only perform this update for VHA claim reviews for now
return nil if benefit_type != "vha"

if request_issues_without_decision_dates?
review_task = tasks.find { |task| task.is_a?(DecisionReviewTask) }
review_task&.on_hold!
elsif !request_issues_without_decision_dates?
review_task = tasks.find { |task| task.is_a?(DecisionReviewTask) }
review_task&.assigned!
end
end

def request_issues_without_decision_dates?
request_issues.active.any? { |issue| issue.decision_date.blank? }
end

def create_business_line_tasks!
create_decision_review_task! if processed_in_caseflow?

tasks.reload

handle_issues_with_no_decision_date!
end

def redirect_url
if benefit_type == "vha" && request_issues_without_decision_dates?
"#{business_line.tasks_url}?tab=incomplete"
else
business_line.tasks_url
end
end

# Idempotent method to create all the artifacts for this claim.
Expand Down
6 changes: 5 additions & 1 deletion app/models/concerns/has_business_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ module HasBusinessLine

def business_line
business_line_name = Constants::BENEFIT_TYPES[benefit_type]
@business_line ||= BusinessLine.find_or_create_by(name: business_line_name) { |org| org.url = benefit_type }
@business_line ||= if benefit_type == "vha"
VhaBusinessLine.singleton
else
BusinessLine.find_or_create_by(name: business_line_name) { |org| org.url = benefit_type }
end
end

def processed_in_vbms?
Expand Down
1 change: 0 additions & 1 deletion app/models/judge_case_assignment_to_attorney.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class JudgeCaseAssignmentToAttorney
attr_accessor :appeal_id, :assigned_to, :task_id, :assigned_by, :judge

validates :assigned_by, :assigned_to, presence: true
validates :task_id, format: { with: /\A[0-9A-Z]+-[0-9]{4}-[0-9]{2}-[0-9]{2}\Z/i }, allow_blank: true
validate :assigned_by_role_is_valid

def assign_to_attorney!
Expand Down
4 changes: 2 additions & 2 deletions app/models/membership_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def requesting_vha_predocket_access?

def check_request_for_automatic_addition_to_vha_businessline(deciding_user)
if requesting_vha_predocket_access?
vha_business_line = BusinessLine.find_by(url: "vha")
vha_business_line = VhaBusinessLine.singleton

# If the requestor also has an outstanding membership request to the vha_businessline approve it
# If the requestor also has an outstanding membership request to the vha_business_line approve it
# Also send an approval email
vha_business_line_request = requestor.membership_requests.assigned.find_by(organization: vha_business_line)
vha_business_line_request&.update_status_and_send_email("approved", deciding_user, "VHA")
Expand Down
Loading

0 comments on commit 77969be

Please sign in to comment.