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

Ops reports #3457

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Ops reports #3457

wants to merge 7 commits into from

Conversation

rjlynch
Copy link
Contributor

@rjlynch rjlynch commented Dec 6, 2024

Ops reports

This PR introduces some new reporting functionality for the ops team.
We've added a new button on the admin claims index page that links to the
/admin/reports page where the ops team can download various reports.

Initially there are three reports:

  1. Duplicate approved claims
  2. Approved claims failing qualification task
  3. FE approved claims failing provider verification

Reports 2 and 3 are fairly straight forward, we just need to join to the
appropriate tasks and present the data. Report 1 is involved! For report 1 we
need to duplicate the functionality of the Claim::MatchingAttributeFinder but
rather than checking for duplicates of a single claim, it needs to work across
all claims. Running the claim matching attribute finder in a loop over all
claims takes a long time (6 minuets to check 1000 claims), even with moving
generating the report into a background job it would be tanning the DB and who
wants to wait for an 1hr 30 for a report to generate! To avoid this we've
re implemented all the duplicate checking in SQL.

Having the report in SQL feels a little less maintainable, so something we
might want to consider is:

  • when a claim is created kick off a background job to check for duplicates
    using claim matching attribute finder
  • if duplicates are found associate them with the "source" claim using some
    new join model
  • duplicate claims are then claims which can be joined with the source model

However we'd need to back fill the duplicate records for existing claims on
production using something like the logic we've written here for finding the
duplicates.

If we do decide to keep the version of the claim duplicate checking from this
pr then we probably want to update the Claim::MatchingAttributeFinder to use
the logic introduced in this PR so we don't have two definitions of what
constitutes a duplicate claim.

Open for suggestions of the namespacing of these reports.

NOTE for reviewers: probably worth reviewing each commit separately.

@rjlynch rjlynch force-pushed the CAPT-1797-ops-queries branch from dc8caee to c84088e Compare December 9, 2024 14:41
@rjlynch rjlynch added the deploy Deploy a review app for this PR label Dec 9, 2024
@rjlynch rjlynch force-pushed the CAPT-1797-ops-queries branch from c84088e to 57cd3ea Compare December 9, 2024 16:30
end
end
end
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kenfodder @slorek instead of doing this gnarly query we could:

  • add a new claim verifier for detecting duplicates
  • when the verifier runs use the existing matching attributes finder code to find any duplciates
  • create a record associating the new claim with these duplicates (Duplicate belongs_to :source_claim, belongs_to :duplicate_claim)
  • replace the use of matching attribute finder in the app with looking at the new duplicates record for the given claim.
  • this report can be simplified by simply joining claims to the new duplicate record.

Might need this query logic for the initial back fill on production but it can then be deleted.

What do you guys think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something along these lines 07013ac

Adds the model to handle generating the reporting code for further
education claims that have been approved but with a failing provider
verification.
Adds the controller and views for downloading the ops reports.
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.
Adds the query to identify duplicate approved claims.
As per the MatchingAttributeFinder claims can either be duplicates on
claim attributes or on eligibility attributes. Certain eligibilities can
only be compared with other eligibilities determined by the policy's
`SomePolicy.policies_claimable` method. Eligibilities define the
attributes they should be compared with other eligibilities by in their
`SomePolicy.eligibility_matching_attributes` method, however some
policies that are comparable don't implement the attributes used for
finding matches (eg `EarlyYearsPayments` is in `EarlyCareerPayments`
`policies_claimable` list, but it doesn't implement
`teacher_reference_number` which is what `EarlyCareerPayments` uses to
determine duplicates). We have to do some fairly gnarl joins and unions
to compare eligibilities!

When comparing claims we search all approved claims in the current
academic year for duplicates, ignoring the claim's policy's
`policies_claimable` list, this is how MatchingAttributeFinder works so
we've kept that behaviour. For each group in the
`CLAIM_ATTRIBUTE_GROUPS_TO_MATCH` list we AND the conditions together,
normalising strings, we then use UNION to handle the OR conditions, this
performs significantly better than complicating the join condition. When
adding new attributes to the duplicate detection list we _really_ need
to make sure we add the appropriate indexes.
Return the duplicate claim ids from the query and introduce a struct to
wrap the result. This change will make it easier to reuse this query if
trying to find duplicates of a specific claim.
Noticed we were missing the csv extension on the report
Ignores the sql injection warning in duplicate claims. Non of the
interpolated values in this query are supplable by a user, and using
bind params would make this a lot harder to read! Anyone modifying this
query needs to be careful not to introduce a sql injection attack!
@rjlynch
Copy link
Contributor Author

rjlynch commented Dec 18, 2024

Part of the work in CAPT-2065 (#3468) is to show the matching attribute alert for all
policy combinations (eg include IRP when checking other policies for dupes).
No longer needing to handle policy combinations (as we can compare them all)
will let us greatly simplify the duplicates_by_eligibility query.
I'll hold off merging this pr until I've refactored duplicates_by_eligibility
to remove the policy combination handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deploy Deploy a review app for this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant