2015-01-21 08:29:14 +00:00
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
|
|
|
|
|
|
from netforce.model import Model, fields, get_model
|
|
|
|
from netforce.access import get_active_user
|
|
|
|
|
|
|
|
DRT=0
|
|
|
|
|
|
|
|
class VisitPopupConfirm(Model):
|
|
|
|
_name="clinic.popup.visit.confirm"
|
|
|
|
_transient=True
|
|
|
|
|
|
|
|
_fields={
|
|
|
|
"visitboard_id": fields.Many2One("clinic.visit.board","Visit Board",required=True,on_delete="cascade"),
|
|
|
|
'user_id': fields.Many2One("base.user","User"),
|
|
|
|
"note": fields.Text("Note"),
|
|
|
|
'lines': fields.One2Many("clinic.popup.visit.confirm.line","popup_visit_id",'Lines'),
|
|
|
|
}
|
|
|
|
|
|
|
|
def _get_visitboard_id(self,context={}):
|
|
|
|
visitboard_id=context.get("refer_id")
|
|
|
|
if not visitboard_id:
|
|
|
|
return None
|
|
|
|
return int(visitboard_id)
|
|
|
|
|
|
|
|
def _get_default_lines(self,context={}):
|
|
|
|
visitboard_id=context.get("refer_id")
|
|
|
|
if not visitboard_id:
|
|
|
|
return []
|
|
|
|
return self._get_lines(int(visitboard_id))
|
|
|
|
|
|
|
|
def _get_lines(self,visitboard_id=None):
|
|
|
|
lines=[]
|
|
|
|
if not visitboard_id:
|
|
|
|
return lines
|
|
|
|
board=get_model("clinic.visit.board").browse(visitboard_id)
|
|
|
|
date_from=datetime.now().strftime("%Y-%m-%d")
|
|
|
|
date_to=(datetime.now()+timedelta(days=DRT)).strftime("%Y-%m-%d")
|
|
|
|
date_from=board.date_from
|
|
|
|
date_to=board.date_to
|
|
|
|
patient_id=board.patient_id.id
|
|
|
|
cycle_id=board.cycle_id.id
|
|
|
|
doctor_id=board.doctor_id.id
|
|
|
|
department_id=board.department_id.id
|
|
|
|
branch_id=board.branch_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])
|
|
|
|
dom.append(['state','in',['pending']])
|
|
|
|
if patient_id:
|
|
|
|
dom.append(['patient_id','=',patient_id])
|
|
|
|
if cycle_id:
|
|
|
|
dom.append(['cycle_id','=',cycle_id])
|
|
|
|
if doctor_id:
|
|
|
|
dom.append(['doctor_id','=',doctor_id])
|
|
|
|
if department_id:
|
|
|
|
dom.append(['department_id','=',department_id])
|
|
|
|
if branch_id:
|
|
|
|
dom.append(['branch_id','=',branch_id])
|
|
|
|
|
|
|
|
for visit in get_model("clinic.visit").search_browse(dom):
|
|
|
|
cycle=visit.cycle_id
|
|
|
|
patient=visit.patient_id
|
|
|
|
department=visit.department_id
|
2015-05-06 08:09:27 +00:00
|
|
|
doctor=visit.doctor_id
|
|
|
|
vals={
|
2015-01-21 08:29:14 +00:00
|
|
|
'patient_id': patient.id,
|
|
|
|
'cycle_id': cycle.id,
|
|
|
|
'department_id': department.id,
|
|
|
|
'visit_id': visit.id,
|
2015-05-06 08:09:27 +00:00
|
|
|
}
|
|
|
|
if doctor:
|
|
|
|
vals['doctor_id']=doctor.id
|
|
|
|
lines.append(vals)
|
2015-01-21 08:29:14 +00:00
|
|
|
return lines
|
|
|
|
|
|
|
|
_defaults={
|
|
|
|
'visitboard_id': _get_visitboard_id,
|
|
|
|
'user_id': lambda *a: get_active_user(),
|
|
|
|
'lines': _get_default_lines,
|
|
|
|
}
|
|
|
|
|
|
|
|
def confirm(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
board=obj.visitboard_id
|
|
|
|
count=0
|
|
|
|
for line in obj.lines:
|
|
|
|
vs=line.visit_id
|
2015-05-06 08:09:27 +00:00
|
|
|
dt=line.doctor_id
|
|
|
|
if dt:
|
|
|
|
vs.write({
|
|
|
|
'doctor_id': dt.id,
|
|
|
|
})
|
2015-01-21 08:29:14 +00:00
|
|
|
vs.confirm()
|
|
|
|
count+=1
|
|
|
|
return {
|
|
|
|
'next': {
|
|
|
|
'name': 'clinic_visit_board',
|
|
|
|
'mode': 'form',
|
|
|
|
'active_id': board.id,
|
|
|
|
},
|
|
|
|
'flash': 'Total confirmed is %s'%count,
|
|
|
|
}
|
|
|
|
|
|
|
|
VisitPopupConfirm.register()
|