Skip to content

Commit

Permalink
Adds approved claims failing qualification tasks
Browse files Browse the repository at this point in the history
One gotcha that we might need to deal with in this report is the
`dqt_teacher_status`. When the qualification claim verifier runs is uses
the dqt record to set some notes on the claim. If the claim has a
populated `dqt_teacher_status` field it uses that to build the dqt
teacher record object, if not the status is fetched from the api,
however this information from the api is not persisted to the claim.
When generating the report we don't want to hit the dqt api for
potentially many claims, so if we're missing this dqt status we don't
include it in the report. Checking the current academic year's claims
there don't seem to be any claims that would be returned from this
report that are missing their `dqt_teacher_status`. If missing
`dqt_teacher_status` in this report is causing issues for the ops team,
we could consider parsing the claim notes to get this information.
  • Loading branch information
rjlynch committed Dec 11, 2024
1 parent 03e0fbc commit 67d5338
Show file tree
Hide file tree
Showing 5 changed files with 454 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/admin/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def report
@report ||= case params[:name]
when "fe-approved-claims-with-failing-provider-verification"
Reports::FeApprovedClaimsWithFailingProviderVerification.new
when "approved-claims-failing-qualification-task"
Reports::ApprovedClaimsFailingQualificationTask.new
else
raise ActiveRecord::RecordNotFound
end
Expand Down
121 changes: 121 additions & 0 deletions app/models/admin/reports/approved_claims_failing_qualification_task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
module Admin
module Reports
class ApprovedClaimsFailingQualificationTask
HEADERS = [
"Claim reference",
"Teacher reference number",
"Policy",
"Status",
"Decision date",
"Decision agent",
"Qualification",
"ITT start year",
"ITT subject",
"ITT subjects",
"ITT start date",
"QTS award date",
"Qualification name"
]

def filename
"approved_claims_failing_qualification_task"
end

def to_csv
CSV.generate(
row_sep: "\r\n",
write_headers: true,
headers: HEADERS
) do |csv|
rows.each { |row| csv << row }
end
end

private

def rows
scope.map(&ClaimPresenter.method(:new)).map(&:to_a)
end

def scope
Claim
.approved
.where(academic_year: AcademicYear.current)
.joins(:tasks)
.merge(Task.where(name: "qualifications", passed: false))
.includes(:eligibility, decisions: :created_by)
end

class ClaimPresenter
include Admin::ClaimsHelper

def initialize(claim)
@claim = claim
end

def to_a
[
claim.reference,
claim.eligibility.teacher_reference_number,
I18n.t("#{claim.policy.locale_key}.policy_acronym"),
status(claim),
I18n.l(approval.created_at.to_date, format: :day_month_year),
approval.created_by.full_name,
qualification,
itt_academic_year&.to_s,
eligible_itt_subject,
dqt_teacher_record.itt_subjects.join(", "),
I18n.l(dqt_teacher_record.itt_start_date, format: :day_month_year),
I18n.l(dqt_teacher_record.qts_award_date, format: :day_month_year),
dqt_teacher_record.qualification_name
]
end

private

attr_reader :claim

def approval
@approval ||= claim.decisions.reject(&:undone).last
end

# StudentLoans doesn't have an eligible_itt_subject
def eligible_itt_subject
claim.eligibility.try(:eligible_itt_subject)
end

# StudentLoans doesn't have an itt_academic_year
def itt_academic_year
claim.eligibility.try(:itt_academic_year)
end

# StudentLoans doesn't have a qualification
def qualification
claim.eligibility.try(:qualification)
end

def itt_subjects
dqt_teacher_record&.itt_subjects
end

def itt_start_date
dqt_teacher_record&.itt_start_date
end

def qts_award_date
dqt_teacher_record&.qts_award_date
end

def qualification_name
dqt_teacher_record&.qualification_name
end

def dqt_teacher_record
@dqt_teacher_record ||= if claim.has_dqt_record?
Dqt::Teacher.new(claim.dqt_teacher_status)
end
end
end
end
end
end
6 changes: 6 additions & 0 deletions app/views/admin/reports/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@
admin_report_path("fe-approved-claims-with-failing-provider-verification", format: :csv),
secondary: true
) %>

<%= govuk_button_link_to(
"Approved claims failing qualification task",
admin_report_path("approved-claims-failing-qualification-task", format: :csv),
secondary: true
) %>
</div>
</div>
64 changes: 64 additions & 0 deletions spec/features/admin/reports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,68 @@
expect(row.fetch("Disciplinary")).to eq("Yes")
end
end

describe "Approved claims failing qualification task" do
it "returns a CSV report" do
claim = create(
:claim,
:with_dqt_teacher_status,
:approved,
policy: Policies::LevellingUpPremiumPayments,
first_name: "Elizabeth",
surname: "Hoover",
eligibility_attributes: {
teacher_reference_number: "1234567",
qualification: :postgraduate_itt,
itt_academic_year: "2023/2024",
eligible_itt_subject: :mathematics
},
dqt_teacher_status: {
initial_teacher_training: {
programme_start_date: "2022-09-01",
subject1: "mathematics",
subject1_code: "G100",
qualification: "BA (Hons)"
},
qualified_teacher_status: {
qts_date: "2022-12-01"
}
}
)

create(
:task,
:failed,
name: "qualifications",
claim: claim
)

sign_in_as_service_operator

visit admin_claims_path

click_on "Reports"

click_on "Approved claims failing qualification task"

csv_data = page.body

csv = CSV.parse(csv_data, headers: true)
row = csv.first

expect(row.fetch("Claim reference")).to eq(claim.reference)
expect(row.fetch("Teacher reference number")).to eq("1234567")
expect(row.fetch("Policy")).to eq("STRI")
expect(row.fetch("Status")).to eq("Approved awaiting payroll")
expect(row.fetch("Decision date")).to eq("06/12/2024")
expect(row.fetch("Decision agent")).to eq("Aaron Admin")
expect(row.fetch("Qualification")).to eq("postgraduate_itt")
expect(row.fetch("ITT start year")).to eq("2023/2024")
expect(row.fetch("ITT subject")).to eq("mathematics")
expect(row.fetch("ITT subjects")).to eq("mathematics")
expect(row.fetch("ITT start date")).to eq("01/09/2022")
expect(row.fetch("QTS award date")).to eq("01/12/2022")
expect(row.fetch("Qualification name")).to eq("BA (Hons)")
end
end
end
Loading

0 comments on commit 67d5338

Please sign in to comment.