diff --git a/netforce_clinic/actions/clinic_schedule.xml b/netforce_clinic/actions/clinic_schedule.xml
index a61472b..2b0b1b1 100644
--- a/netforce_clinic/actions/clinic_schedule.xml
+++ b/netforce_clinic/actions/clinic_schedule.xml
@@ -3,5 +3,6 @@
multi_view
clinic.schedule
calendar,list,page,form
+ [["All",[]],["Draft",[["state","=","draft"]]],["Confirmed",[["state","=","confirmed"]]]]
clinic_menu
diff --git a/netforce_clinic/actions/clinic_visit.xml b/netforce_clinic/actions/clinic_visit.xml
index 42c5502..7108110 100644
--- a/netforce_clinic/actions/clinic_visit.xml
+++ b/netforce_clinic/actions/clinic_visit.xml
@@ -3,6 +3,6 @@
multi_view
clinic.visit
[["All",[]],["Draft",[["state","=","draft"]]],["Confirmed",[["state","=","confirmed"]]],["Cancelled",[["state","=","cancelled"]]]]
- calendar,list,form
+ list,form,calendar
clinic_menu
diff --git a/netforce_clinic/layouts/clinic_personal_list.xml b/netforce_clinic/layouts/clinic_personal_list.xml
index 6daf35d..75817ac 100644
--- a/netforce_clinic/layouts/clinic_personal_list.xml
+++ b/netforce_clinic/layouts/clinic_personal_list.xml
@@ -1,6 +1,7 @@
+
diff --git a/netforce_clinic/layouts/clinic_schedule_form.xml b/netforce_clinic/layouts/clinic_schedule_form.xml
index 618d668..9ff4400 100644
--- a/netforce_clinic/layouts/clinic_schedule_form.xml
+++ b/netforce_clinic/layouts/clinic_schedule_form.xml
@@ -1,11 +1,19 @@
-
diff --git a/netforce_clinic/layouts/clinic_schedule_list.xml b/netforce_clinic/layouts/clinic_schedule_list.xml
index 4ac4079..b4e3712 100644
--- a/netforce_clinic/layouts/clinic_schedule_list.xml
+++ b/netforce_clinic/layouts/clinic_schedule_list.xml
@@ -2,4 +2,5 @@
+
diff --git a/netforce_clinic/models/address.py b/netforce_clinic/models/address.py
index 304a456..b5b71f2 100644
--- a/netforce_clinic/models/address.py
+++ b/netforce_clinic/models/address.py
@@ -5,6 +5,7 @@ class Address(Model):
_fields={
"patient_id": fields.Many2One("clinic.patient","Patient"),
+ "personal_id": fields.Many2One("clinic.personal","Personal"),
}
Address.register()
diff --git a/netforce_clinic/models/gen_visit.py b/netforce_clinic/models/gen_visit.py
index a1edf8e..6e92c6c 100644
--- a/netforce_clinic/models/gen_visit.py
+++ b/netforce_clinic/models/gen_visit.py
@@ -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()
diff --git a/netforce_clinic/models/personal.py b/netforce_clinic/models/personal.py
index 414bc3a..a39b49a 100644
--- a/netforce_clinic/models/personal.py
+++ b/netforce_clinic/models/personal.py
@@ -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"),
diff --git a/netforce_clinic/models/schedule.py b/netforce_clinic/models/schedule.py
index ead691b..f2e254d 100644
--- a/netforce_clinic/models/schedule.py
+++ b/netforce_clinic/models/schedule.py
@@ -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()
diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt
index ee8c9e9..49a51bf 100644
--- a/netforce_clinic/todo.txt
+++ b/netforce_clinic/todo.txt
@@ -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