diff --git a/netforce_clinic/layouts/clinic_make_apt.xml b/netforce_clinic/layouts/clinic_make_apt.xml
index 9f2371d..c656474 100644
--- a/netforce_clinic/layouts/clinic_make_apt.xml
+++ b/netforce_clinic/layouts/clinic_make_apt.xml
@@ -3,9 +3,9 @@
-
-
-
+
+
+
diff --git a/netforce_clinic/layouts/clinic_setting.xml b/netforce_clinic/layouts/clinic_setting.xml
index e829c3c..98b490a 100644
--- a/netforce_clinic/layouts/clinic_setting.xml
+++ b/netforce_clinic/layouts/clinic_setting.xml
@@ -2,6 +2,7 @@
+
diff --git a/netforce_clinic/models/make_apt.py b/netforce_clinic/models/make_apt.py
index 16e75e9..cc3ad74 100644
--- a/netforce_clinic/models/make_apt.py
+++ b/netforce_clinic/models/make_apt.py
@@ -147,12 +147,18 @@ class MakeAPT(Model):
visit_vals=[]
date_from=datetime.strptime(obj.date_from,FMT_DATE)
date_to=datetime.strptime(obj.date_to,FMT_DATE)
-
+ old_pids=[]
for line in obj.lines:
patient=line.patient_id
if not patient:
continue
dpt=line.department_id or patient.department_id
+ # skip already gen
+ if patient.id in old_pids:
+ print("skip patient ", patient.id, old_pids)
+ continue
+ old_pids.append(patient.id)
+
days=[]
if line.mon_cycle_id:
cycle=line.mon_cycle_id
@@ -181,7 +187,6 @@ class MakeAPT(Model):
if line.sun_cycle_id:
cycle=line.sun_cycle_id
days.append([7,cycle,dpt])
-
# remove the rest
dom=[]
dom.append(['visit_date','>=', obj.date_from])
@@ -190,7 +195,6 @@ class MakeAPT(Model):
dom.append(['state','=','pending'])
vids=visit_obj.search(dom)
visit_obj.delete(vids)
-
ntoday=1
day_total=(date_to-date_from).days+ntoday
for weekday, cycle, department in days:
@@ -231,7 +235,7 @@ class MakeAPT(Model):
vids=visit_obj.search(dom)
if not vids:
visit_vals.append(vals)
- count+=7 #XXX
+ count+=7 #XXX recheck
start_date=tmp
user_id=get_active_user()
staff_ids=get_model("clinic.staff").search([['type','=','type'],['user_id','=',user_id]])
diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py
index eb07a7d..d3630c9 100644
--- a/netforce_clinic/models/setting.py
+++ b/netforce_clinic/models/setting.py
@@ -1,6 +1,6 @@
from netforce.model import Model, fields, get_model
from netforce.utils import get_file_path, get_data_path
-from netforce.access import get_active_company, get_active_user
+from netforce.access import get_active_company, get_active_user, set_active_user
from netforce.database import get_connection
class ClinicSetting(Model):
@@ -126,19 +126,37 @@ class ClinicSetting(Model):
if user_id !=1:
print("Only admin!!")
return
- pids=get_model("clinic.patient").search([['state','=','dispose']])
- count=0
- for visit in get_model("clinic.visit").search_browse([['patient_id','in',pids]]):
- if visit.state=='confirmed':
- continue
- visit.to_draft()
- hdcase=visit.hd_case_id
- if hdcase:
- hdcase.to_draft()
- hdcase.delete()
- visit.delete()
- count+=1
- print("count ", count)
+ for pt in get_model("clinic.patient").search_browse([]):
+ dates=[]
+ print("="*50)
+ for visit in pt.visits:
+ if visit.state=='confirmed':
+ continue
+ if visit.visit_date in dates:
+ print(pt.name, ' delete ', visit.visit_date)
+ visit.to_draft()
+ visit.delete()
+ dates.append(visit.visit_date)
+ print("="*50)
+ print("Done!")
+ return
+
+ def remove_douplicate_visit(self,ids,context={}):
+ user_id=get_active_user()
+ set_active_user(1)
+ for pt in get_model("clinic.patient").search_browse([]):
+ dates=[]
+ print("="*50)
+ for visit in pt.visits:
+ if visit.state=='confirmed':
+ continue
+ if visit.visit_date in dates:
+ print(pt.name, ' delete ', visit.visit_date)
+ visit.to_draft()
+ visit.delete()
+ dates.append(visit.visit_date)
+ print("="*50)
+ set_active_user(user_id)
print("Done!")
return