Skip to content

Commit

Permalink
Merge pull request #1180 from rcpch/eatyourpeas/issue1169
Browse files Browse the repository at this point in the history
transfer-kpi-organisation
  • Loading branch information
eatyourpeas authored Jan 19, 2025
2 parents a9aa4f8 + 9075d9e commit 410c5fd
Show file tree
Hide file tree
Showing 7 changed files with 1,348 additions and 52 deletions.
2 changes: 1 addition & 1 deletion epilepsy12/common_view_functions/aggregate_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def calculate_kpi_value_counts_queryset(
if abstraction_level is EnumAbstractionLevel.NATIONAL:
# NO NEED TO GROUPBY IF NATIONAL
kpi_value_counts = KPI.objects.filter(
registration__id__in=filtered_cases.values_list("registration")
registration__id__in=filtered_cases.values_list("registration"),
).aggregate(**aggregate_queries)
else:
kpi_value_counts = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# python imports
from dateutil.relativedelta import relativedelta

# django imports

Expand Down
2 changes: 0 additions & 2 deletions epilepsy12/common_view_functions/calculate_kpis.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ def calculate_kpis(registration_instance):
calculate_age_at_first_paediatric_assessment_in_years(registration_instance)
)

print(f"age_at_first_paediatric_assessment: {age_at_first_paediatric_assessment}")

# child must be registered in the audit for the KPI to be counted
if not check_is_registered(registration_instance):
# cannot proceed any further if registration incomplete.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Generated by Django 5.1.4 on 2025-01-19 15:03

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("epilepsy12", "0044_alter_comorbidity_comorbidityentity"),
]

operations = [
migrations.AlterField(
model_name="kpi",
name="assessment_of_mental_health_issues",
field=models.IntegerField(
default=None,
help_text={
"label": "6. Assessment of Mental Health Issues",
"reference": "Percentage of children and young people with epilepsy where there is documented evidence that they have been asked about mental health either through clinical screening, or a questionnaire/measure.",
},
null=True,
),
),
migrations.AlterField(
model_name="kpi",
name="comprehensive_care_planning_agreement",
field=models.IntegerField(
default=None,
help_text={
"label": "9A. Care Planning Agreement",
"reference": "Percentage of children and young people with epilepsy after 12 months where there is evidence of a comprehensive care plan that is agreed between the person, their family and/or carers and primary and secondary care providers, and the care plan has been updated where necessary.",
},
null=True,
),
),
migrations.AlterField(
model_name="kpi",
name="comprehensive_care_planning_content",
field=models.IntegerField(
default=None,
help_text={
"label": "9B. Care Planning Components",
"reference": "Percentage of children diagnosed with epilepsy with documented evidence of communication regarding core elements of care planning (items a - f).",
},
null=True,
),
),
migrations.AlterField(
model_name="kpi",
name="epilepsy_specialist_nurse",
field=models.IntegerField(
default=None,
help_text={
"label": "2. Access to Epilepsy Specialist Nurse",
"reference": "Percentage of children and young people with epilepsy, with input by epilepsy specialist nurse within the first year of care.",
},
null=True,
),
),
migrations.AlterField(
model_name="kpi",
name="epilepsy_surgery_referral",
field=models.IntegerField(
default=None,
help_text={
"label": "3b. Epilepsy Surgery Referral",
"reference": "Percentage of ongoing children and young people meeting defined epilepsy surgery referral criteria with evidence of epilepsy surgery referral.",
},
null=True,
),
),
migrations.AlterField(
model_name="kpi",
name="mental_health_support",
field=models.IntegerField(
default=None,
help_text={
"label": "7. Mental Health Support",
"reference": "Percentage of children and young people with epilepsy and a mental health problem who have evidence of mental health support",
},
null=True,
),
),
migrations.AlterField(
model_name="kpi",
name="mri",
field=models.IntegerField(
default=None,
help_text={
"label": "5. MRI within 6 weeks",
"reference": "Percentage of children and young people with defined indications for an MRI, who had timely MRI within 6 weeks of request",
},
null=True,
),
),
migrations.AlterField(
model_name="kpi",
name="paediatrician_with_expertise_in_epilepsies",
field=models.IntegerField(
default=None,
help_text={
"label": "1. Paediatrician with expertise in Epilepsy within 2 weeks",
"reference": "Percentage of children and young people with epilepsy, with input by a 'consultant paediatrician with expertise in epilepsies' within 2 weeks of initial referral",
},
null=True,
),
),
migrations.AlterField(
model_name="kpi",
name="sodium_valproate",
field=models.IntegerField(
default=None,
help_text={
"label": "8. Medication and Reproduction Risks",
"reference": "Percentage of all females 12 years and above currently on valproate treatment with annual risk acknowledgement form completed",
},
null=True,
),
),
migrations.AlterField(
model_name="kpi",
name="tertiary_input",
field=models.IntegerField(
default=None,
help_text={
"label": "3a. Tertiary Input",
"reference": "Percentage of children and young people meeting defined criteria for paediatric neurology referral, with input of tertiary care and/or CESS referral within the first year of care.",
},
null=True,
),
),
]
166 changes: 163 additions & 3 deletions epilepsy12/tests/model_tests/test_assessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
from django.core.exceptions import ValidationError

# RCPCH imports
from epilepsy12.models import (
Assessment,
)
from epilepsy12.models import Assessment, Organisation, Site
from epilepsy12.views.assessment_views import update_site_model

"""
- [x] Assessment.consultant_paediatrician_referral_date and Assessment.consultant_paediatrician_input_date are both None if Assessment.consultant_paediatrician_referral_made is False
Expand Down Expand Up @@ -305,3 +304,164 @@ def test_epilepsy_nurse_specialist_wait_same_day(e12_case_factory):

# Check if the calculated wait time for the epilepsy nurse specialist is correct
assert assessment.epilepsy_nurse_specialist_wait() == 0


@pytest.mark.django_db
def test_allocate_general_paediatric_centre_to_case_same_organisation_as_lead(
e12_case_factory, e12_site_factory
):
"""
Tests the update_site_model function
it accepts the following parameters:
centre_role: str, selected_organisation, case, user, site_id=None
centre_role is one of the following:
- general_paediatric_centre
- paediatric_neurology_centre
- epilepsy_surgery_centre
"""
# create a case object
case = e12_case_factory(
registration__assessment__consultant_paediatrician_input_date=None
)

GOSH = Organisation.objects.get(
ods_code="RP401",
trust__ods_code="RP4",
)

ADDENBROOKES = Organisation.objects.get(ods_code="RGT01") # Addenbrookes

site = e12_site_factory(
organisation=ADDENBROOKES,
case=case,
site_is_primary_centre_of_epilepsy_care=True,
site_is_actively_involved_in_epilepsy_care=True,
site_is_general_paediatric_centre=False,
)

# create a case object
assessment = case.registration.assessment

# create a user object
user = assessment.registration.case.created_by

# create an organisation object - this is the selected organisation and may not be the same as the site organisation
selected_organisation = ADDENBROOKES

site = Site.objects.get(
organisation__ods_code="RGT01",
case=case,
)

# ensure the site associated with the case is not a general paediatric centre
assert site.organisation == ADDENBROOKES
assert site.site_is_primary_centre_of_epilepsy_care is True
assert site.site_is_actively_involved_in_epilepsy_care is True
assert site.site_is_general_paediatric_centre is False

# update the site model
update_site_model(
centre_role="general_paediatric_centre",
selected_organisation=selected_organisation,
case=case,
user=user,
site_id=site.id,
)

# check if the site model was updated
site = Site.objects.get(
organisation__ods_code="RGT01",
case=case,
)

# check if the site model was updated
assert site.organisation == ADDENBROOKES
assert site.site_is_primary_centre_of_epilepsy_care is True
assert site.site_is_actively_involved_in_epilepsy_care is True
assert site.site_is_general_paediatric_centre is True
assert site.case == case


@pytest.mark.django_db
def test_allocate_general_paediatric_centre_to_case_different_organisation_as_lead(
e12_case_factory, e12_site_factory
):
"""
Tests the update_site_model function
it accepts the following parameters:
centre_role: str, selected_organisation, case, user, site_id=None
centre_role is one of the following:
- general_paediatric_centre
- paediatric_neurology_centre
- epilepsy_surgery_centre
"""
# create a case object
case = e12_case_factory(
registration__assessment__consultant_paediatrician_input_date=None
)

GOSH = Organisation.objects.get(
ods_code="RP401",
trust__ods_code="RP4",
)

ADDENBROOKES = Organisation.objects.get(ods_code="RGT01") # Addenbrookes

site = e12_site_factory(
organisation=ADDENBROOKES,
case=case,
site_is_primary_centre_of_epilepsy_care=True,
site_is_actively_involved_in_epilepsy_care=True,
site_is_general_paediatric_centre=False,
)

# create a case object
assessment = case.registration.assessment

# create a user object
user = assessment.registration.case.created_by

# create an organisation object - this is the selected organisation and may not be the same as the site organisation
selected_organisation = GOSH

site = Site.objects.get(
organisation=ADDENBROOKES,
case=case,
)

# update the site model
update_site_model(
centre_role="general_paediatric_centre",
selected_organisation=selected_organisation,
case=case,
user=user,
site_id=site.id,
)

# check if the site model was updated
addenbrookes_site = Site.objects.get(
organisation=ADDENBROOKES,
case=case,
)

gosh_site = Site.objects.get(
organisation=GOSH,
case=case,
)

# check if the site model was updated
assert addenbrookes_site.organisation == ADDENBROOKES
assert addenbrookes_site.site_is_primary_centre_of_epilepsy_care is True
assert addenbrookes_site.site_is_actively_involved_in_epilepsy_care is True
assert addenbrookes_site.site_is_general_paediatric_centre is False
assert addenbrookes_site.case == case

assert gosh_site.organisation == GOSH
assert gosh_site.site_is_primary_centre_of_epilepsy_care is False
assert gosh_site.site_is_actively_involved_in_epilepsy_care is True
assert gosh_site.site_is_general_paediatric_centre is True
assert gosh_site.case == case
Loading

0 comments on commit 410c5fd

Please sign in to comment.