fix
parent
60c55cd6f1
commit
8271ea4740
|
@ -13,3 +13,6 @@ force to print table for 1 page ->ok
|
|||
---- visit ---
|
||||
- check duplicate visit
|
||||
- run script to take department to patient
|
||||
|
||||
--- visit board
|
||||
- hide branch and department according to user profile
|
||||
|
|
|
@ -77,6 +77,9 @@
|
|||
<!--<field name="cycle_id"/>-->
|
||||
</group>
|
||||
</tab>
|
||||
<tab string="Location">
|
||||
<field name="departments"/>
|
||||
</tab>
|
||||
<tab string="Accounting">
|
||||
<field name="partner_id" domain='[["is_patient","=","true"]]'/>
|
||||
</tab>
|
||||
|
|
|
@ -4,6 +4,7 @@ class User(Model):
|
|||
_inherit="base.user"
|
||||
_fields={
|
||||
'department_profile_id': fields.Many2One("clinic.department.profile","Department Profile"),
|
||||
'department_id': fields.Many2One("clinic.department","Current Department"),
|
||||
}
|
||||
|
||||
User.register()
|
||||
|
|
|
@ -429,7 +429,7 @@ class HDCase(Model):
|
|||
|
||||
def cancelled(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
obj.write({" state":"cancelled"})
|
||||
obj.write({"state":"cancelled"})
|
||||
|
||||
def make_invoices(self,ids,context={}):
|
||||
setting=get_model("settings").browse(1,context)
|
||||
|
|
|
@ -68,8 +68,11 @@ class Patient(Model):
|
|||
res={}
|
||||
for obj in self.browse(ids):
|
||||
dpt_codes=set()
|
||||
for cline in obj.cycles:
|
||||
dpt_codes.update({cline.department_id.code})
|
||||
for dpt in obj.departments:
|
||||
dpt_codes.update({dpt.code})
|
||||
if not dpt_codes:
|
||||
for cline in obj.cycles:
|
||||
dpt_codes.update({cline.department_id.code})
|
||||
if not dpt_codes:
|
||||
dpt_codes=[obj.department_id.code]
|
||||
res[obj.id]=','.join([code for code in dpt_codes if code])
|
||||
|
@ -184,6 +187,9 @@ class Patient(Model):
|
|||
if b_ids:
|
||||
return b_ids[0]
|
||||
|
||||
def _get_dpts(self,context={}):
|
||||
return get_model("clinic.department").search([])
|
||||
|
||||
_defaults={
|
||||
#"number": _get_number,
|
||||
"number": "",
|
||||
|
@ -195,6 +201,7 @@ class Patient(Model):
|
|||
"active" : True,
|
||||
'state': 'admit',
|
||||
'walkin': 'no',
|
||||
'departments': _get_dpts,
|
||||
}
|
||||
|
||||
_sql_constraints=("clinic_patient_key_uniq","unique(name_check,branch_id)","name should be unique"),
|
||||
|
|
|
@ -20,52 +20,6 @@ class SelectCompany(Model):
|
|||
'department': _get_department,
|
||||
}
|
||||
|
||||
def _get_departments(self,context={}):
|
||||
user_id=get_active_user()
|
||||
user=get_model('base.user').browse(user_id)
|
||||
dom=[]
|
||||
if user.department_profile_id:
|
||||
set_active_user(1)
|
||||
dpt_ids=[]
|
||||
for dpt in user.department_profile_id.departments:
|
||||
dpt_ids.append(dpt.id)
|
||||
if dpt_ids:
|
||||
dom.append(['id','in',dpt_ids])
|
||||
res=get_model("clinic.department").search_read(dom,["name"])
|
||||
set_active_user(user_id)
|
||||
return [(r["name"],r["name"]) for r in res]
|
||||
|
||||
def _select(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
if obj.department:
|
||||
user_id=get_active_user()
|
||||
user=get_model('base.user').browse(user_id)
|
||||
set_active_user(1)
|
||||
staff=None
|
||||
for dpt in get_model("clinic.department").search_browse([["name","=",obj.department]]):
|
||||
for staff in get_model("clinic.staff").search_browse([['user_id','=',user_id]]):
|
||||
staff.write({
|
||||
'department_id': dpt.id,
|
||||
'branch_id': dpt.branch_id.id,
|
||||
})
|
||||
if not staff:
|
||||
raise Exception("No staff match with user %s"%user.name)
|
||||
pf_id=None
|
||||
if dpt.branch_id.code=='LS':
|
||||
for pf in get_model("profile").search_browse([['name','=','Nurse Laksi']]):
|
||||
pf_id=pf.id
|
||||
elif dpt.branch_id.code=='SS':
|
||||
for pf in get_model("profile").search_browse([['name','=','Nurse Samsan']]):
|
||||
pf_id=pf.id
|
||||
if pf_id:
|
||||
user=get_model("base.user").browse(user_id)
|
||||
user.write({
|
||||
'profile_id': pf_id,
|
||||
})
|
||||
set_active_user(user_id)
|
||||
res=super().select(ids,context)
|
||||
return res
|
||||
|
||||
def get_departments(self,context={}):
|
||||
user_id=get_active_user()
|
||||
set_active_user(1)
|
||||
|
@ -94,6 +48,9 @@ class SelectCompany(Model):
|
|||
user=get_model('base.user').browse(user_id)
|
||||
set_active_user(1)
|
||||
for dpt in get_model("clinic.department").search_browse([["name","=",obj.department]]):
|
||||
user.write({
|
||||
'department_id': dpt.id, #current department
|
||||
})
|
||||
pf_id=None
|
||||
for pf in get_model("profile").search_read(['code','=',dpt.code]):
|
||||
pf_id=pf['id']
|
||||
|
@ -112,15 +69,10 @@ class SelectCompany(Model):
|
|||
db=get_connection()
|
||||
department_id=None
|
||||
branch_id=None
|
||||
count=0
|
||||
for r in db.query("select department from select_company where write_uid=%s order by id desc",user_id):
|
||||
for dpt in get_model("clinic.department").search_browse([['name','=',r['department']]]):
|
||||
department_id=dpt.id
|
||||
branch_id=dpt.branch_id.id
|
||||
count+=1
|
||||
break
|
||||
if count<1:
|
||||
return {}
|
||||
user=get_model("base.user").browse(user_id)
|
||||
dpt=user.department_id
|
||||
department_id=dpt.id
|
||||
res={}
|
||||
return {
|
||||
'department_id': department_id,
|
||||
'branch_id': branch_id,
|
||||
|
|
|
@ -145,6 +145,74 @@ class ClinicSetting(Model):
|
|||
})
|
||||
|
||||
def run_script(self,ids,context={}):
|
||||
user_id=get_active_user()
|
||||
if user_id !=1:
|
||||
print("Only admin!!")
|
||||
return
|
||||
# update
|
||||
for pt in get_model("clinic.patient").search_browse([]):
|
||||
dpt=pt.department_id
|
||||
dpt_ids=set()
|
||||
for cc in pt.cycles:
|
||||
dp=cc.department_id
|
||||
vals={}
|
||||
if not dp:
|
||||
vals.update({
|
||||
'department_id': dpt.id,
|
||||
})
|
||||
if (dp.day or "").isdigit():
|
||||
day=DAYS[int(dp.day)]
|
||||
vals.update({
|
||||
'day': day,
|
||||
})
|
||||
cc.write(vals)
|
||||
dp=dp or dpt
|
||||
dpt_ids.update({dp.id})
|
||||
dpt_ids=list(dpt_ids)
|
||||
pt.write({
|
||||
'departments': [('set',dpt_ids)],
|
||||
})
|
||||
return
|
||||
### remove douplicate visit
|
||||
visits={}
|
||||
for visit in get_model("clinic.visit").search_browse([]):
|
||||
key='%s-%s'%(visit.visit_date, visit.patient_id.id)
|
||||
if not key in visits.keys():
|
||||
visits[key]=[]
|
||||
hd_ids=[]
|
||||
for hdcase in visit.hd_cases:
|
||||
hd_ids.append(hdcase.id)
|
||||
visits[key].append({
|
||||
'id': visit.id,
|
||||
'date': visit.visit_date,
|
||||
'patient_id': visit.patient_id.id,
|
||||
'state': visit.state,
|
||||
'hd_ids': hd_ids,
|
||||
})
|
||||
for k, vs in visits.items():
|
||||
if len(vs) > 1:
|
||||
vids=[]
|
||||
for v in vs:
|
||||
if v['state']=='pending':
|
||||
visit=get_model("clinic.visit").browse(v['id'])
|
||||
for hdcase in visit.hd_cases:
|
||||
hdcase.delete()
|
||||
visit.delete()
|
||||
print('deleted id ', v['id'], v['patient_id'], v['date'])
|
||||
elif len(v['hd_ids']) < 1:
|
||||
visit=get_model("clinic.visit").browse(v['id'])
|
||||
if visit:
|
||||
for hdcase in visit.hd_cases:
|
||||
hdcase.delete()
|
||||
visit.to_draft()
|
||||
visit.delete()
|
||||
print('deleted id ', v['id'], v['patient_id'], v['date'])
|
||||
elif v['state'] in ('confirmed', 'cancelled'):
|
||||
vids.append(v['id'])
|
||||
print('need to delete id ', vids, vids[0])
|
||||
print("Done!")
|
||||
|
||||
def multi_department(self,ids,context={}):
|
||||
user_id=get_active_user()
|
||||
if user_id !=1:
|
||||
print("Only admin!!")
|
||||
|
@ -242,49 +310,6 @@ class ClinicSetting(Model):
|
|||
print('Done!')
|
||||
return
|
||||
|
||||
### remove douplicate visit
|
||||
visits={}
|
||||
for visit in get_model("clinic.visit").search_browse([]):
|
||||
key='%s-%s'%(visit.visit_date, visit.patient_id.id)
|
||||
if not key in visits.keys():
|
||||
visits[key]=[]
|
||||
hd_ids=[]
|
||||
for hdcase in visit.hd_cases:
|
||||
hd_ids.append(hdcase.id)
|
||||
visits[key].append({
|
||||
'id': visit.id,
|
||||
'date': visit.visit_date,
|
||||
'patient_id': visit.patient_id.id,
|
||||
'state': visit.state,
|
||||
'hd_ids': hd_ids,
|
||||
})
|
||||
for k, vs in visits.items():
|
||||
if len(vs) > 1:
|
||||
vids=[]
|
||||
for v in vs:
|
||||
if v['state']=='pending':
|
||||
visit=get_model("clinic.visit").browse(v['id'])
|
||||
for hdcase in visit.hd_cases:
|
||||
hdcase.delete()
|
||||
visit.delete()
|
||||
print('deleted id ', v['id'], v['patient_id'], v['date'])
|
||||
elif len(v['hd_ids']) < 1:
|
||||
visit=get_model("clinic.visit").browse(v['id'])
|
||||
if visit:
|
||||
for hdcase in visit.hd_cases:
|
||||
hdcase.delete()
|
||||
visit.to_draft()
|
||||
visit.delete()
|
||||
print('deleted id ', v['id'], v['patient_id'], v['date'])
|
||||
elif v['state'] in ('confirmed', 'cancelled'):
|
||||
vids.append(v['id'])
|
||||
print('need to delete id ', vids, vids[0])
|
||||
|
||||
|
||||
#files=['SS3-1.csv','SS4-1.csv','SS4.csv']
|
||||
#self.update_patient_file(files)
|
||||
print("Done!")
|
||||
|
||||
def update_patient_file(self,files=[]):
|
||||
import csv
|
||||
for _file in files:
|
||||
|
|
Loading…
Reference in New Issue