2014-11-25 10:26:10 +00:00
|
|
|
import time
|
2014-12-02 08:34:28 +00:00
|
|
|
from calendar import monthrange
|
2014-11-25 10:26:10 +00:00
|
|
|
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
#from calendar import monthrange
|
|
|
|
from netforce.model import Model, fields, get_model
|
|
|
|
from netforce.access import get_active_company
|
|
|
|
|
|
|
|
from . import utils
|
|
|
|
|
2014-12-20 09:48:29 +00:00
|
|
|
DRT=0
|
|
|
|
HD_STATE={
|
|
|
|
"draft":"Draft",
|
|
|
|
'waiting_treatment':'Waiting Treatment',
|
|
|
|
"in_progress":"In Progress",
|
|
|
|
"completed":"Finish Treatment",
|
|
|
|
'paid':'Paid',
|
|
|
|
"waiting_payment":"Waiting Payment",
|
|
|
|
"discountinued":"Discountinued",
|
|
|
|
"cancelled":"Cancelled"
|
|
|
|
}
|
2014-11-25 10:26:10 +00:00
|
|
|
|
|
|
|
class VisitBoard(Model):
|
|
|
|
_name="clinic.visit.board"
|
|
|
|
_string="Visit Board"
|
|
|
|
_transient=True
|
|
|
|
|
|
|
|
_fields={
|
2014-12-02 08:34:28 +00:00
|
|
|
"date": fields.Date("Month", required=True),
|
2014-11-25 10:26:10 +00:00
|
|
|
"date_from": fields.Date("From", required=True),
|
|
|
|
"date_to": fields.Date("To", required=True),
|
|
|
|
'patient_id': fields.Many2One("clinic.patient","Patient"),
|
|
|
|
}
|
|
|
|
|
|
|
|
_defaults={
|
2014-12-02 08:34:28 +00:00
|
|
|
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
2014-11-25 10:26:10 +00:00
|
|
|
'date_from': lambda *a: time.strftime("%Y-%m-%d"),
|
|
|
|
'date_to': lambda *a: (datetime.now()+timedelta(days=DRT)).strftime("%Y-%m-%d"),
|
|
|
|
}
|
|
|
|
|
|
|
|
def get_report_data(self,ids,context={}):
|
|
|
|
company_id=get_active_company()
|
|
|
|
company=get_model("company").browse(company_id)
|
|
|
|
|
|
|
|
date_from=datetime.now().strftime("%Y-%m-%d")
|
|
|
|
date_to=(datetime.now()+timedelta(days=DRT)).strftime("%Y-%m-%d")
|
|
|
|
patient_id=None
|
|
|
|
if ids:
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
date_from=obj.date_from
|
|
|
|
date_to=obj.date_to
|
|
|
|
patient_id=obj.patient_id.id
|
|
|
|
|
|
|
|
time_start='%s 00:00:00'%(date_from)
|
|
|
|
time_stop='%s 23:59:59'%(date_to)
|
|
|
|
|
|
|
|
dom=[]
|
|
|
|
dom.append(['time_start','>=','%s'%time_start])
|
|
|
|
dom.append(['time_stop','<=','%s'%time_stop])
|
|
|
|
if patient_id:
|
|
|
|
dom.append(['patient_id','=',patient_id])
|
|
|
|
|
|
|
|
lines=[]
|
|
|
|
empty_line={
|
|
|
|
'no': '',
|
|
|
|
'number': '',
|
|
|
|
'visit_id': None,
|
|
|
|
'cycle_name': '',
|
|
|
|
'cycle_color': '',
|
2014-11-26 07:35:09 +00:00
|
|
|
'patient_id': None,
|
2014-11-25 10:26:10 +00:00
|
|
|
'patient_name': '',
|
|
|
|
'patient_type': '',
|
2014-12-20 09:48:29 +00:00
|
|
|
'patient_type_id': None,
|
2014-11-25 10:26:10 +00:00
|
|
|
'doctor_name': '',
|
2014-11-26 07:35:09 +00:00
|
|
|
'doctor_id': None,
|
2014-11-25 10:26:10 +00:00
|
|
|
'hd_case_number': '',
|
|
|
|
'hd_case_id': None,
|
|
|
|
'success_color': '',
|
|
|
|
'date':'',
|
|
|
|
'title': True,
|
2014-12-20 09:48:29 +00:00
|
|
|
'footer': False,
|
2014-11-25 10:26:10 +00:00
|
|
|
'details':'',
|
2014-12-20 09:48:29 +00:00
|
|
|
'hd_case_state': '',
|
2014-12-20 10:09:27 +00:00
|
|
|
'hn': '',
|
2014-11-25 10:26:10 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:08:20 +00:00
|
|
|
patient_types={t['id']:t['name'] for t in get_model("clinic.patient.type").search_read([[]],['name'])}
|
2014-12-20 10:54:34 +00:00
|
|
|
cycle_names={t['id']:t['name'] for t in get_model("clinic.cycle").search_read([[]],['name'])}
|
2014-11-25 10:26:10 +00:00
|
|
|
types={}
|
2014-12-20 10:54:34 +00:00
|
|
|
cycles={}
|
2014-11-25 10:26:10 +00:00
|
|
|
no=1
|
|
|
|
for visit in get_model("clinic.visit").search_browse(dom):
|
|
|
|
hd_case_id=None
|
|
|
|
hd_case_number=''
|
2014-12-20 09:48:29 +00:00
|
|
|
hd_case_state=''
|
|
|
|
visit_color=''
|
2014-11-25 10:26:10 +00:00
|
|
|
if visit.hd_cases:
|
|
|
|
hd_case=visit.hd_cases[0]
|
|
|
|
hd_case_id=hd_case.id,
|
2014-12-20 09:48:29 +00:00
|
|
|
if hd_case.number=='/':
|
|
|
|
hd_case_number='*รอการรรักษา'
|
|
|
|
else:
|
|
|
|
hd_case_number=hd_case.number
|
|
|
|
hd_case_state=hd_case.state
|
|
|
|
if hd_case_state=='completed':
|
|
|
|
visit_color='#99ff99'
|
2014-11-25 10:26:10 +00:00
|
|
|
number=visit.number
|
|
|
|
if number=='/':
|
2014-12-20 09:48:29 +00:00
|
|
|
number='*รอการยืนยัน'
|
2014-11-25 10:26:10 +00:00
|
|
|
cycle=visit.cycle_id
|
|
|
|
patient=visit.patient_id
|
2014-12-20 10:09:27 +00:00
|
|
|
hn_name=patient.hn or ''
|
2014-11-25 10:26:10 +00:00
|
|
|
visit_date=visit.visit_date
|
2014-12-20 09:48:29 +00:00
|
|
|
#if visit.state=='confirmed':
|
|
|
|
#visit_color='#99ff99'
|
|
|
|
#elif visit.state=='cancelled':
|
|
|
|
#visit_color='#D84B4B',
|
2014-11-25 10:26:10 +00:00
|
|
|
line={
|
|
|
|
'number': number,
|
2014-12-20 10:09:27 +00:00
|
|
|
'hn_name': hn_name,
|
2014-11-25 10:26:10 +00:00
|
|
|
'visit_id': visit.id,
|
2014-12-20 09:48:29 +00:00
|
|
|
'sickbed_name': visit.sickbed_id.name or "",
|
2014-11-25 10:26:10 +00:00
|
|
|
'cycle_name': cycle.name,
|
|
|
|
'cycle_color': cycle.color,
|
|
|
|
'patient_name': patient.name,
|
2014-11-26 07:35:09 +00:00
|
|
|
'patient_id': patient.id,
|
2014-12-02 07:08:20 +00:00
|
|
|
'patient_type': patient.type_id.name or "",
|
2014-12-20 09:48:29 +00:00
|
|
|
'patient_type_id': patient.type_id.id or None,
|
2014-11-25 10:26:10 +00:00
|
|
|
'doctor_name': visit.doctor_id.name,
|
2014-11-26 07:35:09 +00:00
|
|
|
'doctor_id': visit.doctor_id.id,
|
2014-11-25 10:26:10 +00:00
|
|
|
'hd_case_number': hd_case_number,
|
|
|
|
'hd_case_id': hd_case_id,
|
|
|
|
'visit_color': visit_color,
|
|
|
|
'date': visit_date,
|
|
|
|
'title': False,
|
2014-12-20 09:48:29 +00:00
|
|
|
'footer': False,
|
2014-11-25 10:26:10 +00:00
|
|
|
'details':'',
|
|
|
|
'no': no,
|
2014-12-20 09:48:29 +00:00
|
|
|
'note': visit.note,
|
|
|
|
'hd_case_state':HD_STATE.get(hd_case_state,''),
|
2014-11-25 10:26:10 +00:00
|
|
|
}
|
|
|
|
lines.append(line)
|
|
|
|
no+=1
|
|
|
|
if not types.get(visit_date):
|
|
|
|
ptype={}
|
2014-12-02 07:08:20 +00:00
|
|
|
[ptype.setdefault(t,0) for t in patient_types.keys()]
|
2014-11-25 10:26:10 +00:00
|
|
|
types[visit_date]=ptype
|
2014-12-02 07:08:20 +00:00
|
|
|
types[visit_date][patient.type_id.id]+=1
|
2014-12-20 10:54:34 +00:00
|
|
|
|
|
|
|
if not cycles.get(visit_date):
|
|
|
|
cycle_name={}
|
|
|
|
[cycle_name.setdefault(cid,0) for cid in cycle_names.keys()]
|
|
|
|
cycles[visit_date]=cycle_name
|
|
|
|
cycles[visit_date][cycle.id]+=1
|
2014-11-25 10:26:10 +00:00
|
|
|
|
|
|
|
dates=[]
|
|
|
|
index=0
|
2014-12-20 09:48:29 +00:00
|
|
|
total_qty=0
|
|
|
|
count=0
|
2014-11-25 10:26:10 +00:00
|
|
|
for line in lines:
|
|
|
|
date=line['date']
|
2014-12-20 09:48:29 +00:00
|
|
|
if not date:
|
|
|
|
continue
|
2014-11-25 10:26:10 +00:00
|
|
|
if date not in dates:
|
2014-12-20 09:48:29 +00:00
|
|
|
count=0
|
2014-11-25 10:26:10 +00:00
|
|
|
total_qty=0
|
2014-12-20 09:48:29 +00:00
|
|
|
line=empty_line.copy()
|
2014-11-25 10:26:10 +00:00
|
|
|
for qty in types[date].values():
|
|
|
|
total_qty+=qty
|
|
|
|
line['cycle_name']=utils.date2thai(date,format='%(Td)s %(d)s %(Tm)s',lang="th_TH2"),
|
|
|
|
lines.insert(index,line)
|
|
|
|
dates.append(date)
|
2014-12-20 09:48:29 +00:00
|
|
|
if count==total_qty:
|
|
|
|
index+=1
|
|
|
|
# footer
|
|
|
|
line=empty_line.copy()
|
2014-12-20 10:54:34 +00:00
|
|
|
patient_str='[%s]'%', '.join('%s %s'%(patient_types[k],v) for k,v in types[date].items())
|
|
|
|
cycle_str='[%s]'%', '.join('%s: %s'%(cycle_names[k],v) for k,v in cycles[date].items())
|
|
|
|
line['details']='รวม %s: %s'%(total_qty,', '.join([cycle_str,patient_str]))
|
2014-12-20 09:48:29 +00:00
|
|
|
line['footer']=True
|
|
|
|
line['title']=False
|
|
|
|
lines.insert(index,line)
|
|
|
|
count+=1
|
2014-11-25 10:26:10 +00:00
|
|
|
index+=1
|
|
|
|
|
|
|
|
has_duration=False
|
|
|
|
if date_from != date_to:
|
|
|
|
has_duration=True
|
|
|
|
data={
|
|
|
|
'lines': lines,
|
|
|
|
'date': utils.date2thai(date_from,format='ประจำวัน%(Td)s ที่ %(d)s %(Tm)s %(BY)s'),
|
|
|
|
'company_name': company.name,
|
|
|
|
'company_parent_name': company.parent_id.name,
|
|
|
|
'has_duration': has_duration,
|
|
|
|
'date_from': utils.date2thai(date_from,format='%(d)s %(Tm)s %(By)s',lang="th_TH2"),
|
|
|
|
'date_to': utils.date2thai(date_to,format='%(d)s %(Tm)s %(By)s',lang="th_TH2"),
|
|
|
|
}
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
2014-12-02 08:34:28 +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-12-20 09:48:29 +00:00
|
|
|
|
|
|
|
def make_visit(self,ids,context={}):
|
|
|
|
return {
|
|
|
|
'next': {
|
|
|
|
'name': 'clinic_visit',
|
|
|
|
'mode': 'form',
|
|
|
|
}
|
|
|
|
}
|
2014-12-02 08:34:28 +00:00
|
|
|
|
2014-11-25 10:26:10 +00:00
|
|
|
VisitBoard.register()
|