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

Eatyourpeas/aggregation-logs-text-fixes #933

Open
wants to merge 6 commits into
base: development
Choose a base branch
from

Conversation

eatyourpeas
Copy link
Member

Overview

Another incremental improvement in the aggregation suite.
This ensures logs for any updates or creates to the KPIAggregation models, with a summary of how many models changed, and how many records updated with 0 if unscored.

There are also some fixes to the tests:

  1. update the filter to accept only completed cases who have completed a full year of care
  2. deprecate the get_filtered_cases_queryset_for which is not used for the aggregations anyway in favour of the newer filter_completed_cases_at_one_year_by_abstraction_level so testing closer to real life

Code changes

  1. add filter_completed_cases_at_one_year_by_abstraction_level to __init__.py to allow easier importing
  2. remove the return statement after testing for None, and nest any code below this test into a conditional.
  3. Change _register_kpi_scored_cases function in the e12case factory to include cases who have completed a full year of care
  4. deprecate get_filtered_cases_queryset_for which was now failing update KPIAggregation table tests, and replace with filter_completed_cases_at_one_year_by_abstraction_level which is used in the actual calculations anyway

Documentation changes (done or required as a result of this PR)

This needs doing - mostly to make explicit that the aggregation tables now only contain fully scored cases that have completed a full year of care

Related Issues

Closes #907

@eatyourpeas eatyourpeas requested a review from mbarton May 2, 2024 07:41
@eatyourpeas eatyourpeas self-assigned this May 2, 2024
Copy link
Member

@mbarton mbarton left a comment

Choose a reason for hiding this comment

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

Looks fine, just some small comments

# value_counts for this abstraction level already updated
# Set all measures to 0 for remaining abstraction levels
logger.debug(f"{len(list_of_updated_abstraction_level_instance)} scored {abstraction_level.name} instances updated with aggregated scores of a total {AbstractionKPIAggregationModel.objects.filter(cohort=cohort).count()} {abstraction_level.name}s")
empty_kpis = {
Copy link
Member

Choose a reason for hiding this comment

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

I think we can probably avoid writing the zero rows now we know that we must clear out all the aggregations rows and re-seed if we change the case filtering criteria at the top of the pipeline

kpi_value_counts = (
KPI.objects.filter(
registration__id__in=filtered_cases.values_list("registration")
registration__id__in=filtered_cases.values("registration")
Copy link
Member

Choose a reason for hiding this comment

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

Should this still be values_list as on line 266? I think if we change one we should change both

return
ABSTRACTION_CODE = value_count.pop(f"organisation__{abstraction_level.value}") #value_count.get(next(iter(value_count))) #
if ABSTRACTION_CODE is not None:
# the last value in each abstraction_level is None - discard
Copy link
Member

Choose a reason for hiding this comment

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

I agree with removing the early return but maybe the comment is clearer above the if?

I also don't think the last value is None, I think it's if we're grouping by an abstraction level not relevant here eg by local health board in England

cohort=6
)
)
# kpi_aggregation_model_instance = (
Copy link
Member

Choose a reason for hiding this comment

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

remove?

@mbarton
Copy link
Member

mbarton commented May 13, 2024

@eatyourpeas what's left to get this merged? :)

Copy link
Member Author

@eatyourpeas eatyourpeas left a comment

Choose a reason for hiding this comment

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

I am not sure how much extra this PR really adds any more. The new filter function is already in live, so this was really about the logs, the zero rows and maybe a test update.
Perhaps this is one we can do together or we could just close if it nolonger adds value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QE King's Lynn
2 participants