improve
parent
34f4f66312
commit
f8e8f0f700
|
@ -43,7 +43,7 @@
|
||||||
<field name="patient_id" domain='[["type_id","=",type_id]]'/>
|
<field name="patient_id" domain='[["type_id","=",type_id]]'/>
|
||||||
<field name="partner_id" domain='[["is_patient","=","true"]]'/>
|
<field name="partner_id" domain='[["is_patient","=","true"]]'/>
|
||||||
<field name="hn"/>
|
<field name="hn"/>
|
||||||
<field name="card_no"/>
|
<!--<field name="card_no"/>-->
|
||||||
</list>
|
</list>
|
||||||
</field>
|
</field>
|
||||||
</tab>
|
</tab>
|
||||||
|
|
|
@ -153,6 +153,8 @@ class MatchingPayment(Model):
|
||||||
contact=patient_type.contact_id
|
contact=patient_type.contact_id
|
||||||
if not contact:
|
if not contact:
|
||||||
raise Exception("contact not found")
|
raise Exception("contact not found")
|
||||||
|
st=get_model("clinic.setting").browse(1)
|
||||||
|
patient_hn=st.get_patient_hn()
|
||||||
matches1={}
|
matches1={}
|
||||||
matches2={}
|
matches2={}
|
||||||
matches3={}
|
matches3={}
|
||||||
|
@ -166,14 +168,18 @@ class MatchingPayment(Model):
|
||||||
print("len(invoices)", len(invoices))
|
print("len(invoices)", len(invoices))
|
||||||
for invoice in invoices:
|
for invoice in invoices:
|
||||||
pname,hn,card_no='', '', ''
|
pname,hn,card_no='', '', ''
|
||||||
|
pname2=pname
|
||||||
if invoice.related_id:
|
if invoice.related_id:
|
||||||
hdcase=invoice.related_id
|
hdcase=invoice.related_id
|
||||||
patient=hdcase.patient_id
|
patient=hdcase.patient_id
|
||||||
pname=patient.name_check or ""
|
#pname=patient.name_check or "" #XXX
|
||||||
|
pname='%s%s'%(patient.first_name or "",patient.last_name or "")
|
||||||
|
pname2='%s %s'%(patient.first_name or "",patient.last_name or "")
|
||||||
card_no=patient.card_no or ""
|
card_no=patient.card_no or ""
|
||||||
hn=patient.hn_no
|
hn=patient.hn_no
|
||||||
elif invoice.ref:
|
elif invoice.ref:
|
||||||
pname=invoice.ref or ''
|
pname=invoice.ref or ''
|
||||||
|
pname2=pname
|
||||||
pname=pname.replace(" ","") # remove space
|
pname=pname.replace(" ","") # remove space
|
||||||
for pt in get_model("clinic.patient").search_browse([['name_check','=',pname]]):
|
for pt in get_model("clinic.patient").search_browse([['name_check','=',pname]]):
|
||||||
hn=pt.hn_no or ""
|
hn=pt.hn_no or ""
|
||||||
|
@ -201,8 +207,9 @@ class MatchingPayment(Model):
|
||||||
'fee': fee,
|
'fee': fee,
|
||||||
'epo': epo,
|
'epo': epo,
|
||||||
'srv': srv,
|
'srv': srv,
|
||||||
|
'name': pname2,
|
||||||
}
|
}
|
||||||
due_amount+=fee+epo+srv
|
due_amount+=fee+epo+srv #XXX
|
||||||
date=invoice.date
|
date=invoice.date
|
||||||
req_vals=[date,due_amount]
|
req_vals=[date,due_amount]
|
||||||
key1=':'.join([str(v) for v in [hn]+req_vals])
|
key1=':'.join([str(v) for v in [hn]+req_vals])
|
||||||
|
@ -282,7 +289,18 @@ class MatchingPayment(Model):
|
||||||
'state': 'match',
|
'state': 'match',
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
pass
|
# from ratchawat account settting
|
||||||
|
phn=patient_hn.get(hn)
|
||||||
|
if phn:
|
||||||
|
key1=':'.join([str(v) for v in [phn['hn']]+req_vals])
|
||||||
|
ss="not found"
|
||||||
|
if matches1.get(key1):
|
||||||
|
ss="found"
|
||||||
|
record.update({
|
||||||
|
'invoice_id': matches1[key1]['invoice_id'],
|
||||||
|
'state': 'match',
|
||||||
|
})
|
||||||
|
print(ss, ' account mathing ', key1)
|
||||||
## unmatch
|
## unmatch
|
||||||
records.append(record)
|
records.append(record)
|
||||||
elif obj.pcode=='UC':
|
elif obj.pcode=='UC':
|
||||||
|
@ -309,8 +327,9 @@ class MatchingPayment(Model):
|
||||||
hn=line['hn']
|
hn=line['hn']
|
||||||
hn=hn.replace(" ", "")
|
hn=hn.replace(" ", "")
|
||||||
key_uc=''
|
key_uc=''
|
||||||
|
req_vals=[date,fee]
|
||||||
if date and time:
|
if date and time:
|
||||||
key_uc='%s:%s:%s'%(line['hn'],date,fee,)
|
key_uc=':'.join([str(v) for v in [line['hn']]+req_vals])
|
||||||
pname=''
|
pname=''
|
||||||
pid=''
|
pid=''
|
||||||
for pt in get_model("clinic.patient").search_browse([['hn_no','=',hn]]):
|
for pt in get_model("clinic.patient").search_browse([['hn_no','=',hn]]):
|
||||||
|
@ -333,8 +352,23 @@ class MatchingPayment(Model):
|
||||||
'state': 'match',
|
'state': 'match',
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
pass
|
|
||||||
#print("not found")
|
#print("not found")
|
||||||
|
hn=hn.replace("-", "")
|
||||||
|
hn=hn.replace("/", "")
|
||||||
|
phn=patient_hn.get(hn)
|
||||||
|
if phn:
|
||||||
|
# match with name
|
||||||
|
key3=':'.join([str(v) for v in [phn['name']]+req_vals])
|
||||||
|
ss="not found"
|
||||||
|
mvals=matches3.get(key3)
|
||||||
|
if mvals:
|
||||||
|
ss="found"
|
||||||
|
record.update({
|
||||||
|
'invoice_id': mvals['invoice_id'],
|
||||||
|
'name': mvals['name'],
|
||||||
|
'state': 'match',
|
||||||
|
})
|
||||||
|
print(ss, ' account mathing ', key_uc)
|
||||||
records.append(record)
|
records.append(record)
|
||||||
if obj.hcode_id and not records:
|
if obj.hcode_id and not records:
|
||||||
raise Exception("Nothing to match! for %s"%(obj.hcode_id.name or ""))
|
raise Exception("Nothing to match! for %s"%(obj.hcode_id.name or ""))
|
||||||
|
|
|
@ -205,14 +205,15 @@ class Patient(Model):
|
||||||
obj=self.browse(obj_id)
|
obj=self.browse(obj_id)
|
||||||
partner_id=obj.partner_id
|
partner_id=obj.partner_id
|
||||||
if not partner_id:
|
if not partner_id:
|
||||||
for partner in get_model("partner").search_browse([['name', '=', obj.name]]):
|
partner_name='%s %s'%(obj.first_name or "",obj.last_name or "") # XXX
|
||||||
|
for partner in get_model("partner").search_browse([['name', '=', partner_name]]):
|
||||||
if partner.name==obj.name:
|
if partner.name==obj.name:
|
||||||
partner_id=partner.id
|
partner_id=partner.id
|
||||||
break
|
break
|
||||||
if not partner_id:
|
if not partner_id:
|
||||||
partner_id=get_model("partner").create({
|
partner_id=get_model("partner").create({
|
||||||
'name': obj.name,
|
'first_name': obj.first_name or "",
|
||||||
'last_name': obj.name,
|
'last_name': obj.last_name or "",
|
||||||
'type': 'person',
|
'type': 'person',
|
||||||
'is_patient': True,
|
'is_patient': True,
|
||||||
})
|
})
|
||||||
|
@ -299,18 +300,28 @@ class Patient(Model):
|
||||||
# create partner if not found
|
# create partner if not found
|
||||||
partner_id=obj.partner_id
|
partner_id=obj.partner_id
|
||||||
if not partner_id:
|
if not partner_id:
|
||||||
for partner in get_model("partner").search_browse([['name', '=', obj.name]]):
|
partner_name='%s %s'%(obj.first_name or "", obj.last_name or "") # XXX
|
||||||
|
for partner in get_model("partner").search_browse([['name', '=', partner_name]]):
|
||||||
if partner.name==obj.name:
|
if partner.name==obj.name:
|
||||||
partner_id=partner.id
|
partner_id=partner.id
|
||||||
break
|
break
|
||||||
if not partner_id:
|
if not partner_id:
|
||||||
partner_id=get_model("partner").create({
|
partner_id=get_model("partner").create({
|
||||||
'name': obj.name,
|
'first_name': obj.first_name or "",
|
||||||
'last_name': obj.name,
|
'last_name': obj.last_name or "",
|
||||||
'type': 'person',
|
'type': 'person',
|
||||||
'is_patient': True,
|
'is_patient': True,
|
||||||
})
|
})
|
||||||
vals['partner_id']=partner_id
|
vals['partner_id']=partner_id
|
||||||
|
|
||||||
|
#add to account setting
|
||||||
|
get_model("clinic.setting.account.patient").create({
|
||||||
|
'setting_id': 1,
|
||||||
|
'type_id': obj.type_id.id,
|
||||||
|
'patient_id': obj.id,
|
||||||
|
'partner_id': partner_id,
|
||||||
|
'hn': obj.hn_no,
|
||||||
|
})
|
||||||
if not isinstance(partner_id,int):
|
if not isinstance(partner_id,int):
|
||||||
partner_id=partner_id.id
|
partner_id=partner_id.id
|
||||||
if obj.addresses:
|
if obj.addresses:
|
||||||
|
@ -341,7 +352,9 @@ class Patient(Model):
|
||||||
for obj in self.browse(ids):
|
for obj in self.browse(ids):
|
||||||
print(obj.name or "")
|
print(obj.name or "")
|
||||||
obj.partner_id.write({
|
obj.partner_id.write({
|
||||||
'last_name': obj.name,
|
'type': 'person',
|
||||||
|
'first_name': obj.first_name or "",
|
||||||
|
'last_name': obj.last_name or "",
|
||||||
})
|
})
|
||||||
|
|
||||||
def name_get(self,ids,context={}):
|
def name_get(self,ids,context={}):
|
||||||
|
|
|
@ -136,18 +136,18 @@ class ClinicSetting(Model):
|
||||||
if user_id !=1:
|
if user_id !=1:
|
||||||
print("Only admin!!")
|
print("Only admin!!")
|
||||||
return
|
return
|
||||||
obj=self.browse(ids)[0]
|
|
||||||
lines=[]
|
|
||||||
for pt in get_model("clinic.patient").search_browse([]):
|
for pt in get_model("clinic.patient").search_browse([]):
|
||||||
lines.append(('create',{
|
pt.partner_id.write({
|
||||||
'patient_id': pt.id,
|
'type': 'person',
|
||||||
'partner_id': pt.partner_id.id,
|
'first_name': pt.first_name or "",
|
||||||
'type_id': pt.type_id.id,
|
'last_name': pt.last_name or "",
|
||||||
'hn': pt.hn_no,
|
})
|
||||||
'card_no': pt.card_no,
|
for st in get_model("clinic.staff").search_browse([]):
|
||||||
}))
|
st.partner_id.write({
|
||||||
obj.write({
|
'type': 'person',
|
||||||
'account_patients': lines,
|
'first_name': st.first_name or "",
|
||||||
|
'last_name': st.last_name or "",
|
||||||
})
|
})
|
||||||
print('Done!')
|
print('Done!')
|
||||||
return
|
return
|
||||||
|
@ -809,4 +809,19 @@ class ClinicSetting(Model):
|
||||||
break
|
break
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def get_patient_hn(self,ids,context={}):
|
||||||
|
obj=self.browse(ids)[0]
|
||||||
|
res={}
|
||||||
|
for line in obj.account_patients:
|
||||||
|
pt=line.patient_id
|
||||||
|
hn=line.hn
|
||||||
|
if hn not in res.keys():
|
||||||
|
res[hn]={
|
||||||
|
'hn': pt.hn,
|
||||||
|
'pid': pt.id,
|
||||||
|
'card_no': pt.card_no,
|
||||||
|
'name': "%s%s"%(pt.first_name or "", pt.last_name or ""),
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
|
||||||
ClinicSetting.register()
|
ClinicSetting.register()
|
||||||
|
|
|
@ -2,7 +2,7 @@ from netforce.model import Model, fields
|
||||||
|
|
||||||
class SettingAccountPatient(Model):
|
class SettingAccountPatient(Model):
|
||||||
_name="clinic.setting.account.patient"
|
_name="clinic.setting.account.patient"
|
||||||
_string="Setting Account Patient"
|
_string="Account Patient"
|
||||||
|
|
||||||
_fields={
|
_fields={
|
||||||
"setting_id": fields.Many2One("clinic.setting","Setting",required=True,on_delete="cascade"),
|
"setting_id": fields.Many2One("clinic.setting","Setting",required=True,on_delete="cascade"),
|
||||||
|
|
|
@ -256,15 +256,16 @@ class Staff(Model):
|
||||||
vals['name']='%s%s %s'%(title_name,vals['first_name'],vals['last_name'])
|
vals['name']='%s%s %s'%(title_name,vals['first_name'],vals['last_name'])
|
||||||
else:
|
else:
|
||||||
vals['name']='%s %s'%(vals['first_name'],vals['last_name'])
|
vals['name']='%s %s'%(vals['first_name'],vals['last_name'])
|
||||||
|
partner_name='%s %s'%(vals['first_name'],vals['last_name']) #XXX
|
||||||
employee_id=vals.get('employee_id')
|
employee_id=vals.get('employee_id')
|
||||||
name=vals['name']
|
name=vals['name']
|
||||||
emp_id=self.check_emp(name,employee_id)
|
emp_id=self.check_emp(name,employee_id)
|
||||||
if emp_id:
|
if emp_id:
|
||||||
vals['employee_id']=emp_id
|
vals['employee_id']=emp_id
|
||||||
partner_id=get_model("clinic.staff").check_contact(name)
|
partner_id=get_model("clinic.staff").check_contact(partner_name)
|
||||||
address_id=None
|
address_id=None
|
||||||
if not partner_id:
|
if not partner_id:
|
||||||
vals['partner_id'],address_id=self.create_contact(vals['number'],name)
|
vals['partner_id'],address_id=self.create_contact(vals['number'],partner_name)
|
||||||
new_id=super().create(vals,**kw)
|
new_id=super().create(vals,**kw)
|
||||||
self.function_store([new_id])
|
self.function_store([new_id])
|
||||||
for obj in self.browse([new_id]):
|
for obj in self.browse([new_id]):
|
||||||
|
@ -284,10 +285,11 @@ class Staff(Model):
|
||||||
emp_id=self.check_emp(name,obj.employee_id.id)
|
emp_id=self.check_emp(name,obj.employee_id.id)
|
||||||
if emp_id:
|
if emp_id:
|
||||||
vals['employee_id']=emp_id
|
vals['employee_id']=emp_id
|
||||||
partner_id=get_model("clinic.staff").check_contact(name)
|
partner_name='%s %s'%(obj.first_name or "",obj.last_name or "")
|
||||||
|
partner_id=get_model("clinic.staff").check_contact(partner_name)
|
||||||
address_id=None
|
address_id=None
|
||||||
if not partner_id:
|
if not partner_id:
|
||||||
vals['partner_id'],address_id=self.create_contact(name,name) #XXX
|
vals['partner_id'],address_id=self.create_contact(partner_name,partner_name) #XXX
|
||||||
super().write(ids,vals,**kw)
|
super().write(ids,vals,**kw)
|
||||||
self.function_store(ids)
|
self.function_store(ids)
|
||||||
if address_id:
|
if address_id:
|
||||||
|
|
Loading…
Reference in New Issue