prevent duplicate patient & staff
parent
9d9072dbf0
commit
a3d621bfcf
|
@ -21,6 +21,7 @@
|
||||||
<field name="visit_id" span="2"/>
|
<field name="visit_id" span="2"/>
|
||||||
<field name="branch_id" span="2"/>
|
<field name="branch_id" span="2"/>
|
||||||
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
|
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
|
||||||
|
<field name="doctor_id" string="Personal Doctor" span="3"/>
|
||||||
<field name="req_fee" span="2" invisible="1"/>
|
<field name="req_fee" span="2" invisible="1"/>
|
||||||
<field name="company_id" span="2" invisible="1"/> <!-- to show company name, don't remove -->
|
<field name="company_id" span="2" invisible="1"/> <!-- to show company name, don't remove -->
|
||||||
<field name="hct_include" span="2" invisible="1"/>
|
<field name="hct_include" span="2" invisible="1"/>
|
||||||
|
|
|
@ -390,7 +390,7 @@ class HDCase(Model):
|
||||||
data['staffs'].append({
|
data['staffs'].append({
|
||||||
'staff_id': doctor.id,
|
'staff_id': doctor.id,
|
||||||
'type': 'doctor',
|
'type': 'doctor',
|
||||||
'priop': 'owner',
|
'priop': 'personal',
|
||||||
})
|
})
|
||||||
|
|
||||||
if data['patient_type_id']:
|
if data['patient_type_id']:
|
||||||
|
@ -1311,7 +1311,7 @@ class HDCase(Model):
|
||||||
doctor_id=None
|
doctor_id=None
|
||||||
for ps in obj.staffs:
|
for ps in obj.staffs:
|
||||||
if ps.type=="doctor":
|
if ps.type=="doctor":
|
||||||
if ps.priop=='owner':
|
if ps.priop=='personal':
|
||||||
doctor_id=ps.staff_id.id
|
doctor_id=ps.staff_id.id
|
||||||
doctor+= 1
|
doctor+= 1
|
||||||
else:
|
else:
|
||||||
|
@ -1336,7 +1336,7 @@ class HDCase(Model):
|
||||||
vals['staffs'].append(('create',{
|
vals['staffs'].append(('create',{
|
||||||
'staff_id': doctor.id,
|
'staff_id': doctor.id,
|
||||||
'type': 'doctor',
|
'type': 'doctor',
|
||||||
'priop': 'owner',
|
'priop': 'personal',
|
||||||
}))
|
}))
|
||||||
# fee
|
# fee
|
||||||
st=get_model("clinic.setting").browse(1)
|
st=get_model("clinic.setting").browse(1)
|
||||||
|
@ -1577,7 +1577,7 @@ class HDCase(Model):
|
||||||
path=context['path']
|
path=context['path']
|
||||||
line=get_data_path(data,path,parent=True)
|
line=get_data_path(data,path,parent=True)
|
||||||
if not line.get('priop'):
|
if not line.get('priop'):
|
||||||
line['priop']='owner'
|
line['priop']='personal'
|
||||||
return data
|
return data
|
||||||
|
|
||||||
HDCase.register()
|
HDCase.register()
|
||||||
|
|
|
@ -24,7 +24,7 @@ class HDCaseStaff(Model):
|
||||||
"hd_case_id": fields.Many2One("clinic.hd.case","HD Case",required=True,on_delete="cascade"),
|
"hd_case_id": fields.Many2One("clinic.hd.case","HD Case",required=True,on_delete="cascade"),
|
||||||
"staff_id": fields.Many2One("clinic.staff","Doctor",search=True),
|
"staff_id": fields.Many2One("clinic.staff","Doctor",search=True),
|
||||||
"type": fields.Selection([("doctor","Doctor"),('nurse','Nurse'),("staff","Staff")],"Type",required=True),
|
"type": fields.Selection([("doctor","Doctor"),('nurse','Nurse'),("staff","Staff")],"Type",required=True),
|
||||||
"priop": fields.Selection([("owner","Owner"),('second','Secondary'),('other','Other')],"Priority"),
|
"priop": fields.Selection([("personal","Personal"),('other','Other')],"Priority"),
|
||||||
'note': fields.Char("Note"),
|
'note': fields.Char("Note"),
|
||||||
'sickbed_id': fields.Many2One("clinic.sickbed","Sickbed",function="_get_all",function_multi=True),
|
'sickbed_id': fields.Many2One("clinic.sickbed","Sickbed",function="_get_all",function_multi=True),
|
||||||
'patient_id': fields.Many2One("clinic.patient","Patient",domain=[['state','=','admit']], function="_get_all",function_multi=True),
|
'patient_id': fields.Many2One("clinic.patient","Patient",domain=[['state','=','admit']], function="_get_all",function_multi=True),
|
||||||
|
@ -37,7 +37,7 @@ class HDCaseStaff(Model):
|
||||||
|
|
||||||
_defaults={
|
_defaults={
|
||||||
'type': 'doctor',
|
'type': 'doctor',
|
||||||
'priop': 'owner',
|
'priop': 'personal',
|
||||||
}
|
}
|
||||||
|
|
||||||
HDCaseStaff.register()
|
HDCaseStaff.register()
|
||||||
|
|
|
@ -44,6 +44,7 @@ class Patient(Model):
|
||||||
for obj in self.browse(ids):
|
for obj in self.browse(ids):
|
||||||
name=''
|
name=''
|
||||||
title=obj.title_id
|
title=obj.title_id
|
||||||
|
title_name=''
|
||||||
if title:
|
if title:
|
||||||
title_name=title.name or ""
|
title_name=title.name or ""
|
||||||
title_name=title_name.replace(" ","")
|
title_name=title_name.replace(" ","")
|
||||||
|
@ -58,9 +59,11 @@ class Patient(Model):
|
||||||
name+='__'
|
name+='__'
|
||||||
elif context.get('active'):
|
elif context.get('active'):
|
||||||
name+='__'
|
name+='__'
|
||||||
|
name_check=name.replace(" ","")
|
||||||
|
name_check=name_check.replace(title_name,"")
|
||||||
res[obj.id]={
|
res[obj.id]={
|
||||||
'name': name,
|
'name': name,
|
||||||
'name_check': name.replace(" ",""), # remove all space for make sure
|
'name_check': name_check,
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@ -320,6 +323,8 @@ class Patient(Model):
|
||||||
get_model("address").delete(address_ids)
|
get_model("address").delete(address_ids)
|
||||||
vids=get_model("clinic.visit").search([['patient_id','in',ids],['state','in',['draft','pending']]])
|
vids=get_model("clinic.visit").search([['patient_id','in',ids],['state','in',['draft','pending']]])
|
||||||
get_model('clinic.visit').delete(vids)
|
get_model('clinic.visit').delete(vids)
|
||||||
|
for pt in get_model('clinic.setting.account.patient').search_browse([['patient_id','=',obj.id]]):
|
||||||
|
pt.delete()
|
||||||
super().delete(ids)
|
super().delete(ids)
|
||||||
|
|
||||||
def write(self,ids,vals,**kw):
|
def write(self,ids,vals,**kw):
|
||||||
|
|
|
@ -161,18 +161,107 @@ class ClinicSetting(Model):
|
||||||
if user_id !=1:
|
if user_id !=1:
|
||||||
print("Only admin!!")
|
print("Only admin!!")
|
||||||
return
|
return
|
||||||
res={}
|
|
||||||
for l in get_model("clinic.hd.case.line").search_browse([]):
|
|
||||||
prod=l.product_id
|
|
||||||
categ=l.product_categ_id
|
|
||||||
res.setdefault(categ.name,[]).append(1)
|
|
||||||
for k,v in res.items():
|
|
||||||
print(k, len(v))
|
|
||||||
|
|
||||||
#obj=self.browse(ids)[0]
|
#obj=self.browse(ids)[0]
|
||||||
#obj.del_duplicate_staff()
|
#obj.del_duplicate_staff()
|
||||||
print("Done!")
|
print("Done!")
|
||||||
|
|
||||||
|
def merge_staff(self,ids,context={}):
|
||||||
|
user_id=get_active_user()
|
||||||
|
if user_id !=1:
|
||||||
|
print("Only admin!!")
|
||||||
|
return
|
||||||
|
sts={}
|
||||||
|
print('='*50, 'patients duplicate')
|
||||||
|
db=get_connection()
|
||||||
|
print('='*50, 'staffs duplicate')
|
||||||
|
for st in get_model("clinic.staff").search_browse([]):
|
||||||
|
name='%s %s'%(st.first_name or '', st.last_name or '')
|
||||||
|
name=name.replace(" ","")
|
||||||
|
if not sts.get(name):
|
||||||
|
sts[name]=[]
|
||||||
|
sts[name].append({
|
||||||
|
'id': st.id,
|
||||||
|
'name': name,
|
||||||
|
'branch_id': st.department_id.id,
|
||||||
|
'type': st.type,
|
||||||
|
'date': st.date,
|
||||||
|
})
|
||||||
|
|
||||||
|
for st, vals in sts.items():
|
||||||
|
vals=sorted(vals,key=lambda x: x['date'])
|
||||||
|
count=len(vals)
|
||||||
|
if count > 1:
|
||||||
|
print("z"*50)
|
||||||
|
id_lines=[]
|
||||||
|
no=0
|
||||||
|
for val in vals:
|
||||||
|
no+=1
|
||||||
|
staff_id=val['id']
|
||||||
|
staff_type=val['type']
|
||||||
|
if staff_type=='nurse':
|
||||||
|
res=get_model("clinic.cycle.item.line").search_browse([['nurse_id','=',staff_id]])
|
||||||
|
if len(res)<=0:
|
||||||
|
print('nurse zero delete ', st)
|
||||||
|
get_model('clinic.staff').delete([staff_id])
|
||||||
|
else:
|
||||||
|
print('merge nurse... ', st, staff_id, val['date'], val['branch_id'], len(res))
|
||||||
|
print('no ', no, len(vals), len(res))
|
||||||
|
if no==len(vals):
|
||||||
|
print("--> ", staff_id, id_lines)
|
||||||
|
for id_line in id_lines:
|
||||||
|
for rec in get_model("clinic.cycle.item.line").search_browse([['nurse_id','=',id_line]]):
|
||||||
|
rec.write({
|
||||||
|
'nurse_id': staff_id,
|
||||||
|
})
|
||||||
|
dom=[
|
||||||
|
['type','=','nurse'],
|
||||||
|
['staff_id','=',id_line],
|
||||||
|
]
|
||||||
|
for lcost in get_model("clinic.labor.cost.line").search_browse(dom):
|
||||||
|
lcost.write({
|
||||||
|
'staff_id': staff_id,
|
||||||
|
})
|
||||||
|
id_lines.append(staff_id)
|
||||||
|
elif staff_type=='doctor':
|
||||||
|
res=get_model("clinic.hd.case.staff").search_browse([['staff_id','=',staff_id]])
|
||||||
|
if len(res)<=0:
|
||||||
|
print('doctor zero delete ', st)
|
||||||
|
get_model('clinic.staff').delete([staff_id])
|
||||||
|
else:
|
||||||
|
print('merge doctor... ', st, staff_id, val['date'], val['branch_id'], len(res))
|
||||||
|
if no==len(vals):
|
||||||
|
print("--> ", staff_id, id_lines)
|
||||||
|
db=get_connection()
|
||||||
|
for id_line in id_lines:
|
||||||
|
for rec in get_model("clinic.hd.case.staff").search_browse([['staff_id','=',id_line]]):
|
||||||
|
rec.write({
|
||||||
|
'staff_id': staff_id,
|
||||||
|
})
|
||||||
|
hdcase=rec.hd_case_id
|
||||||
|
vs=hdcase.visit_id
|
||||||
|
#vs.write({
|
||||||
|
#'doctor_id': staff_id,
|
||||||
|
#})
|
||||||
|
db.execute("update clinic_visit set doctor_id=%s where id=%s",staff_id,vs.id)
|
||||||
|
pt=hdcase.patient_id
|
||||||
|
#pt.write({
|
||||||
|
#'doctor_id': staff_id,
|
||||||
|
#})
|
||||||
|
db.execute("update clinic_patient set doctor_id=%s where id=%s",staff_id,pt.id)
|
||||||
|
citem=hdcase.cycle_item_id
|
||||||
|
dom=[
|
||||||
|
['type','=','doctor'],
|
||||||
|
['staff_id','=',id_line],
|
||||||
|
['labor_cost_id.cycle_item_id','=',citem.id],
|
||||||
|
]
|
||||||
|
for lcost in get_model("clinic.labor.cost.line").search_browse(dom):
|
||||||
|
lcost.write({
|
||||||
|
'staff_id': staff_id,
|
||||||
|
})
|
||||||
|
id_lines.append(staff_id)
|
||||||
|
print("z"*50)
|
||||||
|
print("Done!")
|
||||||
|
|
||||||
def del_duplicate_staff(self,ids,context={}):
|
def del_duplicate_staff(self,ids,context={}):
|
||||||
user_id=get_active_user()
|
user_id=get_active_user()
|
||||||
if user_id !=1:
|
if user_id !=1:
|
||||||
|
@ -273,6 +362,7 @@ class ClinicSetting(Model):
|
||||||
print('='*50, 'staffs duplicate')
|
print('='*50, 'staffs duplicate')
|
||||||
for st in get_model("clinic.staff").search_browse([]):
|
for st in get_model("clinic.staff").search_browse([]):
|
||||||
name='%s %s'%(st.first_name or '', st.last_name or '')
|
name='%s %s'%(st.first_name or '', st.last_name or '')
|
||||||
|
name=name.replace(" ","")
|
||||||
if not sts.get(name):
|
if not sts.get(name):
|
||||||
sts[name]=[]
|
sts[name]=[]
|
||||||
sts[name].append({
|
sts[name].append({
|
||||||
|
|
|
@ -73,6 +73,7 @@ class Staff(Model):
|
||||||
res={}
|
res={}
|
||||||
for obj in self.browse(ids):
|
for obj in self.browse(ids):
|
||||||
name=''
|
name=''
|
||||||
|
title_name=''
|
||||||
title=obj.title_id
|
title=obj.title_id
|
||||||
if title:
|
if title:
|
||||||
title_name=title.name or ""
|
title_name=title.name or ""
|
||||||
|
@ -88,9 +89,11 @@ class Staff(Model):
|
||||||
name+='__'
|
name+='__'
|
||||||
elif context.get('active'):
|
elif context.get('active'):
|
||||||
name+='__'
|
name+='__'
|
||||||
|
name_check=name.replace(" ","")
|
||||||
|
name_check=name_check.replace(title_name,"")
|
||||||
res[obj.id]={
|
res[obj.id]={
|
||||||
'name': name,
|
'name': name,
|
||||||
'name_check': name.replace(" ",""), # remove all space for make sure
|
'name_check': name_check, # remove all space for make sure
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
|
@ -194,7 +194,7 @@ class Visit(Model):
|
||||||
vals['staffs'].append(('create',{
|
vals['staffs'].append(('create',{
|
||||||
'staff_id': obj.doctor_id.id,
|
'staff_id': obj.doctor_id.id,
|
||||||
'type': 'doctor',
|
'type': 'doctor',
|
||||||
'priop': 'owner',
|
'priop': 'personal',
|
||||||
}))
|
}))
|
||||||
|
|
||||||
# use exist hd_case (in case set to draft)
|
# use exist hd_case (in case set to draft)
|
||||||
|
|
Loading…
Reference in New Issue