-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Automated] Merged master into target k8s
- Loading branch information
Showing
7 changed files
with
314 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -51,6 +38,7 @@ def build(date_from, date_to, submissions = nil, yearly_submissions = nil) # rub | |
body: | ||
) | ||
end | ||
# rubocop:enable Metrics/ParameterLists | ||
|
||
private | ||
|
||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
modules/claims_api/spec/mailers/report_monthly_submissions_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.