contact on patient type
parent
cf78444020
commit
57950fbf4f
|
@ -95,7 +95,10 @@
|
|||
</group>
|
||||
</tab>
|
||||
<tab string="Other">
|
||||
<field name="cycle_id"/>
|
||||
<group form_layout="stacked">
|
||||
<field name="cycle_id" span="2"/>
|
||||
<field name="hn_num" span="2"/>
|
||||
</group>
|
||||
</tab>
|
||||
</tabs>
|
||||
<related>
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
<form model="clinic.patient.type">
|
||||
<head>
|
||||
<button string="Options" dropdown="1">
|
||||
<item string="New Contact" method="new_contact"/>
|
||||
</button>
|
||||
</head>
|
||||
<field name="name"/>
|
||||
<field name="code"/>
|
||||
<field name="contact_id"/>
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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([])
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
- missing
|
||||
- import schedule -> wait K. Ekk
|
||||
- missing hd case in staff (nurse, doctor)
|
||||
|
||||
|
||||
===============
|
||||
|
||||
hd case
|
||||
start / stop -> option udpate time
|
||||
|
|
Loading…
Reference in New Issue