Skip to content

Commit

Permalink
Update discharge summary to reflect age and year of birth (#2053)
Browse files Browse the repository at this point in the history
* Update discharge summary to reflect age and year of birth

fixes #2052

* suggestions from codereview
  • Loading branch information
rithviknishad authored Apr 4, 2024
1 parent ef53bec commit 397695d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions care/facility/models/patient.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 10 additions & 4 deletions care/templates/reports/patient_discharge_summary_pdf.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ <h3 class="text-lg text-gray-900">
<span class="text-sm text-gray-500">Gender:</span> {{patient.get_gender_display}}
</p>
<p>
<span class="text-sm text-gray-500">Age:</span> {{patient.age}}
</p>
<p>
<span class="text-sm text-gray-500">Date of Birth:</span> {{patient.date_of_birth}}
<span class="text-sm text-gray-500">Age:</span> {{patient.get_age}}
</p>
{% if patient.date_of_birth %}
<p>
<span class="text-sm text-gray-500">Date of Birth:</span> {{patient.date_of_birth}}
</p>
{% else %}
<p>
<span class="text-sm text-gray-500">Year of Birth:</span> {{patient.year_of_birth}}
</p>
{% endif %}
<p>
<span class="text-sm text-gray-500">Blood Group:</span> {{patient.blood_group}}
</p>
Expand Down

0 comments on commit 397695d

Please sign in to comment.