Skip to content

Commit

Permalink
APPEALS-23420 add held_by for legacy hearings
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpmessner committed Oct 3, 2024
1 parent 0ea89ea commit 33e5167
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 11 deletions.
44 changes: 41 additions & 3 deletions app/services/search_query_service/appeal_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ def attributes
SearchQueryService::Attributes.new(
aod: aod,
appellant_full_name: appellant_full_name,
appellant_date_of_birth: appellant_date_of_birth,
appellant_email_address: appellant_person["email_address"],
appellant_first_name: appellant_person["first_name"],
appellant_hearing_email_recipient: json_array("hearing_email_recipient").first,
appellant_is_not_veteran: !!queried_appeal.veteran_is_not_claimant,
appellant_last_name: appellant_person["last_name"],
appellant_middle_name: appellant_person["middle_name"],
appellant_party_type: appellant_party_type,
appellant_phone_number: appellant_phone_number,
appellant_relationship: nil,
appellant_substitution: nil,
appellant_suffix: appellant_person["name_suffix"],
appellant_type: appellant&.type,
appellant_tz: nil,
assigned_to_location: queried_appeal.assigned_to_location,
assigned_attorney: assigned_attorney,
assigned_judge: assigned_judge,
Expand Down Expand Up @@ -56,8 +70,32 @@ def attributes
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength

def appellant_date_of_birth
if appellant.person.present?
Date.parse appellant.person.try(:[], "date_of_birth")
end
rescue TypeError
nil
end

def appellant_party_type
appellant&.unrecognized_party_details.try(:[], "party_type")
end

def appellant_phone_number
appellant&.unrecognized_party_details.try(:[], "phone_number")
end

def aod
query_row["aod_granted_for_person"].present?
queried_appeal.advanced_on_docket_based_on_age? || query_row["aod_granted_for_person"]
end

def appellant_person
appellant.person || {}
end

def appellant
queried_appeal.claimant
end

def decision_issues
Expand Down Expand Up @@ -88,7 +126,7 @@ def veteran_file_number
attrs["veteran_file_number"]
end

def issue(attributes)
def clean_issue_attributes!(attributes)
unless FeatureToggle.enabled?(:pact_identification)
attributes.delete("pact_status")
end
Expand All @@ -100,7 +138,7 @@ def issue(attributes)
def issues
json_array("request_issues").map do |attributes|
attributes.tap do |attrs|
issue(attrs)
clean_issue_attributes!(attrs)
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions app/services/search_query_service/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@
SearchQueryService::Attributes = Struct.new(
:aod,
:power_of_attorney,
:appellant_date_of_birth,
:appellant_email_address,
:appellant_first_name,
:appellant_full_name,
:appellant_hearing_email_recipient,
:appellant_is_not_veteran,
:appellant_last_name,
:appellant_middle_name,
:appellant_party_type,
:appellant_phone_number,
:appellant_relationship,
:appellant_substitution,
:appellant_suffix,
:appellant_type,
:appellant_tz,
:assigned_attorney,
:assigned_judge,
:assigned_to_location,
Expand Down
19 changes: 19 additions & 0 deletions app/services/search_query_service/legacy_appeal_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def call
request_type: attributes["type"],
appeal_type: VACOLS::Case::TYPES[attributes["bfac"]],
external_id: attributes["external_id"],
held_by: held_by,
is_virtual: false,
notes: attributes["notes"],
type: type,
created_at: nil,
scheduled_in_timezone: nil,
date: HearingMapper.datetime_based_on_type(
datetime: attributes["date"],
regional_office: regional_office(attributes["venue"]),
Expand All @@ -81,6 +87,19 @@ def call

attr_reader :attributes

def type
Hearing::HEARING_TYPES[attributes["hearing_type"]&.to_sym]
end

def held_by
fname = attributes["held_by_first_name"]
lname = attributes["held_by_last_name"]

if fname.present? && lname.present?
"#{fname} #{lname}"
end
end

def regional_office(ro_key)
RegionalOffice.find!(ro_key)
rescue NotFoundError
Expand Down
10 changes: 9 additions & 1 deletion app/services/search_query_service/queried_appeal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ def claimant_participant_ids
claimants.map(&:participant_id)
end

def claimant
claimants.max_by(&:id)
end

def claimants
@claimants ||= begin
attributes.claimants.map do |attrs|
Struct.new(:participant_id).new(attrs["participant_id"])
OpenStruct.new(attrs)
end
end
end
Expand All @@ -46,6 +50,10 @@ def root_task
end
end

def advanced_on_docket_based_on_age?
claimant&.date_of_birth.present? && Date.parse(claimant.date_of_birth) < 75.years.ago
end

def open_tasks
@open_tasks ||= tasks.select do |task|
Task.open_statuses.include?(task.status)
Expand Down
42 changes: 39 additions & 3 deletions app/services/search_query_service/query.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# rubocop:disable Metrics/ClassLength
class SearchQueryService::Query
def initialize
@vacols = SearchQueryService::VacolsQuery.new
Expand Down Expand Up @@ -92,6 +93,19 @@ def legacy_appeals_internal_query
v.last_name veteran_last_name,
v.file_number as veteran_file_number,
v.date_of_death,
(
select jsonb_agg(her2) from
(
select
her.*
from hearing_email_recipients her
where
her.appeal_type = 'LegacyAppeal' and
her.appeal_id = a.id and
her.type = 'AppellantHearingEmailRecipient'
limit 1
) her2
) hearing_email_recipient,
(
select jsonb_agg(u2) from
(
Expand Down Expand Up @@ -175,7 +189,7 @@ def appeals_internal_query
a.id,
a.uuid::varchar external_id,
a.stream_type type,
aod.id aod_granted_for_person,
aod.granted aod_granted_for_person,
a.docket_type,
(
select jsonb_agg(a2)
Expand All @@ -198,9 +212,17 @@ def appeals_internal_query
select jsonb_agg(c2) from
(
select
c.id,
c.participant_id
c.*,
row_to_json(p.*) person,
row_to_json(ua.*) unrecognized_appellants,
row_to_json(upd.*) unrecognized_party_details
from claimants c
left join unrecognized_appellants ua on
c.id = ua.claimant_id
left join unrecognized_party_details upd on
ua.unrecognized_party_detail_id = upd.id
left join people p on
c.participant_id = p.participant_id
where
c.decision_review_type = 'Appeal' and
c.decision_review_id=a.id
Expand All @@ -219,6 +241,19 @@ def appeals_internal_query
v.last_name veteran_last_name,
v.file_number as veteran_file_number,
v.date_of_death,
(
select jsonb_agg(her2) from
(
select
her.*
from hearing_email_recipients her
where
her.appeal_type = 'Appeal' and
her.appeal_id = a.id and
her.type = 'AppellantHearingEmailRecipient'
limit 1
) her2
) hearing_email_recipient,
(
select jsonb_agg(u2) from
(
Expand Down Expand Up @@ -414,3 +449,4 @@ def judge_task_classes
]
end
end
# rubocop:enable Metrics/ClassLength
6 changes: 5 additions & 1 deletion app/services/search_query_service/vacols_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ def query
'external_id' value "h".hearing_pkseq,
'type' value "h".hearing_type,
'disposition' value "h".hearing_disp,
'date' value "h".hearing_date
'date' value "h".hearing_date,
'held_by_first_name' value "s".snamef,
'held_by_last_name' value "s".snamel,
'notes' value "h".notes1
))
from hearsched "h"
left outer join staff "s" on "s".sattyid = "h".board_member
where "h".folder_nr="cases".bfkey
) hearings,
(select
Expand Down
29 changes: 26 additions & 3 deletions spec/services/search_query_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
appeal.overtime = true
AdvanceOnDocketMotion.create(
person: appeal.claimants.first.person,
granted: false,
appeal: appeal
)
end.reload
Expand All @@ -84,15 +85,20 @@
context "finds by docket number" do
subject { SearchQueryService.new(docket_number: appeal.stream_docket_number) }

it "finds by docket number" do
before do
create(
:virtual_hearing,
hearing: appeal.hearings.first
)
appeal.hearings.first.update(updated_by: judge)
appeal.hearings.first.hearing_day.update(regional_office: "RO19")
appeal.hearings.first.hearing_views.create(user_id: judge.id)
AppellantHearingEmailRecipient.first.update(
appeal: appeal
)
end

it "finds by docket number" do
expect(appeal).to be_persisted

search_results = subject.search_by_docket_number
Expand All @@ -106,7 +112,7 @@

attributes = result.attributes

expect(attributes.aod).to be_truthy
expect(attributes.aod).to be_falsy
expect(attributes.appellant_full_name).to eq veteran_full_name
expect(attributes.assigned_to_location).to eq appeal.assigned_to_location
expect(attributes.caseflow_veteran_id).to eq veteran.id
Expand Down Expand Up @@ -197,6 +203,15 @@
)
end

let(:judge) do
create(
:staff,
:hearing_judge,
snamel: Faker::Name.last_name,
snamef: Faker::Name.first_name
)
end

# must be created first for legacy_appeal factory to find it
let!(:veteran) do
create(
Expand Down Expand Up @@ -238,10 +253,17 @@

let(:hearings_count) { 5 }
let(:vacols_case_hearings) do
create_list(
hearings = create_list(
:case_hearing,
hearings_count
)

hearings.map do |hearing|
hearing.board_member = judge.sattyid
hearing.save
end

hearings
end

let(:vacols_correspondent) do
Expand Down Expand Up @@ -304,6 +326,7 @@
expect(attributes.docket_number).to eq vacols_folder.tinum
expect(attributes.external_id).to eq vacols_case.id
expect(attributes.hearings.length).to eq hearings_count
expect(attributes.hearings.first[:held_by]).to eq "#{judge.snamef} #{judge.snamel}"
expect(attributes.issues.length).to eq issues_count
expect(attributes.mst).to be_truthy
expect(attributes.pact).to be_truthy
Expand Down

0 comments on commit 33e5167

Please sign in to comment.