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

New provisional assessment report #5862

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions app/models/stats/stats_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def updatable?
Report.new(name: :agfs_management_information_statistics, date_required: true),
Report.new(name: :lgfs_management_information_statistics, date_required: true),
Report.new(name: :provisional_assessment),
Report.new(name: :provisional_assessment_new),
Report.new(name: :provisional_assessment_summary),
Report.new(name: :rejections_refusals),
Report.new(name: :submitted_claims),
Report.new(name: :reports_access_details, hidden: true, updatable: false)].freeze
Expand Down
55 changes: 55 additions & 0 deletions app/services/reports/provisional_assessments_new.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module Reports
class ProvisionalAssessmentsNew
COLUMNS = %w[
supplier_name
total
assessed
disallowed
bill_type
case_type
earliest_representation_order_date
case_worker
maat_number
].freeze
INCLUDES = [
:case_type,
:determinations,
:case_workers,
{
external_user: :provider,
defendants: :representation_orders
}
].freeze

def self.call(...) = new(...).call

def call
Claim::BaseClaim.includes(INCLUDES)
.where(state: %w[authorised part_authorised])
.map { |claim| format_row(claim) }.to_a
end

private

def format_row(claim) = summary_fields(claim) + extended_fields(claim)

def summary_fields(claim)
[
claim.provider.name,
claim.total_including_vat,
claim.amount_assessed,
claim.total_including_vat - claim.amount_assessed
]
end

def extended_fields(claim)
[
claim.type.gsub('Claim::', ''),
claim.case_type.name,
claim.earliest_representation_order_date,
claim.case_workers.last.name,
claim.defendants.last.representation_orders.last.maat_reference
]
end
end
end
12 changes: 12 additions & 0 deletions app/services/reports/provisional_assessments_summary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Reports
class ProvisionalAssessmentsSummary < ProvisionalAssessmentsNew
COLUMNS = %w[
supplier_name
total
assessed
disallowed
].freeze

def extended_fields(claim) = []
end
end
4 changes: 3 additions & 1 deletion app/services/stats/simple_report_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def report_klass
@report_klass ||= {
provisional_assessment: Reports::ProvisionalAssessments,
rejections_refusals: Reports::RejectionsRefusals,
submitted_claims: Reports::SubmittedClaims
submitted_claims: Reports::SubmittedClaims,
provisional_assessment_new: Reports::ProvisionalAssessmentsNew,
provisional_assessment_new: Reports::ProvisionalAssessmentsSummary,
}[@report.to_sym]
end
end
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en/views/management_information.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ en:
management_information_v2_html: |
Management information <strong class="govuk-tag govuk-tag--blue">beta</strong>
provisional_assessment_html: Provisional assessment
provisional_assessment_new_html: Provisional assessment (New)
provisional_assessment_summary_html: Provisional assessment (New/Summary)
rejections_refusals_html: 'Rejections/Refusals'
submitted_claims_html: Submitted claims
reports_access_details_html: Reports access details
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
agfs_management_information_statistics
lgfs_management_information_statistics
provisional_assessment
provisional_assessment_new
provisional_assessment_summary
rejections_refusals
submitted_claims
reports_access_details]
Expand Down
88 changes: 88 additions & 0 deletions spec/services/reports/provisional_assessments_new_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
require 'rails_helper'
require File.expand_path('shared_examples_for_reports.rb', __dir__)

RSpec.describe Reports::ProvisionalAssessmentsNew do
subject(:report) { described_class.new }

it_behaves_like 'data for an MI report'

describe '::COLUMNS' do
subject { described_class::COLUMNS }

it { is_expected.to eq(
%w[
supplier_name
total
assessed
disallowed
bill_type
case_type
earliest_representation_order_date
case_worker
maat_number
]
)}
end

describe '#call' do
subject(:call) { described_class.call }

context 'with a single draft claim' do
before { create(:claim, :draft) }

it { is_expected.to be_empty }
end

context 'with a single submitted claim' do
before { create(:claim, :submitted) }

it { is_expected.to be_empty }
end

context 'with a single allocated claim' do
before { create(:claim, :allocated) }

it { is_expected.to be_empty }
end

context 'with a single rejected claim' do
before { create(:claim, :rejected) }

it { is_expected.to be_empty }
end

context 'with a single redetermination claim' do
before { create(:claim, :redetermination) }

it { is_expected.to be_empty }
end

context 'with a single authorised claim' do
before { create(:claim, :authorised) }

it { expect(call.length).to eq(1) }
end

context 'with a single part_authorised claim' do
let!(:claim) do
create(
:claim, :part_authorised,
external_user:
)
end
let(:external_user) { build(:external_user, provider: build(:provider, name: 'Test provider')) }

it { expect(call.length).to eq(1) }
it { expect(call.first.length).to eq(9) }
it { expect(call.first[0]).to eq('Test provider') }
it { expect(call.first[1]).to eq(claim.total_including_vat) }
it { expect(call.first[2]).to eq(claim.amount_assessed) }
it { expect(call.first[3]).to eq(claim.total_including_vat - claim.amount_assessed) }
it { expect(call.first[4]).to eq('AdvocateClaim') }
it { expect(call.first[5]).to eq(claim.case_type.name) }
it { expect(call.first[6]).to eq(claim.earliest_representation_order_date) }
it { expect(call.first[7]).to eq(claim.case_workers.last.name) }
it { expect(call.first[8]).to eq(claim.defendants.last.representation_orders.last.maat_reference) }
end
end
end
78 changes: 78 additions & 0 deletions spec/services/reports/provisional_assessments_summary_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
require 'rails_helper'
require File.expand_path('shared_examples_for_reports.rb', __dir__)

RSpec.describe Reports::ProvisionalAssessmentsSummary do
subject(:report) { described_class.new }

describe '::COLUMNS' do
subject { described_class::COLUMNS }

it { is_expected.to eq(
%w[
supplier_name
total
assessed
disallowed
]
)}
end

it_behaves_like 'data for an MI report'

describe '#call' do
subject(:call) { described_class.call }

context 'with a single draft claim' do
before { create(:claim, :draft) }

it { is_expected.to be_empty }
end

context 'with a single submitted claim' do
before { create(:claim, :submitted) }

it { is_expected.to be_empty }
end

context 'with a single allocated claim' do
before { create(:claim, :allocated) }

it { is_expected.to be_empty }
end

context 'with a single rejected claim' do
before { create(:claim, :rejected) }

it { is_expected.to be_empty }
end

context 'with a single redetermination claim' do
before { create(:claim, :redetermination) }

it { is_expected.to be_empty }
end

context 'with a single authorised claim' do
before { create(:claim, :authorised) }

it { expect(call.length).to eq(1) }
end

context 'with a single part_authorised claim' do
let!(:claim) do
create(
:claim, :part_authorised,
external_user:
)
end
let(:external_user) { build(:external_user, provider: build(:provider, name: 'Test provider')) }

it { expect(call.length).to eq(1) }
it { expect(call.first.length).to eq(4) }
it { expect(call.first[0]).to eq('Test provider') }
it { expect(call.first[1]).to eq(claim.total_including_vat) }
it { expect(call.first[2]).to eq(claim.amount_assessed) }
it { expect(call.first[3]).to eq(claim.total_including_vat - claim.amount_assessed) }
end
end
end
5 changes: 5 additions & 0 deletions spec/services/reports/shared_examples_for_reports.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RSpec.shared_examples 'data for an MI report' do
it { expect(described_class::COLUMNS).to be_an(Array) }
it { expect(described_class.call).to be_an(Array) }
it { expect(described_class.new.call).to be_an(Array) }
end