conv_bal
chayut.s 2014-10-27 10:35:25 +07:00
commit 6ff15dc241
49 changed files with 859 additions and 72 deletions

View File

@ -0,0 +1,7 @@
<action>
<field name="string">Cycle Items</field>
<field name="view_cls">multi_view</field>
<field name="model">clinic.cycle.item</field>
<field name="modes">list,form</field>
<field name="menu">clinic_menu</field>
</action>

View File

@ -0,0 +1,7 @@
<action>
<field name="string">NHSO</field>
<field name="view_cls">multi_view</field>
<field name="tabs">[["All",[]],["Success",[["type","=","success"]]],["Fail",[["type","=","fail"]]]]</field>
<field name="model">clinic.data.nhso</field>
<field name="menu">account_menu</field>
</action>

View File

@ -0,0 +1,7 @@
<action>
<field name="string">Social Security</field>
<field name="view_cls">multi_view</field>
<field name="tabs">[["All",[]],["Success",[["type","=","success"]]],["Fail",[["type","=","fail"]]]]</field>
<field name="model">clinic.data.sc</field>
<field name="menu">account_menu</field>
</action>

View File

@ -0,0 +1,7 @@
<action>
<field name="string">Personal Categories</field>
<field name="view_cls">multi_view</field>
<field name="model">clinic.personal.categ</field>
<field name="modes">list,page,form</field>
<field name="menu">clinic_menu</field>
</action>

View File

@ -1,5 +1,14 @@
<form model="clinic.cycle">
<head>
<button string="Options" dropdown="1">
</button>
</head>
<field name="name"/>
<field name="duration"/>
<field name="sequence"/>
<related>
<field name="cycle_items"/>
<field name="visits"/>
<field name="hd_cases"/>
</related>
</form>

View File

@ -0,0 +1,60 @@
<form model="clinic.cycle.item" attrs='{"readonly":[["state","in",["done"]]]}' show_company="1">
<head>
<field name="state"/>
<button string="Options" dropdown="1">
<item string="Create Journal" method="create_journal" states="draft"/>
<item string="View Journal" method="view_journal" states="done"/>
<item string="To Draft" method="to_draft" states="done"/>
</button>
</head>
<field name="cycle_id" required="1"/>
<field name="date"/>
<tabs>
<tab string="Nurse Service">
<field name="var_k"/>
<field name="var_x"/>
<field name="total_pt"/>
<field name="nurse_lines" nolabel="1">
<list>
<field name="personal_categ" domain="[['type','=','nurse']]"/>
<field name="description"/>
<field name="formular"/>
<field name="qty" onchange="onchange_line"/>
<field name="rate" onchange="onchange_line"/>
<field name="amount"/>
</list>
</field>
<group span="8" columns="1">
</group>
<group span="4" columns="1">
<field name="total"/>
<field name="total_amount"/>
<field name="total_balance"/>
</group>
</tab>
<tab string="Doctor Service">
<field name="var_doctor"/>
<field name="doctor_lines" nolabel="1">
<list>
<field name="personal_categ" domain="[['type','=','doctor']]"/>
<field name="description"/>
<field name="formular"/>
<field name="qty" onchange="onchange_line"/>
<field name="rate" onchange="onchange_line"/>
<field name="amount"/>
</list>
</field>
<group span="8" columns="1">
</group>
<group span="4" columns="1">
<field name="total2"/>
</group>
</tab>
</tabs>
<foot>
<button string="Compute" type="default" icon="refresh" method="compute" states="draft"/>
</foot>
<related>
<field name="hd_cases"/>
</related>
</form>

View File

@ -0,0 +1,8 @@
<list model="clinic.cycle.item" colors='{"#9f9":[["state","=","done"]]}'>
<field name="name"/>
<field name="cycle_id"/>
<field name="date"/>
<field name="var_k"/>
<field name="var_x"/>
<field name="state"/>
</list>

View File

@ -0,0 +1,18 @@
<form model="clinic.data.nhso">
<field name="name"/>
<field name="epostat"/>
<field name="hdrate"/>
<field name="hdflag"/>
<field name="amount"/>
<field name="paid"/>
<field name="paychk"/>
<field name="dttran"/>
<field name="hreg"/>
<field name="station"/>
<field name="hn"/>
<field name="invno"/>
<field name="rid"/>
<field name="cstat"/>
<field name="reimbpay"/>
<field name="type"/>
</form>

View File

@ -0,0 +1,19 @@
<!--<list model="clinic.data.nhso" colors='{"#9f9":[["type","=","success"]],"red":[["type","=","fail"]]}'>-->
<list model="clinic.data.nhso">
<field name="name"/>
<field name="epostat"/>
<field name="hdrate"/>
<field name="hdflag"/>
<field name="amount"/>
<field name="paid"/>
<field name="paychk"/>
<field name="dttran"/>
<field name="hreg"/>
<field name="station"/>
<field name="hn"/>
<field name="invno"/>
<field name="rid"/>
<field name="cstat"/>
<field name="reimbpay"/>
<field name="type"/>
</list>

View File

@ -0,0 +1,14 @@
<form model="clinic.data.sc">
<field name="hn"/>
<field name="name14"/>
<field name="hcode18"/>
<field name="dttran"/>
<field name="amount23"/>
<field name="cur"/>
<field name="epoadm29"/>
<field name="eponame"/>
<field name="ln"/>
<field name="st"/>
<field name="allow37"/>
<field name="type"/>
</form>

View File

@ -0,0 +1,14 @@
<list model="clinic.data.sc" colors='{"red":[["type","=","fail"]]}'>
<field name="hn"/>
<field name="name14"/>
<field name="hcode18"/>
<field name="dttran"/>
<field name="amount23"/>
<field name="cur"/>
<field name="epoadm29"/>
<field name="eponame"/>
<field name="ln"/>
<field name="st"/>
<field name="allow37"/>
<field name="type"/>
</list>

View File

@ -28,5 +28,6 @@
</foot>
<related>
<field name="pickings" click_action="view_picking"/>
<field name="hd_cases" readonly="1"/>
</related>
</form>

View File

@ -15,6 +15,7 @@
<field name="expiry_card"/>
<field name="birthday"/>
<field name="department_id"/>
<field name="categ_id"/>
</group>
<group span="6" columns="1">
<field name="picture"/>

View File

@ -1,10 +1,13 @@
<form model="clinic.gen.visit">
<field name="date_from" onchange="onchange_time" span="6"/>
<field name="date_to" onchange="onchange_dateto" span="6"/>
<field name="cycle_id" onchange="onchange_time" span="6"/>
<field name="doctor_id" span="6"/>
<field name="nurse_id" span="6"/>
<field name="duration" span="6"/>
<group form_layout="stacked">
<field name="date_from" onchange="onchange_time" span="6"/>
<field name="date_to" onchange="onchange_dateto" span="6"/>
<field name="cycle_id" onchange="onchange_time" span="6"/>
<field name="duration" span="6"/>
<field name="nurse_id" span="6"/>
<field name="doctor_id" span="6"/>
<field name="department_id" span="6"/>
</group>
<separator string="Select Days"/>
<field name="monday" span="4"/>
<field name="tuesday" span="4"/>

View File

@ -2,7 +2,8 @@
<head>
<field name="state"/>
<button string="Options" dropdown="1">
<item string="Get Dialyzer" action="clinic_get_dlz"/>
<item string="New Dialyzer" method="new_dialyzer" states="draft"/>
<item string="To Draft" method="to_draft" states="in_progress"/>
</button>
</head>
<group span="6" columns="1">

View File

@ -3,6 +3,9 @@
<item string="Personals">
<item string="Doctors" action="clinic_doctor"/>
<item string="Nurses" action="clinic_nurse"/>
<divider/>
<header string="CATEGORIES"/>
<item string="Personal Categories" action="clinic_personal_categ"/>
</item>
<item string="Patients">
<item string="Patients" action="clinic_patient"/>
@ -16,6 +19,10 @@
<item string="Comorbidities" action="clinic_comorbidity"/>
<item string="Morbidities" action="clinic_morbidity"/>
</item>
<item string="Cycles">
<item string="Cycles" action="clinic_cycle"/>
<item string="Cycle Items" action="clinic_cycle_item"/>
</item>
<item string="Visits" action="clinic_visit"/>
<item string="Treatments" action="clinic_hd_case"/>
<item string="Reports">
@ -26,11 +33,13 @@
<item string="Medical Summary" action="clinic_report_hd_medical"/>
<header string="HD Payment"/>
<item string="Payment Summary" action="clinic_report_hd_payment"/>"
<header string="HD Madical"/>
<item string="Madical Summary" action="clinic_report_hd_madical"/>
<header string="REPORT SETTINGS"/>
<item string="Topics" action="clinic_translate"/>
</item>
<item string="Settings">
<item string="Cycles" action="clinic_cycle"/>
<item string="Departments" action="clinic_department"/>
<item string="Translate" action="clinic_translate"/>
<item string="Clinic Settings" action="clinic_setting"/>
</item>
</menu>

View File

@ -2,14 +2,14 @@
<item string="Settings" position="before">
<item string="Ratchawat">
<header string="IMPORT PAYMENT"/>
<item string="Medical Government" action="import_clinic_mg"/>
<!--<item string="Medical Government" action="import_clinic_mg"/>-->
<item string="Social Security" action="import_clinic_sc"/>
<item string="NHSO 30฿" action="import_clinic_nhso"/>
<divider/>
<header string="IMPORT DATA"/>
<item string="Medical Government" action="clinic_import_payment"/>
<item string="Social Security" action="clinic_import_payment"/>
<item string="NHSO 30฿" action="clinic_import_payment"/>
<!--<item string="Medical Government" action="clinic_import_payment"/>-->
<item string="Social Security" action="clinic_data_sc"/>
<item string="NHSO 30฿" action="clinic_data_nhso"/>
</item>
</item>
</inherit>

View File

@ -15,6 +15,7 @@
<field name="expiry_card"/>
<field name="birthday"/>
<field name="department_id"/>
<field name="categ_id"/>
</group>
<group span="6" columns="1">
<field name="picture"/>

View File

@ -0,0 +1,7 @@
<form model="clinic.personal.categ">
<field name="code"/>
<field name="name"/>
<field name="type"/>
<field name="formular"/>
<field name="sequence"/>
</form>

View File

@ -0,0 +1,7 @@
<list model="clinic.personal.categ">
<field name="code"/>
<field name="name"/>
<field name="type"/>
<field name="formular"/>
<field name="sequence"/>
</list>

View File

@ -0,0 +1,3 @@
<form model="clinic.report.hd.medical">
<field name="date" mode="month" span="2"/>
</form>

View File

@ -0,0 +1,12 @@
<form model="clinic.report.hd.payment">
<group>
<field name="patient_id" span="3"/>
<field name="type" span="3"/>
<field name="doctor_id" span="3"/>
<field name="nurse_id" span="3"/>
<newline/>
<field name="date_from" span="3"/>
<field name="date_to" span="3"/>
<field name="cycle_id" span="3"/>
</group>
</form>

View File

@ -1,2 +1,4 @@
<form model="clinic.setting" title="Clinic Settings">
<separator string="Labor Cost"/>
<field name="var_k"/>
</form>

View File

@ -7,5 +7,7 @@
<field name="ap_sc_id"/>
<field name="ar_nhso_id"/>
<field name="ap_nhso_id"/>
<field name="ap_nurse_id"/>
<field name="ap_doctor_id"/>
</field>
</inherit>

View File

@ -1,6 +1,12 @@
<form title="Import Medical Government">
<field name="file"/>
<group span="6" columns="1">
<field name="file"/>
</group>
<group span="6" columns="1">
<separator string="Result"/>
<field name="result" nolabel="1" height="240" width="540"/>
</group>
<foot replace="1">
<button string="Import Data" method="import_mg" type="primary" icon="arrow-right"/>
<button string="Import Data" method="import_nhso" type="primary" icon="arrow-right"/>
</foot>
</form>

View File

@ -1,10 +1,11 @@
<form title="Import NHSO">
<field name="file"/>
<field name="date">
<template>
<a href="ui#name=clinic_hd_case">xx{{context.data}}</a>
</template>
</field>
<group span="6" columns="1">
<field name="file"/>
</group>
<group span="6" columns="1">
<!--<separator string="Result"/>-->
<!--<field name="result" nolabel="1" height="240" width="540"/>-->
</group>
<foot replace="1">
<button string="Import Data" method="import_nhso" type="primary" icon="arrow-right"/>
<!--<button string="Post" method="post" type="success"/>-->

View File

@ -1,5 +1,14 @@
<form title="Import Social Security">
<field name="file"/>
<group span="6" columns="1">
<field name="file"/>
</group>
<group span="6" columns="1">
<separator string="Result"/>
<template>
<a href="ui#name=clinic_data_sc" target="_blank"><span class="glyphicon glyphicon-arrow-right"></span> Review Data</a>
</template>
<field name="result" nolabel="1" height="240" width="540"/>
</group>
<foot replace="1">
<button string="Import Data" method="import_sc" type="primary" icon="arrow-right"/>
</foot>

View File

@ -7,6 +7,7 @@ from . import graduation
from . import morbidity
from . import nation
from . import nurse
from . import address
from . import patient
from . import patient_cause_line
from . import patient_comorbidity_line
@ -26,6 +27,8 @@ from . import dialyzer_line
from . import import_payment
from . import file_sheet
from . import cycle
from . import cycle_item
from . import cycle_item_line
from . import gen_visit
from . import gen_visit_line
from . import report_hd_detail
@ -40,3 +43,4 @@ from . import translate
from . import payment
from . import account_payment
from . import report_hd_payment
from . import personal_categ

View File

@ -0,0 +1,10 @@
from netforce.model import Model, fields
class Address(Model):
_inherit="address"
_fields={
"patient_id": fields.Many2One("clinic.patient","Patient"),
}
Address.register()

View File

@ -1,4 +1,5 @@
from netforce.model import Model, fields
from netforce.access import get_active_company
class Cycle(Model):
_name="clinic.cycle"
@ -8,11 +9,17 @@ class Cycle(Model):
"name": fields.Char("Name",required=True,search=True),
'duration': fields.Integer("Duration (hrs)"),
'sequence': fields.Integer("Sequence"),
'company_id': fields.Many2One("company", "Company"),
'hd_cases': fields.One2Many("clinic.hd.case","cycle_id", "HD Cases"),
'visits': fields.One2Many("clinic.visit","cycle_id", "Visits"),
'cycle_items': fields.One2Many("clinic.cycle.item","cycle_id", "Cycle Items"),
'var_k': fields.Float("K"),
}
_defaults={
'duration': 1,
'sequence': 1,
'company_id': lambda *a: get_active_company(),
}

View File

@ -0,0 +1,237 @@
import time
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company
from netforce.utils import get_data_path
class CycleItem(Model):
_name="clinic.cycle.item"
_string="Cycle Item"
_name_field="name"
def _get_all(self,ids,context):
res={}
for obj in self.browse(ids):
name="%s-%s"%(obj.cycle_id.name,obj.date)
hd_total=len([hd_case for hd_case in obj.hd_cases if hd_case.state=='completed']) # XXX
pt=(hd_total or 0.0)
k=(obj.var_k or 0.0)
pt_k=pt*k
x=(pt_k + 1275)/13.5
total=0.0
for line in obj.nurse_lines:
total+=line.amount
total2=0.0
for line in obj.doctor_lines:
total2+=line.amount
res[obj.id]={
'name': name,
'var_x': x,
'total_pt': hd_total,
'total_amount': hd_total*k,
'total': total,
'total2': total2,
'total_balance': (hd_total*k)-total,
}
return res
_fields={
'name': fields.Char("Name", function="_get_all",function_multi=True), # need to field related in journal
'company_id': fields.Many2One("company", "Company"),
'cycle_id': fields.Many2One("clinic.cycle", "Cycle",search=True),
'date': fields.Date("Date",search=True),
'var_k': fields.Float("K"),
'var_x': fields.Float("X", function="_get_all",function_multi=True),
'total_pt': fields.Float("PT", function="_get_all",function_multi=True),
'total_amount': fields.Float("PT*K", function="_get_all",function_multi=True),
'total_balance': fields.Float("Total Balance", function="_get_all",function_multi=True),
'total': fields.Float("Total", function="_get_all",function_multi=True),
'total2': fields.Float("Total", function="_get_all",function_multi=True),
"state": fields.Selection([("draft","Draft"),("done","Done")],"Status",required=True),
'hd_cases': fields.One2Many("clinic.hd.case","cycle_item_id", "HD Cases"),
'nurse_lines': fields.One2Many('clinic.cycle.item.line', 'cycle_item_id', 'Nurse Lines',domain=[['type','=','nurse']]),
'doctor_lines': fields.One2Many('clinic.cycle.item.line', 'cycle_item_id', 'Doctor Lines',domain=[['type','=','doctor']]),
'var_doctor': fields.Float("K Doctor"),
}
_defaults={
'state': 'draft',
'company_id': lambda *a: get_active_company(),
'date': lambda *a: time.strftime("%Y-%m-%d"),
'var_k': 450,
'var_doctor': 450,
}
def compute(self,ids,context={}):
for obj in self.browse(ids):
vals={
'nurse_lines': [],
'doctor_lines': [],
}
nurse_dict={}
doctor_dict={}
for hd_case in obj.hd_cases:
if hd_case.state=='completed':
nurse_code=hd_case.nurse_id.categ_id.code or ""
if not nurse_dict.get(nurse_code):
nurse_dict[nurse_code]=0
nurse_dict[nurse_code]+=1
doctor_categ=hd_case.doctor_id.categ_id or ""
if not doctor_categ:
continue
doctor_name=hd_case.doctor_id.name or ""
key=(doctor_categ,doctor_name)
if not doctor_dict.get(key):
doctor_dict[key]=0
doctor_dict[key]+=1
for line in obj.nurse_lines:
line.delete()
for line in obj.doctor_lines:
line.delete()
for k, v in doctor_dict.items():
categ=k[0]
name=k[1]
qty=v
vals['doctor_lines'].append(('create',{
'personal_categ': categ.id,
'description': name,
'type': 'doctor',
'formular': categ.formular,
'qty': qty,
'rate': obj.var_doctor or 0.0,
}))
print(nurse_dict)
for personal_categ in get_model("clinic.personal.categ").search_browse([]):
if personal_categ.type=='nurse':
formular=personal_categ.formular or ""
rate=0
try:
var_x="%s"%(round(obj.var_x,2))
formulared=formular.replace("x",var_x)
rate=eval(formulared)
except:
rate=0
vals['nurse_lines'].append(('create',{
'personal_categ': personal_categ.id,
'type': 'nurse',
'formular': formular,
'qty': nurse_dict.get(personal_categ.code,0),
'rate': rate,
}))
obj.write(vals)
return {
'next': {
'name': 'clinic_cycle_item',
'mode': 'form',
'active_id': obj.id,
},
'flash': 'Compute OK',
}
def onchange_line(self,context={}):
data=context['data']
path=context["path"]
line=get_data_path(data,path,parent=True)
#qty=line.get("qty")
#rate=line.get("rate")
total=0.0
for line in data['nurse_lines']:
line['amount']=(line['qty'] or 0) * (line['rate'] or 0.0)
total+=line['amount']
print(line)
data['total']=total
data['total_amount']=data['total_pt']*(data['var_k'] or 0)
data['total_balance']=data['total_amount']-data['total']
return data
def create_journal(self,ids,context={}):
obj=self.browse(ids)[0]
settings=get_model("settings").browse(1)
account_id=settings.ap_nurse_id.id
if not account_id:
raise Exception("No Account payment for nurse")
vals={
"company_id": obj.company_id.id,
"type": "in",
"pay_type": "direct",
#"date": time.strftime("%Y-%m-%d"),
"date": obj.date or time.strftime("%Y-%m-%d"),
"account_id": account_id,
'related_id': "clinic.cycle.item,%s"%obj.id,
'direct_lines': [],
}
for line in obj.nurse_lines:
if not line.amount:
continue
vals['direct_lines'].append(('create',{
'description': 'Payment; %s'%line.personal_categ.name,
'account_id': account_id,
'qty': 1,
'unit_price': line.amount,
'amount': line.amount,
}))
for line in obj.doctor_lines:
if not line.amount:
continue
vals['direct_lines'].append(('create',{
'description': 'Payment; %s'%line.description,
'account_id': account_id,
'qty': line.qty,
'unit_price': line.amount,
'amount': line.amount,
}))
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
get_model("account.payment").browse(payment_id).post()
obj.write({
'state': 'done',
})
return {
'next': {
'name': 'payment',
'mode': 'form',
'active_id': payment_id,
},
'flash': 'Create journal successfully',
}
def to_draft(self,ids,context={}):
obj=self.browse(ids)[0]
related_id="clinic.cycle.item,%s"%obj.id
for payment in get_model("account.payment").search_browse([['related_id','=',related_id]]):
payment.to_draft()
payment.delete()
obj.write({
'state': 'draft',
})
return {
'next': {
'name': 'clinic_cycle_item',
'mode': 'form',
'active_id': obj.id,
},
'flash': 'Cycle item is set to draft',
}
def view_journal(self,ids,context={}):
obj=self.browse(ids)[0]
related_id="clinic.cycle.item,%s"%obj.id
payment_ids=get_model("account.payment").search([['related_id','=',related_id]])
if payment_ids:
payment_id=payment_ids[0]
return {
'next': {
'name': 'payment',
'mode': 'form',
'active_id': payment_id,
},
}
CycleItem.register()

View File

@ -0,0 +1,33 @@
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company
class CycleItemLine(Model):
_name="clinic.cycle.item.line"
_string="Cycle Item Line"
def all_amount(self,ids,context={}):
res={}
for obj in self.browse(ids):
res[obj.id]={
'amount': (obj.qty or 0) * (obj.rate or 0.0),
}
return res
_fields={
'cycle_item_id': fields.Many2One("clinic.cycle.item", "Cycle Item"),
"type": fields.Selection([("doctor","Doctor"),("nurse","Nurse")],"Personal Type",required=True),
'personal_categ': fields.Many2One("clinic.personal.categ", "Nurse Category",),
'formular': fields.Char("Formular", size=100),
'description': fields.Char("Description"),
'qty': fields.Integer("Qty"),
'rate': fields.Float("Rate"),
'amount': fields.Float("Amount",function="all_amount", function_multi=True),
'company_id': fields.Many2One('company','Company'),
}
_defaults={
"company_id": lambda *a: get_active_company(),
}
CycleItemLine.register()

View File

@ -1,9 +1,9 @@
from netforce.model import Model, fields
from netforce.access import get_active_company
class Department(Model):
_name="clinic.department"
_string="Department"
#_name_field="name"
_fields={
"name": fields.Char("Name",required=True,search=True),
@ -11,4 +11,8 @@ class Department(Model):
"parent_id": fields.Many2One("clinic.department", "Parent"),
}
_defaults={
'company_id': lambda *a: get_active_company(),
}
Department.register()

View File

@ -9,6 +9,7 @@ class Dialyzer(Model):
_audit_log=True
_name_field="number"
_multi_company=True
_fields={
"number": fields.Char("Number",required=True,search=True),
"description": fields.Text("Description",search=True),
@ -28,6 +29,7 @@ class Dialyzer(Model):
"patient_id": fields.Many2One("clinic.patient","Patient"),
"visit_id": fields.Many2One("clinic.visit","Visit"),
"hd_case_id": fields.Many2One("clinic.hd.case","HD Case"),
"hd_cases": fields.One2Many("clinic.hd.case","dlz_id","HD Case"), #TODO funtion to get hd case
}
def _get_number(self,context={}):
@ -50,26 +52,27 @@ class Dialyzer(Model):
def _get_product(self,context={}):
categ_ids=get_model("product.categ").search([['name','=','Dialyzer']])
product_id=None
stop=False
found=False
for prod in get_model("product").search_browse([]):
if stop:
if found:
break
for categ in prod.categs:
if categ.id in categ_ids:
product_id=prod.id
stop=True
found=True
break
return product_id
_defaults={
"state": "new",
"date": lambda *a: time.strftime("%Y-%m-%d"),
#"number": _get_number,
'number': '/',
"max_use_time": 10,
"use_time": 0,
"company_id": lambda *a: get_active_company(),
'product_id': _get_product,
'dialyzer_type': 'low',
'member_type': 'unsub',
}
_order="date desc,number desc"

View File

@ -44,6 +44,7 @@ class Doctor(Model):
"user_id": fields.Many2One("base.user","User"),
'picture': fields.File("Picture"),
'note': fields.Text("Note"),
'categ_id': fields.Many2One("clinic.personal.categ", "Doctor Category", domain=[['type','=','doctor']]),
}

View File

@ -9,6 +9,8 @@ class Settings(Model):
"ar_mg_id": fields.Many2One("account.account","Account Recieve Medical Government"),
"ar_nhso_id": fields.Many2One("account.account","Account Recieve NHSO 30B"),
"ar_sc_id": fields.Many2One("account.account","Account Recieve Social Security"),
"ap_nurse_id": fields.Many2One("account.account","Account Payment Nurse"),
"ap_doctor_id": fields.Many2One("account.account","Account Doctor Nurse"),
}
Settings.register()

View File

@ -29,6 +29,7 @@ class GenVisit(Model):
'friday': fields.Boolean("Fridays"),
'doctor_id': fields.Many2One("clinic.doctor","Doctor"),
'nurse_id': fields.Many2One("clinic.nurse","Nurse"),
'department_id': fields.Many2One("clinic.department","Department"),
'duration': fields.Integer("Duration (hrs)", function="_get_duration"),
}
@ -119,6 +120,7 @@ class GenVisit(Model):
'patient_id': line.patient_id.id,
'doctor_id': obj.doctor_id.id,
'nurse_id': obj.nurse_id.id,
'department_id': obj.department_id.id,
'cycle_id': obj.cycle_id.id,
'time_start': "%s %s" % (tmp.strftime(FMT_DATE),date_from.strftime(FMT_DATETIME)[11:]),
'time_stop': "%s %s" % (tmp.strftime(FMT_DATE),date_to.strftime(FMT_DATETIME)[11:]),
@ -131,6 +133,7 @@ class GenVisit(Model):
dom.append(['time_start','>=','%s %s'%(tmp.strftime(FMT_DATE)[0:10],' 00:00:00')])
dom.append(['time_stop','<=','%s %s'%(tmp.strftime(FMT_DATE)[0:10],' 23:59:59')])
dom.append(['patient_id', '=', line.patient_id.id])
dom.append(['cycle_id', '=', obj.cycle_id.id]) #XXX
dom.append(['state','=','draft'])
vids=visit_obj.search(dom)
visit_obj.delete(vids)

View File

@ -28,7 +28,6 @@ class HDCase(Model):
res[obj.id]=obj.amount
return res
_fields={
"number": fields.Char("Number",required=True,search=True),
"time_start": fields.DateTime("Time start",required=True,search=True),
@ -53,8 +52,7 @@ class HDCase(Model):
"state": fields.Selection([("draft","Draft"),("in_progress","In Progress"),("completed","Completed"),("waiting_payment","Waiting Payment"),("discountinued","Discountinued"),("in_completed","In completed")],"Status",required=True),
"dialyzers": fields.One2Many("clinic.dialyzer.line","hd_case_id","Dialyzers"),
"lines": fields.One2Many("clinic.hd.case.line","hd_case_id","Lines"),
"comments": fields.One2Many("message","related_id","Comments"),
"company_id": fields.Many2One("company","Company"),
"comments": fields.One2Many("message","related_id","Comments"), "company_id": fields.Many2One("company","Company"),
"amount": fields.Float("Due Amount",function="get_total",readonly=True,function_multi=True),
"total": fields.Float("Total",function="get_total",readonly=True,function_multi=True),
"reconcile_id": fields.Many2One("account.reconcile","Reconcile Id",readonly=True),
@ -69,10 +67,12 @@ class HDCase(Model):
'fee_paid': fields.Boolean("Fee Paid"),
'note': fields.Text("Note"),
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
"cycle_item_id": fields.Many2One("clinic.cycle.item","Cycle Item"), # compute labor cost
'pay_amount': fields.Float("Amount",function="get_pay_amount"),
'pay_date': fields.Date("Pay Date"),
'pay_account_id': fields.Many2One("account.account","Account"),
'payment_id': fields.Many2One("account.payment","Payment"), # for print
'dlz_id': fields.Many2One("clinic.dialyzer","Dialyzer"), # for link
}
def _get_number(self,context={}):
@ -127,7 +127,7 @@ class HDCase(Model):
})
raise Exception("%s is expired"%dialyzer.number)
use_time+=1
line["description"]=dialyzer.description or ""
line["description"]=dialyzer.description or dialyzer.product_id.name or ""
line["use_time"]=use_time
line["max_use_time"]=dialyzer.max_use_time
line["member_type"]=dialyzer.member_type
@ -135,6 +135,7 @@ class HDCase(Model):
line["bid_flow_rate"]=dialyzer.bid_flow_rate
line["ultrafittration"]=dialyzer.ultrafittration
line["state"]=dialyzer.state
data['dlz_id']=dialyzer.id
return data
def onchange_patient(self,context={}):
@ -182,7 +183,7 @@ class HDCase(Model):
else:
total+=amt
data['total']=total
data['total']=total+fee_amt
data['fee_amount']=fee_amt
for line in data['payment_lines']:
total-=line['amount'] or 0.0
@ -461,11 +462,30 @@ class HDCase(Model):
})
return True
def create_cycle_item(self,ids,context={}):
for obj in self.browse(ids):
cycle_item=get_model("clinic.cycle.item")
datenow=time.strftime('%Y-%m-%d')
cycle_id=obj.cycle_id.id
cycle_item_ids=cycle_item.search([['date','=',datenow],['cycle_id','=',cycle_id]])
cycle_item_id=None
if cycle_item_ids:
cycle_item_id=cycle_item_ids[0]
else:
cycle_item_id=cycle_item.create({
'cycle_id': obj.cycle_id.id,
})
obj.write({
'cycle_item_id': cycle_item_id,
})
return True
def complete(self,ids,context={}):
obj=self.browse(ids)[0]
obj.make_invoices()
obj.post_invoices()
obj.update_usetime()
obj.create_cycle_item()
obj.write({
"state":"completed",
})
@ -551,10 +571,12 @@ class HDCase(Model):
for pm_line in obj.payment_lines:
pm_line.delete()
state=context.get("state","in_progress") #force state
obj.write({
'state': 'in_progress',
'state': state,
'fee_paid': False,
})
return {
'next': {
'name': 'clinic_hd_case',
@ -619,5 +641,46 @@ class HDCase(Model):
data['amount_total']=payment.amount_total or 0.0
return data
def new_dialyzer(self,ids,context={}):
obj=self.browse(ids)[0]
dlz_vals=get_model("clinic.dialyzer").default_get()
dlz_vals['patient_id']=obj.patient_id.id
dlz_vals['company_id']=dlz_vals['company_id'][0]
product_name=dlz_vals['product_id'][1]
dlz_vals['product_id']=dlz_vals['product_id'][0]
dlz_id=get_model('clinic.dialyzer').create(dlz_vals)
dialyzer=get_model("clinic.dialyzer").browse(dlz_id)
dialyzer.confirm()
vals={
'dlz_id': dlz_id,
'dialyzers': [],
}
vals['dialyzers'].append(('create',{
'dialyzer_id': dlz_id,
'description': dialyzer.description or product_name,
'use_time': 1,
'max_use_time': dialyzer.max_use_time,
'member_type': dialyzer.member_type,
'dialyzer_type': dialyzer.dialyzer_type,
'bid_flow_rate': dialyzer.bid_flow_rate,
'ultrafittration': dialyzer.ultrafittration,
'state': dialyzer.state,
}))
obj.write(vals)
return {
'next': {
'name': 'clinic_hd_case',
'mode': 'form',
'active_id': obj.id,
},
'flash': 'Create new dialyzer successfully',
}
def to_draft(self,ids,context={}):
obj=self.browse(ids)[0]
context['state']='draft'
obj.undo(context=context)
HDCase.register()

View File

@ -10,7 +10,7 @@ class Hdcaseline(Model):
"uom_id": fields.Many2One("uom","UOM",required=True,search=True),
"price":fields.Float("Price"),
"amount":fields.Float("Amount"),
"type": fields.Selection([("fee","Fee"),("other","Other")],"Type",required=True),
"type": fields.Selection([("fee","Fee"),("other","Other"),("service","Service")],"Type",required=True),
}
_defaults={

View File

@ -51,6 +51,7 @@ class HDCasePayment(Model):
if obj.pay_amount:
hd_case.make_payment(context=context)
if obj.complete:
hd_case.create_cycle_item()
hd_case.write({
'state': 'completed',
})
@ -71,6 +72,7 @@ class HDCasePayment(Model):
hd_case=get_model("clinic.hd.case").browse(obj.hd_case_id.id)
hd_case.make_invoices()
hd_case.post_invoices()
hd_case.create_cycle_item()
#if obj.complete:
hd_case.write({
'state': 'completed',

View File

@ -5,7 +5,7 @@ class ImportDataNHSO(Model):
_transient=True
_fields={
'name': fields.Char("Name"),
'type': fields.Selection([['sucess','Succes'],['fail','Fail']],'Type'),
'type': fields.Selection([['success','Succes'],['fail','Fail']],'Type'),
'epostat': fields.Char("Epostat"),
'hdrate': fields.Char("Hdrate"),
'hdflag': fields.Char("Hdflag"),
@ -22,4 +22,5 @@ class ImportDataNHSO(Model):
'reimbpay': fields.Char("Reimbpay"),
}
ImportDataNHSO.register()

View File

@ -4,7 +4,18 @@ class ImportDataSC(Model):
_name="clinic.data.sc"
_transient=True
_fields={
'name': fields.Char("Name"),
'hn': fields.Char("hn", search=True),
'name14': fields.Char("name14", search=True),
'hcode18': fields.Char("hcode18", search=True),
'amount23': fields.Char("amount23", search=True),
"cur": fields.Char("cur"),
'epoadm29': fields.Char("epoadm29"),
'eponame': fields.Char("eponame"),
'ln': fields.Char('ln'),
'st': fields.Char('st'),
'allow37': fields.Char('allow37'),
'dttran': fields.Date("dttran"),
'type': fields.Selection([['success','Succes'],['fail','Fail']],'Type', search=True),
}

View File

@ -1,4 +1,5 @@
import time
import datetime
import xlrd
import xmltodict
@ -14,6 +15,7 @@ class ImportPayment(Model):
_fields={
'date': fields.DateTime("Date"),
'file': fields.File("File"),
'result': fields.Text("Success"),
}
_defaults={
@ -27,12 +29,24 @@ class ImportPayment(Model):
if suffix not in ('xls', 'xlsx'):
raise Exception("ERROR : please should file xls or xlsx")
wb=xlrd.open_workbook(fpath)
worksheet=wb.sheet_by_name("Sheet1")
num_rows=worksheet.nrows-1
curr_row=-1
while curr_row < num_rows:
curr_row +=1
worksheet.cell_value(curr_row,2)
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_xml(self,fpath=None,node=""):
@ -72,8 +86,85 @@ class ImportPayment(Model):
lines=self.read_xml(fpath,node='HDBills')
if not lines:
raise Exception("Wrong file")
data_nhso=get_model("clinic.data.nhso")
nhso_ids=data_nhso.search([])
data_nhso.delete(nhso_ids)
result=""
result+="Match: %s"%(50)
result+="\n"
result+="*"*50
for line in lines:
# TODO need to check match or not
data_nhso.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=self.read_excel(fpath)
if not lines:
raise Exception("Wrong File")
data_sc=get_model("clinic.data.sc")
sc_ids=data_sc.search([])
data_sc.delete(sc_ids)
st={}
patient=get_model("clinic.patient")
old_patient=[x['hn'] for x in patient.search_read([],['hn']) if x['hn']]
fail_qty=0
success_qty=0
for line in lines:
hn=line.get('hn')
if not hn:
continue
# create patient if not found
if not st.get(hn) and (not hn in old_patient):
patient.create({
'type': 'sc',
'hn': hn,
'name': line.get('name14'),
'reg_date': time.strftime("%Y-%m-%d"),
})
st.update({hn: line.get('name14')})
print("create %s ok"%hn)
hcode=int((line.get('hcode18') or "0")) # XXX
type=hcode==23869 and 'success' or 'fail'
if type=='success':
success_qty+=1
else:
fail_qty+=1
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,
}
data_sc.create(vals)
msg=''
msg+="%s\n"%("*"*50)
msg+='success: %s\n'%success_qty
msg+='fail: %s\n'%fail_qty
msg+="%s\n"%("*"*50)
obj.write({
'result': msg,
})
def import_mg(self,ids,context={}):
obj=self.browse(ids)[0]
@ -81,11 +172,6 @@ class ImportPayment(Model):
fpath=get_file_path(fname)
print("fpath ", fpath)
def import_sc(self,ids,context={}):
obj=self.browse(ids)[0]
fname=obj.file
fpath=get_file_path(fname)
print("fpath ", fpath)
ImportPayment.register()

View File

@ -44,6 +44,7 @@ class Nurse(Model):
"user_id": fields.Many2One("base.user","User"),
'picture': fields.File("Picture"),
'note': fields.Text("Note"),
'categ_id': fields.Many2One("clinic.personal.categ", "Nurse Category", domain=[['type','=','nurse']]),
}
def _get_number(self,context={}):

View File

@ -48,7 +48,7 @@ class Patient(Model):
'card_exp' : fields.Date("Card Expiry"),
"app_no": fields.Char("Application No."),
"salary": fields.Selection([["20000","5,001-20,000"],["50000","20,001-50,000"],["100000","50,001-100,000"],["100001","100,000+"]], "Salary"),
"addresses": fields.One2Many("address","related_id","Addresses"),
"addresses": fields.One2Many("address","patient_id","Addresses"),
"gender": fields.Selection([("male","Male"),("female","Female")],"Gender",required=False),
"marital_status": fields.Selection([("single","Single"),("marry","Marry"),("divorce","Divorce"),("separated","Saparated"),("widowed","Widowed")],"Marital Status",required=False),
"nation_id": fields.Many2One("clinic.nation","Nationality"),
@ -161,6 +161,19 @@ class Patient(Model):
'last_name': obj.name,
'type': 'person',
})
address_id=get_model('address').create({
'type': 'shipping',
'partner_id': partner_id,
'address': 'your address',
'address2': 'your address2',
'city': 'your city',
'postal_code': 'your zip',
'country_id': 1, #XXX
})
get_model('address').browse(address_id).write({
'related_id': "clinic.patient,%s"%obj.id,
})
obj.write({
'partner_id': partner_id,
})
@ -170,7 +183,9 @@ class Patient(Model):
partner_ids=[]
for obj in self.browse(ids):
partner_ids.append(obj.partner_id.id)
address_ids=[addr.id for addr in obj.partner_id.addresses]
get_model("partner").delete(partner_ids)
get_model("address").delete(address_ids)
super().delete(ids)
def write(self,ids,vals,**kw):
@ -188,7 +203,49 @@ class Patient(Model):
'type': 'person',
})
vals['partner_id']=partner_id
# XXX
if not isinstance(partner_id,int):
partner_id=partner_id.id
if obj.addresses:
addr=obj.addresses[0]
get_model("address").browse(addr.id).write({
'partner_id': partner_id,
})
else:
if vals.get("addresses"):
# in case no address in patient
addr_vals=vals.get("addresses")[0][1]
addr_id=get_model("address").create(addr_vals)
get_model("address").browse(addr_id).write({
'patient_id': obj.id,
'partner_id': partner_id,
})
del vals['addresses']
print("create address for %s"%obj.name)
super().write(ids,vals,**kw)
def name_get(self,ids,context={}):
vals=[]
for obj in self.browse(ids):
name="%s [%s] %s"%(obj.name,obj.number,obj.hn or "")
vals.append((obj.id,name))
return vals
def name_search(self,name,domain=None,context={},**kw):
dom=[["number","ilike","%"+name+"%"]]
if domain:
dom=[dom,domain]
ids1=self.search(dom)
dom=[["name","ilike","%"+name+"%"]]
if domain:
dom=[dom,domain]
ids2=self.search(dom)
dom=[["hn","ilike","%"+name+"%"]]
if domain:
dom=[dom,domain]
ids3=self.search(dom)
ids=list(set(ids1+ids2+ids3))
return self.name_get(ids,context=context)
Patient.register()

View File

@ -0,0 +1,43 @@
from netforce.model import Model, fields
from netforce.access import get_active_company
class NurseCateg(Model):
_name="clinic.personal.categ"
_string="Personal Category"
_fields={
"name": fields.Char("Name",required=True,search=True),
"code": fields.Char("Code",required=True,search=True),
'formular': fields.Text("Formular"),
'sequence': fields.Integer("Sequence"),
"type": fields.Selection([("doctor","Doctor"),("nurse","Nurse")],"Personal Type",required=True),
}
_defaults={
"company_id": lambda *a: get_active_company(),
'sequence': 0,
'type': 'doctor',
}
_order="sequence"
def name_get(self,ids,context={}):
vals=[]
for obj in self.browse(ids):
name="%s [%s]"%(obj.name,obj.code or "")
vals.append((obj.id,name))
return vals
def name_search(self,name,domain=None,context={},**kw):
dom=[["name","ilike","%"+name+"%"]]
if domain:
dom=[dom,domain]
ids1=self.search(dom)
dom=[["code","ilike","%"+name+"%"]]
if domain:
dom=[dom,domain]
ids2=self.search(dom)
ids=list(set(ids1+ids2))
return self.name_get(ids,context=context)
NurseCateg.register()

View File

@ -1,25 +1,10 @@
from netforce.model import Model, fields, get_model
from netforce.utils import get_data_path
import time
from netforce.access import get_active_user
from netforce.access import get_active_company
class ClinicSetting(Model):
_name="clinic.setting"
_string="Setting"
_fields={
"mg_partner_id": fields.Many2One("partner","Partner Medical Govement"),
"ar_mg_id": fields.Many2One("account.account","Account Receivable Medical Govement"),
"ap_mg_id": fields.Many2One("account.account","Account Payment Medical Govement"),
"nhso_partner_id": fields.Many2One("partner","Partner NHSO 30B"),
"ar_nhso_id": fields.Many2One("account.account","Account Receiveble NHSO 30B"),
"ap_nhso_id": fields.Many2One("account.account","Account Payment NHSO 30B"),
"sc_partner_id": fields.Many2One("partner","Partner Social Security"),
"ar_sc_id": fields.Many2One("account.account","Account Receiveble Social Security"),
"ap_sc_id": fields.Many2One("account.account","Account Payment Social Security"),
#"ori_str": fields.Char("ori_str","Original String"),
#"translate": fields.Char("translate","Translation"),
"var_k": fields.Float("K"),
}
ClinicSetting.register()

View File

@ -90,9 +90,6 @@ class Visit(Model):
}
_order="id desc"
def get_dialyzer(self):
return
def confirm(self,ids,context={}):
obj=self.browse(ids[0])
number=obj.number
@ -119,7 +116,9 @@ class Visit(Model):
'dialyzers': [],
'state': 'draft',
}
# search dialyzer and count automatically
# search Nurse with category
products=get_model("product").search_browse([['code','=','FEE']])
for product in products:
vals['lines'].append(('create',{

View File

@ -1,7 +1,7 @@
===
- skip holiday
-> mum
-
====
question:
- can filter field in related
find dialyzer automatic after confirm visit
====
- import data
- payment