From 397695dd4faee85377071bac893204248b5c54e6 Mon Sep 17 00:00:00 2001 From: Rithvik Nishad Date: Thu, 4 Apr 2024 21:15:16 +0530 Subject: [PATCH] Update discharge summary to reflect age and year of birth (#2053) * Update discharge summary to reflect age and year of birth fixes #2052 * suggestions from codereview --- care/facility/models/patient.py | 6 ++++++ .../reports/patient_discharge_summary_pdf.html | 14 ++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) 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 @@

Gender: {{patient.get_gender_display}}

- 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}}