clinic/netforce_clinic/models/report_hd_monthly.py

118 lines
3.6 KiB
Python

import time
from datetime import datetime
from calendar import monthrange
from netforce.model import Model, fields, get_model
class ReportHDMonthly(Model):
_name="clinic.report.hd.monthly"
_string="Report HD Monthly"
_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")
datemonth=datetime.now().strftime("%m")
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")
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)
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)
dom=[]
dom.append(['state','=','completed'])
dom.append(['time_start','>=',time_start])
dom.append(['time_stop','<=',time_stop])
hd_cases=get_model("clinic.hd.case").search_browse(dom)
lines=[
{
'topic': 'The number of times the Hemodialysis',
'month': month_str,
'amount': len(hd_cases),
},
{
'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),
},
]
data={
'month': month_str,
'year': year,
'lines': lines,
}
return data
ReportHDMonthly.register()