report cycle item

conv_bal
watcha.h 2015-03-06 18:30:00 +07:00
parent 86e6f77724
commit 75acc0e98a
2 changed files with 110 additions and 2 deletions

View File

@ -63,7 +63,7 @@ class ReportCycleItem(Model):
dom.append(['department_id','=',department_id]) dom.append(['department_id','=',department_id])
no=1 no=1
lines=[] lines=[]
for citem in get_model('clinic.cycle.item').search_browse(dom): for citem in get_model('clinic.cycle.item').search_browse(dom,order="date"):
for hdcase in citem.hd_cases: for hdcase in citem.hd_cases:
patient=hdcase.patient_id patient=hdcase.patient_id
ptype=patient.type_id ptype=patient.type_id

View File

@ -133,7 +133,115 @@ class ClinicSetting(Model):
def run_script(self,ids,context={}): def run_script(self,ids,context={}):
files=['SS3-1.csv','SS4-1.csv','SS4.csv'] files=['SS3-1.csv','SS4-1.csv','SS4.csv']
self.update_pcycle(files) self.update_patient_file(files)
print("Done!")
def update_patient_file(self,files=[]):
import csv
for _file in files:
f=open("/tmp/%s"%_file,"r")
rd=csv.reader(f)
row1=next(rd)
headers=[]
for header in row1:
header='_'.join([x.lower() for x in header.split()])
headers.append(header)
lines=[]
for row in rd:
vals=dict(zip(headers,row))
lines.append(vals)
def get_dicts(model_name,dom=[]):
res={}
if not model_name:
return res
for sr in get_model(model_name).search_read(dom,['name']):
res[sr['name']]=sr['id']
return res
vasculars=get_dicts('clinic.vascular.access')
cycles=get_dicts('clinic.cycle')
titles=get_dicts('clinic.name.title')
default_title=None
for tname, tid in titles.items():
if tname=='No Title':
default_title=tid
break
types=get_dicts('clinic.patient.type')
dpts=get_dicts('clinic.department')
doctors=get_dicts(model_name='clinic.staff',dom=['type','=','doctor'])
days={
'Monday': 'mon',
'Tuesday': 'tue',
'Wednesday': 'wed',
'Thursday': 'thu',
'Friday': 'fri',
'Saturday': 'sat',
'Sunday': 'sun',
}
datas={}
olds=set({})
dbid2=0
dpt_id=None
for line in lines:
dbid=line['database_id']
if dbid not in olds:
dbid=line['database_id']
dbid2=dbid
else:
dbid=dbid2
olds.update({dbid})
fname=line['first_name']
lname=line['last_name']
dname=line['doctor']
cycle=line['cycles/cycle']
cycle=cycles.get(cycle,None)
day=line['cycles/day']
day=days.get(day)
dpt=line['department']
dpt=dpts.get(dpt,None)
if not dpt:
dpt=dpt_id
else:
dpt_id=dpt
bday=line['birthday'] or None
title=line['title']
title=titles.get(title,default_title) or None
idcard=line['id_card']
trt=line['trt']
type=line['type']
type=types.get(type,None)
valc=line['vascular_ac.']
valc=vasculars.get(valc)
hn=line['hn_number']
if not datas.get(dbid):
datas[dbid]={
'card_no': (idcard or "").replace(" ",""),
'number': hn,
'type_id': type,
'first_name': fname,
'last_name': lname,
'birthday': bday,
'title_id': title,
'trt_no': trt,
'doctor_id': doctors.get(dname),
'vascular_acc': valc,
'department_id': dpt,
}
print(" update patient data")
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
if not vals['card_no']:
vals['card_no']='/'
pvals=vals.copy()
get_model("clinic.patient").browse(int(patient_id)).write(pvals)
print("Done!") print("Done!")
def update_pcycle(self,files=[]): def update_pcycle(self,files=[]):