diff --git a/netforce_clinic/layouts/clinic_visit_board_confirm.xml b/netforce_clinic/layouts/clinic_visit_board_confirm.xml
index 6b29578..f8a0974 100644
--- a/netforce_clinic/layouts/clinic_visit_board_confirm.xml
+++ b/netforce_clinic/layouts/clinic_visit_board_confirm.xml
@@ -8,6 +8,9 @@
+
+
+
diff --git a/netforce_clinic/migrations/__init__.py b/netforce_clinic/migrations/__init__.py
index 0e0750c..d5e40e0 100644
--- a/netforce_clinic/migrations/__init__.py
+++ b/netforce_clinic/migrations/__init__.py
@@ -11,4 +11,8 @@ from . import clinic_setting
#from . import reset_hdcase_number
#from . import remove_dbl_contact
#from . import update_invoice
-from . import update_pick_out_number
+#from . import update_pick_out_number
+#from . import reimport10to15
+#from . import add_missing_dlz # pending
+#from . import validate_cycle_item
+from . import update_line_amount
diff --git a/netforce_clinic/migrations/add_missing_dlz.py b/netforce_clinic/migrations/add_missing_dlz.py
new file mode 100644
index 0000000..2452319
--- /dev/null
+++ b/netforce_clinic/migrations/add_missing_dlz.py
@@ -0,0 +1,45 @@
+import csv
+import xlrd
+
+from netforce.model import get_model
+from netforce import migration
+from netforce.access import set_active_user, set_active_company
+from netforce.database import get_connection
+
+class Migration(migration.Migration):
+ _name="clinic.add.missing.dlz"
+ _version="2.12.4"
+
+ def migrate(self):
+ set_active_company(1)
+ set_active_user(1)
+ cond=[
+ ['date','>=','2016-11-10'],
+ ['date','<=','2016-11-15'],
+ ['patient_id','=',16907], # test
+ ]
+ for hdcase in get_model("clinic.hd.case").search_browse(cond):
+ if not hdcase.dialyzers:
+ patient=hdcase.patient_id
+ dialyzer=patient.dialyzers[0] #active
+ print('hdcase.number : ', hdcase.number)
+ print("//"*30)
+ dlzs=get_model("clinic.hd.case.dialyzer").search_browse([['dialyzer_id','=',dialyzer.id]])
+ if dlzs:
+ dlz=dlzs[0]
+ next_usetime=dlz.use_time+1
+ vals={
+ "description": dialyzer.name,
+ 'use_time': next_usetime,
+ 'max_use_time': dialyzer.max_use_time,
+ 'dialyzer_type': dialyzer.type,
+ 'dlz_id': dialyzer.id,
+ 'hd_case_id': hdcase.id,
+ }
+
+ print(patient.id, patient.name, dialyzer.id, dlz.use_time)
+ print("//"*30)
+ break
+
+
+Migration.register()
diff --git a/netforce_clinic/migrations/reimport10to15.py b/netforce_clinic/migrations/reimport10to15.py
new file mode 100644
index 0000000..2ffcd3c
--- /dev/null
+++ b/netforce_clinic/migrations/reimport10to15.py
@@ -0,0 +1,212 @@
+import csv
+import xlrd
+
+from netforce.model import get_model
+from netforce import migration
+from netforce.access import set_active_user, set_active_company
+from netforce.database import get_connection
+
+class Migration(migration.Migration):
+ _name="clinic.reimport.10to15"
+ _version="2.12.4"
+
+ def migrate(self):
+ set_active_company(1)
+ set_active_user(1)
+ #find hdcase => date, patient => fill up => hct , erythopoie => validate
+ #///////////////// SAMSEN //////////////////////
+ #path="/home/watcha/Desktop/RD-10-15.csv"
+ for fname in ["RD-10-15.csv","LS-10-15.csv"]:
+ #for fname in ["RD-10-15.csv"]:
+ path="/tmp/"+fname
+
+ field_names=[]
+ nolines=[]
+ print('RUN.%s ... '%fname)
+ with open(path) as csvfile:
+ reader = csv.DictReader(csvfile)
+ field_names=reader.fieldnames
+ count=0
+ found=0
+ no=0
+ for row in reader:
+ count+=1
+ name=row['name']
+ hn=row['hn']
+ pid=row['pid']
+ cond=[
+ ['or',[
+ ['name','ilike',name],
+ #['hn','ilike',hn],
+ #['card_no','ilike',pid],
+ ],
+ ],
+ ]
+
+ pids=get_model("clinic.patient").search(cond)
+ if pids:
+ patient_id=pids[0]
+ dpt=row['dpt']
+ dpt_id=None
+ if dpt=='LS01':
+ dpt_id=1
+ elif dpt=='LS02':
+ dpt_id=2
+ elif dpt=='LS03':
+ dpt_id=3
+ elif dpt=='RD02':
+ dpt_id=4
+ elif dpt=='RD03':
+ dpt_id=5 # สามเสนช้น 4
+ cycle_id=None
+ cycle=row['cycle']
+ if '1' in cycle:
+ cycle_id=1
+ elif '2' in cycle:
+ cycle_id=2
+ elif '3' in cycle:
+ cycle_id=3
+ elif '4' in cycle:
+ cycle_id=4
+
+ cycle=get_model("clinic.cycle").browse(cycle_id)
+
+ m,d,y=row['datehd'].split("/") #mm/dd/yyyy
+ date="-".join([y.zfill(2), m.zfill(2), d.zfill(2)])
+ cond=[
+ ['date','=', date],
+ ['department_id','=',dpt_id],
+ #['cycle_id','=',cycle_id], # maybe change the cycle
+ ['patient_id','=',pids[0]],
+ ]
+ #print('cond >>> ', cond)
+ res=get_model("clinic.hd.case").search_read(cond,['cycle_id'])
+ if res:
+ if len(res)>1:
+ pass
+ #continue
+ hdcase_id=res[0]['id']
+ hdcase=get_model("clinic.hd.case").browse(hdcase_id)
+ vals={'hct': row['hct']}
+ for line in hdcase.lines:
+ categ=line.product_categ_id
+ if categ:
+ #36 | Fee
+ #43 | Service
+ #34 | Erythropoietin
+ if categ.id==43:
+ line.write({
+ 'qty': row['qty'],
+ 'price': row['inject_price'],
+ })
+ if categ.id==34:
+ prods=get_model("product").search_read([['description','ilike',row['epo_nf']]],['name'])
+ if prods:
+ product_id=prods[0]['id']
+ desc=prods[0]['name'] or ""
+ line.write({
+ 'description': desc,
+ 'product_id': product_id,
+ 'qty': row['qty'],
+ 'price': row['product_price'],
+ })
+
+ if cycle_id!=res[0]['cycle_id'][0]:
+ print("update cycle hdcase.%s "%(hdcase.number))
+ hdcase.visit_id.write({
+ 'cycle_id': cycle_id,
+ })
+ vals.update({
+ 'cycle_id': cycle_id,
+ })
+
+ if vals and hdcase.state not in ("waiting_payment","paid"):
+ hdcase.write(vals)
+ #req_fee : 1=> topay else claim expense
+ if not hdcase.req_fee:
+ hdcase.make_invoices()
+ hdcase.post_invoices()
+ hdcase.write({
+ 'state': 'waiting_payment'
+ })
+ else:
+ hdcase.make_payment()
+ hdcase.write({
+ 'state': 'paid'
+ })
+ found+=1
+ else:
+ no+=1
+ # create new visit -> hdcase
+ patient=get_model('clinic.patient').browse(patient_id)
+ dpt=get_model("clinic.department").browse(dpt_id)
+ visit_vals={
+ 'patient_id': patient.id,
+ 'department_id': dpt.id,
+ 'cycle_id': cycle_id,
+ 'doctor_id': patient.doctor_id.id,
+ 'branch_id': dpt.branch_id.id,
+ 'time_start': '%s %s:00'%(date,cycle.time_start),
+ 'time_stop': '%s %s:00'%(date,cycle.time_stop),
+ 'visit_date': date,
+ 'state': 'pending',
+ }
+ context={
+ 'no_dlz': True,
+ 'random_sickbed': True
+ }
+ new_id=get_model('clinic.visit').create(visit_vals,context=context)
+ visit=get_model('clinic.visit').browse(new_id)
+ visit.confirm(context)
+ for hdcase in visit.hd_cases:
+ for line in hdcase.lines:
+ categ=line.product_categ_id
+ if categ:
+ #36 | Fee
+ #43 | Service
+ #34 | Erythropoietin
+ if categ.id==43:
+ line.write({
+ 'qty': row['qty'],
+ 'price': row['inject_price'],
+ })
+ if categ.id==34:
+ prods=get_model("product").search_read([['description','ilike',row['epo_nf']]],['name'])
+ if prods:
+ product_id=prods[0]['id']
+ desc=prods[0]['name'] or ""
+ line.write({
+ 'product_id': product_id,
+ 'description': desc,
+ 'qty': row['qty'],
+ 'price': row['product_price'],
+ })
+ if not hdcase.req_fee:
+ hdcase.make_invoices()
+ hdcase.post_invoices()
+ hdcase.write({
+ 'state': 'waiting_payment'
+ })
+ else:
+ hdcase.make_payment()
+ hdcase.write({
+ 'state': 'paid'
+ })
+ nolines.append(row)
+ else:
+ no+=1 #XXX
+
+ if field_names and nolines:
+ fname="no-%s"%(fname)
+ path='/tmp/%s'%(fname)
+ with open(path, 'w') as csvfile:
+ writer = csv.DictWriter(csvfile, fieldnames=field_names)
+ writer.writeheader()
+ for noline in nolines:
+ writer.writerow(noline)
+ print("Missing %s please checkout %s"%(len(nolines), path))
+ print(count, found, no)
+
+ #///////////////// LAKSI //////////////////////
+
+Migration.register()
diff --git a/netforce_clinic/migrations/update_line_amount.py b/netforce_clinic/migrations/update_line_amount.py
new file mode 100644
index 0000000..f687788
--- /dev/null
+++ b/netforce_clinic/migrations/update_line_amount.py
@@ -0,0 +1,81 @@
+import csv
+import xlrd
+
+from netforce.model import get_model
+from netforce import migration
+from netforce.access import set_active_user, set_active_company
+from netforce.database import get_connection
+
+class Migration(migration.Migration):
+ _name="clinic.update.line.amount"
+ _version="2.12.5"
+
+ def migrate(self):
+ set_active_company(1)
+ set_active_user(1)
+ cond=[
+ ['date','>=','2016-11-10'],
+ ['date','<=','2016-11-15'],
+ ['state','in',['waiting_payment','paid']],
+ ]
+ settings=get_model('settings').browse(1)
+ cst=get_model("clinic.setting").browse(1)
+ prod_acc=cst.get_product_account
+ currency_id=settings.currency_id.id
+
+ for hdcase in get_model("clinic.hd.case").search_browse(cond):
+ print("hdcase.number ", hdcase.id, hdcase.number)
+ patient=hdcase.patient_id
+ ptype=patient.type_id
+ partner=ptype.contact_id
+ track_id=hdcase.branch_id.track_id.id
+ for line in hdcase.lines:
+ categ=line.product_categ_id
+ if line.reimbursable=='yes' and categ.id==34: #Erythopo...
+ prod=line.product_id
+ acc=prod_acc(prod.id,hdcase.patient_type_id.id)
+ account_id=acc.get("ar_credit_id",None)
+ ar_debit_id=acc.get("ar_debit_id",None) # account receiveable
+ amount=line.amount or (line.price*line.qty) or 0
+ if not amount:
+ continue
+ lines=[
+ ('create',{
+ "product_id": prod.id,
+ "description": line.description or "",
+ "qty": line.qty,
+ "uom_id": line.uom_id.id,
+ "unit_price": line.price or 0,
+ "amount": amount,
+ 'account_id': account_id,
+ #'ar_debit_id': ar_debit_id,
+ 'track_id': track_id,
+ })
+ ]
+ context={
+ 'date' : hdcase.date,
+ 'branch_id': hdcase.branch_id.id,
+ "type": "out",
+ "inv_type": "invoice",
+ }
+ vals={
+ "type": "out",
+ "inv_type": "invoice",
+ "tax_type": "tax_in",
+ 'date': hdcase.date,
+ 'due_date': hdcase.date,
+ "ref": '%s (%s)'%(patient.name or '',patient.number or ''),
+ 'department_id': hdcase.department_id.id,
+ "related_id": "clinic.hd.case,%s"%hdcase.id,
+ "currency_id": currency_id,
+ "company_id": hdcase.company_id.id,
+ "partner_id": partner.id,
+ 'patient_partner_id':patient.partner_id.id,
+ 'account_id':account_id,
+ 'lines':lines,
+ }
+ inv_id=get_model("account.invoice").create(vals,context=context)
+ inv=get_model("account.invoice").browse(inv_id)
+ inv.post()
+
+Migration.register()
diff --git a/netforce_clinic/migrations/validate_cycle_item.py b/netforce_clinic/migrations/validate_cycle_item.py
new file mode 100644
index 0000000..90ae887
--- /dev/null
+++ b/netforce_clinic/migrations/validate_cycle_item.py
@@ -0,0 +1,19 @@
+import csv
+import xlrd
+
+from netforce.model import get_model
+from netforce import migration
+from netforce.access import set_active_user, set_active_company
+from netforce.database import get_connection
+
+class Migration(migration.Migration):
+ _name="clinic.validate.cycle.item"
+ _version="2.12.5"
+
+ def migrate(self):
+ set_active_company(1)
+ set_active_user(1)
+ for citem in get_model("clinic.cycle.item").search_browse([['date','>=','2016-11-10'],['date','<=','2016-11-15']]):
+ citem.validate()
+
+Migration.register()
diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py
index 3c1c09e..1d65184 100644
--- a/netforce_clinic/models/hd_case.py
+++ b/netforce_clinic/models/hd_case.py
@@ -297,6 +297,7 @@ class HDCase(Model):
'hd_case_id': fields.Many2One("clinic.hd.case","HD",function="_get_all",function_multi=True), # XXX
'company_id': fields.Many2One("company","Company"),
'branch_id': fields.Many2One("clinic.branch","Branch"),
+ 'check_dlz': fields.Boolean("Check Dialyzer"),
}
def _get_number(self,context={}):
@@ -342,6 +343,7 @@ class HDCase(Model):
'invoice_policy': 'fee',
'req_fee': 0,
'hct_include': False,
+ 'check_dlz': True,
}
_order="date desc,number desc"
@@ -886,8 +888,7 @@ class HDCase(Model):
def do_treatment(self,ids,context={}):
obj=self.browse(ids)[0]
- #TODO should find dlz when confirm visit
- if not obj.dialyzers:
+ if obj.check_dlz and not obj.dialyzers:
raise Exception("Please input dialyzer!")
vals={
'state': 'in_progress',
diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py
index c075edf..074fb11 100644
--- a/netforce_clinic/models/visit.py
+++ b/netforce_clinic/models/visit.py
@@ -1,4 +1,5 @@
import time
+from random import random
from datetime import datetime, timedelta
@@ -187,11 +188,20 @@ class Visit(Model):
'date': obj.visit_date, #XXX
}
+ random_sickbed=context.get("random_sickbed")
+ if random_sickbed:
+ ids=get_model('clinic.sickbed').search([['department_id','=',obj.department_id.id]])
+ i=int(random()*len(ids))
+ vals['sickbed_id']=ids[i]
+ no_gen_dlz=context.get("no_dlz")
+
st=get_model("clinic.setting").browse(1)
- if st.find_dlz and not obj.hd_cases: # force to remove
+ if not no_gen_dlz and st.find_dlz and not obj.hd_cases: # force to remove
dialyzer=self.get_dlz(obj.id)
if dialyzer:
vals['dialyzers'].append(('create',dialyzer))
+ else:
+ vals['check_dlz']=False
vals['staffs'].append(('create',{
'staff_id': obj.doctor_id.id,
diff --git a/netforce_clinic/models/visit_board.py b/netforce_clinic/models/visit_board.py
index b7f556e..ee5d2de 100644
--- a/netforce_clinic/models/visit_board.py
+++ b/netforce_clinic/models/visit_board.py
@@ -44,6 +44,7 @@ class VisitBoard(Model):
'department_id': fields.Many2One("clinic.department","Department"),
'branch_id': fields.Many2One("clinic.branch","Branch"),
"state": fields.Selection([["draft","Draft"],['pending','Pending'],["confirmed","Confirmed"],["cancelled","Cancelled"]],"Status",required=True),
+ 'gen_back': fields.Boolean("Gen Back (Admin)"),
}
def default_get(self,field_names=None,context={},**kw):
@@ -88,6 +89,7 @@ class VisitBoard(Model):
branch_id=defaults.get("branch_id",None)
context['branch_id']=branch_id
state=defaults.get("state",'pending')
+ gen_back=False
if ids:
obj=self.browse(ids)[0]
date_from=obj.date_from
@@ -99,6 +101,7 @@ class VisitBoard(Model):
branch_id=obj.branch_id.id
context['branch_id']=branch_id
state=obj.state
+ gen_back=obj.gen_back
# auto generate visit day to day
def auto_gen_visit(dom=[]):
dom.append(['dispose','=',False])
@@ -117,7 +120,7 @@ class VisitBoard(Model):
weekday=date.weekday()
date_txt=date.strftime("%Y-%m-%d")
datenow=time.strftime("%Y-%m-%d")
- if date_txt < datenow:
+ if date_txt < datenow and not gen_back:
print("continue ", date_txt, datenow)
continue
for pt in get_model("clinic.patient").search_browse(dom):
diff --git a/netforce_clinic/models/visit_popup_confirm.py b/netforce_clinic/models/visit_popup_confirm.py
index 950bdf7..a387bb4 100644
--- a/netforce_clinic/models/visit_popup_confirm.py
+++ b/netforce_clinic/models/visit_popup_confirm.py
@@ -15,6 +15,8 @@ class VisitPopupConfirm(Model):
'user_id': fields.Many2One("base.user","User"),
"note": fields.Text("Note"),
'lines': fields.One2Many("clinic.popup.visit.confirm.line","popup_visit_id",'Lines'),
+ 'no_dlz': fields.Boolean("No Dialyzer"),
+ 'random_sickbed': fields.Boolean("Random Sickbed"),
}
def _get_visitboard_id(self,context={}):
@@ -93,13 +95,15 @@ class VisitPopupConfirm(Model):
vals={}
if nurse_ids:
vals['nurse_id']=nurse_ids[0]
+ context['no_dlz']=obj.no_dlz
+ context['random_sickbed']=obj.random_sickbed
for line in obj.lines:
vs=line.visit_id
dt=line.doctor_id
if dt:
vals['doctor_id']=dt.id
vs.write(vals)
- vs.confirm()
+ vs.confirm(context)
count+=1
return {
'next': {