diff --git a/netforce_clinic/actions/clinic_hospital.xml b/netforce_clinic/actions/clinic_hospital.xml
new file mode 100644
index 0000000..594f747
--- /dev/null
+++ b/netforce_clinic/actions/clinic_hospital.xml
@@ -0,0 +1,6 @@
+
+ Hospital
+ multi_view
+ clinic.hospital
+ clinic_menu
+
diff --git a/netforce_clinic/actions/import_clinic_payment.xml b/netforce_clinic/actions/import_clinic_payment.xml
new file mode 100644
index 0000000..11ee46d
--- /dev/null
+++ b/netforce_clinic/actions/import_clinic_payment.xml
@@ -0,0 +1,6 @@
+
+ Import Payment
+ multi_view
+ import.clinic.payment
+ clinic_menu
+
diff --git a/netforce_clinic/layouts/clinic_hospital_form.xml b/netforce_clinic/layouts/clinic_hospital_form.xml
new file mode 100644
index 0000000..658ea78
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_hospital_form.xml
@@ -0,0 +1,4 @@
+
diff --git a/netforce_clinic/layouts/clinic_hospital_list.xml b/netforce_clinic/layouts/clinic_hospital_list.xml
new file mode 100644
index 0000000..db09778
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_hospital_list.xml
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml
index 158ac7e..c5f2919 100644
--- a/netforce_clinic/layouts/clinic_menu.xml
+++ b/netforce_clinic/layouts/clinic_menu.xml
@@ -55,6 +55,7 @@
-
+
@@ -65,5 +66,6 @@
+
diff --git a/netforce_clinic/layouts/import_clinic_hd_case.xml b/netforce_clinic/layouts/import_clinic_hd_case.xml
index e36c6fc..a064e39 100644
--- a/netforce_clinic/layouts/import_clinic_hd_case.xml
+++ b/netforce_clinic/layouts/import_clinic_hd_case.xml
@@ -1,11 +1,20 @@
diff --git a/netforce_clinic/layouts/import_clinic_payment_list.xml b/netforce_clinic/layouts/import_clinic_payment_list.xml
new file mode 100644
index 0000000..aa84d7b
--- /dev/null
+++ b/netforce_clinic/layouts/import_clinic_payment_list.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index e1a6ef6..7c7410a 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -72,3 +72,4 @@ from . import import_hd_case
from . import import_data_uc
from . import import_data_sc
from . import vascular_access
+from . import hospital
diff --git a/netforce_clinic/models/hospital.py b/netforce_clinic/models/hospital.py
new file mode 100644
index 0000000..8940721
--- /dev/null
+++ b/netforce_clinic/models/hospital.py
@@ -0,0 +1,32 @@
+from netforce.model import Model, fields
+
+class Hospital(Model):
+ _name="clinic.hospital"
+ _string="Hospital"
+ _key=['code','name']
+
+ _fields={
+ "code": fields.Char("Code",required=True,search=True),
+ "name": fields.Char("Name",required=True,search=True),
+ }
+
+ def name_get(self,ids,context={}):
+ vals=[]
+ for obj in self.browse(ids):
+ name="[%s] %s"%(obj.code,obj.name)
+ vals.append((obj.id,name))
+ return vals
+
+ def name_search(self,name,domain=None,context={},**kw):
+ dom=[["code","ilike","%"+name+"%"]]
+ if domain:
+ dom=[dom,domain]
+ ids1=self.search(dom)
+ dom=[["name","ilike","%"+name+"%"]]
+ if domain:
+ dom=[dom,domain]
+ ids2=self.search(dom)
+ ids=list(set(ids1+ids2))
+ return self.name_get(ids,context=context)
+
+Hospital.register()
diff --git a/netforce_clinic/models/import_hd_case.py b/netforce_clinic/models/import_hd_case.py
index 5f55536..868d37b 100644
--- a/netforce_clinic/models/import_hd_case.py
+++ b/netforce_clinic/models/import_hd_case.py
@@ -1,9 +1,7 @@
import time
-from calendar import monthrange
from netforce.model import Model, fields, get_model
from netforce.utils import get_file_path
-from netforce.database import get_connection
from . import utils
class ImportHDCase(Model):
@@ -13,20 +11,25 @@ class ImportHDCase(Model):
_fields={
'date': fields.Date("Date"),
'file': fields.File("File"),
- 'hcode': fields.Char("Hospital Code"),
+ 'hcode_id': fields.Many2One("clinic.hospital", "Hospital",required=True),
'max_row': fields.Integer("Max Row"),
- 'remain_row': fields.Integer("Remain Row"),
- 'total_row': fields.Integer("Totol Row"),
+ 'remain_row': fields.Integer("Import Pending"),
+ 'total_row': fields.Integer("Total Case"),
+ '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
+ if hp_ids:
+ hp_id=hp_ids[0]
+ return hp_id
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
- 'hcode': get_hcode,
+ 'hcode_id': get_hcode_id,
'max_row': 50,
}
@@ -58,15 +61,14 @@ class ImportHDCase(Model):
if st_policy=='sc':
policy=st_policy.invoice_policy
option=st_policy.invoice_option
-
- # make hd case
- # 1. create hd case
- # - add all expense, set policy
- # 2. find visit
- # 3. update visit (state: 'confirmed', hd_cases)
- print('total line ', len(lines))
+ msg=""
max_row=obj.max_row
count=0
+ nofound=0
+ did=0
+ blank=0
+ fail_qty=0
+ done_qty=0
for line in lines:
name=line.get("name14")
hn=line.get('hn',"")
@@ -76,11 +78,17 @@ class ImportHDCase(Model):
hcode='0'
hcode=int(hcode)
hcode=str(hcode)
- if not obj.hcode==hcode:
+ if not obj.hcode_id.code==hcode:
+ if hcode:
+ nofound+=1
+ if hcode!='0':
+ msg+="not found %s, %s, %s \n"%(hcode,hn,name)
+ fail_qty+=1
+ else:
+ blank+=1
continue
dttran=line.get("dttran","")
date=dttran[0:10]
- #time_stop=dttran[11:] # finish hd case
pt_ids=get_model("clinic.patient").search([['name','=',name]])
if not pt_ids:
pt_ids=get_model("clinic.patient").search([['hn','=',hn]])
@@ -111,7 +119,7 @@ class ImportHDCase(Model):
visits=visit_obj.search_browse([['visit_date','=',date],['patient_id','=',patient_id],['state','=','draft']])
if visits:
count+=1
- print("confirming")
+ done_qty+=1
hlines+=st_lines
visit=visits[0]
cycle=visit.cycle_id
@@ -136,16 +144,21 @@ class ImportHDCase(Model):
inv.write({
'date': inv.due_date,
})
- print("confirm visit ", visit.number)
+ msg+="confirm visit %s\n"%(visit.visit_date)
else:
- print("not found visit for %s on %s"%(name,date))
+ did+=1
+ #print("not found visit for %s on %s"%(name,date))
else:
pass
- #print("XXXX ", name)
-
+ remain_row=len(lines)-blank-did-count
+ if remain_row <= 0:
+ msg="Nothing to import"
obj.write({
'total_row': len(lines),
- 'remain_row': len(lines)-count,
+ 'remain_row': remain_row,
+ 'msg': msg,
+ 'done_qty': done_qty,
+ 'fail_qty': fail_qty,
})
print("Done!")
diff --git a/netforce_clinic/models/import_payment.py b/netforce_clinic/models/import_payment.py
index 129647e..37fa915 100644
--- a/netforce_clinic/models/import_payment.py
+++ b/netforce_clinic/models/import_payment.py
@@ -1,161 +1,92 @@
import time
from netforce.model import Model, fields, get_model
-from netforce.access import get_active_company
from netforce.utils import get_file_path
-
from . import utils
class ImportPayment(Model):
- _name="clinic.import.payment"
- _transient=True
+ _name="import.clinic.payment"
+ _string="Clinic Payment"
+
+ def _get_name(self,ids,context={}):
+ res={}
+ for obj in self.browse(ids):
+ res[obj.id]=obj.type_id.name
+ return res
_fields={
- 'date': fields.DateTime("Date"),
+ 'name': fields.Char("Name",function="_get_name"),
+ 'type_id': fields.Many2One("clinic.patient.type","Patient Type"),
+ 'date': fields.Date("Date"),
'file': fields.File("File"),
- 'result': fields.Text("Success"),
- 'hcode': fields.Char("Hospital Code"),
+ 'hcode_id': fields.Many2One("clinic.hospital", "Hospital",required=True),
+ 'max_row': fields.Integer("Max Row"),
+ 'remain_row': fields.Integer("Pending"),
+ 'total_row': fields.Integer("Total Payment"),
+ 'msg': fields.Text("Message"),
+ 'done_qty': fields.Integer("Success"),
+ 'fail_qty': fields.Integer("Fail"),
+ 'state': fields.Selection([['draft','Draft'],['fail','Fail'],['success','Success']],'State'),
}
- 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
+ if hp_ids:
+ hp_id=hp_ids[0]
+ return hp_id
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
- 'hcode': get_hcode,
+ 'hcode_id': get_hcode_id,
+ 'max_row': 50,
+ 'state': 'draft',
}
-
- def import_uc(self,ids,context={}):
+ def import_payment(self,ids,context={}):
obj=self.browse(ids)[0]
fname=obj.file
fpath=get_file_path(fname)
- if not fpath:
- raise Exception("Please select file")
- lines=utils.read_xml(fpath,node='HDBills')
- if not lines:
- raise Exception("Wrong file")
- data_uc=get_model("clinic.data.uc")
- uc_ids=data_uc.search([])
- data_uc.delete(uc_ids)
- result=""
- result+="Match: %s"%(50)
- result+="\n"
- result+="*"*50
- for line in lines:
- # TODO need to check match or not
- data_uc.create(line)
- line['type']='success'
- print(line)
- result+="\n"
- result+="Not Match: %s"%(40)
- result+="\n"
- result+="*"*50
- obj.write({
- 'result': result,
- })
-
- def import_sc(self,ids,context={}):
- obj=self.browse(ids)[0]
- fname=obj.file
- fpath=get_file_path(fname)
- lines=utils.read_excel(fpath)
+ lines=utils.read_excel(fpath,show_datetime=True)
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())
-
+ msg=""
+ max_row=obj.max_row
+ count=0
+ nofound=0
+ did=0
+ blank=0
+ fail_qty=0
+ done_qty=0
+ msg+=""*10; msg+="hcode,hn,name\n"
for line in lines:
+ name=line.get("name14")
+ hn=line.get('hn',"")
+ hct=line.get("hct","")
hcode=line.get('hcode18','0')
if not hcode:
hcode='0'
hcode=int(hcode)
hcode=str(hcode)
- if obj.hcode==hcode:
- 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","")
-
- vals=patients.get(hn_num)
- if vals:
- #print(vals)
- pass
+ if not obj.hcode_id.code==hcode:
+ if hcode:
+ nofound+=1
+ if hcode!='0':
+ msg+="not found %s, %s, %s \n"%(hcode,hn,name)
+ fail_qty+=1
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([])
- get_model("clinic.data.sc").delete(sc_ids)
- obj=self.browse(ids)[0]
+ blank+=1
+ continue
+ remain_row=len(lines)-blank-did-count
+ if remain_row <= 0:
+ msg="Nothing to import"
obj.write({
- 'result': 'Clear OK',
+ 'total_row': len(lines),
+ 'remain_row': remain_row,
+ 'msg': msg,
+ 'done_qty': done_qty,
+ 'fail_qty': fail_qty,
})
-
- def match_invoice_sc(self,ids,context={}):
- obj=self.browse(ids)[0]
- for sc in get_model("clinic.data.sc").search_browse([['type','=','match']]):
- for invoice in sc.hd_case_id.invoices:
- print(invoice.number)
-
- obj.write({
- 'result': 'Match OK',
- })
-
- def approve_sc(self,ids,context={}):
- settings=get_model("settings").browse(1)
- account_id=settings.ap_sc_id.id
- if not account_id:
- raise Exception("No Account payment for Social Security")
- obj=self.browse(ids)[0]
- vals={
- 'partner_id': '',
- "company_id": get_active_company(),
- "type": "in",
- "pay_type": "invoice",
- "date": obj.date or time.strftime("%Y-%m-%d"),
- "account_id": account_id,
- 'invoice_lines': [],
- }
- invoice_ids=[]
- partner_id=None
- for sc in get_model("clinic.data.sc").search_browse([['type','=','match']]):
- if not partner_id:
- partner_id=sc.hd_case_id.fee_partner_id.id
- for invoice in sc.hd_case_id.invoices:
- invoice_ids.append(invoice.id)
- vals['invoice_lines'].append(('create',{
- 'invoice_id': invoice.id,
- 'amount': invoice.amount_due or 0.0,
- }))
- sc.delete() #XXX
- vals['partner_id']=partner_id
- payment_id=get_model("account.payment").create(vals,context={"type":"in"})
- #get_model("account.payment").browse(payment_id).post()
- return {
- 'next': {
- 'name': 'payment',
- 'mode': 'form',
- 'active_id': payment_id,
- },
- 'flash': 'Paid',
- }
+ print("Done!")
ImportPayment.register()
diff --git a/netforce_clinic/models/old/import_payment.py b/netforce_clinic/models/old/import_payment.py
new file mode 100644
index 0000000..129647e
--- /dev/null
+++ b/netforce_clinic/models/old/import_payment.py
@@ -0,0 +1,161 @@
+import time
+
+from netforce.model import Model, fields, get_model
+from netforce.access import get_active_company
+from netforce.utils import get_file_path
+
+from . import utils
+
+class ImportPayment(Model):
+ _name="clinic.import.payment"
+ _transient=True
+
+ _fields={
+ 'date': fields.DateTime("Date"),
+ 'file': fields.File("File"),
+ 'result': fields.Text("Success"),
+ 'hcode': fields.Char("Hospital Code"),
+ }
+
+ def get_hcode(self,context={}):
+ settings=get_model("settings").browse(1)
+ hcode=settings.hospital_code or ""
+ return hcode
+
+ _defaults={
+ 'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
+ 'hcode': get_hcode,
+ }
+
+
+ def import_uc(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ fname=obj.file
+ fpath=get_file_path(fname)
+ if not fpath:
+ raise Exception("Please select file")
+ lines=utils.read_xml(fpath,node='HDBills')
+ if not lines:
+ raise Exception("Wrong file")
+ data_uc=get_model("clinic.data.uc")
+ uc_ids=data_uc.search([])
+ data_uc.delete(uc_ids)
+ result=""
+ result+="Match: %s"%(50)
+ result+="\n"
+ result+="*"*50
+ for line in lines:
+ # TODO need to check match or not
+ data_uc.create(line)
+ line['type']='success'
+ print(line)
+ result+="\n"
+ result+="Not Match: %s"%(40)
+ result+="\n"
+ result+="*"*50
+ obj.write({
+ 'result': result,
+ })
+
+ def import_sc(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ fname=obj.file
+ fpath=get_file_path(fname)
+ 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:
+ hcode='0'
+ hcode=int(hcode)
+ hcode=str(hcode)
+ if obj.hcode==hcode:
+ 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","")
+
+ 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([])
+ get_model("clinic.data.sc").delete(sc_ids)
+ obj=self.browse(ids)[0]
+ obj.write({
+ 'result': 'Clear OK',
+ })
+
+ def match_invoice_sc(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ for sc in get_model("clinic.data.sc").search_browse([['type','=','match']]):
+ for invoice in sc.hd_case_id.invoices:
+ print(invoice.number)
+
+ obj.write({
+ 'result': 'Match OK',
+ })
+
+ def approve_sc(self,ids,context={}):
+ settings=get_model("settings").browse(1)
+ account_id=settings.ap_sc_id.id
+ if not account_id:
+ raise Exception("No Account payment for Social Security")
+ obj=self.browse(ids)[0]
+ vals={
+ 'partner_id': '',
+ "company_id": get_active_company(),
+ "type": "in",
+ "pay_type": "invoice",
+ "date": obj.date or time.strftime("%Y-%m-%d"),
+ "account_id": account_id,
+ 'invoice_lines': [],
+ }
+ invoice_ids=[]
+ partner_id=None
+ for sc in get_model("clinic.data.sc").search_browse([['type','=','match']]):
+ if not partner_id:
+ partner_id=sc.hd_case_id.fee_partner_id.id
+ for invoice in sc.hd_case_id.invoices:
+ invoice_ids.append(invoice.id)
+ vals['invoice_lines'].append(('create',{
+ 'invoice_id': invoice.id,
+ 'amount': invoice.amount_due or 0.0,
+ }))
+ sc.delete() #XXX
+ vals['partner_id']=partner_id
+ payment_id=get_model("account.payment").create(vals,context={"type":"in"})
+ #get_model("account.payment").browse(payment_id).post()
+ return {
+ 'next': {
+ 'name': 'payment',
+ 'mode': 'form',
+ 'active_id': payment_id,
+ },
+ 'flash': 'Paid',
+ }
+
+ImportPayment.register()