diff --git a/netforce_clinic/layouts/clinic_patient_form.xml b/netforce_clinic/layouts/clinic_patient_form.xml
index 0dccd6d..0c77b46 100644
--- a/netforce_clinic/layouts/clinic_patient_form.xml
+++ b/netforce_clinic/layouts/clinic_patient_form.xml
@@ -85,7 +85,7 @@
-
Note: "Main Department" คือ สถานที่ี่ที่ผู้ป่วยรักษาประจำ
+ Note: "Main Department" คือ สถานที่หลักที่ผู้ป่วยรักษา
diff --git a/netforce_clinic/layouts/clinic_setting.xml b/netforce_clinic/layouts/clinic_setting.xml
index 2325576..6fb2b83 100644
--- a/netforce_clinic/layouts/clinic_setting.xml
+++ b/netforce_clinic/layouts/clinic_setting.xml
@@ -1,6 +1,7 @@
diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py
index bf1ac48..1d28f8c 100644
--- a/netforce_clinic/models/setting.py
+++ b/netforce_clinic/models/setting.py
@@ -15,7 +15,7 @@ DAYS={
4: 'fri',
5: 'sat',
6: 'sun',
- }
+}
class ClinicSetting(Model):
_name="clinic.setting"
@@ -152,16 +152,8 @@ class ClinicSetting(Model):
if user_id !=1:
print("Only admin!!")
return
- for pt in get_model("clinic.patient").browse([1267]):
- print(pt.name or "")
- cycles={}
- for vs in pt.visits:
- date=vs.visit_date
- wd=datetime.strptime(date,"%Y-%m-%d").weekday()
- key='%s-%s-%s'%(vs.cycle_id.id, wd, vs.department_id.id)
- cycles[key]=key
- for k, v in cycles.items():
- print(k)
+ path='/tmp/test'
+ self.update_pcycle(path,['ls1.csv','ls2.csv','ls3.csv'])
###TODO remove douplicate patient
###TODO remove douplicate staff
###TODO remove douplicate visit
@@ -265,10 +257,13 @@ class ClinicSetting(Model):
print('Done!')
return
- def update_patient_file(self,files=[]):
+ def update_patient_file(self,path='/tmp/',file_lines=[]):
import csv
- for _file in files:
- f=open("/tmp/%s"%_file,"r")
+ for file_line in file_lines:
+ if path.endswith("/"):
+ path=path[0:len(path)-1] # remove /
+ fpath="/".join([path,file_line])
+ f=open(fpath,"r")
rd=csv.reader(f)
row1=next(rd)
headers=[]
@@ -363,8 +358,8 @@ class ClinicSetting(Model):
try:
m,d,y=(vals['birthday'] or "").split("/")
vals['birthday']='%s-%s-%s'%(y,m.zfill(2),d.zfill(2))
- except:
- pass
+ except Exception as e:
+ print("ERROR: ",e)
if not vals['card_no']:
vals['card_no']='/'
else:
@@ -377,10 +372,14 @@ class ClinicSetting(Model):
get_model("clinic.patient").browse(int(patient_id)).write(pvals)
print("Done!")
- def update_pcycle(self,files=[]):
+ def update_pcycle(self,path='/tmp/',file_lines=[]):
import csv
- for _file in files:
- f=open("/tmp/%s"%_file,"r")
+ for file_line in file_lines:
+ if path.endswith("/"):
+ path=path[0:len(path)-1] # remove /
+ fpath="/".join([path,file_line])
+ print('fpath ', fpath)
+ f=open(fpath,"r")
rd=csv.reader(f)
row1=next(rd)
headers=[]
@@ -472,10 +471,16 @@ class ClinicSetting(Model):
if dbid and cycle and day:
datas[dbid]['cycles'].append({'department_id': dpt, 'cycle_id': cycle, 'day': day})
- def del_pcycle(patient_id):
- ids=get_model("clinic.patient.cycle").search([['patient_id','=',patient_id]])
- get_model("clinic.patient.cycle").delete(ids)
- print("pcycle del ", ids)
+ def check_pcycle(patient_id,cycle_id,day,department_id):
+ dom=[
+ ['patient_id','=',patient_id],
+ ['cycle_id','=',cycle_id],
+ ['day','=',day],
+ ['department_id','=',department_id],
+ ]
+ ids=get_model("clinic.patient.cycle").search(dom)
+ print("found pcycle: ", ids)
+ return ids
def create_pcycle(all_vals):
new_ids=[]
for vals in all_vals:
@@ -487,25 +492,33 @@ class ClinicSetting(Model):
print("pcycle create ", new_ids)
print(" update patient data")
+ all_vals=[]
for patient_id, vals in datas.items():
if not patient_id:
continue
try:
m,d,y=(vals['birthday'] or "").split("/")
vals['birthday']='%s-%s-%s'%(y,m.zfill(2),d.zfill(2))
- except:
- pass
+ except Exception as e:
+ print("ERROR : ", e)
if not vals['card_no']:
vals['card_no']='/'
+ else:
+ #get only number
+ vals['card_no']=''.join([x for x in vals['card_no'] if x.isdigit()])
pvals=vals.copy()
del pvals['cycles']
- get_model("clinic.patient").browse(int(patient_id)).write(pvals)
- del_pcycle(patient_id)
- all_vals=[]
- for cycle_vals in vals['cycles']:
- cycle_vals.update({'patient_id': patient_id})
- all_vals.append(cycle_vals)
- create_pcycle(all_vals)
+ patient=get_model("clinic.patient").browse(int(patient_id))
+ print(patient_id, ' ----> ', pvals)
+ patient.write(pvals)
+ for cvals in vals['cycles']:
+ cycle_id=cvals['cycle_id']
+ day=cvals['day']
+ department_id=cvals['department_id']
+ if not check_pcycle(patient_id,cycle_id,day,department_id):
+ cvals.update({'patient_id': patient_id})
+ all_vals.append(cvals)
+ create_pcycle(all_vals)
print("Done!")
def update_staff_department(self,ids,context={}):
diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt
index 53c3c85..4df99c9 100644
--- a/netforce_clinic/todo.txt
+++ b/netforce_clinic/todo.txt
@@ -1,3 +1,6 @@
> script:
merge staff, patient
> invoice payment on rd shop
+
+> report:
+ improve cycle item report