clinic/netforce_clinic/models/patient.py

581 lines
24 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-10-02 01:12:46 +00:00
from netforce.access import get_active_company, get_active_user, set_active_user
2015-05-07 08:10:23 +00:00
from netforce.database import get_connection
2014-08-19 11:36:46 +00:00
2015-01-13 07:56:30 +00:00
from . import utils
2014-08-19 11:36:46 +00:00
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-11-30 13:05:14 +00:00
def _get_last_cycle(self,ids,context={}):
res={}
for obj in self.browse(ids):
cycle_id=None
for vs in obj.visits:
cycle=vs.cycle_id
cycle_id=cycle.id
res[obj.id]=cycle_id
return res
2014-12-02 08:34:28 +00:00
2015-01-09 05:19:52 +00:00
def _get_hn_no(self,ids,context={}):
2014-12-02 11:41:05 +00:00
res={}
for obj in self.browse(ids):
2015-01-13 07:56:30 +00:00
hn=''.join(x for x in (obj.number or "") if x.isdigit())
2014-12-02 11:41:05 +00:00
res[obj.id]=hn
return res
def _get_name(self,ids,context={}):
res={}
for obj in self.browse(ids):
name=''
title=obj.title_id
2015-04-29 01:36:05 +00:00
title_name=''
if title:
title_name=title.name or ""
title_name=title_name.replace(" ","")
if title_name.lower()!='notitle':
name+=obj.title_id.name or ""
if obj.first_name:
name+=obj.first_name or ""
name+=" "
if obj.last_name:
name+=obj.last_name or ""
if not obj.active:
2015-03-03 16:53:31 +00:00
name+='__'
elif context.get('active'):
2015-03-03 16:53:31 +00:00
name+='__'
2015-04-29 01:36:05 +00:00
name_check=name.replace(" ","")
name_check=name_check.replace(title_name,"")
res[obj.id]={
'name': name,
2015-04-29 01:36:05 +00:00
'name_check': name_check,
}
return res
2015-03-13 06:43:12 +00:00
def _get_location(self,ids,context={}):
res={}
for obj in self.browse(ids):
dpt_codes=set()
2015-05-07 05:08:51 +00:00
# main department
dpt_codes.update({obj.department_id.code})
# cycle settings
for cline in obj.cycles:
dpt_codes.update({cline.department_id.code})
2015-03-13 06:43:12 +00:00
res[obj.id]=','.join([code for code in dpt_codes if code])
return res
2015-03-13 17:20:48 +00:00
def _get_department_names(self,ids,context={}):
res={}
2015-03-15 15:42:15 +00:00
user_id=get_active_user()
set_active_user(1)
2015-03-13 17:20:48 +00:00
for obj in self.browse(ids):
res[obj.id]=','.join([dpt.name for dpt in obj.departments])
2015-03-15 15:42:15 +00:00
set_active_user(user_id)
2015-03-13 17:20:48 +00:00
return res
2015-05-07 08:10:23 +00:00
def _get_log(self,ids,context={}):
res={}
db=get_connection()
for obj in self.browse(ids):
for r in db.query("select create_time,create_uid,write_time,write_uid from clinic_patient where id = %s",obj.id):
res[obj.id]={
'c_time': r['create_time'],
'c_uid': r['create_uid'],
'w_uid': r['write_uid'],
'w_time': r['write_time'],
}
return res
2014-08-19 11:36:46 +00:00
_fields={
2015-05-07 08:10:23 +00:00
'c_time': fields.DateTime("Created",function="_get_log", function_multi=True),
'c_uid': fields.Many2One("base.user","Create By",function="_get_log", function_multi=True),
'w_time': fields.DateTime("Edited",function="_get_log", function_multi=True),
'w_uid': fields.Many2One("base.user","Lasted Edit",function="_get_log", function_multi=True),
2015-02-05 09:03:51 +00:00
"number": fields.Char("HN Number",required=True,search=True),
"trt_no": fields.Char("TRT",search=True),
2015-02-09 12:49:26 +00:00
"hn_no": fields.Char("HN",function="_get_hn_no",store=True),
2015-01-13 09:25:51 +00:00
"hn": fields.Char("REF/HN",search=False),
2015-02-24 14:59:49 +00:00
'title_id': fields.Many2One("clinic.name.title","Title"),
"first_name": fields.Char("First Name"),
"last_name": fields.Char("Last Name"),
"name": fields.Char("Name",function="_get_name",function_multi=True,store=True,search=True),
"name_check": fields.Char("Name",function="_get_name",function_multi=True,store=True), # prevent duplicate
2015-02-24 14:59:49 +00:00
'type_id': fields.Many2One("clinic.patient.type","Type",search=True,required=True),
2015-02-10 04:29:27 +00:00
"reg_date": fields.Date("Reg. 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"),
2015-01-09 05:19:52 +00:00
'image': fields.File("Image"),
2014-10-01 16:14:52 +00:00
'email': fields.Char("Email"),
2015-01-23 09:41:12 +00:00
"weight": fields.Float("Weight (kg.)"),
"height": fields.Float("Height (cm.)"),
2015-02-10 04:29:27 +00:00
"card_type": fields.Selection([("identification","Identification"),("passport","Passport")],"Card Type"),
2016-11-29 16:28:36 +00:00
'card_no' : fields.Char("ID Card",size=13, search=True),
2015-02-10 04:29:27 +00:00
'card_exp' : fields.Date("Card Exp."),
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-26 01:34:10 +00:00
"addresses": fields.One2Many("address","patient_id","Addresses"),
2014-11-28 04:54:21 +00:00
"gender": fields.Selection([("male","Male"),("female","Female")],"Gender",search=True),
2014-09-30 11:17:46 +00:00
"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-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 ?"),
2015-02-20 01:52:14 +00:00
'causes': fields.One2Many("clinic.patient.cause","patient_id","Cause Of Chronic Renal Failure"),
'comorbilities': fields.One2Many("clinic.patient.comorbidity","patient_id","Comorbilities"),
'morbilities': fields.One2Many("clinic.patient.morbidity","patient_id","Morbilities"),
2014-08-19 11:36:46 +00:00
"comments": fields.One2Many("message","related_id","Comments"),
2015-01-14 08:06:19 +00:00
"company_id": fields.Many2One("company","Company",search=True),
2014-08-19 11:36:46 +00:00
"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-10-02 07:36:13 +00:00
"partner_id": fields.Many2One("partner","Contact"),
2014-10-03 02:00:47 +00:00
"dialyzers": fields.One2Many("clinic.dialyzer","patient_id","Dialyzers"),
2015-03-02 07:27:39 +00:00
"active":fields.Boolean("Active"),
2015-03-17 12:18:05 +00:00
"dispose":fields.Boolean("Dispose",search=True),
2014-10-29 09:10:19 +00:00
'note': fields.Text("Note"),
2014-11-01 08:49:27 +00:00
'categ_id': fields.Many2One("clinic.patient.categ","Category"),
'doctor_id': fields.Many2One("clinic.staff","Doctor",domain=[['type','=','doctor']]),
2014-11-05 05:06:43 +00:00
"documents": fields.One2Many("document","related_id","Documents"),
2015-03-17 12:18:05 +00:00
'resign_date': fields.Date("Dispose Date", search=True),
2014-11-18 06:02:47 +00:00
'rm_remain_visit': fields.Boolean("Auto Remove Remaining Visit"),
2016-11-29 16:28:36 +00:00
'department_id': fields.Many2One("clinic.department","Main Department",search=True),
2014-11-30 13:05:14 +00:00
'cycle_id': fields.Many2One("clinic.cycle","Last Cycle",function="_get_last_cycle"),
2015-01-14 13:36:23 +00:00
'branch_id': fields.Many2One("clinic.branch","Branch",search=True),
2015-01-15 07:37:36 +00:00
'cycles': fields.One2Many("clinic.patient.cycle","patient_id", "Cycles"),
2015-01-29 14:55:05 +00:00
"vascular_acc": fields.Many2One("clinic.vascular.access","Vascular Ac."),
2015-03-02 04:03:07 +00:00
'state': fields.Selection([['admit','Admit'],['dispose','Dispose']],'State'),
2015-04-24 11:22:11 +00:00
'walkin': fields.Selection([['yes','Yes'],['no','No']],"Walkin"),
2016-11-29 16:28:36 +00:00
'location': fields.Char("Share Department"), #to filter
2015-06-12 07:38:26 +00:00
'cw_time': fields.DateTime("Cycle Updated"),
'cw_uid': fields.Many2One("base.user"," Cycle Edit"),
"moves": fields.One2Many("clinic.patient.move","patient_id","Moves"),
2014-08-19 11:36:46 +00:00
}
def _get_number(self,context={}):
2014-09-30 11:17:46 +00:00
while 1:
2014-10-02 01:12:46 +00:00
seq_id=get_model("sequence").find_sequence(name="Clinic Patient")
num=get_model("sequence").get_next_number(seq_id,context=context)
2014-08-19 11:36:46 +00:00
if not num:
return None
2014-10-02 01:12:46 +00:00
user_id=get_active_user()
set_active_user(1)
2015-01-13 07:56:30 +00:00
# reformat number: month-running num-year thai(2 digit)
monthnow=int(time.strftime("%m"))
yearnow=utils.date2thai(time.strftime("%Y-%m-%d"),"%(By)s")
num="%s-%s-%s"%(monthnow,num,yearnow)
2014-08-19 11:36:46 +00:00
res=self.search([["number","=",num]])
2014-10-02 01:12:46 +00:00
set_active_user(user_id)
2014-08-19 11:36:46 +00:00
if not res:
return num
2014-10-02 01:12:46 +00:00
get_model("sequence").increment_number(seq_id,context=context)
2014-10-05 05:47:19 +00:00
def _get_cause_line(self,context={}):
cause_ids=get_model("clinic.cause.chronic").search([])
return cause_ids
2014-12-04 08:37:54 +00:00
def _get_type(self,context={}):
ptype_id=None
for ptype in get_model("clinic.patient.type").search_browse([]):
if ptype.default:
ptype_id=ptype.id
break
return ptype_id
2015-01-14 13:36:23 +00:00
2015-03-13 16:31:58 +00:00
def _get_departments(self,context={}):
2015-03-13 17:51:19 +00:00
res=get_model('select.company').get_select()
if res:
2015-03-15 15:42:15 +00:00
if res.get("department_ids"):
return res['department_ids']
else:
return [res['department_id']]
2015-03-17 07:00:11 +00:00
dpts=get_model("clinic.department").search([])
return dpts
2015-03-13 11:42:57 +00:00
2015-03-13 16:31:58 +00:00
def _get_department(self,context={}):
res=get_model('select.company').get_select()
if res:
2015-03-15 15:42:15 +00:00
if res.get("department_ids"):
return res['department_ids'][0]
else:
return res['department_id']
2015-03-13 16:31:58 +00:00
def _get_branch(self,context={}):
res=get_model('select.company').get_select()
if res:
return res['branch_id']
2015-03-15 05:36:17 +00:00
def _get_default_location(self,context={}):
res=get_model('select.company').get_select()
2015-03-15 15:42:15 +00:00
code=''
2015-03-15 05:36:17 +00:00
if res:
2015-03-15 15:42:15 +00:00
dpt_ids=[]
if res.get("department_ids"):
dpt_ids=res['department_ids']
else:
2015-03-17 12:18:05 +00:00
dpt_ids=[res['department_id']]
2015-03-15 15:42:15 +00:00
dpts=get_model("clinic.department").browse(dpt_ids)
code=','.join([dpt.code for dpt in dpts])
return code
2015-03-15 05:36:17 +00:00
2015-03-17 04:59:23 +00:00
def _get_nation(self,context={}):
nid=None
for nt in get_model("clinic.nation").search_browse([['default','=',True]]):
nid=nt.id
return nid
2014-08-19 11:36:46 +00:00
_defaults={
2015-03-12 10:28:58 +00:00
#"number": _get_number,
"number": "",
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
"company_id": lambda *a: get_active_company(),
2015-01-14 13:36:23 +00:00
'branch_id': _get_branch,
2015-03-13 16:31:58 +00:00
'department_id': _get_department,
2014-11-26 01:39:49 +00:00
'card_type': 'identification',
2014-12-04 08:37:54 +00:00
'type_id': _get_type,
2014-10-29 04:40:35 +00:00
"active" : True,
2015-03-02 04:03:07 +00:00
'state': 'admit',
2015-03-06 05:15:19 +00:00
'walkin': 'no',
2015-03-13 16:31:58 +00:00
'departments': _get_departments,
2015-03-15 05:36:17 +00:00
'location': _get_default_location,
2015-03-17 04:59:23 +00:00
'nation_id': _get_nation,
2015-03-17 12:18:05 +00:00
'dispose': False,
2014-08-19 11:36:46 +00:00
}
2015-04-28 03:29:15 +00:00
_sql_constraints=("clinic_patient_key_uniq","unique(name_check)","name should be unique"),
2015-03-02 04:03:07 +00:00
2015-03-17 01:49:03 +00:00
def check_idcard(self,card_type,idcard=''):
2015-03-02 04:03:07 +00:00
res=True
2015-03-17 04:59:23 +00:00
if not idcard:
return False
2015-03-17 01:49:03 +00:00
if card_type!='identification':
return False
2015-03-02 07:27:39 +00:00
if idcard=='/':
return True
2015-03-17 04:59:23 +00:00
if not idcard:
res=False
elif idcard.isalpha():
2015-03-02 04:03:07 +00:00
res=False
elif len(idcard)!=13:
res=False
if not res:
raise Exception("Wrong ID Card!")
2014-08-19 11:36:46 +00:00
2014-10-29 04:56:52 +00:00
def create(self, vals,**kw):
2015-03-02 04:03:07 +00:00
if 'card_no' in vals.keys():
2015-03-17 01:49:03 +00:00
self.check_idcard(vals.get("card_type",""),vals['card_no'])
obj_id=super().create(vals,**kw)
self.function_store([obj_id])
2014-10-02 19:12:52 +00:00
obj=self.browse(obj_id)
partner_id=obj.partner_id
if not partner_id:
2015-03-11 10:08:42 +00:00
partner_name='%s %s'%(obj.first_name or "",obj.last_name or "") # XXX
for partner in get_model("partner").search_browse([['name', '=', partner_name]]):
2014-10-02 19:12:52 +00:00
if partner.name==obj.name:
partner_id=partner.id
break
if not partner_id:
partner_id=get_model("partner").create({
2015-03-11 10:08:42 +00:00
'first_name': obj.first_name or "",
'last_name': obj.last_name or "",
2014-10-02 19:12:52 +00:00
'type': 'person',
2015-02-13 07:46:39 +00:00
'is_patient': True,
2014-10-02 19:12:52 +00:00
})
2014-10-24 18:04:36 +00:00
address_id=get_model('address').create({
'type': 'shipping',
'partner_id': partner_id,
2015-02-27 16:10:50 +00:00
'patient_id': obj.id,
'address': ' ',
'address2': ' ',
'city': ' ',
'postal_code': ' ',
2014-11-27 07:36:27 +00:00
'country_id': 1,
2014-10-24 18:04:36 +00:00
})
get_model('address').browse(address_id).write({
'related_id': "clinic.patient,%s"%obj.id,
})
2014-10-02 19:12:52 +00:00
obj.write({
'partner_id': partner_id,
})
#TODO create patient.move
2014-10-02 19:12:52 +00:00
return obj_id
2014-10-02 07:36:13 +00:00
def delete(self,ids,context={}):
2014-10-02 19:12:52 +00:00
partner_ids=[]
for obj in self.browse(ids):
partner_ids.append(obj.partner_id.id)
2014-10-24 18:04:36 +00:00
address_ids=[addr.id for addr in obj.partner_id.addresses]
2014-10-02 19:12:52 +00:00
get_model("partner").delete(partner_ids)
2014-10-24 18:04:36 +00:00
get_model("address").delete(address_ids)
vids=get_model("clinic.visit").search([['patient_id','in',ids],['state','in',['draft','pending']]])
get_model('clinic.visit').delete(vids)
2015-04-29 01:36:05 +00:00
for pt in get_model('clinic.setting.account.patient').search_browse([['patient_id','=',obj.id]]):
pt.delete()
2014-10-02 19:12:52 +00:00
super().delete(ids)
2015-05-28 09:27:41 +00:00
def check_vals(self,vals):
return vals
2014-10-02 19:12:52 +00:00
def write(self,ids,vals,**kw):
2015-05-04 10:35:11 +00:00
if 'cycles' in vals.keys():
2015-05-28 09:27:41 +00:00
datenow=time.strftime("%Y-%m-%d")
vdom=[
['patient_id','in',ids],
2015-06-19 09:35:29 +00:00
['visit_date','>=',datenow],
2015-05-28 09:27:41 +00:00
['state','=','pending'],
['manual','=',False],
]
visit_ids=get_model("clinic.visit").search(vdom)
get_model("clinic.visit").delete(visit_ids)
2015-06-12 07:38:26 +00:00
vals['cw_time']=time.strftime("%Y-%m-%d %H:%M:%S")
vals['cw_uid']=get_active_user()
2015-05-28 09:27:41 +00:00
2015-03-10 11:45:19 +00:00
if 'type_id' in vals.keys():
#update patient in hd case which state is condition below
for obj in self.browse(ids):
for hdcase in get_model('clinic.hd.case').search_browse([['patient_id','in',ids],['state','in',['draft','waiting_treatment']]]):
hdcase.write({
'patient_type_id': vals['type_id'],
})
2015-03-02 07:27:39 +00:00
if 'dispose' in vals.keys():
if vals['dispose']:
vals['state']='dispose'
2015-03-02 07:36:17 +00:00
if not vals.get("resign_date"):
vals['resign_date']=time.strftime("%Y-%m-%d")
2015-03-03 02:32:45 +00:00
vals['rm_remain_visit']=True
2015-03-02 07:27:39 +00:00
else:
vals['state']='admit'
2015-03-03 02:32:45 +00:00
vals['rm_remain_visit']=False
2015-11-13 04:49:13 +00:00
vals['resign_date']=None
2015-02-24 14:59:49 +00:00
ctx={}
2014-11-10 05:10:39 +00:00
if 'active' in vals.keys():
if not vals['active']:
vals['resign_date']=time.strftime("%Y-%m-%d")
vals['rm_remain_visit']=True
2015-02-24 14:59:49 +00:00
ctx['active']=False
2015-02-23 00:50:19 +00:00
else:
vals['rm_remain_visit']=False
2015-02-27 16:10:50 +00:00
def update_visit_pending(obj,visit_vals):
2015-02-24 14:59:49 +00:00
vids=get_model("clinic.visit").search([['patient_id','=',obj.id],['state','in',['draft','pending']]])
for visit in get_model('clinic.visit').browse(vids):
2015-02-27 16:10:50 +00:00
visit.write(visit_vals)
if visit_vals.get("doctor_id"):
for hdcase in visit.hd_cases:
for shdcase in hdcase.staffs:
shdcase.write({
'staff_id': visit_vals['doctor_id'],
})
2014-10-02 19:12:52 +00:00
for obj in self.browse(ids):
2015-03-02 04:03:07 +00:00
if obj.state=='treatment':
vals['note']=''
vals['resign_date']=None
2015-02-27 16:10:50 +00:00
visit_vals={}
2015-02-23 00:50:19 +00:00
if 'department_id' in vals.keys():
2015-02-27 16:10:50 +00:00
visit_vals.update({
2015-02-24 14:59:49 +00:00
'department_id': vals['department_id'],
2015-02-27 16:10:50 +00:00
})
2015-02-23 00:50:19 +00:00
if 'branch_id' in vals.keys():
2015-02-27 16:10:50 +00:00
visit_vals.update({
2015-02-24 14:59:49 +00:00
'branch_id': vals['branch_id'],
2015-02-27 16:10:50 +00:00
})
2015-02-03 14:09:53 +00:00
if 'doctor_id' in vals.keys():
2015-02-27 16:10:50 +00:00
visit_vals.update({
2015-02-24 14:59:49 +00:00
'doctor_id': vals['doctor_id'],
2015-02-27 16:10:50 +00:00
})
if visit_vals:
2015-02-24 14:59:49 +00:00
update_visit_pending(obj,visit_vals)
2015-02-27 16:10:50 +00:00
# create partner if not found
2014-10-03 02:00:47 +00:00
partner_id=obj.partner_id
if not partner_id and not vals.get('partner_id'):
2015-03-11 10:08:42 +00:00
partner_name='%s %s'%(obj.first_name or "", obj.last_name or "") # XXX
for partner in get_model("partner").search_browse([['name', '=', partner_name]]):
2014-10-02 19:12:52 +00:00
if partner.name==obj.name:
partner_id=partner.id
break
if not partner_id:
partner_id=get_model("partner").create({
2015-03-11 10:08:42 +00:00
'first_name': obj.first_name or "",
'last_name': obj.last_name or "",
2014-10-02 19:12:52 +00:00
'type': 'person',
2015-02-13 07:46:39 +00:00
'is_patient': True,
2014-10-02 19:12:52 +00:00
})
vals['partner_id']=partner_id
2015-03-11 10:08:42 +00:00
#add to account setting
get_model("clinic.setting.account.patient").create({
'setting_id': 1,
'type_id': obj.type_id.id,
'patient_id': obj.id,
'partner_id': partner_id,
'hn': obj.hn_no,
})
2014-10-26 01:34:10 +00:00
if not isinstance(partner_id,int):
partner_id=partner_id.id
if obj.addresses:
addr=obj.addresses[0]
get_model("address").browse(addr.id).write({
'partner_id': partner_id,
2014-11-29 14:56:15 +00:00
'patient_id': obj.id,
2015-02-27 16:10:50 +00:00
'related_id': "clinic.patient,%s"%obj.id,
2014-10-26 01:34:10 +00:00
})
else:
2015-02-27 16:10:50 +00:00
# in case add more one address
2014-10-26 01:34:10 +00:00
if vals.get("addresses"):
addr_vals=vals.get("addresses")[0][1]
addr_id=get_model("address").create(addr_vals)
get_model("address").browse(addr_id).write({
'patient_id': obj.id,
'partner_id': partner_id,
2015-02-27 16:10:50 +00:00
'related_id': "clinic.patient,%s"%obj.id,
2014-10-26 01:34:10 +00:00
})
del vals['addresses']
2015-03-13 07:43:57 +00:00
else:
obj.simple_address()
if obj.rm_remain_visit or vals.get('rm_remain_visit'):
visit_ids=get_model('clinic.visit').search([['patient_id','=',obj.id],['state','in',('draft','pending')]])
2014-11-26 01:39:49 +00:00
get_model('clinic.visit').delete(visit_ids)
print('remove visit auto %s'%visit_ids)
2014-10-02 11:50:11 +00:00
super().write(ids,vals,**kw)
self.function_store(ids,context=ctx)
2015-02-27 16:10:50 +00:00
# update name of partner
for obj in self.browse(ids):
2015-03-17 02:04:48 +00:00
if obj.card_type=='identification':
self.check_idcard(obj.card_type, obj.card_no)
obj.partner_id.write({
2015-03-11 10:08:42 +00:00
'type': 'person',
'first_name': obj.first_name or "",
'last_name': obj.last_name or "",
})
2014-10-14 03:57:20 +00:00
2015-01-09 05:19:52 +00:00
def name_get(self,ids,context={}):
2014-10-24 08:08:56 +00:00
vals=[]
for obj in self.browse(ids):
2015-01-09 05:19:52 +00:00
name=obj.name or ''
2015-02-09 12:49:26 +00:00
nick_name=obj.nick_name or ""
if nick_name:
name+=" (%s)"%nick_name
2015-01-09 05:19:52 +00:00
if obj.hn_no:
2015-02-09 12:49:26 +00:00
name+=" / %s"%obj.hn_no
2015-01-09 07:48:01 +00:00
vals.append((obj.id,name,obj.image))
2014-10-24 08:08:56 +00:00
return vals
def name_search(self,name,domain=None,context={},**kw):
2015-01-09 05:19:52 +00:00
dom=[["name","ilike","%"+name+"%"]]
2014-10-24 08:08:56 +00:00
if domain:
dom=[dom,domain]
ids1=self.search(dom)
2015-02-09 12:49:26 +00:00
dom=[["hn_no","ilike","%"+name+"%"]]
2014-10-24 08:08:56 +00:00
if domain:
dom=[dom,domain]
2015-01-09 05:19:52 +00:00
ids2=self.search(dom)
2015-02-09 12:49:26 +00:00
2015-01-09 05:19:52 +00:00
ids=list(set(ids1+ids2))
2014-10-24 08:08:56 +00:00
return self.name_get(ids,context=context)
2014-10-27 19:01:18 +00:00
def simple_address(self,ids,context={}):
print("call simple address ")
for obj in self.browse(ids):
if not obj.addresses:
2014-10-29 04:56:52 +00:00
address_id=get_model("address").create({
2014-10-27 19:01:18 +00:00
'patient_id': obj.id,
'partner_id': obj.partner_id.id,
'type': 'shipping',
'address': 'xxxx',
'address2': 'xxxx',
'city': 'BKK',
'country_id': 1,
'postal_code': '12000',
})
if context.get('called'):
return obj.id
return {
'next': {
'name': 'clinic_patient',
'mode': 'form',
'active_id': obj.id,
},'flash': 'Simple Address OK',
}
def new_dialyzer(self,ids,context={}):
dlz_id=None
for obj in self.browse(ids):
2015-02-18 08:50:35 +00:00
dlz_vals=get_model("clinic.dialyzer").default_get(context=context)
2014-10-27 19:01:18 +00:00
dlz_vals['patient_id']=obj.id
dlz_vals['company_id']=dlz_vals['company_id'][0]
dlz_vals['product_id']=dlz_vals['product_id'][0]
dlz_id=get_model('clinic.dialyzer').create(dlz_vals)
dialyzer=get_model("clinic.dialyzer").browse(dlz_id)
dialyzer.confirm()
if context.get('called'):
return dlz_id
return {
'next': {
'name': 'clinic_patient',
'mode': 'form',
'active_id': obj.id,
},'flash': 'New Dialyzer successfully',
}
2015-03-02 04:03:07 +00:00
2015-03-02 07:27:39 +00:00
def onchange_state(self,ids,context={}):
pass
2014-10-20 06:22:31 +00:00
2015-03-17 02:04:48 +00:00
def onchange_nation(self,context={}):
data=context['data']
nation_id=data['nation_id']
if nation_id:
nation=get_model("clinic.nation").browse(nation_id)
if nation.code:
if nation.code=='TH':
data['card_type']='identification'
else:
data['card_type']=''
else:
data['card_type']=''
return data
2015-06-19 09:35:29 +00:00
def onchange_walkin(self,context={}):
data=context['data']
if data['walkin']=='yes':
res=get_model('clinic.staff').search([['number','=','walkin'],['type','=','doctor']])
if res:
data['doctor_id']=res[0]
#else:
#data['doctor_id']=None
2015-06-19 09:35:29 +00:00
return data
2014-08-19 11:36:46 +00:00
Patient.register()