Skip to content

Commit

Permalink
Add hearing to original_request_type/changed_request_type database fi…
Browse files Browse the repository at this point in the history
…elds and accompanying code (#16049)

Resolves #15880

### Description
Renamed `original_request_type` to `original_hearing_request_type` and `changed_request_type` to `changed_hearing_request_type` in the database and throughout the codebase.

### Acceptance Criteria
- [ ] Code compiles correctly

### Database Changes

* [ ] Column comments updated
* [ ] Have your migration classes inherit from `Caseflow::Migration`, especially when adding indexes (use `add_safe_index`)
* [ ] Verify that `migrate:rollback` works as desired ([`change` supported functions](https://edgeguides.rubyonrails.org/active_record_migrations.html#using-the-change-method))
* [ ] Query profiling performed (eyeball Rails log, check bullet and fasterer output)
* [ ] Appropriate indexes added (especially for foreign keys, polymorphic columns, unique constraints, and Rails scopes)
* [ ] DB schema docs updated with `make docs` (after running `make migrate`)
* [ ] #appeals-schema notified with summary and link to this PR
  • Loading branch information
Jeremy1026 authored Apr 5, 2021
1 parent 95f5aec commit c4e7af1
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 94 deletions.
37 changes: 21 additions & 16 deletions app/models/concerns/hearing_request_type_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module HearingRequestTypeConcern

included do
# Add Paper Trail configuration
has_paper_trail only: [:changed_request_type], on: [:update]
has_paper_trail only: [:changed_hearing_request_type], on: [:update]

validates :changed_request_type,
validates :changed_hearing_request_type,
inclusion: {
in: [
HearingDay::REQUEST_TYPES[:central],
Expand All @@ -18,21 +18,22 @@ module HearingRequestTypeConcern
},
allow_nil: true

validates :original_request_type,
validates :original_hearing_request_type,
inclusion: {
in: %w[central central_office travel_board video virtual],
message: "original request type (%<value>s) is invalid"
},
allow_nil: true
end

# uses the paper_trail version on LegacyAppeal
def latest_appeal_event
TaskEvent.new(version: versions.last) if versions.any?
def last_converted_by
if versions.any?
versions.last.whodunnit.present? ? User.find(versions.last.whodunnit) : User.new
end
end

def original_hearing_request_type
return original_request_type.to_sym if original_request_type.present?
def formatted_original_hearing_request_type
return original_hearing_request_type.to_sym if original_hearing_request_type.present?

# Use the VACOLS value for LegacyAppeals, otherwise use the closest regional office
original = is_a?(LegacyAppeal) ? hearing_request_type : closest_regional_office
Expand All @@ -41,15 +42,17 @@ def original_hearing_request_type
end

def readable_original_hearing_request_type
LegacyAppeal::READABLE_HEARING_REQUEST_TYPES[original_hearing_request_type]
LegacyAppeal::READABLE_HEARING_REQUEST_TYPES[formatted_original_hearing_request_type]
end

def remember_original_hearing_request_type
update!(original_request_type: original_hearing_request_type&.to_s) if original_request_type.blank?
if original_hearing_request_type.blank?
update!(original_hearing_request_type: formatted_original_hearing_request_type&.to_s)
end
end

def current_hearing_request_type
format_or_formatted_original_request_type(changed_request_type)
format_or_formatted_original_hearing_request_type(changed_hearing_request_type)
end

def readable_current_hearing_request_type
Expand All @@ -73,25 +76,27 @@ def readable_current_hearing_request_type_for_task(task_id)
private

def previous_hearing_request_type_for_task(task_id)
format_or_formatted_original_request_type(changeset_at_index_for_task(task_id)&.first)
format_or_formatted_original_hearing_request_type(changeset_at_index_for_task(task_id)&.first)
end

def current_hearing_request_type_for_task(task_id)
format_or_formatted_original_request_type(changeset_at_index_for_task(task_id)&.last)
format_or_formatted_original_hearing_request_type(changeset_at_index_for_task(task_id)&.last)
end

def changeset_at_index_for_task(task_id)
request_type_index = tasks.where(type: "ChangeHearingRequestTypeTask").order(:id).map(&:id).index(task_id)
return nil if request_type_index.blank?

versions[request_type_index].changeset["changed_request_type"]
# support versions that were recorded before the column name changed
versions[request_type_index].changeset["changed_hearing_request_type"] ||
versions[request_type_index].changeset["changed_request_type"]
end

def format_or_formatted_original_request_type(request_type)
def format_or_formatted_original_hearing_request_type(request_type)
if request_type.present?
format_hearing_request_type(request_type)
else
original_hearing_request_type
formatted_original_hearing_request_type
end
end

Expand Down
12 changes: 5 additions & 7 deletions app/models/tasks/change_hearing_request_type_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Travel Board hearing request. Gives the user the option to convert that request to a video
# or virtual hearing request so it can be scheduled in Caseflow.
#
# When task is completed, i.e the field `changed_request_type` is passed as payload, the location
# When task is completed, i.e the field `changed_hearing_request_type` is passed as payload, the location
# of LegacyAppeal is moved `CASEFLOW` and the parent `ScheduleHearingTask` is set to be `assigned`
class ChangeHearingRequestTypeTask < Task
include RunAsyncable
Expand Down Expand Up @@ -38,9 +38,7 @@ def converted_on
end

def converted_by
if completed?
appeal.latest_appeal_event.who
end
appeal.last_converted_by if completed?
end

def default_instructions
Expand All @@ -61,7 +59,7 @@ def available_actions(user)
def update_from_params(params, user)
payload_values = params.delete(:business_payloads)&.dig(:values)

if payload_values&.[](:changed_request_type).present?
if payload_values&.[](:changed_hearing_request_type).present?
update_appeal_and_self(payload_values, params)

[self]
Expand All @@ -88,14 +86,14 @@ def update_appeal_and_self(payload_values, params)
# save the original request type if needed
appeal.remember_original_hearing_request_type
appeal.update!(
changed_request_type: payload_values[:changed_request_type],
changed_hearing_request_type: payload_values[:changed_hearing_request_type],
closest_regional_office: payload_values[:closest_regional_office]
)

# in VACOLS, update location to `CASEFLOW` and save the new hearing request type
if appeal.is_a?(LegacyAppeal)
AppealRepository.update_location!(appeal, LegacyAppeal::LOCATION_CODES[:caseflow])
AppealRepository.update_vacols_hearing_request_type!(appeal, payload_values[:changed_request_type])
AppealRepository.update_vacols_hearing_request_type!(appeal, payload_values[:changed_hearing_request_type])
end

update!(params)
Expand Down
2 changes: 1 addition & 1 deletion app/models/tasks/schedule_hearing_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def update_from_params(params, current_user)
verify_user_can_update!(current_user)

# Either change the hearing request type or schedule/cancel the hearing
if params.dig(:business_payloads, :values, :changed_request_type).present?
if params.dig(:business_payloads, :values, :changed_hearing_request_type).present?
change_hearing_request_type(params, current_user)
else
created_tasks = create_schedule_hearing_tasks(params)
Expand Down
4 changes: 2 additions & 2 deletions app/services/cached_appeal_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ def original_hearing_request_type_for_vacols_case(vacols_case)
def hearing_request_types_for_all_vacols_ids
@hearing_request_types_for_all_vacols_ids ||= LegacyAppeal
.where
.not(changed_request_type: nil)
.pluck(:vacols_id, :changed_request_type, :original_request_type)
.not(changed_hearing_request_type: nil)
.pluck(:vacols_id, :changed_hearing_request_type, :original_hearing_request_type)
.map { |group| [group[0], { changed: group[1], original: group[2] }] }
.to_h
end
Expand Down
2 changes: 1 addition & 1 deletion client/app/hearings/components/HearingTypeConversion.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const HearingTypeConversion = ({
status: TASK_STATUSES.completed,
business_payloads: {
values: {
changed_request_type: changedRequestType,
changed_hearing_request_type: changedRequestType,
closest_regional_office: appeal?.closestRegionalOffice || appeal?.regionalOffice?.key
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const HearingTypeConversionModal = ({
status: TASK_STATUSES.completed,
business_payloads: {
values: {
changed_request_type: changedRequestType,
changed_hearing_request_type: changedRequestType,
closest_regional_office: closestRegionalOffice
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class RenameChangedRequestTypeToChangedHearingRequestType < Caseflow::Migration
def up
safety_assured do
rename_column :appeals, :changed_request_type, :changed_hearing_request_type
rename_column :legacy_appeals, :changed_request_type, :changed_hearing_request_type
end
end
def down
safety_assured do
rename_column :appeals, :changed_hearing_request_type, :changed_request_type
rename_column :legacy_appeals, :changed_hearing_request_type, :changed_request_type
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class RenameOriginalRequestTypeToOriginalHearingRequestType < Caseflow::Migration
def up
safety_assured do
rename_column :appeals, :original_request_type, :original_hearing_request_type
rename_column :legacy_appeals, :original_request_type, :original_hearing_request_type
end
end
def down
safety_assured do
rename_column :appeals, :original_hearing_request_type, :original_request_type
rename_column :legacy_appeals, :original_hearing_request_type, :original_request_type
end
end
end
10 changes: 5 additions & 5 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_03_22_220713) do
ActiveRecord::Schema.define(version: 2021_03_24_184415) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -94,7 +94,7 @@

create_table "appeals", comment: "Decision reviews intaken for AMA appeals to the board (also known as a notice of disagreement).", force: :cascade do |t|
t.boolean "aod_based_on_age", comment: "If true, appeal is advance-on-docket due to claimant's age."
t.string "changed_request_type", comment: "The new hearing type preference for an appellant that needs a hearing scheduled"
t.string "changed_hearing_request_type", comment: "The new hearing type preference for an appellant that needs a hearing scheduled"
t.string "closest_regional_office", comment: "The code for the regional office closest to the Veteran on the appeal."
t.datetime "created_at"
t.date "docket_range_date", comment: "Date that appeal was added to hearing docket range."
Expand All @@ -107,7 +107,7 @@
t.datetime "establishment_processed_at", comment: "Timestamp for when the establishment has succeeded in processing."
t.datetime "establishment_submitted_at", comment: "Timestamp for when the the intake was submitted for asynchronous processing."
t.boolean "legacy_opt_in_approved", comment: "Indicates whether a Veteran opted to withdraw matching issues from the legacy process. If there is a matching legacy issue and it is not withdrawn then it is ineligible for the decision review."
t.string "original_request_type", comment: "The hearing type preference for an appellant before any changes were made in Caseflow"
t.string "original_hearing_request_type", comment: "The hearing type preference for an appellant before any changes were made in Caseflow"
t.string "poa_participant_id", comment: "Used to identify the power of attorney (POA) at the time the appeal was dispatched to BVA. Sometimes the POA changes in BGS after the fact, and BGS only returns the current representative."
t.date "receipt_date", comment: "Receipt date of the appeal form. Used to determine which issues are within the timeliness window to be appealed. Only issues decided prior to the receipt date will show up as contestable issues."
t.string "stream_docket_number", comment: "Multiple appeals with the same docket number indicate separate appeal streams, mimicking the structure of legacy appeals."
Expand Down Expand Up @@ -913,7 +913,7 @@

create_table "legacy_appeals", force: :cascade do |t|
t.bigint "appeal_series_id"
t.string "changed_request_type", comment: "The new hearing type preference for an appellant that needs a hearing scheduled"
t.string "changed_hearing_request_type", comment: "The new hearing type preference for an appellant that needs a hearing scheduled"
t.string "closest_regional_office"
t.boolean "contaminated_water_at_camp_lejeune", default: false
t.datetime "created_at"
Expand All @@ -932,7 +932,7 @@
t.boolean "mustard_gas", default: false
t.boolean "national_cemetery_administration", default: false
t.boolean "nonrating_issue", default: false
t.string "original_request_type", comment: "The hearing type preference for an appellant before any changes were made in Caseflow"
t.string "original_hearing_request_type", comment: "The hearing type preference for an appellant before any changes were made in Caseflow"
t.boolean "pension_united_states", default: false
t.boolean "private_attorney_or_agent", default: false
t.boolean "radiation", default: false
Expand Down
2 changes: 1 addition & 1 deletion db/seeds/hearings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def create_former_travel_currently_virtual_requested_legacy_appeals
:with_veteran,
vacols_case: vacols_case,
closest_regional_office: nil,
changed_request_type: "R"
changed_hearing_request_type: "R"
)
)
end
Expand Down
8 changes: 4 additions & 4 deletions docs/schema/caseflow.csv
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ api_views,updated_at,datetime,,,,,,
api_views,vbms_id,string,,,,,,
appeals,,,,,,,,Decision reviews intaken for AMA appeals to the board (also known as a notice of disagreement).
appeals,aod_based_on_age,boolean,,,,,x,"If true, appeal is advance-on-docket due to claimant's age."
appeals,changed_request_type,string,,,,,,The new hearing type preference for an appellant that needs a hearing scheduled
appeals,changed_hearing_request_type,string,,,,,,The new hearing type preference for an appellant that needs a hearing scheduled
appeals,closest_regional_office,string,,,,,,The code for the regional office closest to the Veteran on the appeal.
appeals,created_at,datetime,,,,,,
appeals,docket_range_date,date,,,,,,Date that appeal was added to hearing docket range.
Expand All @@ -57,7 +57,7 @@ appeals,establishment_processed_at,datetime,,,,,,Timestamp for when the establis
appeals,establishment_submitted_at,datetime,,,,,,Timestamp for when the the intake was submitted for asynchronous processing.
appeals,id,integer (8) PK,x,x,,,,
appeals,legacy_opt_in_approved,boolean,,,,,,Indicates whether a Veteran opted to withdraw matching issues from the legacy process. If there is a matching legacy issue and it is not withdrawn then it is ineligible for the decision review.
appeals,original_request_type,string,,,,,,The hearing type preference for an appellant before any changes were made in Caseflow
appeals,original_hearing_request_type,string,,,,,,The hearing type preference for an appellant before any changes were made in Caseflow
appeals,poa_participant_id,string,,,,,,"Used to identify the power of attorney (POA) at the time the appeal was dispatched to BVA. Sometimes the POA changes in BGS after the fact, and BGS only returns the current representative."
appeals,receipt_date,date ∗,x,,,,,Receipt date of the appeal form. Used to determine which issues are within the timeliness window to be appealed. Only issues decided prior to the receipt date will show up as contestable issues.
appeals,stream_docket_number,string,,,,,,"Multiple appeals with the same docket number indicate separate appeal streams, mimicking the structure of legacy appeals."
Expand Down Expand Up @@ -689,7 +689,7 @@ judge_case_reviews,task_id,string ∗ FK,x,,x,,,
judge_case_reviews,updated_at,datetime ∗,x,,,,x,
legacy_appeals,,,,,,,,
legacy_appeals,appeal_series_id,integer (8) FK,,,x,,x,
legacy_appeals,changed_request_type,string,,,,,,The new hearing type preference for an appellant that needs a hearing scheduled
legacy_appeals,changed_hearing_request_type,string,,,,,,The new hearing type preference for an appellant that needs a hearing scheduled
legacy_appeals,closest_regional_office,string,,,,,,
legacy_appeals,contaminated_water_at_camp_lejeune,boolean,,,,,,
legacy_appeals,created_at,datetime,,,,,,
Expand All @@ -709,7 +709,7 @@ legacy_appeals,manlincon_compliance,boolean,,,,,,
legacy_appeals,mustard_gas,boolean,,,,,,
legacy_appeals,national_cemetery_administration,boolean,,,,,,
legacy_appeals,nonrating_issue,boolean,,,,,,
legacy_appeals,original_request_type,string,,,,,,The hearing type preference for an appellant before any changes were made in Caseflow
legacy_appeals,original_hearing_request_type,string,,,,,,The hearing type preference for an appellant before any changes were made in Caseflow
legacy_appeals,pension_united_states,boolean,,,,,,
legacy_appeals,private_attorney_or_agent,boolean,,,,,,
legacy_appeals,radiation,boolean,,,,,,
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/tasks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@
status: Constants.TASK_STATUSES.completed,
business_payloads: {
values: {
changed_request_type: HearingDay::REQUEST_TYPES[:video]
changed_hearing_request_type: HearingDay::REQUEST_TYPES[:video]
}
}
},
Expand All @@ -907,12 +907,12 @@

it "sucessfully updates appeal and closes related tasks", :aggregate_failures do
# Ensure that the changed request type is nil before we take action
expect(legacy_appeal.changed_request_type).to eq(nil)
expect(legacy_appeal.changed_hearing_request_type).to eq(nil)
subject

# Ensure the update successfully completed the task and changed the appeal
expect(response.status).to eq 200
expect(legacy_appeal.reload.changed_request_type).to eq(HearingDay::REQUEST_TYPES[:video])
expect(legacy_appeal.reload.changed_hearing_request_type).to eq(HearingDay::REQUEST_TYPES[:video])
expect(action.reload.status).to eq(Constants.TASK_STATUSES.completed)
expect(ChangeHearingRequestTypeTask.find_by(
appeal: legacy_appeal
Expand Down
2 changes: 1 addition & 1 deletion spec/feature/hearings/assign_hearings_table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def navigate_to_ama_tab
folder: create(:folder, tinum: "3") # docket number
),
closest_regional_office: closest_regional_office,
changed_request_type: HearingDay::REQUEST_TYPES[:virtual]
changed_hearing_request_type: HearingDay::REQUEST_TYPES[:virtual]
)
)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/update_cached_appeals_attributes_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
create(
:legacy_appeal,
vacols_case: vacols_case3,
changed_request_type: HearingDay::REQUEST_TYPES[:virtual]
changed_hearing_request_type: HearingDay::REQUEST_TYPES[:virtual]
)
end

Expand Down
Loading

0 comments on commit c4e7af1

Please sign in to comment.