From 57950fbf4f7c62ac866d290da9b0de89151d0d56 Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Tue, 2 Dec 2014 18:41:05 +0700 Subject: [PATCH] contact on patient type --- .../layouts/clinic_patient_form.xml | 5 +- .../layouts/clinic_patient_type_form.xml | 5 + netforce_clinic/models/hd_case.py | 4 + netforce_clinic/models/import_payment.py | 185 +++--------------- netforce_clinic/models/patient.py | 8 + netforce_clinic/models/patient_type.py | 22 ++- netforce_clinic/todo.txt | 4 + 7 files changed, 70 insertions(+), 163 deletions(-) diff --git a/netforce_clinic/layouts/clinic_patient_form.xml b/netforce_clinic/layouts/clinic_patient_form.xml index d9234df..d9635ec 100644 --- a/netforce_clinic/layouts/clinic_patient_form.xml +++ b/netforce_clinic/layouts/clinic_patient_form.xml @@ -95,7 +95,10 @@ - + + + + diff --git a/netforce_clinic/layouts/clinic_patient_type_form.xml b/netforce_clinic/layouts/clinic_patient_type_form.xml index 2735ffd..dc81533 100644 --- a/netforce_clinic/layouts/clinic_patient_type_form.xml +++ b/netforce_clinic/layouts/clinic_patient_type_form.xml @@ -1,4 +1,9 @@
+ + + diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index 985fd67..422db39 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -812,9 +812,12 @@ class HDCase(Model): 'qty': qty, 'amount': amt, })) + # XXX need to get default partner=patient.type_id.contact_id if partner: vals['fee_partner_id']=partner.id + if not partner: + raise Exception("Not found contact %s at menu: Patiens -> Type"%patient.type_id.name) return vals def get_invoice_policy(self,vals,patient_id=None): @@ -841,6 +844,7 @@ class HDCase(Model): def write(self,ids,vals,**kw): patient_id=vals.get('patient_id') # XXX import problem + # when change patient #vals=self.get_staff_line(vals,patient_id) vals=self.get_invoice_policy(vals,patient_id) obj=self.browse(ids)[0] diff --git a/netforce_clinic/models/import_payment.py b/netforce_clinic/models/import_payment.py index 25be19f..129647e 100644 --- a/netforce_clinic/models/import_payment.py +++ b/netforce_clinic/models/import_payment.py @@ -1,15 +1,10 @@ import time -import datetime -import xlrd -import xmltodict from netforce.model import Model, fields, get_model from netforce.access import get_active_company from netforce.utils import get_file_path -from netforce.utils import get_data_path -from netforce.database import get_connection -from pprint import pprint +from . import utils class ImportPayment(Model): _name="clinic.import.payment" @@ -32,60 +27,6 @@ class ImportPayment(Model): 'hcode': get_hcode, } - def read_excel(self,fpath=None): - data={} - if fpath: - suffix=fpath.split(".")[-1] - if suffix not in ('xls', 'xlsx'): - raise Exception("ERROR : please should file xls or xlsx") - wb=xlrd.open_workbook(fpath) - sheet=wb.sheet_by_name("Sheet1") - # read header values into the list - keys = [sheet.cell(0, col_index).value for col_index in range(sheet.ncols)] - data=[] - for row_index in range(1, sheet.nrows): - #d = {(keys[col_index] or "").lower(): sheet.cell(row_index, col_index).value for col_index in range(sheet.ncols)} - d={} - for col_index in range(sheet.ncols): - ctype=sheet.cell(row_index,col_index).ctype - if ctype==3: - value=sheet.cell(row_index, col_index).value - year, month, day, hour, minute, second = xlrd.xldate_as_tuple(value,wb.datemode) - value=datetime.datetime(year, month, day, hour, minute,second) - value=value.strftime("%Y-%m-%d") - else: - value=sheet.cell(row_index, col_index).value - d.update({(keys[col_index] or "").lower():value}) - data.append(d) - return data - - def read_xml(self,fpath=None,node=""): - data={} - if not node: - return data - if fpath: - suffix=fpath.split(".")[-1] - if suffix not in ('xml'): - raise Exception("ERROR : please should file xml") - data=xmltodict.parse(open(fpath,"r").read()) - - stmstm=data.get('STMSTM') - if stmstm: - hdbills=stmstm.get(node) - if not hdbills: - return {} - lines=[] - for k, v in hdbills.items(): - collections=v - for collection in collections: - if isinstance(collection,dict): - line={} - for i, j in collection.items(): - key=(i or "").lower() - line[key]=j - lines.append(line) - #titles=[title for title, value in lines[0].items()] - return lines def import_uc(self,ids,context={}): obj=self.browse(ids)[0] @@ -93,7 +34,7 @@ class ImportPayment(Model): fpath=get_file_path(fname) if not fpath: raise Exception("Please select file") - lines=self.read_xml(fpath,node='HDBills') + lines=utils.read_xml(fpath,node='HDBills') if not lines: raise Exception("Wrong file") data_uc=get_model("clinic.data.uc") @@ -120,10 +61,23 @@ class ImportPayment(Model): obj=self.browse(ids)[0] fname=obj.file fpath=get_file_path(fname) - lines=self.read_excel(fpath) + lines=utils.read_excel(fpath) if not lines: raise Exception("Wrong File") - + + patients={} + for pt in get_model("clinic.patient").search_read([[]],['hn_num','name']): + hn=pt['hn_num'] + if not hn: + continue + patients[hn]={ + 'id': pt['id'], + 'name': pt['name'], + } + + def get_hn_nu(hn=""): + return ''.join(x for x in hn if x.isdigit()) + for line in lines: hcode=line.get('hcode18','0') if not hcode: @@ -134,107 +88,18 @@ class ImportPayment(Model): invno=line.get("invno","") name=line.get("name14") hn=line.get('hn',"") + hn_num=get_hn_nu(hn) hct=line.get("HCT","") amount=line.get("amount23",0) dttran=line.get("dttran","") - #==== product ===== - prod_code=line.get("code31","") - prod_name=line.get('eponame',"") - prod_qty=line.get("qty",0) - prod_unit=line.get("unit32","") - prod_ids=get_model("product").search([['code','=',prod_code]]) - if not prod_ids: - print('create') - vals={ - 'code': prod_code, - 'name': prod_name, - 'type': 'stock', - } - unit_ids=get_model("uom").search([['name','=',prod_unit]]) - if not unit_ids: - prod_unit_id=get_model("uom").create({ - 'name': prod_unit, - 'type': 'unit', - }) - else: - prod_unit_id=unit_ids[0] - vals['uom_id']=prod_unit_id - prod_id=get_model("product").create(vals) - print("create product ", prod_id, prod_name) - # ================ - print(dttran, invno, hcode, hn, name, hct, amount) - return - - data_sc=get_model("clinic.data.sc") - sc_ids=data_sc.search([]) - data_sc.delete(sc_ids) - st={} - patient=get_model("clinic.patient") - old_patient=[x['hn'] for x in patient.search_read([],['hn']) if x['hn']] - fail_qty=0 - success_qty=0 - - hd_cases=get_model("clinic.hd.case").search_browse([['state','=','completed']]) - - def get_hdcase(hn,date): - for hd_case in hd_cases: - hd_date=hd_case.time_start[0:10] - if hn==hd_case.patient_id.hn and date==hd_date: #XXX - return hd_case.id - - for line in lines: - hn=line.get('hn') - if not hn: - continue - # create patient if not found - if not st.get(hn) and (not hn in old_patient): - patient.create({ - 'type': 'sc', - 'hn': hn, - 'name': line.get('name14'), - 'reg_date': time.strftime("%Y-%m-%d"), - }) - st.update({hn: line.get('name14')}) - print("create %s ok"%hn) - hcode=int((line.get('hcode18') or "0")) # XXX - type='match' - if hcode!=(int(obj.hcode)): - continue - - dttran=line.get("dttran","") - hd_case_id=get_hdcase(hn,dttran) - if hd_case_id: - success_qty+=1 - else: - fail_qty+=1 - type='not_match' - - vals={ - 'hn': hn, - 'name14': line.get('name14'), - 'hcode18': hcode, - 'amount23': line.get('amount23'), - "cur": line.get('cur'), - 'epoadm29': line.get('epoadm29'), - 'eponame': line.get('eponame'), - 'ln': line.get('ln'), - 'st': line.get('st'), - 'allow37': line.get('allow37'), - 'dttran': line.get("dttran"), - 'type': type, - 'hd_case_id': hd_case_id, - } - data_sc.create(vals) - msg='' - msg+="%s\n"%("*"*50) - msg+='success: %s\n'%success_qty - msg+='fail: %s\n'%fail_qty - msg+="%s\n"%("*"*50) - - obj.write({ - 'result': msg, - }) + vals=patients.get(hn_num) + if vals: + #print(vals) + pass + else: + print('not found ', hn, hn_num, name) + #print(dttran, invno, hcode, hn, name, hct, amount) def clear_sc(self,ids,context={}): sc_ids=get_model("clinic.data.sc").search([]) diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py index 66de882..ea0d6ee 100644 --- a/netforce_clinic/models/patient.py +++ b/netforce_clinic/models/patient.py @@ -32,10 +32,18 @@ class Patient(Model): res[obj.id]=cycle_id return res + def _get_hn_num(self,ids,context={}): + res={} + for obj in self.browse(ids): + hn=''.join(x for x in (obj.hn or "") if x.isdigit()) + res[obj.id]=hn + return res + _fields={ 'type_id': fields.Many2One("clinic.patient.type","Type",search=True,required=True), "number": fields.Char("Number",required=True,search=True), "hn": fields.Char("REF/HN",search=True), + "hn_num": fields.Char("HN Numeric",function="_get_hn_num"), "name": fields.Char("Name",required=True,search=True), "reg_date": fields.Date("Register Date",required=False,search=True), "birthday": fields.Date("Birthday",required=False,search=True), diff --git a/netforce_clinic/models/patient_type.py b/netforce_clinic/models/patient_type.py index f6c76f8..c5fcee9 100644 --- a/netforce_clinic/models/patient_type.py +++ b/netforce_clinic/models/patient_type.py @@ -1,4 +1,4 @@ -from netforce.model import Model, fields +from netforce.model import Model, fields, get_model class PatientType(Model): _name="clinic.patient.type" @@ -8,7 +8,25 @@ class PatientType(Model): _fields={ "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']]), + 'contact_id': fields.Many2One("partner","Contact",domain=[['type','=','org']],required=True,search=True), } + + def new_contact(self,ids,context={}): + obj=self.browse(ids)[0] + code=obj.code or "" + name=obj.name or "" + pids=get_model("partner").search([['code','=',code]]) + if not pids: + vals={ + 'name': name, + 'code': code, + 'customer': True, + 'type': 'org', + } + new_contact_id=get_model("partner").create(vals) + obj.write({ + 'contact_id': new_contact_id, + }) + PatientType.register() diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt index 1dbcd8d..0659875 100644 --- a/netforce_clinic/todo.txt +++ b/netforce_clinic/todo.txt @@ -1,5 +1,9 @@ - missing - import schedule -> wait K. Ekk + - missing hd case in staff (nurse, doctor) + + +=============== hd case start / stop -> option udpate time