91 lines
2.8 KiB
Python
91 lines
2.8 KiB
Python
|
import time
|
||
|
|
||
|
from datetime import datetime
|
||
|
from netforce.model import Model, fields, get_model
|
||
|
from netforce.access import get_active_company
|
||
|
|
||
|
from . import utils
|
||
|
|
||
|
class HDCaseDialy(Model):
|
||
|
_name="clinic.hd.case.daily"
|
||
|
_string="HD Case Daily"
|
||
|
_transient=True
|
||
|
|
||
|
_fields={
|
||
|
"date": fields.Date("Date", required=True),
|
||
|
}
|
||
|
|
||
|
_defaults={
|
||
|
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
||
|
}
|
||
|
|
||
|
def get_report_data(self,ids,context={}):
|
||
|
company_id=get_active_company()
|
||
|
company=get_model("company").browse(company_id)
|
||
|
|
||
|
date=datetime.now().strftime("%Y-%m-%d")
|
||
|
if ids:
|
||
|
obj=self.browse(ids)[0]
|
||
|
date=obj.date
|
||
|
month=int(date[5:7])
|
||
|
day=date[8:10]
|
||
|
year=date[0:4]
|
||
|
month_str=utils.MONTHS['th_TH'][month]
|
||
|
dom=[]
|
||
|
dom.append(['time_start','>=','%s 00:00:00'%date])
|
||
|
dom.append(['time_stop','<=','%s 23:59:59'%date])
|
||
|
lines=[]
|
||
|
|
||
|
for obj in get_model("clinic.hd.case").search_browse(dom):
|
||
|
patient_type=obj.patient_id.type_id.name or ""
|
||
|
dlz_number=""
|
||
|
dlz_id=None
|
||
|
for line in obj.dialyzers:
|
||
|
dlz=line.dialyzer_id
|
||
|
dlz_id=dlz.id
|
||
|
dlz_number=dlz.number
|
||
|
cycle=obj.cycle_id
|
||
|
line={
|
||
|
'cycle_name': cycle.name,
|
||
|
'cycle_sequence': cycle.sequence,
|
||
|
'cycle_color': cycle.color or "",
|
||
|
'hd_case_number': obj.number,
|
||
|
'patient_name': obj.patient_id.name,
|
||
|
'patient_type': patient_type,
|
||
|
'doctor_name': obj.doctor_id.name,
|
||
|
'doctor_id': obj.doctor_id.id,
|
||
|
'fee_amount': obj.fee_amount,
|
||
|
'hd_case_id': obj.id,
|
||
|
'dlz_number': dlz_number,
|
||
|
'dlz_id': dlz_id,
|
||
|
'success_color': obj.state=='completed' and '#99ff99' or '',
|
||
|
'note': obj.note or "",
|
||
|
'last': False,
|
||
|
}
|
||
|
lines.append(line)
|
||
|
|
||
|
year=int(year)+543
|
||
|
date_str='%s %s %s'%(day,month_str,year)
|
||
|
|
||
|
no=1
|
||
|
slines=[]
|
||
|
for line in sorted(lines,key=lambda x: (x['cycle_sequence'],x['hd_case_number'])):
|
||
|
line['no']=no
|
||
|
slines.append(line)
|
||
|
no+=1
|
||
|
|
||
|
# find all nurse for each cycle
|
||
|
items=get_model("clinic.cycle.item").search_browse([['date','=',date]])
|
||
|
for item in sorted(items,key=lambda x: x.cycle_id.sequence):
|
||
|
pass
|
||
|
|
||
|
data={
|
||
|
'lines': slines,
|
||
|
'date': date_str,
|
||
|
'company_name': company.name,
|
||
|
'company_parent_name': company.parent_id.name,
|
||
|
}
|
||
|
return data
|
||
|
|
||
|
HDCaseDialy.register()
|