From bdb5697d7b97fa65d625ed1a809289ba80787a71 Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Thu, 4 Dec 2014 15:37:54 +0700 Subject: [PATCH] improve --- .../layouts/clinic_hd_case_form.xml | 2 +- .../layouts/clinic_patient_type_form.xml | 13 +- .../layouts/clinic_patient_type_list.xml | 1 + .../layouts/import_clinic_payment_form.xml | 2 + netforce_clinic/models/hd_case.py | 11 +- netforce_clinic/models/import_payment.py | 111 ++++++++++-------- netforce_clinic/models/import_payment_line.py | 1 + netforce_clinic/models/patient.py | 9 ++ netforce_clinic/models/patient_type.py | 12 +- netforce_clinic/models/visit.py | 8 +- 10 files changed, 104 insertions(+), 66 deletions(-) diff --git a/netforce_clinic/layouts/clinic_hd_case_form.xml b/netforce_clinic/layouts/clinic_hd_case_form.xml index 4f8f5bd..5bd7cb1 100644 --- a/netforce_clinic/layouts/clinic_hd_case_form.xml +++ b/netforce_clinic/layouts/clinic_hd_case_form.xml @@ -3,7 +3,7 @@ diff --git a/netforce_clinic/layouts/clinic_patient_type_form.xml b/netforce_clinic/layouts/clinic_patient_type_form.xml index 8cbb8a5..1d77f04 100644 --- a/netforce_clinic/layouts/clinic_patient_type_form.xml +++ b/netforce_clinic/layouts/clinic_patient_type_form.xml @@ -4,13 +4,8 @@ - - - - - - - - - + + + + diff --git a/netforce_clinic/layouts/clinic_patient_type_list.xml b/netforce_clinic/layouts/clinic_patient_type_list.xml index 01d5129..b65bddd 100644 --- a/netforce_clinic/layouts/clinic_patient_type_list.xml +++ b/netforce_clinic/layouts/clinic_patient_type_list.xml @@ -2,4 +2,5 @@ + diff --git a/netforce_clinic/layouts/import_clinic_payment_form.xml b/netforce_clinic/layouts/import_clinic_payment_form.xml index 56b21d0..daa68e1 100644 --- a/netforce_clinic/layouts/import_clinic_payment_form.xml +++ b/netforce_clinic/layouts/import_clinic_payment_form.xml @@ -33,6 +33,7 @@ + @@ -40,6 +41,7 @@
+ diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index 13c9904..c4f2965 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -779,20 +779,21 @@ class HDCase(Model): return res - def get_staff_line(self,vals,patient_id=None): + def get_staff_fee(self,vals,patient_id=None): if not patient_id: return vals + # staff patient=get_model("clinic.patient").browse(patient_id) doctor=patient.doctor_id if doctor: + vals['staffs']=[] if not vals.get('staffs'): - vals['staffs']=[] vals['staffs'].append(('create',{ 'staff_id': doctor.id, 'type': 'doctor', 'priop': 'owner', })) - + # fee st=get_model("clinic.setting").browse(1) if not vals.get('lines'): vals['lines']=[] @@ -837,7 +838,7 @@ class HDCase(Model): def create(self,vals,**kw): patient_id=vals['patient_id'] - vals=self.get_staff_line(vals,patient_id) + vals=self.get_staff_fee(vals,patient_id) vals=self.get_invoice_policy(vals,patient_id) new_id=super().create(vals,**kw) return new_id @@ -846,7 +847,7 @@ class HDCase(Model): patient_id=vals.get('patient_id') # XXX importing problem # when change patient - #vals=self.get_staff_line(vals,patient_id) + #vals=self.get_staff_fee(vals,patient_id) vals=self.get_invoice_policy(vals,patient_id) super().write(ids,vals,**kw) diff --git a/netforce_clinic/models/import_payment.py b/netforce_clinic/models/import_payment.py index c6b1fb6..1532dfa 100644 --- a/netforce_clinic/models/import_payment.py +++ b/netforce_clinic/models/import_payment.py @@ -96,6 +96,49 @@ class ImportPayment(Model): 'node': 'HDBills', } + def get_patient_invoice(self,state="waiting_payment"): + print("getting patient invoice") + dom=[] + dom.append(['state','=',state]) + invoices={} + for inv in get_model("account.invoice").search_browse(dom): + hd_case=inv.related_id + patient=hd_case.patient_id + key=(inv.date,patient.id) + invoices[key]={ + 'id': inv.id, + 'amount_due': inv.amount_due, + 'hd_case_id': hd_case.id, + } + return invoices + + def get_all_patient(self): + print("getting patient") + patients={} + for pt in get_model("clinic.patient").search_read([[]],['name','hn','hn_num']): + key=pt['hn_num'] + patients[key]={ + 'id': pt['id'], + 'name': pt['name'], + } + return patients + + + def get_hd_case(self): + print("getting hd case") + hd_cases={} + for hd_case in get_model("clinic.hd.case").search_read([[]],['patient_id','date']): + patient_id=hd_case['patient_id'][0] + date=hd_case['date'] + key=(date,patient_id) + hd_cases[key]={ + 'id': hd_case['id'], + } + return hd_cases + + def get_hn_num(self,hn=""): + return ''.join(h for h in hn if h.isdigit()) + def import_payment_pks(self,ids,context={}): fmt='%Y-%m-%d %H:%M:%S' start_time=time.strftime(fmt) @@ -112,51 +155,18 @@ class ImportPayment(Model): match_qty=0 unmatch_qty=0 msg+=""*10; msg+="hcode,hn,name,note\n" - print("getting invoice") - dom=[] - dom.append(['state','=','waiting_payment']) - invoices={} - for inv in get_model("account.invoice").search_browse(dom): - hd_case=inv.related_id - patient=hd_case.patient_id - key=(inv.date,patient.id) - invoices[key]={ - 'id': inv.id, - 'amount_due': inv.amount_due, - 'hd_case_id': hd_case.id, - } - - print("getting patient") - patients={} - for pt in get_model("clinic.patient").search_read([[]],['hn','hn_num']): - key=pt['hn_num'] - patients[key]={ - 'id': pt['id'], - } - - print("getting hd case") - # need to optimize -> from, to - hd_cases={} - for hd_case in get_model("clinic.hd.case").search_read([[]],['patient_id','date']): - patient_id=hd_case['patient_id'][0] - date=hd_case['date'] - key=(date,patient_id) - hd_cases[key]={ - 'id': hd_case['id'], - } - def get_hn_num(hn=""): - return ''.join(h for h in hn if h.isdigit()) + invoices=self.get_patient_invoice(state='waiting_payment') + patients=self.get_all_patient() + hd_cases=self.get_hd_case() mlines=[] umlines=[] for line in lines: patient_name=line.get("name14") hn=line.get('hn',"") - hn_num=get_hn_num(hn) - #hct=line.get("hct","") + hn_num=self.get_hn_num(hn) inv_date=line.get("dttran") - #amount=line.get('amount23') hcode=line.get('hcode18','0') if not hcode: hcode='0' @@ -242,22 +252,26 @@ class ImportPayment(Model): lines=utils.read_xml(fpath,node=obj.node) if not lines: raise Exception("No Data to import") - total=0.0 - qty=0 - import pprint + + invoices=self.get_patient_invoice(state='waiting_payment') + patients=self.get_all_patient() + hd_cases=self.get_hd_case() + for line in lines: - pprint.pprint(line) date,time=line.get("dttran").split("T") invno=line.get("invno") hdrate=float(line.get("hdrate","0")) - hn=line.get("hn") - paid=float(line.get("paid","0")) - epostat=line.get('epostat') - total+=hdrate - qty+=1 + hn=line.get('hn',"") + hn_num=self.get_hn_num(hn) + #if hn+ + patient=patients.get(hn_num) + if patient: + key=(date,patient['id']) + if patient['id']==16953: + print("key ", patient) + #paid=float(line.get("paid","0")) + #epostat=line.get('epostat') - print('Total: ', total) - print("Qty: ", qty) obj.write({ 'match_qty': 0, 'unmatch_qty': 0, @@ -373,4 +387,5 @@ class ImportPayment(Model): data['is_uc']=is_uc return data + ImportPayment.register() diff --git a/netforce_clinic/models/import_payment_line.py b/netforce_clinic/models/import_payment_line.py index e1a20d0..4a0862c 100644 --- a/netforce_clinic/models/import_payment_line.py +++ b/netforce_clinic/models/import_payment_line.py @@ -7,6 +7,7 @@ class PaymentLine(Model): _fields={ 'import_payment_id': fields.Many2One("import.clinic.payment","Payment",required=True,on_delete="cascade"), 'date': fields.Date("Date"), + 'ref': fields.Char("Ref"), 'invoice_id': fields.Many2One("account.invoice","Invoice"), 'patient_id': fields.Many2One("clinic.patient","Patient"), 'hd_case_id': fields.Many2One("clinic.hd.case","HDCase"), diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py index ea0d6ee..1ece3e1 100644 --- a/netforce_clinic/models/patient.py +++ b/netforce_clinic/models/patient.py @@ -117,12 +117,21 @@ class Patient(Model): def _get_cause_line(self,context={}): cause_ids=get_model("clinic.cause.chronic").search([]) return cause_ids + + def _get_type(self,context={}): + ptype_id=None + for ptype in get_model("clinic.patient.type").search_browse([]): + if ptype.default: + ptype_id=ptype.id + break + return ptype_id _defaults={ "number": _get_number, "reg_date": lambda *a: time.strftime("%Y-%m-%d"), "company_id": lambda *a: get_active_company(), 'card_type': 'identification', + 'type_id': _get_type, "active" : True, } _order="resign_date desc,number desc" diff --git a/netforce_clinic/models/patient_type.py b/netforce_clinic/models/patient_type.py index c5fcee9..eb57061 100644 --- a/netforce_clinic/models/patient_type.py +++ b/netforce_clinic/models/patient_type.py @@ -9,6 +9,7 @@ class PatientType(Model): "name": fields.Char("Name",required=True,search=True), "code": fields.Char("Code",required=True,search=True), 'contact_id': fields.Many2One("partner","Contact",domain=[['type','=','org']],required=True,search=True), + 'default': fields.Boolean("Default"), } def new_contact(self,ids,context={}): @@ -27,6 +28,15 @@ class PatientType(Model): obj.write({ 'contact_id': new_contact_id, }) - + + def write(self,ids,vals,**kw): + default=vals.get('default') + if default: + for obj in self.search_browse([]): + if obj.id not in ids: + obj.write({ + 'default': False, + }) + super().write(ids,vals,**kw) PatientType.register() diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py index fecdde8..cfbce14 100644 --- a/netforce_clinic/models/visit.py +++ b/netforce_clinic/models/visit.py @@ -201,7 +201,7 @@ class Visit(Model): 'mode': 'form', 'active_id': hd_case_id, }, - 'flash': 'Visit %s has been confirmed'%obj.number, + 'flash': 'Visit has been confirmed', } def discard(self,ids,context={}): @@ -215,16 +215,20 @@ class Visit(Model): def onchange_patient(self,context={}): data=context['data'] patient_id=data['patient_id'] + patient=get_model("clinic.patient").browse(patient_id) visits=self.search_browse([['patient_id','=',patient_id]],order="number desc") if visits: visit=visits[0] doctor=visit.doctor_id department=visit.department_id if not department: - patient=get_model("clinic.patient").browse(patient_id) department=patient.department_id data['doctor_id']=doctor.id data['department_id']=department.id + if not patient.doctor_id: + patient.write({ + 'doctor_id': doctor.id, + }) else: data['doctor_id']=None data['department_id']=None