get visit

conv_bal
watcha.h 2014-10-20 12:17:21 +07:00
parent 28431a348b
commit 219fb09612
5 changed files with 106 additions and 28 deletions

View File

@ -18,5 +18,6 @@
</field>
<foot>
<button string="Generate" type="success" method="gen_visit"/>
<button string="Clear" type="danger" icon="remove" method="clear_visit"/>
</foot>
</form>

View File

@ -1,5 +1,4 @@
<!--<calendar model="clinic.visit" states='waiting_treatment' date_field="date_visit" colors='{"#090":[["cycle","=",1]],"#2400ff":[["cycle","=",2]],"#ebff00":[["cycle","=",3]],"#f20000":[["cycle","=",4]]}'>-->
<calendar model="clinic.visit" states='waiting_treatment' start_field="time_start" end_field="time_stop" colors='{"#090":[["cycle","=",1]],"#2400ff":[["cycle","=",2]],"orange":[["cycle","=",3]],"#f20000":[["cycle","=",4]]}'>
<calendar model="clinic.visit" states='draft' start_field="time_start" end_field="time_stop" colors='{"#090":[["cycle","=",1]],"#2400ff":[["cycle","=",2]],"orange":[["cycle","=",3]],"#f20000":[["cycle","=",4]]}'>
<field name="patient_id"/>
<field name="cycle_id"/>
<field name="number"/>

View File

@ -85,7 +85,7 @@ class GenVisit(Model):
def gen_visit(self,ids,context):
obj=self.browse(ids)[0]
#time_stop=obj.date_to[11:]
visit_obj=get_model('clinic.visit')
days=[
obj.monday and 1 or 0,
obj.tuesday and 2 or 0,
@ -94,17 +94,12 @@ class GenVisit(Model):
obj.friday and 5 or 0,
]
days=[day for day in days if day]
print("days ", days)
if not days:
raise Exception("Please select Day")
#duration=datetime.strptime(obj.date_to,FMT_DATETIME)-datetime.strptime(obj.date_from,FMT_DATETIME)
# loop patient
visit_vals=[]
date_from=datetime.strptime(obj.date_from,FMT_DATETIME)
date_to=datetime.strptime(obj.date_to,FMT_DATETIME)
#total_days=(date_to-date_from).days
for line in obj.lines:
# loop days in weekend
ntoday=1
day_total=(date_to-date_from).days+ntoday
for weekday in days:
@ -114,7 +109,7 @@ class GenVisit(Model):
start_date+=timedelta(days=1)
wd=start_date.weekday()
#XXX should gen only in scoop
#XXX should gen only in scope
if start_date.strftime(FMT_DATE) > date_to.strftime(FMT_DATE):
continue
count=0
@ -131,23 +126,18 @@ class GenVisit(Model):
}
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', '=', line.patient_id.id])
dom.append(['state','=','draft'])
vids=visit_obj.search(dom)
visit_obj.delete(vids)
start_date=tmp
if visit_vals:
dom=[]
dom.append(['time_start','>=','%s %s'%(date_from.strftime(FMT_DATE)[0:10],' 00:00:00')])
dom.append(['time_stop','<=','%s %s'%(start_date.strftime(FMT_DATE)[0:10],' 23:59:59')])
# search patient
dom.append(['state','=','draft'])
patient_ids=[visit['patient_id'] for visit in visit_vals]
dom.append(['patient_id', 'in', tuple(patient_ids)])
print("dom ", dom)
visit_obj=get_model('clinic.visit')
visit_ids=visit_obj.search(dom)
# delete old visit (same duration)
visit_obj.delete(visit_ids)
for vals in visit_vals:
visit_obj.create(vals)
for vals in visit_vals:
visit_obj.create(vals)
return {
'next': {
@ -157,5 +147,95 @@ class GenVisit(Model):
'flash': 'Generate OK',
}
def clear_visit(self,ids,context={}):
obj=self.browse(ids)[0]
days=[
obj.monday and 1 or 0,
obj.tuesday and 2 or 0,
obj.wednesday and 3 or 0,
obj.thursday and 4 or 0,
obj.friday and 5 or 0,
]
days=[day for day in days if day]
visit_ids=[]
date_from=datetime.strptime(obj.date_from,FMT_DATETIME)
date_to=datetime.strptime(obj.date_to,FMT_DATETIME)
visit_obj=get_model("clinic.visit")
if days:
for line in obj.lines:
# loop days in weekend
ntoday=1
day_total=(date_to-date_from).days+ntoday
for weekday 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 scop
if start_date.strftime(FMT_DATE) > date_to.strftime(FMT_DATE):
continue
count=0
while count < day_total:
tmp=start_date+timedelta(days=count)
time_start="%s 00:00:00" % (tmp.strftime(FMT_DATE))
time_stop="%s 23:59:59" % (tmp.strftime(FMT_DATE))
patient_id=line.patient_id.id
dom=[]
dom.append(['time_start','>=','%s'%time_start])
dom.append(['time_stop','<=','%s'%time_stop])
dom.append(['patient_id','=','%s'%patient_id])
dom.append(['state','=','draft'])
count+=7
print(dom)
vids=visit_obj.search(dom)
if vids:
visit_ids.append(vids[0])
start_date=tmp
else:
time_start=obj.date_from
time_stop=obj.date_to
for line in obj.lines:
patient_id=line.patient_id.id
dom=[]
dom.append(['time_start','>=','%s'%time_start])
dom.append(['time_stop','<=','%s'%time_stop])
dom.append(['patient_id','=','%s'%patient_id])
dom.append(['state','=','draft'])
vids=visit_obj.search(dom)
if vids:
visit_ids.append(vids[0])
if visit_ids:
print("visit_ids ", len(visit_ids))
get_model("clinic.visit").delete(visit_ids)
return {
'next': {
'name': 'clinic_patient',
'mode': 'list',
},
'flash': 'Clear OK',
}
def _clear_visit(self,ids,context):
obj=self.browse(ids)[0]
visit_obj=get_model("clinic.visit")
for line in obj.lines:
patient_id=line.patient_id
dom=[]
dom.append(['patient_id','=',patient_id.id])
dom.append(['state','=','draft'])
# clear
# only from to and day
visit_ids=visit_obj.search(dom)
visit_obj.delete(visit_ids)
return {
'next': {
'name': 'clinic_patient',
'mode': 'list',
},
'flash': 'Clear OK',
}
GenVisit.register()

View File

@ -199,8 +199,4 @@ class Patient(Model):
vals['partner_id']=partner_id
super().write(ids,vals,**kw)
def generate_visit(self,ids,context={}):
obj=self.browse(ids)[0]
pass
Patient.register()

View File

@ -1,3 +1,5 @@
===
- skip holiday
====
- import data
- payment