import
parent
7a384046fe
commit
a07f6025c2
|
@ -64,6 +64,9 @@
|
|||
<separator string="Doctor"/>
|
||||
<field name="cost_per_case"/>
|
||||
</tab>
|
||||
<tab string="Importing">
|
||||
<field name="patient_type_id"/>
|
||||
</tab>
|
||||
</tabs>
|
||||
<foot>
|
||||
</foot>
|
||||
|
|
|
@ -1,7 +1,18 @@
|
|||
<form title="Import Patient">
|
||||
<group form_layout="stacked">
|
||||
<field name="file" span="3"/>
|
||||
<field name="hcode" span="3"/>
|
||||
<field name="hcode_id" span="3"/>
|
||||
<field name="patient_type_id" span="3"/>
|
||||
<separator string="Summary"/>
|
||||
<tabs>
|
||||
<tab string="General">
|
||||
<field name="done_qty" readonly="1"/>
|
||||
<field name="fail_qty" readonly="1"/>
|
||||
</tab>
|
||||
<tab string="Message">
|
||||
<field name="msg" nolabel="1"/>
|
||||
</tab>
|
||||
</tabs>
|
||||
</group>
|
||||
<foot replace="1">
|
||||
<button string="Import" method="import_patient" type="primary" icon="arrow-right"/>
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
<!--<field name="remain_row" span="3" readonly="1"/>-->
|
||||
<field name="match_qty" span="3" readonly="1"/>
|
||||
<field name="unmatch_qty" span="3" readonly="1"/>
|
||||
<newline/>
|
||||
<field name="done_qty" span="3" readonly="1"/>
|
||||
<field name="fail_qty" span="3" readonly="1"/>
|
||||
<field name="est_time" span="3" readonly="1"/>
|
||||
<newline/>
|
||||
<!--<field name="done_qty" span="3" readonly="1"/>-->
|
||||
<field name="est_time" span="4" readonly="1"/>
|
||||
</tab>
|
||||
<tab string="Match">
|
||||
<field name="match_lines" nolabel="1">
|
||||
|
@ -66,8 +66,9 @@
|
|||
<tab string="Accounting">
|
||||
<group form_layout="stacked">
|
||||
<field name="payment_id" span="3" readonly="1"/>
|
||||
<field name="partner_id" span="3"/>
|
||||
<button string="Approve" method="approve" icon="ok" span="3"/>
|
||||
<button string="Approve" method="approve" icon="ok" span="3" confirm="Are you sure?"/>
|
||||
<newline/>
|
||||
<field name="partner_id" span="3" readonly="1"/>
|
||||
</group>
|
||||
</tab>
|
||||
</tabs>
|
||||
|
|
|
@ -12,7 +12,11 @@ class ImportPatient(Model):
|
|||
'date': fields.DateTime("Date"),
|
||||
'file': fields.File("File"),
|
||||
'result': fields.Text("Success"),
|
||||
'hcode': fields.Char("Hospital Code"),
|
||||
'hcode_id': fields.Many2One("clinic.hospital", "Hospital",required=True),
|
||||
'patient_type_id': fields.Many2One('clinic.patient.type','Type',required=True),
|
||||
'msg': fields.Text("Message"),
|
||||
'done_qty': fields.Integer("Success"),
|
||||
'fail_qty': fields.Integer("Fail"),
|
||||
}
|
||||
|
||||
def get_hcode(self,context={}):
|
||||
|
@ -20,35 +24,109 @@ class ImportPatient(Model):
|
|||
hcode=settings.hospital_code or ""
|
||||
return hcode
|
||||
|
||||
def get_hcode_id(self,context={}):
|
||||
hp_ids=get_model("clinic.hospital").search([])
|
||||
hp_id=None
|
||||
if hp_ids:
|
||||
hp_id=hp_ids[0]
|
||||
return hp_id
|
||||
|
||||
def _get_patient_type(self,context={}):
|
||||
st=get_model('clinic.setting').browse(1)
|
||||
ptype=st.patient_type_id
|
||||
ptype_id=None
|
||||
if ptype:
|
||||
ptype_id=ptype.id
|
||||
return ptype_id
|
||||
|
||||
_defaults={
|
||||
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
'hcode': get_hcode,
|
||||
'hcode_id': get_hcode_id,
|
||||
'patient_type_id': _get_patient_type,
|
||||
}
|
||||
|
||||
|
||||
def import_patient(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
ptype=obj.patient_type_id
|
||||
res={}
|
||||
if ptype.code=='PKS':
|
||||
res=self.import_patient_pks(ids,context)
|
||||
elif ptype.code=='UC':
|
||||
res=self.import_patient_uc(ids,context)
|
||||
else:
|
||||
raise Exception('No script to import patient with type %s'%ptype.name)
|
||||
|
||||
return res
|
||||
|
||||
def import_patient_uc(self,ids,context):
|
||||
obj=self.browse(ids)[0]
|
||||
#ptype=obj.patient_type_id
|
||||
fname=obj.file
|
||||
fpath=get_file_path(fname)
|
||||
lines=utils.read_xml(fpath,node='HDBills')
|
||||
if not lines:
|
||||
raise Exception("Wrong File")
|
||||
for line in lines:
|
||||
print(line)
|
||||
|
||||
return {
|
||||
'next': {
|
||||
'name': 'import_clinic_patient',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': 'Import successfully',
|
||||
}
|
||||
|
||||
def import_patient_pks(self,ids,context):
|
||||
obj=self.browse(ids)[0]
|
||||
ptype=obj.patient_type_id
|
||||
fname=obj.file
|
||||
fpath=get_file_path(fname)
|
||||
lines=utils.read_excel(fpath,show_datetime=True)
|
||||
if not lines:
|
||||
raise Exception("Wrong File")
|
||||
msg=""
|
||||
msg+="hcode,hn,name,note\n"
|
||||
done_qty=0
|
||||
fail_qty=0
|
||||
for line in lines:
|
||||
hcode=line.get('hcode18','0')
|
||||
if not hcode:
|
||||
hcode='0'
|
||||
hcode=int(hcode)
|
||||
hcode=str(hcode)
|
||||
if obj.hcode==hcode:
|
||||
name=line.get("name14")
|
||||
hn=line.get('hn',"")
|
||||
patient_ids=get_model("clinic.patient").search([['name','=',name]])
|
||||
hn=line.get('hn',"")
|
||||
patient_name=line.get("name14")
|
||||
if obj.hcode_id.code==hcode:
|
||||
patient_ids=get_model("clinic.patient").search([['name','=',patient_name]])
|
||||
|
||||
if not patient_ids:
|
||||
done_qty+=1
|
||||
vals={
|
||||
'name': name,
|
||||
'name': patient_name,
|
||||
'hn': hn,
|
||||
'type': 'sc',
|
||||
'type_id': ptype.id,
|
||||
}
|
||||
patient_id=get_model('clinic.patient').create(vals)
|
||||
msg+="%s,%s,%s,%s\n"%(hcode,hn,patient_name,"Created")
|
||||
print("create patient ", patient_id)
|
||||
else:
|
||||
if hcode!='0':
|
||||
msg+="%s,%s,%s,%s\n"%(hcode,hn,patient_name,"Wrong Code hospital")
|
||||
fail_qty+=1
|
||||
obj.write({
|
||||
'fail_qty': fail_qty,
|
||||
'done_qty': done_qty,
|
||||
'msg': msg,
|
||||
})
|
||||
return {
|
||||
'next': {
|
||||
'name': 'import_clinic_patient',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': 'Import successfully',
|
||||
}
|
||||
|
||||
ImportPatient.register()
|
||||
|
|
|
@ -18,6 +18,18 @@ class ImportPayment(Model):
|
|||
res[obj.id]=obj.type_id.name
|
||||
return res
|
||||
|
||||
def _get_partner(self,ids,context={}):
|
||||
res={}
|
||||
for obj in self.browse(ids):
|
||||
ptype=obj.type_id
|
||||
contact_id=None
|
||||
if ptype:
|
||||
contact=ptype.contact_id
|
||||
if contact:
|
||||
contact_id=contact.id
|
||||
res[obj.id]=contact_id
|
||||
return res
|
||||
|
||||
_fields={
|
||||
'name': fields.Char("Name",function="_get_name"),
|
||||
'type_id': fields.Many2One("clinic.patient.type","Patient Type",required=True),
|
||||
|
@ -28,19 +40,19 @@ class ImportPayment(Model):
|
|||
'file': fields.File("File"),
|
||||
'max_row': fields.Integer("Max Row"),
|
||||
'remain_row': fields.Integer("Pending"),
|
||||
'total_row': fields.Integer("Total Record"),
|
||||
'total_row': fields.Integer("Total"),
|
||||
'est_time': fields.Float("Estimate Time",scale=4),
|
||||
'msg': fields.Text("Message"),
|
||||
'done_qty': fields.Integer("Success"),
|
||||
'fail_qty': fields.Integer("Fail"),
|
||||
'fail_qty': fields.Integer("Other"),
|
||||
'match_qty': fields.Integer("Match"),
|
||||
'unmatch_qty': fields.Integer("UnMatch"),
|
||||
'state': fields.Selection([['draft','Draft'],['confirmed','Confirmed'],['fail','Fail'],['success','Success']],'State'),
|
||||
'state': fields.Selection([['draft','Draft'],['confirmed','Confirmed'],['approved','Approved'],['fail','Fail'],['success','Success']],'State'),
|
||||
'match_lines': fields.One2Many("import.clinic.payment.line","import_payment_id","Match",domain=[["state","=","match"]]),
|
||||
'unmatch_lines': fields.One2Many("import.clinic.payment.line","import_payment_id","UnMatch",domain=[["state","=","unmatch"]]),
|
||||
'payment_id': fields.Many2One("account.payment","Payment"),
|
||||
'company_id': fields.Many2One("company","Company"),
|
||||
'partner_id': fields.Many2One("partner","Partner"),
|
||||
'partner_id': fields.Many2One("partner","Fee Contact",function="_get_partner"),
|
||||
}
|
||||
|
||||
def get_hcode_id(self,context={}):
|
||||
|
@ -60,7 +72,14 @@ class ImportPayment(Model):
|
|||
year,month,day=datenow.split("-")
|
||||
weekday, total_day=monthrange(int(year), int(month))
|
||||
return '%s-%s-%s'%(year,month,total_day)
|
||||
|
||||
|
||||
def _get_patient_type(self,context={}):
|
||||
st=get_model('clinic.setting').browse(1)
|
||||
ptype=st.patient_type_id
|
||||
ptype_id=None
|
||||
if ptype:
|
||||
ptype_id=ptype.id
|
||||
return ptype_id
|
||||
|
||||
_defaults={
|
||||
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
||||
|
@ -68,6 +87,7 @@ class ImportPayment(Model):
|
|||
'date_to': _get_date_to,
|
||||
'hcode_id': get_hcode_id,
|
||||
'company_id': lambda *a: get_active_company(),
|
||||
'type_id': _get_patient_type,
|
||||
'max_row': 50,
|
||||
'state': 'draft',
|
||||
}
|
||||
|
@ -86,16 +106,13 @@ class ImportPayment(Model):
|
|||
if not lines:
|
||||
raise Exception("Wrong File")
|
||||
msg=""
|
||||
count=0
|
||||
nofound=0
|
||||
did=0
|
||||
blank=0
|
||||
fail_qty=0
|
||||
done_qty=0
|
||||
match_qty=0
|
||||
unmatch_qty=0
|
||||
|
||||
msg+=""*10; msg+="hcode,hn,name\n"
|
||||
msg+=""*10; msg+="hcode,hn,name,note\n"
|
||||
|
||||
print("getting invoice")
|
||||
dom=[]
|
||||
|
@ -136,7 +153,7 @@ class ImportPayment(Model):
|
|||
mlines=[]
|
||||
umlines=[]
|
||||
for line in lines:
|
||||
name=line.get("name14")
|
||||
patient_name=line.get("name14")
|
||||
hn=line.get('hn',"")
|
||||
hn_num=get_hn_num(hn)
|
||||
hct=line.get("hct","")
|
||||
|
@ -151,8 +168,10 @@ class ImportPayment(Model):
|
|||
if hcode:
|
||||
nofound+=1
|
||||
if hcode!='0':
|
||||
msg+="not found %s, %s, %s \n"%(hcode,hn,name)
|
||||
msg+="%s, %s, %s, Wrong hospital code \n"%(hcode,hn,patient_name)
|
||||
fail_qty+=1
|
||||
else:
|
||||
blank+=1
|
||||
else:
|
||||
blank+=1
|
||||
continue
|
||||
|
@ -176,13 +195,16 @@ class ImportPayment(Model):
|
|||
vals={
|
||||
'date': inv_date,
|
||||
'patient_id': patient_id,
|
||||
'amount': amount,
|
||||
}
|
||||
if hd_case:
|
||||
vals['hd_case_id']=hd_case['id']
|
||||
umlines.append(('create',vals))
|
||||
unmatch_qty+=1
|
||||
else:
|
||||
msg+="%s,%s,%s,Not found invoice on %s\n"%(hcode,hn,patient_name,inv_date)
|
||||
nofound+=1
|
||||
|
||||
unmatch_qty+=nofound #XXX
|
||||
for mline in obj.match_lines:
|
||||
mline.delete()
|
||||
for umline in obj.unmatch_lines:
|
||||
|
@ -191,9 +213,8 @@ class ImportPayment(Model):
|
|||
stop_time=time.strftime(fmt)
|
||||
est_time=datetime.strptime(stop_time,fmt)-datetime.strptime(start_time,fmt)
|
||||
|
||||
remain_row=len(lines)-blank-did-count
|
||||
if remain_row <= 0:
|
||||
msg="Nothing to import"
|
||||
total_row=len(lines)
|
||||
remain_row=total_row-blank-match_qty-unmatch_qty
|
||||
obj.write({
|
||||
'total_row': len(lines),
|
||||
'remain_row': remain_row-match_qty,
|
||||
|
@ -201,7 +222,7 @@ class ImportPayment(Model):
|
|||
'done_qty': match_qty+unmatch_qty,
|
||||
'fail_qty': fail_qty,
|
||||
'match_qty': match_qty,
|
||||
'unmatch_qty': unmatch_qty,
|
||||
'unmatch_qty': unmatch_qty-fail_qty,
|
||||
'est_time': est_time.seconds/3600,
|
||||
'match_lines': mlines,
|
||||
'unmatch_lines': umlines,
|
||||
|
@ -210,7 +231,7 @@ class ImportPayment(Model):
|
|||
|
||||
def approve(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
partner=obj.patient_id.partner_id
|
||||
partner=obj.partner_id
|
||||
if not partner:
|
||||
raise Exception("No contact on this patient")
|
||||
company_id=get_active_company()
|
||||
|
@ -220,30 +241,54 @@ class ImportPayment(Model):
|
|||
account_receivable_id=st.account_receivable_id
|
||||
if not account_receivable_id:
|
||||
raise Exception("Not found account recieveable in account setting")
|
||||
account_id=account_receivable_id.id
|
||||
if not account_id:
|
||||
raise Exception("No Account for payment")
|
||||
account_id=account_receivable_id.id
|
||||
datenow=time.strftime("%Y-%m-%d")
|
||||
vals={
|
||||
"partner_id": partner.id,
|
||||
"company_id": company_id,
|
||||
"type": "in",
|
||||
"pay_type": "invoice",
|
||||
'date': time.strftime("%Y-%m-%d"),
|
||||
'date': datenow,
|
||||
"account_id": account_id,
|
||||
'related_id': "clinic.hd.case,%s"%obj.id,
|
||||
'related_id': "import.clinic.payment,%s"%obj.id,
|
||||
'invoice_lines': [],
|
||||
}
|
||||
|
||||
for mline in obj.match_lines:
|
||||
inv=mline.invoice_id
|
||||
if inv:
|
||||
amt=inv.amount_due or 0.0
|
||||
vals['invoice_lines'].append(('create',{
|
||||
'type': 'invoice',
|
||||
'account_id': account_id,
|
||||
'invoice_id': inv.id,
|
||||
'amount': amt,
|
||||
}))
|
||||
|
||||
vals['invoice_lines'].append(('create',{
|
||||
'type': 'invoice',
|
||||
'description': 'Payment; %s'%obj.number,
|
||||
'account_id': account_id,
|
||||
'qty': 1,
|
||||
'unit_price': pay_amount,
|
||||
'amount': pay_amount,
|
||||
}))
|
||||
for umline in obj.unmatch_lines:
|
||||
inv=mline.invoice_id
|
||||
if inv:
|
||||
amt=inv.amount_due or 0.0
|
||||
vals['invoice_lines'].append(('create',{
|
||||
'type': 'invoice',
|
||||
'account_id': account_id,
|
||||
'invoice_id': inv.id,
|
||||
'amount': amt,
|
||||
}))
|
||||
|
||||
payment=obj.payment_id
|
||||
if payment:
|
||||
for inv_line in payment.invoice_lines:
|
||||
inv_line.delete()
|
||||
payment.write(vals)
|
||||
else:
|
||||
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
|
||||
vals['payment_id']=payment_id
|
||||
obj.write({
|
||||
'payment_id': payment_id,
|
||||
'state': 'approved',
|
||||
})
|
||||
|
||||
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
|
||||
#payment=get_model('account.payment').browse(payment_id)
|
||||
#payment.post()
|
||||
return {
|
||||
|
@ -252,7 +297,7 @@ class ImportPayment(Model):
|
|||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': 'Done!',
|
||||
'flash': '%s has been paid'%obj.type_id.name,
|
||||
}
|
||||
|
||||
ImportPayment.register()
|
||||
|
|
|
@ -5,6 +5,8 @@ from netforce.access import get_active_company
|
|||
class ClinicSetting(Model):
|
||||
_name="clinic.setting"
|
||||
_string="Setting"
|
||||
|
||||
|
||||
_fields={
|
||||
"var_k": fields.Float("K"),
|
||||
'file': fields.File("File"),
|
||||
|
@ -16,6 +18,7 @@ class ClinicSetting(Model):
|
|||
'period_id': fields.Many2One("clinic.period","Period"),
|
||||
'waiting_approval': fields.Boolean("Waiting Approval"),
|
||||
'real_time': fields.Boolean("Real Time"),
|
||||
'patient_type_id': fields.Many2One("clinic.patient.type","Default Type"),
|
||||
}
|
||||
|
||||
_defaults={
|
||||
|
|
Loading…
Reference in New Issue