171 lines
5.4 KiB
Python
171 lines
5.4 KiB
Python
import time
|
|
|
|
from datetime import datetime
|
|
from calendar import monthrange
|
|
from netforce.model import Model, fields, get_model
|
|
#from netforce.access import get_active_company
|
|
|
|
class ReportHDSummary(Model):
|
|
_name="clinic.report.hd.summary"
|
|
_string="Hemodialysis Report Summary"
|
|
_transient=True
|
|
|
|
_fields={
|
|
"date": fields.Date("Month", required=True),
|
|
}
|
|
|
|
_defaults={
|
|
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
|
}
|
|
|
|
def get_report_data(self,ids,context={}):
|
|
# 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
|
|
|
|
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")
|
|
|
|
time_start='2014-%s-01'%(month) # 2014-10-20
|
|
time_stop='2014-%s-%s'%(month,total_day)
|
|
|
|
dom=[]
|
|
dom.append(['time_start','>=',time_start])
|
|
dom.append(['time_stop','<=',time_stop])
|
|
|
|
dom=[]
|
|
dom.append(['type','=','mg'])
|
|
patients_mg=len(get_model("clinic.patient").search(dom))
|
|
dom.append(['type','=','sc'])
|
|
patients_sc=len(get_model("clinic.patient").search(dom))
|
|
dom.append(['type','=','nhso'])
|
|
patients_nhso=len(get_model("clinic.patient").search(dom))
|
|
dom.append(['type','=','nhso'])
|
|
patients_nhso=len(get_model("clinic.patient").search(dom))
|
|
dom.append(['type','=','pn'])
|
|
patients_pn=len(get_model("clinic.patient").search(dom))
|
|
|
|
patients=len(get_model("clinic.patient").search_browse(['type','=','All']))
|
|
#new_patients=len(patients)
|
|
|
|
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))
|
|
|
|
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)
|
|
|
|
dom=[]
|
|
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))
|
|
items={
|
|
'topic1': {
|
|
'month': month_str,
|
|
'amount': cur_total_case,
|
|
'date_from': time_start,
|
|
'date_to': time_stop,
|
|
},
|
|
'topic2':
|
|
{
|
|
'month': previous_month_str,
|
|
'amount': prev_total_case,
|
|
'date_from': time_start_pre,
|
|
'date_to': time_stop_pre,
|
|
},
|
|
'topic3':
|
|
{
|
|
'month': month_str,
|
|
'amount': patients,
|
|
'date_from': time_start,
|
|
'date_to': time_stop,
|
|
},
|
|
'topic4':
|
|
{
|
|
'month': month_str,
|
|
'amount': 'N/A',
|
|
'date_from': time_start,
|
|
'date_to': time_stop,
|
|
},
|
|
'topic5':
|
|
{
|
|
'month': next_month_str,
|
|
'amount': 'N/A',
|
|
'date_from': time_start,
|
|
'date_to': time_stop,
|
|
},
|
|
'topic6':
|
|
{
|
|
'month': '',
|
|
'amount': patients_sc,
|
|
'date_from': time_start,
|
|
'date_to': time_stop,
|
|
},
|
|
'topic7':
|
|
{
|
|
'month':'',
|
|
'amount': patients_mg,
|
|
'date_from': time_start,
|
|
'date_to': time_stop,
|
|
},
|
|
'topic8':
|
|
{
|
|
'month':'',
|
|
'amount': patients_nhso,
|
|
'date_from': time_start,
|
|
'date_to': time_stop,
|
|
},
|
|
'topic9':
|
|
{
|
|
'month': '',
|
|
'amount': patients_pn,
|
|
'date_from': time_start,
|
|
'date_to': time_stop,
|
|
},
|
|
}
|
|
|
|
lines=[]
|
|
for item in get_model("clinic.translate").search_browse([]):
|
|
topic=item.org
|
|
line=items.get(topic,{})
|
|
line['topic']=item.tr
|
|
lines.append(line)
|
|
|
|
data={
|
|
'month': month_str,
|
|
'year': year,
|
|
'lines': lines,
|
|
'company_name': company_name,
|
|
}
|
|
print("data", data)
|
|
return data
|
|
|
|
|
|
ReportHDSummary.register()
|