2015-02-10 12:01:46 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
from netforce.model import Model, fields, get_model
|
|
|
|
from netforce.utils import get_file_path
|
|
|
|
|
|
|
|
class MatchingHDCase(Model):
|
|
|
|
_name="clinic.matching.hdcase"
|
|
|
|
_transient=True
|
|
|
|
|
|
|
|
_fields={
|
|
|
|
"date": fields.Date("Date", required=True),
|
|
|
|
'file': fields.File("File"),
|
|
|
|
}
|
|
|
|
|
|
|
|
def _get_date(self,context={}):
|
|
|
|
return time.strftime("%Y-%m-%d")
|
|
|
|
|
|
|
|
_defaults={
|
|
|
|
'date': _get_date,
|
|
|
|
}
|
|
|
|
|
|
|
|
def get_rows(self,fpath=None):
|
|
|
|
if not fpath:
|
|
|
|
raise Exception("File not found")
|
|
|
|
try:
|
|
|
|
# or codecs.open on Python 2
|
|
|
|
filedata = open(fpath, encoding='UTF-8').read()
|
|
|
|
except:
|
|
|
|
filedata = open(fpath, encoding='TIS-620').read()
|
|
|
|
lines=filedata.split("\n")
|
|
|
|
count=0
|
|
|
|
rows=[]
|
|
|
|
for line in lines:
|
|
|
|
#open
|
|
|
|
if '***' in line and count==0:
|
|
|
|
count+=1
|
|
|
|
#end
|
|
|
|
elif '***' in line and count==1:
|
|
|
|
count=0
|
|
|
|
|
|
|
|
#table content
|
|
|
|
if count==1:
|
|
|
|
line=line.replace("*","")
|
|
|
|
line=line.replace("|","")
|
|
|
|
i=0
|
|
|
|
vals={}
|
|
|
|
for l in line.split(","):
|
|
|
|
if l:
|
|
|
|
vals[i]=l
|
|
|
|
i+=1
|
|
|
|
# only right data
|
|
|
|
if vals:
|
|
|
|
if len(vals)>1:
|
|
|
|
rows.append(vals)
|
|
|
|
return rows
|
|
|
|
|
|
|
|
def get_report_data(self,ids,context={}):
|
|
|
|
hdcases={}
|
2015-02-10 16:08:38 +00:00
|
|
|
date=time.strftime("%Y-%m-%d")
|
2015-02-10 12:01:46 +00:00
|
|
|
if ids:
|
|
|
|
obj=self.browse(ids)[0]
|
2015-02-10 16:08:38 +00:00
|
|
|
date=obj.date
|
2015-02-10 12:01:46 +00:00
|
|
|
if obj.file:
|
|
|
|
fpath=get_file_path(obj.file)
|
|
|
|
rows=self.get_rows(fpath)
|
|
|
|
if not rows:
|
|
|
|
raise Exception("No Data")
|
|
|
|
#{0: ' A 01',
|
|
|
|
#1: ' 6',
|
|
|
|
#2: ' 11686',
|
|
|
|
#3: ' 91312851',
|
|
|
|
#4: ' 450124497',
|
|
|
|
#5: ' 27/01/2558 06:05:00',
|
|
|
|
#6: ' C',
|
|
|
|
#7: ' O',
|
|
|
|
#8: ' U ',
|
|
|
|
#9: ' N',
|
|
|
|
#10: ' Espogen',
|
|
|
|
#11: ' 4000',
|
|
|
|
#12: ' 30',
|
|
|
|
#13: ' 1',
|
|
|
|
#14: ' 0',
|
|
|
|
#15: ' 1500',
|
|
|
|
#16: ' 1500',
|
|
|
|
#17: ' 0',
|
|
|
|
#18: ' 1500',
|
|
|
|
#19: ' S',
|
|
|
|
#20: ' U '}
|
|
|
|
|
|
|
|
patients={}
|
2015-02-10 16:08:38 +00:00
|
|
|
for pt in get_model("clinic.patient").search_read([],['name','hn_no','type_id']):
|
2015-02-10 12:01:46 +00:00
|
|
|
hn=pt['hn_no']
|
|
|
|
patients[hn]={
|
|
|
|
'id': pt['id'],
|
|
|
|
'name': pt['name'] or '',
|
2015-02-10 16:08:38 +00:00
|
|
|
'type': pt['type_id'][1],
|
2015-02-10 12:01:46 +00:00
|
|
|
}
|
|
|
|
products={}
|
|
|
|
for prod in get_model("product").search_read([],['name']):
|
|
|
|
name=(prod['name'] or "").replace(" ", "")
|
|
|
|
name=name.upper()
|
|
|
|
products[name]=prod['id']
|
|
|
|
dom=[]
|
|
|
|
dom.append(['date',">=",obj.date])
|
|
|
|
dom.append(['date',"<=",obj.date])
|
|
|
|
dom.append(['state','!=','cancelled'])
|
|
|
|
hdcases={}
|
2015-02-10 16:08:38 +00:00
|
|
|
hdcases2={}
|
2015-02-10 12:01:46 +00:00
|
|
|
for hdcase in get_model("clinic.hd.case").search_browse(dom):
|
|
|
|
date=hdcase.date
|
|
|
|
hn=hdcase.patient_id.hn_no or 0
|
|
|
|
fee_amt=0
|
2015-02-10 16:08:38 +00:00
|
|
|
hct=hdcase.hct or "0"
|
|
|
|
hct=round(float(hct),2)
|
|
|
|
prod_line=[]
|
2015-02-10 12:01:46 +00:00
|
|
|
for line in hdcase.lines:
|
|
|
|
prod=line.product_id
|
|
|
|
categ=prod.categ_id
|
2015-02-10 16:08:38 +00:00
|
|
|
if categ and line.reimbursable=='yes':
|
2015-02-10 12:01:46 +00:00
|
|
|
if categ.code=='EPO':
|
2015-02-10 16:08:38 +00:00
|
|
|
prod_line.append((prod.name or "").upper())
|
2015-02-10 12:01:46 +00:00
|
|
|
elif categ.code=='FEE':
|
|
|
|
fee_amt=line.amount or 0
|
|
|
|
prod_name=','.join(prod_line)
|
2015-02-10 16:08:38 +00:00
|
|
|
key1='%s-%s-%s-%s-%s'%(date,hn,hct,prod_name,fee_amt)
|
|
|
|
hdcases[key1]={
|
2015-02-10 12:01:46 +00:00
|
|
|
'id': hdcase.id,
|
2015-02-10 16:08:38 +00:00
|
|
|
'number': hdcase.number or '',
|
|
|
|
'note': '',
|
2015-02-10 12:01:46 +00:00
|
|
|
}
|
2015-02-10 16:08:38 +00:00
|
|
|
key2='%s-%s'%(date,hn)
|
|
|
|
hdcases2[key2]={
|
|
|
|
'id': hdcase.id,
|
|
|
|
'number': hdcase.number or '',
|
|
|
|
'note': '%s, %s, %s, %s, %s'%(date,hn,hct,prod_name,fee_amt),
|
|
|
|
}
|
|
|
|
|
|
|
|
lines=[]
|
2015-02-10 12:01:46 +00:00
|
|
|
for row in rows:
|
|
|
|
vals=list(row.values())
|
2015-02-10 16:08:38 +00:00
|
|
|
date,_time=(vals[5] or "").split()
|
2015-02-10 12:01:46 +00:00
|
|
|
if len(date)<3:
|
|
|
|
raise Exception("Wrong format date")
|
|
|
|
d,m,y=date.split("/")
|
|
|
|
y=int(y)-543
|
|
|
|
date='%s-%s-%s'%(y,m,d)
|
|
|
|
hn=vals[3]
|
|
|
|
hn=''.join(x for x in (hn or "") if x.isdigit())
|
|
|
|
pt=patients.get(hn)
|
2015-02-10 16:08:38 +00:00
|
|
|
pt_type=''
|
2015-02-10 12:01:46 +00:00
|
|
|
pt_name=''
|
|
|
|
pt_id=None
|
|
|
|
if pt:
|
|
|
|
pt_name=pt['name']
|
|
|
|
pt_id=pt['id']
|
2015-02-10 16:08:38 +00:00
|
|
|
pt_type=pt['type']
|
|
|
|
hct=float(vals[12] or "0")
|
|
|
|
hct=round(hct,2)
|
2015-02-10 12:01:46 +00:00
|
|
|
fee_amt=float(vals[15] or "0")
|
2015-02-10 16:08:38 +00:00
|
|
|
fee_amt=round(fee_amt,2)
|
2015-02-10 12:01:46 +00:00
|
|
|
prod_name=vals[10] or ''
|
|
|
|
prod_name=prod_name.replace(" ", "")
|
|
|
|
prod_id=products.get(prod_name.upper(),None)
|
2015-02-10 16:08:38 +00:00
|
|
|
key1='%s-%s-%s-%s-%s'%(date,hn,hct,prod_name.upper(),fee_amt)
|
|
|
|
hdcase=hdcases.get(key1)
|
|
|
|
line_vals={
|
2015-02-10 12:01:46 +00:00
|
|
|
'hn': hn,
|
|
|
|
'date': date,
|
|
|
|
'patient_name': pt_name,
|
|
|
|
'patient_id': pt_id,
|
2015-02-10 16:08:38 +00:00
|
|
|
'patient_type': pt_type,
|
2015-02-10 12:01:46 +00:00
|
|
|
'hct': hct,
|
|
|
|
'prod_name': prod_name,
|
|
|
|
'prod_id': prod_id,
|
|
|
|
'fee_amt': fee_amt,
|
2015-02-10 16:08:38 +00:00
|
|
|
'note': '',
|
2015-02-10 12:01:46 +00:00
|
|
|
}
|
2015-02-10 16:08:38 +00:00
|
|
|
if hdcase:
|
|
|
|
line_vals['is_match']=True
|
|
|
|
line_vals['hd_case_id']=hdcase['id']
|
|
|
|
line_vals['hd_case_number']=hdcase['number']
|
|
|
|
else:
|
|
|
|
key2='%s-%s'%(date,hn)
|
|
|
|
hdcase2=hdcases2.get(key2)
|
|
|
|
if hdcase2:
|
|
|
|
line_vals['is_match']=False
|
|
|
|
line_vals['hd_case_id']=hdcase2['id']
|
|
|
|
line_vals['hd_case_number']=hdcase2['number']
|
|
|
|
line_vals['note']=hdcase2['note']
|
|
|
|
lines.append(line_vals)
|
2015-02-10 12:01:46 +00:00
|
|
|
no=1
|
|
|
|
lines2=[]
|
|
|
|
for line in sorted(lines,key=lambda x: x['hn']):
|
|
|
|
line['no']=no
|
|
|
|
lines2.append(line)
|
|
|
|
no+=1
|
|
|
|
lines=lines2
|
|
|
|
data={
|
|
|
|
'lines': lines,
|
2015-02-10 16:08:38 +00:00
|
|
|
'date': date,
|
2015-02-10 12:01:46 +00:00
|
|
|
}
|
|
|
|
return data
|
|
|
|
|
|
|
|
MatchingHDCase.register()
|