clinic/netforce_clinic/models/report_hd.py

64 lines
1.7 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={}):
obj=self.browse(ids)[0]
lines=[]
PATIENT_TYPE={
"mg":"Medical Government",
"sc":"Social Security",
"nhso":"NHSO (30฿)",
"personal": "Personal",
"others": "Others",
}
dom=[]
dom.append([
'state','=','completed',
])
if obj.cycle_id:
dom.append([
'cycle_id','=',obj.cycle_id.id,
])
if obj.date:
dom.append(['time_start', ">=", obj.date+" 00:00:00"])
dom.append(['time_stop', "<=", obj.date+" 23:59:59"])
print("dom ", dom)
for hd_case in get_model("clinic.hd.case").search_browse(dom):
patient_type=hd_case.patient_id.type
patient_type=PATIENT_TYPE.get(patient_type)
lines.append({
'cycle' : hd_case.cycle_id.name,
'patient': hd_case.patient_id.name,
'patient_type' : patient_type,
'doctor' : hd_case.doctor_id.name,
'total' : hd_case.fee,
'rc_no' : hd_case.number,
'nurse' : hd_case.nurse_id.name,
})
data={
'lines': lines,
}
return data
HDReport.register()