\ No newline at end of file
diff --git a/project/npda/templates/visits.html b/project/npda/templates/visits.html
index 7af39d22..25806f79 100644
--- a/project/npda/templates/visits.html
+++ b/project/npda/templates/visits.html
@@ -97,8 +97,8 @@
This child has had no visits yet!
-
- Patient KPIs will go here...
+
+ {% include 'partials/kpi_patient.html' with kpi_results=kpi_results patient=patient %}
diff --git a/project/npda/tests/kpi_calculations/test_kpi_calculations.py b/project/npda/tests/kpi_calculations/test_kpi_calculations.py
index e5b2f02e..a9e97e32 100644
--- a/project/npda/tests/kpi_calculations/test_kpi_calculations.py
+++ b/project/npda/tests/kpi_calculations/test_kpi_calculations.py
@@ -7,7 +7,7 @@
import pytest
-from project.npda.general_functions.kpis import CalculateKPIS, KPIResult
+from project.npda.kpi_class.kpis import CalculateKPIS, KPIResult
from project.npda.models.patient import Patient
# Logging
@@ -29,9 +29,7 @@ def assert_kpi_result_equal(expected: KPIResult, actual: KPIResult) -> None:
f"expected must be of type KPIResult (current: {type(expected)}"
)
if isinstance(actual, KPIResult) is False:
- raise TypeError(
- f"actual must be of type KPIResult (current: {type(actual)}"
- )
+ raise TypeError(f"actual must be of type KPIResult (current: {type(actual)}")
mismatches = []
@@ -90,13 +88,12 @@ def test_kpi_calculations_dont_break_when_no_patients(AUDIT_START_DATE):
pz_code="PZ130", calculation_date=AUDIT_START_DATE
).calculate_kpis_for_patients()
- for kpi, results in kpi_calculations_object[
- "calculated_kpi_values"
- ].items():
+ for kpi, results in kpi_calculations_object["calculated_kpi_values"].items():
+ # remove the kpi_label key from the results
+ results.pop("kpi_label", None)
+
values = list(results.values())
+
assert all(
- [
- isinstance(value, int) or isinstance(value, float)
- for value in values
- ]
+ [isinstance(value, int) or isinstance(value, float) for value in values]
), f"KPI {kpi} has non-integer values: {results}"
diff --git a/project/npda/tests/kpi_calculations/test_kpis_13_20.py b/project/npda/tests/kpi_calculations/test_kpis_13_20.py
index 423592ae..66f4ac23 100644
--- a/project/npda/tests/kpi_calculations/test_kpis_13_20.py
+++ b/project/npda/tests/kpi_calculations/test_kpis_13_20.py
@@ -1,13 +1,15 @@
"""Tests for the Treatment Regimen KPIS."""
+
import pytest
from dateutil.relativedelta import relativedelta
from project.constants.diabetes_treatment import TREATMENT_TYPES
-from project.npda.general_functions.kpis import CalculateKPIS, KPIResult
+from project.npda.kpi_class.kpis import CalculateKPIS, KPIResult
from project.npda.models import Patient
from project.npda.tests.factories.patient_factory import PatientFactory
-from project.npda.tests.kpi_calculations.test_kpi_calculations import \
- assert_kpi_result_equal
+from project.npda.tests.kpi_calculations.test_kpi_calculations import (
+ assert_kpi_result_equal,
+)
# Set up test params for kpis 13-20, as they all have the same denominator
# and the only thing being changed is value for visit__treatment
@@ -77,9 +79,7 @@ def test_kpi_calculations_13_to_20(
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
# Dynamically get the kpi calc method based on treatment type
# `treatment` is an int between 1-8
diff --git a/project/npda/tests/kpi_calculations/test_kpis_1_12.py b/project/npda/tests/kpi_calculations/test_kpis_1_12.py
index a9b0f233..5e560144 100644
--- a/project/npda/tests/kpi_calculations/test_kpis_1_12.py
+++ b/project/npda/tests/kpi_calculations/test_kpis_1_12.py
@@ -6,12 +6,13 @@
from dateutil.relativedelta import relativedelta
from project.constants.diabetes_types import DIABETES_TYPES
-from project.npda.general_functions.kpis import CalculateKPIS, KPIResult
+from project.npda.kpi_class.kpis import CalculateKPIS, KPIResult
from project.npda.models import Patient
from project.npda.tests.factories.patient_factory import PatientFactory
from project.npda.tests.factories.visit_factory import VisitFactory
-from project.npda.tests.kpi_calculations.test_kpi_calculations import \
- assert_kpi_result_equal
+from project.npda.tests.kpi_calculations.test_kpi_calculations import (
+ assert_kpi_result_equal,
+)
@pytest.mark.django_db
@@ -33,11 +34,9 @@ def test_kpi_calculation_1(AUDIT_START_DATE):
# Create Patients and Visits that should FAIL KPI1
# Visit date before audit period
- ineligible_patients_visit_date: List[Patient] = (
- PatientFactory.create_batch(
- size=N_PATIENTS_INELIGIBLE,
- visit__visit_date=AUDIT_START_DATE - relativedelta(days=10),
- )
+ ineligible_patients_visit_date: List[Patient] = PatientFactory.create_batch(
+ size=N_PATIENTS_INELIGIBLE,
+ visit__visit_date=AUDIT_START_DATE - relativedelta(days=10),
)
# Above age 25 at start of audit period
ineligible_patients_too_old: List[Patient] = PatientFactory.create_batch(
@@ -46,9 +45,7 @@ def test_kpi_calculation_1(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_KPIRESULT = KPIResult(
total_eligible=N_PATIENTS_ELIGIBLE,
@@ -87,18 +84,14 @@ def test_kpi_calculation_2(AUDIT_START_DATE):
# Create Patients and Visits that should FAIL KPI2
# Visit date before audit period
- ineligible_patients_visit_date: List[Patient] = (
- PatientFactory.create_batch(
- size=N_PATIENTS_INELIGIBLE,
- visit__visit_date=AUDIT_START_DATE - relativedelta(days=10),
- )
+ ineligible_patients_visit_date: List[Patient] = PatientFactory.create_batch(
+ size=N_PATIENTS_INELIGIBLE,
+ visit__visit_date=AUDIT_START_DATE - relativedelta(days=10),
)
# Diagnosis date before audit period
- ineligible_patients_diagnosis_date: List[Patient] = (
- PatientFactory.create_batch(
- size=N_PATIENTS_INELIGIBLE,
- diagnosis_date=AUDIT_START_DATE - relativedelta(days=10),
- )
+ ineligible_patients_diagnosis_date: List[Patient] = PatientFactory.create_batch(
+ size=N_PATIENTS_INELIGIBLE,
+ diagnosis_date=AUDIT_START_DATE - relativedelta(days=10),
)
# Above age 25 at start of audit period
ineligible_patients_too_old: List[Patient] = PatientFactory.create_batch(
@@ -107,9 +100,7 @@ def test_kpi_calculation_2(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_KPIRESULT = KPIResult(
total_eligible=N_PATIENTS_ELIGIBLE,
@@ -150,11 +141,9 @@ def test_kpi_calculation_3(AUDIT_START_DATE):
# Create Patients and Visits that should FAIL KPI3
# Visit date before audit period
- ineligible_patients_visit_date: List[Patient] = (
- PatientFactory.create_batch(
- size=N_PATIENTS_INELIGIBLE,
- visit__visit_date=AUDIT_START_DATE - relativedelta(days=10),
- )
+ ineligible_patients_visit_date: List[Patient] = PatientFactory.create_batch(
+ size=N_PATIENTS_INELIGIBLE,
+ visit__visit_date=AUDIT_START_DATE - relativedelta(days=10),
)
# Above age 25 at start of audit period
ineligible_patients_too_old: List[Patient] = PatientFactory.create_batch(
@@ -167,9 +156,7 @@ def test_kpi_calculation_3(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_KPIRESULT = KPIResult(
total_eligible=N_PATIENTS_ELIGIBLE,
@@ -213,11 +200,9 @@ def test_kpi_calculation_4(AUDIT_START_DATE):
# Create Patients and Visits that should FAIL KPI4
# Visit date before audit period
- ineligible_patients_visit_date: List[Patient] = (
- PatientFactory.create_batch(
- size=N_PATIENTS_INELIGIBLE,
- visit__visit_date=AUDIT_START_DATE - relativedelta(days=10),
- )
+ ineligible_patients_visit_date: List[Patient] = PatientFactory.create_batch(
+ size=N_PATIENTS_INELIGIBLE,
+ visit__visit_date=AUDIT_START_DATE - relativedelta(days=10),
)
# Above age 25 at start of audit period
ineligible_patients_too_old: List[Patient] = PatientFactory.create_batch(
@@ -235,9 +220,7 @@ def test_kpi_calculation_4(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_KPIRESULT = KPIResult(
total_eligible=N_PATIENTS_ELIGIBLE,
@@ -324,8 +307,7 @@ def test_kpi_calculation_5(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -337,9 +319,7 @@ def test_kpi_calculation_5(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 3
EXPECTED_TOTAL_INELIGIBLE = 5
@@ -400,8 +380,7 @@ def test_kpi_calculation_6(AUDIT_START_DATE):
diabetes_type=DIABETES_TYPES[0][0],
# an observation within the audit period
**{
- f"visit__{field_name}": AUDIT_START_DATE
- + relativedelta(days=2),
+ f"visit__{field_name}": AUDIT_START_DATE + relativedelta(days=2),
f"visit__visit_date": AUDIT_START_DATE + relativedelta(days=2),
},
)
@@ -430,8 +409,7 @@ def test_kpi_calculation_6(AUDIT_START_DATE):
VisitFactory(
patient=eligible_patient_second_visit_observation,
visit_date=AUDIT_START_DATE + relativedelta(months=2),
- height_weight_observation_date=AUDIT_START_DATE
- + relativedelta(months=2),
+ height_weight_observation_date=AUDIT_START_DATE + relativedelta(months=2),
psychological_screening_assessment_date=AUDIT_START_DATE
+ relativedelta(months=2),
)
@@ -451,8 +429,7 @@ def test_kpi_calculation_6(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -464,9 +441,7 @@ def test_kpi_calculation_6(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = len(observation_field_names) + 1
EXPECTED_TOTAL_INELIGIBLE = 3
@@ -523,10 +498,7 @@ def test_kpi_calculation_7(AUDIT_START_DATE):
# Diagnosis date within audit date range
diagnosis_date=AUDIT_START_DATE + relativedelta(days=2),
# an observation within the audit period
- **{
- f"visit__{field_name}": AUDIT_START_DATE
- + relativedelta(days=2)
- },
+ **{f"visit__{field_name}": AUDIT_START_DATE + relativedelta(days=2)},
)
# Create Patients and Visits that should BE EXCLUDED
@@ -550,9 +522,7 @@ def test_kpi_calculation_7(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = len(observation_field_names)
EXPECTED_TOTAL_INELIGIBLE = 2
@@ -614,9 +584,7 @@ def test_kpi_calculation_8(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 1
EXPECTED_TOTAL_INELIGIBLE = 3
@@ -652,8 +620,7 @@ def test_kpi_calculation_9(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# leaving_date within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
# Create Patients and Visits that should be excluded
@@ -683,14 +650,11 @@ def test_kpi_calculation_9(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving_date outside the audit period"
- transfer__date_leaving_service=AUDIT_START_DATE
- - relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE - relativedelta(days=2),
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 1
EXPECTED_TOTAL_INELIGIBLE = 4
@@ -753,9 +717,7 @@ def test_kpi_calculation_10(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 1
EXPECTED_TOTAL_INELIGIBLE = 3
@@ -827,9 +789,7 @@ def test_kpi_calculation_11(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 2
EXPECTED_TOTAL_INELIGIBLE = 3
@@ -892,9 +852,7 @@ def test_kpi_calculation_12(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 1
EXPECTED_TOTAL_INELIGIBLE = 3
diff --git a/project/npda/tests/kpi_calculations/test_kpis_21_23.py b/project/npda/tests/kpi_calculations/test_kpis_21_23.py
index 555b6138..53ec3b18 100644
--- a/project/npda/tests/kpi_calculations/test_kpis_21_23.py
+++ b/project/npda/tests/kpi_calculations/test_kpis_21_23.py
@@ -1,12 +1,14 @@
"""Tests for the Glucose Monitoring KPIS."""
+
import pytest
from dateutil.relativedelta import relativedelta
-from project.npda.general_functions.kpis import CalculateKPIS, KPIResult
+from project.npda.kpi_class.kpis import CalculateKPIS, KPIResult
from project.npda.models import Patient
from project.npda.tests.factories.patient_factory import PatientFactory
-from project.npda.tests.kpi_calculations.test_kpi_calculations import \
- assert_kpi_result_equal
+from project.npda.tests.kpi_calculations.test_kpi_calculations import (
+ assert_kpi_result_equal,
+)
@pytest.mark.django_db
@@ -62,9 +64,7 @@ def test_kpi_calculation_21(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 6
EXPECTED_TOTAL_INELIGIBLE = 2
@@ -131,9 +131,7 @@ def test_kpi_calculation_22(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 6
EXPECTED_TOTAL_INELIGIBLE = 2
@@ -202,9 +200,7 @@ def test_kpi_calculation_23(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 6
EXPECTED_TOTAL_INELIGIBLE = 2
diff --git a/project/npda/tests/kpi_calculations/test_kpis_24.py b/project/npda/tests/kpi_calculations/test_kpis_24.py
index f5cf1b70..0c32c765 100644
--- a/project/npda/tests/kpi_calculations/test_kpis_24.py
+++ b/project/npda/tests/kpi_calculations/test_kpis_24.py
@@ -1,12 +1,14 @@
"""Tests for the HCL KPI."""
+
import pytest
from dateutil.relativedelta import relativedelta
-from project.npda.general_functions.kpis import CalculateKPIS, KPIResult
+from project.npda.kpi_class.kpis import CalculateKPIS, KPIResult
from project.npda.models import Patient
from project.npda.tests.factories.patient_factory import PatientFactory
-from project.npda.tests.kpi_calculations.test_kpi_calculations import \
- assert_kpi_result_equal
+from project.npda.tests.kpi_calculations.test_kpi_calculations import (
+ assert_kpi_result_equal,
+)
@pytest.mark.django_db
@@ -103,9 +105,7 @@ def test_kpi_calculation_24(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 8
EXPECTED_TOTAL_INELIGIBLE = 8
diff --git a/project/npda/tests/kpi_calculations/test_kpis_25_32.py b/project/npda/tests/kpi_calculations/test_kpis_25_32.py
index af594940..d1b65abd 100644
--- a/project/npda/tests/kpi_calculations/test_kpis_25_32.py
+++ b/project/npda/tests/kpi_calculations/test_kpis_25_32.py
@@ -5,14 +5,14 @@
from project.constants.diabetes_types import DIABETES_TYPES
from project.constants.hba1c_format import HBA1C_FORMATS
-from project.constants.retinal_screening_results import \
- RETINAL_SCREENING_RESULTS
-from project.npda.general_functions.kpis import CalculateKPIS, KPIResult
+from project.constants.retinal_screening_results import RETINAL_SCREENING_RESULTS
+from project.npda.kpi_class.kpis import CalculateKPIS, KPIResult
from project.npda.models import Patient
from project.npda.tests.factories.patient_factory import PatientFactory
from project.npda.tests.factories.visit_factory import VisitFactory
-from project.npda.tests.kpi_calculations.test_kpi_calculations import \
- assert_kpi_result_equal
+from project.npda.tests.kpi_calculations.test_kpi_calculations import (
+ assert_kpi_result_equal,
+)
@pytest.mark.django_db
@@ -104,8 +104,7 @@ def test_kpi_calculation_25(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -117,9 +116,7 @@ def test_kpi_calculation_25(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 3
EXPECTED_TOTAL_INELIGIBLE = 5
@@ -174,8 +171,7 @@ def test_kpi_calculation_26(AUDIT_START_DATE):
# valid ht wt values within audit period
visit__height=140.0,
visit__weight=40.0,
- visit__height_weight_observation_date=AUDIT_START_DATE
- + relativedelta(days=2),
+ visit__height_weight_observation_date=AUDIT_START_DATE + relativedelta(days=2),
)
passing_patient_valid_ht_wt_within_audit_period_2 = PatientFactory(
postcode="passing_patient_valid_ht_wt_within_audit_period_2",
@@ -184,8 +180,7 @@ def test_kpi_calculation_26(AUDIT_START_DATE):
# valid ht wt values within audit period
visit__height=160.0,
visit__weight=50.0,
- visit__height_weight_observation_date=AUDIT_START_DATE
- + relativedelta(days=2),
+ visit__height_weight_observation_date=AUDIT_START_DATE + relativedelta(days=2),
)
# Failing patients
@@ -207,8 +202,7 @@ def test_kpi_calculation_26(AUDIT_START_DATE):
# ht wt value before audit period
visit__height=160.0,
visit__weight=50.0,
- visit__height_weight_observation_date=AUDIT_START_DATE
- - relativedelta(days=2),
+ visit__height_weight_observation_date=AUDIT_START_DATE - relativedelta(days=2),
)
# Create Patients and Visits that should be ineligble
@@ -239,8 +233,7 @@ def test_kpi_calculation_26(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -252,9 +245,7 @@ def test_kpi_calculation_26(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 4
EXPECTED_TOTAL_INELIGIBLE = 5
@@ -363,8 +354,7 @@ def test_kpi_calculation_27(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -376,9 +366,7 @@ def test_kpi_calculation_27(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 4
EXPECTED_TOTAL_INELIGIBLE = 5
@@ -440,8 +428,7 @@ def test_kpi_calculation_28(AUDIT_START_DATE):
**eligible_criteria,
# valid bp date within audit period
visit__systolic_blood_pressure=120,
- visit__blood_pressure_observation_date=AUDIT_START_DATE
- + relativedelta(days=2),
+ visit__blood_pressure_observation_date=AUDIT_START_DATE + relativedelta(days=2),
)
passing_patient_systolic_bp_within_audit_period_2 = PatientFactory(
postcode="passing_patient_systolic_bp_within_audit_period_2",
@@ -449,8 +436,7 @@ def test_kpi_calculation_28(AUDIT_START_DATE):
**eligible_criteria,
# valid bp date within audit period
visit__systolic_blood_pressure=130,
- visit__blood_pressure_observation_date=AUDIT_START_DATE
- + relativedelta(days=5),
+ visit__blood_pressure_observation_date=AUDIT_START_DATE + relativedelta(days=5),
)
# Failing patients
@@ -470,8 +456,7 @@ def test_kpi_calculation_28(AUDIT_START_DATE):
**eligible_criteria,
# systolic date before audit period
visit__systolic_blood_pressure=120,
- visit__blood_pressure_observation_date=AUDIT_START_DATE
- - relativedelta(days=2),
+ visit__blood_pressure_observation_date=AUDIT_START_DATE - relativedelta(days=2),
)
# Create Patients and Visits that should be ineligble
@@ -489,8 +474,7 @@ def test_kpi_calculation_28(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -502,9 +486,7 @@ def test_kpi_calculation_28(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 4
EXPECTED_TOTAL_INELIGIBLE = 3
@@ -564,8 +546,7 @@ def test_kpi_calculation_29(AUDIT_START_DATE):
**eligible_criteria,
# valid ACR within audit period
visit__albumin_creatinine_ratio=2,
- visit__albumin_creatinine_ratio_date=AUDIT_START_DATE
- + relativedelta(days=2),
+ visit__albumin_creatinine_ratio_date=AUDIT_START_DATE + relativedelta(days=2),
)
passing_patient_urinary_albumin_within_audit_period_2 = PatientFactory(
postcode="passing_patient_urinary_albumin_within_audit_period_2",
@@ -573,8 +554,7 @@ def test_kpi_calculation_29(AUDIT_START_DATE):
**eligible_criteria,
# valid ACR within audit period
visit__albumin_creatinine_ratio=3,
- visit__albumin_creatinine_ratio_date=AUDIT_START_DATE
- + relativedelta(days=27),
+ visit__albumin_creatinine_ratio_date=AUDIT_START_DATE + relativedelta(days=27),
)
# Failing patients
@@ -594,8 +574,7 @@ def test_kpi_calculation_29(AUDIT_START_DATE):
**eligible_criteria,
# ACR before audit period
visit__albumin_creatinine_ratio=3,
- visit__albumin_creatinine_ratio_date=AUDIT_START_DATE
- - relativedelta(days=2),
+ visit__albumin_creatinine_ratio_date=AUDIT_START_DATE - relativedelta(days=2),
)
# Create Patients and Visits that should be ineligble
@@ -613,8 +592,7 @@ def test_kpi_calculation_29(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -626,9 +604,7 @@ def test_kpi_calculation_29(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 4
EXPECTED_TOTAL_INELIGIBLE = 3
@@ -746,8 +722,7 @@ def test_kpi_calculation_30(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -759,9 +734,7 @@ def test_kpi_calculation_30(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 5
EXPECTED_TOTAL_INELIGIBLE = 3
@@ -866,8 +839,7 @@ def test_kpi_calculation_31(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -879,9 +851,7 @@ def test_kpi_calculation_31(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 4
EXPECTED_TOTAL_INELIGIBLE = 3
@@ -952,8 +922,7 @@ def test_kpi_calculation_32_1(AUDIT_START_DATE):
visit_date=AUDIT_START_DATE + relativedelta(months=3),
height=160.0,
weight=50.0,
- height_weight_observation_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ height_weight_observation_date=AUDIT_START_DATE + relativedelta(months=3),
)
pt_lt_12yo_3_health_checks = PatientFactory(
@@ -970,8 +939,7 @@ def test_kpi_calculation_32_1(AUDIT_START_DATE):
visit_date=AUDIT_START_DATE + relativedelta(months=3),
height=160.0,
weight=50.0,
- height_weight_observation_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ height_weight_observation_date=AUDIT_START_DATE + relativedelta(months=3),
)
# Separate Visit has HC3
VisitFactory(
@@ -996,12 +964,10 @@ def test_kpi_calculation_32_1(AUDIT_START_DATE):
# HC 2
height=160.0,
weight=50.0,
- height_weight_observation_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ height_weight_observation_date=AUDIT_START_DATE + relativedelta(months=3),
# HC 3
systolic_blood_pressure=120,
- blood_pressure_observation_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ blood_pressure_observation_date=AUDIT_START_DATE + relativedelta(months=3),
)
pt_gte_12yo_6_health_checks = PatientFactory(
@@ -1019,8 +985,7 @@ def test_kpi_calculation_32_1(AUDIT_START_DATE):
# HC 2
height=160.0,
weight=50.0,
- height_weight_observation_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ height_weight_observation_date=AUDIT_START_DATE + relativedelta(months=3),
# HC 3
thyroid_function_date=AUDIT_START_DATE + relativedelta(months=3),
)
@@ -1030,15 +995,12 @@ def test_kpi_calculation_32_1(AUDIT_START_DATE):
visit_date=AUDIT_START_DATE + relativedelta(months=6),
# HC 4
systolic_blood_pressure=120,
- blood_pressure_observation_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ blood_pressure_observation_date=AUDIT_START_DATE + relativedelta(months=3),
# HC 5
albumin_creatinine_ratio=2,
- albumin_creatinine_ratio_date=AUDIT_START_DATE
- + relativedelta(months=6),
+ albumin_creatinine_ratio_date=AUDIT_START_DATE + relativedelta(months=6),
# HC 6
- foot_examination_observation_date=AUDIT_START_DATE
- + relativedelta(months=6),
+ foot_examination_observation_date=AUDIT_START_DATE + relativedelta(months=6),
)
# Create Patients and Visits that should be ineligble
@@ -1070,8 +1032,7 @@ def test_kpi_calculation_32_1(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -1083,9 +1044,7 @@ def test_kpi_calculation_32_1(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 18 # (2*3) + (2*6)
EXPECTED_TOTAL_INELIGIBLE = 5
@@ -1149,8 +1108,7 @@ def test_kpi_calculation_32_2(AUDIT_START_DATE):
height=160.0,
weight=50.0,
# HC 3
- height_weight_observation_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ height_weight_observation_date=AUDIT_START_DATE + relativedelta(months=3),
thyroid_function_date=AUDIT_START_DATE + relativedelta(months=3),
)
@@ -1169,8 +1127,7 @@ def test_kpi_calculation_32_2(AUDIT_START_DATE):
# HC 2
height=160.0,
weight=50.0,
- height_weight_observation_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ height_weight_observation_date=AUDIT_START_DATE + relativedelta(months=3),
)
# Separate Visit has HC3
VisitFactory(
@@ -1193,8 +1150,7 @@ def test_kpi_calculation_32_2(AUDIT_START_DATE):
patient=failing_pt_only_2_HCs,
visit_date=AUDIT_START_DATE + relativedelta(months=3),
# HC 3
- height_weight_observation_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ height_weight_observation_date=AUDIT_START_DATE + relativedelta(months=3),
thyroid_function_date=AUDIT_START_DATE + relativedelta(months=3),
)
@@ -1208,8 +1164,7 @@ def test_kpi_calculation_32_2(AUDIT_START_DATE):
patient=failing_pt_only_1_HCs,
visit_date=AUDIT_START_DATE + relativedelta(months=3),
# HC 1
- height_weight_observation_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ height_weight_observation_date=AUDIT_START_DATE + relativedelta(months=3),
thyroid_function_date=AUDIT_START_DATE + relativedelta(months=3),
)
@@ -1241,8 +1196,7 @@ def test_kpi_calculation_32_2(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -1254,9 +1208,7 @@ def test_kpi_calculation_32_2(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 4
EXPECTED_TOTAL_INELIGIBLE = 5
@@ -1320,8 +1272,7 @@ def test_kpi_calculation_32_3(AUDIT_START_DATE):
# HC 2
height=160.0,
weight=50.0,
- height_weight_observation_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ height_weight_observation_date=AUDIT_START_DATE + relativedelta(months=3),
# HC 3
thyroid_function_date=AUDIT_START_DATE + relativedelta(months=3),
)
@@ -1331,15 +1282,12 @@ def test_kpi_calculation_32_3(AUDIT_START_DATE):
visit_date=AUDIT_START_DATE + relativedelta(months=6),
# HC 4
systolic_blood_pressure=120,
- blood_pressure_observation_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ blood_pressure_observation_date=AUDIT_START_DATE + relativedelta(months=3),
# HC 5
albumin_creatinine_ratio=2,
- albumin_creatinine_ratio_date=AUDIT_START_DATE
- + relativedelta(months=6),
+ albumin_creatinine_ratio_date=AUDIT_START_DATE + relativedelta(months=6),
# HC 6
- foot_examination_observation_date=AUDIT_START_DATE
- + relativedelta(months=6),
+ foot_examination_observation_date=AUDIT_START_DATE + relativedelta(months=6),
)
passing_pt_2 = PatientFactory(
@@ -1363,8 +1311,7 @@ def test_kpi_calculation_32_3(AUDIT_START_DATE):
thyroid_function_date=AUDIT_START_DATE + relativedelta(months=3),
# HC 4
systolic_blood_pressure=120,
- blood_pressure_observation_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ blood_pressure_observation_date=AUDIT_START_DATE + relativedelta(months=3),
)
# Separate Visit has HC5+6
VisitFactory(
@@ -1372,11 +1319,9 @@ def test_kpi_calculation_32_3(AUDIT_START_DATE):
visit_date=AUDIT_START_DATE + relativedelta(months=6),
# HC 5
albumin_creatinine_ratio=2,
- albumin_creatinine_ratio_date=AUDIT_START_DATE
- + relativedelta(months=6),
+ albumin_creatinine_ratio_date=AUDIT_START_DATE + relativedelta(months=6),
# HC 6
- foot_examination_observation_date=AUDIT_START_DATE
- + relativedelta(months=6),
+ foot_examination_observation_date=AUDIT_START_DATE + relativedelta(months=6),
)
# Failing patients
@@ -1393,8 +1338,7 @@ def test_kpi_calculation_32_3(AUDIT_START_DATE):
patient=failing_pt_only_2_HCs,
visit_date=AUDIT_START_DATE + relativedelta(months=3),
# HC 3
- height_weight_observation_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ height_weight_observation_date=AUDIT_START_DATE + relativedelta(months=3),
thyroid_function_date=AUDIT_START_DATE + relativedelta(months=3),
)
@@ -1415,16 +1359,13 @@ def test_kpi_calculation_32_3(AUDIT_START_DATE):
# HC 3
height=160.0,
weight=50.0,
- height_weight_observation_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ height_weight_observation_date=AUDIT_START_DATE + relativedelta(months=3),
# HC 4
systolic_blood_pressure=120,
- blood_pressure_observation_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ blood_pressure_observation_date=AUDIT_START_DATE + relativedelta(months=3),
# HC 5
albumin_creatinine_ratio=2,
- albumin_creatinine_ratio_date=AUDIT_START_DATE
- + relativedelta(months=3),
+ albumin_creatinine_ratio_date=AUDIT_START_DATE + relativedelta(months=3),
)
# Create Patients and Visits that should be ineligble
@@ -1455,8 +1396,7 @@ def test_kpi_calculation_32_3(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -1468,9 +1408,7 @@ def test_kpi_calculation_32_3(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 4
EXPECTED_TOTAL_INELIGIBLE = 5
diff --git a/project/npda/tests/kpi_calculations/test_kpis_33_40.py b/project/npda/tests/kpi_calculations/test_kpis_33_40.py
index 6d8ddbfa..2f3dc109 100644
--- a/project/npda/tests/kpi_calculations/test_kpis_33_40.py
+++ b/project/npda/tests/kpi_calculations/test_kpis_33_40.py
@@ -7,12 +7,13 @@
from project.constants.diabetes_types import DIABETES_TYPES
from project.constants.smoking_status import SMOKING_STATUS
-from project.npda.general_functions.kpis import CalculateKPIS, KPIResult
+from project.npda.kpi_class.kpis import CalculateKPIS, KPIResult
from project.npda.models import Patient
from project.npda.tests.factories.patient_factory import PatientFactory
from project.npda.tests.factories.visit_factory import VisitFactory
-from project.npda.tests.kpi_calculations.test_kpi_calculations import \
- assert_kpi_result_equal
+from project.npda.tests.kpi_calculations.test_kpi_calculations import (
+ assert_kpi_result_equal,
+)
@pytest.mark.django_db
@@ -139,8 +140,7 @@ def test_kpi_calculation_33(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -273,8 +273,7 @@ def test_kpi_calculation_34(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -362,8 +361,7 @@ def test_kpi_calculation_35(AUDIT_START_DATE):
VisitFactory(
patient=passing_patient_2,
# KPI 6 specific = an observation within the audit period
- height_weight_observation_date=AUDIT_START_DATE
- + relativedelta(days=5),
+ height_weight_observation_date=AUDIT_START_DATE + relativedelta(days=5),
visit_date=AUDIT_START_DATE + relativedelta(days=5),
smoking_status=SMOKING_STATUS[1][0],
)
@@ -403,8 +401,7 @@ def test_kpi_calculation_35(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -477,8 +474,7 @@ def test_kpi_calculation_36(AUDIT_START_DATE):
# KPI5 eligible
**eligible_criteria,
# KPI 35 specific
- visit__smoking_cessation_referral_date=AUDIT_START_DATE
- + relativedelta(days=2),
+ visit__smoking_cessation_referral_date=AUDIT_START_DATE + relativedelta(days=2),
)
# only second visit has a valid smoking cessation referral
passing_patient_2 = PatientFactory(
@@ -492,8 +488,7 @@ def test_kpi_calculation_36(AUDIT_START_DATE):
VisitFactory(
patient=passing_patient_2,
visit_date=AUDIT_START_DATE + relativedelta(days=5),
- smoking_cessation_referral_date=AUDIT_START_DATE
- + relativedelta(days=32),
+ smoking_cessation_referral_date=AUDIT_START_DATE + relativedelta(days=32),
)
# Failing patients
@@ -521,8 +516,7 @@ def test_kpi_calculation_36(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -644,8 +638,7 @@ def test_kpi_calculation_37(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -727,8 +720,7 @@ def test_kpi_calculation_38(AUDIT_START_DATE):
VisitFactory(
patient=passing_patient_2,
visit_date=AUDIT_START_DATE + relativedelta(days=5),
- dietician_additional_appointment_date=AUDIT_START_DATE
- + relativedelta(days=4),
+ dietician_additional_appointment_date=AUDIT_START_DATE + relativedelta(days=4),
)
# Failing patients
@@ -769,8 +761,7 @@ def test_kpi_calculation_38(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -852,8 +843,7 @@ def test_kpi_calculation_39(AUDIT_START_DATE):
VisitFactory(
patient=passing_patient_2,
visit_date=AUDIT_START_DATE + relativedelta(days=5),
- flu_immunisation_recommended_date=AUDIT_START_DATE
- + relativedelta(days=4),
+ flu_immunisation_recommended_date=AUDIT_START_DATE + relativedelta(days=4),
)
# Failing patients
@@ -894,8 +884,7 @@ def test_kpi_calculation_39(AUDIT_START_DATE):
visit__visit_date=AUDIT_START_DATE + relativedelta(days=2),
date_of_birth=AUDIT_START_DATE - relativedelta(days=365 * 10),
# Date of leaving service within the audit period
- transfer__date_leaving_service=AUDIT_START_DATE
- + relativedelta(days=2),
+ transfer__date_leaving_service=AUDIT_START_DATE + relativedelta(days=2),
)
ineligible_patient_death_within_audit_period = PatientFactory(
postcode="ineligible_patient_death_within_audit_period",
@@ -954,8 +943,7 @@ def test_kpi_calculation_40(AUDIT_START_DATE):
# KPI1 eligible
**eligible_criteria,
# KPI 40 specific
- visit__sick_day_rules_training_date=AUDIT_START_DATE
- + relativedelta(days=30),
+ visit__sick_day_rules_training_date=AUDIT_START_DATE + relativedelta(days=30),
)
# only second visit has a valid sick day rule
passing_patient_2 = PatientFactory(
diff --git a/project/npda/tests/kpi_calculations/test_kpis_41_43.py b/project/npda/tests/kpi_calculations/test_kpis_41_43.py
index d4146811..b798e8d7 100644
--- a/project/npda/tests/kpi_calculations/test_kpis_41_43.py
+++ b/project/npda/tests/kpi_calculations/test_kpis_41_43.py
@@ -8,12 +8,13 @@
from project.constants.diabetes_types import DIABETES_TYPES
from project.constants.smoking_status import SMOKING_STATUS
-from project.npda.general_functions.kpis import CalculateKPIS, KPIResult
+from project.npda.kpi_class.kpis import CalculateKPIS, KPIResult
from project.npda.models import Patient
from project.npda.tests.factories.patient_factory import PatientFactory
from project.npda.tests.factories.visit_factory import VisitFactory
-from project.npda.tests.kpi_calculations.test_kpi_calculations import \
- assert_kpi_result_equal
+from project.npda.tests.kpi_calculations.test_kpi_calculations import (
+ assert_kpi_result_equal,
+)
# Logging
logger = logging.getLogger(__name__)
@@ -37,8 +38,7 @@ def test_kpi_calculation_41(AUDIT_START_DATE, AUDIT_END_DATE):
# Create Patients and Visits that should be eligible (KPI7)
DIAB_DIAGNOSIS_91D_BEFORE_END = AUDIT_END_DATE - relativedelta(days=91)
eligible_criteria = {
- "visit__visit_date": DIAB_DIAGNOSIS_91D_BEFORE_END
- - relativedelta(months=2),
+ "visit__visit_date": DIAB_DIAGNOSIS_91D_BEFORE_END - relativedelta(months=2),
"date_of_birth": AUDIT_START_DATE - relativedelta(years=10),
"diabetes_type": DIABETES_TYPES[0][0],
# any other observation date
@@ -68,8 +68,7 @@ def test_kpi_calculation_41(AUDIT_START_DATE, AUDIT_END_DATE):
# create 2nd visit with coeliac screen < 90 days after T1DM diagnosis
VisitFactory(
patient=passing_patient_2,
- coeliac_screen_date=DIAB_DIAGNOSIS_91D_BEFORE_END
- + relativedelta(days=90),
+ coeliac_screen_date=DIAB_DIAGNOSIS_91D_BEFORE_END + relativedelta(days=90),
)
# Failing patients
@@ -167,8 +166,7 @@ def test_kpi_calculation_42(AUDIT_START_DATE, AUDIT_END_DATE):
# Create Patients and Visits that should be eligible (KPI7)
DIAB_DIAGNOSIS_91D_BEFORE_END = AUDIT_END_DATE - relativedelta(days=91)
eligible_criteria = {
- "visit__visit_date": DIAB_DIAGNOSIS_91D_BEFORE_END
- - relativedelta(months=2),
+ "visit__visit_date": DIAB_DIAGNOSIS_91D_BEFORE_END - relativedelta(months=2),
"date_of_birth": AUDIT_START_DATE - relativedelta(years=10),
"diabetes_type": DIABETES_TYPES[0][0],
# any other observation date
@@ -198,8 +196,7 @@ def test_kpi_calculation_42(AUDIT_START_DATE, AUDIT_END_DATE):
# create 2nd visit with thyroid_function_date < 90 days after T1DM diagnosis
VisitFactory(
patient=passing_patient_2,
- thyroid_function_date=DIAB_DIAGNOSIS_91D_BEFORE_END
- + relativedelta(days=90),
+ thyroid_function_date=DIAB_DIAGNOSIS_91D_BEFORE_END + relativedelta(days=90),
)
# Failing patients
@@ -279,6 +276,7 @@ def test_kpi_calculation_42(AUDIT_START_DATE, AUDIT_END_DATE):
actual=calc_kpis.calculate_kpi_42_thyroid_disease_screening(),
)
+
@pytest.mark.django_db
def test_kpi_calculation_43(AUDIT_START_DATE, AUDIT_END_DATE):
"""Tests that KPI43 is calculated correctly.
@@ -299,8 +297,7 @@ def test_kpi_calculation_43(AUDIT_START_DATE, AUDIT_END_DATE):
# Create Patients and Visits that should be eligible (KPI7)
DIAB_DIAGNOSIS_15D_BEFORE_END = AUDIT_END_DATE - relativedelta(days=15)
eligible_criteria = {
- "visit__visit_date": DIAB_DIAGNOSIS_15D_BEFORE_END
- - relativedelta(months=2),
+ "visit__visit_date": DIAB_DIAGNOSIS_15D_BEFORE_END - relativedelta(months=2),
"date_of_birth": AUDIT_START_DATE - relativedelta(years=10),
"diabetes_type": DIABETES_TYPES[0][0],
# any other observation date
@@ -389,7 +386,8 @@ def test_kpi_calculation_43(AUDIT_START_DATE, AUDIT_END_DATE):
diabetes_type=DIABETES_TYPES[0][0],
# Date of diag 2 days before end of audit period
diagnosis_date=AUDIT_END_DATE - relativedelta(days=14),
- visit__carbohydrate_counting_level_three_education_date=AUDIT_END_DATE - relativedelta(days=14),
+ visit__carbohydrate_counting_level_three_education_date=AUDIT_END_DATE
+ - relativedelta(days=14),
)
calc_kpis = CalculateKPIS(
@@ -412,4 +410,4 @@ def test_kpi_calculation_43(AUDIT_START_DATE, AUDIT_END_DATE):
assert_kpi_result_equal(
expected=EXPECTED_KPIRESULT,
actual=calc_kpis.calculate_kpi_43_carbohydrate_counting_education(),
- )
\ No newline at end of file
+ )
diff --git a/project/npda/tests/kpi_calculations/test_kpis_44_49.py b/project/npda/tests/kpi_calculations/test_kpis_44_49.py
index 5a223092..bd50d754 100644
--- a/project/npda/tests/kpi_calculations/test_kpis_44_49.py
+++ b/project/npda/tests/kpi_calculations/test_kpis_44_49.py
@@ -8,16 +8,16 @@
from project.constants.albuminuria_stage import ALBUMINURIA_STAGES
from project.constants.diabetes_types import DIABETES_TYPES
-from project.constants.hospital_admission_reasons import \
- HOSPITAL_ADMISSION_REASONS
+from project.constants.hospital_admission_reasons import HOSPITAL_ADMISSION_REASONS
from project.constants.smoking_status import SMOKING_STATUS
from project.constants.yes_no_unknown import YES_NO_UNKNOWN
-from project.npda.general_functions.kpis import CalculateKPIS, KPIResult
+from project.npda.kpi_class.kpis import CalculateKPIS, KPIResult
from project.npda.models import Patient
from project.npda.tests.factories.patient_factory import PatientFactory
from project.npda.tests.factories.visit_factory import VisitFactory
-from project.npda.tests.kpi_calculations.test_kpi_calculations import \
- assert_kpi_result_equal
+from project.npda.tests.kpi_calculations.test_kpi_calculations import (
+ assert_kpi_result_equal,
+)
# Logging
logger = logging.getLogger(__name__)
@@ -119,17 +119,15 @@ def test_kpi_calculation_44(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
medians = list(map(calculate_median, [pt_1_hba1cs, pt_2_hba1cs]))
EXPECTED_MEAN = sum(medians) / len(medians)
EXPECTED_TOTAL_ELIGIBLE = 2
EXPECTED_TOTAL_INELIGIBLE = 2
- EXPECTED_TOTAL_PASSED = EXPECTED_MEAN # Stores the mean
- EXPECTED_TOTAL_FAILED = -1 # Not used
+ EXPECTED_TOTAL_PASSED = EXPECTED_MEAN # Stores the mean
+ EXPECTED_TOTAL_FAILED = -1 # Not used
EXPECTED_KPIRESULT = KPIResult(
total_eligible=EXPECTED_TOTAL_ELIGIBLE,
@@ -143,6 +141,7 @@ def test_kpi_calculation_44(AUDIT_START_DATE):
actual=calc_kpis.calculate_kpi_44_mean_hba1c(),
)
+
@pytest.mark.django_db
def test_kpi_calculation_45(AUDIT_START_DATE):
"""Tests that KPI45 is calculated correctly.
@@ -240,17 +239,15 @@ def test_kpi_calculation_45(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
medians = list(map(calculate_median, [pt_1_hba1cs, pt_2_hba1cs]))
EXPECTED_MEDIAN = calculate_median(medians)
EXPECTED_TOTAL_ELIGIBLE = 2
EXPECTED_TOTAL_INELIGIBLE = 2
- EXPECTED_TOTAL_PASSED = EXPECTED_MEDIAN # Stores the mean
- EXPECTED_TOTAL_FAILED = -1 # Not used
+ EXPECTED_TOTAL_PASSED = EXPECTED_MEDIAN # Stores the mean
+ EXPECTED_TOTAL_FAILED = -1 # Not used
EXPECTED_KPIRESULT = KPIResult(
total_eligible=EXPECTED_TOTAL_ELIGIBLE,
@@ -294,8 +291,7 @@ def test_kpi_calculation_46(AUDIT_START_DATE):
# valid admission reason
visit__hospital_admission_reason=HOSPITAL_ADMISSION_REASONS[0][0],
# admission date within audit range
- visit__hospital_admission_date=AUDIT_START_DATE
- + relativedelta(days=2),
+ visit__hospital_admission_date=AUDIT_START_DATE + relativedelta(days=2),
)
passing_valid_admission_reason_and_discharge_within_audit_range = PatientFactory(
# KPI1 eligible
@@ -303,8 +299,7 @@ def test_kpi_calculation_46(AUDIT_START_DATE):
# valid admission reason
visit__hospital_admission_reason=HOSPITAL_ADMISSION_REASONS[-1][0],
# discharge date within audit range
- visit__hospital_discharge_date=AUDIT_START_DATE
- + relativedelta(days=2),
+ visit__hospital_discharge_date=AUDIT_START_DATE + relativedelta(days=2),
)
# Create failing pts
@@ -314,8 +309,7 @@ def test_kpi_calculation_46(AUDIT_START_DATE):
# invalid admission reason
visit__hospital_admission_reason="42",
# admission date within audit range
- visit__hospital_admission_date=AUDIT_START_DATE
- + relativedelta(days=2),
+ visit__hospital_admission_date=AUDIT_START_DATE + relativedelta(days=2),
)
failing_both_admission_outside_audit_date = PatientFactory(
# KPI1 eligible
@@ -323,8 +317,7 @@ def test_kpi_calculation_46(AUDIT_START_DATE):
# valid admission reason
visit__hospital_admission_reason=HOSPITAL_ADMISSION_REASONS[-1][0],
# admission date outside audit range
- visit__hospital_admission_date=AUDIT_START_DATE
- - relativedelta(days=2),
+ visit__hospital_admission_date=AUDIT_START_DATE - relativedelta(days=2),
)
# Create Patients and Visits that should be excluded
@@ -342,9 +335,7 @@ def test_kpi_calculation_46(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 4
EXPECTED_TOTAL_INELIGIBLE = 2
@@ -393,8 +384,7 @@ def test_kpi_calculation_47(AUDIT_START_DATE):
# valid dka admission reason
visit__hospital_admission_reason=HOSPITAL_ADMISSION_REASONS[1][0],
# admission date within audit range
- visit__hospital_admission_date=AUDIT_START_DATE
- + relativedelta(days=2),
+ visit__hospital_admission_date=AUDIT_START_DATE + relativedelta(days=2),
)
passing_valid_dka_admission_reason_and_discharge_within_audit_range = PatientFactory(
# KPI1 eligible
@@ -402,8 +392,7 @@ def test_kpi_calculation_47(AUDIT_START_DATE):
# valid dka admission reason
visit__hospital_admission_reason=HOSPITAL_ADMISSION_REASONS[1][0],
# discharge date within audit range
- visit__hospital_discharge_date=AUDIT_START_DATE
- + relativedelta(days=2),
+ visit__hospital_discharge_date=AUDIT_START_DATE + relativedelta(days=2),
)
# Create failing pts
@@ -413,8 +402,7 @@ def test_kpi_calculation_47(AUDIT_START_DATE):
# invalid admission reason
visit__hospital_admission_reason=HOSPITAL_ADMISSION_REASONS[0][0],
# admission date within audit range
- visit__hospital_admission_date=AUDIT_START_DATE
- + relativedelta(days=2),
+ visit__hospital_admission_date=AUDIT_START_DATE + relativedelta(days=2),
)
failing_both_admission_outside_audit_date = PatientFactory(
# KPI1 eligible
@@ -422,8 +410,7 @@ def test_kpi_calculation_47(AUDIT_START_DATE):
# valid admission reason
visit__hospital_admission_reason=HOSPITAL_ADMISSION_REASONS[0][0],
# admission date outside audit range
- visit__hospital_admission_date=AUDIT_START_DATE
- - relativedelta(days=2),
+ visit__hospital_admission_date=AUDIT_START_DATE - relativedelta(days=2),
)
# Create Patients and Visits that should be excluded
@@ -441,9 +428,7 @@ def test_kpi_calculation_47(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 4
EXPECTED_TOTAL_INELIGIBLE = 2
@@ -541,9 +526,7 @@ def test_kpi_calculation_48(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 5
EXPECTED_TOTAL_INELIGIBLE = 2
@@ -641,9 +624,7 @@ def test_kpi_calculation_49(AUDIT_START_DATE):
)
# The default pz_code is "PZ130" for PaediatricsDiabetesUnitFactory
- calc_kpis = CalculateKPIS(
- pz_code="PZ130", calculation_date=AUDIT_START_DATE
- )
+ calc_kpis = CalculateKPIS(pz_code="PZ130", calculation_date=AUDIT_START_DATE)
EXPECTED_TOTAL_ELIGIBLE = 5
EXPECTED_TOTAL_INELIGIBLE = 2
@@ -678,4 +659,4 @@ def calculate_median(values):
# If the length of the list is even, return the average of the two middle elements
middle1 = sorted_values[n // 2 - 1]
middle2 = sorted_values[n // 2]
- return (middle1 + middle2) / 2
\ No newline at end of file
+ return (middle1 + middle2) / 2
diff --git a/project/npda/urls.py b/project/npda/urls.py
index 57cbbe00..edb36f0d 100644
--- a/project/npda/urls.py
+++ b/project/npda/urls.py
@@ -1,7 +1,7 @@
from django.urls import path, include
from django.contrib.auth.views import PasswordResetConfirmView
from django.contrib.auth import urls as auth_urls
-from project.npda.general_functions.kpis import KPIAggregationForPDU
+from project.npda.kpi_class.kpis import KPIAggregationForPDU
from project.npda.views import (
VisitCreateView,
VisitDeleteView,
@@ -101,6 +101,6 @@
path(
"kpis/aggregation/pdu/",
view=KPIAggregationForPDU.as_view(),
- name='aggregation-pdu'
- )
+ name="aggregation-pdu",
+ ),
]
diff --git a/project/npda/views/visit.py b/project/npda/views/visit.py
index ebfd8aca..c6cf7be1 100644
--- a/project/npda/views/visit.py
+++ b/project/npda/views/visit.py
@@ -1,21 +1,24 @@
+# python imports
+import datetime
+
# Django imports
-from django.contrib.messages.views import SuccessMessageMixin
-from django.contrib.auth.mixins import PermissionRequiredMixin
from django.contrib import messages
+from django.contrib.auth.mixins import PermissionRequiredMixin
+from django.contrib.messages.views import SuccessMessageMixin
from django.forms import BaseModelForm
from django.http import HttpResponse, HttpResponseRedirect
-from django.shortcuts import render
-from django.views.generic.edit import CreateView, UpdateView, DeleteView
+from django.urls import reverse, reverse_lazy
from django.views.generic import ListView
-from django.urls import reverse_lazy, reverse
+from django.views.generic.edit import CreateView, UpdateView, DeleteView
# Third party imports
# RCPCH imports
-from ..models import Visit, Patient
from ..forms.visit_form import VisitForm
from ..general_functions import get_visit_categories
-from .mixins import CheckPDUInstanceMixin, CheckPDUListMixin, LoginAndOTPRequiredMixin
+from ..kpi_class.kpis import CalculateKPIS
+from .mixins import CheckPDUListMixin, LoginAndOTPRequiredMixin, CheckPDUInstanceMixin
+from ..models import Visit, Patient, Transfer
class PatientVisitsListView(
@@ -39,6 +42,25 @@ def get_context_data(self, **kwargs):
context["visits"] = calculated_visits
context["patient"] = patient
context["submission"] = submission
+
+ # calculate the KPIs for this patient
+ pdu = (
+ Transfer.objects.filter(patient=patient, date_leaving_service__isnull=True)
+ .first()
+ .paediatric_diabetes_unit
+ )
+ # get the PDU for this patient - this is the PDU that the patient is currently under.
+ # If the patient has left the PDU, the date_leaving_service will be set and it will be possible to view KPIs for the PDU up until transfer,
+ # if this happened during the audit period. This is TODO
+ kpi_results = CalculateKPIS(
+ pz_code=pdu.pz_code,
+ calculation_date=datetime.date.today(),
+ patients=Patient.objects.filter(
+ pk=patient_id
+ ), # this is a queryset of one patient
+ ).calculate_kpis_for_patients()
+ context["kpi_results"] = kpi_results
+
return context