diff --git a/netforce_clinic/layouts/clinic_hd_case_form.xml b/netforce_clinic/layouts/clinic_hd_case_form.xml index 2c56b46..8826fa1 100644 --- a/netforce_clinic/layouts/clinic_hd_case_form.xml +++ b/netforce_clinic/layouts/clinic_hd_case_form.xml @@ -21,6 +21,7 @@ + diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index f56fd6b..e44f449 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -390,7 +390,7 @@ class HDCase(Model): data['staffs'].append({ 'staff_id': doctor.id, 'type': 'doctor', - 'priop': 'owner', + 'priop': 'personal', }) if data['patient_type_id']: @@ -1311,7 +1311,7 @@ class HDCase(Model): doctor_id=None for ps in obj.staffs: if ps.type=="doctor": - if ps.priop=='owner': + if ps.priop=='personal': doctor_id=ps.staff_id.id doctor+= 1 else: @@ -1336,7 +1336,7 @@ class HDCase(Model): vals['staffs'].append(('create',{ 'staff_id': doctor.id, 'type': 'doctor', - 'priop': 'owner', + 'priop': 'personal', })) # fee st=get_model("clinic.setting").browse(1) @@ -1577,7 +1577,7 @@ class HDCase(Model): path=context['path'] line=get_data_path(data,path,parent=True) if not line.get('priop'): - line['priop']='owner' + line['priop']='personal' return data HDCase.register() diff --git a/netforce_clinic/models/hd_case_staff.py b/netforce_clinic/models/hd_case_staff.py index 9ebf33b..05e3e5f 100644 --- a/netforce_clinic/models/hd_case_staff.py +++ b/netforce_clinic/models/hd_case_staff.py @@ -24,7 +24,7 @@ class HDCaseStaff(Model): "hd_case_id": fields.Many2One("clinic.hd.case","HD Case",required=True,on_delete="cascade"), "staff_id": fields.Many2One("clinic.staff","Doctor",search=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"), '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), @@ -37,7 +37,7 @@ class HDCaseStaff(Model): _defaults={ 'type': 'doctor', - 'priop': 'owner', + 'priop': 'personal', } HDCaseStaff.register() diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py index dbcea57..b8e643a 100644 --- a/netforce_clinic/models/patient.py +++ b/netforce_clinic/models/patient.py @@ -44,6 +44,7 @@ class Patient(Model): for obj in self.browse(ids): name='' title=obj.title_id + title_name='' if title: title_name=title.name or "" title_name=title_name.replace(" ","") @@ -58,9 +59,11 @@ class Patient(Model): name+='__' elif context.get('active'): name+='__' + name_check=name.replace(" ","") + name_check=name_check.replace(title_name,"") res[obj.id]={ 'name': name, - 'name_check': name.replace(" ",""), # remove all space for make sure + 'name_check': name_check, } return res @@ -320,6 +323,8 @@ class Patient(Model): 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) + for pt in get_model('clinic.setting.account.patient').search_browse([['patient_id','=',obj.id]]): + pt.delete() super().delete(ids) def write(self,ids,vals,**kw): diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py index 9f79427..c2eba2b 100644 --- a/netforce_clinic/models/setting.py +++ b/netforce_clinic/models/setting.py @@ -161,18 +161,107 @@ class ClinicSetting(Model): if user_id !=1: print("Only admin!!") 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.del_duplicate_staff() 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={}): user_id=get_active_user() if user_id !=1: @@ -273,6 +362,7 @@ class ClinicSetting(Model): 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({ diff --git a/netforce_clinic/models/staff.py b/netforce_clinic/models/staff.py index f297e71..dd5c08e 100644 --- a/netforce_clinic/models/staff.py +++ b/netforce_clinic/models/staff.py @@ -73,6 +73,7 @@ class Staff(Model): res={} for obj in self.browse(ids): name='' + title_name='' title=obj.title_id if title: title_name=title.name or "" @@ -88,9 +89,11 @@ class Staff(Model): name+='__' elif context.get('active'): name+='__' + name_check=name.replace(" ","") + name_check=name_check.replace(title_name,"") res[obj.id]={ 'name': name, - 'name_check': name.replace(" ",""), # remove all space for make sure + 'name_check': name_check, # remove all space for make sure } return res diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py index 6e10816..33443a5 100644 --- a/netforce_clinic/models/visit.py +++ b/netforce_clinic/models/visit.py @@ -194,7 +194,7 @@ class Visit(Model): vals['staffs'].append(('create',{ 'staff_id': obj.doctor_id.id, 'type': 'doctor', - 'priop': 'owner', + 'priop': 'personal', })) # use exist hd_case (in case set to draft)