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

[API-39328] Add totals rows to monthly submission report #18290

Merged
merged 14 commits into from
Sep 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,74 @@ def perform
@from,
@to,
consumer_claims_totals: monthly_claims_totals,
poa_totals:,
itf_totals:,
ews_totals:
poa_totals: monthly_poa_totals,
itf_totals: monthly_itf_totals,
ews_totals: monthly_ews_totals
).deliver_now
end

private

def get_monthly_summary_by_consumer_by_status(monthly_summary_by_cid_by_status, monthly_pact_claims_by_cid = nil)
tycol7 marked this conversation as resolved.
Show resolved Hide resolved
totals_row = Hash.new(0)

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] if monthly_pact_claims_by_cid

column_counts.symbolize_keys!

column_counts.each do |column, count|
tycol7 marked this conversation as resolved.
Show resolved Hide resolved
totals_row[column] += count
end

{ ClaimsApi::CidMapper.new(cid:).name => column_counts }
end

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

def group_by_cid_by_status(consumers)
consumers.group_by(&:cid).transform_values do |submissions|
submissions.group_by(&:status).transform_values(&:count)
end
end

def monthly_claims_totals
monthly_claims_consumers = ClaimsApi::AutoEstablishedClaim.where(created_at: @from..@to)
monthly_pact_claims = ClaimsApi::ClaimSubmission.where(created_at: @from..@to,
claim_id: monthly_claims_consumers.pluck(:id))

monthly_claims_by_cid_by_status = monthly_claims_consumers.group_by(&:cid).transform_values do |claims|
claims.group_by(&:status).transform_values(&:count)
end
monthly_claims_by_cid_by_status = group_by_cid_by_status(monthly_claims_consumers)

monthly_pact_claims_by_cid = monthly_pact_claims.each_with_object(Hash.new(0)) do |pact_claim, hash|
cid = monthly_claims_consumers.find { |claim| claim.id == pact_claim.claim_id }&.cid
hash[cid] += 1 if cid
end

monthly_claims_by_cid_by_status.map do |cid, status_counts|
status_counts[:totals] = status_counts.values.sum
status_counts[:pact_count] = monthly_pact_claims_by_cid[cid]
{
ClaimsApi::CidMapper.new(cid:).name => status_counts.deep_symbolize_keys
}
end
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 = group_by_cid_by_status(monthly_poa_consumers)

get_monthly_summary_by_consumer_by_status(monthly_poa_by_cid_by_status)
end

def monthly_itf_totals
monthly_itf_consumers = ClaimsApi::IntentToFile.where(created_at: @from..@to)
monthly_itf_by_cid_by_status = group_by_cid_by_status(monthly_itf_consumers)

get_monthly_summary_by_consumer_by_status(monthly_itf_by_cid_by_status)
end

def monthly_ews_totals
monthly_ews_consumers = ClaimsApi::EvidenceWaiverSubmission.where(created_at: @from..@to)
monthly_ews_by_cid_by_status = group_by_cid_by_status(monthly_ews_consumers)

get_monthly_summary_by_consumer_by_status(monthly_ews_by_cid_by_status)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<table>
<thead>
<tr>
<th>consumer</th>
<% ClaimsApi::EvidenceWaiverSubmission::ALL_STATUSES.each do |status| %>
<th><%= status %></th>
<% end %>
<th>totals</th>
</tr>
</thead>
<tbody>
<% ews_consumers.each do |consumer| %>
<tr>
<td class="left-align"><%= consumer.keys[0] %></td>
<% ClaimsApi::EvidenceWaiverSubmission::ALL_STATUSES.map(&:to_sym).each do |status| %>
<td class="right-align"><%= consumer.values.first[status] || 0 %></td>
<% end %>
<td class="right-align"><%= consumer.values.first[:totals].to_i %></td>
</tr>
<% end if ews_consumers %>
</tbody>
</table>
<table class="counts">
<thead>
<tr>
<th>consumer</th>
<% ClaimsApi::EvidenceWaiverSubmission::ALL_STATUSES.each do |status| %>
<th><%= status %></th>
<% end %>
<th>totals</th>
</tr>
</thead>
<tbody>
<% ews_consumers.each do |consumer| %>
<tr>
<td class="left-align"><%= consumer.keys.first %></td>
<% ClaimsApi::EvidenceWaiverSubmission::ALL_STATUSES.map(&:to_sym).each do |status| %>
<td class="right-align"><%= consumer.values.first[status] || 0 %></td>
<% end %>
<td class="right-align"><%= consumer.values.first[:totals] || 0 %></td>
</tr>
<% end if ews_consumers %>
</tbody>
</table>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<table>
<table class="counts">
<thead>
<tr>
<th>consumer</th>
Expand All @@ -11,11 +11,11 @@
<tbody>
<% itf_consumers.each do |consumer| %>
<tr>
<td class="left-align"><%= consumer.keys[0] %></td>
<td class="left-align"><%= consumer.keys.first %></td>
<% ClaimsApi::IntentToFile::ALL_STATUSES.map(&:to_sym).each do |status| %>
<td class="right-align"><%= consumer.values.first[status] || 0 %></td>
<% end %>
<td class="right-align"><%= consumer.values.first[:totals].to_i %></td>
<td class="right-align"><%= consumer.values.first[:totals] || 0 %></td>
</tr>
<% end if itf_consumers %>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<table>
<table class="counts">
<thead>
<tr>
<th>consumer</th>
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<table>
<thead>
<tr>
<th>consumer</th>
<% ClaimsApi::PowerOfAttorney::ALL_STATUSES.each do |status| %>
<th><%= status %></th>
<% end %>
<th>totals</th>
</tr>
</thead>
<tbody>
<% poa_consumers.each do |consumer| %>
<tr>
<td class="left-align"><%= consumer.keys[0] %></td>
<% ClaimsApi::PowerOfAttorney::ALL_STATUSES.map(&:to_sym).each do |status| %>
<td class="right-align"><%= consumer.values.first[status] || 0 %></td>
<% end %>
<td class="right-align"><%= consumer.values.first[:totals].to_i %></td>
</tr>
<% end if poa_consumers %>
</tbody>
</table>
<table class="counts">
<thead>
<tr>
<th>consumer</th>
<% ClaimsApi::PowerOfAttorney::ALL_STATUSES.each do |status| %>
<th><%= status %></th>
<% end %>
<th>totals</th>
</tr>
</thead>
<tbody>
<% poa_consumers.each do |consumer| %>
<tr>
<td class="left-align"><%= consumer.keys.first %></td>
<% ClaimsApi::PowerOfAttorney::ALL_STATUSES.map(&:to_sym).each do |status| %>
<td class="right-align"><%= consumer.values.first[status] || 0 %></td>
<% end %>
<td class="right-align"><%= consumer.values.first[:totals] || 0 %></td>
</tr>
<% end if poa_consumers %>
</tbody>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
table tr td.left-align {
text-align: left;
}
table.counts tr:last-child td {
border-top: 2px solid #d3d3d3;
}
h3 {
margin: 30px 0 2px;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
expect(ClaimsApi::SubmissionReportMailer).to receive(:build).once.with(
from,
to,
consumer_claims_totals: match_array(expected_totals),
poa_totals: [],
ews_totals: [],
itf_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) : [],
itf_totals: defined?(expected_itf_totals) ? match_array(expected_itf_totals) : [],
ews_totals: defined?(expected_ews_totals) ? match_array(expected_ews_totals) : []
).and_return(double.tap do |mailer|
expect(mailer).to receive(:deliver_now).once
end)
Expand All @@ -39,7 +43,10 @@

context 'with one claims consumer and one PACT claim' do
let(:claim_setup) { :setup_one_claim_one_pact_claim }
let(:expected_totals) { [{ 'VA TurboClaim' => { established: 1, totals: 1, pact_count: 1 } }] }
let(:expected_consumer_claims_totals) do
[{ 'VA TurboClaim' => { established: 1, totals: 1, pact_count: 1 } },
{ 'Totals' => { established: 1, totals: 1, pact_count: 1 } }]
end

def setup_one_claim_one_pact_claim
claim = create(:auto_established_claim, :status_established, cid: '0oa9uf05lgXYk6ZXn297')
Expand All @@ -51,7 +58,10 @@ 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) { [{ 'VA TurboClaim' => { established: 1, totals: 1, pact_count: 0 } }] }
let(:expected_consumer_claims_totals) do
[{ 'VA TurboClaim' => { established: 1, totals: 1, pact_count: 0 } },
{ 'Totals' => { established: 1, totals: 1, pact_count: 0 } }]
end

def setup_one_claim_no_pact_claims
create(:auto_established_claim, :status_established, cid: '0oa9uf05lgXYk6ZXn297')
Expand All @@ -62,9 +72,10 @@ 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 } }]
{ 'VA.gov' => { errored: 1, totals: 1, pact_count: 0 } },
{ 'Totals' => { established: 1, errored: 1, totals: 2, pact_count: 1 } }]
end

def setup_two_claims_one_pact_claim
Expand All @@ -78,7 +89,10 @@ 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) { [{ 'VA TurboClaim' => { established: 2, errored: 1, totals: 3, pact_count: 0 } }] }
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

def setup_one_consumer_multiple_claims
cid = '0oa9uf05lgXYk6ZXn297'
Expand All @@ -92,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 @@ -101,6 +115,53 @@ 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 'three ITFs' do
let(:claim_setup) { :setup_three_itfs }
let(:expected_itf_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_itfs
create(:intent_to_file, cid: '0oa9uf05lgXYk6ZXn297')
create(:intent_to_file, status: 'errored', cid: '0oa9uf05lgXYk6ZXn297')
create(:intent_to_file, cid: '0oagdm49ygCSJTp8X297')
end
end

context 'three EWSs' do
let(:claim_setup) { :setup_three_ews }
let(:expected_ews_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_ews
create(:evidence_waiver_submission, cid: '0oa9uf05lgXYk6ZXn297')
create(:evidence_waiver_submission, status: 'errored', cid: '0oa9uf05lgXYk6ZXn297')
create(:evidence_waiver_submission, cid: '0oagdm49ygCSJTp8X297')
end
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 @@ -24,14 +24,16 @@ def unsuccessful_claims_submissions
def claims_totals
[
{ 'consumer 1' => { pending: 2, errored: 1, totals: 3, pact_count: 2 } },
{ 'consumer 2' => { pending: 3, errored: 3, totals: 6, pact_count: 1 } }
{ 'consumer 2' => { pending: 3, errored: 3, totals: 6, pact_count: 1 } },
{ 'Totals' => { pending: 5, errored: 4, totals: 9, pact_count: 3 } }
]
end

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 All @@ -45,7 +47,8 @@ def unsuccessful_poa_submissions
def ews_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 All @@ -59,7 +62,8 @@ def unsuccessful_evidence_waiver_submissions
def itf_totals
[
{ 'consumer 1' => { totals: 2, submitted: 1, errored: 1 } },
{ 'consumer 2' => { totals: 1, submitted: 1, errored: 0 } }
{ 'consumer 2' => { totals: 1, submitted: 1, errored: 0 } },
{ 'Totals' => { totals: 3, submitted: 2, errored: 1 } }
]
end
end
Loading