diff --git a/care/facility/models/patient.py b/care/facility/models/patient.py index 090fee13fe..d40733515e 100644 --- a/care/facility/models/patient.py +++ b/care/facility/models/patient.py @@ -1,5 +1,6 @@ import enum +from dateutil.relativedelta import relativedelta from django.contrib.postgres.aggregates import ArrayAgg from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models @@ -470,6 +471,11 @@ def save(self, *args, **kwargs) -> None: self._alias_recovery_to_recovered() super().save(*args, **kwargs) + def get_age(self) -> int: + start = self.date_of_birth or timezone.datetime(self.year_of_birth, 1, 1).date() + end = (self.death_datetime or timezone.now()).date() + return relativedelta(end, start).years + def annotate_diagnosis_ids(*args, **kwargs): return ArrayAgg( "last_consultation__diagnoses__diagnosis_id", diff --git a/care/templates/reports/patient_discharge_summary_pdf.html b/care/templates/reports/patient_discharge_summary_pdf.html index 8884e1d43a..48c05155b1 100644 --- a/care/templates/reports/patient_discharge_summary_pdf.html +++ b/care/templates/reports/patient_discharge_summary_pdf.html @@ -46,11 +46,17 @@
- Age: {{patient.age}} -
-- Date of Birth: {{patient.date_of_birth}} + Age: {{patient.get_age}}
+ {% if patient.date_of_birth %} ++ Date of Birth: {{patient.date_of_birth}} +
+ {% else %} ++ Year of Birth: {{patient.year_of_birth}} +
+ {% endif %}Blood Group: {{patient.blood_group}}