clinic/netforce_clinic/models/patient.py

140 lines
7.2 KiB
Python
Raw Normal View History

2014-08-19 11:36:46 +00:00
import time
2014-10-01 10:52:21 +00:00
from netforce.model import Model, fields, get_model
2014-08-19 11:36:46 +00:00
from netforce.access import get_active_company
class Patient(Model):
_name="clinic.patient"
2014-09-11 03:21:52 +00:00
_string="Patient"
2014-08-19 11:36:46 +00:00
_audit_log=True
_multi_company=True
2014-09-30 11:17:46 +00:00
def _get_age(self,ids,context):
res={}
year_now=int(time.strftime("%Y"))
for obj in self.browse(ids):
age=0
if obj.birthday:
year_bd=int(obj.birthday[0:4])
age=year_now-year_bd
res[obj.id]=age
return res # -> {1: 30, 2: 45,.....}
2014-08-19 11:36:46 +00:00
_fields={
2014-10-01 16:14:52 +00:00
"type": fields.Selection([("mg","Medical Govement"),("sc","Social Security"),("nhso","NHSO (30฿)"),("personal","Personal"),("other","Other")],"Patient Type",required=False),
2014-10-01 11:13:54 +00:00
"number": fields.Char("Patient No.",required=True,search=True),
2014-10-01 10:52:21 +00:00
"name": fields.Char("Name",required=True,search=True),
2014-10-01 11:13:54 +00:00
"reg_date": fields.Date("Register Date",required=False,search=True),
2014-10-01 16:14:52 +00:00
"birthday": fields.Date("Birthday",required=False,search=True),
"phone": fields.Char("Phone",required=False,search=True),
2014-09-30 11:17:46 +00:00
"mobile": fields.Char("Mobile",required=False,search=True),
2014-10-01 11:13:54 +00:00
"job": fields.Char("Job/Position"),
2014-09-30 11:17:46 +00:00
"age": fields.Integer("Age", function="_get_age"),
2014-10-01 16:14:52 +00:00
'picture': fields.File("Picture"),
'email': fields.Char("Email"),
2014-10-01 11:13:54 +00:00
"weight": fields.Float("Weight (cm)"),
"height": fields.Float("Height (Kg)"),
2014-10-01 16:14:52 +00:00
"card_type": fields.Selection([("identification","Identification"),("passport","Passport")],"Card Type",required=True),
2014-10-01 10:52:21 +00:00
'card_no' : fields.Char("Card No."),
2014-08-19 11:36:46 +00:00
"app_no": fields.Char("Application No."),
2014-10-01 07:49:24 +00:00
"salary": fields.Selection([["20000","5,001-20,000"],["50000","20,001-50,000"],["100000","50,001-100,000"],["100001","100,000+"]], "Salary"),
2014-10-01 10:52:21 +00:00
'exp_date' : fields.Date("Expiry Date"),
2014-08-19 11:36:46 +00:00
"addresses": fields.One2Many("address","related_id","Addresses"),
2014-09-30 11:17:46 +00:00
"gender": fields.Selection([("male","Male"),("female","Female")],"Gender",required=False),
"marital_status": fields.Selection([("single","Single"),("marry","Marry"),("divorce","Divorce"),("separated","Saparated"),("widowed","Widowed")],"Marital Status",required=False),
2014-10-01 16:14:52 +00:00
"nation_id": fields.Many2One("clinic.nation","Nationality"),
"race_id": fields.Many2One("clinic.race","Race"),
"grad_id": fields.Many2One("clinic.graduation","Graduation"),
2014-10-01 04:05:52 +00:00
#Patient's +
2014-09-30 11:17:46 +00:00
"smoke": fields.Selection([("never","Never"),("stopped","Stopped"),("smoked","Smoked")],"Smoking"),
"withdrawal" : fields.Selection([("social_security","Social Security"),("health_insurance","Health Insurance"),("etc","ETC.")],"Right of withdrawal"),
"first_treatment" : fields.Selection([("hd","HD"),("test","Test")], "First treatment"),
"first_hemodialysis": fields.Date("First time Hemodialysis",required=False),
"hemodialysis": fields.Char("First Hemodialysis",required=False),
"clinic_after": fields.Selection([("small","Small"),("medium","Medium"),("large","Large")],"Clinic Lastime",required=False),
"clinic_after_name": fields.Char("Clinic after name",required=False),
"first_permanent_vascular_access": fields.Date("First time Permanent Vascular",required=False),
"first_tenckhoff_catheters": fields.Date("First time Tenckhoff Catheters",required=False),
"start_date_clinic": fields.Date("Start Date Clinic",required=False),
"waiting_transplantation": fields.Selection([("yes","Yes"),("no","No")],"Kidney Transplantation Waiting ?"),
2014-08-19 11:36:46 +00:00
"who_transplantation": fields.Char("Who is Transplantation?"),
"reason_of_chronic_renal_failure": fields.Char("Reason chronic renal failure ?"),
2014-10-01 16:59:35 +00:00
'cause_lines': fields.One2Many("clinic.patient.cause.line","patient_id","Cause Line"),
2014-10-01 04:05:52 +00:00
#Co-marbid
"check1" : fields.Boolean("The patient had been diagnosed, Acute MI or Unstable angina"),
"check2" : fields.Boolean("The patient had been diagnosed, Coronary angioplasty or CABG"),
"check3" : fields.Boolean("The patient had been diagnosed, Cerebrovascular accident"),
"check4" : fields.Boolean("The patient had been diagnosed, PVD or Amputation"),
"check5" : fields.Boolean("The patient had been diagnosed, Congestive heart failure"),
"check6" : fields.Boolean("The patient had been diagnosed, Hypertension"),
"check7" : fields.Boolean("The patient had been diagnosed, Diabetes"),
"check8" : fields.Boolean("The patient had been diagnosed, COPD"),
"check9" : fields.Boolean("The patient had been diagnosed, Asthma"),
"check10" : fields.Boolean("The patient had been diagnosed, Pulmonary tuberculosis"),
"check11" : fields.Boolean("The patient had been diagnosed, of cancer"),
"check12" : fields.Boolean("The patient had been diagnosed, Cirrhosis"),
"check13" : fields.Boolean("The patient had been diagnosed, Dyslipidemia"),
"check14" : fields.Boolean("The patient had been diagnosed, PRCA"),
"check15" : fields.Boolean("The patient had been diagnosed, Hyperurinecemia"),
"check16" : fields.Boolean("The patient had been diagnosed, Chronic gouty arthitis"),
"check17" : fields.Boolean("The patient had been diagnosed, Parathyroidectomy"),
#"comarbid" : fields.char("Co-morbid Other"),
#Morbidity
"check18" : fields.Boolean("Ischemic Heart Disease"),
"check19" : fields.Boolean("Of cancer"),
"check20" : fields.Boolean("Cerebrovascular accident"),
"comarbid2": fields.Char("Co-morbid Other"),
#Healthcare
2014-08-19 11:36:46 +00:00
"comments": fields.One2Many("message","related_id","Comments"),
"company_id": fields.Many2One("company","Company"),
"doctorsss": fields.Many2Many("clinic.doctor","Doctors"),
"nurses": fields.Many2Many("clinic.nurse","Nurses"),
"visits": fields.One2Many("clinic.visit","patient_id","Visits"),
2014-08-21 07:29:37 +00:00
"hd_cases": fields.One2Many("clinic.hd.case","patient_id","HD Cases"),
2014-08-19 11:36:46 +00:00
}
def _get_number(self,context={}):
2014-09-30 11:17:46 +00:00
seq_name="clinic_patient"
seq_id=get_model("sequence").find_sequence(name=seq_name)
if not seq_id:
raise Exception("Sequence not found: '%s'"%seq_name)
while 1:
num=get_model("sequence").get_next_number(seq_id)
if not num:
return None
get_model("sequence").increment_number(seq_id)
return num
return
#XXXX
2014-08-19 11:36:46 +00:00
while 1:
2014-08-21 07:29:37 +00:00
num=get_model("sequence").get_number("clinic_patient")
2014-08-19 11:36:46 +00:00
if not num:
return None
res=self.search([["number","=",num]])
if not res:
return num
2014-08-21 07:29:37 +00:00
get_model("sequence").increment("clinic_patient")
2014-08-19 11:36:46 +00:00
_defaults={
2014-10-01 11:27:06 +00:00
"type": "mg",
2014-10-01 11:13:54 +00:00
"reg_date": lambda *a: time.strftime("%Y-%m-%d"),
2014-08-19 11:36:46 +00:00
"number": _get_number,
"company_id": lambda *a: get_active_company(),
}
_order="date desc,number desc"
2014-10-01 06:51:36 +00:00
def name_get(self,ids,context={}):
vals=[]
for obj in self.browse(ids):
name='%s %s'%(obj.first_name or "", obj.last_name or "")
vals.append((obj.id,name))
return vals
2014-08-19 11:36:46 +00:00
def void(self,ids,context={}):
obj=self.browse(ids)[0]
obj.write({"state":"voided"})
Patient.register()