clinic/netforce_clinic/models/report_hd_summary.py

146 lines
4.8 KiB
Python

import time
from datetime import datetime
from calendar import monthrange
from netforce.model import Model, fields, get_model
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={}):
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")
patients=get_model("clinic.patient").search_browse(['type','=','All'])
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'])
new_patients=len(patients)
time_start='2014-%s-01'%(month) # 2014-10-20
time_stop='2014-%s-%s'%(month,total_day)
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))
lines=[
{
'topic': 'The number of times the Hemodialysis',
'month': month_str,
'amount': cur_total_case,
'date_from': time_start,
'date_to': time_stop,
},
{
'topic':'The number of cases brought',
'month': previous_month_str,
'amount': prev_total_case,
'date_from': time_start_pre,
'date_to': time_stop_pre,
},
{
'topic':'Number of new patients',
'month': month_str,
'amount': new_patients,
'date_from': time_start,
'date_to': time_stop,
},
{
'topic':'Number of patients discharged',
'month': month_str,
'amount': 'N/A',
'date_from': time_start,
'date_to': time_stop,
},
{
'topic':'The number of cases brought',
'month': next_month_str,
'amount': 0,
'date_from': time_start,
'date_to': time_stop,
},
{
'topic':'Number of patients withdrawn Social Security',
'month': '',
'amount': len(patients_sc),
'date_from': "",
'date_to': "",
},
{
'topic':'Number of patients withdrawn Medical Government',
'month':'',
'amount': len(patients_mg),
'date_from': "",
'date_to': "",
},
{
'topic':'Number of patients withdrawn NHSO(30B)',
'month':'',
'amount': len(patients_nhso),
'date_from': "",
'date_to': "",
},
{
'topic':'Many patients pay themselves',
'month': '',
'amount': len(patients_pn),
'date_from': "",
'date_to': "",
},
]
data={
'month': month_str,
'year': year,
'lines': lines,
}
#print("data", data)
return data
ReportHDSummary.register()