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

Al/APPEALS-45334 Individual change history table which includes Reassign Cases to CAMO events #22483

Merged
merged 14 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions app/models/organizations/business_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def change_history_rows
), imr_version_agg AS (SELECT
versions.item_id,
versions.item_type,
ARRAY_AGG(versions.object ORDER BY versions.id) AS object_array,
ARRAY_AGG(versions.object_changes ORDER BY versions.id) AS object_changes_array
FROM
versions
Expand Down Expand Up @@ -286,7 +287,7 @@ def change_history_rows
itv.object_changes_array AS imr_versions,
lag(imr.created_at, 1) over (PARTITION BY tasks.id, imr.decision_review_id, imr.decision_review_type ORDER BY imr.created_at) as previous_imr_created_at,
lag(imr.decided_at, 1) over (PARTITION BY tasks.id, imr.decision_review_id, imr.decision_review_type ORDER BY imr.decided_at) as previous_imr_decided_at,
itv.object_changes_array[1] as first_static_version,
itv.object_array as previous_state_array,
MAX(imr.decided_at) over (PARTITION BY tasks.id, imr.decision_review_id, imr.decision_review_type ORDER BY imr.updated_at desc) as imr_last_decided_date
FROM tasks
INNER JOIN request_issues ON request_issues.decision_review_type = tasks.appeal_type
Expand Down Expand Up @@ -393,7 +394,7 @@ def change_history_rows
itv.object_changes_array AS imr_versions,
lag(imr.created_at, 1) over (PARTITION BY tasks.id, imr.decision_review_id, imr.decision_review_type ORDER BY imr.created_at) as previous_imr_created_at,
lag(imr.decided_at, 1) over (PARTITION BY tasks.id, imr.decision_review_id, imr.decision_review_type ORDER BY imr.decided_at) as previous_imr_decided_at,
itv.object_changes_array[1] as first_static_version,
itv.object_array as previous_state_array,
MAX(imr.decided_at) over (PARTITION BY tasks.id, imr.decision_review_id, imr.decision_review_type ORDER BY imr.updated_at desc) as imr_last_decided_date
FROM tasks
INNER JOIN request_issues ON request_issues.decision_review_type = tasks.appeal_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ class ChangeHistoryEventSerializer
requestor: object.requestor,
decider: object.decider,
decidedAtDate: object.decided_at_date,
decisionReason: object.decision_reason
decisionReason: object.decision_reason,
previousIssueType: object.previous_issue_type,
previousIssueDescription: object.previous_issue_description,
previousDecisionDate: object.previous_decision_date,
previousModificationRequestReason: object.previous_modification_request_reason,
previousWithdrawalDate: object.previous_withdrawal_date
}
end
end
86 changes: 68 additions & 18 deletions app/services/claim_change_history/claim_history_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class ClaimHistoryEvent
:event_user_css_id, :new_issue_type, :new_issue_description, :new_decision_date,
:modification_request_reason, :request_type, :decision_reason, :decided_at_date,
:issue_modification_request_withdrawal_date, :requestor,
:decider, :remove_original_issue, :issue_modification_request_status
:decider, :remove_original_issue, :issue_modification_request_status,
:previous_issue_type, :previous_issue_description, :previous_decision_date,
:previous_modification_request_reason, :previous_withdrawal_date

EVENT_TYPES = [
:completed_disposition,
Expand Down Expand Up @@ -109,9 +111,9 @@ def create_issue_modification_request_event(change_data)
request_type = change_data["request_type"]
event_hash = request_issue_modification_event_hash(change_data)

if change_data["first_static_version"].present?
first_version = parse_versions("{#{change_data['first_static_version']}}")
event_hash.merge!(update_event_hash_data_from_version(first_version[0], 0))
if change_data["previous_state_array"].present?
first_version = parse_versions(change_data["previous_state_array"])[0]
event_hash.merge!(update_event_hash_data_from_version_object(first_version))
end

if request_type == "addition"
Expand All @@ -124,39 +126,56 @@ def create_issue_modification_request_event(change_data)
def create_edited_request_issue_events(change_data)
edited_events = []
imr_versions = parse_versions(change_data["imr_versions"])
previous_version = parse_versions(change_data["previous_state_array"])

if imr_versions.present?
*rest_of_versions, last_version = imr_versions

if last_version["status"].present?
edited_events.push(*create_last_version_events(change_data, last_version))
else
rest_of_versions.push(last_version)
end
edited_events.push(*create_event_from_rest_of_versions(change_data, rest_of_versions))
edited_events.push(*create_event_from_rest_of_versions(change_data, rest_of_versions, previous_version))
else
create_pending_status_events(change_data, change_data["issue_modification_request_updated_at"])
end
edited_events
end

def create_event_from_rest_of_versions(change_data, edited_versions)
def create_event_from_rest_of_versions(change_data, edited_versions, previous_version)
edit_of_request_events = []
event_type = :request_edited
event_date_hash = {}

edited_versions.map do |version|
edited_versions.map.with_index do |version, index|
event_date_hash = {
"event_date" => version["updated_at"][1],
"event_user_name" => change_data["requestor"],
"user_facility" => change_data["requestor_station_id"]
}

# this create_event_from_version_object updated the previous version fields in change data
# that is being used in the front end to show the original records.
if !previous_version[index].nil?
event_date_hash.merge!(create_event_from_version_object(previous_version[index]))
# this update_event_hash_data_from_version_object updates the change_data values with previous or
# unedited data. since change_data has the final version of the data that was updated.
# this is necessary to preserve the history that is displayed in the frontend.
event_date_hash.merge!(update_event_hash_data_from_version_object(previous_version[index]))
end

event_date_hash.merge!(update_event_hash_data_from_version(version, 1))
edit_of_request_events.push(*from_change_data(event_type, change_data.merge(event_date_hash)))
end
edit_of_request_events
end

def create_event_from_version_object(version)
previous_version_database_field.each_with_object({}) do |(db_key, version_key), data|
data[db_key] = version[version_key] unless version[version_key].nil?
end
end

def create_last_version_events(change_data, last_version)
edited_events = []

Expand Down Expand Up @@ -404,21 +423,17 @@ def task_status_to_event_type(task_status)
end

def update_event_hash_data_from_version(version, index)
version_database_field_mapping = {
"nonrating_issue_category" => "requested_issue_type",
"nonrating_issue_description" => "requested_issue_description",
"remove_original_issue" => "remove_original_issue",
"request_reason" => "modification_request_reason",
"decision_date" => "requested_decision_date",
"decision_reason" => "decision_reason",
"withdrawal_date" => "issue_modification_request_withdrawal_date"
}

version_database_field_mapping.each_with_object({}) do |(version_key, db_key), data|
data[db_key] = version[version_key][index] unless version[version_key].nil?
end
end

def update_event_hash_data_from_version_object(version)
version_database_field_mapping.each_with_object({}) do |(version_key, db_key), data|
data[db_key] = version[version_key] unless version[version_key].nil?
end
end

def event_from_version(changes, index, change_data)
# If there is no task status change in the set of papertrail changes, ignore the object
if changes["status"]
Expand Down Expand Up @@ -463,6 +478,28 @@ def update_event_hash(change_data)
}
end

def version_database_field_mapping
{
"nonrating_issue_category" => "requested_issue_type",
"nonrating_issue_description" => "requested_issue_description",
"remove_original_issue" => "remove_original_issue",
"request_reason" => "modification_request_reason",
"decision_date" => "requested_decision_date",
"decision_reason" => "decision_reason",
"withdrawal_date" => "issue_modification_request_withdrawal_date"
}
end

def previous_version_database_field
{
"previous_issue_type" => "nonrating_issue_category",
"previous_issue_description" => "nonrating_issue_description",
"previous_decision_date" => "decision_date",
"previous_modification_request_reason" => "request_reason",
"previous_withdrawal_date" => "withdrawal_date"
}
end

def add_issue_update_event_hash(change_data)
# Check the current request issue updates time to see if the issue update is in the correct row
# If it is, then do the normal update_event_hash information
Expand Down Expand Up @@ -734,11 +771,24 @@ def parse_request_issue_modification_attributes(change_data)
@decided_at_date = change_data["decided_at"]
@issue_modification_request_withdrawal_date = change_data["issue_modification_request_withdrawal_date"]
@remove_original_issue = change_data["remove_original_issue"]
@issue_modification_request_status = change_data["issue_modification_request_status"]
@requestor = change_data["requestor"]
@decider = change_data["decider"]
parse_previous_issue_modification_attributes(change_data)
end
end

def parse_previous_issue_modification_attributes(change_data)
@previous_issue_type = change_data["previous_issue_type"] || change_data["requested_issue_type"]
@previous_decision_date = change_data["previous_decision_date"] || change_data["requested_decision_date"]
@previous_modification_request_reason = change_data["previous_modification_request_reason"] ||
change_data["modification_request_reason"]
@previous_issue_description = change_data["previous_issue_description"] ||
change_data["requested_issue_description"]
@previous_withdrawal_date = change_data["previous_withdrawal_date"] ||
change_data["issue_modification_request_withdrawal_date"]
end

############ CSV and Serializer Helpers ############

def abbreviated_user_name(name_string)
Expand Down
Loading
Loading