clinic/netforce_clinic/models/report_hd_detail.py

164 lines
5.3 KiB
Python

import time
from netforce.model import Model, fields, get_model
#from netforce.access import get_active_company
class ReportHDDetail(Model):
_name="clinic.report.hd.detail"
_string="Hemodialysis Report Detail"
_transient=True
_fields={
"patient_id" : fields.Many2One("clinic.patient","Patient"),
"doctor_id" : fields.Many2One("clinic.doctor","Doctor"),
"nurse_id" : fields.Many2One("clinic.nurse","Nurse"),
"date_from": fields.Date("From"),
"date_to": fields.Date("To"),
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
}
_defaults={
'date_from': lambda *a: time.strftime("%Y-%m-%d"),
'date_to': lambda *a: time.strftime("%Y-%m-%d"),
}
_order="cycle_id desc"
def get_report_data(self,ids,context={}):
# company_id=get_active_company
# comp=get_model("company").browse(company_id)
# context=> dict
# inside context => keys => defaults => type => dict
# dict => key: value => '', 1, [], {}
# context['default'] => defaults(dict) => key => inside key => value => '2014-10-22'
for item in get_model("company").search_browse([]):
company_name=item.name
date_from=time.strftime("%Y-%m-%d")
date_to=time.strftime("%Y-%m-%d")
# print('date_from ',date_from)
defaults=context.get("defaults")
if defaults:
if defaults.get("date_from"):
date_from=defaults['date_from']
if defaults.get("date_to"):
date_to=defaults['date_to']
# date_to=context['date_to']
# default => key => dataults
# date_from=context['date_from']
# print(context['date_from'])
#'2014-10-13'
# print('date_from ',date_from)
# print('date_to ',date_to)
PATIENT_TYPE={
"mg":"Medical Government",
"sc":"Social Security",
"nhso":"NHSO (30฿)",
"personal": "Personal",
"others": "Others",
}
dom=[]
dom.append(['state','=','completed'])
if ids:
obj=self.browse(ids)[0]
if obj.date_from:
date_from=obj.date_from
if obj.date_to:
date_to=obj.date_to
if obj.cycle_id:
dom.append([
'cycle_id','=',obj.cycle_id.id,
])
if obj.patient_id:
dom.append([
'patient_id','=',obj.patient_id.id,
])
if obj.nurse_id:
dom.append([
'nurse_id','=',obj.nurse_id.id,
])
if obj.doctor_id:
dom.append([
'doctor_id','=',obj.doctor_id.id,
])
dom.append(['time_start', ">=", date_from+" 00:00:00"])
dom.append(['time_stop',"<=", date_to+" 23:59:59"])
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)
#dialyzer_name=hd_case.dialyzers.id
#dialyzer_name=DIALYZER_NAME.get(dialyzer_name)
cycle_name=hd_case.cycle_id.name or ""
show_cycle=False
if not cycle_name in cycles:
cycles.append(cycle_name)
show_cycle=True
vals={
'color': 'success',
'show_cycle': False,
'cycle' : "",
'patient': "",
'no_patient': no_patient,
'patient_type' : "",
'doctor' : "",
'total' : "",
'rc_no' : "",
'dialyzer_name' : "",
'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.total,
'rc_no' : hd_case.number,
'dialyzer_name' : 'DZ-xxx',
'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' : "",
'dialyzer_name' : "",
'nurse' : "",
}
lines.append(vals)
#XXX
del lines[0]
data={
'lines': lines,
'same_date': date_from==date_to,
'date_from': date_from,
'date_to': date_to,
'company_name': company_name,
}
return data
ReportHDDetail.register()