optimize report labor cost
parent
f3e9392de0
commit
f7f53887e6
|
@ -19,6 +19,7 @@ from . import nation
|
|||
from . import address
|
||||
from . import partner
|
||||
from . import patient
|
||||
from . import patient_move
|
||||
from . import patient_type
|
||||
from . import patient_categ
|
||||
from . import patient_cycle
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
import time
|
||||
|
||||
from netforce.model import Model, fields
|
||||
|
||||
class PatientMove(Model):
|
||||
_name="clinic.patient.move"
|
||||
_fields={
|
||||
'patient_id': fields.Many2One('clinic.patient','Patient'),
|
||||
'date': fields.DateTime("Date"),
|
||||
'location_id': fields.Many2One("clinic.department","Department"),
|
||||
}
|
||||
|
||||
_defaults={
|
||||
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
}
|
||||
|
||||
PatientMove()
|
|
@ -193,6 +193,7 @@ class ReportHDCaseDetail(Model):
|
|||
})
|
||||
total+=1
|
||||
# new patient of this month
|
||||
#TODO should include move_history
|
||||
elif report_type=='topic3':
|
||||
title=titles.get(report_type,'no title')
|
||||
title+=' '+month_str
|
||||
|
@ -207,8 +208,6 @@ class ReportHDCaseDetail(Model):
|
|||
dom.append(['department_id','=',department_id])
|
||||
total=0
|
||||
for patient in get_model('clinic.patient').search_browse(dom):
|
||||
#if patient.dispose and patient.resign_date < date_from:
|
||||
#continue
|
||||
lines.append({
|
||||
'number': patient.hn_no,
|
||||
'pid': patient.id,
|
||||
|
@ -218,6 +217,7 @@ class ReportHDCaseDetail(Model):
|
|||
})
|
||||
total+=1
|
||||
# number for patient who resign for this month
|
||||
#TODO should include move_history
|
||||
elif report_type=='topic4':
|
||||
title=titles.get(report_type,'no title')
|
||||
title+=' '+month_str
|
||||
|
@ -242,17 +242,16 @@ class ReportHDCaseDetail(Model):
|
|||
total+=1
|
||||
# all patient who are in hospital on select month
|
||||
elif report_type=='topic5':
|
||||
print('topic5 ', time_stop)
|
||||
title=titles.get(report_type,'no title')
|
||||
title+=' '+next_month_str
|
||||
dom=[]
|
||||
dom.append(['reg_date','<=',time_stop])
|
||||
print('topic5 ', time_stop)
|
||||
if branch_id:
|
||||
dom.append(['branch_id','=',branch_id])
|
||||
if department_id:
|
||||
dom.append(['department_id','=',department_id])
|
||||
dom.append(['walkin','=',"no"])
|
||||
#dom.append(['dispose','=',False])
|
||||
total=0
|
||||
for patient in get_model('clinic.patient').search_browse(dom,order="reg_date"):
|
||||
if patient.dispose and patient.resign_date:
|
||||
|
@ -276,8 +275,9 @@ class ReportHDCaseDetail(Model):
|
|||
'dispose': patient.dispose and 'yes' or 'no',
|
||||
})
|
||||
total+=1
|
||||
# find patient movement
|
||||
elif report_type=='topic6':
|
||||
#title=titles.get(report_type,'no title')
|
||||
print('topic6')
|
||||
ptype=None
|
||||
if patient_type_id:
|
||||
ptype=get_model('clinic.patient.type').browse(patient_type_id)
|
||||
|
@ -288,14 +288,12 @@ class ReportHDCaseDetail(Model):
|
|||
dom.append(['reg_date','<=',time_stop])
|
||||
dom.append(['type_id','=',ptype['id']])
|
||||
dom.append(['walkin','=',"no"])
|
||||
#dom.append(['dispose','=',False])
|
||||
dom.append(['type_id','=',ptype.id])
|
||||
if branch_id:
|
||||
dom.append(['branch_id','=',branch_id])
|
||||
if department_id:
|
||||
dom.append(['department_id','=',department_id])
|
||||
total=0
|
||||
print('topic6')
|
||||
for patient in get_model("clinic.patient").search_browse(dom):
|
||||
if patient.resign_date:
|
||||
if patient.dispose and patient.resign_date < date_from:
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import time
|
||||
from datetime import datetime
|
||||
from calendar import monthrange
|
||||
|
||||
from netforce.model import Model,fields,get_model
|
||||
from netforce.access import get_active_company
|
||||
from netforce.database import get_connection
|
||||
|
||||
class ReportLaborCost(Model):
|
||||
_name="clinic.report.labor.cost"
|
||||
|
@ -91,6 +93,7 @@ class ReportLaborCost(Model):
|
|||
hdcase_obj=get_model("clinic.hd.case")
|
||||
dstates=dict(hdcase_obj._fields['state'].selection)
|
||||
print('dom ', dom)
|
||||
t1=datetime.now()
|
||||
for hdcase in hdcase_obj.search_browse(dom):
|
||||
dpt=hdcase.department_id
|
||||
state=hdcase.state or ''
|
||||
|
@ -108,6 +111,8 @@ class ReportLaborCost(Model):
|
|||
if not hdcases[dpt.id]['state'].get(state):
|
||||
hdcases[dpt.id]['state'][state]=0
|
||||
hdcases[dpt.id]['state'][state]+=1
|
||||
t2=datetime.now()
|
||||
print('time1 ',t2-t1)
|
||||
def replace_quote(dom=""):
|
||||
dom=dom.replace("False","false")
|
||||
dom=dom.replace("True","true")
|
||||
|
@ -144,6 +149,8 @@ class ReportLaborCost(Model):
|
|||
'sub_lines': sub_lines,
|
||||
})
|
||||
sub_name=''
|
||||
t2=datetime.now()
|
||||
print('time2 ',t2-t1)
|
||||
if department_id:
|
||||
dpt=get_model("clinic.department").browse(department_id)
|
||||
sub_name="(%s)" % dpt.name or ""
|
||||
|
@ -159,20 +166,38 @@ class ReportLaborCost(Model):
|
|||
ctlines=[]
|
||||
if report_type=='cross':
|
||||
dom=[
|
||||
['date','>=',date_from],
|
||||
['date','<=',date_to],
|
||||
['labor_cost_id.cycle_item_id.state','=','validated'],
|
||||
['lcl.date','>=',"'%s'"%date_from],
|
||||
['lcl.date','<=',"'%s'"%date_to],
|
||||
]
|
||||
#TODO dom below make loading data very slow
|
||||
# if we send ids to browse function directly it will fast
|
||||
if branch_id:
|
||||
dom.append(['labor_cost_id.cycle_item_id.branch_id','=',branch_id])
|
||||
dom.append(['cit.branch_id','=',branch_id])
|
||||
if department_id:
|
||||
dom.append(['labor_cost_id.cycle_item_id.department_id','=',department_id])
|
||||
dom.append(['cit.department_id','=',department_id])
|
||||
if cycle_id:
|
||||
dom.append(['labor_cost_id.cycle_item_id.cycle_id','=',cycle_id])
|
||||
dom.append(['cit.cycle_id','=',cycle_id])
|
||||
|
||||
db=get_connection()
|
||||
sql='''
|
||||
select lcl.id from clinic_labor_cost_line as lcl
|
||||
left join clinic_labor_cost as lc on lc.id=lcl.labor_cost_id
|
||||
left join clinic_cycle_item as cit on cit.id=lc.cycle_item_id
|
||||
where cit.state='validated'
|
||||
'''
|
||||
dom_txt=''
|
||||
for f,op,v in dom:
|
||||
dom_txt+=' and %s %s %s'%(f,op,v)
|
||||
if dom_txt:
|
||||
sql+=dom_txt
|
||||
#sql+='order by department_id.name'
|
||||
lcl_ids=[r['id'] for r in db.query(sql)]
|
||||
ddata={}
|
||||
ndata={}
|
||||
ctdata={}
|
||||
for line in get_model('clinic.labor.cost.line').search_browse(dom,order="department_id.name"):
|
||||
t2=datetime.now()
|
||||
print('time3 ',t2-t1)
|
||||
for line in get_model('clinic.labor.cost.line').browse(lcl_ids):
|
||||
cost_id=line.labor_cost_id
|
||||
categ=line.categ_id
|
||||
categ_name=categ.name or "unknow"
|
||||
|
@ -213,6 +238,8 @@ class ReportLaborCost(Model):
|
|||
if hdcase.state in ('waiting_payment','paid'):
|
||||
ndata[dpt_name]['hdcases'].update({hdcase.id})
|
||||
total_amount=0
|
||||
t2=datetime.now()
|
||||
print('time4 ',t2-t1)
|
||||
for categ_name,vals in ctdata.items():
|
||||
amount=vals['amount'] or 0
|
||||
categ_id=vals['categ_id']
|
||||
|
@ -378,6 +405,8 @@ class ReportLaborCost(Model):
|
|||
line['amount']=con2float(line['amount'])
|
||||
return lines
|
||||
|
||||
t2=datetime.now()
|
||||
print('time5 ',t2-t1)
|
||||
data={
|
||||
'company_name': '%s %s' % (company.name or "", sub_name),
|
||||
'date': date,
|
||||
|
|
|
@ -17,7 +17,7 @@ class Shop(Model):
|
|||
shop_categs=[x.id for x in st.shop_categs]
|
||||
for obj in self.browse(ids):
|
||||
sub_total=0
|
||||
tax_amount=0 #XXX
|
||||
tax_amount=0
|
||||
for line in obj.lines:
|
||||
amt=line.amount or 0
|
||||
sub_total+=amt
|
||||
|
|
|
@ -1,2 +1,22 @@
|
|||
- show log for each model that use _log=True
|
||||
- create report patient cycle setting -> link to patient to change cycle setting
|
||||
|
||||
-----
|
||||
- move patient to another location
|
||||
- dispose
|
||||
- copy patient to location_to
|
||||
-if location_to == location_from
|
||||
- update same
|
||||
- go to the list view
|
||||
- shold be dispear
|
||||
====
|
||||
ตารางประวัติการรักษาผู้ป่วย
|
||||
- record
|
||||
- dispose (archive)
|
||||
- resign
|
||||
- report
|
||||
- hd.case.summary.detail
|
||||
find dispose
|
||||
====
|
||||
|
||||
-----
|
||||
|
|
Loading…
Reference in New Issue