clinic/netforce_clinic/models/clinic_patient.py

129 lines
6.6 KiB
Python
Raw Normal View History

2014-08-19 11:36:46 +00:00
from netforce.model import Model, fields, get_model
from netforce.utils import get_data_path
import time
from netforce.access import get_active_user
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
2014-08-21 10:03:45 +00:00
_name_field="name"
2014-08-19 11:36:46 +00:00
_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-09-30 11:17:46 +00:00
"number": fields.Char("Patient ID",required=True,search=True),
"first_name": fields.Char("First Name",required=True,search=True),
"last_name": fields.Char("Last Name",required=False,search=True),
"date": fields.Date("Create Date",required=False,search=True),
"birthday": fields.Date("BirthDay",required=False,search=True),
"telephone": fields.Char("Telephone",required=False,search=True),
"mobile": fields.Char("Mobile",required=False,search=True),
2014-08-19 11:36:46 +00:00
"job": fields.Char("Job"),
2014-09-30 11:17:46 +00:00
"graduation": fields.Selection([("junior_high_school", "Junior High School"),("senior_hish_school","Senior High School"),("vocational_certificate", "Vocational Certificate"),("High_vocational_certificate", "High Vocational Certificate"),("ba", "B.A.(Bachelor of Arts)"),("ma","M.A.(Master of Arts)"),("phd","Ph.D.(Doctor of Philosophy)")],"Graduation"),
"age": fields.Integer("Age", function="_get_age"),
2014-08-19 11:36:46 +00:00
"weight": fields.Integer("Weight (cm)"),
"height": fields.Integer("Height (Kg)"),
2014-09-30 11:17:46 +00:00
"type": fields.Selection([("mg","Medical Govement"),("sc","Social Security"),("nhso","NHSO (30฿)"),("personal","Personal"),("other","Other")],"Type of treatment",required=False),
"card_type": fields.Selection([("iden_id","Identity Card"),("passport","Passport")],"Card Type",required=True),
'iden_id' : fields.Char("Card No."),
2014-08-19 11:36:46 +00:00
"app_no": fields.Char("Application No."),
2014-09-30 11:17:46 +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-08-19 11:36:46 +00:00
'exp_id' : fields.Date("Expiry Date"),
2014-09-30 11:17:46 +00:00
"state": fields.Selection([("draft","Draft"),("active","Active"),("deactive","Deactive")],"Status",required=False),
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-08-19 11:36:46 +00:00
"nationality": fields.Char("Nationality",search=True),
"race": fields.Char("Race",search=True),
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 ?"),
"ac_mi": fields.Boolean("Acute MI"),
"co_an": fields.Boolean("Coronary Angioplasty"),
"ce_ac": fields.Boolean("Cerebrovascular Accident"),
"pvd": fields.Boolean("PVD or Amputation"),
"co_he": fields.Boolean("Congestive heart failure"),
"hypertnsion": fields.Boolean("Hypertension"),
"dia": fields.Boolean("Diabetes"),
"copd": fields.Boolean("Copd"),
"asthma": fields.Boolean("Asthma"),
"pul_tub": fields.Boolean("Pulmonary tuberculosis"),
"cancer": fields.Boolean("Cancer"),
"cirrhosis": fields.Boolean("Cirrhosis"),
"dyslip": fields.Boolean("Dyslipidemia"),
"prca": fields.Boolean("PRCA"),
"hyperucemia": fields.Boolean("Hyperurinencemia"),
"cga": fields.Boolean("Chronic gouty arthitis"),
"parathy": fields.Boolean("Parathyroidectomy"),
"comarbid": fields.Char("Co-morbid 1"),
"comarbid2": fields.Char("Co-morbid 2"),
"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={
"state": "draft",
"date": lambda *a: time.strftime("%Y-%m-%d"),
"number": _get_number,
"company_id": lambda *a: get_active_company(),
}
_order="date desc,number desc"
def void(self,ids,context={}):
obj=self.browse(ids)[0]
obj.write({"state":"voided"})
Patient.register()