Skip to content

Commit

Permalink
Api 25719 current phase back (#12380)
Browse files Browse the repository at this point in the history
* Fix phase type change indicator logic

* Add additional check to current_phase_back, add test and factory

* Rubocop fixes

* Refactor logic for clarity, reduce array vs hash tests

* Rubocop remove unnecessary class length disable

* Add back disable class length check

* Fix to handle single hash return from BGS
  • Loading branch information
mchristiansonVA authored Apr 17, 2023
1 parent 2902208 commit 89e2239
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,31 +201,30 @@ def build_contentions(data)
end
end

def get_phase_type_indicator_array(data)
return if data[:benefit_claim_details_dto][:phase_type_change_ind].nil?
def current_phase_back(data)
lc_status_array = [data&.dig(:benefit_claim_details_dto, :bnft_claim_lc_status)].flatten
return false if lc_status_array.nil?

data = data[:benefit_claim_details_dto][:phase_type_change_ind]
data.split('')
end
return false if lc_status_array.first&.dig(:phase_type_change_ind).nil?

def current_phase_back(data)
return false if data[:benefit_claim_details_dto][:phase_type_change_ind].nil?
indicator = latest_phase_type_change_indicator(data).split('')
return false if indicator == 'N'

indicator.first.to_i > indicator.last.to_i
end

pt_ind_array = get_phase_type_indicator_array(data)
pt_ind_array.first.to_i > pt_ind_array.last.to_i
def latest_phase_type_change_indicator(data)
[data&.dig(:benefit_claim_details_dto, :bnft_claim_lc_status)].flatten.first&.dig(:phase_type_change_ind)
end

def latest_phase_type(data)
return if data&.dig(:benefit_claim_details_dto, :bnft_claim_lc_status).nil?

if data&.dig(:benefit_claim_details_dto, :bnft_claim_lc_status).is_a?(Array)
data[:benefit_claim_details_dto][:bnft_claim_lc_status][0][:phase_type]
elsif data&.dig(:benefit_claim_details_dto, :bnft_claim_lc_status, :phase_type)
data[:benefit_claim_details_dto][:bnft_claim_lc_status][:phase_type]
else
pt_ind_array = get_phase_type_indicator_array(data)
mapper.get_phase_from_phase_type_ind(pt_ind_array.last)
end
latest = [data&.dig(:benefit_claim_details_dto, :bnft_claim_lc_status)].flatten.first&.dig(:phase_type)
return latest unless latest.nil?

indicator = latest_phase_type_change_indicator(data).split('')
mapper.get_phase_from_phase_type_ind(indicator.last.to_i)
end

def get_current_status_from_hash(data)
Expand Down
18 changes: 18 additions & 0 deletions modules/claims_api/spec/factories/auto_established_claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@
factory :bgs_response_with_under_review_lc_status, class: OpenStruct do
benefit_claim_details_dto { (association :bgs_claim_details_dto_with_under_review_lc_status).to_h }
end
factory :bgs_response_with_phaseback_lc_status, class: OpenStruct do
benefit_claim_details_dto { (association :bgs_claim_details_dto_with_phaseback_lc_status).to_h }
end
factory :bgs_claim_details_dto_with_under_review_lc_status, class: OpenStruct do
benefit_claim_id { '111111111' }
phase_chngd_dt { Faker::Time.backward(days: 5, period: :morning) }
Expand Down Expand Up @@ -178,6 +181,14 @@
(association :bnft_claim_lc_status_one).to_h]
}
end
factory :bgs_claim_details_dto_with_phaseback_lc_status, class: OpenStruct do
benefit_claim_id { '111111111' }
phase_chngd_dt { Faker::Time.backward(days: 5, period: :morning) }
ptcpnt_clmant_id { Faker::Number.number(digits: 17) }
ptcpnt_vet_id { Faker::Number.number(digits: 17) }
claim_status_type { 'Compensation' }
bnft_claim_lc_status { [(association :bnft_claim_lc_status_phaseback).to_h] }
end
factory :bnft_claim_lc_status_one, class: OpenStruct do
max_est_claim_complete_dt { Faker::Time.backward(days: 5, period: :morning) }
min_est_claim_complete_dt { Faker::Time.backward(days: 7, period: :morning) }
Expand Down Expand Up @@ -213,4 +224,11 @@
phase_type { 'Preparation for Decision' }
phase_type_change_ind { '45' }
end
factory :bnft_claim_lc_status_phaseback, class: OpenStruct do
max_est_claim_complete_dt { Faker::Time.backward(days: 5, period: :morning) }
min_est_claim_complete_dt { Faker::Time.backward(days: 7, period: :morning) }
phase_chngd_dt { Faker::Time.backward(days: 6, period: :morning) }
phase_type { 'Under Review' }
phase_type_change_ind { '32' }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@

json_response = JSON.parse(response.body)
expect(response.status).to eq(200)
expect(json_response['data']['attributes']['claimPhaseDates']['currentPhaseBack']).to eq(true)
expect(json_response['data']['attributes']['claimPhaseDates']['currentPhaseBack']).to eq(false)
expect(json_response['data']['attributes']['claimPhaseDates']['latestPhaseType'])
.to eq('Claim Received')
expect(json_response['data']['attributes']['claimPhaseDates']['previousPhases']).to be_truthy
Expand Down Expand Up @@ -468,7 +468,7 @@
json_response = JSON.parse(response.body)
expect(response.status).to eq(200)
claim_attributes = json_response['data']['attributes']
expect(claim_attributes['claimPhaseDates']['currentPhaseBack']).to eq(true)
expect(claim_attributes['claimPhaseDates']['currentPhaseBack']).to eq(false)
expect(claim_attributes['claimPhaseDates']['latestPhaseType']).to eq('Claim Received')
expect(claim_attributes['claimPhaseDates']['previousPhases']).to be_truthy
end
Expand Down Expand Up @@ -819,6 +819,33 @@
end
end

context 'when a phaseback to Under Review status is received' do
let(:bgs_claim) { build(:bgs_response_with_phaseback_lc_status).to_h }

it "the v2 mapper sets the 'status' correctly" do
with_okta_user(scopes) do |auth_header|
VCR.use_cassette('bgs/tracked_items/find_tracked_items') do
VCR.use_cassette('evss/documents/get_claim_documents') do
expect_any_instance_of(bcs)
.to receive(:find_benefit_claim_details_by_benefit_claim_id).and_return(bgs_claim)
expect(ClaimsApi::AutoEstablishedClaim)
.to receive(:get_by_id_and_icn).and_return(nil)

get claim_by_id_path, headers: auth_header

json_response = JSON.parse(response.body)
expect(response.status).to eq(200)
expect(json_response).to be_an_instance_of(Hash)
expect(json_response['data']['attributes']['status']).to eq('INITIAL_REVIEW')
expect(json_response['data']['attributes']['claimPhaseDates']['currentPhaseBack']).to eq(true)
expect(json_response['data']['attributes']['claimPhaseDates']['latestPhaseType'])
.to eq('Under Review')
end
end
end
end
end

context 'it picks the newest status' do
it "returns a claim with the 'claimId' and 'lighthouseId' set" do
with_okta_user(scopes) do |auth_header|
Expand Down

0 comments on commit 89e2239

Please sign in to comment.