From 10ec75cde30b4c3576d8513d3b3767029a533ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 9 Jul 2014 14:05:50 +0200 Subject: [PATCH] display age next to birthdate in dossier main page (#3429) --- calebasse/dossiers/models.py | 18 ++++++++++++++++++ .../templates/dossiers/patientrecord_tab1_general.html | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/calebasse/dossiers/models.py b/calebasse/dossiers/models.py index f51029a..5ba5fc1 100644 --- a/calebasse/dossiers/models.py +++ b/calebasse/dossiers/models.py @@ -371,6 +371,24 @@ class PatientContact(People): return None return None + def age(self): + if not self.birthdate: + return 'inconnu' + now = datetime.today().date() + age = now - self.birthdate + years = now.year - self.birthdate.year - ( + (now.month, now.day) < (self.birthdate.month, self.birthdate.day)) + if years < 2: + # for children < 2 years, return the number of months + months = (now.month - self.birthdate.month) - (now.day < self.birthdate.day) + if months < 0: + months += 12 + months += 12*years + if months: + return '%s mois' % months + return '%s jours' % age.days + return '%s ans' % years + class PatientRecordManager(models.Manager): def for_service(self, service): diff --git a/calebasse/dossiers/templates/dossiers/patientrecord_tab1_general.html b/calebasse/dossiers/templates/dossiers/patientrecord_tab1_general.html index 656aa57..78f32f7 100644 --- a/calebasse/dossiers/templates/dossiers/patientrecord_tab1_general.html +++ b/calebasse/dossiers/templates/dossiers/patientrecord_tab1_general.html @@ -8,7 +8,7 @@
  • {{ object.last_name }}
  • {{ object.first_name }}
  • {{ object.get_gender_display|default_if_none:"Non renseigné" }}
  • -
  • {% if object.birthdate %}{{ object.birthdate|date:"d/m/Y" }}{% else %}Non renseignée{% endif %}
  • +
  • {% if object.birthdate %}{{ object.birthdate|date:"d/m/Y" }} ({{ object.age }}){% else %}Non renseignée{% endif %}
  • {% if nb_place_of_lifes == 1 %} -- 2.0.1