muti department
parent
2b1b63a2fc
commit
18925b4dc7
|
@ -6,9 +6,9 @@
|
||||||
<item string="Nurses" action="clinic_staff" action_options="tab_no=4"/>
|
<item string="Nurses" action="clinic_staff" action_options="tab_no=4"/>
|
||||||
<divider/>
|
<divider/>
|
||||||
<header string="SETTINGS"/>
|
<header string="SETTINGS"/>
|
||||||
<item string="Levels" action="clinic_staff_level"/>
|
<item string="Levels" action="clinic_staff_level" perm="clinic_staff_setting"/>
|
||||||
<item string="Categories" action="clinic_staff_categ"/>
|
<item string="Categories" action="clinic_staff_categ" perm="clinic_staff_setting"/>
|
||||||
<item string="Staff Rotation" action="clinic_staff_rotate" perm="staff_rotation"/>
|
<item string="Staff Rotation" action="clinic_staff_rotate" perm="clinic_staff_setting"/>
|
||||||
</item>
|
</item>
|
||||||
<item string="Patients" perm="clinic_patient">
|
<item string="Patients" perm="clinic_patient">
|
||||||
<item string="Patients" action="clinic_patient"/>
|
<item string="Patients" action="clinic_patient"/>
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
<item string="Graduations" action="clinic_grade"/>
|
<item string="Graduations" action="clinic_grade"/>
|
||||||
<item string="Morbidities" action="clinic_morbidity"/>
|
<item string="Morbidities" action="clinic_morbidity"/>
|
||||||
<item string="Patient Cycles" action="clinic_patient_cycle"/>
|
<item string="Patient Cycles" action="clinic_patient_cycle"/>
|
||||||
<item string="Patient Categories" action="clinic_patient_categ"/>
|
<!--<item string="Patient Categories" action="clinic_patient_categ"/>-->
|
||||||
<item string="Patient Types" action="clinic_patient_type"/>
|
<item string="Patient Types" action="clinic_patient_type"/>
|
||||||
<item string="Races" action="clinic_race"/>
|
<item string="Races" action="clinic_race"/>
|
||||||
<item string="Valcular Access" action="clinic_vascular_access"/>
|
<item string="Valcular Access" action="clinic_vascular_access"/>
|
||||||
|
|
|
@ -15,10 +15,10 @@
|
||||||
<field name="reg_date"/>
|
<field name="reg_date"/>
|
||||||
<field name="first_name" required="1"/>
|
<field name="first_name" required="1"/>
|
||||||
<field name="last_name" required="1"/>
|
<field name="last_name" required="1"/>
|
||||||
<field name="department_id" required="1"/>
|
<!--<field name="categ_id"/>-->
|
||||||
<field name="categ_id"/>
|
|
||||||
<field name="doctor_id"/>
|
<field name="doctor_id"/>
|
||||||
<field name="walkin"/>
|
<field name="walkin"/>
|
||||||
|
<field name="department_id" invisible="1"/>
|
||||||
<field name="active" invisible="1"/>
|
<field name="active" invisible="1"/>
|
||||||
<tabs>
|
<tabs>
|
||||||
<tab string="General">
|
<tab string="General">
|
||||||
|
@ -72,11 +72,28 @@
|
||||||
</field>
|
</field>
|
||||||
</group>
|
</group>
|
||||||
<group span="4" columns="1">
|
<group span="4" columns="1">
|
||||||
<!--<field name="cycle_id"/>-->
|
</group>
|
||||||
|
<group span="8" columns="1">
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<p></p>
|
||||||
|
<b>Note: </b><span style="color:green"><b>"Cycle"</b> ที่ระบุไว้ที่หน้านี้ จะเป็นข้อมูลต้นทางที่ระบบจะนำไปสร้าง Visit ล่วงหน้า</span></div>
|
||||||
|
</template>
|
||||||
|
</group>
|
||||||
|
<group span="4" columns="1">
|
||||||
</group>
|
</group>
|
||||||
</tab>
|
</tab>
|
||||||
<tab string="Location">
|
<tab string="Location">
|
||||||
<field name="departments"/>
|
<field name="departments"/>
|
||||||
|
<group span="8" columns="1">
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<p></p>
|
||||||
|
<b>Note: </b><span style="color:green"><b>"Location"</b> คือ สถานที่ที่ผู้ป่วยสามารถรับการรักษา ซึ่งระบุได้มากกว่า 1 ที่</span></div>
|
||||||
|
</template>
|
||||||
|
</group>
|
||||||
|
<group span="4" columns="1">
|
||||||
|
</group>
|
||||||
</tab>
|
</tab>
|
||||||
<tab string="Accounting">
|
<tab string="Accounting">
|
||||||
<field name="partner_id" domain='[["is_patient","=","true"]]'/>
|
<field name="partner_id" domain='[["is_patient","=","true"]]'/>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<inherit model="select.company" inherit="select_company">
|
<inherit model="select.company" inherit="select_company">
|
||||||
<field name="company" position="after">
|
<field name="company" position="after">
|
||||||
<field name="department" selection="get_departments" required="1"/>
|
<field name="department" selection="get_departments"/>
|
||||||
</field>
|
</field>
|
||||||
</inherit>
|
</inherit>
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
<field name="number"/>
|
<field name="number"/>
|
||||||
<field name="time_start" onchange="onchange_datefrom"/>
|
<field name="time_start" onchange="onchange_datefrom"/>
|
||||||
<field name="cycle_id" onchange="onchange_cycle" required="1"/>
|
<field name="cycle_id" onchange="onchange_cycle" required="1"/>
|
||||||
<field name="department_id"/>
|
<field name="department_id" onchange="onchange_department"/>
|
||||||
<field name="branch_id" required="1"/>
|
<field name="branch_id" invisible="1"/>
|
||||||
</group>
|
</group>
|
||||||
<group span="6" columns="1">
|
<group span="6" columns="1">
|
||||||
<field name="patient_id" onchange="onchange_patient"/>
|
<field name="patient_id" onchange="onchange_patient"/>
|
||||||
|
|
|
@ -5,6 +5,7 @@ class User(Model):
|
||||||
_fields={
|
_fields={
|
||||||
'department_profile_id': fields.Many2One("clinic.department.profile","Department Profile"),
|
'department_profile_id': fields.Many2One("clinic.department.profile","Department Profile"),
|
||||||
'department_id': fields.Many2One("clinic.department","Current Department"),
|
'department_id': fields.Many2One("clinic.department","Current Department"),
|
||||||
|
'department_include': fields.Selection([['yes','Yes'],['no','No']],"Include"),
|
||||||
}
|
}
|
||||||
|
|
||||||
User.register()
|
User.register()
|
||||||
|
|
|
@ -286,6 +286,35 @@ class MakeAPT(Model):
|
||||||
if patient.department_id:
|
if patient.department_id:
|
||||||
department_id=patient.department_id.id
|
department_id=patient.department_id.id
|
||||||
line['department_id']=department_id
|
line['department_id']=department_id
|
||||||
|
|
||||||
|
#line_vals={}
|
||||||
|
#for cycle in patient.cycles:
|
||||||
|
#cycle_id=cycle.cycle_id.id
|
||||||
|
#day=cycle.day
|
||||||
|
#dpt=cycle.department_id
|
||||||
|
#key=dpt.id
|
||||||
|
#if dpt.id not in line_vals.keys():
|
||||||
|
#line_vals[key]={}
|
||||||
|
#vals=line_vals[key]
|
||||||
|
#if day=='mon':
|
||||||
|
#vals['mon_cycle_id']=cycle_id
|
||||||
|
#elif day=='tue':
|
||||||
|
#vals['tue_cycle_id']=cycle_id
|
||||||
|
#elif day=='wed':
|
||||||
|
#vals['wed_cycle_id']=cycle_id
|
||||||
|
#elif day=='thu':
|
||||||
|
#vals['thu_cycle_id']=cycle_id
|
||||||
|
#elif day=='fri':
|
||||||
|
#vals['fri_cycle_id']=cycle_id
|
||||||
|
#elif day=='sat':
|
||||||
|
#vals['sat_cycle_id']=cycle_id
|
||||||
|
#elif day=='sun':
|
||||||
|
#vals['sun_cycle_id']=cycle_id
|
||||||
|
#print("="*50)
|
||||||
|
#for line,vals in line_vals.items():
|
||||||
|
#print(line, vals)
|
||||||
|
#print("="*50)
|
||||||
|
|
||||||
for cycle in patient.cycles:
|
for cycle in patient.cycles:
|
||||||
cycle_id=cycle.cycle_id.id
|
cycle_id=cycle.cycle_id.id
|
||||||
day=cycle.day
|
day=cycle.day
|
||||||
|
|
|
@ -1,19 +1,16 @@
|
||||||
from netforce.model import Model, fields, get_model
|
from netforce.model import Model, fields, get_model
|
||||||
from netforce.access import get_active_user, set_active_user
|
from netforce.access import get_active_user, set_active_user, get_active_company
|
||||||
from netforce.database import get_connection
|
|
||||||
|
|
||||||
class SelectCompany(Model):
|
class SelectCompany(Model):
|
||||||
_inherit="select.company"
|
_inherit="select.company"
|
||||||
_fields={
|
_fields={
|
||||||
"department": fields.Selection([],"Deparment")
|
"department": fields.Selection([],"Department"),
|
||||||
}
|
}
|
||||||
|
|
||||||
def _get_department(self,context={}):
|
def _get_department(self,context={}):
|
||||||
user_id=get_active_user()
|
user_id=get_active_user()
|
||||||
dpt_name=None
|
user=get_model("base.user").browse(user_id)
|
||||||
for staff in get_model("clinic.staff").search_browse([['user_id','=',user_id]]):
|
dpt_name=user.department_id.name or ""
|
||||||
dpt=staff.department_id
|
|
||||||
dpt_name=dpt.name
|
|
||||||
return dpt_name
|
return dpt_name
|
||||||
|
|
||||||
_defaults={
|
_defaults={
|
||||||
|
@ -39,14 +36,114 @@ class SelectCompany(Model):
|
||||||
set_active_user(user_id)
|
set_active_user(user_id)
|
||||||
return [(r["name"],r["name"]) for r in res]
|
return [(r["name"],r["name"]) for r in res]
|
||||||
|
|
||||||
|
def check_profile(self,ids,context={}):
|
||||||
|
user_id=get_active_user()
|
||||||
|
user=get_model("base.user").browse(user_id)
|
||||||
|
dpt_profile=user.department_profile_id
|
||||||
|
if not dpt_profile:
|
||||||
|
raise Exception("Missing department profile! Please contact admin.")
|
||||||
|
set_active_user(1)
|
||||||
|
for obj in self.browse(ids):
|
||||||
|
code=dpt_profile.name or ''
|
||||||
|
pf_ids=get_model('profile').search(['code','=',code])
|
||||||
|
if pf_ids:
|
||||||
|
print("Profile %s is already exist"%(code))
|
||||||
|
set_active_user(user_id)
|
||||||
|
return pf_ids[0]
|
||||||
|
except_perms=['Clinic Menu Settings','Clinic Staff Tab Accounting']
|
||||||
|
other_perms=[]
|
||||||
|
for otp in get_model('permission').search_read(['name','ilike','clinic'],['name']):
|
||||||
|
name=otp['name']
|
||||||
|
if name in except_perms:
|
||||||
|
continue
|
||||||
|
other_perms.append(otp['id'])
|
||||||
|
except_model=['clinic.cycle','clinic.department']
|
||||||
|
perms=[]
|
||||||
|
for model in get_model('model').search_read([['name','ilike','clinic']],['name']):
|
||||||
|
vals={
|
||||||
|
'model_id': model['id'],
|
||||||
|
'perm_read': True,
|
||||||
|
'perm_create': True,
|
||||||
|
'perm_write': True,
|
||||||
|
'perm_delete': True,
|
||||||
|
}
|
||||||
|
name=model['name']
|
||||||
|
if name in except_model:
|
||||||
|
vals['perm_create']=False
|
||||||
|
vals['perm_write']=False
|
||||||
|
vals['perm_delete']=False
|
||||||
|
perms.append(('create', vals))
|
||||||
|
profile_id=get_model('profile').create({
|
||||||
|
'perms': perms,
|
||||||
|
'code': code,
|
||||||
|
'name': code,
|
||||||
|
'perms': perms,
|
||||||
|
'other_perms': [('set',other_perms)],
|
||||||
|
'login_company_id': get_active_company(),
|
||||||
|
'home_action': 'clinic_visit_board',
|
||||||
|
})
|
||||||
|
print("create profile %s"%(code))
|
||||||
|
set_active_user(user_id)
|
||||||
|
return profile_id
|
||||||
|
|
||||||
|
def share_profile(self,ids,context={}):
|
||||||
|
#rule: branch_code-deparment_code
|
||||||
|
profile_id=context.get('profile_id')
|
||||||
|
if not profile_id:
|
||||||
|
raise Exception("Profile not found")
|
||||||
|
models=[
|
||||||
|
['clinic.patient','location','ilike'],
|
||||||
|
['clinic.patient.cycle','department_id.code','='],
|
||||||
|
['clinic.staff','location','ilike'],
|
||||||
|
['clinic.staff.rotation','department_id.code','='],
|
||||||
|
['clinic.visit','department_id.code','='],
|
||||||
|
['clinic.hd.case','department_id.code','='],
|
||||||
|
['clinic.cycle.item','department_id.code','='],
|
||||||
|
['clinic.sickbed','department_id.code','='],
|
||||||
|
['clinic.shop','department_id.code','='],
|
||||||
|
['clinic.dialyzer','department_id.code','='],
|
||||||
|
['clinic.schedule','department_id.code','='],
|
||||||
|
]
|
||||||
|
|
||||||
|
user_id=get_active_user()
|
||||||
|
user=get_model("base.user").browse(user_id)
|
||||||
|
dpt_profile=user.department_profile_id
|
||||||
|
dpt_codes=[dpt.code for dpt in dpt_profile.departments]
|
||||||
|
exist_model=[]
|
||||||
|
for obj in self.browse(ids):
|
||||||
|
for sa in get_model('share.access').search_browse([]):
|
||||||
|
for pf in sa.profiles:
|
||||||
|
if profile_id==pf.id:
|
||||||
|
exist_model.append(sa.model_id.name)
|
||||||
|
break
|
||||||
|
# create new
|
||||||
|
for model,field_dom, op in models:
|
||||||
|
if model in exist_model:
|
||||||
|
print('already exist ', model)
|
||||||
|
continue
|
||||||
|
for model_id in get_model("model").search(['name','=',model]):
|
||||||
|
dom=[]
|
||||||
|
dom='["or",%s]'%(', '.join(['["%s","%s","%s"]'%(field_dom,op,dpt_code) for dpt_code in dpt_codes]))
|
||||||
|
print('dom ', dom)
|
||||||
|
get_model('share.access').create({
|
||||||
|
'model_id': model_id,
|
||||||
|
'profiles': [['set',[profile_id]]],
|
||||||
|
'default_access': 'custom',
|
||||||
|
'filter_type': 'rw',
|
||||||
|
'select_profile': 'include',
|
||||||
|
'domain': dom,
|
||||||
|
})
|
||||||
|
return profile_id
|
||||||
|
print("Done!")
|
||||||
|
|
||||||
def select(self,ids,context={}):
|
def select(self,ids,context={}):
|
||||||
user_id=get_active_user()
|
user_id=get_active_user()
|
||||||
if user_id==1:
|
if user_id==1:
|
||||||
return
|
return
|
||||||
|
user=get_model('base.user').browse(user_id)
|
||||||
obj=self.browse(ids)[0]
|
obj=self.browse(ids)[0]
|
||||||
if obj.department:
|
if obj.department:
|
||||||
user=get_model('base.user').browse(user_id)
|
# set to main profile of that user
|
||||||
set_active_user(1)
|
|
||||||
for dpt in get_model("clinic.department").search_browse([["name","=",obj.department]]):
|
for dpt in get_model("clinic.department").search_browse([["name","=",obj.department]]):
|
||||||
user.write({
|
user.write({
|
||||||
'department_id': dpt.id, #current department
|
'department_id': dpt.id, #current department
|
||||||
|
@ -60,7 +157,13 @@ class SelectCompany(Model):
|
||||||
user.write({
|
user.write({
|
||||||
'profile_id': pf_id,
|
'profile_id': pf_id,
|
||||||
})
|
})
|
||||||
set_active_user(user_id)
|
else:
|
||||||
|
context['profile_id']=obj.check_profile(context=context)
|
||||||
|
pf_id=obj.share_profile(context=context)
|
||||||
|
user.write({
|
||||||
|
'department_id': None, #all include department
|
||||||
|
'profile_id': pf_id,
|
||||||
|
})
|
||||||
res=super().select(ids,context)
|
res=super().select(ids,context)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
|
@ -149,18 +149,14 @@ class ClinicSetting(Model):
|
||||||
if user_id !=1:
|
if user_id !=1:
|
||||||
print("Only admin!!")
|
print("Only admin!!")
|
||||||
return
|
return
|
||||||
# update
|
|
||||||
db=get_connection()
|
files=['Patients_Data_LS1.csv','Patients_Data_LS2.csv','Patients_Data_LS3.csv']
|
||||||
res=db.query("select id, day from clinic_patient_cycle")
|
self.update_patient_file(files)
|
||||||
for r in res:
|
print("Done!")
|
||||||
day=r['day'] or ""
|
|
||||||
if day.isdigit():
|
|
||||||
pc=get_model('clinic.patient.cycle').browse(r['id'])
|
|
||||||
pc.write({
|
|
||||||
'day': DAYS[int(r['day'])],
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
### remove douplicate visit
|
###TODO remove douplicate patient
|
||||||
|
###TODO remove douplicate staff
|
||||||
|
###TODO remove douplicate visit
|
||||||
visits={}
|
visits={}
|
||||||
for visit in get_model("clinic.visit").search_browse([]):
|
for visit in get_model("clinic.visit").search_browse([]):
|
||||||
key='%s-%s'%(visit.visit_date, visit.patient_id.id)
|
key='%s-%s'%(visit.visit_date, visit.patient_id.id)
|
||||||
|
@ -319,7 +315,6 @@ class ClinicSetting(Model):
|
||||||
for sr in get_model(model_name).search_read(dom,['name']):
|
for sr in get_model(model_name).search_read(dom,['name']):
|
||||||
res[sr['name']]=sr['id']
|
res[sr['name']]=sr['id']
|
||||||
return res
|
return res
|
||||||
|
|
||||||
vasculars=get_dicts('clinic.vascular.access')
|
vasculars=get_dicts('clinic.vascular.access')
|
||||||
cycles=get_dicts('clinic.cycle')
|
cycles=get_dicts('clinic.cycle')
|
||||||
titles=get_dicts('clinic.name.title')
|
titles=get_dicts('clinic.name.title')
|
||||||
|
@ -389,7 +384,6 @@ class ClinicSetting(Model):
|
||||||
'vascular_acc': valc,
|
'vascular_acc': valc,
|
||||||
'department_id': dpt,
|
'department_id': dpt,
|
||||||
}
|
}
|
||||||
|
|
||||||
print(" update patient data")
|
print(" update patient data")
|
||||||
for patient_id, vals in datas.items():
|
for patient_id, vals in datas.items():
|
||||||
if not patient_id:
|
if not patient_id:
|
||||||
|
@ -401,7 +395,13 @@ class ClinicSetting(Model):
|
||||||
pass
|
pass
|
||||||
if not vals['card_no']:
|
if not vals['card_no']:
|
||||||
vals['card_no']='/'
|
vals['card_no']='/'
|
||||||
|
else:
|
||||||
|
vals['card_no']=''.join([x for x in vals['card_no'] if x.isdigit()])
|
||||||
|
# recheck
|
||||||
|
if not vals['card_no']:
|
||||||
|
vals['card_no']='/'
|
||||||
pvals=vals.copy()
|
pvals=vals.copy()
|
||||||
|
print(pvals)
|
||||||
get_model("clinic.patient").browse(int(patient_id)).write(pvals)
|
get_model("clinic.patient").browse(int(patient_id)).write(pvals)
|
||||||
print("Done!")
|
print("Done!")
|
||||||
|
|
||||||
|
|
|
@ -325,38 +325,28 @@ class Visit(Model):
|
||||||
data=context['data']
|
data=context['data']
|
||||||
patient_id=data['patient_id']
|
patient_id=data['patient_id']
|
||||||
patient=get_model("clinic.patient").browse(patient_id)
|
patient=get_model("clinic.patient").browse(patient_id)
|
||||||
|
doctor=patient.doctor_id
|
||||||
visits=self.search_browse([['patient_id','=',patient_id]],order="number desc")
|
visits=self.search_browse([['patient_id','=',patient_id]],order="number desc")
|
||||||
if visits:
|
if visits:
|
||||||
visit=visits[0]
|
visit=visits[0]
|
||||||
doctor=visit.doctor_id
|
|
||||||
department_id=None
|
department_id=None
|
||||||
if visit.department_id:
|
if visit.department_id:
|
||||||
department_id=visit.department_id.id
|
department_id=visit.department_id.id
|
||||||
elif patient.department_id:
|
elif patient.department_id:
|
||||||
department_id=patient.department_id.id
|
department_id=patient.department_id.id
|
||||||
|
|
||||||
branch_id=None
|
branch_id=None
|
||||||
if visit.branch_id:
|
if visit.branch_id:
|
||||||
branch_id=visit.branch_id.id
|
branch_id=visit.branch_id.id
|
||||||
elif patient.branch_id:
|
elif patient.branch_id:
|
||||||
branch_id=patient.branch_id.id
|
branch_id=patient.branch_id.id
|
||||||
print("branch_id ", branch_id)
|
|
||||||
data['doctor_id']=doctor.id
|
|
||||||
data['department_id']=department_id
|
data['department_id']=department_id
|
||||||
data['branch_id']=branch_id
|
data['branch_id']=branch_id
|
||||||
|
|
||||||
if not patient.doctor_id:
|
|
||||||
patient.write({
|
|
||||||
'doctor_id': doctor.id,
|
|
||||||
})
|
|
||||||
else:
|
else:
|
||||||
doctor=patient.doctor_id
|
|
||||||
department=patient.department_id
|
department=patient.department_id
|
||||||
branch=patient.branch_id
|
branch=patient.branch_id
|
||||||
data['doctor_id']=doctor.id
|
|
||||||
data['department_id']=department.id
|
data['department_id']=department.id
|
||||||
data['branch_id']=branch.id
|
data['branch_id']=branch.id
|
||||||
|
data['doctor_id']=doctor.id
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def copy(self,ids,context={}) :
|
def copy(self,ids,context={}) :
|
||||||
|
@ -493,4 +483,13 @@ class Visit(Model):
|
||||||
'state': 'pending',
|
'state': 'pending',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def onchange_department(self,context={}):
|
||||||
|
data=context['data']
|
||||||
|
dpt_id=data['department_id']
|
||||||
|
if dpt_id:
|
||||||
|
dpt=get_model("clinic.department").browse(dpt_id)
|
||||||
|
data['branch_id']=dpt.branch_id.id
|
||||||
|
return data
|
||||||
|
|
||||||
Visit.register()
|
Visit.register()
|
||||||
|
|
|
@ -28,9 +28,6 @@
|
||||||
<div>
|
<div>
|
||||||
<a href="#name=clinic_patient_type">{{t "Patient Types"}}</a>
|
<a href="#name=clinic_patient_type">{{t "Patient Types"}}</a>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
<a href="#name=clinic_patient_categ">{{t "Patient Categories"}}</a>
|
|
||||||
</div>
|
|
||||||
<div>
|
<div>
|
||||||
<a href="#name=clinic_patient_cycle">{{t "Patient Cycles"}}</a>
|
<a href="#name=clinic_patient_cycle">{{t "Patient Cycles"}}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue