diff --git a/netforce_clinic/layouts/clinic_visit_form.xml b/netforce_clinic/layouts/clinic_visit_form.xml
index 033066d..98cff51 100644
--- a/netforce_clinic/layouts/clinic_visit_form.xml
+++ b/netforce_clinic/layouts/clinic_visit_form.xml
@@ -12,15 +12,15 @@
-
+
-
+
-
+
diff --git a/netforce_clinic/layouts/import_clinic_payment_form.xml b/netforce_clinic/layouts/import_clinic_payment_form.xml
index 6ee4b6b..56b21d0 100644
--- a/netforce_clinic/layouts/import_clinic_payment_form.xml
+++ b/netforce_clinic/layouts/import_clinic_payment_form.xml
@@ -8,8 +8,12 @@
-
+
+
+
+
+
diff --git a/netforce_clinic/layouts/import_clinic_visit.xml b/netforce_clinic/layouts/import_clinic_visit.xml
index eef257e..92ad2d1 100644
--- a/netforce_clinic/layouts/import_clinic_visit.xml
+++ b/netforce_clinic/layouts/import_clinic_visit.xml
@@ -2,6 +2,17 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/netforce_clinic/models/import_payment.py b/netforce_clinic/models/import_payment.py
index 5eee3d4..c6b1fb6 100644
--- a/netforce_clinic/models/import_payment.py
+++ b/netforce_clinic/models/import_payment.py
@@ -1,5 +1,5 @@
import time
-from datetime import datetime, timedelta
+from datetime import datetime
from calendar import monthrange
from netforce.model import Model, fields, get_model
@@ -49,10 +49,12 @@ class ImportPayment(Model):
'unmatch_qty': fields.Integer("UnMatch"),
'state': fields.Selection([['draft','Draft'],['confirmed','Confirmed'],['approved','Approved'],['fail','Fail'],['success','Success']],'State'),
'match_lines': fields.One2Many("import.clinic.payment.line","import_payment_id","Match",domain=[["state","=","match"]]),
- 'unmatch_lines': fields.One2Many("import.clinic.payment.line","import_payment_id","UnMatch",domain=[["state","=","unmatch"]]),
+ 'unmatch_lines': fields.One2Many("import.clinic.payment.line","import_payment_id","Un Match",domain=[["state","=","unmatch"]]),
'payment_id': fields.Many2One("account.payment","Payment"),
'company_id': fields.Many2One("company","Company"),
'partner_id': fields.Many2One("partner","Fee Contact",function="_get_partner"),
+ 'is_uc': fields.Integer("Is UC"),
+ 'node': fields.Char("Node"),
}
def get_hcode_id(self,context={}):
@@ -90,30 +92,26 @@ class ImportPayment(Model):
'type_id': _get_patient_type,
'max_row': 50,
'state': 'draft',
+ 'is_uc': 0,
+ 'node': 'HDBills',
}
-
- def import_payment(self,ids,context={}):
+
+ def import_payment_pks(self,ids,context={}):
fmt='%Y-%m-%d %H:%M:%S'
start_time=time.strftime(fmt)
obj=self.browse(ids)[0]
fname=obj.file
fpath=get_file_path(fname)
- patient_type=obj.type_id
- if patient_type.code in ('PKS'):
- lines=utils.read_excel(fpath,show_datetime=False)
- else:
- lines=utils.read_xml(fpath,show_datetime=False)
+ lines=utils.read_excel(fpath,show_datetime=False)
if not lines:
- raise Exception("Wrong File")
+ raise Exception("No data to import")
msg=""
nofound=0
blank=0
fail_qty=0
match_qty=0
unmatch_qty=0
-
msg+=""*10; msg+="hcode,hn,name,note\n"
-
print("getting invoice")
dom=[]
dom.append(['state','=','waiting_payment'])
@@ -156,9 +154,9 @@ class ImportPayment(Model):
patient_name=line.get("name14")
hn=line.get('hn',"")
hn_num=get_hn_num(hn)
- hct=line.get("hct","")
+ #hct=line.get("hct","")
inv_date=line.get("dttran")
- amount=line.get('amount23')
+ #amount=line.get('amount23')
hcode=line.get('hcode18','0')
if not hcode:
hcode='0'
@@ -228,6 +226,65 @@ class ImportPayment(Model):
'unmatch_lines': umlines,
})
print("Done!")
+ return {
+ 'next': {
+ 'name': 'import_clinic_payment',
+ 'mode': 'form',
+ 'active_id': obj.id,
+ },
+ 'flash': 'Import successfully'
+ }
+
+ def import_payment_uc(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ fname=obj.file
+ fpath=get_file_path(fname)
+ lines=utils.read_xml(fpath,node=obj.node)
+ if not lines:
+ raise Exception("No Data to import")
+ total=0.0
+ qty=0
+ import pprint
+ 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
+
+ print('Total: ', total)
+ print("Qty: ", qty)
+ obj.write({
+ 'match_qty': 0,
+ 'unmatch_qty': 0,
+ })
+ return {
+ 'next': {
+ 'name': 'import_clinic_payment',
+ 'mode': 'form',
+ 'active_id': obj.id,
+ },
+ 'flash': 'Import succeffully',
+ }
+
+ def import_payment(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ fname=obj.file
+ if not fname:
+ raise Exception("File not found")
+ patient_type=obj.type_id
+ res={}
+ if patient_type.code in ('PKS','SC'):
+ res=self.import_payment_pks(ids,context)
+ elif patient_type.code in ('UC','uc','UC.','uc.'):
+ res=self.import_payment_uc(ids,context)
+ else:
+ raise Exception("No script to import payment for type %s"%patient_type.name)
+ return res
def approve(self,ids,context={}):
obj=self.browse(ids)[0]
@@ -299,5 +356,21 @@ class ImportPayment(Model):
},
'flash': '%s has been paid'%obj.type_id.name,
}
+
+ def to_draft(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ obj.write({
+ 'state': 'draft',
+ })
+
+ def onchange_type(self,context={}):
+ data=context['data']
+ is_uc=0
+ type_id=data['type_id']
+ ptype=get_model('clinic.patient.type').browse(type_id)
+ if ptype.code=='UC':
+ is_uc=1
+ data['is_uc']=is_uc
+ return data
ImportPayment.register()
diff --git a/netforce_clinic/models/import_visit.py b/netforce_clinic/models/import_visit.py
index 5cc5218..7d440a5 100644
--- a/netforce_clinic/models/import_visit.py
+++ b/netforce_clinic/models/import_visit.py
@@ -13,8 +13,17 @@ class ImportVisit(Model):
'file': fields.File("File"),
'result': fields.Text("Success"),
'hcode_id': fields.Many2One("clinic.hospital", "Hospital",required=True),
+ 'patient_type_id': fields.Many2One('clinic.patient.type','Type',required=True),
+ 'msg': fields.Text("Message"),
+ 'done_qty': fields.Integer("Success"),
+ 'fail_qty': fields.Integer("Fail"),
}
+ def get_hcode(self,context={}):
+ settings=get_model("settings").browse(1)
+ hcode=settings.hospital_code or ""
+ return hcode
+
def get_hcode_id(self,context={}):
hp_ids=get_model("clinic.hospital").search([])
hp_id=None
@@ -22,20 +31,127 @@ class ImportVisit(Model):
hp_id=hp_ids[0]
return hp_id
+ def _get_patient_type(self,context={}):
+ st=get_model('clinic.setting').browse(1)
+ ptype=st.patient_type_id
+ ptype_id=None
+ if ptype:
+ ptype_id=ptype.id
+ return ptype_id
+
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
'hcode_id': get_hcode_id,
+ 'patient_type_id': _get_patient_type,
}
-
+
def import_visit(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ ptype=obj.patient_type_id
+ res={}
+ if ptype.code=='PKS':
+ res=self.import_visit_pks(ids,context)
+ elif ptype.code=='UC':
+ res=self.import_visit_uc(ids,context)
+ else:
+ raise Exception('No script to import visit with type %s'%ptype.name)
+ return res
+
+ def import_visit_uc(self,ids,context):
+ obj=self.browse(ids)[0]
+ #ptype=obj.patient_type_id
+ fname=obj.file
+ fpath=get_file_path(fname)
+ lines=utils.read_xml(fpath,node='HDBills')
+ if not lines:
+ raise Exception("Wrong File")
+ cycles=[(c['id'],'%s:00'%c['time_start'],'%s:00'%c['time_stop']) for c in get_model("clinic.cycle").search_read([[]],['time_start','time_stop'])]
+ patients={}
+ field_name=['name','hn','hn_num','department_id','doctor_id']
+ for pt in get_model("clinic.patient").search_read([[]],field_name):
+ hn_num=pt['hn_num']
+ dp=pt['department_id']
+ department_id=None
+ if dp:
+ department_id=dp[0]
+ doctor=pt['doctor_id']
+ doctor_id=None
+ if doctor:
+ doctor_id=doctor[0]
+
+ patients[hn_num]={
+ 'id': pt['id'],
+ 'hn': pt['hn'],
+ 'department_id': department_id,
+ 'doctor_id': doctor_id,
+ 'name': pt['name'],
+ }
+ done_qty=0
+ fail_qty=0
+ msg='hn,name,note\n'
+ def get_hn(hn=""):
+ return ''.join(h for h in hn if h.isdigit())
+
+ for line in lines:
+ hn_num=line.get('hn')
+ hn=get_hn(hn_num)
+ date,time=line.get("dttran").split("T")
+ patient=patients.get(hn)
+ if not patient:
+ fail_qty+=1
+ msg+='%s,%s,%s\n'%(hn_num,'','Not found hn')
+ continue
+ vals={
+ 'patient_id': patient['id'],
+ 'doctor_id': patient['doctor_id'],
+ 'department_id': patient['department_id'],
+ }
+ cycle_id=None
+ for cycle in cycles:
+ time_start=cycle[1]
+ time_stop=cycle[2]
+ if time >= time_start:
+ cycle_id=cycle[0]
+ vals['cycle_id']=cycle_id
+ vals['time_start']='%s %s'%(date,time_start)
+ vals['time_stop']='%s %s'%(date,time_stop)
+ if not cycle_id:
+ raise Exception("not found cycle on this time %s"%(time))
+ vals['visit_date']=date
+ dom=[]
+ dom.append(['visit_date','=',date])
+ dom.append(['patient_id','=',patient['id']])
+ visit_ids=get_model("clinic.visit").search(dom)
+ if not visit_ids:
+ visit_id=get_model('clinic.visit').create(vals)
+ done_qty+=1
+ msg+='%s,%s,%s\n'%(hn_num,patient['name'],'Create visit %s'%date)
+ print('create visit %s'%visit_id)
+
+ obj.write({
+ 'done_qty': done_qty,
+ 'fail_qty': fail_qty,
+ 'msg': msg,
+ })
+
+ return {
+ 'next': {
+ 'name': 'import_clinic_visit',
+ 'mode': 'form',
+ 'active_id': obj.id,
+ },
+ 'flash': 'Import successfully',
+ }
+
+ def import_visit_pks(self,ids,context={}):
obj=self.browse(ids)[0]
fname=obj.file
fpath=get_file_path(fname)
lines=utils.read_excel(fpath,show_datetime=True)
if not lines:
raise Exception("Wrong File")
+ cycles=[(c['id'],'%s:00'%c['time_start'],'%s:00'%c['time_stop']) for c in get_model("clinic.cycle").search_read([[]],['time_start','time_stop'])]
for line in lines:
- cycles=[(c['id'],'%s:00'%c['time_start'],'%s:00'%c['time_stop']) for c in get_model("clinic.cycle").search_read([[]],['time_start','time_stop'])]
hcode=line.get('hcode18')
if not hcode:
hcode='0'
@@ -43,7 +159,6 @@ class ImportVisit(Model):
hcode=str(hcode)
if obj.hcode_id.code==hcode:
name=line.get("name14")
- #hn=line.get('hn')
patient_ids=get_model("clinic.patient").search([['name','=',name]])
if patient_ids:
patient_id=patient_ids[0]
@@ -86,7 +201,7 @@ class ImportVisit(Model):
'mode': 'form',
'active_id': obj.id,
},
- 'flash': 'Create visit successully',
+ 'flash': 'Import successully',
}
ImportVisit.register()
diff --git a/netforce_clinic/models/utils.py b/netforce_clinic/models/utils.py
index 8f5a117..6280c1a 100644
--- a/netforce_clinic/models/utils.py
+++ b/netforce_clinic/models/utils.py
@@ -66,22 +66,24 @@ def read_excel(fpath=None,show_datetime=False):
data.append(d)
return data
-def read_xml(fpath=None,node=""):
+def read_xml(fpath=None,node="HDBills"):
+ root_name="STMSTM"
+ child_name=node
data={}
- if not node:
+ if not child_name:
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:
+ root=data.get(root_name)
+ lines=[]
+ if root:
+ child=root.get(child_name)
+ if not child:
return {}
- lines=[]
- for k, v in hdbills.items():
+ for k, v in child.items():
collections=v
for collection in collections:
if isinstance(collection,dict):
diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py
index 3f4d63f..fecdde8 100644
--- a/netforce_clinic/models/visit.py
+++ b/netforce_clinic/models/visit.py
@@ -89,6 +89,7 @@ class Visit(Model):
"state": "draft",
'time_start': _get_time_start,
'time_stop': _get_time_stop,
+ 'visit_date': lambda *a: time.strftime("%Y-%m-%d"),
"number": "/",
"company_id": lambda *a: get_active_company(),
'nurse_id': _get_nurse,
@@ -276,18 +277,32 @@ class Visit(Model):
}
return data
- def onchange_time(self,context={}):
+ def onchange_cycle(self,context={}):
data=context['data']
cycle_id=data['cycle_id']
- duration=1
+ date=data['visit_date']
+ if not date:
+ date=data['time_start'][0:10]
if cycle_id:
cycle=get_model('clinic.cycle').browse(cycle_id)
- duration=cycle.duration or 0
- seconds=duration*3600
- time_start=data['time_start']
- data['time_stop']=(datetime.strptime(time_start,FMT_DATE)+timedelta(seconds=seconds)).strftime(FMT_DATE)
+ data['time_start']=date+' %s:00'%cycle.time_start
+ data['time_stop']=date+' %s:00'%cycle.time_stop
return data
+ def onchange_date(self,context={}):
+ data=context['data']
+ date=data['visit_date']
+ time_start=data['time_start'][11:]
+ time_stop=data['time_stop'][11:]
+ data['time_start']='%s %s'%(date,time_start)
+ data['time_stop']='%s %s'%(date,time_stop)
+ return data
+
+ def onchange_datefrom(self,context={}):
+ data=context['data']
+ data['visit_date']=data['time_start'][0:10]
+ return data
+
def to_draft(self,ids,context={}):
obj=self.browse(ids)[0]
for hd_case in obj.hd_cases:
diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt
index 2681575..66b138b 100644
--- a/netforce_clinic/todo.txt
+++ b/netforce_clinic/todo.txt
@@ -3,7 +3,8 @@
- missing hd case in staff (nurse, doctor)
- special nurse
- report for show max cycle and got cycle
- - create journal entry
+ - create journal entry -> ok
+ - optimize
===============
hd case