Skip to content

Commit

Permalink
Merged together the remand feature branch with the reassign cases to …
Browse files Browse the repository at this point in the history
…camo change history updates feature branch.
  • Loading branch information
TylerBroyles committed Sep 13, 2024
2 parents de9cd83 + 2cd6e15 commit 5bd5f05
Show file tree
Hide file tree
Showing 53 changed files with 1,142 additions and 359 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@

module AppealStateBelongsToPolymorphicAppealConcern
extend ActiveSupport::Concern
include DecisionReviewPolymorphicHelper

included do
belongs_to :appeal, polymorphic: true

belongs_to :ama_appeal,
-> { where(appeal_states: { appeal_type: "Appeal" }) },
class_name: "Appeal", foreign_key: "appeal_id", optional: true

belongs_to :legacy_appeal,
-> { where(appeal_states: { appeal_type: "LegacyAppeal" }) },
class_name: "LegacyAppeal", foreign_key: "appeal_id", optional: true

scope :ama, -> { where(appeal_type: "Appeal") }
scope :legacy, -> { where(appeal_type: "LegacyAppeal") }
define_polymorphic_decision_review_associations(:appeal, :appeal_states, %w[Appeal LegacyAppeal])
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@

module AttorneyCaseReviewBelongsToPolymorphicAppealConcern
extend ActiveSupport::Concern
include DecisionReviewPolymorphicHelper

included do
belongs_to :appeal, polymorphic: true

belongs_to :ama_appeal,
-> { where(attorney_case_reviews: { appeal_type: "Appeal" }) },
class_name: "Appeal", foreign_key: "appeal_id", optional: true

belongs_to :legacy_appeal,
-> { where(attorney_case_reviews: { appeal_type: "LegacyAppeal" }) },
class_name: "LegacyAppeal", foreign_key: "appeal_id", optional: true

scope :ama, -> { where(appeal_type: "Appeal") }
scope :legacy, -> { where(appeal_type: "LegacyAppeal") }
define_polymorphic_decision_review_associations(:appeal, :attorney_case_reviews, %w[Appeal LegacyAppeal])
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@

module AvailableHearingLocationsBelongsToPolymorphicAppealConcern
extend ActiveSupport::Concern
include DecisionReviewPolymorphicHelper

included do
belongs_to :appeal, polymorphic: true

belongs_to :ama_appeal,
-> { where(available_hearing_locations: { appeal_type: "Appeal" }) },
class_name: "Appeal", foreign_key: "appeal_id", optional: true

belongs_to :legacy_appeal,
-> { where(available_hearing_locations: { appeal_type: "LegacyAppeal" }) },
class_name: "LegacyAppeal", foreign_key: "appeal_id", optional: true

scope :ama, -> { where(appeal_type: "Appeal") }
scope :legacy, -> { where(appeal_type: "LegacyAppeal") }
define_polymorphic_decision_review_associations(:appeal, :available_hearing_locations, %w[Appeal LegacyAppeal])
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,9 @@

module ClaimantBelongsToPolymorphicAppealConcern
extend ActiveSupport::Concern
include DecisionReviewPolymorphicHelper

included do
belongs_to :decision_review, polymorphic: true

belongs_to :ama_appeal,
-> { where(claimants: { decision_review_type: "Appeal" }) },
class_name: "Appeal", foreign_key: "decision_review_id", optional: true

belongs_to :legacy_appeal,
-> { where(claimants: { decision_review_type: "LegacyAppeal" }) },
class_name: "LegacyAppeal", foreign_key: "decision_review_id", optional: true

belongs_to :higher_level_review,
-> { where(claimants: { decision_review_type: "HigherLevelReview" }) },
class_name: "HigherLevelReview", foreign_key: "decision_review_id", optional: true

belongs_to :supplemental_claim,
-> { where(claimants: { decision_review_type: "SupplementalClaim" }) },
class_name: "SupplementalClaim", foreign_key: "decision_review_id", optional: true

scope :ama, -> { where(decision_review_type: "Appeal") }
scope :legacy, -> { where(decision_review_type: "LegacyAppeal") }
scope :higher_level_review, -> { where(decision_review_type: "HigherLevelReview") }
scope :supplemental_claim, -> { where(decision_review_type: "SupplementalClaim") }
define_polymorphic_decision_review_associations(:decision_review, :claimants)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@

module DecisionDocumentBelongsToPolymorphicAppealConcern
extend ActiveSupport::Concern
include DecisionReviewPolymorphicHelper

included do
belongs_to :appeal, polymorphic: true

belongs_to :ama_appeal,
-> { where(decision_documents: { appeal_type: "Appeal" }) },
class_name: "Appeal", foreign_key: "appeal_id", optional: true

belongs_to :legacy_appeal,
-> { where(decision_documents: { appeal_type: "LegacyAppeal" }) },
class_name: "LegacyAppeal", foreign_key: "appeal_id", optional: true

scope :ama, -> { where(appeal_type: "Appeal") }
scope :legacy, -> { where(appeal_type: "LegacyAppeal") }
define_polymorphic_decision_review_associations(:appeal, :decision_documents, %w[Appeal LegacyAppeal])
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,11 @@

module DecisionIssueBelongsToPolymorphicAppealConcern
extend ActiveSupport::Concern
include DecisionReviewPolymorphicHelper

included do
belongs_to :decision_review, polymorphic: true

belongs_to :ama_appeal,
-> { where(decision_issues: { decision_review_type: "Appeal" }) },
class_name: "Appeal", foreign_key: "decision_review_id", optional: true

belongs_to :higher_level_review,
-> { where(decision_issues: { decision_review_type: "HigherLevelReview" }) },
class_name: "HigherLevelReview", foreign_key: "decision_review_id", optional: true

belongs_to :supplemental_claim,
-> { where(decision_issues: { decision_review_type: "SupplementalClaim" }) },
class_name: "SupplementalClaim", foreign_key: "decision_review_id", optional: true

scope :ama, -> { where(decision_review_type: "Appeal") }
scope :higher_level_review, -> { where(decision_review_type: "HigherLevelReview") }
scope :supplemental_claim, -> { where(decision_review_type: "SupplementalClaim") }
define_polymorphic_decision_review_associations(:decision_review,
:decision_issues,
%w[Appeal HigherLevelReview SupplementalClaim])
end
end
30 changes: 30 additions & 0 deletions app/models/concerns/decision_review_polymorphic_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module DecisionReviewPolymorphicHelper
extend ActiveSupport::Concern

class_methods do
def define_polymorphic_decision_review_associations(association_name, from_association_name, types = nil)
belongs_to association_name, polymorphic: true

# Specific association mappings that are uniquely different from the calculated class name to underscored symbol
association_name_mapping = { "Appeal" => :ama_appeal, "Hearing" => :ama_hearing }
scope_mapping = { "Appeal" => :ama, "LegacyAppeal" => :legacy, "LegacyHearing" => :legacy, "Hearing" => :ama }

# LegacyAppeals + all of the non abstract subtypes of DecisionReview not incuding child types for STI
types ||= %w[Appeal LegacyAppeal HigherLevelReview SupplementalClaim]

types.each do |type|
type_symbol = type.underscore.to_sym
belongs_to_association_name = association_name_mapping[type] || type_symbol
scope_name = scope_mapping[type] || type_symbol

belongs_to belongs_to_association_name,
-> { where(from_association_name => { "#{association_name}_type": type }) },
class_name: type, foreign_key: "#{association_name}_id", optional: true

scope scope_name.to_sym, -> { where("#{association_name}_type": type) }
end
end
end
end
29 changes: 29 additions & 0 deletions app/models/concerns/decision_review_polymorphic_sti_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module DecisionReviewPolymorphicSTIHelper
extend ActiveSupport::Concern

class_methods do
def define_polymorphic_decision_review_sti_associations(association_name, from_association_name, types = nil)
# Mappings between STI types and their associated parent type and parent database table
sti_table_mapping = { "Remand" => :supplemental_claims }
sti_type_mapping = { "Remand" => "SupplementalClaim" }

types ||= %w[Remand]

types.each do |type|
type_symbol = type.underscore.to_sym
belongs_to_association_name = type_symbol
sti_type = sti_type_mapping[type] || type
sti_table_name = sti_table_mapping[type] || association_name

belongs_to belongs_to_association_name,
lambda {
where(from_association_name => { "#{association_name}_type": sti_type })
.where(Arel::Table.new(sti_table_name)[:type].eq(type))
},
class_name: type, foreign_key: "#{association_name}_id", optional: true
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@

module HearingEmailRecipientBelongsToPolymorphicAppealConcern
extend ActiveSupport::Concern
include DecisionReviewPolymorphicHelper

included do
belongs_to :appeal, polymorphic: true

belongs_to :ama_appeal,
-> { where(hearing_email_recipients: { appeal_type: "Appeal" }) },
class_name: "Appeal", foreign_key: "appeal_id", optional: true

belongs_to :legacy_appeal,
-> { where(hearing_email_recipients: { appeal_type: "LegacyAppeal" }) },
class_name: "LegacyAppeal", foreign_key: "appeal_id", optional: true

scope :ama, -> { where(appeal_type: "Appeal") }
scope :legacy, -> { where(appeal_type: "LegacyAppeal") }
define_polymorphic_decision_review_associations(:appeal, :hearing_email_recipients, %w[Appeal LegacyAppeal])
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@

module JudgeCaseReviewBelongsToPolymorphicAppealConcern
extend ActiveSupport::Concern
include DecisionReviewPolymorphicHelper

included do
belongs_to :appeal, polymorphic: true

belongs_to :ama_appeal,
-> { where(judge_case_reviews: { appeal_type: "Appeal" }) },
class_name: "Appeal", foreign_key: "appeal_id", optional: true

belongs_to :legacy_appeal,
-> { where(judge_case_reviews: { appeal_type: "LegacyAppeal" }) },
class_name: "LegacyAppeal", foreign_key: "appeal_id", optional: true

scope :ama, -> { where(appeal_type: "Appeal") }
scope :legacy, -> { where(appeal_type: "LegacyAppeal") }
define_polymorphic_decision_review_associations(:appeal, :judge_case_reviews, %w[Appeal LegacyAppeal])
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@

module SentHearingEmailEventBelongsToPolymorphicHearingConcern
extend ActiveSupport::Concern
include DecisionReviewPolymorphicHelper

included do
belongs_to :hearing, polymorphic: true

belongs_to :ama_hearing,
-> { where(sent_hearing_email_events: { hearing_type: "Hearing" }) },
class_name: "Hearing", foreign_key: "hearing_id", optional: true

belongs_to :legacy_hearing,
-> { where(sent_hearing_email_events: { hearing_type: "LegacyHearing" }) },
class_name: "LegacyHearing", foreign_key: "hearing_id", optional: true

scope :ama, -> { where(hearing_type: "Hearing") }
scope :legacy, -> { where(hearing_type: "LegacyHearing") }
define_polymorphic_decision_review_associations(:hearing, :sent_hearing_email_events, %w[Hearing LegacyHearing])
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@

module SpecialIssueListBelongsToPolymorphicAppealConcern
extend ActiveSupport::Concern
include DecisionReviewPolymorphicHelper

included do
belongs_to :appeal, polymorphic: true

belongs_to :ama_appeal,
-> { where(special_issue_lists: { appeal_type: "Appeal" }) },
class_name: "Appeal", foreign_key: "appeal_id", optional: true

belongs_to :legacy_appeal,
-> { where(special_issue_lists: { appeal_type: "LegacyAppeal" }) },
class_name: "LegacyAppeal", foreign_key: "appeal_id", optional: true

scope :ama, -> { where(appeal_type: "Appeal") }
scope :legacy, -> { where(appeal_type: "LegacyAppeal") }
define_polymorphic_decision_review_associations(:appeal, :special_issue_lists, %w[Appeal LegacyAppeal])
end
end
26 changes: 4 additions & 22 deletions app/models/concerns/task_belongs_to_polymorphic_appeal_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,11 @@

module TaskBelongsToPolymorphicAppealConcern
extend ActiveSupport::Concern
include DecisionReviewPolymorphicHelper
include DecisionReviewPolymorphicSTIHelper

included do
belongs_to :appeal, polymorphic: true

belongs_to :ama_appeal,
-> { where(tasks: { appeal_type: "Appeal" }) },
class_name: "Appeal", foreign_key: "appeal_id", optional: true

belongs_to :legacy_appeal,
-> { where(tasks: { appeal_type: "LegacyAppeal" }) },
class_name: "LegacyAppeal", foreign_key: "appeal_id", optional: true

belongs_to :higher_level_review,
-> { where(tasks: { appeal_type: "HigherLevelReview" }) },
class_name: "HigherLevelReview", foreign_key: "appeal_id", optional: true

belongs_to :supplemental_claim,
-> { where(tasks: { appeal_type: "SupplementalClaim" }) },
class_name: "SupplementalClaim", foreign_key: "appeal_id", optional: true

scope :ama, -> { where(appeal_type: "Appeal") }
scope :legacy, -> { where(appeal_type: "LegacyAppeal") }
scope :higher_level_review, -> { where(appeal_type: "HigherLevelReview") }
scope :supplemental_claim, -> { where(appeal_type: "SupplementalClaim") }
define_polymorphic_decision_review_associations(:appeal, :tasks)
define_polymorphic_decision_review_sti_associations(:appeal, :tasks)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@

module VbmsUploadedDocumentBelongsToPolymorphicAppealConcern
extend ActiveSupport::Concern
include DecisionReviewPolymorphicHelper

included do
belongs_to :appeal, polymorphic: true

belongs_to :ama_appeal,
-> { where(vbms_uploaded_documents: { appeal_type: "Appeal" }) },
class_name: "Appeal", foreign_key: "appeal_id", optional: true

belongs_to :legacy_appeal,
-> { where(vbms_uploaded_documents: { appeal_type: "LegacyAppeal" }) },
class_name: "LegacyAppeal", foreign_key: "appeal_id", optional: true

scope :ama, -> { where(appeal_type: "Appeal") }
scope :legacy, -> { where(appeal_type: "LegacyAppeal") }
define_polymorphic_decision_review_associations(:appeal, :vbms_uploaded_documents, %w[Appeal LegacyAppeal])
end
end
33 changes: 25 additions & 8 deletions app/models/decision_issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,7 @@ def create_remand_supplemental_claim!
# Checking our assumption that approx_decision_date will always be populated for Decision Issues
fail "approx_decision_date is required to create a DTA Supplemental Claim" unless approx_decision_date

sc = SupplementalClaim.create!(
veteran_file_number: veteran_file_number,
decision_review_remanded: decision_review,
benefit_type: benefit_type,
legacy_opt_in_approved: decision_review.legacy_opt_in_approved,
veteran_is_not_claimant: decision_review.veteran_is_not_claimant,
receipt_date: approx_decision_date
)
sc = determine_remand_creation_type
fail AppealDTAPayeeCodeError, decision_review.id unless dta_payee_code

sc.create_claimant!(
Expand All @@ -273,4 +266,28 @@ def create_remand_supplemental_claim!
decision_review.update_error!("DTA SC creation failed")
raise
end

# Create a Remand if the decision review is an Appeal.
# HLRs will still create remands as SupplementalClaims as of (APPEALS-41559)
def determine_remand_creation_type
if decision_review_type == Appeal.name
Remand.create!(
veteran_file_number: veteran_file_number,
decision_review_remanded: decision_review,
benefit_type: benefit_type,
legacy_opt_in_approved: decision_review.legacy_opt_in_approved,
veteran_is_not_claimant: decision_review.veteran_is_not_claimant,
receipt_date: approx_decision_date
)
else
SupplementalClaim.create!(
veteran_file_number: veteran_file_number,
decision_review_remanded: decision_review,
benefit_type: benefit_type,
legacy_opt_in_approved: decision_review.legacy_opt_in_approved,
veteran_is_not_claimant: decision_review.veteran_is_not_claimant,
receipt_date: approx_decision_date
)
end
end
end
Loading

0 comments on commit 5bd5f05

Please sign in to comment.