Commit cb5fef4d authored by Ángel Ramírez Isea's avatar Ángel Ramírez Isea
Browse files

refactor: Mover compute_age_from_dates de commed_evaluation a res_partner.

parent b8e058bf
......@@ -5,7 +5,7 @@
from datetime import datetime
from odoo import fields, models, api
from odoo.exceptions import ValidationError
from dateutil.relativedelta import relativedelta
from odoo.addons.commed_base.models.res_partner import ResPartner
class CommedPatientEvaluation(models.Model):
......@@ -13,43 +13,9 @@ class CommedPatientEvaluation(models.Model):
_description = 'Patient Evaluation'
# TODO: in views: STATES = {'signed': [('readonly', True)]}
def compute_age_from_dates(dob, deceased, dod, gender, caller, extra_date):
""" Get the person's age.
Calculate the current age of the patient or age at time of death.
Returns:
If caller == 'age': str in Y-M-D,
caller == 'childbearing_age': boolean,
caller == 'raw_age': [Y, M, D]"""
today = datetime.today().date()
if dob:
start = datetime.strptime(str(dob), '%Y-%m-%d')
end = datetime.strptime(str(today), '%Y-%m-%d')
if extra_date:
end = datetime.strptime(str(extra_date), '%Y-%m-%d')
if deceased and dod:
end = datetime.strptime(str(dod), '%Y-%m-%d %H:%M:%S')
rdelta = relativedelta(end, start)
years_months_days = str(rdelta.years) + 'y ' \
+ str(rdelta.months) + 'm ' \
+ str(rdelta.days) + 'd'
else:
return None
if caller == 'age':
return years_months_days
elif caller == 'childbearing_age':
if (rdelta.years >= 11
and rdelta.years <= 55 and gender == 'f'):
return True
else:
return False
elif caller == 'raw_age':
return [rdelta.years, rdelta.months, rdelta.days]
else:
return None
def patient_age_at_evaluation(self, name):
if (self.patient.name.dob and self.evaluation_start):
return self.compute_age_from_dates(
return ResPartner.compute_age_from_dates(
self.patient.name.dob, None, None, None, 'age',
self.evaluation_start.date()
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment