Skip to content

Commit

Permalink
[Automated] Merged master into target k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
va-vsp-bot authored May 8, 2024
2 parents b681d6b + 53eff2e commit f85e810
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 90 deletions.
4 changes: 2 additions & 2 deletions lib/periodic_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
# Daily alert of pending claims longer than acceptable threshold
mgr.register('15 23 * * *', 'ClaimsApi::ReportUnsuccessfulSubmissions')
# Weekly report of unsuccessful claims submissions
mgr.register('15 23 1 * *', 'ClaimsApi::ReportMonthlySubmissions')
# Weekly report of unsuccessful claims submissions
mgr.register('00 00 1 * *', 'ClaimsApi::ReportMonthlySubmissions')
# Monthly report of submissions

mgr.register('30 2 * * *', 'Identity::UserAcceptableVerifiedCredentialTotalsJob')

Expand Down
102 changes: 79 additions & 23 deletions modules/claims_api/app/mailers/claims_api/submission_report_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,20 @@ class SubmissionReportMailer < ApplicationMailer
[email protected]
].freeze

def build(date_from, date_to, submissions = nil, yearly_submissions = nil) # rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/ParameterLists
def build(date_from, date_to, pact_act_data, disability_compensation_count,
poa_count, itf_count, ews_count)

@date_from = date_from.in_time_zone('Eastern Time (US & Canada)').strftime('%a %D %I:%M %p')
@date_to = date_to.in_time_zone('Eastern Time (US & Canada)').strftime('%a %D %I:%M %p')
@data = { month: {}, year: {} }
submissions = ClaimsApi::ClaimSubmission.where(created_at: @from..@to) if submissions.nil?

submissions.pluck(:claim_type).uniq.sort.each do |kind|
@data[:month][kind] = {}
subs = submissions.select { |sub| sub[:claim_type] == kind }
subs.pluck(:consumer_label).uniq.sort.each do |label|
@data[:month][kind][label] = subs.select { |sub| sub[:consumer_label] == label }.size
end
end
@data = { month: {} }

if yearly_submissions.nil?
year_start = Date.new(Time.zone.today.year, 1, 1)
year_end = Date.new(Time.zone.today.year + 1, 1, 1)
yearly_submissions = ClaimsApi::ClaimSubmission.where('created_at > ? AND created_at < ?', year_start, year_end)
end
pact_act_submissions(pact_act_data)
disability_compensation_submissions(disability_compensation_count)
poa_submissions(poa_count)
itf_submissions(itf_count)
ews_submissions(ews_count)

yearly_submissions.pluck(:claim_type).uniq.sort.each do |kind|
@data[:year][kind] = {}
subs = yearly_submissions.select { |sub| sub[:claim_type] == kind }
subs.pluck(:consumer_label).uniq.sort.each do |label|
@data[:year][kind][label] = subs.select { |sub| sub[:consumer_label] == label }.size
end
end
@data.deep_symbolize_keys!

template = File.read(path)
Expand All @@ -51,6 +38,7 @@ def build(date_from, date_to, submissions = nil, yearly_submissions = nil) # rub
body:
)
end
# rubocop:enable Metrics/ParameterLists

private

Expand All @@ -63,5 +51,73 @@ def path
'submission_report.html.erb'
)
end

def pact_act_submissions(pact_act_data)
pact_act_data = ClaimsApi::ClaimSubmission.where(created_at: @date_from..@date_to) if pact_act_data.nil?

add_monthly_pact_data(pact_act_data)
end

def disability_compensation_submissions(disability_compensation_count)
if disability_compensation_count.nil?
disability_compensation_count = ClaimsApi::AutoEstablishedClaim
.where(created_at: @date_from..@date_to)
.pluck(:id)
.uniq
.size
end

add_monthly_data(disability_compensation_count, 'Disability Compensation', 'Form 526')
end

def poa_submissions(poa_count)
if poa_count.nil?
poa_count = ClaimsApi::PowerOfAttorney
.where(created_at: @date_from..@date_to)
.pluck(:id)
.uniq
.size
end

add_monthly_data(poa_count, 'Power of Attorney', 'Form 2122/2122a')
end

def itf_submissions(itf_count)
if itf_count.nil?
itf_count = ClaimsApi::IntentToFile.where(created_at: @date_from..@date_to)
.pluck(:id)
.uniq
.size
end

add_monthly_data(itf_count, 'Intent to File', 'Form 0966')
end

def ews_submissions(ews_count)
if ews_count.nil?
ews_count = ClaimsApi::EvidenceWaiverSubmission.where(created_at: @date_from..@date_to)
.pluck(:id)
.uniq
.size
end

add_monthly_data(ews_count, 'Evidence Waiver', 'Form 5133')
end

def add_monthly_data(records_count, kind, label)
@data[:month][kind] ||= {}

@data[:month][kind][label] = records_count
end

def add_monthly_pact_data(pact_act_data)
pact_act_data.pluck(:claim_type).uniq.sort.each do |kind|
@data[:month][kind] = {}
subs = pact_act_data.select { |sub| sub[:claim_type] == kind }
subs.pluck(:consumer_label).uniq.sort.each do |label|
@data[:month][kind][label] = subs.select { |sub| sub[:consumer_label] == label }.size
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ def perform

@to = Time.zone.now
@from = 1.month.ago
submissions = ClaimsApi::ClaimSubmission.where(created_at: @from..@to)
pact_act_data = ClaimsApi::ClaimSubmission.where(created_at: @from..@to)
disability_compensation_count = ClaimsApi::AutoEstablishedClaim.where(created_at: @from..@to).pluck(:id).uniq.size
power_of_attorney_count = ClaimsApi::PowerOfAttorney.where(created_at: @from..@to).pluck(:id).uniq.size
intent_to_file_count = ClaimsApi::IntentToFile.where(created_at: @from..@to).pluck(:id).uniq.size
evidence_waiver_count = ClaimsApi::EvidenceWaiverSubmission.where(created_at: @from..@to).pluck(:id).uniq.size

ClaimsApi::SubmissionReportMailer.build(
@from,
@to,
submissions
pact_act_data,
disability_compensation_count,
power_of_attorney_count,
intent_to_file_count,
evidence_waiver_count
).deliver_now
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
}
table {
border-collapse: collapse;
margin-bottom:35px;
min-width:475px;
}
table tr th, table tr td {
border: 1px solid #d3d3d3;
Expand Down Expand Up @@ -49,8 +51,9 @@
<h1><%= @date_from %> - <%= @date_to %> (Eastern Time)</h1>
<hr>

<h2>Monthly Submissions</h2>

<% @data[:month].keys.each do |kind| %>
<h2>Monthly 526EZ <%= kind %> Claim Submissions</h2>
<table>
<tr>
<th>Consumer</th>
Expand All @@ -64,24 +67,5 @@
<% end %>
</table>
<% end %>

<br /><hr>

<% @data[:year].keys.each do |kind| %>
<h2>Yearly 526EZ <%= kind %> Claim Submissions</h2>
<table>
<tr>
<th>Consumer</th>
<th><%= kind %> submissions</th>
</tr>
<% @data[:year][kind].keys.each do |label| %>
<tr>
<td><%= label %></td>
<td><%= @data[:year][kind][label] %></td>
</tr>
<% end %>
</table>
<% end %>

</body>
</html>
95 changes: 95 additions & 0 deletions modules/claims_api/spec/mailers/report_monthly_submissions_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe ClaimsApi::SubmissionReportMailer, type: [:mailer] do
describe '#build' do
subject do
from = 1.month.ago
to = Time.zone.now

claim = create(:auto_established_claim, :status_established)
ClaimsApi::ClaimSubmission.create claim:, claim_type: 'PACT', consumer_label: 'Consumer name here'
pact_act_submission = ClaimsApi::ClaimSubmission.where(created_at: from..to)

described_class.build(
from,
to,
pact_act_submission,
67,
12,
112,
1
).deliver_now
end

it 'sends the email' do
expect(subject.subject).to eq('Benefits Claims Monthly Submission Report')
end

it 'has the correct HTML in the email' do
raw_source = subject.body.raw_source.gsub(/\s+/, '')
expect(raw_source).to include(email_html)
end

it 'sends to the right people' do
expect(subject.to).to eq(
%w[
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
]
)
end
end

# rubocop:disable Metrics/MethodLength
def email_html
"<h2>MonthlySubmissions</h2>
<table>
<tr>
<th>Consumer</th>
<th>DisabilityCompensationsubmissions</th>
</tr>
<tr>
<td>Form526</td>
<td>67</td>
</tr>
</table>
<table>
<tr>
<th>Consumer</th>
<th>PowerofAttorneysubmissions</th>
</tr>
<tr>
<td>Form2122/2122a</td>
<td>12</td>
</tr>
</table>
<table>
<tr>
<th>Consumer</th>
<th>IntenttoFilesubmissions</th>
</tr>
<tr>
<td>Form0966</td>
<td>112</td>
</tr>
</table>
<table>
<tr>
<th>Consumer</th>
<th>EvidenceWaiversubmissions</th>
</tr>
<tr>
<td>Form5133</td>
<td>1</td>
</tr>
</table>".gsub(/\s+/, '')
end
# rubocop:enable Metrics/MethodLength
end
Loading

0 comments on commit f85e810

Please sign in to comment.