2015-02-04 14:10:41 +00:00
|
|
|
import time
|
|
|
|
from calendar import monthrange
|
|
|
|
|
2015-01-16 11:19:49 +00:00
|
|
|
from netforce.model import Model, fields, get_model
|
2015-02-04 14:10:41 +00:00
|
|
|
from netforce.utils import get_file_path
|
|
|
|
|
|
|
|
from . import utils
|
2015-01-16 11:19:49 +00:00
|
|
|
|
|
|
|
class MatchingPayment(Model):
|
|
|
|
_name="clinic.matching.payment"
|
|
|
|
_transient=True
|
|
|
|
|
|
|
|
_fields={
|
2015-02-04 14:10:41 +00:00
|
|
|
"date": fields.Date("Month"),
|
|
|
|
"date_from": fields.Date("From", required=True),
|
|
|
|
"date_to": fields.Date("To", required=True),
|
2015-01-16 11:19:49 +00:00
|
|
|
'file': fields.File("File"),
|
|
|
|
'patient_type_id': fields.Many2One("clinic.patient.type","Patient Type",required=True),
|
2015-02-04 14:10:41 +00:00
|
|
|
'pcode': fields.Char("Code",required=True),
|
|
|
|
'hcode_id': fields.Many2One("clinic.hospital","HCode"),
|
2015-01-16 11:19:49 +00:00
|
|
|
'expenes': fields.Many2Many("clinic.hd.case.expense","Expenses"),
|
|
|
|
}
|
|
|
|
|
|
|
|
def _get_ptype(self,context={}):
|
|
|
|
tids=get_model('clinic.patient.type').search([['default','=',True]])
|
|
|
|
tid=None
|
|
|
|
if tids:
|
|
|
|
tid=tids[0]
|
|
|
|
return tid
|
|
|
|
|
2015-02-04 14:10:41 +00:00
|
|
|
def _get_pcode(self,context={}):
|
|
|
|
types=get_model('clinic.patient.type').search_browse([['default','=',True]])
|
|
|
|
if types:
|
|
|
|
return types[0].code
|
|
|
|
|
|
|
|
def _get_date_from(self,context={}):
|
|
|
|
year,month=time.strftime("%Y-%m").split("-")
|
|
|
|
return '%s-%s-01'%(year,month)
|
|
|
|
|
|
|
|
def _get_date_to(self,context={}):
|
|
|
|
year,month,day=time.strftime("%Y-%m-%d").split("-")
|
|
|
|
weekday, total_day=monthrange(int(year), int(month))
|
|
|
|
return "%s-%s-%s"%(year,month,total_day)
|
|
|
|
|
2015-01-16 11:19:49 +00:00
|
|
|
_defaults={
|
2015-02-04 14:10:41 +00:00
|
|
|
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
|
|
|
'date_from': _get_date_from,
|
|
|
|
'date_to': _get_date_to,
|
2015-01-16 11:19:49 +00:00
|
|
|
'patient_type_id': _get_ptype,
|
2015-02-04 14:10:41 +00:00
|
|
|
'pcode': _get_pcode,
|
2015-01-16 11:19:49 +00:00
|
|
|
}
|
2015-02-04 14:10:41 +00:00
|
|
|
|
|
|
|
def get_line(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
if not obj.file:
|
|
|
|
raise Exception("File not found!")
|
|
|
|
fname=obj.file
|
|
|
|
if obj.pcode=='SSO':
|
|
|
|
hcode=obj.hcode_id.code or ""
|
|
|
|
if not hcode:
|
|
|
|
raise Exception("Please input hcode")
|
|
|
|
n,sf=fname.split(".")
|
|
|
|
if sf not in ('xls','xlsx'):
|
|
|
|
raise Exception("File should be xls or xlsx")
|
|
|
|
fpath=get_file_path(fname)
|
|
|
|
lines=utils.read_excel(fpath,show_datetime=True)
|
|
|
|
|
|
|
|
elif obj.pcode=='UC':
|
|
|
|
fpath=get_file_path(fname)
|
|
|
|
node='HDBills'
|
|
|
|
lines=utils.read_xml(fpath,node=node)
|
|
|
|
hcode=fname.split("_")[0]
|
|
|
|
else:
|
|
|
|
raise Exception("Type %s is not support"%obj.pcode or "")
|
|
|
|
|
|
|
|
if not lines:
|
|
|
|
raise Exception("No data to match")
|
|
|
|
return lines
|
2015-01-16 11:19:49 +00:00
|
|
|
|
|
|
|
def match(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
2015-02-04 14:10:41 +00:00
|
|
|
lines=obj.get_line()
|
|
|
|
matches1={}
|
|
|
|
matches2={}
|
|
|
|
if obj.pcode=='SSO':
|
|
|
|
for line in lines:
|
|
|
|
hcode=line.get('hcode18')
|
|
|
|
if not hcode:
|
|
|
|
hcode='0'
|
|
|
|
hcode=int(hcode)
|
|
|
|
hcode=str(hcode)
|
|
|
|
if obj.hcode==hcode:
|
|
|
|
lsrv_amt=line.get('epoadm29') or 0
|
|
|
|
lfee_amt=line.get('amount23') or 0
|
|
|
|
lmdc_amt=line.get('allow37') or 0
|
|
|
|
dttran=line.get("dttran")
|
|
|
|
name=line.get("name14")
|
|
|
|
date=dttran[0:10]
|
|
|
|
time=dttran[11:] #XXX
|
|
|
|
if not time:
|
|
|
|
print("wrong format")
|
|
|
|
continue
|
|
|
|
hn=line.get('hn')
|
|
|
|
hn=''.join([x for x in hn if x.isdigit()])
|
|
|
|
key1='%s:%s:%s:%s:%s'%(
|
|
|
|
hn,
|
|
|
|
date,
|
|
|
|
lfee_amt,
|
|
|
|
lsrv_amt,
|
|
|
|
lmdc_amt,
|
|
|
|
)
|
|
|
|
key2='%s:%s:%s:%s:%s'%(
|
|
|
|
name,
|
|
|
|
date,
|
|
|
|
lfee_amt,
|
|
|
|
lsrv_amt,
|
|
|
|
lmdc_amt,
|
|
|
|
)
|
|
|
|
if not matches1.get(key1):
|
|
|
|
matches1[key1]=0
|
|
|
|
if not matches2.get(key2):
|
|
|
|
matches2[key2]=0
|
|
|
|
elif obj.pcode=='UC':
|
|
|
|
pass
|
|
|
|
|
2015-01-16 11:19:49 +00:00
|
|
|
exp_ids=[]
|
2015-02-04 14:10:41 +00:00
|
|
|
dom=[]
|
|
|
|
dom.append(['date',">=",obj.date_from])
|
|
|
|
dom.append(['date',"<=",obj.date_to])
|
|
|
|
|
|
|
|
return
|
|
|
|
for exp in get_model('clinic.hd.case.expense').search_browse(dom):
|
2015-01-16 11:19:49 +00:00
|
|
|
exp_ids.append(exp.id)
|
2015-02-04 14:10:41 +00:00
|
|
|
#TODO Checking
|
2015-01-16 11:19:49 +00:00
|
|
|
obj.write({
|
|
|
|
'expenes': [('add',exp_ids)]
|
|
|
|
})
|
|
|
|
return {
|
|
|
|
'next': {
|
|
|
|
'name': 'clinic_matching_payment',
|
|
|
|
'mode': 'form',
|
|
|
|
'active_id': obj.id,
|
|
|
|
},
|
|
|
|
'flash': 'Succesfully',
|
|
|
|
}
|
|
|
|
|
2015-02-04 14:10:41 +00:00
|
|
|
def onchange_date(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
date=data['date']
|
|
|
|
year,month,day=date.split("-")
|
|
|
|
weekday, total_day=monthrange(int(year), int(month))
|
|
|
|
data['date_from']="%s-%s-01"%(year,month)
|
|
|
|
data['date_to']="%s-%s-%s"%(year,month,total_day)
|
|
|
|
return data
|
|
|
|
|
|
|
|
def onchange_ptype(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
type_id=data['patient_type_id']
|
|
|
|
if type_id:
|
|
|
|
t=get_model('clinic.patient.type').browse(type_id)
|
|
|
|
data['pcode']=t.code or ""
|
|
|
|
return data
|
|
|
|
|
2015-01-16 11:19:49 +00:00
|
|
|
MatchingPayment.register()
|