clinic/netforce_clinic/models/hd_case_dialy.py

94 lines
2.8 KiB
Python
Raw Normal View History

2014-11-21 17:31:10 +00:00
import time
import urllib.parse as urllib
from datetime import datetime
from calendar import monthrange
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.dialy"
_string="HD Case Dialy"
_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=[]
2014-11-25 05:24:51 +00:00
2014-11-21 17:31:10 +00:00
for obj in get_model("clinic.hd.case").search_browse(dom):
patient_type=utils.PATIENT_TYPE[obj.patient_id.type]
dlz_number=""
dlz_id=None
for line in obj.dialyzers:
dlz=line.dialyzer_id
dlz_id=dlz.id
dlz_number=dlz.number
2014-11-25 01:41:49 +00:00
cycle=obj.cycle_id
2014-11-21 17:31:10 +00:00
line={
2014-11-25 01:41:49 +00:00
'cycle_name': cycle.name,
'cycle_sequence': cycle.sequence,
'cycle_color': cycle.color or "",
2014-11-21 17:31:10 +00:00
'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 "",
2014-11-25 05:24:51 +00:00
'last': False,
2014-11-21 17:31:10 +00:00
}
lines.append(line)
2014-11-25 05:24:51 +00:00
2014-11-21 17:31:10 +00:00
year=int(year)+543
date_str='%s %s %s'%(day,month_str,year)
2014-11-22 05:44:41 +00:00
no=1
2014-11-25 05:24:51 +00:00
slines=[]
cycles=[]
2014-11-22 05:44:41 +00:00
for line in sorted(lines,key=lambda x: (x['cycle_sequence'],x['hd_case_number'])):
line['no']=no
slines.append(line)
no+=1
2014-11-25 05:24:51 +00:00
# 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
2014-11-21 17:31:10 +00:00
data={
2014-11-22 05:44:41 +00:00
'lines': slines,
2014-11-21 17:31:10 +00:00
'date': date_str,
'company_name': company.name,
'company_parent_name': company.parent_id.name,
}
return data
HDCaseDialy.register()