Skip to content

Commit

Permalink
APPEALS-61173 (#23434)
Browse files Browse the repository at this point in the history
* APPEALS-61173 - Improve trascription dispatch search for legacy hearings

* APPEALS-61173 - Use transcription file searching to improve transcription package search

* APPEALS-61173 - Updated rspec coverage

* APPEALS-61173 - Updated transcription files and packages seeds

* APPEALS-61173 - Test search fields on the front end
  • Loading branch information
adam-ducker authored and breedbah committed Nov 19, 2024
1 parent 5a94424 commit 69bc6c9
Show file tree
Hide file tree
Showing 29 changed files with 397 additions and 85 deletions.
18 changes: 9 additions & 9 deletions app/controllers/hearings/transcription_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def render_page_not_found
end

def transcription_file_tasks
@transcription_files = Hearings::TranscriptionFile.filterable_values
@transcription_files = TranscriptionFile.filterable_values
select_based_on_tab
apply_search
apply_filters
Expand All @@ -34,7 +34,7 @@ def transcription_file_tasks
end

def locked
locked_files = Hearings::TranscriptionFile.locked.preload(:locked_by)
locked_files = TranscriptionFile.locked.preload(:locked_by)
files = []
locked_files.each do |file|
status = file.locked_by_id == current_user.id ? "selected" : "locked"
Expand All @@ -46,7 +46,7 @@ def locked
end

def lock
files = Hearings::TranscriptionFile.where(id: params[:file_ids])
files = TranscriptionFile.where(id: params[:file_ids])
status = params[:status] && params[:status].to_s == "true" ? true : false
lockable_file_ids = []
files.each do |file|
Expand All @@ -63,7 +63,7 @@ def lock
locked_at = nil
end

Hearings::TranscriptionFile.where(id: lockable_file_ids).update_all(
TranscriptionFile.where(id: lockable_file_ids).update_all(
locked_by_id: locked_by_id, locked_at: locked_at
)

Expand All @@ -81,7 +81,7 @@ def format_docket_number(file)
def selected_files_info
files = []
ids = params[:file_ids].split(",")
Hearings::TranscriptionFile.where(id: ids).filterable_values.each do |transcription_file|
TranscriptionFile.where(id: ids).filterable_values.each do |transcription_file|
hearing = transcription_file.hearing
files << {
id: transcription_file.id,
Expand All @@ -102,7 +102,7 @@ def selected_files_info

def fetch_file
docket_number = params[:docket_number]
file_path = Hearings::TranscriptionFile.fetch_file_by_docket_and_type(docket_number)
file_path = TranscriptionFile.fetch_file_by_docket_and_type(docket_number)

if file_path
send_file file_path, filename: File.basename(file_path), type: "application/vnd.ms-excel"
Expand All @@ -114,7 +114,7 @@ def fetch_file
private

def file
@file ||= Hearings::TranscriptionFile.find(params[:file_id])
@file ||= TranscriptionFile.find(params[:file_id])
end

def select_based_on_tab
Expand Down Expand Up @@ -178,7 +178,7 @@ def setup_pagination
@transcription_files = @transcription_files
.limit(@page_size)
.offset(@page_start)
.preload(hearing: [:hearing_day, :appeal])
.preload(transcription: [transcription_package: [:contractor]], hearing: [:hearing_day, :appeal])
end

def build_transcription_json(transcription_files)
Expand Down Expand Up @@ -218,7 +218,7 @@ def add_all_tab_fields(task, transcription_file)
task.merge(
{
workOrder: transcription_file.transcription&.task_number,
uploadDate: transcription_file&.date_returned_box&.to_formatted_s(:short_date),
uploadDate: transcription_file&.date_upload_box&.to_formatted_s(:short_date),
returnDate: transcription_file.date_returned_box&.to_formatted_s(:short_date),
contractor: transcription_file&.transcription&.transcription_package&.contractor&.name
}
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/hearings/download_transcription_file_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def docket_number
#
# Returns: TranscriptionFile object
def find_or_create_transcription_file(file_name_arg = file_name)
Hearings::TranscriptionFile.find_or_create_by(
TranscriptionFile.find_or_create_by(
file_name: file_name_arg,
hearing_id: hearing.id,
hearing_type: hearing.class.name,
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/hearings/monitor_box_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def net_new_files
end

def most_recent_returned_file_time
Hearings::TranscriptionFile.maximum(:date_returned_box)
TranscriptionFile.maximum(:date_returned_box)
end

def find_webex_formatted_files(files)
Expand Down
4 changes: 2 additions & 2 deletions app/jobs/hearings/va_box_download_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def extract_file_extension(file_name)
end

def update_database(current_information, file_status)
transcription_records = Hearings::TranscriptionFile.where(
transcription_records = TranscriptionFile.where(
hearing_id: current_information["id"].to_i,
hearing_type: current_information["hearing_type"],
file_type: current_information["file_type"]
Expand Down Expand Up @@ -111,7 +111,7 @@ def create_transcription_file_record(current_information, file_status, aws_link)
end

def add_transcription_file_record(current_information, file_status, aws_link, transcription_id)
Hearings::TranscriptionFile.create!(
TranscriptionFile.create!(
hearing_id: current_information["id"],
hearing_type: current_information["hearing_type"],
docket_number: current_information["docket_number"],
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/hearings/va_box_upload_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def create_to_box(box_service, local_file_path, child_folder_id, transcription_p
# rubocop:enable Metrics/ParameterLists, Metrics/MethodLength

def update_transcription_files(hearing, file_info, transcription_package)
Hearings::TranscriptionFile.where(
TranscriptionFile.where(
hearing_id: hearing[:hearing_id], hearing_type: hearing[:hearing_type]
).update_all(
date_upload_box: Time.current,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def format_creation_date(file_path)
end

def create_and_upload_transcription_file(hearing, file_path)
Hearings::TranscriptionFile.create!(
TranscriptionFile.create!(
file_name: File.basename(file_path),
hearing_id: hearing.id,
hearing_type: hearing.class.name,
Expand Down
2 changes: 1 addition & 1 deletion app/models/hearing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Hearing < CaseflowRecord
has_many :hearing_issue_notes
has_many :email_events, class_name: "SentHearingEmailEvent"
has_many :email_recipients, class_name: "HearingEmailRecipient"
has_many :transcription_files, class_name: "Hearings::TranscriptionFile", as: :hearing
has_many :transcription_files, class_name: "TranscriptionFile", as: :hearing

class HearingDayFull < StandardError; end

Expand Down
2 changes: 1 addition & 1 deletion app/models/hearings/transcription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Transcription < CaseflowRecord
belongs_to :hearing, polymorphic: true
belongs_to :legacy_hearing, polymorphic: true
belongs_to :transcription_contractor
has_many :transcription_files, class_name: "Hearings::TranscriptionFile"
has_many :transcription_files, class_name: "TranscriptionFile"
belongs_to :transcription_package, foreign_key: :task_number, primary_key: :task_number
before_create :sequence_task_id

Expand Down
53 changes: 45 additions & 8 deletions app/models/hearings/transcription_file.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Hearings::TranscriptionFile < CaseflowRecord
class TranscriptionFile < CaseflowRecord
belongs_to :hearing, polymorphic: true

belongs_to :transcription
Expand Down Expand Up @@ -29,7 +29,7 @@ class Hearings::TranscriptionFile < CaseflowRecord
transcription_files.hearing_type = 'LegacyHearing'")
.joins("LEFT OUTER JOIN appeals ON hearings.appeal_id = appeals.id AND
transcription_files.hearing_type = 'Hearing'")
.joins("LEFT OUTER JOIN legacy_appeals ON hearings.appeal_id = legacy_appeals.id AND
.joins("LEFT OUTER JOIN legacy_appeals ON legacy_hearings.appeal_id = legacy_appeals.id AND
transcription_files.hearing_type = 'LegacyHearing'")
.joins("LEFT OUTER JOIN advance_on_docket_motions AS aodm ON
((aodm.appeal_id = appeals.id AND aodm.appeal_type = 'Appeal') OR
Expand All @@ -40,14 +40,19 @@ class Hearings::TranscriptionFile < CaseflowRecord
.joins("LEFT OUTER JOIN claimants ON claimants.decision_review_id = appeals.id AND
claimants.decision_review_type = 'Appeal'")
.joins("LEFT OUTER JOIN people ON people.participant_id = claimants.participant_id")
.joins("LEFT OUTER JOIN veterans ON veterans.file_number = appeals.veteran_file_number")
.joins("LEFT OUTER JOIN veterans ON
veterans.file_number = appeals.veteran_file_number OR legacy_appeals.vbms_id ~ veterans.file_number")
.joins("LEFT OUTER JOIN transcriptions ON transcriptions.id = transcription_files.transcription_id")
.joins("LEFT OUTER JOIN transcription_packages ON
transcription_packages.task_number = transcriptions.task_number")
}

scope :unassigned, -> { where(file_status: Constants.TRANSCRIPTION_FILE_STATUSES.upload.success) }
scope :unassigned, lambda {
where("transcription_packages.status IS NULL")
}

scope :completed, lambda {
where(file_status: ["Successful upload (AWS)", "Failed Retrieval (BOX)", "Overdue"])
where("transcription_packages.status IN ('Successful Retrieval (BOX)', 'Failed Retrieval (BOX)', 'Overdue')")
}

scope :filter_by_hearing_type, ->(values) { where("transcription_files.hearing_type IN (?)", values) }
Expand Down Expand Up @@ -91,11 +96,19 @@ class Hearings::TranscriptionFile < CaseflowRecord
}

scope :search, lambda { |search|
legacy_hearing_ids = legacy_hearing_ids_from_vacols_name(search)
legacy_search = ""
if !legacy_hearing_ids.empty?
legacy_search = "(transcription_files.hearing_type = 'LegacyHearing'
AND transcription_files.hearing_id IN (" + legacy_hearing_ids.join(",") + ")) OR"
end

where("(docket_number LIKE :query) OR
(LOWER(CONCAT_WS(' ', people.first_name, people.last_name)) LIKE :query) OR
(LOWER(CONCAT_WS(' ', veterans.first_name, veterans.last_name)) LIKE :query) OR
(veterans.file_number LIKE :query) OR
(LOWER(transcriptions.task_number) LIKE :query)", query: "%#{search.downcase.strip}%")
(veterans.file_number LIKE :query) OR " +
legacy_search +
"(LOWER(transcriptions.task_number) LIKE :query)", query: "%#{search.downcase.strip}%")
}

scope :order_by_id, ->(direction) { order(Arel.sql("id " + direction)) }
Expand Down Expand Up @@ -232,10 +245,34 @@ def self.reset_files(task_number)
transcription = Transcription.find_by(task_number: task_number)
return unless transcription

transcription_files = Hearings::TranscriptionFile.where(transcription_id: transcription.id)
transcription_files = TranscriptionFile.where(transcription_id: transcription.id)

transcription_files.each do |file|
file.update(file_status: "Successful upload (AWS)", date_upload_box: nil)
end
end

def self.legacy_hearing_ids_from_vacols_name(query)
legacy_hearing_ids = []

# look in VACOLS CORRES table for veterans names that match and return the IDs
vacols_ids = MetricsService.record(
"VACOLS: Get ID values from Correspondents for transcription dispatch search",
name: "TranscriptionFile"
) do
VACOLS::Correspondent
.where("(LOWER(snamef) || ' ' || LOWER(snamel)) LIKE :query", query: "%#{query.downcase.strip}%")
.pluck(:stafkey)
end

# find any legacy hearings that have an appeal matching those VACOLS IDs
if vacols_ids.length
legacy_hearing_ids = LegacyHearing
.where("legacy_appeals.vacols_id IN ('" + vacols_ids.join("','") + "')")
.joins("LEFT OUTER JOIN legacy_appeals ON appeal_id = legacy_appeals.id")
.pluck(:id)
end

legacy_hearing_ids
end
end
17 changes: 16 additions & 1 deletion app/models/hearings/transcription_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,22 @@ class TranscriptionPackage < CaseflowRecord

scope :filter_by_status, ->(values) { where(status: values) }

scope :search, ->(search) { where("LOWER(task_number) LIKE :query", query: "%#{search.downcase.strip}%") }
scope :search, lambda { |search|
# find transcription files that match the search
transcription_ids = TranscriptionFile
.filterable_values.search(search).pluck(:transcription_id)
if transcription_ids.empty?
transcription_ids = [-1]
end

# find task numbers for those transcriptions
task_numbers = Transcription.where(id: transcription_ids).pluck(:task_number)
if task_numbers.empty?
task_numbers = [-1]
end

where(task_number: task_numbers)
}

scope :order_by_field, ->(direction, field_name) { order(Arel.sql(field_name + " " + direction)) }

Expand Down
2 changes: 1 addition & 1 deletion app/models/legacy_hearing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class LegacyHearing < CaseflowRecord
has_one :transcription, -> { order(created_at: :desc) }
has_many :email_events, class_name: "SentHearingEmailEvent", foreign_key: :hearing_id
has_many :email_recipients, class_name: "HearingEmailRecipient", foreign_key: :hearing_id
has_many :transcription_files, class_name: "Hearings::TranscriptionFile", as: :hearing
has_many :transcription_files, class_name: "TranscriptionFile", as: :hearing
has_many :transcriptions, as: :hearing

alias_attribute :location, :hearing_location
Expand Down
2 changes: 1 addition & 1 deletion app/models/transcription_work_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def self.update_transcription_files(task_number)
transcription_file_ids = fetch_transcription_file_ids(task_number)
return if transcription_file_ids.empty?

Hearings::TranscriptionFile.where(id: transcription_file_ids).update_all(
TranscriptionFile.where(id: transcription_file_ids).update_all(
date_upload_box: nil,
file_status: "Successful upload (AWS)",
updated_by_id: current_user.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Hearings::TranscriptionPackageSerializer
class TranscriptionPackageSerializer
include FastJsonapi::ObjectSerializer

set_key_transform :camel_lower
Expand Down
2 changes: 1 addition & 1 deletion client/COPY.json
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@
"TRANSCRIPTION_FILE_DISPATCH_UNASSIGNED_TAB_DESCRIPTION": "Hearing audio files owned by the Transcription team that are unassigned to a contractor:",
"TRANSCRIPTION_FILE_DISPATCH_UNASSIGNED_TAB_SEARCH": "Search by Docket Number, Claimant Name or File Number",
"TRANSCRIPTION_FILE_DISPATCH_UNASSIGNED_TAB_PROMPT": "Please select the files you would like to dispatch for transcription:",
"TRANSCRIPTION_FILE_DISPATCH_ASSIGNED_TAB_SEARCH": "Search by Work Order",
"TRANSCRIPTION_FILE_DISPATCH_ASSIGNED_TAB_SEARCH": "Search by Work Order, Claimant Name, Docket Number and File Number",
"TRANSCRIPTION_FILE_DISPATCH_ASSIGNED_TAB_DESCRIPTION": "Work orders owned by the Transcription team that have been sent to a contractor:",
"TRANSCRIPTION_FILE_DISPATCH_COMPLETED_TAB_SEARCH": "Search by Work Order or Docket Number",
"TRANSCRIPTION_FILE_DISPATCH_COMPLETED_TAB_DESCRIPTION": "Work orders owned by the Transcription team that have been returned from a contractor:",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ export const TranscriptionFileDispatchView = ({ organizations }) => {

const handleSearchBarSubmit = () => {
// use saved search input value and update URL params and pass search to children
// making sure to reset page to 1 as well to avoid weird page states

const currentParams = new URLSearchParams(window.location.search);

currentParams.set('page', 1);
currentParams.set('search', searchInput);
const qs = currentParams.toString();

Expand Down
Loading

0 comments on commit 69bc6c9

Please sign in to comment.