script to prevent duplicate
parent
2326aa85b7
commit
d8fbab28d9
|
@ -252,7 +252,7 @@ class Patient(Model):
|
|||
'dispose': False,
|
||||
}
|
||||
|
||||
_sql_constraints=("clinic_patient_key_uniq","unique(name_check,branch_id)","name should be unique"),
|
||||
_sql_constraints=("clinic_patient_key_uniq","unique(name_check)","name should be unique"),
|
||||
_order="reg_date desc"
|
||||
|
||||
def check_idcard(self,card_type,idcard=''):
|
||||
|
|
|
@ -183,6 +183,7 @@ class ClinicSetting(Model):
|
|||
})
|
||||
sts={}
|
||||
print('='*50, 'patients duplicate')
|
||||
db=get_connection()
|
||||
for pt, vals in pts.items():
|
||||
vals=sorted(vals,key=lambda x: x['date'])
|
||||
count=len(vals)
|
||||
|
@ -190,14 +191,74 @@ class ClinicSetting(Model):
|
|||
if count > 1:
|
||||
id_lines=[]
|
||||
for val in vals:
|
||||
print(val['id'], val['name'])
|
||||
no+=1
|
||||
pt_id=val['id']
|
||||
print(no, val['id'], val['name'], val['date'])
|
||||
if no==len(vals):
|
||||
# hdcase
|
||||
# visit
|
||||
# dialyzer
|
||||
print('---> ', pt_id, id_lines)
|
||||
for del_pt_id in id_lines:
|
||||
visit_ids=[]
|
||||
hdcase_ids=[]
|
||||
print('del_pt_id ', del_pt_id)
|
||||
for hdcase in get_model('clinic.hd.case').search_browse([['patient_id','=',del_pt_id]]):
|
||||
visit_ids.append(hdcase.visit_id.id)
|
||||
hdcase_ids.append(hdcase.id)
|
||||
print('hdcase_ids ', hdcase_ids, 'visit_ids ', visit_ids)
|
||||
if hdcase_ids:
|
||||
print('>>>>>>>> pt_id ', pt_id)
|
||||
db.execute('update clinic_hd_case set patient_id=%s where id in %s', pt_id,tuple(hdcase_ids))
|
||||
db.execute('update clinic_visit set patient_id=%s where id in %s', pt_id,tuple(visit_ids))
|
||||
db.execute('update clinic_dialyzer set patient_id=%s where patient_id = %s', pt_id,del_pt_id)
|
||||
#for hdcase in get_model("clinic.hd.case").browse(hdcase_ids):
|
||||
#hdcase.write({
|
||||
#'patient_id': pt_id,
|
||||
#})
|
||||
#for vs in get_model("clinic.visit").browse(visit_ids):
|
||||
#vs.write({
|
||||
#'patient_id': pt_id,
|
||||
#})
|
||||
#for dlz in get_model("clinic.dialyzer").search_browse([['patient_id','=',del_pt_id]]):
|
||||
#dlz.write({
|
||||
#'patient_id': pt_id,
|
||||
#})
|
||||
for ap in get_model("clinic.setting.account.patient").search_browse([['patient_id','=',del_pt_id]]):
|
||||
ap.write({
|
||||
'patient_id': pt_id,
|
||||
})
|
||||
for hdce in get_model("clinic.hd.case.expense").search_browse([['patient_id','=',del_pt_id]]):
|
||||
hdce.write({
|
||||
'patient_id': pt_id,
|
||||
})
|
||||
#get_model('clinic.patient').delete([del_pt_id])
|
||||
for pt in get_model('clinic.patient').browse([del_pt_id]):
|
||||
pt.write({
|
||||
'first_name': '__%s'% pt.first_name or "",
|
||||
'active': False,
|
||||
})
|
||||
else:
|
||||
print('patient zero delete ', val)
|
||||
for vs in get_model("clinic.visit").search_browse([['patient_id','=',del_pt_id]]):
|
||||
vs.write({
|
||||
'patient_id': pt_id,
|
||||
})
|
||||
for dlz in get_model("clinic.dialyzer").search_browse([['patient_id','=',del_pt_id]]):
|
||||
dlz.write({
|
||||
'patient_id': pt_id,
|
||||
})
|
||||
for ap in get_model("clinic.setting.account.patient").search_browse([['patient_id','=',del_pt_id]]):
|
||||
ap.write({
|
||||
'patient_id': pt_id,
|
||||
})
|
||||
for hdce in get_model("clinic.hd.case.expense").search_browse([['patient_id','=',del_pt_id]]):
|
||||
hdce.write({
|
||||
'patient_id': pt_id,
|
||||
})
|
||||
#get_model('clinic.patient').delete([del_pt_id])
|
||||
for pt in get_model('clinic.patient').browse([del_pt_id]):
|
||||
pt.write({
|
||||
'first_name': '__%s'% pt.first_name or "",
|
||||
'active': False,
|
||||
})
|
||||
print('---> ', pt_id, id_lines, val['date'])
|
||||
else:
|
||||
id_lines.append(pt_id)
|
||||
|
||||
|
|
|
@ -250,8 +250,7 @@ class Staff(Model):
|
|||
'location': _get_default_location,
|
||||
}
|
||||
|
||||
#_key=["name_check","branch_id"] #not working
|
||||
_sql_constraints=("clinic_staff_key_uniq","unique(name_check,branch_id)","name should be unique"),
|
||||
_sql_constraints=("clinic_staff_key_uniq","unique(name_check)","name should be unique"),
|
||||
_order="date desc,number desc"
|
||||
|
||||
def create_contact(self,code,name):
|
||||
|
|
Loading…
Reference in New Issue