clinic/netforce_clinic/models/report_hd.py

132 lines
4.2 KiB
Python
Raw Normal View History

2014-10-09 10:53:01 +00:00
import time
from netforce.model import Model, fields, get_model
2014-10-09 10:53:01 +00:00
class HDReport(Model):
_name="clinic.hd.report"
_string="HD Report"
_transient=True
_fields={
2014-10-14 11:42:21 +00:00
"date": fields.Date("Start-Date"),
2014-10-15 11:46:19 +00:00
"patient_id" : fields.Many2One("clinic.patient","Patient"),
"doctor_id" : fields.Many2One("clinic.doctor","Doctor"),
"nurse_id" : fields.Many2One("clinic.nurse","Nurse"),
2014-10-14 11:42:21 +00:00
#"time_start": fields.DateTime("Time start",required=False,search=True),
#"time_stop": fields.DateTime("Time stop",required=False,search=True),
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
2014-10-09 10:53:01 +00:00
}
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"),
2014-10-14 11:42:21 +00:00
#'time_start': lambda *a: time.strftime("%Y-%m-%d"),
#'time_stop': lambda *a: time.strftime("%Y-%m-%d"),
2014-10-09 10:53:01 +00:00
}
_order="cycle_id desc"
2014-10-09 10:53:01 +00:00
2014-10-14 07:13:59 +00:00
2014-10-15 11:46:19 +00:00
def get_report_data(self,ids,context={}):
2014-10-14 04:36:29 +00:00
PATIENT_TYPE={
"mg":"Medical Government",
"sc":"Social Security",
"nhso":"NHSO (30฿)",
"personal": "Personal",
"others": "Others",
}
2014-10-14 11:42:21 +00:00
#time_start=time.strftime("%Y-%m-%d")
#time_stop=time.strftime("%Y-%m-%d")
2014-10-14 07:07:37 +00:00
date=time.strftime("%Y-%m-%d")
2014-10-14 04:36:29 +00:00
dom=[]
2014-10-14 07:07:37 +00:00
dom.append(['state','=','completed'])
if ids:
obj=self.browse(ids)[0]
if obj.date:
date=obj.date
if obj.cycle_id:
dom.append([
'cycle_id','=',obj.cycle_id.id,
])
2014-10-15 11:46:19 +00:00
if obj.patient_id:
dom.append([
'patient_id','=',obj.patient_id.id,
])
if obj.doctor_id:
dom.append([
'doctor_id','=',obj.doctor_id.id,
])
2014-10-14 07:07:37 +00:00
dom.append(['time_start', ">=", date+" 00:00:00"])
2014-10-15 11:46:19 +00:00
dom.append(['time_stop',"<=", date+" 23:59:59"])
lines=[]
2014-10-14 07:07:37 +00:00
cycles=[]
index=0
no_patient=0
for hd_case in get_model("clinic.hd.case").search_browse(dom,order="cycle_id.sequence"):
2014-10-14 04:36:29 +00:00
patient_type=hd_case.patient_id.type
patient_type=PATIENT_TYPE.get(patient_type)
2014-10-14 11:42:21 +00:00
#dialyzer_name=hd_case.dialyzers.id
#dialyzer_name=DIALYZER_NAME.get(dialyzer_name)
2014-10-14 07:07:37 +00:00
cycle_name=hd_case.cycle_id.name or ""
show_cycle=False
if not cycle_name in cycles:
cycles.append(cycle_name)
show_cycle=True
2014-10-14 11:42:21 +00:00
print("OK")
vals={
'color': 'success',
'show_cycle': False,
'cycle' : "",
'patient': "",
'no_patient': no_patient,
'patient_type' : "",
'doctor' : "",
'total' : "",
'rc_no' : "",
'dialyzer_name' : "",
'nurse' : "",
}
lines.append(vals)
2014-10-14 07:07:37 +00:00
no_patient=1
else:
no_patient+=1
index+=1
vals={
'show_cycle': show_cycle,
'cycle' : cycle_name,
2014-10-14 04:36:29 +00:00
'patient': hd_case.patient_id.name,
'patient_type' : patient_type,
2014-10-14 07:07:37 +00:00
'no_patient': 0,
2014-10-14 04:36:29 +00:00
'doctor' : hd_case.doctor_id.name,
'total' : hd_case.fee,
'rc_no' : hd_case.number,
2014-10-14 11:42:21 +00:00
'dialyzer_name' : 'DZ-xxx',
2014-10-14 04:36:29 +00:00
'nurse' : hd_case.nurse_id.name,
2014-10-14 07:07:37 +00:00
}
lines.append(vals)
2014-10-14 07:07:37 +00:00
# XXX
if lines:
vals={
'color': 'success',
'show_cycle': False,
'cycle' : "",
'patient': "",
'no_patient': no_patient,
'patient_type' : "",
'doctor' : "",
'total' : "",
'rc_no' : "",
2014-10-14 11:42:21 +00:00
'dialyzer_name' : "",
2014-10-14 07:07:37 +00:00
'nurse' : "",
}
lines.append(vals)
2014-10-14 11:42:21 +00:00
#XXX
del lines[0]
2014-10-09 10:53:01 +00:00
data={
'lines': lines,
2014-10-09 10:53:01 +00:00
}
return data
HDReport.register()