From 75acc0e98a23b938154f1904656594793989b5fe Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Fri, 6 Mar 2015 18:30:00 +0700 Subject: [PATCH] report cycle item --- netforce_clinic/models/report_cycle_item.py | 2 +- netforce_clinic/models/setting.py | 110 +++++++++++++++++++- 2 files changed, 110 insertions(+), 2 deletions(-) diff --git a/netforce_clinic/models/report_cycle_item.py b/netforce_clinic/models/report_cycle_item.py index 077a215..af70a26 100644 --- a/netforce_clinic/models/report_cycle_item.py +++ b/netforce_clinic/models/report_cycle_item.py @@ -63,7 +63,7 @@ class ReportCycleItem(Model): dom.append(['department_id','=',department_id]) no=1 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: patient=hdcase.patient_id ptype=patient.type_id diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py index a9c247a..1370258 100644 --- a/netforce_clinic/models/setting.py +++ b/netforce_clinic/models/setting.py @@ -133,9 +133,117 @@ class ClinicSetting(Model): def run_script(self,ids,context={}): 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!") + def update_pcycle(self,files=[]): import csv for _file in files: