140 lines
7.2 KiB
Python
140 lines
7.2 KiB
Python
|
import time
|
||
|
|
||
|
from netforce.model import Model, fields, get_model
|
||
|
from netforce.access import get_active_company
|
||
|
|
||
|
class Patient(Model):
|
||
|
_name="clinic.patient"
|
||
|
_string="Patient"
|
||
|
_audit_log=True
|
||
|
_multi_company=True
|
||
|
|
||
|
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,.....}
|
||
|
|
||
|
_fields={
|
||
|
"type": fields.Selection([("mg","Medical Govement"),("sc","Social Security"),("nhso","NHSO (30฿)"),("personal","Personal"),("other","Other")],"Patient Type",required=False),
|
||
|
"number": fields.Char("Patient No.",required=True,search=True),
|
||
|
"name": fields.Char("Name",required=True,search=True),
|
||
|
"reg_date": fields.Date("Register Date",required=False,search=True),
|
||
|
"birthday": fields.Date("Birthday",required=False,search=True),
|
||
|
"phone": fields.Char("Phone",required=False,search=True),
|
||
|
"mobile": fields.Char("Mobile",required=False,search=True),
|
||
|
"job": fields.Char("Job/Position"),
|
||
|
"age": fields.Integer("Age", function="_get_age"),
|
||
|
'picture': fields.File("Picture"),
|
||
|
'email': fields.Char("Email"),
|
||
|
"weight": fields.Float("Weight (cm)"),
|
||
|
"height": fields.Float("Height (Kg)"),
|
||
|
"card_type": fields.Selection([("identification","Identification"),("passport","Passport")],"Card Type",required=True),
|
||
|
'card_no' : fields.Char("Card No."),
|
||
|
"app_no": fields.Char("Application No."),
|
||
|
"salary": fields.Selection([["20000","5,001-20,000"],["50000","20,001-50,000"],["100000","50,001-100,000"],["100001","100,000+"]], "Salary"),
|
||
|
'exp_date' : fields.Date("Expiry Date"),
|
||
|
"addresses": fields.One2Many("address","related_id","Addresses"),
|
||
|
"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),
|
||
|
"nation_id": fields.Many2One("clinic.nation","Nationality"),
|
||
|
"race_id": fields.Many2One("clinic.race","Race"),
|
||
|
"grad_id": fields.Many2One("clinic.graduation","Graduation"),
|
||
|
#Patient's +
|
||
|
"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 ?"),
|
||
|
"who_transplantation": fields.Char("Who is Transplantation?"),
|
||
|
"reason_of_chronic_renal_failure": fields.Char("Reason chronic renal failure ?"),
|
||
|
'cause_lines': fields.One2Many("clinic.patient.cause.line","patient_id","Cause Line"),
|
||
|
#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
|
||
|
"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"),
|
||
|
"hd_cases": fields.One2Many("clinic.hd.case","patient_id","HD Cases"),
|
||
|
}
|
||
|
|
||
|
def _get_number(self,context={}):
|
||
|
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
|
||
|
while 1:
|
||
|
num=get_model("sequence").get_number("clinic_patient")
|
||
|
if not num:
|
||
|
return None
|
||
|
res=self.search([["number","=",num]])
|
||
|
if not res:
|
||
|
return num
|
||
|
get_model("sequence").increment("clinic_patient")
|
||
|
|
||
|
|
||
|
_defaults={
|
||
|
"type": "mg",
|
||
|
"reg_date": lambda *a: time.strftime("%Y-%m-%d"),
|
||
|
"number": _get_number,
|
||
|
"company_id": lambda *a: get_active_company(),
|
||
|
}
|
||
|
_order="date desc,number desc"
|
||
|
|
||
|
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
|
||
|
|
||
|
def void(self,ids,context={}):
|
||
|
obj=self.browse(ids)[0]
|
||
|
obj.write({"state":"voided"})
|
||
|
|
||
|
Patient.register()
|