multi deparment

conv_bal
watcha.h 2015-03-13 13:43:12 +07:00
parent 9b737c553e
commit f472cea02d
17 changed files with 206 additions and 62 deletions

View File

@ -1,7 +1,7 @@
<form model="clinic.department" show_company="1">
<head>
<button string="Options" dropdown="1">
<item string='Share Access' method="share_access" confirm="Are you sure?"/>
<item string='Copy To Permission' method="share_access" confirm="Are you sure?"/>
</button>
</head>
<field name="name"/>

View File

@ -19,7 +19,7 @@
<field name="cycle_item_id" span="2" onchange="onchange_cycle_item" domain="[['cycle_id','=',cycle_id]]"/>
<field name="visit_id" span="2"/>
<field name="branch_id" span="2"/>
<field name="department_id" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
<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="hct_include" span="2" invisible="1"/>

View File

@ -19,7 +19,7 @@
<field name="categ_id"/>
<!--<field name="branch_id" required="1"/>-->
<!--<field name="department_id" required="1" domain='[["branch_id","=",branch_id]]'/>-->
<field name="department_id"/>
<field name="department_id" required="1"/>
<field name="walkin"/>
<field name="active" invisible="1"/>
<tabs>

View File

@ -10,7 +10,7 @@
<field name="card_no"/>
<field name="name"/>
<field name="type_id"/>
<field name="branch_id"/>
<!--<field name="branch_id"/>-->
<field name="department_id"/>
<field name="doctor_id"/>
<!--<field name="image" preview='1'/>-->

View File

@ -1,5 +1,5 @@
<inherit model="select.company" inherit="select_company">
<field name="company" position="after">
<field name="department" selection="get_departments"/>
<field name="department" selection="get_departments" required="1"/>
</field>
</inherit>

View File

@ -2,7 +2,6 @@ import time
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company, get_active_user
from netforce.utils import get_data_path
class CycleItem(Model):
_name="clinic.cycle.item"
@ -52,14 +51,15 @@ class CycleItem(Model):
}
def _get_branch(self,context={}):
b_ids=get_model('clinic.branch').search([])
if b_ids:
return b_ids[0]
res=get_model('select.company').get_select()
if res:
return res['branch_id']
def _get_department(self,context={}):
dpt_ids=get_model('clinic.department').search([])
if dpt_ids:
return dpt_ids[0]
res=get_model('select.company').get_select()
if res:
return res['department_id']
_defaults={
'state': 'draft',

View File

@ -79,7 +79,7 @@ class Department(Model):
if not profile_id:
raise Exception("Profile not found")
models=[
['clinic.patient','department_id.code','='],
['clinic.patient','location','ilike'],
['clinic.patient.cycle','department_id.code','='],
['clinic.staff','location','ilike'],
['clinic.staff.rotation','staff_id.department_id.code','='],

View File

@ -623,14 +623,15 @@ class HDCase(Model):
if line.qty < 1:
continue
prod=line.product_id
if prod.type != 'stock':
continue
# check orginal product
prod_code=prod.code.split("-")[0]
if len(prod_code)>1:
prods=get_model('product').search_browse(['code','=',prod_code])
if not prods:
raise Exception("Can not create good issue: product code %s is not found!"%prod_code)
prod=prods[0]
if prod.type != 'stock':
continue
#XXX
if prod_ids and prod.id not in prod_ids or prod.id in prod_exist_ids:
continue
prod_exist_ids.append(prod.id)

View File

@ -64,6 +64,17 @@ class Patient(Model):
}
return res
def _get_location(self,ids,context={}):
res={}
for obj in self.browse(ids):
dpt_codes=set()
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])
return res
_fields={
"number": fields.Char("HN Number",required=True,search=True),
"trt_no": fields.Char("TRT",search=True),
@ -134,6 +145,7 @@ class Patient(Model):
'state': fields.Selection([['admit','Admit'],['dispose','Dispose']],'State'),
'walkin': fields.Selection([['yes','Yes'],['no','No']],"Walk In"),
'departments': fields.Many2Many("clinic.department","Departments"),
'location': fields.Char("Location",function="_get_location",store=True), #to filter
}
def _get_number(self,context={}):

View File

@ -33,6 +33,12 @@ class ReportDiscontinuePatient(Model):
department_id=defaults.get('department_id',None)
if department_id:
department_id=int(department_id)
select_apt=get_model('select.company').get_select()
if select_apt:
if not branch_id:
branch_id=select_apt['branch_id']
if not department_id:
department_id=select_apt['department_id']
res={
'date': date,
'date_from': date_from,

View File

@ -30,10 +30,22 @@ class ReportHDCaseSummary(Model):
weekday, total_day=monthrange(int(year), int(month))
return "%s-%s-%s"%(year,month,total_day)
def _get_branch(self,context={}):
res=get_model('select.company').get_select()
if res:
return res['branch_id']
def _get_department(self,context={}):
res=get_model('select.company').get_select()
if res:
return res['department_id']
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"),
'date_from': _get_date_from,
'date_to': _get_date_to,
'branch_id': _get_branch,
'department_id': _get_department,
}
def get_report_data(self,ids,context={}):
@ -44,8 +56,13 @@ class ReportHDCaseSummary(Model):
year=int(date[0:4])
crr_month=int(date[5:7])
weekday, crr_total_day=monthrange(year, crr_month)
branch_id=None
department_id=None
defaults=self.default_get(context=context)
branch_id=defaults.get("branch_id",None)
if branch_id:
branch_id=branch_id[0]
department_id=defaults.get("department_id",None)
if department_id:
department_id=department_id[0]
time_start='%s-%s-01 00:00:00'%(year,str(crr_month).zfill(2))
time_stop='%s-%s-%s 23:59:59'%(year,str(crr_month).zfill(2),crr_total_day)
if ids:

View File

@ -21,7 +21,6 @@ class ReportMedicalSummary(Model):
# in case link from another report
def default_get(self,field_names=None,context={},**kw):
user_id=get_active_user()
defaults=context.get("defaults",{})
date=defaults.get('date',time.strftime("%Y-%m-%d"))
year,month=time.strftime("%Y-%m").split("-")
@ -34,21 +33,15 @@ class ReportMedicalSummary(Model):
if categ_ids:
categ_id=categ_ids[0]
branch_id=defaults.get('branch_id',None)
select_dpt=get_model('select.company').get_select()
if not branch_id:
staff=get_model("clinic.staff").search_browse([['user_id','=',user_id]])
if staff:
branch_id=staff[0].branch_id.id
if select_dpt:
branch_id=select_dpt['branch_id']
else:
branch_id=int(branch_id or "0")
department_id=defaults.get('department_id',None)
if not department_id:
dom=[]
dom.append(['user_id','=',user_id])
if branch_id:
dom.append(['branch_id','=',branch_id])
staff=get_model("clinic.staff").search_browse(dom)
if staff:
department_id=staff[0].department_id.id
department_id=select_dpt['department_id']
else:
department_id=int(department_id or "0")
res={
@ -106,7 +99,7 @@ class ReportMedicalSummary(Model):
if department_id:
dom.append(['department_id','=',department_id])
for hd_case in get_model('clinic.hd.case').search_browse(dom):
patient_type_id=hd_case.patient_id.type_id.id
patient_type_id=hd_case.patient_type_id.id
for line in hd_case.lines:
prod=line.product_id
prod_code=prod.code or ""

View File

@ -32,6 +32,12 @@ class ReportRecentPatient(Model):
department_id=defaults.get('department_id',None)
if department_id:
department_id=int(department_id)
select_apt=get_model('select.company').get_select()
if select_apt:
if not branch_id:
branch_id=select_apt['branch_id']
if not department_id:
department_id=select_apt['department_id']
res={
'date': date,
'date_from': date_from,

View File

@ -1,5 +1,6 @@
from netforce.model import Model, fields, get_model
from netforce.access import get_active_user, set_active_user
from netforce.database import get_connection
class SelectCompany(Model):
_inherit="select.company"
@ -67,10 +68,16 @@ class SelectCompany(Model):
def get_departments(self,context={}):
user_id=get_active_user()
set_active_user(1)
dpt_ids=[]
for st in get_model("clinic.staff").search_browse(['user_id','=',user_id]):
for dpt in st.departments:
dpt_ids.append(dpt.id)
user=get_model("base.user").browse(user_id)
if user.department_profile_id:
for dpt in user.department_profile_id.departments:
dpt_ids.append(dpt.id)
if not dpt_ids:
for st in get_model("clinic.staff").search_browse(['user_id','=',user_id]):
for dpt in st.departments:
dpt_ids.append(dpt.id)
dom=[]
if dpt_ids:
dom.append(['id','in',dpt_ids])
@ -99,5 +106,24 @@ class SelectCompany(Model):
set_active_user(user_id)
res=super().select(ids,context)
return res
def get_select(self,context={}):
user_id=get_active_user()
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 {}
return {
'department_id': department_id,
'branch_id': branch_id,
}
SelectCompany.register()

View File

@ -1,8 +1,21 @@
from datetime import datetime
from netforce.model import Model, fields, get_model
from netforce.utils import get_data_path
from netforce.access import get_active_company, get_active_user, set_active_user
from netforce.database import get_connection
DAYS={
0: 'mon',
1: 'tue',
2: 'wed',
3: 'thu',
4: 'fri',
5: 'sat',
6: 'sun',
}
class ClinicSetting(Model):
_name="clinic.setting"
_string="Setting"
@ -136,18 +149,89 @@ class ClinicSetting(Model):
if user_id !=1:
print("Only admin!!")
return
dpt_ids=get_model("clinic.department").search([])
### udpate working location for staff
staffs={}
for hdcase in get_model('clinic.hd.case').search_browse([]):
dpt=hdcase.department_id
doctor=hdcase.doctor_id
citem=hdcase.cycle_item_id
if not citem:
continue
for cline in citem.lines:
nurse=cline.nurse_id
if nurse.id not in staffs.keys():
staffs[nurse.id]=set()
staffs[nurse.id].update({dpt.id})
if doctor.id not in staffs.keys():
staffs[doctor.id]=set()
staffs[doctor.id].update({dpt.id})
for st_id, dpt_ids in staffs.items():
if not st_id:
continue
st=get_model('clinic.staff').browse(st_id)
olds=[dpt.id for dpt in st.departments]
for dpt_id in dpt_ids:
if dpt_id not in olds:
st.write({
'departments': [('add',[dpt_id])],
})
#### update patient location
for pt in get_model("clinic.patient").search_browse([]):
dpt2_ids=set()
for vst in pt.visits:
if vst.department_id:
dpt2_ids.update({(vst.department_id.id, vst.cycle_id.id)}) # get day
print('dpt2_ids ', dpt2_ids)
if not pt.departments:
pt.write({
'note': ' ',
})
#### update department
#### by visit
dpt_ids=get_model("clinic.department").search([])
fmt='%Y-%m-%d'
for pt in get_model("clinic.patient").search_browse([]):
cycles={}
print('len ', len(pt.visits))
for hd in pt.hd_cases:
if hd.department_id:
date=hd.date
wd=datetime.strptime(date,fmt).weekday()
key='%s-%s-%s'%(hd.department_id.id, hd.cycle_id.id, wd)
if not key in cycles.keys():
cycles[key]={
'department_id': hd.department_id.id,
'cycle_id': hd.cycle_id.id,
'day': wd,
}
print('cycles ', cycles)
if not pt.cycles and cycles:
clines=[]
for key, cycle_vals in cycles.items():
clines.append(('create',cycle_vals)),
pt.write({
#'cycles': [['set',dpt2_ids]],
'cycles': clines,
})
print('set department for ', pt.name)
print('update cycle for ', pt.name)
elif pt.cycles:
continue #XXX
clines=[]
x1=set(cycles.keys())
x2=set()
for pcycle in pt.cycles:
pcycle_id=pcycle.cycle_id.id
pdpt_id=pcycle.department_id.id
wd=pcycle.day
key2='%s-%s-%s'%(pdpt_id,pcycle_id, wd)
x2.update({key2})
for cvals in (x1.difference(x2)):
dpt_id, cycle_id, day=cvals.split("-")
clines.append(('create', {
'department_id': int(dpt_id),
'cycle_id': int(cycle_id),
'day': day,
}))
if clines:
print("---- > update the rest ", clines)
pt.write({
'cycles': clines,
})
else:
pass
for st in get_model("clinic.staff").search_browse([]):
if not st.departments:
st.write({
@ -158,6 +242,7 @@ 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)

View File

@ -464,6 +464,8 @@ class Visit(Model):
def cancel(self,ids,context={}):
obj=self.browse(ids)[0]
for hdcase in obj.hd_cases:
hdcase.cancelled()
obj.write({
'state': 'cancelled',
})

View File

@ -38,26 +38,20 @@ class VisitBoard(Model):
}
def _get_branch(self,context={}):
user_id=get_active_user()
sts=get_model("clinic.staff").search_browse([['user_id','=',user_id]])
branch_id=None
if sts:
branch_id=sts[0].branch_id.id
return branch_id
res=get_model('select.company').get_select()
if res:
return res['branch_id']
def _get_deparment(self,context={}):
user_id=get_active_user()
sts=get_model("clinic.staff").search_browse([['user_id','=',user_id]])
dpt_id=None
if sts:
dpt_id=sts[0].department_id.id
return dpt_id
def _get_department(self,context={}):
res=get_model('select.company').get_select()
if res:
return res['department_id']
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"),
'date_from': lambda *a: time.strftime("%Y-%m-%d"),
'date_to': lambda *a: (datetime.now()+timedelta(days=DRT)).strftime("%Y-%m-%d"),
'department_id': _get_deparment,
'department_id': _get_department,
'branch_id': _get_branch,
}
@ -69,15 +63,17 @@ class VisitBoard(Model):
patient_id=None
cycle_id=None
doctor_id=None
department_id=None
branch_id=None
defaults=self.default_get(context=context)
department_id=defaults.get("department_id",None)
if department_id:
department_id=department_id[0]
branch_id=defaults.get("branch_id",None)
if branch_id:
branch_id=branch_id[0]
user_id=get_active_user()
set_active_user(1) #FIXME to allow user to see doctor different department
sts=get_model("clinic.staff").search_browse([['user_id','=',user_id]])
if sts:
department_id=sts[0].department_id.id
branch_id=sts[0].branch_id.id
if ids:
obj=self.browse(ids)[0]
date_from=obj.date_from