2014-10-15 11:46:19 +00:00
|
|
|
import time
|
2014-10-16 11:45:32 +00:00
|
|
|
|
2014-10-15 12:39:21 +00:00
|
|
|
from datetime import datetime
|
|
|
|
from calendar import monthrange
|
2014-10-15 11:46:19 +00:00
|
|
|
|
2014-10-15 12:39:21 +00:00
|
|
|
from netforce.model import Model, fields, get_model
|
2014-10-15 11:46:19 +00:00
|
|
|
|
2014-10-15 15:55:38 +00:00
|
|
|
class ReportHDMonthly(Model):
|
|
|
|
_name="clinic.report.hd.monthly"
|
|
|
|
_string="Report HD Monthly"
|
2014-10-15 11:46:19 +00:00
|
|
|
_transient=True
|
|
|
|
|
|
|
|
_fields={
|
2014-10-15 12:39:21 +00:00
|
|
|
"date": fields.Date("Month", required=True),
|
2014-10-15 11:46:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_defaults={
|
|
|
|
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
|
|
|
}
|
|
|
|
|
|
|
|
def get_report_data(self,ids,context={}):
|
2014-10-15 15:21:17 +00:00
|
|
|
date=datetime.now().strftime("%Y-%m-%d")
|
2014-10-16 11:45:32 +00:00
|
|
|
datemonth=datetime.now().strftime("%m")
|
2014-10-15 15:21:17 +00:00
|
|
|
if ids:
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
date=obj.date
|
|
|
|
year=int(date[0:4])
|
|
|
|
month=int(date[5:7])
|
|
|
|
month_str=datetime.strptime(date,'%Y-%m-%d').strftime("%B")
|
2014-10-16 11:45:32 +00:00
|
|
|
next_month = str(month + 1)
|
|
|
|
if next_month == 13:
|
|
|
|
next_month = 12
|
|
|
|
next_month_str=datetime.strptime(next_month,'%m').strftime("%B")
|
|
|
|
|
|
|
|
previous_month = str(month - 1)
|
|
|
|
if previous_month == 0:
|
|
|
|
previous_month = 12
|
|
|
|
previous_month_str=datetime.strptime(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=0
|
|
|
|
if datemonth==month:
|
|
|
|
new_patients= len(patients)
|
|
|
|
|
2014-10-15 12:39:21 +00:00
|
|
|
weekday, total_day=monthrange(year, month)
|
|
|
|
time_start='2014-%s-01 00:00:00'%(month)
|
|
|
|
time_stop='2014-%s-%s 23:59:59'%(month,total_day)
|
2014-10-16 11:45:32 +00:00
|
|
|
|
2014-10-15 12:39:21 +00:00
|
|
|
dom=[]
|
|
|
|
dom.append(['state','=','completed'])
|
|
|
|
dom.append(['time_start','>=',time_start])
|
|
|
|
dom.append(['time_stop','<=',time_stop])
|
2014-10-16 11:45:32 +00:00
|
|
|
|
2014-10-15 12:39:21 +00:00
|
|
|
hd_cases=get_model("clinic.hd.case").search_browse(dom)
|
2014-10-16 11:45:32 +00:00
|
|
|
|
|
|
|
lines=[
|
|
|
|
{
|
2014-10-15 12:39:21 +00:00
|
|
|
'topic': 'The number of times the Hemodialysis',
|
|
|
|
'month': month_str,
|
|
|
|
'amount': len(hd_cases),
|
2014-10-16 11:45:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
'topic':'The number of cases brought',
|
|
|
|
'month': previous_month_str,
|
|
|
|
'amount': 'N/A',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'topic':'Number of new patients',
|
|
|
|
'month': month_str,
|
|
|
|
'amount': new_patients,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'topic':'Number of patients discharged',
|
|
|
|
'month': month_str,
|
|
|
|
'amount': 'N/A',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'topic':'The number of cases brought',
|
|
|
|
'month': next_month_str,
|
|
|
|
'amount': 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'topic':'Number of patients withdrawn Social Security',
|
|
|
|
'month': '',
|
|
|
|
'amount': len(patients_sc),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'topic':'Number of patients withdrawn Medical Government',
|
|
|
|
'month':'',
|
|
|
|
'amount': len(patients_mg),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'topic':'Number of patients withdrawn NHSO(30B)',
|
|
|
|
'month':'',
|
|
|
|
'amount': len(patients_nhso),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'topic':'Many patients pay themselves',
|
|
|
|
'month': '',
|
|
|
|
'amount': len(patients_pn),
|
|
|
|
},
|
|
|
|
]
|
2014-10-15 12:39:21 +00:00
|
|
|
|
|
|
|
data={
|
2014-10-15 15:21:17 +00:00
|
|
|
'month': month_str,
|
|
|
|
'year': year,
|
2014-10-15 12:39:21 +00:00
|
|
|
'lines': lines,
|
|
|
|
}
|
2014-10-15 11:46:19 +00:00
|
|
|
return data
|
|
|
|
|
2014-10-15 15:55:38 +00:00
|
|
|
ReportHDMonthly.register()
|