clinic/netforce_clinic/models/report_hd_summary.py

164 lines
5.1 KiB
Python
Raw Normal View History

2014-10-20 09:03:17 +00:00
import time
from datetime import datetime
from calendar import monthrange
from netforce.model import Model, fields, get_model
2014-10-21 11:22:48 +00:00
#from netforce.access import get_active_company
2014-10-20 09:03:17 +00:00
class ReportHDSummary(Model):
_name="clinic.report.hd.summary"
_string="Hemodialysis Report Summary"
_transient=True
_fields={
"date": fields.Date("Month", required=True),
}
_defaults={
2014-10-21 11:22:48 +00:00
'date': lambda *a: time.strftime("%Y-%m-%d"),
2014-10-20 09:03:17 +00:00
}
def get_report_data(self,ids,context={}):
2014-10-21 11:22:48 +00:00
# company_id=get_active_company
# company_name=get_model("company").search("name")
# company_name=get_model("company").search_browse()
for item in get_model("company").search_browse([]):
company_name=item.name
2014-10-20 09:03:17 +00:00
date=datetime.now().strftime("%Y-%m-%d")
dom=[]
if ids:
obj=self.browse(ids)[0]
date=obj.date
month=int(date[5:7])
year=int(date[0:4])
weekday, total_day=monthrange(year, month)
#date_from="%s-%s-01"%(year,month)
#date_to="%s-%s-%s"%(year,month,total_day)
month_str=datetime.strptime(date,'%Y-%m-%d').strftime("%B")
next_month = str(month + 1)
if next_month == 13:
next_month = 12
next_month_str=datetime.strptime(next_month,'%m').strftime("%B")
previous_month = month-1
if previous_month == 0:
previous_month = 12
#tip previous_month=str(month-1 == 0 and 12 or month)
previous_month_str=datetime.strptime('%s'%previous_month,'%m').strftime("%B")
2014-10-21 11:22:48 +00:00
2014-10-20 09:03:17 +00:00
time_start='2014-%s-01'%(month) # 2014-10-20
time_stop='2014-%s-%s'%(month,total_day)
2014-10-20 11:48:39 +00:00
dom=[]
dom.append(['time_start','>=',time_start])
dom.append(['time_stop','<=',time_stop])
patients=get_model("clinic.patient").search_browse(['type','=','All'])
new_patients=len(patients)
2014-10-21 11:22:48 +00:00
2014-10-20 11:48:39 +00:00
patients_mg=get_model("clinic.patient").search_browse(['type','=','mg'])
patients_sc=get_model("clinic.patient").search_browse(['type','=','sc'])
patients_nhso=get_model("clinic.patient").search_browse(['type','=','nhso'])
patients_pn=get_model("clinic.patient").search_browse(['type','=','personal'])
2014-10-21 11:22:48 +00:00
2014-10-20 09:03:17 +00:00
dom=[]
dom.append(['state','=','completed'])
dom.append(['time_start','>=',time_start])
dom.append(['time_stop','<=',time_stop])
cur_total_case=len(get_model("clinic.hd.case").search(dom))
2014-10-20 11:48:39 +00:00
2014-10-20 09:03:17 +00:00
weekday, prev_total_day=monthrange(year, previous_month)
time_start_pre='2014-%s-01'%(previous_month) # 2014-10-20
time_stop_pre='2014-%s-%s'%(previous_month,prev_total_day)
2014-10-20 11:48:39 +00:00
2014-10-21 11:22:48 +00:00
dom=[]
2014-10-20 09:03:17 +00:00
dom.append(['state','=','completed'])
dom.append(['time_start','>=',time_start_pre])
dom.append(['time_stop','<=',time_stop_pre])
prev_total_case=len(get_model("clinic.hd.case").search(dom))
2014-10-21 11:22:48 +00:00
items={
'topic1': {
2014-10-20 09:03:17 +00:00
'month': month_str,
'amount': cur_total_case,
'date_from': time_start,
'date_to': time_stop,
},
2014-10-21 11:22:48 +00:00
'topic2':
2014-10-20 09:03:17 +00:00
{
'month': previous_month_str,
'amount': prev_total_case,
'date_from': time_start_pre,
'date_to': time_stop_pre,
},
2014-10-21 11:22:48 +00:00
'topic3':
2014-10-20 09:03:17 +00:00
{
'month': month_str,
'amount': new_patients,
'date_from': time_start,
'date_to': time_stop,
},
2014-10-21 11:22:48 +00:00
'topic4':
2014-10-20 09:03:17 +00:00
{
'month': month_str,
'amount': 'N/A',
'date_from': time_start,
'date_to': time_stop,
},
2014-10-21 11:22:48 +00:00
'topic5':
2014-10-20 09:03:17 +00:00
{
'month': next_month_str,
2014-10-20 11:48:39 +00:00
'amount': 'N/A',
2014-10-20 09:03:17 +00:00
'date_from': time_start,
'date_to': time_stop,
},
2014-10-21 11:22:48 +00:00
'topic6':
2014-10-20 09:03:17 +00:00
{
'month': '',
'amount': len(patients_sc),
'date_from': "",
'date_to': "",
},
2014-10-21 11:22:48 +00:00
'topic7':
2014-10-20 09:03:17 +00:00
{
'month':'',
'amount': len(patients_mg),
'date_from': "",
'date_to': "",
},
2014-10-21 11:22:48 +00:00
'topic8':
2014-10-20 09:03:17 +00:00
{
'month':'',
'amount': len(patients_nhso),
'date_from': "",
'date_to': "",
},
2014-10-21 11:22:48 +00:00
'topic9':
2014-10-20 09:03:17 +00:00
{
'month': '',
'amount': len(patients_pn),
'date_from': "",
'date_to': "",
},
2014-10-21 11:22:48 +00:00
}
lines=[]
for item in get_model("clinic.translate").search_browse([]):
topic=item.org
line=items.get(topic,{})
line['topic']=item.tr
lines.append(line)
2014-10-20 09:03:17 +00:00
data={
'month': month_str,
'year': year,
'lines': lines,
2014-10-21 11:22:48 +00:00
'company_name': company_name,
2014-10-20 09:03:17 +00:00
}
2014-10-21 11:22:48 +00:00
print("data", data)
2014-10-20 09:03:17 +00:00
return data
2014-10-21 11:22:48 +00:00
2014-10-20 09:03:17 +00:00
ReportHDSummary.register()