From 3650c42f317b30e1c711ab793ba1c7900b03fe2e Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Mon, 10 Jul 2023 17:26:13 +0100 Subject: [PATCH 1/4] New provisional assessment report --- .../reports/provisional_assessments_new.rb | 47 ++++++++++++ .../provisional_assessments_new_spec.rb | 74 +++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 app/services/reports/provisional_assessments_new.rb create mode 100644 spec/services/reports/provisional_assessments_new_spec.rb diff --git a/app/services/reports/provisional_assessments_new.rb b/app/services/reports/provisional_assessments_new.rb new file mode 100644 index 0000000000..d564b7be0c --- /dev/null +++ b/app/services/reports/provisional_assessments_new.rb @@ -0,0 +1,47 @@ +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) + total = claim.total_including_vat + assessed = claim.amount_assessed + [ + claim.provider.name, total, assessed, total - assessed, + 'TBD - Bill type', + 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 diff --git a/spec/services/reports/provisional_assessments_new_spec.rb b/spec/services/reports/provisional_assessments_new_spec.rb new file mode 100644 index 0000000000..fb57275738 --- /dev/null +++ b/spec/services/reports/provisional_assessments_new_spec.rb @@ -0,0 +1,74 @@ +require 'rails_helper' + +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 + +RSpec.describe Reports::ProvisionalAssessmentsNew do + subject(:report) { described_class.new } + + 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[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(Bill type) } + 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 From b6d1db463cdd8ebca3bebf90850ec2809dd2cafe Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Tue, 11 Jul 2023 09:25:40 +0100 Subject: [PATCH 2/4] Add bill type to report I think this is the correct value --- .../reports/provisional_assessments_new.rb | 20 +++++++++++++------ .../provisional_assessments_new_spec.rb | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/services/reports/provisional_assessments_new.rb b/app/services/reports/provisional_assessments_new.rb index d564b7be0c..5abff119e9 100644 --- a/app/services/reports/provisional_assessments_new.rb +++ b/app/services/reports/provisional_assessments_new.rb @@ -21,7 +21,7 @@ class ProvisionalAssessmentsNew } ].freeze - def self.call = new.call + def self.call(...) = new(...).call def call Claim::BaseClaim.includes(INCLUDES) @@ -31,12 +31,20 @@ def call private - def format_row(claim) - total = claim.total_including_vat - assessed = claim.amount_assessed + 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.provider.name, total, assessed, total - assessed, - 'TBD - Bill type', + claim.type.gsub('Claim::', ''), claim.case_type.name, claim.earliest_representation_order_date, claim.case_workers.last.name, diff --git a/spec/services/reports/provisional_assessments_new_spec.rb b/spec/services/reports/provisional_assessments_new_spec.rb index fb57275738..7955209452 100644 --- a/spec/services/reports/provisional_assessments_new_spec.rb +++ b/spec/services/reports/provisional_assessments_new_spec.rb @@ -64,7 +64,7 @@ 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(Bill type) } + 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) } From 0989a23be2505b2223c633df08dc4cc86b0763fe Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Tue, 11 Jul 2023 14:31:02 +0100 Subject: [PATCH 3/4] Add new provisional assesment report --- app/models/stats/stats_report.rb | 1 + app/services/stats/simple_report_generator.rb | 3 ++- config/locales/en/views/management_information.yml | 1 + .../requests/case_workers/admin/management_information_spec.rb | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/stats/stats_report.rb b/app/models/stats/stats_report.rb index 6ce13ce613..141226d76a 100644 --- a/app/models/stats/stats_report.rb +++ b/app/models/stats/stats_report.rb @@ -29,6 +29,7 @@ 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: :rejections_refusals), Report.new(name: :submitted_claims), Report.new(name: :reports_access_details, hidden: true, updatable: false)].freeze diff --git a/app/services/stats/simple_report_generator.rb b/app/services/stats/simple_report_generator.rb index c261c4e3d1..5b58fb7d6a 100644 --- a/app/services/stats/simple_report_generator.rb +++ b/app/services/stats/simple_report_generator.rb @@ -21,7 +21,8 @@ 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 }[@report.to_sym] end end diff --git a/config/locales/en/views/management_information.yml b/config/locales/en/views/management_information.yml index fd9f8dba11..8b6aa3a9f3 100644 --- a/config/locales/en/views/management_information.yml +++ b/config/locales/en/views/management_information.yml @@ -56,6 +56,7 @@ en: management_information_v2_html: | Management information beta provisional_assessment_html: Provisional assessment + provisional_assessment_new_html: Provisional assessment (New) rejections_refusals_html: 'Rejections/Refusals' submitted_claims_html: Submitted claims reports_access_details_html: Reports access details diff --git a/spec/requests/case_workers/admin/management_information_spec.rb b/spec/requests/case_workers/admin/management_information_spec.rb index cb3526ceb2..b76fecb777 100644 --- a/spec/requests/case_workers/admin/management_information_spec.rb +++ b/spec/requests/case_workers/admin/management_information_spec.rb @@ -68,6 +68,7 @@ agfs_management_information_statistics lgfs_management_information_statistics provisional_assessment + provisional_assessment_new rejections_refusals submitted_claims reports_access_details] From 3100fd41faca7451330ecf59b91352c6eb9cedc7 Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Tue, 11 Jul 2023 15:45:15 +0100 Subject: [PATCH 4/4] Add summary provisional assessment report --- app/models/stats/stats_report.rb | 1 + .../provisional_assessments_summary.rb | 12 +++ app/services/stats/simple_report_generator.rb | 3 +- .../en/views/management_information.yml | 1 + .../admin/management_information_spec.rb | 1 + .../provisional_assessments_new_spec.rb | 26 +++++-- .../provisional_assessments_summary_spec.rb | 78 +++++++++++++++++++ .../reports/shared_examples_for_reports.rb | 5 ++ 8 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 app/services/reports/provisional_assessments_summary.rb create mode 100644 spec/services/reports/provisional_assessments_summary_spec.rb create mode 100644 spec/services/reports/shared_examples_for_reports.rb diff --git a/app/models/stats/stats_report.rb b/app/models/stats/stats_report.rb index 141226d76a..fdafd3289c 100644 --- a/app/models/stats/stats_report.rb +++ b/app/models/stats/stats_report.rb @@ -30,6 +30,7 @@ def updatable? 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 diff --git a/app/services/reports/provisional_assessments_summary.rb b/app/services/reports/provisional_assessments_summary.rb new file mode 100644 index 0000000000..36032528f9 --- /dev/null +++ b/app/services/reports/provisional_assessments_summary.rb @@ -0,0 +1,12 @@ +module Reports + class ProvisionalAssessmentsSummary < ProvisionalAssessmentsNew + COLUMNS = %w[ + supplier_name + total + assessed + disallowed + ].freeze + + def extended_fields(claim) = [] + end +end \ No newline at end of file diff --git a/app/services/stats/simple_report_generator.rb b/app/services/stats/simple_report_generator.rb index 5b58fb7d6a..40ccf648af 100644 --- a/app/services/stats/simple_report_generator.rb +++ b/app/services/stats/simple_report_generator.rb @@ -22,7 +22,8 @@ def report_klass provisional_assessment: Reports::ProvisionalAssessments, rejections_refusals: Reports::RejectionsRefusals, submitted_claims: Reports::SubmittedClaims, - provisional_assessment_new: Reports::ProvisionalAssessmentsNew + provisional_assessment_new: Reports::ProvisionalAssessmentsNew, + provisional_assessment_new: Reports::ProvisionalAssessmentsSummary, }[@report.to_sym] end end diff --git a/config/locales/en/views/management_information.yml b/config/locales/en/views/management_information.yml index 8b6aa3a9f3..8ca695e5ae 100644 --- a/config/locales/en/views/management_information.yml +++ b/config/locales/en/views/management_information.yml @@ -57,6 +57,7 @@ en: Management information beta 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 diff --git a/spec/requests/case_workers/admin/management_information_spec.rb b/spec/requests/case_workers/admin/management_information_spec.rb index b76fecb777..68a0c3d51b 100644 --- a/spec/requests/case_workers/admin/management_information_spec.rb +++ b/spec/requests/case_workers/admin/management_information_spec.rb @@ -69,6 +69,7 @@ lgfs_management_information_statistics provisional_assessment provisional_assessment_new + provisional_assessment_summary rejections_refusals submitted_claims reports_access_details] diff --git a/spec/services/reports/provisional_assessments_new_spec.rb b/spec/services/reports/provisional_assessments_new_spec.rb index 7955209452..faf7f8defe 100644 --- a/spec/services/reports/provisional_assessments_new_spec.rb +++ b/spec/services/reports/provisional_assessments_new_spec.rb @@ -1,16 +1,29 @@ require 'rails_helper' - -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 +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 } @@ -60,6 +73,7 @@ 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) } diff --git a/spec/services/reports/provisional_assessments_summary_spec.rb b/spec/services/reports/provisional_assessments_summary_spec.rb new file mode 100644 index 0000000000..23e817ffeb --- /dev/null +++ b/spec/services/reports/provisional_assessments_summary_spec.rb @@ -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 diff --git a/spec/services/reports/shared_examples_for_reports.rb b/spec/services/reports/shared_examples_for_reports.rb new file mode 100644 index 0000000000..60c59ce62d --- /dev/null +++ b/spec/services/reports/shared_examples_for_reports.rb @@ -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