Skip to content

Commit

Permalink
Add totals row to Power of Attorney table
Browse files Browse the repository at this point in the history
  • Loading branch information
tycol7 committed Sep 4, 2024
1 parent ce77d49 commit 6c0e439
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ def perform
@from,
@to,
consumer_claims_totals: monthly_claims_totals,
poa_totals:,
poa_totals: monthly_poa_totals,
itf_totals:,
ews_totals:
).deliver_now
end

private

def get_monthly_claims_by_consumer_by_status(monthly_claims_by_cid_by_status, monthly_pact_claims_by_cid)
def get_monthly_summary_by_consumer_by_status(monthly_summary_by_cid_by_status, monthly_pact_claims_by_cid = nil)
totals_row = Hash.new(0)

monthly_claims_by_consumer_by_status = monthly_claims_by_cid_by_status.map do |cid, column_counts|
monthly_summary_by_consumer_by_status = monthly_summary_by_cid_by_status.map do |cid, column_counts|
column_counts[:totals] = column_counts.values.sum
column_counts[:pact_count] = monthly_pact_claims_by_cid[cid]
column_counts[:pact_count] = monthly_pact_claims_by_cid[cid] if monthly_pact_claims_by_cid

column_counts.symbolize_keys!

Expand All @@ -40,8 +40,8 @@ def get_monthly_claims_by_consumer_by_status(monthly_claims_by_cid_by_status, mo
{ ClaimsApi::CidMapper.new(cid:).name => column_counts }
end

monthly_claims_by_consumer_by_status.tap do |claims_rows|
claims_rows << { 'Totals' => totals_row } unless totals_row.empty?
monthly_summary_by_consumer_by_status.tap do |rows|
rows << { 'Totals' => totals_row } unless totals_row.empty?
end
end

Expand All @@ -59,7 +59,17 @@ def monthly_claims_totals
hash[cid] += 1 if cid
end

get_monthly_claims_by_consumer_by_status(monthly_claims_by_cid_by_status, monthly_pact_claims_by_cid)
get_monthly_summary_by_consumer_by_status(monthly_claims_by_cid_by_status, monthly_pact_claims_by_cid)
end

def monthly_poa_totals
monthly_poa_consumers = ClaimsApi::PowerOfAttorney.where(created_at: @from..@to)

monthly_poa_by_cid_by_status = monthly_poa_consumers.group_by(&:cid).transform_values do |poas|
poas.group_by(&:status).transform_values(&:count)
end

get_monthly_summary_by_consumer_by_status(monthly_poa_by_cid_by_status)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<tbody>
<% claims_consumers.each do |consumer| %>
<tr>
<td class="left-align"><%= consumer.keys[0] %></td>
<td class="left-align"><%= consumer.keys.first %></td>
<% ClaimsApi::AutoEstablishedClaim::ALL_STATUSES.map(&:to_sym).each do |status| %>
<td class="right-align"><%= consumer.values.first[status] || 0 %></td>
<% end %>
Expand Down
35 changes: 28 additions & 7 deletions modules/claims_api/spec/sidekiq/report_monthly_submissions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
expect(ClaimsApi::SubmissionReportMailer).to receive(:build).once.with(
from,
to,
consumer_claims_totals: match_array(expected_totals),
poa_totals: [],
consumer_claims_totals: if defined?(expected_consumer_claims_totals)
match_array(expected_consumer_claims_totals)
else
[]
end,
poa_totals: defined?(expected_poa_totals) ? match_array(expected_poa_totals) : [],
ews_totals: [],
itf_totals: []
).and_return(double.tap do |mailer|
Expand All @@ -39,7 +43,7 @@

context 'with one claims consumer and one PACT claim' do
let(:claim_setup) { :setup_one_claim_one_pact_claim }
let(:expected_totals) do
let(:expected_consumer_claims_totals) do
[{ 'VA TurboClaim' => { established: 1, totals: 1, pact_count: 1 } },
{ 'Totals' => { established: 1, totals: 1, pact_count: 1 } }]
end
Expand All @@ -54,7 +58,7 @@ def setup_one_claim_one_pact_claim

context 'with one claims consumer and no PACT claims' do
let(:claim_setup) { :setup_one_claim_no_pact_claims }
let(:expected_totals) do
let(:expected_consumer_claims_totals) do
[{ 'VA TurboClaim' => { established: 1, totals: 1, pact_count: 0 } },
{ 'Totals' => { established: 1, totals: 1, pact_count: 0 } }]
end
Expand All @@ -68,7 +72,7 @@ def setup_one_claim_no_pact_claims

context 'with two claims consumers and one PACT claim' do
let(:claim_setup) { :setup_two_claims_one_pact_claim }
let(:expected_totals) do
let(:expected_consumer_claims_totals) do
[{ 'VA TurboClaim' => { established: 1, totals: 1, pact_count: 1 } },
{ 'VA.gov' => { errored: 1, totals: 1, pact_count: 0 } },
{ 'Totals' => { established: 1, errored: 1, totals: 2, pact_count: 1 } }]
Expand All @@ -85,7 +89,7 @@ def setup_two_claims_one_pact_claim

context 'with one claims consumer and multiple claims' do
let(:claim_setup) { :setup_one_consumer_multiple_claims }
let(:expected_totals) do
let(:expected_consumer_claims_totals) do
[{ 'VA TurboClaim' => { established: 2, errored: 1, totals: 3, pact_count: 0 } },
{ 'Totals' => { established: 2, errored: 1, totals: 3, pact_count: 0 } }]
end
Expand All @@ -102,7 +106,7 @@ def setup_one_consumer_multiple_claims

context 'no claims' do
let(:claim_setup) { :setup_no_claims }
let(:expected_totals) { [] }
let(:expected_consumer_claims_totals) { [] }

def setup_no_claims
# no claims
Expand All @@ -111,6 +115,23 @@ def setup_no_claims
it_behaves_like 'sends mail with expected totals'
end

context 'three POAs' do
let(:claim_setup) { :setup_three_poas }
let(:expected_poa_totals) do
[{ 'VA TurboClaim' => { submitted: 1, errored: 1, totals: 2 } },
{ 'VA.gov' => { submitted: 1, totals: 1 } },
{ 'Totals' => { submitted: 2, errored: 1, totals: 3 } }]
end

def setup_three_poas
create(:power_of_attorney, cid: '0oa9uf05lgXYk6ZXn297')
create(:power_of_attorney, status: 'errored', cid: '0oa9uf05lgXYk6ZXn297')
create(:power_of_attorney, cid: '0oagdm49ygCSJTp8X297')
end

it_behaves_like 'sends mail with expected totals'
end

context 'shared reporting behavior' do
it_behaves_like 'shared reporting behavior'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def claims_totals
def poa_totals
[
{ 'consumer 1' => { totals: 10, updated: 5, errored: 2, pending: 1, uploaded: 2 } },
{ 'consumer 2' => { totals: 8, updated: 3, errored: 2, pending: 1, uploaded: 2 } }
{ 'consumer 2' => { totals: 8, updated: 3, errored: 2, pending: 1, uploaded: 2 } },
{ 'Totals' => { totals: 18, updated: 8, errored: 4, pending: 2, uploaded: 4 } }
]
end

Expand Down

0 comments on commit 6c0e439

Please sign in to comment.