Projet

Général

Profil

« Précédent | Suivant » 

Révision 1af9e727

Ajouté par Frédéric Péters il y a plus de 9 ans

dossiers: make the age format configurable via service settings

Closes #5469

Voir les différences:

calebasse/dossiers/models.py
21 21
from calebasse.actes.models import Act
22 22

  
23 23
from ..middleware.request import get_request
24
from ..utils import get_service_setting
24 25

  
25 26
DEFAULT_ACT_NUMBER_DIAGNOSTIC = 6
26 27
DEFAULT_ACT_NUMBER_TREATMENT = 30
......
368 369
                return None
369 370
        return None
370 371

  
371
    def age(self):
372
    def age(self, age_format=None):
372 373
        if not self.birthdate:
373 374
            return 'inconnu'
375

  
376
        if not age_format:
377
            age_format = get_service_setting('age_format')
378

  
374 379
        now = datetime.today().date()
375 380
        age = relativedelta(now, self.birthdate)
376
        if age.years < 2:
377
            # for children < 2 years, return the number of months
378
            months = age.years * 12 + age.months
379
            if months:
380
                return '%s mois' % months
381
            return '%s jours' % age.days
382
        return '%s ans' % age.years
381

  
382
        # by default we return the number of months for children < 2 years, but
383
        # there's a service setting to have it always displayed that way.
384
        months = age.years * 12 + age.months
385
        if months == 0:
386
            components = []
387
        elif age.years < 2 or age_format == 'months_only':
388
            components = ['%s mois' % months]
389
        else:
390
            components = ['%s ans' % age.years]
391
            if age.months:
392
                components.append('%s mois' % age.months)
393

  
394
        # under three months, we also display the number of days
395
        if months < 3:
396
            if age.days == 1:
397
                components.append("%s jour" % age.days)
398
            elif age.days > 1:
399
                components.append('%s jours' % age.days)
400

  
401
        return ' et '.join(components)
383 402

  
384 403

  
385 404
class PatientRecordManager(models.Manager):

Formats disponibles : Unified diff