2014-10-02 19:12:52 +00:00
|
|
|
import time
|
2014-10-05 08:29:21 +00:00
|
|
|
from datetime import datetime, timedelta
|
2014-10-02 19:12:52 +00:00
|
|
|
|
2014-08-21 07:29:37 +00:00
|
|
|
from netforce.model import Model, fields, get_model
|
|
|
|
from netforce.utils import get_data_path
|
2014-09-11 03:21:52 +00:00
|
|
|
from netforce.access import get_active_user,set_active_user
|
2014-08-21 07:29:37 +00:00
|
|
|
from netforce.access import get_active_company
|
|
|
|
|
2014-10-01 06:51:36 +00:00
|
|
|
class HDcase(Model):
|
2014-08-21 07:29:37 +00:00
|
|
|
_name="clinic.hd.case"
|
2014-10-04 15:51:54 +00:00
|
|
|
_string="Treatment"
|
2014-08-21 07:29:37 +00:00
|
|
|
_audit_log=True
|
|
|
|
_name_field="number"
|
|
|
|
_multi_company=True
|
2014-10-02 19:12:52 +00:00
|
|
|
|
|
|
|
def get_hrs(self,ids,context={}):
|
|
|
|
res={}
|
|
|
|
fmt="%Y-%m-%d %H:%M:%S"
|
|
|
|
for obj in self.browse(ids):
|
2014-10-05 05:47:19 +00:00
|
|
|
diff=datetime.strptime(obj.time_stop,fmt)-datetime.strptime(obj.time_start,fmt)
|
2014-10-02 19:12:52 +00:00
|
|
|
total_time=round(diff.seconds/3600,2)
|
|
|
|
res[obj.id]=total_time
|
|
|
|
return res
|
|
|
|
|
2014-08-21 07:29:37 +00:00
|
|
|
_fields={
|
|
|
|
"number": fields.Char("Number",required=True,search=True),
|
2014-10-02 00:34:58 +00:00
|
|
|
"patient_id": fields.Many2One("clinic.patient","Patient",required=True,search=True),
|
|
|
|
"doctor_id": fields.Many2One("clinic.doctor","Doctor", required=True,search=True),
|
|
|
|
"nurse_id": fields.Many2One("clinic.nurse","Nurse", required=True,search=True),
|
2014-10-02 07:36:13 +00:00
|
|
|
"date_start": fields.DateTime("Time start",required=True,search=True),
|
2014-10-08 04:36:22 +00:00
|
|
|
"date_stop": fields.DateTime("Time stop",required=True,search=True),
|
2014-10-02 00:34:58 +00:00
|
|
|
"department_id": fields.Many2One("clinic.department", "Department",search=True),
|
|
|
|
"wh_start": fields.Float("Wt.Kg start"),
|
|
|
|
"wh_stop": fields.Float("Wt.Kg stop"),
|
|
|
|
"bp_start": fields.Integer("BP mmHG start"),
|
|
|
|
"per_bp_start": fields.Integer("/Per start"),
|
|
|
|
"bp_stop": fields.Integer("BP mmHG stop"),
|
|
|
|
"per_bp_stop": fields.Integer("/Per stop"),
|
2014-10-08 04:36:22 +00:00
|
|
|
"epo_tn" : fields.Char("EpoTn (Drug name)"),
|
|
|
|
"epo_unit" : fields.Integer("EpoUnit (Unit of Used drug)"),
|
|
|
|
"hct": fields.Integer("HCT %", required=True),
|
|
|
|
"check_goverment_pay" : fields.Boolean("The Government Pay"),
|
|
|
|
"check_personal_pay" : fields.Boolean("Pay yourself"),
|
2014-10-02 19:12:52 +00:00
|
|
|
"state": fields.Selection([("draft","Draft"),("confirmed","Confirmed"),("approved","Approved"),("cancelled","Cancelled"),("paid","Paid")],"Status",required=True),
|
2014-10-02 00:34:58 +00:00
|
|
|
"hct": fields.Integer("HCT %"),
|
2014-10-05 05:47:19 +00:00
|
|
|
"state": fields.Selection([("draft","Draft"),("in_progress","In Progress"),("completed","Completed"),("discountinued","Discountinued"),("uncompleted","Uncompleted")],"Status",required=True),
|
2014-10-04 18:33:18 +00:00
|
|
|
"dialyzers": fields.One2Many("clinic.dialyzer.line","hd_case_id","Dializers"),
|
2014-10-02 19:12:52 +00:00
|
|
|
"lines": fields.One2Many("clinic.hd.case.line","hd_case_id","Lines"),
|
2014-08-21 07:29:37 +00:00
|
|
|
"comments": fields.One2Many("message","related_id","Comments"),
|
|
|
|
"company_id": fields.Many2One("company","Company"),
|
2014-10-02 19:12:52 +00:00
|
|
|
"fee": fields.Float("HD Fee"),
|
2014-10-03 02:00:47 +00:00
|
|
|
"amount": fields.Float("Due Amount",function="get_total",readonly=True,function_multi=True),
|
2014-09-11 03:21:52 +00:00
|
|
|
"total": fields.Float("Total",function="get_total",readonly=True,function_multi=True),
|
|
|
|
"reconcile_id": fields.Many2One("account.reconcile","Reconcile Id",readonly=True),
|
2014-10-01 07:40:18 +00:00
|
|
|
"invoices": fields.One2Many("account.invoice","related_id","Invoices"),
|
|
|
|
"pickings": fields.One2Many("stock.picking","related_id","Pickings"),
|
|
|
|
"payments": fields.One2Many("account.payment","related_id","Payments"),
|
2014-10-02 02:02:22 +00:00
|
|
|
'visit_id': fields.Many2One("clinic.visit", "Visit"),
|
2014-10-02 19:12:52 +00:00
|
|
|
'total_time': fields.Integer("Total Time(Hrs)",function="get_hrs"),
|
|
|
|
"fee_type": fields.Selection([("mg","Medical Government"),("sc","Social Security"),("nhso","NHSO (30฿)"),("personal","Personal"),("others","Others")],"Fee Type"),
|
2014-10-06 00:48:42 +00:00
|
|
|
'fee_partner_id': fields.Many2One("partner","Contact Fee"),
|
2014-10-04 18:33:18 +00:00
|
|
|
'paid': fields.Boolean("Paid"),
|
2014-10-05 05:47:19 +00:00
|
|
|
"time_start": fields.DateTime("Time start",required=True,search=True),
|
|
|
|
"time_stop": fields.DateTime("Time stop",required=True,search=True),
|
|
|
|
"date": fields.Date("Date Treatment",required=True),
|
2014-10-05 08:29:21 +00:00
|
|
|
'planes': fields.One2Many("clinic.visit.plane","hd_case_id","Planning"),
|
2014-10-05 09:43:28 +00:00
|
|
|
'note': fields.Text("Note"),
|
2014-08-21 07:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def _get_number(self,context={}):
|
|
|
|
while 1:
|
2014-10-02 01:12:46 +00:00
|
|
|
seq_id=get_model("sequence").find_sequence(name="Clinic HD Case")
|
|
|
|
num=get_model("sequence").get_next_number(seq_id,context=context)
|
2014-08-21 07:29:37 +00:00
|
|
|
if not num:
|
|
|
|
return None
|
2014-10-02 01:12:46 +00:00
|
|
|
user_id=get_active_user()
|
|
|
|
set_active_user(1)
|
2014-08-21 07:29:37 +00:00
|
|
|
res=self.search([["number","=",num]])
|
2014-10-02 01:12:46 +00:00
|
|
|
set_active_user(user_id)
|
2014-08-21 07:29:37 +00:00
|
|
|
if not res:
|
|
|
|
return num
|
2014-10-02 01:12:46 +00:00
|
|
|
get_model("sequence").increment_number(seq_id,context=context)
|
2014-08-21 07:29:37 +00:00
|
|
|
|
2014-10-02 00:34:58 +00:00
|
|
|
def _get_nurse(self,context={}):
|
|
|
|
user_id=get_active_user()
|
|
|
|
print("user_id ",user_id)
|
|
|
|
nurse_ids=get_model("clinic.nurse").search([['user_id','=',user_id]])
|
|
|
|
if nurse_ids:
|
|
|
|
return nurse_ids[0]
|
|
|
|
return None
|
|
|
|
|
|
|
|
_defaults={
|
|
|
|
"state": "draft",
|
2014-10-05 05:47:19 +00:00
|
|
|
"date": lambda *a: time.strftime("%Y-%m-%d"),
|
|
|
|
"time_start": lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
"time_stop": lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
2014-10-02 00:34:58 +00:00
|
|
|
'nurse_id': _get_nurse,
|
|
|
|
"number": _get_number,
|
|
|
|
"company_id": lambda *a: get_active_company(),
|
|
|
|
"fee": 1500,
|
|
|
|
}
|
2014-10-05 05:47:19 +00:00
|
|
|
_order="date desc,number desc"
|
2014-10-02 00:34:58 +00:00
|
|
|
|
2014-08-28 11:20:49 +00:00
|
|
|
def onchange_dialyzer(self,context={}):
|
|
|
|
data=context["data"]
|
|
|
|
path=context["path"]
|
|
|
|
line=get_data_path(data,path,parent=True)
|
2014-10-04 18:33:18 +00:00
|
|
|
dialyzer_id=line.get("dialyzer_id")
|
2014-08-28 11:20:49 +00:00
|
|
|
if not dialyzer_id:
|
|
|
|
return {}
|
|
|
|
dialyzer=get_model("clinic.dialyzer").browse(dialyzer_id)
|
2014-10-04 18:33:18 +00:00
|
|
|
line["description"]=dialyzer.description or ""
|
2014-08-28 11:20:49 +00:00
|
|
|
line["use_time"]=dialyzer.use_time
|
|
|
|
line["max_use_time"]=dialyzer.max_use_time
|
|
|
|
line["member_type"]=dialyzer.member_type
|
|
|
|
line["dialyzer_type"]=dialyzer.dialyzer_type
|
|
|
|
line["bid_flow_rate"]=dialyzer.bid_flow_rate
|
|
|
|
line["ultrafittration"]=dialyzer.ultrafittration
|
|
|
|
line["state"]=dialyzer.state
|
|
|
|
return data
|
2014-08-21 07:29:37 +00:00
|
|
|
|
2014-10-02 00:34:58 +00:00
|
|
|
def onchange_patient(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
patient_id=data['patient_id']
|
|
|
|
hd_cases=self.search_browse([['patient_id','=',patient_id]])
|
2014-10-05 05:47:19 +00:00
|
|
|
# TODO reset dialyzer
|
2014-10-02 00:34:58 +00:00
|
|
|
if hd_cases:
|
|
|
|
hd_case=hd_cases[-1]
|
|
|
|
data['doctor_id']=hd_case.doctor_id.id
|
|
|
|
data['department_id']=hd_case.department_id.id
|
|
|
|
else:
|
|
|
|
data['doctor_id']=None
|
|
|
|
data['department_id']=None
|
|
|
|
|
|
|
|
return data
|
2014-08-21 07:29:37 +00:00
|
|
|
|
2014-10-03 02:00:47 +00:00
|
|
|
def onchange_product(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
path=context["path"]
|
|
|
|
line=get_data_path(data,path,parent=True)
|
|
|
|
product_id=line.get('product_id')
|
|
|
|
if not product_id:
|
|
|
|
return
|
|
|
|
prod=get_model("product").browse(product_id)
|
|
|
|
line['uom_id']=prod.uom_id.id
|
|
|
|
line['description']=prod.name
|
|
|
|
line['qty']=1
|
|
|
|
line['price']=prod.sale_price or 0.0
|
|
|
|
line['amount']=prod.sale_price or 0.0
|
|
|
|
self.onchange_line(context)
|
|
|
|
return data
|
|
|
|
|
|
|
|
def onchange_line(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
total=0.0
|
|
|
|
for line in data['lines']:
|
|
|
|
price=line.get('price') or 0
|
|
|
|
qty=line.get('qty') or 0
|
|
|
|
amt=qty * price
|
|
|
|
product_id=line.get("product_id")
|
|
|
|
if product_id:
|
|
|
|
line['amount']=amt
|
|
|
|
total+=amt
|
|
|
|
data['total']=total
|
|
|
|
return data
|
|
|
|
|
2014-10-08 04:36:22 +00:00
|
|
|
def onchange_htc(self,context={}):
|
|
|
|
data=context['htc']
|
|
|
|
total=0.0
|
|
|
|
if (htc > 39):
|
|
|
|
data['htc']=total
|
|
|
|
return data
|
|
|
|
|
2014-10-02 00:34:58 +00:00
|
|
|
def cancelled(self,ids,context={}):
|
2014-08-21 07:29:37 +00:00
|
|
|
obj=self.browse(ids)[0]
|
2014-10-02 00:34:58 +00:00
|
|
|
obj.write({"state":"cancelled"})
|
2014-08-21 07:29:37 +00:00
|
|
|
|
2014-10-03 02:00:47 +00:00
|
|
|
def make_invoices(self,ids,context={}):
|
|
|
|
setting=get_model("settings").browse(1)
|
|
|
|
currency_id=setting.currency_id.id
|
2014-10-06 00:48:42 +00:00
|
|
|
#
|
2014-10-03 02:00:47 +00:00
|
|
|
account_receivable_id=setting.account_receivable_id.id
|
|
|
|
company_id=get_active_company()
|
|
|
|
uom=get_model("uom").search_browse([['name','ilike','%Unit%']])
|
|
|
|
if not uom:
|
|
|
|
raise Exception("Unit not found in uom")
|
|
|
|
obj=self.browse(ids[0])
|
2014-10-05 08:29:21 +00:00
|
|
|
due_date=obj.date[0:10]
|
2014-10-03 02:00:47 +00:00
|
|
|
# XXX
|
|
|
|
context['type']='out'
|
|
|
|
context['inv_type']='invoice'
|
2014-10-04 18:33:18 +00:00
|
|
|
if obj.lines and obj.total:
|
2014-10-03 02:00:47 +00:00
|
|
|
# XXX need to split function prepare invoice
|
|
|
|
vals={
|
|
|
|
"type": "out",
|
|
|
|
"inv_type": "invoice",
|
|
|
|
"tax_type": "tax_in",
|
|
|
|
'due_date': due_date,
|
|
|
|
"ref": obj.number,
|
|
|
|
"related_id": "clinic.hd.case,%s"%obj.id,
|
|
|
|
"currency_id": currency_id,
|
|
|
|
"company_id": company_id,
|
|
|
|
"lines": [],
|
|
|
|
"company_id": company_id,
|
|
|
|
}
|
|
|
|
partner=obj.patient_id.partner_id
|
|
|
|
if not partner:
|
|
|
|
raise Exception("No contact for patient %s"%obj.patient_id.name)
|
|
|
|
vals["partner_id"]=partner.id
|
|
|
|
for line in obj.lines:
|
2014-10-06 00:48:42 +00:00
|
|
|
account_id=line.product_id.sale_account_id.id or account_receivable_id
|
|
|
|
if not account_id:
|
|
|
|
raise Exception("%s not found account recievable %s"%partner.name)
|
2014-10-03 02:00:47 +00:00
|
|
|
line={
|
|
|
|
"product_id": line.product_id.id,
|
|
|
|
"description": line.description,
|
|
|
|
"qty": line.qty,
|
|
|
|
"uom_id": line.uom_id.id,
|
|
|
|
"unit_price": line.price,
|
|
|
|
"amount": line.amount,
|
2014-10-06 00:48:42 +00:00
|
|
|
'account_id': account_id,
|
2014-10-03 02:00:47 +00:00
|
|
|
}
|
|
|
|
vals['lines'].append(('create',line))
|
|
|
|
inv_id=get_model("account.invoice").create(vals,context)
|
2014-10-03 07:27:57 +00:00
|
|
|
# create picking
|
|
|
|
obj.make_pickings()
|
2014-10-03 02:00:47 +00:00
|
|
|
if obj.fee:
|
|
|
|
vals={
|
|
|
|
"type": "out",
|
|
|
|
"inv_type": "invoice",
|
|
|
|
"tax_type": "tax_in",
|
|
|
|
'due_date': due_date,
|
|
|
|
"ref": obj.number,
|
|
|
|
"related_id": "clinic.hd.case,%s"%obj.id,
|
|
|
|
"currency_id": currency_id,
|
|
|
|
"company_id": company_id,
|
|
|
|
"lines": [],
|
|
|
|
"company_id": company_id,
|
|
|
|
}
|
|
|
|
vals["partner_id"]=obj.fee_partner_id.id
|
2014-10-06 00:48:42 +00:00
|
|
|
# XXX
|
|
|
|
#if obj.fee_partner_id.account_payable_id:
|
|
|
|
#account_receivable_id=obj.fee_partner_id.account_payable_id.id
|
|
|
|
if obj.fee_partner_id.account_receivable_id:
|
|
|
|
account_id=obj.fee_partner_id.account_receivable_id.id or account_receivable_id
|
|
|
|
if not account_receivable_id:
|
|
|
|
raise Exception("%s not found account recievable %s"%obj.fee_partner_id.name)
|
2014-10-03 02:00:47 +00:00
|
|
|
line={
|
|
|
|
"product_id": None,
|
|
|
|
"description": "Fee",
|
|
|
|
"qty": 1,
|
|
|
|
"uom_id": uom[0].id,
|
|
|
|
"unit_price": obj.fee,
|
|
|
|
"amount": obj.fee,
|
2014-10-06 00:48:42 +00:00
|
|
|
'account_id': account_id,
|
2014-10-03 02:00:47 +00:00
|
|
|
}
|
|
|
|
vals['lines'].append(('create',line))
|
|
|
|
inv_id=get_model("account.invoice").create(vals,context)
|
|
|
|
|
2014-10-03 07:27:57 +00:00
|
|
|
def make_pickings(self,ids,context={}):
|
|
|
|
obj=self.browse(ids[0])
|
|
|
|
# no picking
|
|
|
|
if not obj.lines:
|
|
|
|
return
|
|
|
|
|
|
|
|
partner=obj.patient_id.partner_id
|
|
|
|
if not partner:
|
|
|
|
raise Exception("Contact not for this patient")
|
|
|
|
ship_address_id=None
|
|
|
|
for address in partner.addresses:
|
|
|
|
if address.type=="shipping":
|
|
|
|
ship_address_id=address.id
|
|
|
|
break
|
|
|
|
if not ship_address_id:
|
|
|
|
raise Exception("contact %s dont'have address with type shipping"%partner.name)
|
|
|
|
pick_vals={
|
|
|
|
"type": "out",
|
|
|
|
"ref": obj.number,
|
|
|
|
"related_id": "clinic.hd.case,%s"%obj.id,
|
|
|
|
"partner_id": obj.patient_id.partner_id.id,
|
|
|
|
"ship_address_id": ship_address_id,
|
|
|
|
"state": "draft",
|
|
|
|
"lines": [],
|
|
|
|
}
|
|
|
|
res=get_model("stock.location").search([["type","=","customer"]])
|
|
|
|
if not res:
|
|
|
|
raise Exception("Customer location not found")
|
|
|
|
cust_loc_id=res[0]
|
|
|
|
|
|
|
|
|
|
|
|
for line in obj.lines:
|
|
|
|
prod=line.product_id
|
|
|
|
if prod.type != 'stock':
|
|
|
|
continue
|
|
|
|
wh_loc_id=prod.location_id.id
|
|
|
|
if not wh_loc_id:
|
|
|
|
res=get_model("stock.location").search([["type","=","internal"]])
|
|
|
|
if not res:
|
|
|
|
raise Exception("Warehouse not found")
|
|
|
|
wh_loc_id=res[0]
|
|
|
|
line_vals={
|
|
|
|
"product_id": prod.id,
|
|
|
|
"qty": 1,
|
|
|
|
"uom_id": prod.uom_id.id,
|
|
|
|
"location_from_id": wh_loc_id,
|
|
|
|
"location_to_id": cust_loc_id,
|
|
|
|
}
|
|
|
|
pick_vals["lines"].append(("create",line_vals))
|
|
|
|
if not pick_vals["lines"]:
|
|
|
|
return {
|
|
|
|
"flash": "Nothing left to deliver",
|
|
|
|
}
|
|
|
|
picking_obj=get_model("stock.picking")
|
|
|
|
pick_id=picking_obj.create(pick_vals,context={"pick_type": "out"})
|
|
|
|
pick=picking_obj.browse(pick_id)
|
|
|
|
pick.set_done([pick_id])
|
|
|
|
|
2014-10-03 02:00:47 +00:00
|
|
|
def post_invoices(self,ids,context={}):
|
|
|
|
obj=self.browse(ids[0])
|
|
|
|
for inv in obj.invoices:
|
|
|
|
inv.post()
|
|
|
|
print("Post!")
|
2014-10-02 19:12:52 +00:00
|
|
|
|
|
|
|
def confirm(self,ids,context={}):
|
2014-09-11 03:21:52 +00:00
|
|
|
obj=self.browse(ids)[0]
|
2014-10-04 18:33:18 +00:00
|
|
|
obj.write({"state":"in_progress"})
|
2014-09-11 03:21:52 +00:00
|
|
|
|
2014-10-05 05:47:19 +00:00
|
|
|
def discontinue(self,ids,context={}):
|
2014-09-11 03:21:52 +00:00
|
|
|
obj=self.browse(ids)[0]
|
2014-10-05 05:47:19 +00:00
|
|
|
# TODO pop to note
|
|
|
|
obj.write({"state":"uncompleted"})
|
2014-10-02 19:12:52 +00:00
|
|
|
|
2014-10-04 18:33:18 +00:00
|
|
|
def complete(self,ids,context={}):
|
2014-10-02 19:12:52 +00:00
|
|
|
obj=self.browse(ids)[0]
|
2014-10-03 02:00:47 +00:00
|
|
|
obj.make_invoices()
|
|
|
|
obj.post_invoices()
|
2014-10-04 18:33:18 +00:00
|
|
|
obj.write({
|
|
|
|
"state":"completed",
|
2014-10-05 09:56:36 +00:00
|
|
|
#'paid': True,
|
2014-10-04 18:33:18 +00:00
|
|
|
})
|
2014-10-03 02:00:47 +00:00
|
|
|
return {
|
|
|
|
'next': {
|
|
|
|
'name': 'clinic_hd_case',
|
|
|
|
'mode': 'form',
|
|
|
|
'active_id': obj.id,
|
|
|
|
},
|
2014-10-04 18:33:18 +00:00
|
|
|
'flash': '%s is completed'%obj.number,
|
2014-10-03 02:00:47 +00:00
|
|
|
}
|
2014-09-11 03:21:52 +00:00
|
|
|
|
|
|
|
def journal_report(self,ids,context={}):
|
|
|
|
obj=self.browse(ids[0])
|
|
|
|
move_id = get_model("account.move").search([["narration","=",obj.number]])
|
|
|
|
if not move_id:
|
|
|
|
raise Exception("Order is not post or nove have jounal entry.")
|
|
|
|
return {
|
|
|
|
"next": {
|
|
|
|
"name": "journal_entry",
|
|
|
|
"mode":"form",
|
|
|
|
"active_id":move_id[0],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def get_total(self,ids,context={}):
|
|
|
|
vals={}
|
|
|
|
for obj in self.browse(ids):
|
|
|
|
total=0
|
|
|
|
amt=0
|
2014-10-01 07:47:50 +00:00
|
|
|
fee=obj.fee or 0
|
2014-10-02 19:12:52 +00:00
|
|
|
for line in obj.lines:
|
2014-10-03 02:00:47 +00:00
|
|
|
total+=line.amount or 0
|
2014-10-02 07:36:13 +00:00
|
|
|
fee=0 # XXX
|
2014-09-11 03:21:52 +00:00
|
|
|
amt=total+fee
|
|
|
|
vals[obj.id]={
|
|
|
|
"total": total,
|
|
|
|
"amount": amt,
|
|
|
|
}
|
|
|
|
return vals
|
|
|
|
|
2014-10-01 10:52:21 +00:00
|
|
|
def view_hdcase(self,ids,context={}):
|
|
|
|
return {
|
|
|
|
'name': 'clinic_hd_case',
|
|
|
|
'mode': 'form',
|
|
|
|
'form_view_xml': 'clinic_hd_case_form',
|
|
|
|
'active_id': ids[0],
|
|
|
|
}
|
2014-10-02 07:36:13 +00:00
|
|
|
|
2014-10-02 19:12:52 +00:00
|
|
|
def delete(self,ids,context={}):
|
|
|
|
for obj in self.browse(ids):
|
|
|
|
if obj.state != 'draft':
|
|
|
|
raise Exception("Can not delete HD Case %s because state is not draft"%obj.number)
|
|
|
|
super().delete(ids)
|
|
|
|
|
|
|
|
def onchange_fee_type(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
fee_type=data.get("fee_type","")
|
|
|
|
if fee_type in ("mg","sc","nhso"):
|
|
|
|
data['fee']=1500
|
|
|
|
else:
|
|
|
|
data['fee']=0.0
|
|
|
|
return data
|
2014-10-05 08:29:21 +00:00
|
|
|
|
|
|
|
def new_visit(self,ids,context={}):
|
|
|
|
obj=self.browse(ids[0])
|
|
|
|
skip_plan_id=0
|
2014-10-05 08:36:58 +00:00
|
|
|
plane=None
|
2014-10-05 08:29:21 +00:00
|
|
|
for plane in obj.planes:
|
|
|
|
if plane.state=='close':
|
|
|
|
continue
|
|
|
|
break
|
|
|
|
# XXX
|
|
|
|
if not plane or plane.state=='close':
|
|
|
|
raise Exception("No Planing")
|
|
|
|
print("found plane ",plane)
|
|
|
|
vals={
|
|
|
|
'date_visit': plane.date,
|
|
|
|
'time_start': plane.time_start,
|
|
|
|
'time_stop': plane.time_stop,
|
|
|
|
'patient_id': obj.patient_id.id,
|
|
|
|
'doctor_id': obj.doctor_id.id,
|
|
|
|
'nurse_id': obj.nurse_id.id,
|
|
|
|
'department_id': obj.department_id.id,
|
|
|
|
'planes': [],
|
|
|
|
'dialyzers': [],
|
|
|
|
#'state': 'waiting_treatment',
|
|
|
|
'state': 'draft', # XXX need to gen new doc
|
|
|
|
}
|
|
|
|
plane.write({
|
|
|
|
'state': 'close',
|
|
|
|
})
|
|
|
|
visit_id=get_model("clinic.visit").create(vals)
|
|
|
|
visit=get_model('clinic.visit').browse(visit_id)
|
|
|
|
skip_plan_id=plane.id
|
|
|
|
# copy remaining plane to new visit
|
|
|
|
new_planes=[]
|
|
|
|
for pl in obj.planes:
|
|
|
|
# XXX
|
|
|
|
if skip_plan_id==pl.id:
|
|
|
|
continue
|
|
|
|
if pl.state=='close':
|
|
|
|
continue
|
|
|
|
print("pl state ", pl.state)
|
|
|
|
line={
|
|
|
|
'date': pl.date,
|
|
|
|
'time_start': pl.time_start,
|
|
|
|
'time_stop': pl.time_stop,
|
|
|
|
'visit_id': visit_id,
|
|
|
|
}
|
|
|
|
new_planes.append(('create',line))
|
|
|
|
new_dialyzers=[]
|
|
|
|
for dlz in obj.dialyzers:
|
|
|
|
if dlz.use_time > dlz.dialyzer_id.max_use_time:
|
|
|
|
continue
|
|
|
|
use_time=(dlz.use_time or 0)+1
|
|
|
|
line={
|
|
|
|
"visit_id": visit_id,
|
|
|
|
"dialyzer_id": dlz.dialyzer_id.id,
|
|
|
|
"description": dlz.description,
|
|
|
|
"use_time": use_time,
|
|
|
|
"max_use_time": dlz.max_use_time,
|
|
|
|
"member_type": dlz.member_type,
|
|
|
|
"dialyzer_type": dlz.dialyzer_type,
|
|
|
|
"bid_flow_rate": dlz.bid_flow_rate,
|
|
|
|
"ultrafittration": dlz.ultrafittration,
|
|
|
|
}
|
|
|
|
new_dialyzers.append(('create',line))
|
|
|
|
vals={
|
|
|
|
'planes': new_planes,
|
|
|
|
'dialyzers': new_dialyzers,
|
|
|
|
}
|
|
|
|
visit.write(vals)
|
|
|
|
return {
|
|
|
|
'next': {
|
|
|
|
'name': "clinic_visit",
|
|
|
|
'mode': 'form',
|
|
|
|
'active_id': visit_id,
|
|
|
|
},
|
|
|
|
'flash': "New visit is created",
|
|
|
|
}
|
|
|
|
|
|
|
|
def onchange_dateplane(self,context={}):
|
|
|
|
data=context["data"]
|
|
|
|
path=context["path"]
|
|
|
|
line=get_data_path(data,path,parent=True)
|
|
|
|
start_date=line.get("date")
|
|
|
|
if not start_date:
|
|
|
|
return {}
|
|
|
|
timenow=time.strftime("%H:%M:%S")
|
|
|
|
timevisit=timenow
|
|
|
|
# XXX
|
|
|
|
timevisit=data['time_start'][11:20]
|
|
|
|
fmt_date="%Y-%m-%d %H:%M:%S"
|
|
|
|
fix_hrs=data['total_time'] or 0 # XXX
|
|
|
|
time_start=datetime.strptime("%s %s"%(start_date,timevisit),fmt_date)
|
|
|
|
seconds=fix_hrs*3600
|
|
|
|
time_stop=time_start+timedelta(seconds=seconds)
|
|
|
|
line['time_start']=time_start.strftime(fmt_date)
|
|
|
|
line['time_stop']=time_stop.strftime(fmt_date)
|
|
|
|
if not line.get('state'):
|
|
|
|
line['state']='open'
|
|
|
|
|
|
|
|
return data
|
2014-10-05 09:43:28 +00:00
|
|
|
|
2014-10-01 10:52:21 +00:00
|
|
|
|
2014-10-01 06:51:36 +00:00
|
|
|
HDcase.register()
|