update script
parent
1fb1de70cb
commit
75b47a9eb8
|
@ -85,7 +85,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<p></p>
|
<p></p>
|
||||||
<b>Note: </b><span style="color:green"><b style="color:#3477b0">"Main Department"</b> คือ สถานที่ี่ที่ผู้ป่วยรักษาประจำ</span></div>
|
<b>Note: </b><span style="color:green"><b style="color:#3477b0">"Main Department"</b> คือ สถานที่หลักที่ผู้ป่วยรักษา</span></div>
|
||||||
</template>
|
</template>
|
||||||
</group>
|
</group>
|
||||||
<group span="4" columns="1">
|
<group span="4" columns="1">
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<form model="clinic.setting" title="Clinic Settings">
|
<form model="clinic.setting" title="Clinic Settings">
|
||||||
<head>
|
<head>
|
||||||
<button string="Options" dropdown="1">
|
<button string="Options" dropdown="1">
|
||||||
|
<item string="Run Script" type="default" method="run_script" perm="clinic_setting_test"/>
|
||||||
<item string="Manual Generate Visit" perm="clinic_gen_visit" method="manual_generate_visit" confirm="This action will remove all pending visit of this month and generate new one. Are you sure?"/>
|
<item string="Manual Generate Visit" perm="clinic_gen_visit" method="manual_generate_visit" confirm="This action will remove all pending visit of this month and generate new one. Are you sure?"/>
|
||||||
</button>
|
</button>
|
||||||
</head>
|
</head>
|
||||||
|
@ -33,9 +34,4 @@
|
||||||
<separator string="RD Shop"/>
|
<separator string="RD Shop"/>
|
||||||
<field name="shop_type_id"/>
|
<field name="shop_type_id"/>
|
||||||
<field name="signature"/>
|
<field name="signature"/>
|
||||||
<tabs>
|
|
||||||
<tab string="Development">
|
|
||||||
<button string="Click Me" type="default" method="run_script" perm="clinic_setting_test"/>
|
|
||||||
</tab>
|
|
||||||
</tabs>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -15,7 +15,7 @@ DAYS={
|
||||||
4: 'fri',
|
4: 'fri',
|
||||||
5: 'sat',
|
5: 'sat',
|
||||||
6: 'sun',
|
6: 'sun',
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClinicSetting(Model):
|
class ClinicSetting(Model):
|
||||||
_name="clinic.setting"
|
_name="clinic.setting"
|
||||||
|
@ -152,16 +152,8 @@ class ClinicSetting(Model):
|
||||||
if user_id !=1:
|
if user_id !=1:
|
||||||
print("Only admin!!")
|
print("Only admin!!")
|
||||||
return
|
return
|
||||||
for pt in get_model("clinic.patient").browse([1267]):
|
path='/tmp/test'
|
||||||
print(pt.name or "")
|
self.update_pcycle(path,['ls1.csv','ls2.csv','ls3.csv'])
|
||||||
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)
|
|
||||||
###TODO remove douplicate patient
|
###TODO remove douplicate patient
|
||||||
###TODO remove douplicate staff
|
###TODO remove douplicate staff
|
||||||
###TODO remove douplicate visit
|
###TODO remove douplicate visit
|
||||||
|
@ -265,10 +257,13 @@ class ClinicSetting(Model):
|
||||||
print('Done!')
|
print('Done!')
|
||||||
return
|
return
|
||||||
|
|
||||||
def update_patient_file(self,files=[]):
|
def update_patient_file(self,path='/tmp/',file_lines=[]):
|
||||||
import csv
|
import csv
|
||||||
for _file in files:
|
for file_line in file_lines:
|
||||||
f=open("/tmp/%s"%_file,"r")
|
if path.endswith("/"):
|
||||||
|
path=path[0:len(path)-1] # remove /
|
||||||
|
fpath="/".join([path,file_line])
|
||||||
|
f=open(fpath,"r")
|
||||||
rd=csv.reader(f)
|
rd=csv.reader(f)
|
||||||
row1=next(rd)
|
row1=next(rd)
|
||||||
headers=[]
|
headers=[]
|
||||||
|
@ -363,8 +358,8 @@ class ClinicSetting(Model):
|
||||||
try:
|
try:
|
||||||
m,d,y=(vals['birthday'] or "").split("/")
|
m,d,y=(vals['birthday'] or "").split("/")
|
||||||
vals['birthday']='%s-%s-%s'%(y,m.zfill(2),d.zfill(2))
|
vals['birthday']='%s-%s-%s'%(y,m.zfill(2),d.zfill(2))
|
||||||
except:
|
except Exception as e:
|
||||||
pass
|
print("ERROR: ",e)
|
||||||
if not vals['card_no']:
|
if not vals['card_no']:
|
||||||
vals['card_no']='/'
|
vals['card_no']='/'
|
||||||
else:
|
else:
|
||||||
|
@ -377,10 +372,14 @@ class ClinicSetting(Model):
|
||||||
get_model("clinic.patient").browse(int(patient_id)).write(pvals)
|
get_model("clinic.patient").browse(int(patient_id)).write(pvals)
|
||||||
print("Done!")
|
print("Done!")
|
||||||
|
|
||||||
def update_pcycle(self,files=[]):
|
def update_pcycle(self,path='/tmp/',file_lines=[]):
|
||||||
import csv
|
import csv
|
||||||
for _file in files:
|
for file_line in file_lines:
|
||||||
f=open("/tmp/%s"%_file,"r")
|
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)
|
rd=csv.reader(f)
|
||||||
row1=next(rd)
|
row1=next(rd)
|
||||||
headers=[]
|
headers=[]
|
||||||
|
@ -472,10 +471,16 @@ class ClinicSetting(Model):
|
||||||
if dbid and cycle and day:
|
if dbid and cycle and day:
|
||||||
datas[dbid]['cycles'].append({'department_id': dpt, 'cycle_id': cycle, 'day': day})
|
datas[dbid]['cycles'].append({'department_id': dpt, 'cycle_id': cycle, 'day': day})
|
||||||
|
|
||||||
def del_pcycle(patient_id):
|
def check_pcycle(patient_id,cycle_id,day,department_id):
|
||||||
ids=get_model("clinic.patient.cycle").search([['patient_id','=',patient_id]])
|
dom=[
|
||||||
get_model("clinic.patient.cycle").delete(ids)
|
['patient_id','=',patient_id],
|
||||||
print("pcycle del ", ids)
|
['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):
|
def create_pcycle(all_vals):
|
||||||
new_ids=[]
|
new_ids=[]
|
||||||
for vals in all_vals:
|
for vals in all_vals:
|
||||||
|
@ -487,25 +492,33 @@ class ClinicSetting(Model):
|
||||||
print("pcycle create ", new_ids)
|
print("pcycle create ", new_ids)
|
||||||
|
|
||||||
print(" update patient data")
|
print(" update patient data")
|
||||||
|
all_vals=[]
|
||||||
for patient_id, vals in datas.items():
|
for patient_id, vals in datas.items():
|
||||||
if not patient_id:
|
if not patient_id:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
m,d,y=(vals['birthday'] or "").split("/")
|
m,d,y=(vals['birthday'] or "").split("/")
|
||||||
vals['birthday']='%s-%s-%s'%(y,m.zfill(2),d.zfill(2))
|
vals['birthday']='%s-%s-%s'%(y,m.zfill(2),d.zfill(2))
|
||||||
except:
|
except Exception as e:
|
||||||
pass
|
print("ERROR : ", e)
|
||||||
if not vals['card_no']:
|
if not vals['card_no']:
|
||||||
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()
|
pvals=vals.copy()
|
||||||
del pvals['cycles']
|
del pvals['cycles']
|
||||||
get_model("clinic.patient").browse(int(patient_id)).write(pvals)
|
patient=get_model("clinic.patient").browse(int(patient_id))
|
||||||
del_pcycle(patient_id)
|
print(patient_id, ' ----> ', pvals)
|
||||||
all_vals=[]
|
patient.write(pvals)
|
||||||
for cycle_vals in vals['cycles']:
|
for cvals in vals['cycles']:
|
||||||
cycle_vals.update({'patient_id': patient_id})
|
cycle_id=cvals['cycle_id']
|
||||||
all_vals.append(cycle_vals)
|
day=cvals['day']
|
||||||
create_pcycle(all_vals)
|
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!")
|
print("Done!")
|
||||||
|
|
||||||
def update_staff_department(self,ids,context={}):
|
def update_staff_department(self,ids,context={}):
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
> script:
|
> script:
|
||||||
merge staff, patient
|
merge staff, patient
|
||||||
> invoice payment on rd shop
|
> invoice payment on rd shop
|
||||||
|
|
||||||
|
> report:
|
||||||
|
improve cycle item report
|
||||||
|
|
Loading…
Reference in New Issue