gent visit

conv_bal
watcha.h 2014-11-01 13:04:30 +07:00
parent 63bdaff4d9
commit 963b606d67
10 changed files with 103 additions and 15 deletions

View File

@ -3,5 +3,6 @@
<field name="view_cls">multi_view</field>
<field name="model">clinic.schedule</field>
<field name="modes">calendar,list,page,form</field>
<field name="tabs">[["All",[]],["Draft",[["state","=","draft"]]],["Confirmed",[["state","=","confirmed"]]]]</field>
<field name="menu">clinic_menu</field>
</action>

View File

@ -3,6 +3,6 @@
<field name="view_cls">multi_view</field>
<field name="model">clinic.visit</field>
<field name="tabs">[["All",[]],["Draft",[["state","=","draft"]]],["Confirmed",[["state","=","confirmed"]]],["Cancelled",[["state","=","cancelled"]]]]</field>
<field name="modes">calendar,list,form</field>
<field name="modes">list,form,calendar</field>
<field name="menu">clinic_menu</field>
</action>

View File

@ -1,6 +1,7 @@
<list model="clinic.personal">
<field name="number"/>
<field name="name"/>
<field name="categ_id"/>
<field name="type"/>
<field name="state"/>
</list>

View File

@ -1,11 +1,19 @@
<form model="clinic.schedule">
<form model="clinic.schedule" attrs='{"readonly":[["state","in",["confirmed"]]]}' show_company="1">
<head>
<field name="state"/>
<button string="Options" dropdown="1">
<item string="Copy" method="copy"/>
</button>
</head>
<field name="time_start"/>
<field name="time_start"/>
<field name="cycle_id"/>
<field name="nurses"/>
<group form_layout="stacked">
<field name="time_start" span="3"/>
<field name="time_start" span="3"/>
<field name="cycle_id" span="3"/>
<newline/>
<field name="nurses" span="8"/>
</group>
<foot>
<button string="Confirm" type="success" method="confirm" states="draft" />
<button string="To Draft" type="default" icon="repeat" method="to_draft" states="confirmed" />
</foot>
</form>

View File

@ -2,4 +2,5 @@
<field name="name"/>
<field name="time_start"/>
<field name="time_start"/>
<field name="state"/>
</list>

View File

@ -5,6 +5,7 @@ class Address(Model):
_fields={
"patient_id": fields.Many2One("clinic.patient","Patient"),
"personal_id": fields.Many2One("clinic.personal","Personal"),
}
Address.register()

View File

@ -2,6 +2,7 @@ from datetime import datetime, timedelta
from netforce.access import get_active_user
from netforce.model import Model, fields, get_model
from netforce.database import get_connection
FMT_DATE="%Y-%m-%d"
FMT_DATETIME="%Y-%m-%d %H:%M:%S"
@ -113,12 +114,15 @@ class GenVisit(Model):
visit_vals=[]
date_from=datetime.strptime(obj.date_from,FMT_DATETIME)
date_to=datetime.strptime(obj.date_to,FMT_DATETIME)
patients=[p.patient_id.id for p in obj.patient_lines]
patients=[p.patient_id.id for p in obj.patient_lines if p.patient_id]
if not patients and obj.patient_type:
patients=get_model("clinic.patient").search([['type','=',obj.patient_type]])
elif patients:
pass
else:
raise Exception("Please select some patient or patient type")
schedules={}
for patient_id in patients:
ntoday=1
day_total=(date_to-date_from).days+ntoday
@ -135,14 +139,16 @@ class GenVisit(Model):
count=0
while count < day_total:
tmp=start_date+timedelta(days=count)
ttime_start="%s %s" % (tmp.strftime(FMT_DATE),date_from.strftime(FMT_DATETIME)[11:])
ttime_stop="%s %s" % (tmp.strftime(FMT_DATE),date_to.strftime(FMT_DATETIME)[11:])
vals={
'patient_id': patient_id,
'doctor_id': obj.doctor_id.id,
'nurse_id': obj.nurse_id.id,
'department_id': obj.department_id.id,
'cycle_id': obj.cycle_id.id,
'time_start': "%s %s" % (tmp.strftime(FMT_DATE),date_from.strftime(FMT_DATETIME)[11:]),
'time_stop': "%s %s" % (tmp.strftime(FMT_DATE),date_to.strftime(FMT_DATETIME)[11:]),
'time_start': ttime_start,
'time_stop': ttime_stop,
'state': 'draft',
}
visit_vals.append(vals)
@ -156,11 +162,40 @@ class GenVisit(Model):
dom.append(['state','=','draft'])
vids=visit_obj.search(dom)
visit_obj.delete(vids)
key='%s-%s'%(vals['cycle_id'], vals['time_start'])
if not schedules.get(key):
schedules[key]={
'cycle_id': obj.cycle_id.id,
'time_start': ttime_start,
'time_stop': ttime_stop,
'state':'draft',
}
start_date=tmp
for vals in visit_vals:
visit_obj.create(vals)
nurse_ids=[]
for nurse_line in obj.nurse_lines:
nurse_id=nurse_line.nurse_id.id
# None
if nurse_id:
nurse_ids.append(nurse_id)
if not nurse_ids:
nurse_ids=get_model("clinic.personal").search([['type','=','nurse'],['categ_id','=',obj.nurse_categ_id.id]])
dom=[]
dom.append(['time_start','>=','%s %s'%(obj.date_from[0:10],' 00:00:00')])
dom.append(['time_stop','<=','%s %s'%(start_date.strftime(FMT_DATE)[0:10],' 23:59:59')])
dom.append(['cycle_id','=',obj.cycle_id.id])
schedule_obj=get_model("clinic.schedule")
schedule_ids=schedule_obj.search(dom)
schedule_obj.delete(schedule_ids)
for key, vals in schedules.items():
vals['nurses']=[('add', nurse_ids)]
schedule_obj.create(vals)
return {
'next': {
'name': 'clinic_visit',
@ -183,11 +218,33 @@ class GenVisit(Model):
date_from=datetime.strptime(obj.date_from,FMT_DATETIME)
date_to=datetime.strptime(obj.date_to,FMT_DATETIME)
visit_obj=get_model("clinic.visit")
patients=[p.patient_id.id for p in obj.patient_lines]
schedule_obj=get_model("clinic.schedule")
patients=[p.patient_id.id for p in obj.patient_lines if p.patient_id]
if not patients and obj.patient_type:
patients=get_model("clinic.patient").search([['type','=',obj.patient_type]])
elif patients:
pass
else:
raise Exception("Please select some patient or patient type")
#XXX search date to
dom=[]
dom.append(['time_start','>=','%s %s'%(obj.date_from[0:10],' 00:00:00')])
dom.append(['time_stop','<=','%s %s'%(obj.date_to[0:10],' 23:59:59')])
dom.append(['cycle_id','=',obj.cycle_id.id])
dom.append(['state','=','draft'])
vids=visit_obj.search(dom)
visit_ids.append(vids)
schedule_obj=get_model("clinic.schedule")
schedule_ids=schedule_obj.search(dom)
schedule_obj.delete(schedule_ids)
return {
'next': {
'name': 'clinic_gen_visit_form',
'mode': 'form',
},
'flash': 'Clear OK',
}
if days:
for patient_id in patients:
# loop days in weekend
@ -232,8 +289,13 @@ class GenVisit(Model):
if vids:
visit_ids.append(vids[0])
if visit_ids:
print("visit_ids ", len(visit_ids))
get_model("clinic.visit").delete(visit_ids)
dom=[]
dom.append(['time_start','>=','%s %s'%(obj.date_from[0:10],' 00:00:00')])
dom.append(['time_stop','<=','%s %s'%(start_date.strftime(FMT_DATE)[0:10],' 23:59:59')])
dom.append(['cycle_id','=',obj.cycle_id.id])
schedule_ids=schedule_obj.search(dom)
schedule_obj.delete(schedule_ids)
return {
'next': {
'name': 'clinic_visit',
@ -242,6 +304,5 @@ class GenVisit(Model):
'flash': 'Clear OK',
}
GenVisit.register()

View File

@ -37,7 +37,7 @@ class Personal(Model):
"birthday": fields.Date("BirthDay",search=True),
"department_id": fields.Many2One("clinic.department", "Department",search=True),
"patients": fields.Many2Many("clinic.patient","Patients"),
"addresses": fields.One2Many("address","related_id","Addresses"),
"addresses": fields.One2Many("address","personal_id","Addresses"),
"comments": fields.One2Many("message","related_id","Comments"),
"visits": fields.One2Many("clinic.visit","nurse_id","Visits"),
"hd_cases": fields.One2Many("clinic.hd.case","nurse_id","HD Cases"),

View File

@ -19,11 +19,25 @@ class Schedule(Model):
"time_start": fields.DateTime("Time Start",required=True),
"time_stop": fields.DateTime("Time Stop",required=True),
'company_id': fields.Many2One("company","Company"),
'nurses': fields.Many2Many('clinic.nurse','Nurses'),
'nurses': fields.Many2Many('clinic.personal','Nurses'), # XXX domain
'state': fields.Selection([['draft','Draft'],['confirmed', 'Confirmed']],'State'),
}
_defaults={
"company_id": lambda *a: get_active_company(),
}
def confirm(self,ids,context={}):
obj=self.browse(ids)[0]
obj.write({
'state': 'confirmed',
})
def to_draft(self,ids,context={}):
obj=self.browse(ids)[0]
obj.write({
'state': 'draft',
})
Schedule.register()

View File

@ -1,5 +1,6 @@
after finish hd case -> show popup to check nurse and doctor after finish
many2many -> domain
formalar
tick:
find all -> replace -> multiple x