rcpch / rcpch-audit-engine

Epilepsy12 Audit Platform
https://e12.rcpch.ac.uk/
GNU Affero General Public License v3.0
5 stars 5 forks source link

Refactor to use consistent helper functions when generating the KPI report #944

Closed mbarton closed 3 months ago

mbarton commented 3 months ago

When @eatyourpeas, @dc2007git and I mob coded on https://github.com/rcpch/rcpch-audit-engine/pull/941 we felt like there was a simpler way to express the code but focused on fixing the report with the minimum possible changes.

This PR tries to capture as many simplifications as possible before the context inevitably falls out of my head!

The core change is to use the functions from aggregate_by.py consistently across all sheets we generate in the report. To achieve this I broke them out into two:

These changes allow us to push the sheet specific logic back up into kpi.py, for example combining local health boards in Wales and trusts in England when generating the "HBT" sheet.

I've also linked the definition of the measures directly to the fields on the models. This doesn't change any functionality but makes it clearer they're linked and in the unlikely event we change them we would automatically update here.

That means we can pass the Django field definition all the way down to create_kpi_report_row, meaning one less parameter for all the function calls. This is maybe not clearer than before but felt like a logical follow on from linking directly to the model definitions at the top level of kpi.py.

Questions