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
|
2015-03-02 08:44:23 +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-05 06:45:28 +00:00
|
|
|
class ReportDiscontinuePatient(Model):
|
|
|
|
_name="clinic.report.discontinue.patient"
|
|
|
|
_string="Report Discontinue Patient"
|
|
|
|
_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),
|
2015-02-24 14:59:49 +00:00
|
|
|
"branch_id": fields.Many2One("clinic.branch","Branch"),
|
|
|
|
"department_id": fields.Many2One("clinic.department","Department"),
|
2014-11-05 06:45:28 +00:00
|
|
|
}
|
|
|
|
|
2015-02-24 14:59:49 +00:00
|
|
|
def default_get(self,field_names=None,context={},**kw):
|
|
|
|
defaults=context.get("defaults",{})
|
|
|
|
date=defaults.get('date',time.strftime("%Y-%m-%d"))
|
2014-11-12 11:13:23 +00:00
|
|
|
year,month=time.strftime("%Y-%m").split("-")
|
|
|
|
weekday, total_day=monthrange(int(year), int(month))
|
2015-02-24 14:59:49 +00:00
|
|
|
date_from=defaults.get('date_from','%s-%s-01'%(year,month))
|
|
|
|
date_to=defaults.get('date_to',"%s-%s-%s"%(year,month,total_day))
|
|
|
|
branch_id=defaults.get('branch_id',None)
|
2015-03-02 08:44:23 +00:00
|
|
|
print('defaults ', defaults)
|
|
|
|
if branch_id:
|
|
|
|
branch_id=int(branch_id)
|
2015-02-24 14:59:49 +00:00
|
|
|
department_id=defaults.get('department_id',None)
|
2015-03-02 08:44:23 +00:00
|
|
|
if department_id:
|
|
|
|
department_id=int(department_id)
|
2015-03-13 06:43:12 +00:00
|
|
|
select_apt=get_model('select.company').get_select()
|
|
|
|
if select_apt:
|
|
|
|
if not branch_id:
|
|
|
|
branch_id=select_apt['branch_id']
|
|
|
|
if not department_id:
|
|
|
|
department_id=select_apt['department_id']
|
2015-02-24 14:59:49 +00:00
|
|
|
res={
|
|
|
|
'date': date,
|
|
|
|
'date_from': date_from,
|
|
|
|
'date_to': date_to,
|
|
|
|
'branch_id': branch_id,
|
|
|
|
'department_id': department_id,
|
|
|
|
}
|
|
|
|
return res
|
2014-11-12 11:13:23 +00:00
|
|
|
|
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))
|
2015-02-24 14:59:49 +00:00
|
|
|
defaults=self.default_get(context=context)
|
|
|
|
time_start=defaults.get("date_from")
|
|
|
|
time_stop=defaults.get("date_to")
|
|
|
|
branch_id=defaults.get("branch_id")
|
|
|
|
department_id=defaults.get("department_id")
|
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
|
2015-02-24 14:59:49 +00:00
|
|
|
branch_id=obj.branch_id.id
|
|
|
|
department_id=obj.department_id.id
|
2014-11-10 11:33:01 +00:00
|
|
|
# new patient of this month
|
|
|
|
dom=[]
|
|
|
|
dom.append(['resign_date','>=',time_start])
|
|
|
|
dom.append(['resign_date','<=',time_stop])
|
2015-02-24 14:59:49 +00:00
|
|
|
if branch_id:
|
|
|
|
dom.append(['branch_id','=',branch_id])
|
|
|
|
if department_id:
|
|
|
|
dom.append(['department_id','=',department_id])
|
|
|
|
print("dom ", dom)
|
2014-11-10 11:33:01 +00:00
|
|
|
records=get_model('clinic.patient').search_browse(dom)
|
|
|
|
lines=[]
|
|
|
|
no=1
|
|
|
|
for record in records:
|
|
|
|
lines.append({
|
|
|
|
'no': no,
|
|
|
|
'name': record.name or '',
|
2014-11-12 11:13:23 +00:00
|
|
|
'pid': record.id,
|
2014-11-10 11:33:01 +00:00
|
|
|
'note': record.note or '',
|
2014-11-12 11:13:23 +00:00
|
|
|
'resign_date': record.resign_date or '',
|
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
|
2015-02-27 16:10:50 +00:00
|
|
|
sub_name=''
|
|
|
|
if department_id:
|
|
|
|
dpt=get_model("clinic.department").browse(department_id)
|
|
|
|
sub_name="(%s)" % dpt.name or ""
|
|
|
|
elif branch_id:
|
|
|
|
branch=get_model("clinic.branch").browse(branch_id)
|
|
|
|
sub_name="(%s)" % branch.name or ""
|
2014-11-05 07:03:12 +00:00
|
|
|
data={
|
2015-02-27 16:10:50 +00:00
|
|
|
'company_name': '%s %s' % (company.name or "", sub_name),
|
2014-11-05 07:03:12 +00:00
|
|
|
'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-12 11:13:23 +00:00
|
|
|
return data
|
2014-11-10 11:33:01 +00:00
|
|
|
|
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)
|
2014-11-05 06:45:28 +00:00
|
|
|
return data
|
|
|
|
|
2015-02-24 14:59:49 +00:00
|
|
|
def onchange_branch(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
data['department_id']=None
|
|
|
|
return data
|
|
|
|
|
2014-11-05 06:45:28 +00:00
|
|
|
ReportDiscontinuePatient.register()
|