update script
parent
1fb1de70cb
commit
75b47a9eb8
|
@ -85,7 +85,7 @@
|
|||
<template>
|
||||
<div>
|
||||
<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>
|
||||
</group>
|
||||
<group span="4" columns="1">
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<form model="clinic.setting" title="Clinic Settings">
|
||||
<head>
|
||||
<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?"/>
|
||||
</button>
|
||||
</head>
|
||||
|
@ -33,9 +34,4 @@
|
|||
<separator string="RD Shop"/>
|
||||
<field name="shop_type_id"/>
|
||||
<field name="signature"/>
|
||||
<tabs>
|
||||
<tab string="Development">
|
||||
<button string="Click Me" type="default" method="run_script" perm="clinic_setting_test"/>
|
||||
</tab>
|
||||
</tabs>
|
||||
</form>
|
||||
|
|
|
@ -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,24 +492,32 @@ 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)
|
||||
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!")
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
> script:
|
||||
merge staff, patient
|
||||
> invoice payment on rd shop
|
||||
|
||||
> report:
|
||||
improve cycle item report
|
||||
|
|
Loading…
Reference in New Issue