From f8e8f0f700c3691bfa3802b64cfc99d2c0db407e Mon Sep 17 00:00:00 2001 From: "watcha.h@almacom.co.th" Date: Wed, 11 Mar 2015 17:08:42 +0700 Subject: [PATCH] improve --- .../layouts/clinic_account_setting.xml | 2 +- netforce_clinic/models/matching_payment.py | 44 ++++++++++++++++--- netforce_clinic/models/patient.py | 27 +++++++++--- netforce_clinic/models/setting.py | 39 +++++++++++----- .../models/setting_account_patient.py | 2 +- netforce_clinic/models/staff.py | 10 +++-- 6 files changed, 94 insertions(+), 30 deletions(-) diff --git a/netforce_clinic/layouts/clinic_account_setting.xml b/netforce_clinic/layouts/clinic_account_setting.xml index 450d1bf..b2bc491 100644 --- a/netforce_clinic/layouts/clinic_account_setting.xml +++ b/netforce_clinic/layouts/clinic_account_setting.xml @@ -43,7 +43,7 @@ - + diff --git a/netforce_clinic/models/matching_payment.py b/netforce_clinic/models/matching_payment.py index b66c21a..2bec042 100644 --- a/netforce_clinic/models/matching_payment.py +++ b/netforce_clinic/models/matching_payment.py @@ -153,6 +153,8 @@ class MatchingPayment(Model): contact=patient_type.contact_id if not contact: raise Exception("contact not found") + st=get_model("clinic.setting").browse(1) + patient_hn=st.get_patient_hn() matches1={} matches2={} matches3={} @@ -166,14 +168,18 @@ class MatchingPayment(Model): print("len(invoices)", len(invoices)) for invoice in invoices: pname,hn,card_no='', '', '' + pname2=pname if invoice.related_id: hdcase=invoice.related_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 "" hn=patient.hn_no elif invoice.ref: pname=invoice.ref or '' + pname2=pname pname=pname.replace(" ","") # remove space for pt in get_model("clinic.patient").search_browse([['name_check','=',pname]]): hn=pt.hn_no or "" @@ -201,8 +207,9 @@ class MatchingPayment(Model): 'fee': fee, 'epo': epo, 'srv': srv, + 'name': pname2, } - due_amount+=fee+epo+srv + due_amount+=fee+epo+srv #XXX date=invoice.date req_vals=[date,due_amount] key1=':'.join([str(v) for v in [hn]+req_vals]) @@ -282,7 +289,18 @@ class MatchingPayment(Model): 'state': 'match', }) 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 records.append(record) elif obj.pcode=='UC': @@ -309,8 +327,9 @@ class MatchingPayment(Model): hn=line['hn'] hn=hn.replace(" ", "") key_uc='' + req_vals=[date,fee] 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='' pid='' for pt in get_model("clinic.patient").search_browse([['hn_no','=',hn]]): @@ -333,8 +352,23 @@ class MatchingPayment(Model): 'state': 'match', }) else: - pass #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) if obj.hcode_id and not records: raise Exception("Nothing to match! for %s"%(obj.hcode_id.name or "")) diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py index b99d243..297e1a7 100644 --- a/netforce_clinic/models/patient.py +++ b/netforce_clinic/models/patient.py @@ -205,14 +205,15 @@ class Patient(Model): obj=self.browse(obj_id) partner_id=obj.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: partner_id=partner.id break if not partner_id: partner_id=get_model("partner").create({ - 'name': obj.name, - 'last_name': obj.name, + 'first_name': obj.first_name or "", + 'last_name': obj.last_name or "", 'type': 'person', 'is_patient': True, }) @@ -299,18 +300,28 @@ class Patient(Model): # create partner if not found partner_id=obj.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: partner_id=partner.id break if not partner_id: partner_id=get_model("partner").create({ - 'name': obj.name, - 'last_name': obj.name, + 'first_name': obj.first_name or "", + 'last_name': obj.last_name or "", 'type': 'person', 'is_patient': True, }) 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): partner_id=partner_id.id if obj.addresses: @@ -341,7 +352,9 @@ class Patient(Model): for obj in self.browse(ids): print(obj.name or "") 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={}): diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py index e77a313..a0bc4ec 100644 --- a/netforce_clinic/models/setting.py +++ b/netforce_clinic/models/setting.py @@ -136,19 +136,19 @@ class ClinicSetting(Model): if user_id !=1: print("Only admin!!") return - obj=self.browse(ids)[0] - lines=[] + for pt in get_model("clinic.patient").search_browse([]): - lines.append(('create',{ - 'patient_id': pt.id, - 'partner_id': pt.partner_id.id, - 'type_id': pt.type_id.id, - 'hn': pt.hn_no, - 'card_no': pt.card_no, - })) - obj.write({ - 'account_patients': lines, - }) + pt.partner_id.write({ + 'type': 'person', + 'first_name': pt.first_name or "", + 'last_name': pt.last_name or "", + }) + for st in get_model("clinic.staff").search_browse([]): + st.partner_id.write({ + 'type': 'person', + 'first_name': st.first_name or "", + 'last_name': st.last_name or "", + }) print('Done!') return @@ -809,4 +809,19 @@ class ClinicSetting(Model): break 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() diff --git a/netforce_clinic/models/setting_account_patient.py b/netforce_clinic/models/setting_account_patient.py index 104509c..daacbe8 100644 --- a/netforce_clinic/models/setting_account_patient.py +++ b/netforce_clinic/models/setting_account_patient.py @@ -2,7 +2,7 @@ from netforce.model import Model, fields class SettingAccountPatient(Model): _name="clinic.setting.account.patient" - _string="Setting Account Patient" + _string="Account Patient" _fields={ "setting_id": fields.Many2One("clinic.setting","Setting",required=True,on_delete="cascade"), diff --git a/netforce_clinic/models/staff.py b/netforce_clinic/models/staff.py index 8a193bd..fe11fbc 100644 --- a/netforce_clinic/models/staff.py +++ b/netforce_clinic/models/staff.py @@ -256,15 +256,16 @@ class Staff(Model): vals['name']='%s%s %s'%(title_name,vals['first_name'],vals['last_name']) else: 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') name=vals['name'] emp_id=self.check_emp(name,employee_id) if 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 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) self.function_store([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) if 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 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) self.function_store(ids) if address_id: