diff --git a/lib/periodic_jobs.rb b/lib/periodic_jobs.rb index 6ca7889613e..14c85656381 100644 --- a/lib/periodic_jobs.rb +++ b/lib/periodic_jobs.rb @@ -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') diff --git a/modules/claims_api/app/mailers/claims_api/submission_report_mailer.rb b/modules/claims_api/app/mailers/claims_api/submission_report_mailer.rb index 6f8007b9540..ed0d51b3c72 100644 --- a/modules/claims_api/app/mailers/claims_api/submission_report_mailer.rb +++ b/modules/claims_api/app/mailers/claims_api/submission_report_mailer.rb @@ -12,33 +12,20 @@ class SubmissionReportMailer < ApplicationMailer rockwell.rice@oddball.io ].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 diff --git a/modules/claims_api/app/sidekiq/claims_api/report_monthly_submissions.rb b/modules/claims_api/app/sidekiq/claims_api/report_monthly_submissions.rb index 5d0fa89b7cf..60f4944f57f 100644 --- a/modules/claims_api/app/sidekiq/claims_api/report_monthly_submissions.rb +++ b/modules/claims_api/app/sidekiq/claims_api/report_monthly_submissions.rb @@ -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 diff --git a/modules/claims_api/app/views/claims_api/submission_report_mailer/submission_report.html.erb b/modules/claims_api/app/views/claims_api/submission_report_mailer/submission_report.html.erb index 3b3d976dd6d..95b4a946f6e 100644 --- a/modules/claims_api/app/views/claims_api/submission_report_mailer/submission_report.html.erb +++ b/modules/claims_api/app/views/claims_api/submission_report_mailer/submission_report.html.erb @@ -10,6 +10,8 @@ } table { border-collapse: collapse; + margin-bottom:35px; + min-width:475px; } table tr th, table tr td { border: 1px solid #d3d3d3; @@ -49,8 +51,9 @@

<%= @date_from %> - <%= @date_to %> (Eastern Time)


+

Monthly Submissions

+ <% @data[:month].keys.each do |kind| %> -

Monthly 526EZ <%= kind %> Claim Submissions

@@ -64,24 +67,5 @@ <% end %>
Consumer
<% end %> - -

- - <% @data[:year].keys.each do |kind| %> -

Yearly 526EZ <%= kind %> Claim Submissions

- - - - - - <% @data[:year][kind].keys.each do |label| %> - - - - - <% end %> -
Consumer<%= kind %> submissions
<%= label %><%= @data[:year][kind][label] %>
- <% end %> - diff --git a/modules/claims_api/spec/mailers/report_monthly_submissions_spec.rb b/modules/claims_api/spec/mailers/report_monthly_submissions_spec.rb new file mode 100644 index 00000000000..5e57377769b --- /dev/null +++ b/modules/claims_api/spec/mailers/report_monthly_submissions_spec.rb @@ -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[ + alex.wilson@oddball.io + austin.covrig@oddball.io + emily.goodrich@oddball.io + jennica.stiehl@oddball.io + kayla.watanabe@adhocteam.us + matthew.christianson@adhocteam.us + rockwell.rice@oddball.io + ] + ) + end + end + + # rubocop:disable Metrics/MethodLength + def email_html + "

MonthlySubmissions

+ + + + + + + + + +
ConsumerDisabilityCompensationsubmissions
Form52667
+ + + + + + + + + +
ConsumerPowerofAttorneysubmissions
Form2122/2122a12
+ + + + + + + + + +
ConsumerIntenttoFilesubmissions
Form0966112
+ + + + + + + + + +
ConsumerEvidenceWaiversubmissions
Form51331
".gsub(/\s+/, '') + end + # rubocop:enable Metrics/MethodLength +end diff --git a/modules/claims_api/spec/sidekiq/report_monthly_submissions_spec.rb b/modules/claims_api/spec/sidekiq/report_monthly_submissions_spec.rb index 14592b36695..7bfc6ebe747 100644 --- a/modules/claims_api/spec/sidekiq/report_monthly_submissions_spec.rb +++ b/modules/claims_api/spec/sidekiq/report_monthly_submissions_spec.rb @@ -3,30 +3,117 @@ require 'rails_helper' RSpec.describe ClaimsApi::ReportMonthlySubmissions, type: :job do - before do - claim = create(:auto_established_claim, :status_established) # TODO: make this a pact claim - ClaimsApi::ClaimSubmission.create claim:, claim_type: 'PACT', consumer_label: 'Consumer name here' - create(:auto_established_claim, :status_established) - end + subject { described_class.new } describe '#perform' do let(:from) { 1.month.ago } let(:to) { Time.zone.now } - it 'sends mail' do - with_settings(Settings.claims_api, - report_enabled: true) do - Timecop.freeze - submissions = ClaimsApi::ClaimSubmission.where(created_at: from..to) - expect(ClaimsApi::SubmissionReportMailer).to receive(:build).once.with( - from, - to, - submissions - ).and_return(double.tap do |mailer| - expect(mailer).to receive(:deliver_now).once - end) - described_class.new.perform - Timecop.return + context 'with counts returned for all the record types' do + before do + claim = create(:auto_established_claim, :status_established) + ClaimsApi::ClaimSubmission.create claim:, claim_type: 'PACT', consumer_label: 'Consumer name here' + create(:auto_established_claim, :status_established) + + allow(ClaimsApi::AutoEstablishedClaim).to receive(:where).and_return(double(pluck: %w[claim1 claim_2])) + allow(ClaimsApi::PowerOfAttorney).to receive(:where).and_return(double(pluck: %w[poa_1 poa_2])) + allow(ClaimsApi::IntentToFile).to receive(:where).and_return(double(pluck: %w[itf_1 itf_2 otf_3])) + allow(ClaimsApi::EvidenceWaiverSubmission).to receive(:where).and_return(double(pluck: ['ews_1'])) + end + + it 'sends mail' do + with_settings(Settings.claims_api, + report_enabled: true) do + Timecop.freeze + pact_act_data = ClaimsApi::ClaimSubmission.where(created_at: from..to) + + expect(ClaimsApi::SubmissionReportMailer).to receive(:build).once.with( + from, + to, + pact_act_data, + 2, + 2, + 3, + 1 + ).and_return(double.tap do |mailer| + expect(mailer).to receive(:deliver_now).once + end) + + subject.perform + Timecop.return + end + end + end + + context 'with counts returned for all but ITF' do + before do + claim = create(:auto_established_claim, :status_established) + ClaimsApi::ClaimSubmission.create claim:, claim_type: 'PACT', consumer_label: 'Consumer name here' + create(:auto_established_claim, :status_established) + + allow(ClaimsApi::AutoEstablishedClaim).to receive(:where).and_return(double(pluck: %w[claim1 claim_2])) + allow(ClaimsApi::PowerOfAttorney).to receive(:where).and_return(double(pluck: %w[poa_1 poa_2])) + allow(ClaimsApi::IntentToFile).to receive(:where).and_return(double(pluck: %w[])) + allow(ClaimsApi::EvidenceWaiverSubmission).to receive(:where).and_return(double(pluck: ['ews_1'])) + end + + it 'sends mail' do + with_settings(Settings.claims_api, + report_enabled: true) do + Timecop.freeze + pact_act_data = ClaimsApi::ClaimSubmission.where(created_at: from..to) + + expect(ClaimsApi::SubmissionReportMailer).to receive(:build).once.with( + from, + to, + pact_act_data, + 2, + 2, + 0, + 1 + ).and_return(double.tap do |mailer| + expect(mailer).to receive(:deliver_now).once + end) + + subject.perform + Timecop.return + end + end + end + + context 'with counts returned for all but EWS' do + before do + claim = create(:auto_established_claim, :status_established) + ClaimsApi::ClaimSubmission.create claim:, claim_type: 'PACT', consumer_label: 'Consumer name here' + create(:auto_established_claim, :status_established) + + allow(ClaimsApi::AutoEstablishedClaim).to receive(:where).and_return(double(pluck: %w[claim1 claim_2])) + allow(ClaimsApi::PowerOfAttorney).to receive(:where).and_return(double(pluck: %w[poa_1 poa_2])) + allow(ClaimsApi::IntentToFile).to receive(:where).and_return(double(pluck: %w[])) + allow(ClaimsApi::EvidenceWaiverSubmission).to receive(:where).and_return(double(pluck: %w[])) + end + + it 'sends mail' do + with_settings(Settings.claims_api, + report_enabled: true) do + Timecop.freeze + pact_act_data = ClaimsApi::ClaimSubmission.where(created_at: from..to) + + expect(ClaimsApi::SubmissionReportMailer).to receive(:build).once.with( + from, + to, + pact_act_data, + 2, + 2, + 0, + 0 + ).and_return(double.tap do |mailer| + expect(mailer).to receive(:deliver_now).once + end) + + subject.perform + Timecop.return + end end end end diff --git a/spec/mailers/previews/claims_api_submission_report_mailer_preview.rb b/spec/mailers/previews/claims_api_submission_report_mailer_preview.rb index 9dc9549f684..14cdc7da55f 100644 --- a/spec/mailers/previews/claims_api_submission_report_mailer_preview.rb +++ b/spec/mailers/previews/claims_api_submission_report_mailer_preview.rb @@ -9,7 +9,10 @@ def build from, to, submissions, - yearly_submissions + disability_claims, + poa_claims, + itf_claims, + ews_claims ) end @@ -29,32 +32,23 @@ def submissions created_at: DateTime.now, updated_at: DateTime.now }, { id: 4, claim_id: '9096cd0e-0d97-4ee3-be3f-2279e47a81bc', claim_type: 'PACT', consumer_label: 'Claims API Smoketesting - Local - third consumer', - created_at: DateTime.now, updated_at: DateTime.now }, - { id: 5, claim_id: 'e31fa2aa-a009-4476-91a6-87b7421fdd74', - claim_type: 'another type', - consumer_label: 'Claims API Smoketesting - Local', created_at: DateTime.now, updated_at: DateTime.now } ] end - def yearly_submissions - [ - { id: 1, claim_id: '3a03bc5e-b77d-42c7-bad5-0fe3c334f852', - claim_type: 'PACT', consumer_label: 'Claims API Smoketesting - Local', - created_at: DateTime.now - 1.month, updated_at: DateTime.now - 1.month }, - { id: 2, claim_id: '87f2c86a-9773-425a-9477-adcae4011e7b', - claim_type: 'PACT', consumer_label: 'Claims API Smoketesting - Local', - created_at: DateTime.now - 2.months, updated_at: DateTime.now - 2.months }, - { id: 3, claim_id: 'c3527ebb-710a-4806-9339-59dc846623c9', - claim_type: 'PACT', consumer_label: 'Claims API Smoketesting - Local - second consumer', - created_at: DateTime.now, updated_at: DateTime.now }, - { id: 4, claim_id: '9096cd0e-0d97-4ee3-be3f-2279e47a81bc', - claim_type: 'PACT', consumer_label: 'Claims API Smoketesting - Local - third consumer', - created_at: DateTime.now, updated_at: DateTime.now }, - { id: 5, claim_id: 'e31fa2aa-a009-4476-91a6-87b7421fdd74', - claim_type: 'another type', - consumer_label: 'Claims API Smoketesting - Local', - created_at: DateTime.now, updated_at: DateTime.now } - ] + def disability_claims + 115 + end + + def poa_claims + 23 + end + + def itf_claims + 0 + end + + def ews_claims + 2 end end