payment
parent
26e8119935
commit
563fd8a1aa
|
@ -2,8 +2,8 @@
|
||||||
<head>
|
<head>
|
||||||
<field name="state"/>
|
<field name="state"/>
|
||||||
<button string="Options" dropdown="1">
|
<button string="Options" dropdown="1">
|
||||||
<item string="Create Journal" method="create_journal" states="draft"/>
|
<item string="Create Payment" method="create_payment" states="draft"/>
|
||||||
<item string="View Journal" method="view_journal" states="done"/>
|
<item string="View Payment" method="view_payment" states="done"/>
|
||||||
<item string="To Draft" method="to_draft" states="done"/>
|
<item string="To Draft" method="to_draft" states="done"/>
|
||||||
</button>
|
</button>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
<list model="clinic.cycle.item" colors='{"#9f9":[["state","=","done"]]}'>
|
<list model="clinic.cycle.item" colors='{"#9f9":[["state","=","done"]]}'>
|
||||||
|
<head>
|
||||||
|
<button string="Pay" method="pay" icon="ok" type="success" confirm="Are you sure?"/>
|
||||||
|
<!--<button string="To Draft" method="to_drafts" icon="repeat" type="default" confirm="Are you sure?"/>-->
|
||||||
|
</head>
|
||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="cycle_id"/>
|
<field name="cycle_id"/>
|
||||||
<field name="date"/>
|
<field name="date"/>
|
||||||
|
|
|
@ -1,4 +1,14 @@
|
||||||
<form model="clinic.setting" title="Clinic Settings">
|
<form model="clinic.setting" title="Clinic Settings">
|
||||||
|
<tabs>
|
||||||
|
<tab string="Testing">
|
||||||
|
<field name="file"/>
|
||||||
|
<newline/>
|
||||||
|
<button string="Read Case" method="read_hd_case"/>
|
||||||
|
<button string="Post" method="done_hd_case"/>
|
||||||
|
</tab>
|
||||||
|
<tab string="General">
|
||||||
<separator string="Labor Cost"/>
|
<separator string="Labor Cost"/>
|
||||||
<field name="var_k"/>
|
<field name="var_k"/>
|
||||||
|
</tab>
|
||||||
|
</tabs>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -9,5 +9,6 @@
|
||||||
<field name="ap_nhso_id"/>
|
<field name="ap_nhso_id"/>
|
||||||
<field name="ap_nurse_id"/>
|
<field name="ap_nurse_id"/>
|
||||||
<field name="ap_doctor_id"/>
|
<field name="ap_doctor_id"/>
|
||||||
|
<field name="hospital_code"/>
|
||||||
</field>
|
</field>
|
||||||
</inherit>
|
</inherit>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<form title="Import Social Security">
|
<form title="Import Social Security">
|
||||||
<group span="6" columns="1">
|
<group span="6" columns="1">
|
||||||
<field name="file"/>
|
<field name="file"/>
|
||||||
|
<field name="hcode"/>
|
||||||
</group>
|
</group>
|
||||||
<group span="6" columns="1">
|
<group span="6" columns="1">
|
||||||
<separator string="Result"/>
|
<separator string="Result"/>
|
||||||
|
|
|
@ -42,4 +42,5 @@ from . import import_data_sc
|
||||||
from . import translate
|
from . import translate
|
||||||
from . import payment
|
from . import payment
|
||||||
from . import account_payment
|
from . import account_payment
|
||||||
|
from . import account_invoice
|
||||||
from . import personal_categ
|
from . import personal_categ
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
from netforce.model import Model, fields, get_model
|
||||||
|
|
||||||
|
class AccountPayment(Model):
|
||||||
|
_inherit="account.payment"
|
||||||
|
|
||||||
|
def run_report(self,ids,context={}):
|
||||||
|
obj=self.browse(ids)[0]
|
||||||
|
hd_case_id=obj.related_id.id
|
||||||
|
hd_case=get_model("clinic.hd.case").browse(hd_case_id)
|
||||||
|
# TODO
|
||||||
|
# set payment_id on hd case
|
||||||
|
# send to action print form payment
|
||||||
|
hd_case.write({
|
||||||
|
'payment_id': obj.id,
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
'next': {
|
||||||
|
'name': 'report_clinic_payment_form',
|
||||||
|
'refer_id': hd_case_id,
|
||||||
|
'payment_id': obj.id,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
AccountPayment.register()
|
|
@ -20,10 +20,10 @@ class CycleItem(Model):
|
||||||
x=(pt_k + 1275)/13.5
|
x=(pt_k + 1275)/13.5
|
||||||
total=0.0
|
total=0.0
|
||||||
for line in obj.nurse_lines:
|
for line in obj.nurse_lines:
|
||||||
total+=line.amount
|
total+=(line.amount or 0.0)
|
||||||
total2=0.0
|
total2=0.0
|
||||||
for line in obj.doctor_lines:
|
for line in obj.doctor_lines:
|
||||||
total2+=line.amount
|
total2+=(line.amount or 0.0)
|
||||||
res[obj.id]={
|
res[obj.id]={
|
||||||
'name': name,
|
'name': name,
|
||||||
'var_x': x,
|
'var_x': x,
|
||||||
|
@ -102,6 +102,7 @@ class CycleItem(Model):
|
||||||
'formular': categ.formular,
|
'formular': categ.formular,
|
||||||
'qty': qty,
|
'qty': qty,
|
||||||
'rate': obj.var_doctor or 0.0,
|
'rate': obj.var_doctor or 0.0,
|
||||||
|
'amount': qty*obj.var_doctor,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
print(nurse_dict)
|
print(nurse_dict)
|
||||||
|
@ -115,13 +116,16 @@ class CycleItem(Model):
|
||||||
rate=eval(formulared)
|
rate=eval(formulared)
|
||||||
except:
|
except:
|
||||||
rate=0
|
rate=0
|
||||||
|
qty=nurse_dict.get(personal_categ.code,0)
|
||||||
vals['nurse_lines'].append(('create',{
|
vals['nurse_lines'].append(('create',{
|
||||||
'personal_categ': personal_categ.id,
|
'personal_categ': personal_categ.id,
|
||||||
'type': 'nurse',
|
'type': 'nurse',
|
||||||
'formular': formular,
|
'formular': formular,
|
||||||
'qty': nurse_dict.get(personal_categ.code,0),
|
'qty': qty,
|
||||||
'rate': rate,
|
'rate': rate,
|
||||||
|
'amount': qty*rate,
|
||||||
}))
|
}))
|
||||||
|
print("qty * rate ", qty, ' ', rate)
|
||||||
|
|
||||||
obj.write(vals)
|
obj.write(vals)
|
||||||
|
|
||||||
|
@ -142,25 +146,28 @@ class CycleItem(Model):
|
||||||
#rate=line.get("rate")
|
#rate=line.get("rate")
|
||||||
total=0.0
|
total=0.0
|
||||||
for line in data['nurse_lines']:
|
for line in data['nurse_lines']:
|
||||||
line['amount']=(line['qty'] or 0) * (line['rate'] or 0.0)
|
#line['amount']=(line['qty'] or 0) * (line['rate'] or 0.0)
|
||||||
|
formular=line['formular']
|
||||||
|
print(formular)
|
||||||
|
qty=line['qty']
|
||||||
|
rate=line['rate']
|
||||||
|
line['amount']=qty*rate
|
||||||
total+=line['amount']
|
total+=line['amount']
|
||||||
print(line)
|
|
||||||
data['total']=total
|
data['total']=total
|
||||||
data['total_amount']=data['total_pt']*(data['var_k'] or 0)
|
data['total_amount']=data['total_pt']*(data['var_k'] or 0)
|
||||||
data['total_balance']=data['total_amount']-data['total']
|
data['total_balance']=data['total_amount']-data['total']
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def create_journal(self,ids,context={}):
|
def create_payment(self,ids,context={}):
|
||||||
obj=self.browse(ids)[0]
|
obj=self.browse(ids)[0]
|
||||||
settings=get_model("settings").browse(1)
|
settings=get_model("settings").browse(1)
|
||||||
account_id=settings.ap_nurse_id.id
|
account_id=settings.ap_nurse_id.id
|
||||||
if not account_id:
|
if not account_id:
|
||||||
raise Exception("No Account payment for nurse")
|
raise Exception("No Account payment for Nurse")
|
||||||
vals={
|
vals={
|
||||||
"company_id": obj.company_id.id,
|
"company_id": obj.company_id.id,
|
||||||
"type": "in",
|
"type": "out",
|
||||||
"pay_type": "direct",
|
"pay_type": "direct",
|
||||||
#"date": time.strftime("%Y-%m-%d"),
|
|
||||||
"date": obj.date or time.strftime("%Y-%m-%d"),
|
"date": obj.date or time.strftime("%Y-%m-%d"),
|
||||||
"account_id": account_id,
|
"account_id": account_id,
|
||||||
'related_id': "clinic.cycle.item,%s"%obj.id,
|
'related_id': "clinic.cycle.item,%s"%obj.id,
|
||||||
|
@ -176,6 +183,9 @@ class CycleItem(Model):
|
||||||
'unit_price': line.amount,
|
'unit_price': line.amount,
|
||||||
'amount': line.amount,
|
'amount': line.amount,
|
||||||
}))
|
}))
|
||||||
|
account_id=settings.ap_doctor_id.id
|
||||||
|
if not account_id:
|
||||||
|
raise Exception("No Account payment for Doctor")
|
||||||
for line in obj.doctor_lines:
|
for line in obj.doctor_lines:
|
||||||
if not line.amount:
|
if not line.amount:
|
||||||
continue
|
continue
|
||||||
|
@ -188,10 +198,12 @@ class CycleItem(Model):
|
||||||
}))
|
}))
|
||||||
|
|
||||||
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
|
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
|
||||||
get_model("account.payment").browse(payment_id).post()
|
#get_model("account.payment").browse(payment_id).post()
|
||||||
obj.write({
|
obj.write({
|
||||||
'state': 'done',
|
'state': 'done',
|
||||||
})
|
})
|
||||||
|
if context.get('called'):
|
||||||
|
return obj.id
|
||||||
return {
|
return {
|
||||||
'next': {
|
'next': {
|
||||||
'name': 'payment',
|
'name': 'payment',
|
||||||
|
@ -210,6 +222,8 @@ class CycleItem(Model):
|
||||||
obj.write({
|
obj.write({
|
||||||
'state': 'draft',
|
'state': 'draft',
|
||||||
})
|
})
|
||||||
|
if context.get('called'):
|
||||||
|
return obj.id
|
||||||
return {
|
return {
|
||||||
'next': {
|
'next': {
|
||||||
'name': 'clinic_cycle_item',
|
'name': 'clinic_cycle_item',
|
||||||
|
@ -219,7 +233,19 @@ class CycleItem(Model):
|
||||||
'flash': 'Cycle item is set to draft',
|
'flash': 'Cycle item is set to draft',
|
||||||
}
|
}
|
||||||
|
|
||||||
def view_journal(self,ids,context={}):
|
def to_drafts(self,ids,context={}):
|
||||||
|
for obj in self.browse(ids):
|
||||||
|
context['called']=True
|
||||||
|
obj.to_draft(context=context)
|
||||||
|
return {
|
||||||
|
'next': {
|
||||||
|
'name': 'clinic_cycle_item',
|
||||||
|
'mode': 'list',
|
||||||
|
},
|
||||||
|
'flash': 'Cycle item is set to draft',
|
||||||
|
}
|
||||||
|
|
||||||
|
def view_payment(self,ids,context={}):
|
||||||
obj=self.browse(ids)[0]
|
obj=self.browse(ids)[0]
|
||||||
related_id="clinic.cycle.item,%s"%obj.id
|
related_id="clinic.cycle.item,%s"%obj.id
|
||||||
payment_ids=get_model("account.payment").search([['related_id','=',related_id]])
|
payment_ids=get_model("account.payment").search([['related_id','=',related_id]])
|
||||||
|
@ -234,4 +260,16 @@ class CycleItem(Model):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def pay(self,ids,context={}):
|
||||||
|
context['called']=True
|
||||||
|
for obj in self.browse(ids):
|
||||||
|
obj.create_payment(context)
|
||||||
|
return {
|
||||||
|
'next': {
|
||||||
|
'name': 'clinic_cycle_item',
|
||||||
|
'mode': 'list',
|
||||||
|
},
|
||||||
|
'flash': 'Paid',
|
||||||
|
}
|
||||||
|
|
||||||
CycleItem.register()
|
CycleItem.register()
|
||||||
|
|
|
@ -21,7 +21,8 @@ class CycleItemLine(Model):
|
||||||
'description': fields.Char("Description"),
|
'description': fields.Char("Description"),
|
||||||
'qty': fields.Integer("Qty"),
|
'qty': fields.Integer("Qty"),
|
||||||
'rate': fields.Float("Rate"),
|
'rate': fields.Float("Rate"),
|
||||||
'amount': fields.Float("Amount",function="all_amount", function_multi=True),
|
#'amount': fields.Float("Amount",function="all_amount", function_multi=True),
|
||||||
|
'amount': fields.Float("Amount"),
|
||||||
'company_id': fields.Many2One('company','Company'),
|
'company_id': fields.Many2One('company','Company'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,8 @@ class Settings(Model):
|
||||||
"ar_nhso_id": fields.Many2One("account.account","Account Recieve NHSO 30B"),
|
"ar_nhso_id": fields.Many2One("account.account","Account Recieve NHSO 30B"),
|
||||||
"ar_sc_id": fields.Many2One("account.account","Account Recieve Social Security"),
|
"ar_sc_id": fields.Many2One("account.account","Account Recieve Social Security"),
|
||||||
"ap_nurse_id": fields.Many2One("account.account","Account Payment Nurse"),
|
"ap_nurse_id": fields.Many2One("account.account","Account Payment Nurse"),
|
||||||
"ap_doctor_id": fields.Many2One("account.account","Account Doctor Nurse"),
|
"ap_doctor_id": fields.Many2One("account.account","Account Payment Doctor"),
|
||||||
|
'hospital_code': fields.Char("Hospital Code", multi_company=True),
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings.register()
|
Settings.register()
|
||||||
|
|
|
@ -67,7 +67,7 @@ class HDCase(Model):
|
||||||
'fee_paid': fields.Boolean("Fee Paid"),
|
'fee_paid': fields.Boolean("Fee Paid"),
|
||||||
'note': fields.Text("Note"),
|
'note': fields.Text("Note"),
|
||||||
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
|
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
|
||||||
"cycle_item_id": fields.Many2One("clinic.cycle.item","Cycle Item"), # compute labor cost
|
"cycle_item_id": fields.Many2One("clinic.cycle.item","Cycle Item",on_delete="cascade"), # compute labor cost
|
||||||
'pay_amount': fields.Float("Amount",function="get_pay_amount"),
|
'pay_amount': fields.Float("Amount",function="get_pay_amount"),
|
||||||
'pay_date': fields.Date("Pay Date"),
|
'pay_date': fields.Date("Pay Date"),
|
||||||
'pay_account_id': fields.Many2One("account.account","Account"),
|
'pay_account_id': fields.Many2One("account.account","Account"),
|
||||||
|
@ -465,6 +465,8 @@ class HDCase(Model):
|
||||||
def create_cycle_item(self,ids,context={}):
|
def create_cycle_item(self,ids,context={}):
|
||||||
for obj in self.browse(ids):
|
for obj in self.browse(ids):
|
||||||
cycle_item=get_model("clinic.cycle.item")
|
cycle_item=get_model("clinic.cycle.item")
|
||||||
|
datenow=obj.start_time[0:10]
|
||||||
|
if not datenow:
|
||||||
datenow=time.strftime('%Y-%m-%d')
|
datenow=time.strftime('%Y-%m-%d')
|
||||||
cycle_id=obj.cycle_id.id
|
cycle_id=obj.cycle_id.id
|
||||||
cycle_item_ids=cycle_item.search([['date','=',datenow],['cycle_id','=',cycle_id]])
|
cycle_item_ids=cycle_item.search([['date','=',datenow],['cycle_id','=',cycle_id]])
|
||||||
|
|
|
@ -12,14 +12,22 @@ from netforce.database import get_connection
|
||||||
class ImportPayment(Model):
|
class ImportPayment(Model):
|
||||||
_name="clinic.import.payment"
|
_name="clinic.import.payment"
|
||||||
_transient=True
|
_transient=True
|
||||||
|
|
||||||
_fields={
|
_fields={
|
||||||
'date': fields.DateTime("Date"),
|
'date': fields.DateTime("Date"),
|
||||||
'file': fields.File("File"),
|
'file': fields.File("File"),
|
||||||
'result': fields.Text("Success"),
|
'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={
|
_defaults={
|
||||||
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
|
'hcode': get_hcode,
|
||||||
}
|
}
|
||||||
|
|
||||||
def read_excel(self,fpath=None):
|
def read_excel(self,fpath=None):
|
||||||
|
@ -172,6 +180,7 @@ class ImportPayment(Model):
|
||||||
fpath=get_file_path(fname)
|
fpath=get_file_path(fname)
|
||||||
print("fpath ", fpath)
|
print("fpath ", fpath)
|
||||||
|
|
||||||
|
def test_sc(self,ids,context={}):
|
||||||
|
pass
|
||||||
|
|
||||||
ImportPayment.register()
|
ImportPayment.register()
|
||||||
|
|
|
@ -1,10 +1,219 @@
|
||||||
|
import time
|
||||||
|
import random
|
||||||
|
import datetime
|
||||||
|
import xlrd
|
||||||
|
import xmltodict
|
||||||
|
|
||||||
from netforce.model import Model, fields, get_model
|
from netforce.model import Model, fields, get_model
|
||||||
|
from netforce.utils import get_file_path
|
||||||
|
from netforce.database import get_connection
|
||||||
|
|
||||||
class ClinicSetting(Model):
|
class ClinicSetting(Model):
|
||||||
_name="clinic.setting"
|
_name="clinic.setting"
|
||||||
_string="Setting"
|
_string="Setting"
|
||||||
_fields={
|
_fields={
|
||||||
"var_k": fields.Float("K"),
|
"var_k": fields.Float("K"),
|
||||||
|
'file': fields.File("File"),
|
||||||
}
|
}
|
||||||
|
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_cash(self,ids,context={}):
|
||||||
|
obj=self.browse(ids)[0]
|
||||||
|
fname=obj.file
|
||||||
|
fpath=get_file_path(fname)
|
||||||
|
lines=self.read_excel(fpath)
|
||||||
|
if not lines:
|
||||||
|
raise Exception("Wrong File")
|
||||||
|
medicals=[]
|
||||||
|
patients=[]
|
||||||
|
for line in lines:
|
||||||
|
medical=line['medical'] or ""
|
||||||
|
if not medical in medicals:
|
||||||
|
medicals.append(medical)
|
||||||
|
patient=line['hn'] or ""
|
||||||
|
name14=line['name14'] or ""
|
||||||
|
value=(patient,name14)
|
||||||
|
if not value in patients:
|
||||||
|
patients.append(value)
|
||||||
|
#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,
|
||||||
|
#}
|
||||||
|
products=[p['name'] for p in get_model("product").search_read([],['name'])]
|
||||||
|
print('generate product')
|
||||||
|
print("="*50)
|
||||||
|
seq=1
|
||||||
|
for md in medicals:
|
||||||
|
md=md.replace(" ","")
|
||||||
|
if not md:
|
||||||
|
continue
|
||||||
|
if not md in products:
|
||||||
|
vals={
|
||||||
|
'code': "m"+("%s"%seq).zfill(4),
|
||||||
|
'name':md,
|
||||||
|
'uom_id': 2,
|
||||||
|
'type': 'stock',
|
||||||
|
}
|
||||||
|
seq+=1
|
||||||
|
prod_id=get_model("product").create(vals)
|
||||||
|
print(prod_id)
|
||||||
|
|
||||||
|
print("="*50)
|
||||||
|
print('generate patient')
|
||||||
|
hns=[pt['hn'] for pt in get_model("clinic.patient").search_read([],['hn'])]
|
||||||
|
for hn, name in patients:
|
||||||
|
hn=hn.replace(' ',"")
|
||||||
|
if not hn:
|
||||||
|
continue
|
||||||
|
if not hn in hns:
|
||||||
|
vals={
|
||||||
|
'hn': hn,
|
||||||
|
'name': name,
|
||||||
|
'type': 'sc',
|
||||||
|
}
|
||||||
|
pt_id=get_model("clinic.patient").create(vals)
|
||||||
|
print('hn ', pt_id)
|
||||||
|
print("="*50)
|
||||||
|
patients=get_model("clinic.patient").search_read([],['name','hn'])
|
||||||
|
visits=get_model("clinic.visit").search_read([],['number','time_start','cycle_id','state'])
|
||||||
|
doctor_ids=[dt['id'] for dt in get_model("clinic.doctor").search_read([],['name'])]
|
||||||
|
nurse_ids=[ns['id'] for ns in get_model("clinic.nurse").search_read([],['name'])]
|
||||||
|
cycle_ids=[cc['id'] for cc in get_model("clinic.cycle").search_read([],['name'])]
|
||||||
|
department_ids=[dp['id'] for dp in get_model("clinic.department").search_read([],['name'])]
|
||||||
|
#db=get_connection()
|
||||||
|
def get_patient(hn):
|
||||||
|
for pt in patients:
|
||||||
|
if hn==pt['hn']:
|
||||||
|
return pt
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_visit(date,cycle_name=None,state=None):
|
||||||
|
for visit in visits:
|
||||||
|
if date==visit['time_start'][0:10]:
|
||||||
|
if state:
|
||||||
|
print(state, " ", visit['state'])
|
||||||
|
if visit['state']==state:
|
||||||
|
if cycle_name:
|
||||||
|
if cycle_name==visit['cycle_id'][1]:
|
||||||
|
return visit
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
return visit
|
||||||
|
else:
|
||||||
|
print("else ")
|
||||||
|
return None
|
||||||
|
return visit
|
||||||
|
print("="*50)
|
||||||
|
print("create simple visit")
|
||||||
|
timenow=time.strftime("%H:%M:%S")
|
||||||
|
timenow2="%s:%s:%s" % (int(time.strftime("%H"))+1, time.strftime("%M"), time.strftime("%S"))
|
||||||
|
time_start=timenow
|
||||||
|
for line in lines:
|
||||||
|
hn=line['hn']
|
||||||
|
date=line['dttran']
|
||||||
|
visit=get_visit(date)
|
||||||
|
if not visit:
|
||||||
|
patient=get_patient(hn)
|
||||||
|
if patient:
|
||||||
|
time_start="%s %s"%(date,timenow)
|
||||||
|
time_stop="%s %s"%(date,timenow2)
|
||||||
|
vals={
|
||||||
|
'time_start': time_start,
|
||||||
|
'time_stop': time_stop,
|
||||||
|
'patient_id': patient['id'],
|
||||||
|
'cycle_id': random.choice(cycle_ids),
|
||||||
|
'nurse_id': random.choice(nurse_ids),
|
||||||
|
'doctor_id': random.choice(doctor_ids),
|
||||||
|
'department_id': random.choice(department_ids),
|
||||||
|
}
|
||||||
|
visit_id=get_model("clinic.visit").create(vals)
|
||||||
|
print("create visit %s ", visit_id)
|
||||||
|
print("="*50)
|
||||||
|
print("visit with state is draft")
|
||||||
|
count=0
|
||||||
|
for line in lines:
|
||||||
|
date=line['dttran']
|
||||||
|
# prevent timeout
|
||||||
|
if count > 10:
|
||||||
|
break
|
||||||
|
visit=get_visit(date=date,state='draft')
|
||||||
|
if visit:
|
||||||
|
visit_id=visit['id']
|
||||||
|
context['called']=True
|
||||||
|
hd_case_id=get_model("clinic.visit").browse(visit_id).confirm(context=context)
|
||||||
|
#allow37=line['allow37']
|
||||||
|
hct=line['hct']
|
||||||
|
medical=line['medical']
|
||||||
|
medical_cost=line['medical_cost']
|
||||||
|
inject_service=line['inject_service']
|
||||||
|
vals={
|
||||||
|
'hct': hct and hct or 0,
|
||||||
|
'lines': [],
|
||||||
|
}
|
||||||
|
if medical:
|
||||||
|
prods=get_model("product").search_browse([['name','=',medical]])
|
||||||
|
if prods:
|
||||||
|
prod=prods[0]
|
||||||
|
vals['lines'].append(('create',{
|
||||||
|
'type': 'other',
|
||||||
|
'product_id': prod.id,
|
||||||
|
'description': prod.name,
|
||||||
|
'uom_id': prod.uom_id.id,
|
||||||
|
'qty': 1,
|
||||||
|
'price': medical_cost,
|
||||||
|
'amount': medical_cost,
|
||||||
|
}))
|
||||||
|
if inject_service:
|
||||||
|
vals['lines'].append(('create',{
|
||||||
|
'type': 'other',
|
||||||
|
'product_id': 55, #XXX
|
||||||
|
'description': prod.name,
|
||||||
|
'uom_id': prod.uom_id.id,
|
||||||
|
'qty': 1,
|
||||||
|
'price': medical_cost,
|
||||||
|
'amount': medical_cost,
|
||||||
|
}))
|
||||||
|
hd_case=get_model("clinic.hd.case").browse(hd_case_id)
|
||||||
|
hd_case.write(vals)
|
||||||
|
count+=1
|
||||||
|
print("#%s write hd_case %s ok and visit %s" % (count,hd_case_id,hd_case.visit_id.number))
|
||||||
|
print("="*50)
|
||||||
|
print("Done")
|
||||||
|
return
|
||||||
|
|
||||||
ClinicSetting.register()
|
ClinicSetting.register()
|
||||||
|
|
|
@ -93,7 +93,7 @@ class Visit(Model):
|
||||||
def confirm(self,ids,context={}):
|
def confirm(self,ids,context={}):
|
||||||
obj=self.browse(ids[0])
|
obj=self.browse(ids[0])
|
||||||
number=obj.number
|
number=obj.number
|
||||||
if number=="/":
|
if number=="/" or not number:
|
||||||
number=self._get_number(context)
|
number=self._get_number(context)
|
||||||
vals={
|
vals={
|
||||||
'number': number,
|
'number': number,
|
||||||
|
@ -152,6 +152,8 @@ class Visit(Model):
|
||||||
break
|
break
|
||||||
|
|
||||||
hd_case_id=hd_case_obj.create(vals)
|
hd_case_id=hd_case_obj.create(vals)
|
||||||
|
if context.get("called"): #XXX call outside
|
||||||
|
return hd_case_id
|
||||||
return {
|
return {
|
||||||
'next': {
|
'next': {
|
||||||
'name': 'clinic_hd_case',
|
'name': 'clinic_hd_case',
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
====
|
====
|
||||||
|
-todo:
|
||||||
|
- make script to import hd case
|
||||||
|
|
||||||
|
---
|
||||||
question:
|
question:
|
||||||
- can filter field in related
|
- can filter field in related
|
||||||
find dialyzer automatic after confirm visit
|
find dialyzer automatic after confirm visit
|
||||||
|
|
Loading…
Reference in New Issue