conv_bal
watcha.h@almacom.co.th 2015-01-15 18:45:11 +07:00
parent 206554cb60
commit 81ab2ff33d
8 changed files with 259 additions and 2 deletions

View File

@ -0,0 +1,8 @@
<record model="action">
<field name="name">clinic_make_apt</field>
<field name="view">form_view</field>
<field name="model">clinic.make.apt</field>
<field name="view_xml">clinic_make_apt</field>
<field name="menu">clinic_menu</field>
</record>

View File

@ -0,0 +1,23 @@
<form model="clinic.make.apt">
<separator string="1. Select Period > 2. Click Load Data > 3. Select Patient > 4. Generate Visit"/>
<field name="date" span="3" mode="month" onchange="onchange_date"/>
<field name="date_from" span="3"/>
<field name="date_to" span="3"/>
<field name="lines" nolabel="1">
<list>
<field name="patient_id"/>
<field name="department_id"/>
<field name="mon_cycle_id"/>
<field name="tue_cycle_id"/>
<field name="wed_cycle_id"/>
<field name="thu_cycle_id"/>
<field name="fri_cycle_id"/>
<field name="sat_cycle_id"/>
<field name="sun_cycle_id"/>
</list>
</field>
<foot replace="1">
<button string="Load Data" method="load" icon="repeat" type="success"/>
<button string="Generate" method="gen" icon="arrow-right" type="primary"/>
</foot>
</form>

View File

@ -37,6 +37,8 @@
<item string="Visits" perm="clinic_visit">
<item string="Visits" action="clinic_visit"/>
<item string="Visit Board" action="clinic_visit_board"/>
<divider/>
<item string="Make An Appoitment" action="clinic_make_apt"/>
</item>
<item string="HD Cases" perm="clinic_hdcase">
<item string="HD Cases" action="clinic_hd_case"/>

View File

@ -4,7 +4,7 @@
<button string="Options" dropdown="1">
<item string="Generate Visit" action="clinic_gen_visit"/>
<item string="New Dialyzer" method="new_dialyzer"/>
<!--<item string="Simple Address" method="simple_address"/>-->
<item string="Simple Address" method="simple_address" perm="clinic_simple_address"/>
</button>
</head>
<field name="number"/>

View File

@ -7,7 +7,7 @@
<button string="New Visit" method="make_visit" span="1" icon="plus" type="success" size="small"/>
</group>
<group span="2" columns="1">
<button string="Make An Appointment" action="clinic_gen_visit_form" span="1" icon="calendar" type="default" size="small"/>
<!--<button string="Make An Appointment" action="clinic_gen_visit_form" span="1" icon="calendar" type="default" size="small"/>-->
<!--<button string="Calendar" offset="10" icon="calendar" size="small"/>-->
</group>
</form>

View File

@ -86,3 +86,5 @@ from . import labor_cost_entry_line
from . import sickbed
from . import product_categ
from . import import_uc
from . import make_apt
from . import make_apt_line

View File

@ -0,0 +1,200 @@
import time
from datetime import datetime, timedelta
from calendar import monthrange
from netforce.model import Model, fields, get_model
from netforce.access import get_active_user
DRT=0
FMT_DATE="%Y-%m-%d"
FMT_DATETIME="%Y-%m-%d %H:%M:%S"
class MakeAPT(Model):
_name="clinic.make.apt"
_transient=True
_fields={
"date": fields.Date("Month"),
"date_from": fields.Date("From", required=True),
"date_to": fields.Date("To", required=True),
"lines": fields.One2Many("clinic.make.apt.line","apt_id","Lines"),
}
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"),
'date_from': lambda *a: time.strftime("%Y-%m-%d"),
'date_to': lambda *a: (datetime.now()+timedelta(days=DRT)).strftime("%Y-%m-%d"),
}
def load(self,ids,context={}):
obj=self.browse(ids)[0]
pts={}
for pc in get_model("clinic.patient.cycle").search_browse([]):
patient=pc.patient_id
dpt=pc.department_id
key='%s-%s'%(patient.id,dpt.id)
if not pts.get(key):
pts[key]={
'mon_cycle_id': None,
'tue_cycle_id': None,
'wed_cycle_id': None,
'thu_cycle_id': None,
'fri_cycle_id': None,
'sat_cycle_id': None,
'sun_cycle_id': None,
}
cycle=pc.cycle_id
day=pc.day or ''
if day=='mon':
pts[key]['mon_cycle_id']=cycle.id
elif day=='tue':
pts[key]['tue_cycle_id']=cycle.id
elif day=='wed':
pts[key]['wed_cycle_id']=cycle.id
elif day=='thu':
pts[key]['thu_cycle_id']=cycle.id
elif day=='fri':
pts[key]['fri_cycle_id']=cycle.id
elif day=='sat':
pts[key]['sat_cycle_id']=cycle.id
else:
pts[key]['sun_cycle_id']=cycle.id
lines=[]
for k, vals in pts.items():
pt_id, dpt_id=k.split("-")
vals['patient_id']=pt_id
vals['department_id']=dpt_id
lines.append(('create',vals))
for line in obj.lines:
line.delete()
obj.write({
'lines': lines,
})
return {
'next': {
'name': 'clinic_make_apt',
'mode': 'form',
'active_id': obj.id,
},
'flash': 'Reload Successfully',
}
def gen(self,ids,context={}):
obj=self.browse(ids)[0]
if not obj.lines:
raise Exception("Nothing to generate")
visit_obj=get_model("clinic.visit")
visit_vals=[]
date_from=datetime.strptime(obj.date_from,FMT_DATE)
date_to=datetime.strptime(obj.date_to,FMT_DATE)
for line in obj.lines:
patient=line.patient_id
dpt=line.department_id or patient.department_id
days=[]
if line.mon_cycle_id:
cycle=line.mon_cycle_id
days.append([1,cycle,dpt])
if line.tue_cycle_id:
cycle=line.tue_cycle_id
days.append([2,cycle,dpt])
if line.wed_cycle_id:
days.append([3,cycle,dpt])
cycle=line.wed_cycle_id
if line.thu_cycle_id:
cycle=line.thu_cycle_id
days.append([4,cycle,dpt])
if line.fri_cycle_id:
cycle=line.fri_cycle_id
days.append([5,cycle,dpt])
if line.sat_cycle_id:
cycle=line.sat_cycle_id
days.append([6,cycle,dpt])
if line.sun_cycle_id:
cycle=line.sun_cycle_id
days.append([7,cycle,dpt])
ntoday=1
day_total=(date_to-date_from).days+ntoday
for weekday, cycle, department in days:
wd=date_from.weekday()
start_date=date_from
while wd != weekday-1:
start_date+=timedelta(days=1)
wd=start_date.weekday()
#XXX should gen only in scope
if start_date.strftime(FMT_DATE) > date_to.strftime(FMT_DATE):
continue
count=0
tmp=start_date
cstart=cycle.time_start
cstop=cycle.time_stop
while count < day_total:
tmp=start_date+timedelta(days=count)
visit_date="%s"%(tmp.strftime(FMT_DATE))
ttime_start="%s %s" % (visit_date,cstart)
ttime_stop="%s %s" % (visit_date,cstop)
vals={
'patient_id': patient.id,
'doctor_id': patient.doctor_id.id,
'department_id': department.id,
'branch_id': patient.branch_id.id or department.branch_id.id,
'cycle_id': cycle.id,
'time_start': ttime_start,
'time_stop': ttime_stop,
'visit_date': visit_date,
'state': 'pending',
}
visit_vals.append(vals)
count+=7
dom=[]
dom.append(['time_start','>=','%s %s'%(tmp.strftime(FMT_DATE)[0:10],' 00:00:00')])
dom.append(['time_stop','<=','%s %s'%(tmp.strftime(FMT_DATE)[0:10],' 23:59:59')])
dom.append(['patient_id', '=', patient.id])
dom.append(['cycle_id', '=', cycle.id])
dom.append(['state','=','pending'])
vids=visit_obj.search(dom)
visit_obj.delete(vids)
start_date=tmp
user_id=get_active_user()
staff_ids=get_model("clinic.staff").search([['type','=','type'],['user_id','=',user_id]])
confirm_id=None
if staff_ids:
confirm_id=staff_ids[0]
for vals in visit_vals:
vals['nurse_id']=confirm_id
visit_obj.create(vals)
return {
'next': {
'name': 'clinic_make_apt',
'mode': 'form',
'active_id': obj.id,
},
'flash': 'Generate Visit Successfully',
}
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
MakeAPT.register()

View File

@ -0,0 +1,22 @@
from netforce.model import Model, fields
class MakeAPTLine(Model):
_name="clinic.make.apt.line"
_transient=True
_fields={
'apt_id': fields.Many2One("clinic.make.apt","APT", required=True,on_delete="cascade"),
'patient_id': fields.Many2One("clinic.patient","Patient"),
'mon_cycle_id': fields.Many2One("clinic.cycle","Monday"),
'tue_cycle_id': fields.Many2One("clinic.cycle","Tueday"),
'wed_cycle_id': fields.Many2One("clinic.cycle","Wedsday"),
'thu_cycle_id': fields.Many2One("clinic.cycle","Thursday"),
'fri_cycle_id': fields.Many2One("clinic.cycle","Friday"),
'sat_cycle_id': fields.Many2One("clinic.cycle","Satherday"),
'sun_cycle_id': fields.Many2One("clinic.cycle","Sunday"),
'department_id': fields.Many2One("clinic.department","Department"),
}
_order="patient_id"
MakeAPTLine.register()