Mercurial > hgweb > health
changeset 5318:e70ca5cae10a
task #16261: Implement estimated date of birth. Completed
| author | Luis Falcon <falcon@gnuhealth.org> |
|---|---|
| date | Thu, 15 Sep 2022 13:39:59 +0100 |
| parents | 7154827f915f |
| children | 863ce188e76c |
| files | tryton/health/core.py tryton/health/health.py tryton/health/view/party_form.xml |
| diffstat | 3 files changed, 38 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/tryton/health/core.py +++ b/tryton/health/core.py @@ -58,6 +58,18 @@ return res +def estimated_date_from_years(years_old): + """ returns a date of substracting the + referred number of years from today's date + It can be used in different context, such as to estimate + the date of birth from a referred age in years + """ + + today = datetime.today().date() + est_dob = today - relativedelta(years=years_old) + return est_dob + + def compute_age_from_dates(dob, deceased, dod, gender, caller, extra_date): """ Get the person's age.
--- a/tryton/health/health.py +++ b/tryton/health/health.py @@ -59,6 +59,7 @@ ) from .core import (get_institution, compute_age_from_dates, + estimated_date_from_years, get_health_professional) @@ -395,6 +396,8 @@ 'Family names', help='Family or last names', states={'invisible': Not(Bool(Eval('is_person')))}) dob = fields.Date('DoB', help='Date of Birth') + est_dob = fields.Boolean('Est', help="Estimated from referred years") + est_years = fields.Integer('Years', help="Referred years") age = fields.Function(fields.Char('Age'), 'person_age') @@ -830,6 +833,24 @@ if (self.du): return self.get_du_address(name=None) + @fields.depends('est_years', 'dob', 'deceased', 'dod', 'gender') + def on_change_est_years(self): + if (self.est_years): + self.dob = estimated_date_from_years(self.est_years) + self.est_dob = True + self.age = self.person_age(name='age') + # Resets the referred age in years to None after it computes + # the age, so the form won't confuse the reader. + self.est_years = None + + @fields.depends('dob', 'deceased', 'dod', 'gender') + def on_change_dob(self): + """ Automatically show the age in Y-M-D format upon + entering the date of birth + """ + self.age = self.person_age(name='age') + self.est_years = None + @classmethod def validate(cls, parties): super(Party, cls).validate(parties)
--- a/tryton/health/view/party_form.xml +++ b/tryton/health/view/party_form.xml @@ -18,9 +18,13 @@ </group> <newline/> <group colspan="4" id="person_details"> - <group yfill="1" id="person_demographics" string="Demographics"> + <group col="8" id="person_demographics" string="Demographics"> <label name="dob"/> <field name="dob"/> + <label name="est_dob"/> + <field name="est_dob"/> + <label name="est_years"/> + <field name="est_years"/> <label name="age"/> <field name="age"/> <newline/> @@ -50,8 +54,6 @@ <group yfill="1" string="Picture" id="person_picture"> <field xfill="0" xexpand="1" name="photo" height="200" width="200" widget="image"/> </group> - - <newline/> </group> <newline/>
