clinic/netforce_clinic/models/report_hd.py

109 lines
3.2 KiB
Python

import time
from netforce.model import Model, fields, get_model
class HDReport(Model):
_name="clinic.hd.report"
_string="HD Report"
_transient=True
_fields={
"date": fields.Date("Date"),
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
}
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"),
}
_order="cycle_id desc"
def get_report_data(self,ids,context={}):
PATIENT_TYPE={
"mg":"Medical Government",
"sc":"Social Security",
"nhso":"NHSO (30฿)",
"personal": "Personal",
"others": "Others",
}
date=time.strftime("%Y-%m-%d")
dom=[]
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,
])
dom.append(['time_start', ">=", date+" 00:00:00"])
dom.append(['time_stop', "<=", date+" 23:59:59"])
print("dom ", dom)
lines=[]
cycles=[]
index=0
no_patient=0
for hd_case in get_model("clinic.hd.case").search_browse(dom,order="cycle_id.sequence"):
patient_type=hd_case.patient_id.type
patient_type=PATIENT_TYPE.get(patient_type)
cycle_name=hd_case.cycle_id.name or ""
show_cycle=False
if not cycle_name in cycles:
cycles.append(cycle_name)
show_cycle=True
if index > 1:
vals={
'color': 'success',
'show_cycle': False,
'cycle' : "",
'patient': "",
'no_patient': no_patient,
'patient_type' : "",
'doctor' : "",
'total' : "",
'rc_no' : "",
'nurse' : "",
}
lines.append(vals)
no_patient=1
else:
no_patient+=1
index+=1
vals={
'show_cycle': show_cycle,
'cycle' : cycle_name,
'patient': hd_case.patient_id.name,
'patient_type' : patient_type,
'no_patient': 0,
'doctor' : hd_case.doctor_id.name,
'total' : hd_case.fee,
'rc_no' : hd_case.number,
'nurse' : hd_case.nurse_id.name,
}
lines.append(vals)
# XXX
if lines:
vals={
'color': 'success',
'show_cycle': False,
'cycle' : "",
'patient': "",
'no_patient': no_patient,
'patient_type' : "",
'doctor' : "",
'total' : "",
'rc_no' : "",
'nurse' : "",
}
lines.append(vals)
data={
'lines': lines,
}
return data
HDReport.register()