2014-11-05 06:45:28 +00:00
|
|
|
import time
|
2014-11-10 11:33:01 +00:00
|
|
|
from calendar import monthrange
|
2014-11-05 06:45:28 +00:00
|
|
|
|
|
|
|
from netforce.model import Model,fields,get_model
|
2014-11-05 07:03:12 +00:00
|
|
|
from netforce.access import get_active_company
|
2014-11-05 06:45:28 +00:00
|
|
|
|
2014-11-10 11:33:01 +00:00
|
|
|
from . import utils
|
|
|
|
|
2014-11-13 04:16:25 +00:00
|
|
|
class ReportRecentPatient(Model):
|
|
|
|
_name="clinic.report.recent.patient"
|
|
|
|
_string="Report Recent Patient"
|
2014-11-05 06:45:28 +00:00
|
|
|
_transient=True
|
|
|
|
|
|
|
|
_fields={
|
2014-11-12 11:13:23 +00:00
|
|
|
"date": fields.Date("Month"),
|
|
|
|
"date_from": fields.Date("From", required=True),
|
|
|
|
"date_to": fields.Date("To", required=True),
|
2014-11-05 06:45:28 +00:00
|
|
|
}
|
|
|
|
|
2014-11-12 11:13:23 +00:00
|
|
|
def _get_date_from(self,context={}):
|
|
|
|
year,month=time.strftime("%Y-%m").split("-")
|
|
|
|
return '%s-%s-01'%(year,month)
|
|
|
|
|
|
|
|
def _get_date_to(self,context={}):
|
|
|
|
year,month,day=time.strftime("%Y-%m-%d").split("-")
|
|
|
|
weekday, total_day=monthrange(int(year), int(month))
|
|
|
|
return "%s-%s-%s"%(year,month,total_day)
|
|
|
|
|
2014-11-05 06:45:28 +00:00
|
|
|
_defaults={
|
|
|
|
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
2014-11-12 11:13:23 +00:00
|
|
|
'date_from': _get_date_from,
|
|
|
|
'date_to': _get_date_to,
|
2014-11-05 06:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def get_report_data(self,ids,context={}):
|
2014-11-05 07:03:12 +00:00
|
|
|
company_id=get_active_company()
|
|
|
|
company=get_model('company').browse(company_id)
|
2014-11-10 11:33:01 +00:00
|
|
|
year, month=time.strftime("%Y-%m").split("-")
|
2014-11-12 11:13:23 +00:00
|
|
|
weekday, total_day=monthrange(int(year), int(month))
|
|
|
|
time_start='%s-%s-01'%(year,str(month).zfill(2))
|
|
|
|
time_stop='%s-%s-%s'%(year,str(month).zfill(2),total_day)
|
2014-11-10 14:52:47 +00:00
|
|
|
|
|
|
|
defaults=context.get('defaults')
|
|
|
|
if defaults:
|
|
|
|
year,month,day=defaults['date'].split("-")
|
2014-12-02 12:54:10 +00:00
|
|
|
# XXX
|
|
|
|
weekday, total_day=monthrange(int(year), int(month))
|
2014-11-12 11:13:23 +00:00
|
|
|
time_start='%s-%s-01'%(year,str(month).zfill(2))
|
|
|
|
time_stop='%s-%s-%s'%(year,str(month).zfill(2),total_day)
|
2014-11-10 11:33:01 +00:00
|
|
|
if ids:
|
|
|
|
obj=self.browse(ids)[0]
|
2014-11-12 11:13:23 +00:00
|
|
|
month=obj.date_from.split("-")[1]
|
|
|
|
time_start=obj.date_from
|
|
|
|
time_stop=obj.date_to
|
2014-11-10 11:33:01 +00:00
|
|
|
# new patient of this month
|
|
|
|
dom=[]
|
|
|
|
dom.append(['reg_date','>=',time_start])
|
|
|
|
dom.append(['reg_date','<=',time_stop])
|
|
|
|
records=get_model('clinic.patient').search_browse(dom)
|
|
|
|
lines=[]
|
|
|
|
no=1
|
|
|
|
for record in records:
|
|
|
|
lines.append({
|
|
|
|
'no': no,
|
|
|
|
'name': record.name or '',
|
|
|
|
'pid': record.id,
|
|
|
|
'note': record.note or '',
|
2014-11-12 11:13:23 +00:00
|
|
|
'reg_date': record.reg_date,
|
2014-11-10 11:33:01 +00:00
|
|
|
})
|
|
|
|
no+=1
|
|
|
|
|
2014-11-12 11:13:23 +00:00
|
|
|
month_str=utils.MONTHS['th_TH'][int(month)]
|
|
|
|
start=int(time_start[8:10])
|
|
|
|
stop=int(time_stop[8:10])
|
|
|
|
diff=stop-start
|
2014-11-05 07:03:12 +00:00
|
|
|
data={
|
|
|
|
'company_name': company.name or "",
|
|
|
|
'parent_company_name': company.parent_id.name or "",
|
2014-11-10 11:33:01 +00:00
|
|
|
'lines': lines,
|
|
|
|
'month': month_str,
|
2014-11-12 11:13:23 +00:00
|
|
|
'from': time_start,
|
|
|
|
'to': time_stop,
|
|
|
|
'is_duration': diff+1 < total_day,
|
2014-11-10 11:33:01 +00:00
|
|
|
'year': year,
|
2014-11-05 07:03:12 +00:00
|
|
|
}
|
2014-11-05 06:45:28 +00:00
|
|
|
return data
|
|
|
|
|
2014-11-12 11:13:23 +00:00
|
|
|
def onchange_date(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
date=data['date']
|
|
|
|
year,month,day=date.split("-")
|
|
|
|
weekday, total_day=monthrange(int(year), int(month))
|
|
|
|
data['date_from']="%s-%s-01"%(year,month)
|
|
|
|
data['date_to']="%s-%s-%s"%(year,month,total_day)
|
|
|
|
return data
|
|
|
|
|
2014-11-13 04:16:25 +00:00
|
|
|
ReportRecentPatient.register()
|