merge and savepoint 20180607

master
SPP 2018-06-07 17:15:42 +07:00
commit 4941950d73
90 changed files with 2592 additions and 197 deletions

View File

@ -0,0 +1,11 @@
<action>
<field name="string">Patient Moves</field>
<field name="view_cls">multi_view</field>
<field name="model">clinic.patient.move</field>
<field name="tabs">[
["All",[[]]],
["In",[["type","=","in"]]],
["Out",[["type","=","out"]]]]
</field>
<field name="menu">clinic_menu</field>
</action>

View File

@ -0,0 +1,6 @@
<record model="action">
<field name="string">Report Wizard Labor Cost</field>
<field name="view_cls">multi_view</field>
<field name="model">clinic.print.wizard.labor.cost</field>
<field name="menu">clinic_menu</field>
</record>

View File

@ -1,5 +1,5 @@
<action>
<field name="string">Report Account HD Case Detail</field>
<field name="string">Account HD Case Detail</field>
<field name="view_cls">report</field>
<field name="model">clinic.report.account.hd.case.detail</field>
<field name="report_template">report_account_hd_case_detail</field>

View File

@ -1,8 +0,0 @@
<action>
<field name="string">Report Account HD Case Summary</field>
<field name="view_cls">report</field>
<field name="model">clinic.report.account.hd.case.summary</field>
<field name="report_template">report_account_hd_case_summary</field>
<field name="report_template_xls">report_account_hd_case_summary</field>
<field name="menu">account_menu</field>
</action>

View File

@ -1,5 +1,5 @@
<action>
<field name="string">HD Case Summary</field>
<field name="string">HD Case Summary (old)</field>
<field name="view_cls">report</field>
<field name="model">clinic.report.hd.case.summary</field>
<field name="report_template">report_hd_case_summary</field>

View File

@ -0,0 +1,8 @@
<action>
<field name="string">Report Wizard Labor Cost</field>
<field name="view_cls">report</field>
<field name="model">clinic.report.wizard.labor.cost</field>
<field name="report_template">report_wizard_labor_cost</field>
<field name="report_template_xls">report_wizard_labor_cost</field>
<field name="menu">account_menu</field>
</action>

View File

@ -3,5 +3,6 @@
<field name="view_cls">multi_view</field>
<field name="model">clinic.sickbed</field>
<field name="menu">clinic_menu</field>
<field name="limit">25</field>
<field name="tabs">[["All",[]],["Archived",[["active","=",false]]],["Available",[["state","=","available"]]],["Not Available",[["state","=","not_available"]]]]</field>
</action>

View File

@ -0,0 +1,5 @@
<action>
<field name="view">template_view</field>
<field name="template">rdc_page</field>
<field name="menu">account_menu</field>
</action>

View File

@ -0,0 +1,8 @@
<action>
<field name="string">HDCase Expense Summary</field>
<field name="view_cls">report</field>
<field name="model">report.hdcase.expense.summary</field>
<field name="report_template">report_hdcase_expense_summary</field>
<field name="report_template_xls">report_hdcase_expense_summary</field>
<field name="menu">account_menu</field>
</action>

View File

@ -0,0 +1,9 @@
<action>
<field name="string">HD Case Summary</field>
<field name="view_cls">report</field>
<field name="model">report.hdcase.summary</field>
<field name="report_template">report_hdcase_summary</field>
<field name="report_template_xls">report_hdcase_summary</field>
<field name="export_pdf">1</field>
<field name="menu">clinic_menu</field>
</action>

View File

@ -0,0 +1 @@
from . import json_rpc

View File

@ -0,0 +1,99 @@
from netforce.controller import Controller
from netforce.model import get_model, clear_cache
from netforce import database
from netforce import access
import json
import traceback
import sys
import time
import random
from netforce.locale import translate
from netforce.utils import timeout
from netforce.log import rpc_log
class JsonRpc(Controller):
_path = "/json_rpc"
def get(self):
self.render("base/json_rpc.xml")
def post(self):
req = json.loads(self.request.body.decode())
# open("/tmp/json_rpc.log","a").write(self.request.body.decode()+"\n###############################################################\n")
db = database.get_connection()
if db:
db.begin()
try:
clear_cache()
method = req["method"]
params = req["params"]
if method == "execute":
model = params[0]
method = params[1]
if method.startswith("_"):
raise Exception("Invalid method")
args = params[2]
if len(params) >= 4:
opts = params[3] or {}
else:
opts = {}
user_id = access.get_active_user()
rpc_log.info("EXECUTE db=%s model=%s method=%s user=%s" %
(database.get_active_db(), model, method, user_id))
m = get_model(model)
f = getattr(m, method)
ctx = {
"request_handler": self,
"request": self.request,
}
ctx.update(self.get_cookies())
opts.setdefault("context", {}).update(ctx)
with timeout(seconds=900): # XXX: can make this faster? (less signal sys handler overhead)
t0 = time.time()
res = f(*args, **opts)
t1 = time.time()
dt = (t1 - t0) * 1000
rpc_log.info("<<< %d ms" % dt)
resp = {
"result": res,
"error": None,
"id": req["id"],
}
else:
raise Exception("Invalid method: %s" % method)
db = database.get_connection()
if db:
db.commit()
except Exception as e:
try:
msg = translate(str(e))
except:
print("WARNING: Failed to translate error message")
msg = str(e)
rpc_log.error(msg)
db = database.get_connection()
if db:
db.rollback()
rpc_log.error(traceback.format_exc())
err = {
"message": msg,
}
error_fields = getattr(e, "error_fields", None)
if error_fields:
err["error_fields"] = error_fields
resp = {
"result": None,
"error": err,
"id": req["id"],
}
access.clear_active_user()
try:
data = json.dumps(resp)
except:
print("JSONRPC ERROR: invalid response")
from pprint import pprint
pprint(resp)
self.write(data)
JsonRpc.register()

View File

@ -1,34 +1,6 @@
<inherit inherit="account_menu">
<item string="Settings" position="before">
<item string="Ratchawat">
<item string="Account Product" action="clinic_setting_account_product"/>
<item string="Account Patient" action="clinic_setting_account_patient"/>
<item string="HD Case Expense" action="clinic_report_account_hd_case_summary"/>
<item string="HD Case Expense(2)" action="clinic_report_account_hd_case_detail"/>
<item string="RD Shop Expense" action="clinic_report_account_shop"/>
<item string="Payment Matching" action="clinic_matching_payment"/>
<item string="Payment Invoices" action="clinic_invoice_payment"/>
<divider/>
<item string="Recompute Cost" action="clinic_compute_labor_cost"/>
<item string="Print Labor Cost" action="clinic_print_labor_cost"/>
<item string="Labor Costs" action="clinic_report_labor_cost"/>
<item string="Labor Cost Summary" action="clinic_report_labor_cost_summary"/>
<item string="Labor Cost Detail" action="clinic_report_labor_cost_detail"/>
<item string="Labor Cost Sub Detail" action="clinic_report_labor_cost_sub_detail"/>
<item string="Labor Cost Daily" action="clinic_report_labor_cost_daily"/>
<item string="Labor Cost Overtime" action="clinic_report_labor_cost_overtime"/>
</item>
<item string="Matching">
<item string="Payment Matching" action="clinic_payment_matching"/>
<item string="HD Cases Matching" action="clinic_matching_hdcase_acc"/>
</item>
</item>
<item string="Financial Settings" position="after">
<item string="Ratchawat Settings" action="clinic_account_setting"/>
<item string="Labor Costs" action="clinic_labor_cost"/>
</item>
<item string="Conversion Balances" position="after">
<item string="Pay Period" action="clinic_period"/>
<item string="Ratchawat" action="rdc_board"/>
</item>
</inherit>

View File

@ -0,0 +1,38 @@
<inherit inherit="account_menu">
<item string="Settings" position="before">
<item string="Ratchawat">
<header string="Accounting"/>
<divider/>
<!--<item string="Account Product" action="clinic_setting_account_product"/>-->
<!--<item string="Account Patient" action="clinic_setting_account_patient"/>-->
<!--<item string="HD Case Expense" action="clinic_report_account_hd_case_summary"/>-->
<!--<item string="HD Case Expense(2)" action="clinic_report_account_hd_case_detail"/>-->
<item string="HDCase Expense Summary" action="report_hdcase_expense_summary"/>
<!--<item string="HDCase Expense Detail" action="clinic_report_account_hd_case_detail"/>-->
<item string="RD Shop Expense" action="clinic_report_account_shop"/>
<!--<item string="Payment Matching" action="clinic_matching_payment"/>-->
<!--<item string="Payment Invoices" action="clinic_invoice_payment"/>-->
<divider/>
<header string="Doctor/Nurse Cost"/>
<item string="Labor Costs" action="clinic_report_labor_cost"/>
<item string="Labor Cost Summary" action="clinic_report_labor_cost_summary"/>
<item string="Labor Cost Detail" action="clinic_report_labor_cost_detail"/>
<item string="Labor Cost Sub Detail" action="clinic_report_labor_cost_sub_detail"/>
<item string="Labor Cost Daily" action="clinic_report_labor_cost_daily"/>
<item string="Labor Cost Overtime" action="clinic_report_labor_cost_overtime"/>
<item string="Recompute Cost" action="clinic_compute_labor_cost"/>
<!--<item string="Print Labor Cost" action="clinic_print_labor_cost"/>-->
<item string="Print All" color="red" action="clinic_report_wizard_labor_cost"/>
<divider/>
<header string="Matching"/>
<item string="Payment Matching" action="clinic_payment_matching"/>
<item string="HD Cases Matching" action="clinic_matching_hdcase_acc"/>
<divider/>
<header string="Settings"/>
<item string="Ratchawat Settings" action="clinic_account_setting"/>
<item string="Labor Costs" action="clinic_labor_cost"/>
<item string="Pay Period" action="clinic_period"/>
</item>
</item>
</inherit>

View File

@ -55,6 +55,7 @@
<field name="cash_account_id"/>
<field name="income_account_id" string="Account Receivable"/>
<field name="import_account_id"/>
<field name="hdcase_payment_account_id"/>
</tab>
<tab string="Reporting">
<field name="helper_categ_id"/>

View File

@ -16,7 +16,7 @@
<field name="membrane_type" required="1"/>
</group>
<group span="6" columns="1">
<field name="product_id" onchange="onchange_product"/>
<field name="product_id" onchange="onchange_product" domain="[['categ_id.name','=','Dialyzer']]"/>
<field name="dialyzer_type"/>
<field name="use_time"/>
<field name="max_use_time"/>

View File

@ -1,4 +1,4 @@
<list model="clinic.dialyzer" colors='{"#cfc":[["state","=","active"]],"#dbdbdb":[["state","=","drop"]]}'>
<list model="clinic.dialyzer" colors='{"#CD5C5C":[["state","=","expire"]],"#cfc":[["state","=","active"]],"#dbdbdb":[["state","=","drop"]]}'>
<top replace="1"></top>
<field name="date"/>
<field name="number"/>

View File

@ -1,5 +1,6 @@
<form model="clinic.hd.case.popup.dlz">
<field name="hd_case_id" invisible="1"/>
<field name="new_product" span="6"/>
<field name="product_id" onchange="onchange_product" domain="[['categ_id.name','=','Dialyzer']]" span="6"/>
<field name="dialyzer_type" required="1" span="6"/>
<field name="max_use_time" span="6" required="1"/>
@ -7,6 +8,11 @@
<field name="exp_date" span="6"/>
<field name="note" span="6"/>
<field name="drop_old" span="6"/>
<template>
<p class="well text-warning">
<span class="glyphicon glyphicon-info-sign"></span> กรณีในช่อง product ไม่มีให้เลือก ให้ระบุที่ชอ่ง New Product แทน
</p>
</template>
<foot>
<button string="Validate" type="success" method="new_dlz"/>
</foot>

View File

@ -113,8 +113,13 @@
</group>
</tab>
<tab string="Other">
<field name="nurse_id" span="4"/>
<field name="check_dlz" span="4"/>
<group span="6" columns="1">
<field name="patient_name"/>
<field name="nurse_id"/>
<field name="check_dlz"/>
</group>
<group span="6" columns="1">
</group>
<!--<field name="fee_partner_id" span="4" domain="[['type','=','org']]"/>-->
</tab>
</tabs>
@ -130,6 +135,8 @@
<list colors='{"#9f9":[["state","=","paid"]]}'>
<head>
<button string="Print" action="clinic_hdcase_invoice_print" action_options="convert=pdf" icon="print"/>
<button string="Pay" method="pay_invoice" type="success"/>
<button string="To Draft" method="hdcase_to_draft" type="default"/>
</head>
<field name="number"/>
<field name="ref"/>

View File

@ -2,7 +2,8 @@
<field name="number"/>
<field name="date"/>
<field name="cycle_id"/>
<field name="patient_id"/>
<!--<field name="patient_id"/>-->
<field name="patient_name"/>
<field name="patient_type_id"/>
<field name="epo"/>
<field name="department_id"/>

View File

@ -2,7 +2,8 @@
<field name="number"/>
<field name="date"/>
<field name="cycle_id"/>
<field name="patient_id"/>
<!--<field name="patient_id"/>-->
<field name="patient_name"/>
<field name="patient_type_id"/>
<field name="department_id"/>
<field name="branch_id"/>

View File

@ -42,23 +42,26 @@
<item string="Sickbed" action="clinic_sickbed"/>
</item>
<item string="Reports" perm="clinic_report">
<item string="HD Case Summary" action="report_hdcase_summary"/>
<item string="Report Cycle Setting" action="clinic_report_cycle_setting"/>
<item string="Cycle Item Summary" action="clinic_report_cycle_item"/>
<item string="HD Case Summary" action="clinic_report_hd_case_summary"/>
<item string="HD Case Expense" action="clinic_report_claim"/>
<!--<item string="HD Case Summary (old)" action="clinic_report_hd_case_summary"/>-->
<item string="HD Case Expense" action="report_hdcase_expense_summary"/>
<item string="RD Shop Expense" action="clinic_report_shop"/>
<divider/>
<item string="Receipt Summary" action="clinic_report_receipt_summary"/>
</item>
<item string="Settings" perm="clinic_settings">
<item string="Clinic Settings" action="clinic_setting"/>
<divider/>
<item string="Cycles" action="clinic_cycle"/>
<item string="Hospitals" action="clinic_hospital"/>
<item string="Nationalities" action="clinic_nation"/>
<divider/>
<item string="Merge Staff" action="clinic_merge_staff"/>
<item string="Titles" action="clinic_name_title" perm="clinic_name_title"/>
<item string="Branches" action="clinic_branch" perm="clinic_branch"/>
<item string="Departments" action="clinic_department"/>
<item string="Department Products" action="clinic_department_product"/>
<item string="Hospitals" action="clinic_hospital"/>
<item string="Nationalities" action="clinic_nation"/>
</item>
</menu>

View File

@ -133,6 +133,7 @@
</tabs>
<related>
<field name="addresses"/>
<field name="moves"/>
<field name="visits" readonly="1"/>
<field name="hd_cases" readonly="1"/>
<field name="dialyzers" readonly="1"/>

View File

@ -0,0 +1,8 @@
<form model="clinic.patient.move">
<field name="date"/>
<field name="patient_id"/>
<field name="type_id"/>
<field name="type"/>
<field name="patient_name"/>
<field name="patient_type"/>
</form>

View File

@ -0,0 +1,7 @@
<list model="clinic.patient.move">
<field name="date"/>
<field name="patient_id"/>
<field name="type"/>
<field name="patient_name"/>
<field name="patient_type"/>
</list>

View File

@ -0,0 +1,27 @@
<form model="clinic.print.wizard.labor.cost" title="Print Wizard Labor Cost" show_company="1">
<head>
<field name="state"/>
</head>
<group form_layout="stacked">
<field name="period_id" domain='[["state","=","open"]]' onchange="onchange_period" span="2"/>
<field name="date_from" span="2"/>
<field name="date_to" span="2"/>
<field name="branch_id" onchange='onchange_branch' span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
<field name="staff_type" span="2"/>
<field name="file_pdf1" span="4"/>
<field name="file_pdf2" span="4"/>
<field name="file_pdf3" span="4"/>
<!--<field name="file_pdf4" span="4"/>-->
</group>
<group span="12" columns="1">
<template>
<div><b>Note:</b><span style="color:green"> <b style="color:#3477b0">"Waiting Document"</b> About 2minutes ~ 4minutes, there will be a notification at the right-hand mailbox.</span></div>
</template>
</group>
<foot>
<button string="Generate Report" states="draft" method="do_generate" icon="arrow-right" type="default"/>
<button string="Regenerate Report" states="done" method="do_generate" icon="arrow-right" type="default"/>
<button string="Waiting Document" states="waiting_doc" type="default"/>
</foot>
</form>

View File

@ -0,0 +1,9 @@
<list model="clinic.print.wizard.labor.cost">
<field name="period_id"/>
<field name="date_from"/>
<field name="date_to"/>
<field name="staff_type"/>
<field name="branch_id"/>
<field name="department_id"/>
<field name="state"/>
</list>

View File

@ -11,6 +11,6 @@
<field name="reimbursable" span="2"/>
<field name="pay_type" attrs='{"invisible":[["reimbursable","=","yes"]]}' span="2"/>
<foot>
<button string="Create Journal Entry" type="default" icon="arrow-right"/>
<!--<button string="Create Journal Entry" type="default" icon="arrow-right"/>-->
</foot>
</form>

View File

@ -3,7 +3,7 @@
<field name="date_from" required="1" span="2"/>
<field name="date_to" required="1" span="2"/>
<field name="staff_type" onchange="onchange_type" span="2"/>
<field name="staff_id" domain='[["type","=",type]]' span="2"/>
<field name="staff_id" domain='[["type","=",staff_type]]' span="2"/>
<field name="branch_id" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
</form>

View File

@ -0,0 +1,18 @@
<form model="clinic.report.wizard.labor.cost">
<group form_layout="stacked">
<field name="period_id" onchange="onchange_period" domain='[["state","=","open"]]' span="2"/>
<field name="date_from" onchange="onchange_from" required="1" span="2"/>
<field name="date_to" required="1" span="2"/>
<field name="branch_id" onchange="onchange_branch" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
<field name="staff_type" onchange="onchange_type" span="2" />
<field name="staff_id" domain='[["type","=",staff_type]]' span="2" />
<!--<field name="cycle_id" span="2"/>-->
<!--<field name="staff_type" required="1" span="2"/>-->
</group>
<foot replace="Run Report">
<button string="PDF Summary" type="success" method="wizard_report_summary" icon="print"/>
<button string="PDF Details" type="success" method="wizard_report_details" icon="print"/>
<button string="PDF Items" type="success" method="wizard_report_sub_details" icon="print"/>
</foot>
</form>

View File

@ -3,7 +3,6 @@
<field name="name"/>
<field name="date"/>
<field name="patient_id"/>
<field name="image" preview="1"/>
<field name="department_id"/>
<field name="branch_id"/>
<field name="note"/>

View File

@ -5,10 +5,11 @@
<field name="number"/>
<field name="visit_date"/>
<field name="cycle_id"/>
<field name="patient_id"/>
<field name="patient_name"/>
<field name="patient_type_id"/>
<field name="doctor_id"/>
<field name="department_id"/>
<field name="branch_id"/>
<!--<field name="branch_id"/>-->
<field name="nurse_id"/>
<field name="state"/>
</list>

View File

@ -1,4 +1,4 @@
<form model="clinic.report.account.hd.case.summary">
<form model="report.hdcase.expense.summary">
<field name="date" span="2" mode="month" onchange="onchange_date"/>
<field name="date_from" onchange="onchange_datefrom" span="2"/>
<field name="date_to" span="2"/>
@ -10,4 +10,7 @@
<field name="product_id" span="2"/>
<field name="reimbursable" span="2"/>
<field name="pay_type" attrs='{"invisible":[["reimbursable","=","yes"]]}' span="2"/>
<foot string="Export XLS" position="after">
<button string="Export PDF" type="success" method="get_report_data_pdf" icon="print" convert="pdf"/>
</foot>
</form>

View File

@ -0,0 +1,8 @@
<form model="report.hdcase.summary">
<field name="date" span="2" mode="month" onchange="onchange_date"/>
<field name="date_from" span="2"/>
<field name="date_to" span="2"/>
<field name="hdcase_type" required="1" span="2"/>
<field name="branch_id" onchange="onchange_branch" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
</form>

View File

@ -17,3 +17,8 @@ from . import clinic_setting
#from . import validate_cycle_item
#from . import update_line_amount
#from . import fix_tracking
#from . import revise
#from . import add_patient_moves #XXX do not run it again!!!
#from . import check_patient
#from . import update_patient_name
#from . import del_dbl_visit

View File

@ -0,0 +1,66 @@
import time
from netforce.model import get_model
from netforce import migration
from netforce.access import set_active_user, get_active_user, set_active_company, get_active_company
from netforce.database import get_connection
class Migration(migration.Migration):
_name="clinic.patient.move"
_version="2.12.7"
def migrate(self):
set_active_company(1)
set_active_user(1)
user_id=get_active_user()
company_id=get_active_company()
count_out=0
count_in=0
db=get_connection()
vals=[]
for patient in get_model("clinic.patient").search_browse([]):
count_out=0
count_in=0
date_str=""
time_tuple=""
if patient.dispose==True:
if not patient.resign_date:
#time_tuple=lambda *a: time.strftime("%Y-%m-%d %H:%M:%S")
time_tuple = lambda *a: time.strftime("%Y-%m-%d")
else:
date_str = patient.resign_date
time_tuple = lambda *a: time.strptime(date_str, "%Y-%m-%d")
line_vals={
"patient_id": patient.id,
"patient_name": "%s %s"% (patient.first_name or "",patient.last_name or ""),
"patient_type": patient.type_id.name,
"type": "out",
"type_id": patient.type_id.id,
"date": date_str,
#"location_from_id": obj.location,
#"location_to_id": obj.location,
}
db.execute("""
insert INTO clinic_patient_move (patient_id,patient_name,patient_type,type_id,type,date,create_time,create_uid) VALUES (%d,'%s','%s',%d,'%s','%s',CURRENT_DATE,%d);
"""%(line_vals.get('patient_id'),line_vals.get('patient_name'),line_vals.get('patient_type'),line_vals.get('type_id'),line_vals.get('type'),line_vals.get('date'),user_id))
print("insert INTO clinic.patient.move ('OUT'): %s , %s , %s"%(line_vals.get('patient_name'),line_vals.get('type'),line_vals.get('date')))
date_str = patient.reg_date
time_tuple = lambda *a: time.strptime(date_str, "%Y-%m-%d")
line_vals={
"patient_id": patient.id,
"patient_name": "%s %s"% (patient.first_name or "",patient.last_name or ""),
"patient_type": patient.type_id.name,
"type": "in",
"type_id": patient.type_id.id,
"date": date_str,
#"location_from_id": obj.location,
#"location_to_id": obj.location,
}
db.execute("""
insert INTO clinic_patient_move (patient_id,patient_name,patient_type,type_id,type,date,create_time,create_uid) VALUES (%d,'%s','%s',%d,'%s','%s',CURRENT_DATE,%d);
"""%(line_vals.get('patient_id'),line_vals.get('patient_name'),line_vals.get('patient_type'),line_vals.get('type_id'),line_vals.get('type'),line_vals.get('date'),user_id))
print("insert INTO clinic.patient.move ('IN'): %s , %s , %s"%(line_vals.get('patient_name'),line_vals.get('type'),line_vals.get('date')))
#set_active_user(user_id)
return True
Migration.register()

View File

@ -0,0 +1,70 @@
from netforce.model import get_model
from netforce import migration
from netforce.access import set_active_user, get_active_user, set_active_company, get_active_company
import collections
class Migration(migration.Migration):
_name="check.patient"
_version="2.12.8"
def migrate(salf):
set_active_company(1)
set_active_user(1)
totals={}
context={
'active_test': False,
}
for pt in get_model('clinic.patient').search_browse([], context=context):
key=(pt.number, pt.card_no, pt.walkin)
#key=(pt.hn_no)
totals.setdefault(key,{
'count': 0,
'pid': pt.id,
'pname': pt.name,
})
totals[key]['count']+=1
for k in sorted(totals.keys()):
hn_no, card_no, walkin = k
pt=totals[k]
if pt['count'] > 1:
#hn_no, card_no, walkin = k
print(k, pt)
return
user_id=get_active_user()
company_id=get_active_company()
count=0
lines_hn=[]
lines_pid=[]
lines_h=[]
lines_p=[]
print('start check patients.')
for pat in get_model('clinic.patient').search_browse([]):
lines_hn.append(pat.hn_no)
lines_pid.append(pat.card_no)
count+=1
print('count : %d'%(count))
total_hn = [item for item, count in collections.Counter(lines_hn).items() if count > 1]
total_pid = [item for item, count in collections.Counter(lines_pid).items() if count > 1]
count=0
for total in total_hn:
for line in get_model('clinic.patient').search_browse(['hn_no','=',total]):
data = '%d : %s'%(line.id,line.hn_no)
lines_h.append(data)
count+=1
print('#%d : id=%d, name=%s %s, hn_no=%s'%(count,line.id,line.first_name,line.last_name,line.hn_no))
print("")
print("*"*100)
print("")
count=0
for total in total_pid:
for line in get_model('clinic.patient').search_browse(['card_no','=',total]):
data = '%d : %s'%(line.id,line.card_no)
lines_p.append(data)
count+=1
print('#%d : id=%d, name=%s %s, pid=%s'%(count,line.id,line.first_name,line.last_name,line.card_no))
print('check patients : Done!')
return True
Migration.register()

View File

@ -0,0 +1,39 @@
import time
from netforce.migration import Migration
from netforce.model import Model, fields, get_model
class UpdatePatientName(Migration):
_name='del.dbl.visit'
_version="2.12.9"
def migrate(self):
cond=[
['visit_date','>=','2018-03-06'],
['visit_date','<=', '2018-03-06'],
['department_id','=', 4],
['state','!=', 'confirmed'],
]
patients={}
add_count=0
del_count=0
for index, visit in enumerate(get_model("clinic.visit").search_browse(cond)):
patient_id=visit.patient_id.id
cycle_id=visit.cycle_id.id
key=(patient_id, cycle_id)
if key in patients.keys():
print("del ", visit.id)
try:
visit.delete()
except Exception as e:
print("ERROR ", e)
print("visit ", visit.id, visit.number)
del_count+=1
else:
print("add ", visit.id)
add_count+=1
patients.setdefault(key)
print('total ', add_count, del_count)
UpdatePatientName.register()

View File

@ -0,0 +1,21 @@
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.revise"
_version="2.12.6"
def migrate(self):
set_active_user(1)
for hdcase in get_model('clinic.hd.case').search_browse([]):
if not hdcase.patient_name and hdcase.patient_id:
hdcase.write({
'patient_name': hdcase.patient_id.name_get()[-1][1],
})
Migration.register()

View File

@ -0,0 +1,34 @@
import time
from netforce.migration import Migration
from netforce.model import Model, fields, get_model
class UpdatePatientName(Migration):
_name='update.petient.name'
_version="2.12.9"
def migrate(self):
datenow=time.strftime("%Y-%m-%d")
y,m,d=datenow.split("-")
for f, model in [('date', 'clinic.hd.case'),('visit_date','clinic.visit')]:
cond=[
#[f,'>=','%s-01-01'%(y)],
[f,'>=','2014-01-01'],
[f,'<=',datenow],
['patient_name','=',None],
]
print("update %s ... "%model)
context={
'migration': True,
}
objs=get_model(model).search_browse(cond)
for index, obj in enumerate(objs):
patient=obj.patient_id
vals={
'patient_name': patient.name_get()[-1][1]
}
obj.write(vals,context=context)
#print("%s/%s"%(index+1, len(hdcases)))
UpdatePatientName.register()

View File

@ -67,7 +67,7 @@ from . import report_clinic
from . import report_visit
from . import report_cycle_item
from . import report_hd_case_summary
from . import report_account_hd_case_summary
from . import report_hdcase_expense_summary
from . import report_account_hd_case_detail
from . import report_hd_case_detail
from . import report_medical_summary
@ -148,3 +148,9 @@ from . import payment_matching
from . import create_invoice_payment
from . import report_stock_card
from . import report_receipt_summary
from . import report_wizard_labor_cost
#revise
from . import patient_move
from . import report_hdcase_summary
from . import print_wizard_labor_cost

View File

@ -394,6 +394,8 @@ class AccountInvoice(Model):
currency_code=inv.currency_id.code or ""
due_date=inv.due_date
add=st.default_address_id
hdcase=inv.related_id
patient=hdcase.patient_id
data={
'partner_name': cust_name,
'partner_address': cust_addr,
@ -425,6 +427,7 @@ class AccountInvoice(Model):
'is_cheque': is_cheque,
'is_draft': is_draft,
'user_name': user.name or "",
'patient_name': patient.name or "",
'state': inv.state or "",
}
data['pay_type']='Credit'
@ -432,6 +435,49 @@ class AccountInvoice(Model):
data['logo']=get_file_path(st.logo)
if cst.signature:
data['signature']=get_file_path(cst.signature)
data['auth_signature']=get_file_path(cst.signature)
return data
def pay_invoice(self, ids, context={}):
paid_inv=[]
for obj in self.browse(ids):
if obj.state!='waiting_payment':
continue
rel=obj.related_id
if rel and rel._model=='clinic.hd.case':
clinic_setting=get_model("clinic.setting").browse(1)
if not clinic_setting.hdcase_payment_account_id:
raise Exception("Missing HDCase Payment Account in setting!")
inv_pm_id=get_model("invoice.payment").create({
'date': time.strftime("%Y-%m-%d"),
'invoice_id': obj.id,
'account_id': clinic_setting.hdcase_payment_account_id.id,
'ref': rel.number,
'amount': obj.amount_due,
})
inv_pm=get_model("invoice.payment").browse(inv_pm_id)
inv_pm.add_payment(context)
for pm_line in obj.payments:
pm=pm_line.payment_id
pm.write({
'related_id': "clinic.hd.case,%s"%rel.id,
})
paid_inv.append(obj.number)
if not paid_inv:
raise Exception("Nothing to paid!")
return {
'flash': 'Invoice: %s has been paid'%(','.join(paid_inv)),
}
def hdcase_to_draft(self, ids, context={}):
for payment_line in get_model("account.payment.line").search_browse([['invoice_id','in',ids]]):
payment=payment_line.payment_id
rel=payment.related_id
if rel._model=='clinic.hd.case':
payment.to_draft()
payment.delete()
for inv in self.browse(ids):
inv.to_draft()
inv.approve()
AccountInvoice.register()

View File

@ -46,7 +46,7 @@ class AccountPayment(Model):
'next': {
'name': 'report_clinic_payment_form',
'refer_id': hd_case_id,
'payment_id': obj.id,
'payment_ids': ids,
'convert': 'pdf',
},
}

View File

@ -75,8 +75,8 @@ class Dialyzer(Model):
product_id=prod.id
found=True
break
if not product_id:
raise Exception("No Product with category 'Dialyzer'")
#if not product_id:
#raise Exception("No Product with category 'Dialyzer'")
return product_id
def _get_product_name(self,context={}):
@ -126,7 +126,6 @@ class Dialyzer(Model):
if not ship_address_id:
patient.simple_address()
#XXX
st=get_model("clinic.setting").browse(1)
stock_journal=st.stock_journal_id
@ -170,7 +169,7 @@ class Dialyzer(Model):
raise Exception("Warehouse not found")
wh_loc_id=res[0]
if prod.type=='stock':
if prod and prod.type=='stock':
line_vals={
"product_id": prod.id,
"qty": 1,
@ -191,7 +190,7 @@ class Dialyzer(Model):
number=obj.number.replace("/","")
if not number:
department=obj.department_id
context['branch_id']=department.branch_id.id
context['branch_id']=department.branch_id.id
number=self._get_number(context=context)
obj.write({
"number": number,

View File

@ -298,6 +298,8 @@ class HDCase(Model):
'company_id': fields.Many2One("company","Company"),
'branch_id': fields.Many2One("clinic.branch","Branch"),
'check_dlz': fields.Boolean("Check Dialyzer"),
#revise
'patient_name': fields.Char("Patient Name", search=True),
}
def _get_number(self,context={}):
@ -409,6 +411,7 @@ class HDCase(Model):
data['branch_id']=branch.id
data['cycle_id']=cycle.id
data['patient_type_id']=patient.type_id.id
data['patient_name']=patient.name_get()[-1][1]
data['type_code']=patient.type_id.code
if patient.type_id.hct_include:
data['hct_include']=True
@ -437,7 +440,6 @@ class HDCase(Model):
'price': pline.price or 0,
'amount': pline.amount or 0,
})
return data
def onchange_line(self,context={}):
@ -1107,7 +1109,7 @@ class HDCase(Model):
# update sickbed
if obj.sickbed_id:
obj.sickbed_id.write({
'available': False,
'available': True, #reset to available, => please recheck art
})
obj.recompute_labor_cost()
return {
@ -1319,7 +1321,10 @@ class HDCase(Model):
for obj in self.browse(ids):
if not obj.payments:
raise Exception("Receipt not found!")
for payment in obj.payments:
payment_ids=[]
if context.get('payment_ids'):
payment_ids=eval(context['payment_ids'])
for payment in get_model('account.payment').browse(payment_ids):
context['payment_id']=payment.id
data=self.get_report_payment_data(context=context)
limit_item=9
@ -1572,13 +1577,14 @@ class HDCase(Model):
def create(self,vals,context):
patient_id=vals['patient_id']
patient=get_model("clinic.patient").browse(patient_id)
if 'vascular_acc' in vals.keys():
patient=get_model("clinic.patient").browse(patient_id)
patient.write({
'vascular_acc': vals['vascular_acc']
})
vals=self.get_staff_line(vals,patient_id)
vals=self.get_hct(vals,patient_id)
vals['patient_name']=patient.name_get()[-1][1]
new_id=super().create(vals,context=context)
self.function_store([new_id])
return new_id
@ -1612,7 +1618,8 @@ class HDCase(Model):
})
sb=get_model("clinic.sickbed").browse(vals['sickbed_id'])
sb.write({
'state': 'not_available',
'available': False,
'state': 'not_available', #XXX Check state.
})
set_active_user(user_id)
if 'lines' in vals.keys():

View File

@ -6,7 +6,8 @@ class HDCasePopupDlz(Model):
_fields={
"hd_case_id": fields.Many2One("clinic.hd.case","HdCase",required=True,on_delete="cascade"),
'product_id': fields.Many2One("product", "Product",required=True),
'product_id': fields.Many2One("product", "Product",required=False),
'new_product': fields.Char("New Product"),
"dialyzer_type": fields.Selection([("low","low flux"),("high","high flux"),("dbl","dbl hifulx")],"Dialyzer Type"),
"max_use_time": fields.Integer("Max Use Time"),
"exp_date": fields.Date("Expiry Date"),
@ -48,7 +49,7 @@ class HDCasePopupDlz(Model):
'product_id': product_id,
'drop_old': True,
}
print('res', res)
print('dlz.res', res)
return res
def new_dlz(self,ids,context={}):
@ -59,8 +60,34 @@ class HDCasePopupDlz(Model):
context['is_wiz']=True
context['pop_id']=obj.id
context['drop_old']=obj.drop_old
if obj.new_product:
name=obj.new_product
uom_id=None
for r_id in get_model("uom").search([['name','=','Unit']]):
uom_id=r_id
if not uom_id:
raise Exception("Missing UoM <Unit>!")
categ_id=None
for r_id in get_model("product.categ").search([['code','=','DLZ']]):
categ_id=r_id
if not categ_id:
raise Exception("Missing Product category code DLZ!")
new_prod_id=get_model("product").create({
'type': 'stock',
'code': name.upper(),
'name': name,
'description': name,
"uom_id": uom_id,
'categ_id': categ_id,
'can_sell': True,
'can_purchase': True,
})
obj.write({
'product_id': new_prod_id,
})
if not obj.product_id:
raise Exception("Missing product!")
res=hd_case.new_dialyzer(context=context)
print('res ', res)
return res
def onchange_product(self,context={}):

View File

@ -112,8 +112,8 @@ class Patient(Model):
"hn_no": fields.Char("HN",function="_get_hn_no",store=True),
"hn": fields.Char("REF/HN",search=False),
'title_id': fields.Many2One("clinic.name.title","Title"),
"first_name": fields.Char("First Name"),
"last_name": fields.Char("Last Name"),
"first_name": fields.Char("First Name", search=True),
"last_name": fields.Char("Last Name", search=True),
"name": fields.Char("Name",function="_get_name",function_multi=True,store=True,search=True),
"name_check": fields.Char("Name",function="_get_name",function_multi=True,store=True), # prevent duplicate
'type_id': fields.Many2One("clinic.patient.type","Type",search=True,required=True),
@ -178,6 +178,7 @@ class Patient(Model):
'location': fields.Char("Share Department"), #to filter
'cw_time': fields.DateTime("Cycle Updated"),
'cw_uid': fields.Many2One("base.user"," Cycle Edit"),
"moves": fields.One2Many("clinic.patient.move","patient_id","Moves"),
}
def _get_number(self,context={}):
@ -271,7 +272,7 @@ class Patient(Model):
'dispose': False,
}
_sql_constraints=("clinic_patient_key_uniq","unique(name_check)","name should be unique"),
_sql_constraints=("clinic_patient_key_uniq","unique(number,card_no,walkin)","HN, Card and Walkin should be unique"),
def check_idcard(self,card_type,idcard=''):
res=True
@ -327,6 +328,19 @@ class Patient(Model):
obj.write({
'partner_id': partner_id,
})
#TODO create patient.move
if obj.walkin=="no":
patient_move={
"patient_id": obj.id,
"patient_name": "%s %s"% (obj.first_name or "",obj.last_name or ""),
"patient_type": obj.type_id.name,
"type": "in",
"type_id": obj.type_id.id,
#"location_from_id": obj.location,
#"location_to_id": obj.location,
}
get_model("clinic.patient.move").create(patient_move)
return obj_id
def delete(self,ids,context={}):
@ -372,10 +386,35 @@ class Patient(Model):
if not vals.get("resign_date"):
vals['resign_date']=time.strftime("%Y-%m-%d")
vals['rm_remain_visit']=True
obj=self.browse(ids)[0]
if obj.walkin=='no':
patient_move={
'date': obj.resign_date, #XXX
"patient_id": obj.id,
"patient_name": "%s %s"% (obj.first_name or "",obj.last_name or ""),
"patient_type": obj.type_id.name,
"type": "out",
"type_id": obj.type_id.id,
#"location_from_id": obj.location,
#"location_to_id": obj.location,
}
get_model("clinic.patient.move").create(patient_move)
else:
vals['state']='admit'
vals['rm_remain_visit']=False
vals['resign_date']=None
obj=self.browse(ids)[0]
if obj.walkin=='no':
patient_move={
"patient_id": obj.id,
"patient_name": "%s %s"% (obj.first_name or "",obj.last_name or ""),
"patient_type": obj.type_id.name,
"type": "in",
"type_id": obj.type_id.id,
#"location_from_id": obj.location,
#"location_to_id": obj.location,
}
get_model("clinic.patient.move").create(patient_move)
ctx={}
if 'active' in vals.keys():
if not vals['active']:

View File

@ -1,17 +1,23 @@
import time
from netforce.model import Model, fields
from netforce.model import Model, fields, get_model
class PatientMove(Model):
_name="clinic.patient.move"
_name='clinic.patient.move'
_fields={
'patient_id': fields.Many2One('clinic.patient','Patient'),
'date': fields.DateTime("Date"),
'location_id': fields.Many2One("clinic.department","Department"),
"patient_id": fields.Many2One("clinic.patient", "Patient", required=True, on_delete="cascade"),
"type_id": fields.Many2One("clinic.patient.type","Type",search=True,required=True),
"date": fields.DateTime("Date"),
"patient_name": fields.Char("Patient Name"),
"patient_type": fields.Char("Patient Type"), #ปกส. ....
"type": fields.Selection([['in','In'],['out','Out']], 'Type', required=True),
"location_from_id": fields.Many2One("stock.location", "From Location", required=False, search=True),
"location_to_id": fields.Many2One("stock.location", "To Location", required=False, search=True),
}
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
}
PatientMove()
PatientMove.register()

View File

@ -0,0 +1,189 @@
import os
import time
import urllib
from calendar import monthrange
from netforce.model import Model,fields,get_model
from netforce.database import get_active_db, get_connection
from netforce.access import get_active_user, get_active_company, set_active_user
import netforce.config as config
class PrintLaborCost(Model):
_name="clinic.print.wizard.labor.cost"
_string="Report Wizard Labor Cost"
_audit_log=True
_fields={
"date": fields.Date("Month"),
"period_id": fields.Many2One("clinic.period.line", "Period", search=True),
"date_from": fields.Date("From", required=True),
"date_to": fields.Date("To", required=True),
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
"branch_id": fields.Many2One("clinic.branch","Branch"),
"department_id": fields.Many2One("clinic.department","Department"),
"staff_type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type", required=True),
'staff_id': fields.Many2One("clinic.staff","Staff"),
'state': fields.Selection([['draft','Draft'],['waiting_doc','Waiting Document'],['done','Done']],'State',search=True),
'company_id': fields.Many2One('company','Company'),
'file_pdf1': fields.File("File_Labor_cost_sunmary"),
'file_pdf2': fields.File("File_Labor_cost_details"),
'file_pdf3': fields.File("File_Labor_cost_Sub_Deatils(Doctor)"),
'file_pdf4': fields.File("File_Labor_cost_Sub_Deatils(Nurse)"),
}
def _get_date_from(self,context={}):
year,month,day=time.strftime("%Y-%m-%d").split("-")
#return '%s-%s-01'%(year,month)
return '%s-%s-%s'%(year,month,day)
def _get_date_to(self,context={}):
year,month,day=time.strftime("%Y-%m-%d").split("-")
weekday, total_day=monthrange(int(year), int(month))
#return "%s-%s-%s"%(year,month,total_day)
return "%s-%s-%s"%(year,month,day)
def default_get(self,field_names=None,context={},**kw):
defaults=context.get("defaults",{})
date_from=defaults.get("date_from", self._get_date_from())
date_to=defaults.get("date_to", self._get_date_to())
print('defaults ', defaults)
yearnow=date_from.split("-")[0]
if len(get_model('clinic.period').search_browse([['name','=',yearnow]]))==0:
period_id=None
for period in get_model('clinic.period').search_browse([['name','=',yearnow]]):
for line in period.lines:
if line.state=='open':
period_id=line.id
date_from=line.date_start
date_to=line.date_stop
break
res={
'period_id': period_id,
'date': time.strftime("%Y-%m-%d"),
'date_from': date_from,
'date_to': date_to,
'state': 'draft',
'company_id': get_active_company(),
}
return res
def generate_report(self,ids,context={}):
db=get_connection()
user_id=get_active_user()
set_active_user(1)
if ids:
obj=self.browse(ids)[0]
else:
return
obj.write({
'state': 'waiting_doc',
'file_pdf1': None,
'file_pdf2': None,
'file_pdf3': None,
#'file_pdf4': None,
})
db.commit()
def load_report(fname,link):
host=config.config['host']
port=config.config['port']
hostname='http://%s:%s/'%(host,port)
link=hostname+link
req=urllib.request.Request(link)
response=urllib.request.urlopen(req)
data=response.read()
fpath=os.path.join('/tmp/wizard_lc',fname)
open(fpath,"wb").write(data)
dbname=get_active_db()
fdir=os.path.join("static","db",dbname,"files")
tmp_dir='/tmp/wizard_lc'
print('majins',fdir)
print('majins',tmp_dir)
if not os.path.isdir(tmp_dir):
os.system("mkdir %s"%(tmp_dir))
#Create File Name
fname1='%s_wizard_sunmary_%s_to_%s.pdf'%(obj.id,obj.date_from,obj.date_to)
fname2='%s_wizard_details_%s_to_%s.pdf'%(obj.id,obj.date_from,obj.date_to)
fname3='%s_wizard_sub_details_%s_to_%s(%s).pdf'%(obj.id,obj.date_from,obj.date_to,obj.staff_type)
#fname3='%s_wizard_sub_details_%s_to_%s(docter).pdf'%(obj.id,obj.date_from,obj.date_to)
#fname4='%s_wizard_sub_details_%s_to_%s(nurse).pdf'%(obj.id,obj.date_from,obj.date_to)
defaults='&data=%s&period_id=%s&date_from=%s&date_to=%s&cycle_id=%s&branch_id=%s&department_id=%s&staff_type=%s'%(obj.date_from,obj.period_id.id,obj.date_from,obj.date_to,obj.cycle_id.id or None,obj.branch_id.id or None,obj.department_id.id or None,obj.staff_type or None)
lc_id=get_model('clinic.report.wizard.labor.cost').create({})
link1="report?convert=pdf&refer_id=%s&template=report_wizard_labor_cost_summary&model=clinic.report.wizard.labor.cost&type=report_odt2&method=get_report_wizard_summary%s&type_report=wizard&user=admin" % (lc_id,defaults)
load_report(fname1,link1)
link2="report?convert=pdf&refer_id=%s&template=report_wizard_labor_cost_details&model=clinic.report.wizard.labor.cost&type=report_odt2&method=get_report_wizard_details%s&type_report=wizard&user=admin" % (lc_id,defaults)
load_report(fname2,link2)
link3="report?convert=pdf&refer_id=%s&template=report_wizard_labor_cost_sub_details&model=clinic.report.wizard.labor.cost&type=report_odt2&method=get_report_wizard_sub_details%s&type_report=wizard&user=admin" % (lc_id,defaults)
load_report(fname3,link3)
#link4="report?convert=pdf&refer_id=%s&template=report_wizard_labor_cost_sub_details&model=clinic.report.wizard.labor.cost&type=report_odt2&method=get_report_wizard_sub_details%s&type_report=wizard&user=admin" % (lc_id,defaults+'&staff_type=nurse')
#load_report(fname4,link4)
obj.write({
'file_pdf1': '%s' % (fname1),
'file_pdf2': '%s' % (fname2),
'file_pdf3': '%s' % (fname3),
#'file_pdf4': '%s' % (fname4),
'state': 'done',
})
os.chdir('%s'%fdir)
os.system("mv /%s/%s* ."%(tmp_dir,obj.id))
os.chdir('../../../../')
set_active_user(user_id)
vals={
'to_id': get_active_user(),
'subject': 'Generate Report',
'body': """
Generate labor cost report for successfully.
<a href="/ui#name=clinic_print_wizard_labor_cost&mode=form&active_id=%s" class="msg-btn-ok">Open Print Wizard Labor Cost</a>
"""%(obj.id),
}
get_model("message").create(vals)
db.commit()
return {
'next': {
'name': 'clinic.print.wizard.labor.cost',
'mode': 'form',
'active_id': obj.id,
},
}
def wkf_gen_report(self,context={},**kw):
print("#"*80)
trigger_ids=context.get("trigger_ids")
if not trigger_ids:
raise Exception("Missing trigger ids")
print("trigger_ids",trigger_ids)
self.generate_report(trigger_ids,context,**kw)
def do_generate(self,ids,context={}):
self.trigger(ids,"do_gen")
def onchange_date(self,context={}):
data=context['data']
date=data['date']
year,month,day=date.split("-")
weekday, total_day=monthrange(int(year), int(month))
data['date_from']="%s-%s-01"%(year,month)
data['date_to']="%s-%s-%s"%(year,month,total_day)
return data
def onchange_branch(self,context={}):
data=context['data']
data['department_id']=None
return data
def onchange_from(self,context={}):
data=context['data']
data['date_to']=data['date_from']
return data
def onchange_period(self,context={}):
data=context['data']
period_id=data['period_id']
period=get_model('clinic.period.line').browse(period_id)
data['date_from']=period.date_start
data['date_to']=period.date_stop
return data
PrintLaborCost.register()

View File

@ -259,6 +259,15 @@ class ReportAccountHDCaseDetail(Model):
'qty': 0,
'color': line['ptype_color'] or "default",
}
######XXX revise for accountant: convert to int
line['fee']=int(line.get('fee',0))
line['srv']=int(line.get('srv',0))
line['epo']=int(line.get('epo',0))
line['mdc']=int(line.get('mdc',0))
line['lab']=int(line.get('lab',0))
line['misc']=int(line.get('misc',0))
######
ptypes[ptype]['qty']+=1
total_fee+=line.get('fee',0)
total_srv+=line.get('srv',0)

View File

@ -277,7 +277,7 @@ class ReportCycleItem(Model):
# if nurse more that cres, should show name of nurses
nlines+=more_lines
if no==count:
epo_items=[{'name': k, 'qty': v} for k,v in epos.items() if k ]
epo_items=sorted([{'name': k, 'qty': v} for k,v in epos.items() if k ], key=lambda a: a['name'])
#sort item
#clines=sorted(clines,key=lambda cl: cl[sort_by])
no=1
@ -322,13 +322,13 @@ class ReportCycleItem(Model):
'fee': sub_fee,
'mdc': sub_mdc,
'epo_items': epo_items,
'epo_txt': ', '.join(['%s = %s'%(k,v) for k,v in epos.items() if k])
'epo_txt': ', '.join(['%s = %s'%(v['name'], v['qty']) for v in epo_items if v])
})
for epo_item in epo_items:
if not total_epos.get(epo_item['name']):
total_epos[epo_item['name']]=0
total_epos[epo_item['name']]+=epo_item['qty'] or 0
total_epo_items=[{'name': k, 'qty': v} for k,v in total_epos.items() if k ]
total_epo_items=sorted([{'name': k, 'qty': v} for k,v in total_epos.items() if k ], key=lambda a: a['name'])
vscl_lines=[]
for k,v in vasculars.items():
vscl_lines.append({

View File

@ -2,7 +2,7 @@ import time
from calendar import monthrange
from netforce.model import Model,fields,get_model
from netforce.access import get_active_company
from netforce.access import get_active_company, get_active_user, set_active_user
from . import utils
@ -52,6 +52,72 @@ class ReportDiscontinuePatient(Model):
return res
def get_report_data(self,ids,context={}):
company_id=get_active_company()
company=get_model('company').browse(company_id)
year, month=time.strftime("%Y-%m").split("-")
weekday, total_day=monthrange(int(year), int(month))
defaults=self.default_get(context=context)
time_start=defaults.get("date_from")
time_stop=defaults.get("date_to")
branch_id=defaults.get("branch_id")
department_id=defaults.get("department_id")
if ids:
obj=self.browse(ids)[0]
month=obj.date_from.split("-")[1]
time_start=obj.date_from
time_stop=obj.date_to
branch_id=obj.branch_id.id
department_id=obj.department_id.id
# new patient of this month
dom=[]
dom.append(['date','>=',"%s 00:00:00"%(time_start)])
dom.append(['date','<=',"%s 23:59:59"%(time_stop)])
dom.append(['type','=','out'])
records=get_model('clinic.patient.move').search_browse(dom)
lines=[]
no=1
user_id=get_active_user()
set_active_user(1)
for record in records:
if record.patient_id.branch_id.id!=branch_id:
continue
if record.patient_id.department_id.id!=department_id:
continue
if record.patient_id.walkin!='no':
continue
lines.append({
'no': no,
'name': record.patient_name or '',
'pid': record.id,
'note': record.patient_id.note or '',
'resign_date': record.date[:10] or '',
})
no+=1
set_active_user(user_id)
month_str=utils.MONTHS['th_TH'][int(month)]
start=int(time_start[8:10])
stop=int(time_stop[8:10])
diff=stop-start
sub_name=''
if department_id:
dpt=get_model("clinic.department").browse(department_id)
sub_name="(%s)" % dpt.name or ""
elif branch_id:
branch=get_model("clinic.branch").browse(branch_id)
sub_name="(%s)" % branch.name or ""
data={
'company_name': '%s %s' % (company.name or "", sub_name),
'parent_company_name': company.parent_id.name or "",
'lines': lines,
'month': month_str,
'from': time_start,
'to': time_stop,
'is_duration': diff+1 < total_day,
'year': year,
}
return data
def get_report_data_bak(self,ids,context={}):
company_id=get_active_company()
company=get_model('company').browse(company_id)
year, month=time.strftime("%Y-%m").split("-")

View File

@ -81,6 +81,291 @@ class ReportHDCaseDetail(Model):
user_id=get_active_user()
set_active_user(1)
company_id=get_active_company()
company=get_model("company").browse(company_id)
defaults=self.default_get(context=context)
date=defaults.get('date',time.strftime("%Y-%m-%d"))
year=int(date[0:4])
crr_month=int(date[5:7])
weekday, crr_total_day=monthrange(year, crr_month)
date_from=defaults.get('date_from',date)
date_to=defaults.get('date_to',date)
branch_id=defaults.get("branch_id",None)
department_id=defaults.get("department_id",None)
hdcase_type=defaults.get('hdcase_type')
report_type=defaults.get('report_type','topic1')
patient_type_id=defaults.get('patient_type_id')
time_start='%s-%s-01'%(year,str(crr_month).zfill(2))
time_stop='%s-%s-%s'%(year,str(crr_month).zfill(2),crr_total_day)
titles=dict(self._fields['report_type'].selection)
title=titles.get(report_type,'no title')
if ids:
obj=self.browse(ids)[0]
branch_id=obj.branch_id.id
department_id=obj.department_id.id
date=obj.date
crr_month=int(date[5:7])
time_start=obj.date_from
time_stop=obj.date_to
year=int(date[0:4])
date_from=obj.date_from
date_to=obj.date_to
report_type=obj.report_type or 'topic1'
hdcase_type=obj.hdcase_type or 'completed'
patient_type_id=obj.patient_type_id.id
time_start="%s 00:00:00"%(time_start)
time_stop="%s 23:59:59"%(time_stop)
prev_year=year
next_year=year
prev_month=crr_month-1
next_month=crr_month+1
if crr_month==1:
prev_month=12
prev_year-=1
if crr_month==12:
next_month=1
next_year+=1
month_str=utils.MONTHS['th_TH'][crr_month]
next_month_str=utils.MONTHS['th_TH'][next_month]
prev_month_str=utils.MONTHS['th_TH'][prev_month]
def replace_quote(dom=""):
dom=dom.replace("False","false")
dom=dom.replace("True","true")
return dom.replace("'","\"")
dom=[]
lines=[]
total=0
# current hd case
if report_type=='topic1':
title=titles.get(report_type,'no title')
dom=[]
dom.append(["date",">=",date_from])
dom.append(["date","<=",date_to])
if hdcase_type=='completed':
dom.append(["state","in",["waiting_payment","paid"]])
else:
dom.append(["state","not in",["waiting_payment","paid"]])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
total=0
for hdcase in get_model("clinic.hd.case").search_browse(dom,order="number"):
patient=hdcase.patient_id
lines.append({
'number': hdcase.number,
'date': hdcase.date,
'name': patient.name,
'note': hdcase.note,
})
total+=1
# number of patient from previous month
elif report_type=='topic2':
title=titles.get(report_type,'no title')
title+=' '+prev_month_str
prev_weekday, prev_total_day=monthrange(prev_year, prev_month)
reg_date='%s-%s-%s 23:59:59'%(prev_year,str(prev_month).zfill(2),str(prev_total_day).zfill(2))
#print('topic2 ', reg_date)
dom=[]
dom.append(['walkin','=',"no"])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
total=0
for patient in get_model("clinic.patient").search_browse(dom):
if len(get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',reg_date]],order="date desc"))==0:
continue
if len(get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','out'],['date','<=',reg_date]],order="date desc"))==0:
moves_in=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',reg_date]],order="date desc")[0]
data={
'number': moves_in.patient_id.hn_no,
'pid': moves_in.patient_id.id,
'name': moves_in.patient_name,
'note': moves_in.patient_id.note,
'date': moves_in.patient_id.reg_date,
}
else:
moves_in=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',reg_date]],order="date desc")[0]
moves_out=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','out'],['date','<=',reg_date]],order="date desc")[0]
if moves_out.date > moves_in.date:
continue
data={
'number': moves_in.patient_id.hn_no,
'pid': moves_in.patient_id.id,
'name': moves_in.patient_name,
'note': moves_in.patient_id.note,
'date': moves_in.patient_id.reg_date,
}
lines.append(data)
total+=1
# new patient of this month
#TODO should include move_history
elif report_type=='topic3':
title=titles.get(report_type,'no title')
title+=' '+month_str
dom=[]
dom.append(['date','>=',time_start])
dom.append(['date','<=',time_stop])
dom.append(['type','=',"in"])
total=0
for moves in get_model('clinic.patient.move').search_browse(dom):
if moves.patient_id.branch_id.id!=branch_id:
continue
if moves.patient_id.department_id.id!=department_id:
continue
if moves.patient_id.walkin!='no':
continue
lines.append({
'number': moves.patient_id.hn_no,
'pid': moves.patient_id.id,
'name': moves.patient_name,
'note': moves.patient_id.note,
'date': moves.date[:10],
})
total+=1
# number for patient who resign for this month
#TODO should include move_history
elif report_type=='topic4':
title=titles.get(report_type,'no title')
title+=' '+month_str
dom=[]
dom.append(['date','>=',time_start])
dom.append(['date','<=',time_stop])
dom.append(['type','=',"out"])
total=0
for moves in get_model('clinic.patient.move').search_browse(dom):
if moves.patient_id.branch_id.id!=branch_id:
continue
if moves.patient_id.department_id.id!=department_id:
continue
if moves.patient_id.walkin!='no':
continue
lines.append({
'number': moves.patient_id.hn_no,
'pid': moves.id,
'name': moves.patient_name,
'note': moves.patient_id.note,
'date': moves.date[:10],
})
total+=1
# all patient who are in hospital on select month
elif report_type=='topic5':
#print('topic5 ', time_stop)
title=titles.get(report_type,'no title')
title+=' '+next_month_str
dom=[]
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
dom.append(['walkin','=',"no"])
total=0
count=0
data_check={}
for patient in get_model('clinic.patient').search_browse(dom):
if len(get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',time_stop]],order="date desc"))==0:
continue
if len(get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','out'],['date','<=',time_stop]],order="date desc"))==0:
moves_in=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',time_stop]],order="date desc")[0]
data={
'number': moves_in.patient_id.hn_no,
'pid': moves_in.patient_id.id,
'name': moves_in.patient_name,
'note': moves_in.patient_id.note,
'date': moves_in.patient_id.reg_date,
}
else:
moves_in=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',time_stop]],order="date desc")[0]
moves_out=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','out'],['date','<=',time_stop]],order="date desc")[0]
if moves_out.date > moves_in.date:
continue
data={
'number': moves_in.patient_id.hn_no,
'pid': moves_in.patient_id.id,
'name': moves_in.patient_name,
'note': moves_in.patient_id.note,
'date': moves_in.patient_id.reg_date,
}
lines.append(data)
total+=1
# find patient movement
elif report_type=='topic6':
#print('topic6')
ptype=None
if patient_type_id:
ptype=get_model('clinic.patient.type').browse(patient_type_id)
if not ptype:
return {'total': 0}
title=ptype.name or ''
dom=[]
dom.append(['type_id','=',ptype['id']])
dom.append(['walkin','=',"no"])
dom.append(['type_id','=',ptype.id])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
total=0
for patient in get_model('clinic.patient').search_browse(dom):
if len(get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',time_stop]],order="date desc"))==0:
continue
if len(get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','out'],['date','<=',time_stop]],order="date desc"))==0:
moves_in=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',time_stop]],order="date desc")[0]
data={
'number': moves_in.patient_id.hn_no,
'pid': moves_in.patient_id.id,
'name': moves_in.patient_name,
'date': moves_in.patient_id.reg_date,
}
else:
moves_in=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',time_stop]],order="date desc")[0]
moves_out=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','out'],['date','<=',time_stop]],order="date desc")[0]
if moves_out.date > moves_in.date:
continue
data={
'number': moves_in.patient_id.hn_no,
'pid': moves_in.patient_id.id,
'name': moves_in.patient_name,
'date': moves_in.patient_id.reg_date,
}
lines.append(data)
total+=1
sub_name=''
if department_id:
dpt=get_model("clinic.department").browse(department_id)
sub_name="(%s)" % dpt.name or ""
elif branch_id:
branch=get_model("clinic.branch").browse(branch_id)
sub_name="(%s)" % branch.name or ""
no=1
for line in lines:
line['no']="{0:,.0f}".format(no)
no+=1
data={
'total_txt': "{0:,.0f}".format(total),
'total': total,
'title': title,
'report_type': report_type,
'date': date,
'date_from': date_from,
'date_to': date_to,
'month': month_str,
'year': year,
'branch_id': branch_id,
'department_id': department_id,
'lines': lines,
'company_name': '%s %s'% (company.name or "", sub_name),
'parent_company_name': company.parent_id.name or "",
}
set_active_user(user_id)
return data
def get_report_data_bak(self,ids,context={}):
user_id=get_active_user()
set_active_user(1)
company_id=get_active_company()
company=get_model("company").browse(company_id)
defaults=self.default_get(context=context)
@ -164,7 +449,7 @@ class ReportHDCaseDetail(Model):
title+=' '+prev_month_str
prev_weekday, prev_total_day=monthrange(prev_year, prev_month)
reg_date='%s-%s-%s'%(prev_year,str(prev_month).zfill(2),str(prev_total_day).zfill(2))
print('topic2 ', reg_date)
#print('topic2 ', reg_date)
dom=[]
dom.append(['reg_date','<=',reg_date])
dom.append(['walkin','=',"no"])
@ -193,6 +478,7 @@ class ReportHDCaseDetail(Model):
'name': patient.name,
'note': patient.note,
'date': patient.reg_date,
'dispose': patient.dispose and 'yes' or 'no',
})
total+=1
# new patient of this month
@ -245,7 +531,7 @@ class ReportHDCaseDetail(Model):
total+=1
# all patient who are in hospital on select month
elif report_type=='topic5':
print('topic5 ', time_stop)
#print('topic5 ', time_stop)
title=titles.get(report_type,'no title')
title+=' '+next_month_str
dom=[]
@ -280,7 +566,7 @@ class ReportHDCaseDetail(Model):
total+=1
# find patient movement
elif report_type=='topic6':
print('topic6')
#print('topic6')
ptype=None
if patient_type_id:
ptype=get_model('clinic.patient.type').browse(patient_type_id)
@ -315,6 +601,7 @@ class ReportHDCaseDetail(Model):
'number': patient.hn_no,
'name': patient.name or '',
'date': patient.reg_date,
'dispose': patient.dispose and 'yes' or 'no',
})
total+=1
sub_name=''

View File

@ -4,7 +4,7 @@ import urllib.parse as urllib
from datetime import datetime
from calendar import monthrange
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company, get_active_user
from netforce.access import get_active_company, get_active_user, set_active_user
from . import utils
@ -56,6 +56,7 @@ class ReportHDCaseSummary(Model):
def get_report_data(self,ids,context={}):
company_id=get_active_company()
company=get_model("company").browse(company_id)
user_id=get_active_user()
date=datetime.now().strftime("%Y-%m-%d")
year=int(date[0:4])
crr_month=int(date[5:7])
@ -271,8 +272,8 @@ class ReportHDCaseSummary(Model):
plines=medicals['plines']
prod_titles=medicals['prod_titles']
date_print=time.strftime("%m/%d/%Y %H:%M:%S")
user_id=get_active_user()
user=get_model('base.user').browse(user_id)
set_active_user(1)
data={
'user_name': user.name,
'hdcase_type': hdcase_type,
@ -294,6 +295,7 @@ class ReportHDCaseSummary(Model):
'company_name': '%s %s'% (company.name or "", sub_name),
'parent_company_name': company.parent_id.name or "",
}
set_active_user(user_id)
return data
def onchange_date(self,context={}):

View File

@ -4,9 +4,9 @@ from calendar import monthrange
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company
class ReportAccountHDCaseSummary(Model):
_name="clinic.report.account.hd.case.summary"
_string="HD Case Report Summary"
class ReportHDCaseExpenseSummary(Model):
_name="report.hdcase.expense.summary"
_string="HDCase Expense Summary"
_transient=True
_fields={
@ -60,7 +60,20 @@ class ReportAccountHDCaseSummary(Model):
'product_id': product_id,
}
return res
def get_report_data_pdf(self,ids,context={}):
obj=self.browse(ids)[0]
return {
"next": {
"type": "report_odt2",
"model": self._name,
"template": "report_hdcase_expense_summary_pdf",
"refer_id": obj.id,
"method": "get_report_data",
"convert": "pdf",
}
}
def get_report_data(self,ids,context={}):
company_id=get_active_company()
company=get_model("company").browse(company_id)
@ -259,6 +272,16 @@ class ReportAccountHDCaseSummary(Model):
'qty': 0,
'color': line['ptype_color'] or "default",
}
######XXX revise for accountant: convert to int
line['fee']=int(line.get('fee',0))
line['srv']=int(line.get('srv',0))
line['epo']=int(line.get('epo',0))
line['mdc']=int(line.get('mdc',0))
line['lab']=int(line.get('lab',0))
line['misc']=int(line.get('misc',0))
######
ptypes[ptype]['qty']+=1
total_fee+=line.get('fee',0)
total_srv+=line.get('srv',0)
@ -269,6 +292,15 @@ class ReportAccountHDCaseSummary(Model):
total_dlz+=line.get('dlz_price',0)
line['no']=no
######XXX revise for accountant: convert from int to thounsand without decimal zero
line['fee']=line.get('fee') and '{:,}'.format(line.get('fee',0)) or ""
line['srv']=line.get('srv') and '{:,}'.format(line.get('srv',0)) or ""
line['epo']=line.get('epo') and '{:,}'.format(line.get('epo',0)) or ""
line['mdc']=line.get('mdc') and '{:,}'.format(line.get('mdc',0)) or ""
line['lab']=line.get('lab') and '{:,}'.format(line.get('lab',0)) or ""
line['misc']=line.get('misc') and '{:,}'.format(line.get('misc',0)) or ""
######
cid=line['cid']
if not cid in old:
old.append(cid)
@ -284,7 +316,8 @@ class ReportAccountHDCaseSummary(Model):
no+=1
types=[]
total_qty=0
for name, vals in ptypes.items():
for name in sorted(ptypes.keys()):
vals=ptypes[name]
qty=vals['qty'] or 0
total_qty+=qty
color=vals['color'] or "default"
@ -300,20 +333,21 @@ class ReportAccountHDCaseSummary(Model):
'date': date,
'date_from': date_from,
'date_to': date_to,
'lines': slines,
'total_fee': total_fee,
'total_srv': total_srv,
'total_epo': total_epo,
'total_mdc': total_mdc,
'total_lab': total_lab,
'total_misc': total_misc,
'total_dlz': total_dlz,
'total_qty': total_qty,
'lines': sorted(slines, key=lambda a: (a.get('ptype',''), a.get('epo_name',''), a.get('pname',''))),
'total_fee': total_fee and '{:,}'.format(total_fee) or "",
'total_srv': total_srv and '{:,}'.format(total_srv) or "",
'total_epo': total_epo and '{:,}'.format(total_epo) or "",
'total_mdc': total_mdc and '{:,}'.format(total_mdc) or "",
'total_lab': total_lab and '{:,}'.format(total_lab) or "",
'total_misc': total_misc and '{:,}'.format(total_misc) or "",
'total_dlz': total_dlz and '{:,}'.format(total_dlz) or "",
'total_qty': total_qty and '{:,}'.format(total_qty) or "",
'types': types,
'reimbursable': reimbursable,
'is_reim': reimbursable=='yes' and True or False,
'ptype_id': ptype_id,
}
if not reimbursable:
data['title']=''
elif reimbursable=='yes':
@ -329,13 +363,16 @@ class ReportAccountHDCaseSummary(Model):
hdcase=get_model("clinic.hd.case").browse(hdcase_id)
for line2 in hdcase.lines:
prod=line2.product_id
if not prod:
print("missing product hdcase.line.id: ", line2.id)
continue
categ=line2.product_categ_id
if categ.code=='EPO':
categs.setdefault(prod.description, 0)
categs[prod.description]+=line2.qty or 0
data['categ_lines']=[]
for categ, qty in categs.items():
for categ in sorted(categs.keys()):
qty=categs[categ]
data['categ_lines'].append({
'name': categ,
'qty': qty,
@ -363,4 +400,4 @@ class ReportAccountHDCaseSummary(Model):
data['date_to']=data['date_from']
return data
ReportAccountHDCaseSummary.register()
ReportHDCaseExpenseSummary.register()

View File

@ -0,0 +1,274 @@
import time
import urllib.parse as urllib
from datetime import datetime
from calendar import monthrange
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company, get_active_user
from . import utils
class ReportHDCaseSummary(Model):
_name="report.hdcase.summary"
_string="Report HDCase Summary"
_transient=True
_fields={
"date": fields.Date("Month", required=True),
"date_from": fields.Date("From", required=True),
"date_to": fields.Date("To", required=True),
'branch_id': fields.Many2One("clinic.branch","Branch"),
'department_id': fields.Many2One("clinic.department","Departments"),
'hdcase_type': fields.Selection([['completed','Completed'],['not_completed','Not Completed']],"HDCase Type"),
}
def _get_date_from(self,context={}):
year,month=time.strftime("%Y-%m").split("-")
return '%s-%s-01'%(year,month)
def _get_date_to(self,context={}):
year,month,day=time.strftime("%Y-%m-%d").split("-")
weekday, total_day=monthrange(int(year), int(month))
return "%s-%s-%s"%(year,month,total_day)
def _get_branch(self,context={}):
res=get_model('select.company').get_select()
if res:
return res['branch_id']
def _get_department(self,context={}):
res=get_model('select.company').get_select()
if res:
if res.get("department_ids"):
return res['department_ids'][0]
else:
return res['department_id']
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"),
'date_from': _get_date_from,
'date_to': _get_date_to,
'branch_id': _get_branch,
'department_id': _get_department,
'hdcase_type': 'completed',
}
def get_report_data(self,ids,context={}):
company_id=get_active_company()
company=get_model("company").browse(company_id)
date=datetime.now().strftime("%Y-%m-%d")
year=int(date[0:4])
crr_month=int(date[5:7])
weekday, crr_total_day=monthrange(year, crr_month)
defaults=self.default_get(context=context)
date_from=defaults.get('date_from',date)
date_to=defaults.get('date_to',date)
branch_id=defaults.get("branch_id",None)
department_id=defaults.get("department_id",None)
hdcase_type=defaults.get('hdcase_type','completed')
#TODO get data from clinic.patient.move
#DO SOME STAFF
data={}
year=year+543
sub_name=''
if department_id:
department_id=department_id[0]
if branch_id:
branch_id=branch_id[0]
if ids:
obj=self.browse(ids)[0]
branch_id=obj.branch_id.id
department_id=obj.department_id.id
date=obj.date
crr_month=int(date[5:7]) #XXX
year=int(date[0:4])
date_from=obj.date_from
date_to=obj.date_to
hdcase_type=obj.hdcase_type or 'completed'
prev_year=year
next_year=year
prev_month=crr_month-1
next_month=crr_month+1
if crr_month==1:
prev_month=12
prev_year-=1
if crr_month==12:
next_month=1
next_year+=1
month_str=utils.MONTHS['th_TH'][crr_month]
next_month_str=utils.MONTHS['th_TH'][next_month]
prev_month_str=utils.MONTHS['th_TH'][prev_month]
def rzero(n):
if not n:
return '0'
n="{0:,.0f}".format(n)
return n
def set_default(dom=[],topic='topic1'):
dom_txt=''
for f,op,v in dom:
if 'in' in op:
continue
dom_txt+='defaults.%s%s%s&'%(f,op,v)
if date:
dom_txt+='&defaults.date=%s'%date
if date_from:
dom_txt+='&defaults.date_from=%s'%date_from
if date_to:
dom_txt+='&defaults.date_to=%s'%date_to
if topic:
dom_txt+='&defaults.report_type=%s'%topic
if hdcase_type:
dom_txt+='&defaults.hdcase_type=%s'%hdcase_type
return dom_txt
def set_ctx(dom=[],topic='topic1'):
ctx={'defaults': {}}
ctx['defaults'].update({
'report_type': topic,
'hdcase_type': hdcase_type,
'date': date,
'date_from': date_from,
'date_to': date_to,
})
for f,op,v in dom:
if 'in' in op: #XXX
continue
ctx['defaults'].update({
f: v,
})
return ctx
dom=[]
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
topics=utils.TOPICS
count=6
number=[1,2,3,4,5]
for ptype in get_model("clinic.patient.type").search_browse([[]]):
topic='topic%s'%count
topics.update({
topic:{
'name': ptype.name,
'unit': 'คน',
'ptype_id': ptype.id,
}
})
number.append(count)
count+=1
month_val=''
items={}
for index in number:
if index==2:
weekday, prev_total_day=monthrange(prev_year, prev_month)
month_val=prev_month_str
elif index==5:
month_val=next_month_str
else:
month_val=month_str
topic="topic%s"%(str(index))
if 'ptype_id' in topics[topic]:
dom2=dom+[['patient_type_id','=',topics[topic]['ptype_id']]]
dom_txt=set_default(dom2,topic)
ctx=set_ctx(dom2,topic)
qty=get_model("clinic.report.hd.case.detail").get_report_data(ids=[],context=ctx)['total']
else:
dom_txt=set_default(dom,topic)
ctx=set_ctx(dom,topic)
qty=get_model("clinic.report.hd.case.detail").get_report_data(ids=[],context=ctx)['total']
item_vals={
"topic": topics[topic]['name'],
"unit": topics[topic]['unit'],
"month": month_val if index<=5 else "",
"qty": rzero(qty),
"action": 'clinic_patient' if index==5 else "",
"link": "clinic_report_hd_case_detail&%s"%dom_txt,
}
if hdcase_type!="completed" and index==1:
item_vals['link']='clinic_report_hd_case_detail&%s'%dom_txt
items[topic]=item_vals
lines=[]
items_vals=sorted(items, key=lambda s: int(s[5:]))
for item in items_vals:
line=items[item]
lines.append(line)
if hdcase_type=='not_completed':
lines[0]['topic']='%s (ไม่สำเร็จ)'%lines[0]['topic']
context['defaults']={
'date': date,
'date_from': date_from,
'date_to': date_to,
'branch_id': branch_id,
'department_id': department_id,
'hdcase_type': hdcase_type,
}
medicals=get_model("clinic.report.medical.summary").get_report_data(ids=[],context=context)
if department_id:
dpt=get_model("clinic.department").browse(department_id)
sub_name="(%s)" % dpt.name or ""
if branch_id:
branch=get_model("clinic.branch").browse(branch_id)
sub_name="(%s)" % branch.name or ""
medical_lines=medicals['lines']
medical_titles=medicals['titles']
plines=medicals['plines']
prod_titles=medicals['prod_titles']
date_print=time.strftime("%m/%d/%Y %H:%M:%S")
user=get_model('base.user').browse(get_active_user())
data={
'user_name': user.name,
'hdcase_type': hdcase_type,
'branch_id': branch_id,
'department_id': department_id,
'date_from': date_from,
'date_to': date_to,
'date': date,
'date_print': date_print,
'month': month_str,
'year': year,
'lines': lines,
'recent_patients': get_model("clinic.report.recent.patient").get_report_data(ids=[],context=context)['lines'],
'resign_patients': get_model("clinic.report.discontinue.patient").get_report_data(ids=[],context=context)['lines'],
'medicals': medical_lines,
'titles': medical_titles,
'plines': plines,
'prod_titles': prod_titles,
'company_name': '%s %s'% (company.name or "", sub_name),
'parent_company_name': company.parent_id.name or "",
}
return data
def onchange_date(self,context={}):
data=context['data']
date=data['date']
year,month,day=date.split("-")
weekday, total_day=monthrange(int(year), int(month))
data['date_from']="%s-%s-01"%(year,month)
data['date_to']="%s-%s-%s"%(year,month,total_day)
return data
def onchange_branch(self,context={}):
data=context['data']
data['department_id']=None
return data
def run_report(self,ids,context={}):
return {
'next': {
'name': 'clinic_print_hd_case_summary',
'refer_id': ids[0],
'action_options': 'convert=pdf',
}
}
def export_pdf(self,ids,context={}):
raise Exception("TODO")
return
ReportHDCaseSummary.register()

View File

@ -50,6 +50,14 @@ class ReportLaborCost(Model):
date_from=line.date_start
date_to=line.date_stop
break
if defaults.get('report_type_wizard'):
date_from=defaults.get('date_from')
date_to=defaults.get('date_to')
if defaults.get('period_id') != 'None':
per = get_model('clinic.period.line').browse(int(defaults.get('period_id')))
period_id=per.id
date_from=per.date_start
date_to=per.date_stop
res={
'period_id': period_id,
'date': time.strftime("%Y-%m-%d"),
@ -404,7 +412,7 @@ class ReportLaborCost(Model):
if key=='name':
vals['desc']=True
for line in lines:
vals[no]=con2float(line[key])
vals['l%s'%(no)]=con2float(line[key])
no+=1
lines2.append(vals)
return lines2

View File

@ -56,7 +56,7 @@ class ReportLaborCostDetail(Model):
if not branch_id and department_id:
dpt=get_model('clinic.department').browse(department_id)
branch_id=dpt.branch_id.id
print('defaults ', defaults)
#print('defaults ', defaults)
res={
'date': time.strftime("%Y-%m-%d"),
'date_from': date_from,
@ -68,7 +68,7 @@ class ReportLaborCostDetail(Model):
'cycle_id': cycle_id or None,
'categ_id': categ_id or None,
}
print('res ', res)
#print('res ', res)
return res
def get_report_data(self,ids,context={}):
@ -279,12 +279,12 @@ class ReportLaborCostDetail(Model):
'dpt_lines': dpt_lines,
'show_all': show_count <=1 and True or False,
}
data['dpts_txt']=[{0: '#', 1: 'วันที่'}]
data['dpts_txt']=[{'l0': '#', 'l1': 'วันที่'}]
vals={}
no=0
dpt_len=len(data['dpts_txt'][0])
for dpt in dpts:
data['dpts_txt'][0][no+dpt_len]=dpt['name']
data['dpts_txt'][0]['l%s'% (no+dpt_len)]=dpt['name']
vals[no]=0
no+=1
count=1

View File

@ -57,7 +57,7 @@ class ReportLaborCostSubDetail(Model):
'department_id': department_id,
'branch_id': branch_id,
}
print('res ', res)
#print('res ', res)
return res
def get_report_data(self,ids,context={}):
@ -93,7 +93,7 @@ class ReportLaborCostSubDetail(Model):
if staff_id and staff_type=='doctor':
dom.append(['staff_id','=',staff_id])
elif staff_id and staff_type=='nurse':
pass
dom.append(['staff_id','=',staff_id])
if staff_type:
dom.append(['type','=',staff_type])
if department_id:
@ -115,25 +115,35 @@ class ReportLaborCostSubDetail(Model):
qty=line.qty or 0
if qty:
amount=amount/qty
for hdcase in citem.hd_cases:
if hdcase.state not in ("waiting_payment","paid"):
continue
patient=hdcase.patient_id
doctor=hdcase.doctor_id
if staff_type=='nurse':
vals={
'date': date,
'patient_name': patient.name or "",
'patient_name': line.staff_id.name or "",
'department_name': dpt.name or "",
'amount': amount,
}
if staff_type=='doctor' and doctor.id==staff_id:
lines.append(vals)
amount_total+=amount
elif staff_type=='nurse':
lines.append(vals)
amount_total+=amount
else:
pass
lines.append(vals)
amount_total+=amount
if staff_type=='doctor':
for hdcase in citem.hd_cases:
if hdcase.state not in ("waiting_payment","paid"):
continue
patient=hdcase.patient_id
doctor=hdcase.doctor_id
vals={
'date': date,
'patient_name': patient.name or "",
'department_name': dpt.name or "",
'amount': amount,
}
if staff_type=='doctor' and doctor.id==staff_id:
lines.append(vals)
amount_total+=amount
elif staff_type=='nurse':
lines.append(vals)
amount_total+=amount
else:
pass
slines=[]
no=1
for line in sorted(lines,key=lambda x: (x['date'], x['department_name'])):

View File

@ -69,7 +69,7 @@ class ReportLaborCostSummary(Model):
'level_id': level_id or None,
'cycle_id': cycle_id or None,
}
print('res ', res)
#print('res ', res)
return res
def get_report_data(self,ids,context={}):
@ -295,7 +295,7 @@ class ReportLaborCostSummary(Model):
no=0
dpt_len=len(data['dpts_txt'][0])
for dpt in dpts:
data['dpts_txt'][0][no+dpt_len]=dpt['name']
data['dpts_txt'][0]['l%s'%(no+dpt_len)]=dpt['name']
vals[no]=0
no+=1
count=1

View File

@ -2,7 +2,7 @@ import time
from calendar import monthrange
from netforce.model import Model,fields,get_model
from netforce.access import get_active_company, get_active_user
from netforce.access import get_active_company, get_active_user, set_active_user
from . import utils
@ -51,6 +51,73 @@ class ReportRecentPatient(Model):
return res
def get_report_data(self,ids,context={}):
company_id=get_active_company()
company=get_model('company').browse(company_id)
year, month=time.strftime("%Y-%m").split("-")
weekday, total_day=monthrange(int(year), int(month))
defaults=self.default_get(context=context)
time_start=defaults.get("date_from")
time_stop=defaults.get("date_to")
branch_id=defaults.get("branch_id")
department_id=defaults.get("department_id")
if ids:
obj=self.browse(ids)[0]
month=obj.date_from.split("-")[1]
time_start=obj.date_from
time_stop=obj.date_to
branch_id=obj.branch_id.id
department_id=obj.department_id.id
# new patient of this month
dom=[]
dom.append(['date','>=',"%s 00:00:00"%(time_start)])
dom.append(['date','<=',"%s 23:59:59"%(time_stop)])
dom.append(['type','=',"in"])
records=get_model('clinic.patient.move').search_browse(dom)
lines=[]
no=1
user_id=get_active_user()
set_active_user(1)
for record in records:
if record.patient_id.branch_id.id!=branch_id:
continue
if record.patient_id.department_id.id!=department_id:
continue
if record.patient_id.walkin!='no':
continue
lines.append({
'no': no,
'name': record.patient_name or '',
'pid': record.id,
'note': record.patient_id.note or '',
'reg_date': record.date[:10],
})
no+=1
set_active_user(user_id)
month_str=utils.MONTHS['th_TH'][int(month)]
start=int(time_start[8:10])
stop=int(time_stop[8:10])
diff=stop-start
sub_name=''
if department_id:
dpt=get_model("clinic.department").browse(department_id)
sub_name="(%s)" % dpt.name or ""
elif branch_id:
branch=get_model("clinic.branch").browse(branch_id)
sub_name="(%s)" % branch.name or ""
data={
'company_name': '%s %s'%(company.name or "", sub_name),
'parent_company_name': company.parent_id.name or "",
'lines': lines,
'month': month_str,
'from': time_start,
'to': time_stop,
'is_duration': diff+1 < total_day,
'year': year,
}
return data
def get_report_data_bak(self,ids,context={}):
company_id=get_active_company()
company=get_model('company').browse(company_id)
year, month=time.strftime("%Y-%m").split("-")

View File

@ -0,0 +1,477 @@
import time
from datetime import datetime
from calendar import monthrange
from netforce.model import Model,fields,get_model
from netforce.access import get_active_company, set_active_company, get_active_user, set_active_user
from netforce.database import get_connection
class ReportLaborCost(Model):
_name="clinic.report.wizard.labor.cost"
_string="Report Wizard Labor Cost"
_transient=True
_fields={
"date": fields.Date("Month"),
"period_id": fields.Many2One("clinic.period.line","Period"),
"date_from": fields.Date("From", required=True),
"date_to": fields.Date("To", required=True),
"branch_id": fields.Many2One("clinic.branch","Branch", required=False),
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
"department_id": fields.Many2One("clinic.department","Department", required=False),
"staff_type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
"staff_id": fields.Many2One("clinic.staff","Staff")
}
def _get_date_from(self,context={}):
year,month,day=time.strftime("%Y-%m-%d").split("-")
#return '%s-%s-01'%(year,month)
return '%s-%s-%s'%(year,month,day)
def _get_date_to(self,context={}):
year,month,day=time.strftime("%Y-%m-%d").split("-")
weekday, total_day=monthrange(int(year), int(month))
#return "%s-%s-%s"%(year,month,total_day)
return "%s-%s-%s"%(year,month,day)
def default_get(self,field_names=None,context={},**kw):
defaults=context.get("defaults",{})
date_from=defaults.get("date_from", self._get_date_from())
date_to=defaults.get("date_to", self._get_date_to())
print('defaults ', defaults)
yearnow=date_from.split("-")[0]
period_id=None
for period in get_model('clinic.period').search_browse([[]]):
for line in period.lines:
if line.state=='open':
period_id=line.id
date_from=line.date_start
date_to=line.date_stop
break
res={
'period_id': period_id,
'date': time.strftime("%Y-%m-%d"),
'date_from': date_from,
'date_to': date_to,
}
return res
def wizard_report_summary(self,ids,context={}):
obj=self.browse(ids)[0]
return {
"next": {
"type": "report_odt2",
"model": self._name,
"template": "report_wizard_labor_cost_summary",
"refer_id": obj.id,
"method": "get_report_wizard_summary",
"convert": "pdf",
}
}
def wizard_report_details(self,ids,context={}):
obj=self.browse(ids)[0]
return {
"next": {
"type": "report_odt2",
"model": self._name,
"template": "report_wizard_labor_cost_details",
"refer_id": obj.id,
"method": "get_report_wizard_details",
"convert": "pdf",
}
}
def wizard_report_sub_details(self,ids,context={}):
obj=self.browse(ids)[0]
return {
"next": {
"type": "report_odt",
"model": self._name,
"template": "report_wizard_labor_cost_sub_details",
"refer_id": obj.id,
"method": "get_report_wizard_sub_details",
"convert": "pdf",
"date_from": obj.date_from,
}
}
def get_report_data(self,ids,context={}):
return
def get_report_wizard_summary(self,ids,context={}):
obj=[]
if ids:
if not context.get('type_report'):
obj = self.browse(ids)[0]
date = obj.date
period_id = obj.period_id.id
date_from = obj.date_from
date_to = obj.date_to
cycle_id = obj.cycle_id.id or None
staff_id = obj.staff_id.id or None
staff_type = obj.staff_type or None
branch_id = obj.branch_id.id or None
department_id = obj.department_id.id or None
else:
date=context.get('date')
period_id=context.get('period_id')
date_from=context.get('date_from')
date_to=context.get('date_to')
if context.get('staff_type')=='None':
staff_type=None
else:
staff_type=context.get('staff_type')
if context.get('staff_id')=='None':
staff_id=None
else:
staff_id=context.get('staff_id')
if context.get('cycle_id')=='None':
cycle_id=None
else:
cycle_id=context.get('cycle_id')
if context.get('branch_id')=='None':
branch_id=None
else:
branch_id=context.get('branch_id')
if context.get('department_id')=='None':
department_id=None
else:
department_id=context.get('department_id')
if context.get('user')=='admin':
user_id=get_active_user()
set_active_user(1)
company_id=get_active_company()
if not company_id:
set_active_company(1)
company_id=1
company=get_model("company").browse(company_id)
pages1=[]
pages2=[]
t1=datetime.now()
lc_vals={
'date': date_from,
'period_id': period_id,
'date_from': date_from,
'date_to': date_to,
'cycle_id': cycle_id or None,
'branch_id': branch_id or None,
'report_type': 'cross',
'department_id': department_id or None,
'report_type_wizard':'t',
}
lc_id=get_model('clinic.report.labor.cost').create({},context={'defaults':lc_vals,})
lc_data=get_model('clinic.report.labor.cost').get_report_data([lc_id])
#data['lc_data'].append(lc_data) # END STEP 1
data={
"comp_name":company.name,
"date_from_1": date_from,
"date_to_1": date_to,
"dlines2": lc_data['dlines2'] or None,
"nlines2": lc_data['nlines2'] or None,
"ctlines2": lc_data['ctlines2'] or None,
}
pages1.append(data)
t2=datetime.now()
print('step 1 : ',t2-t1)
#STEP 2
staff_data=[]
if staff_type:
staff_data.append(staff_type)
else:
staff_data=['doctor','nurse']
for s_line in staff_data:
s_vals={
'date': date_from,
'date_from': date_from,
'date_to': date_to,
'staff_type': staff_type or s_line,
'staff_id': staff_id or None,
'cycle_id': cycle_id or None,
'branch_id': branch_id or None,
'department_id': department_id or None,
}
sum_id=get_model('clinic.report.labor.cost.summary').create({},context={
'defaults':s_vals,
})
sum_data=get_model('clinic.report.labor.cost.summary').get_report_data([sum_id])
if s_line=='doctor':
sum_data.update({'staff_name':'ตารางหมอ'})
elif s_line=='nurse':
sum_data.update({'staff_name':'ตารางพยาบาล'})
data={
"comp_name":company.name,
"date_from_1": date_from,
"date_to_1": date_to,
"emp_type": sum_data['staff_type'] or None,
"dpts_txt": sum_data['dpts_txt'] or None,
"items": sum_data['items'] or None,
"total_lines_txt": sum_data['total_lines_txt'] or None,
}
pages2.append(data)
t2=datetime.now()
if context.get('user')=='admin':
set_active_user(user_id)
if pages1 and pages2:
pages1[-1]['is_last_page']=True
pages2[-1]['is_last_page']=True
return {
"pages1": pages1,
"pages2": pages2,
}
def get_report_wizard_details(self,ids,context={}):
obj=[]
if ids:
if not context.get('type_report'):
obj = self.browse(ids)[0]
date = obj.date
period_id = obj.period_id.id
date_from = obj.date_from
date_to = obj.date_to
cycle_id = obj.cycle_id.id or None
staff_id = obj.staff_id.id or None
staff_type = obj.staff_type or None
branch_id = obj.branch_id.id or None
department_id = obj.department_id.id or None
else:
date=context.get('date')
period_id=context.get('period_id')
date_from=context.get('date_from')
date_to=context.get('date_to')
if context.get('staff_type')=='None':
staff_type=None
else:
staff_type=context.get('staff_type')
if context.get('staff_id')=='None':
staff_id=None
else:
staff_id=context.get('staff_id')
if context.get('cycle_id')=='None':
cycle_id=None
else:
cycle_id=context.get('cycle_id')
if context.get('branch_id')=='None':
branch_id=None
else:
branch_id=context.get('branch_id')
if context.get('department_id')=='None':
department_id=None
else:
department_id=context.get('department_id')
if context.get('user')=='admin':
user_id=get_active_user()
set_active_user(1)
company_id=get_active_company()
if not company_id:
set_active_company(1)
company_id=1
company=get_model("company").browse(company_id)
pages=[]
t1=datetime.now()
#STEP 2
i=0
staff_data=[]
if staff_type:
staff_data.append(staff_type)
else:
staff_data=['doctor','nurse']
for s_line in staff_data:
sum_id=get_model('clinic.report.labor.cost.summary').create({
'date': date_from,
'date_from': date_from,
'date_to': date_to,
'staff_type': staff_type or s_line,
'staff_id': staff_id or None,
'cycle_id': cycle_id or None,
'branch_id': branch_id or None,
'department_id': department_id or None,
})
sum_data=get_model('clinic.report.labor.cost.summary').get_report_data([sum_id])
t2=datetime.now()
#STEP 3
for detail_line in sum_data['lines']:
detail_id=get_model('clinic.report.labor.cost.detail').create({
'date': date_from,
'date_from': date_from,
'date_to': date_to,
'staff_type': detail_line['staff_type'] or None,
'staff_id': detail_line['staff_id'] or None,
'cycle_id': None,
'branch_id': branch_id or None,
'department_id': department_id or None,
})
detail_data=get_model('clinic.report.labor.cost.detail').get_report_data([detail_id])
data={
"date_from_1": date_from,
"date_to_1": date_to,
"emp_type": detail_line['staff_type'] or None,
"emp_name": detail_line['staff_name'] or None,
"detail_dpts_txt": detail_data['dpts_txt'] or None,
"detail_items": detail_data['items'] or None,
"detail_total_lines_txt": detail_data['total_lines_txt'] or None,
}
pages.append(data)
t2=datetime.now()
i=i+1
print('step 3 : ',t2-t1,' item in %d and name %s >>>>>>>> %s'%(i,detail_line['staff_name'],detail_line['staff_type']))
if pages:
pages[-1]['is_last_page']=True
if context.get('user')=='admin':
set_active_user(user_id)
if not company_id:
set_active_company(company_id)
return {
"pages": pages,
}
def get_report_wizard_sub_details(self,ids,context={}):
obj=[]
if ids:
if not context.get('type_report'):
obj = self.browse(ids)[0]
date = obj.date
period_id = obj.period_id.id
date_from = obj.date_from
date_to = obj.date_to
cycle_id = obj.cycle_id.id or None
staff_id = obj.staff_id.id or None
staff_type = obj.staff_type or None
branch_id = obj.branch_id.id or None
department_id = obj.department_id.id or None
else:
date=context.get('date')
period_id=context.get('period_id')
date_from=context.get('date_from')
date_to=context.get('date_to')
if context.get('staff_type')=='None':
staff_type=None
else:
staff_type=context.get('staff_type')
if context.get('staff_id')=='None':
staff_id=None
else:
staff_id=context.get('staff_id')
if context.get('cycle_id')=='None':
cycle_id=None
else:
cycle_id=context.get('cycle_id')
if context.get('branch_id')=='None':
branch_id=None
else:
branch_id=context.get('branch_id')
if context.get('department_id')=='None':
department_id=None
else:
department_id=context.get('department_id')
if context.get('user')=='admin':
user_id=get_active_user()
set_active_user(1)
company_id=get_active_company()
if not company_id:
set_active_company(1)
company_id=1
company=get_model("company").browse(company_id)
pages=[]
t1=datetime.now()
staff_data=[]
if staff_type:
staff_data.append(staff_type)
else:
staff_data=['doctor']
for s_line in staff_data:
ctx_sum={
'date': date_from,
'date_from': date_from,
'date_to': date_to,
'staff_type': staff_type or s_line,
'staff_id': None,
'cycle_id': None,
'branch_id': None,
'department_id': None,
}
sum_id=get_model('clinic.report.labor.cost.summary').create({
'date': date_from,
'date_from': date_from,
'date_to': date_to,
'staff_type': staff_type or s_line,
'staff_id': staff_id or None,
'cycle_id': cycle_id or None,
'branch_id': branch_id or None,
'department_id': department_id or None,
}, context=ctx_sum)
sum_data=get_model('clinic.report.labor.cost.summary').get_report_data([sum_id])
t2=datetime.now()
for line in sum_data['lines']:
ctx={
'defaults': {
'date': date_from,
'date_from': date_from,
'date_to': date_to,
'staff_type': line['staff_type'] or None,
'staff_id': line['staff_id'] or None,
'branch_id': branch_id or None,
'department_id': department_id or None,
}
}
sub_detail_id=get_model('clinic.report.labor.cost.sub.detail').create({},context=ctx)
sub_data=get_model('clinic.report.labor.cost.sub.detail').get_report_data([sub_detail_id])
data={
"date_from_1": date_from,
"date_to_1": date_to,
"emp_name": line['staff_name'] or None,
"emp_type": line['staff_type'] or None,
"lines": sub_data['lines'] or None,
"amount_total": line['total'] or None,
}
print('Get Data : Name : %s, Type : %s, Total : %s'%(line['staff_name'],line['staff_type'],line['total']))
pages.append(data)
t2=datetime.now
if pages:
pages[-1]['is_last_page']=True
if context.get('user')=='admin':
set_active_user(user_id)
if not company_id:
set_active_company(company_id)
return {
"pages":pages,
}
def onchange_date(self,context={}):
data=context['data']
date=data['date']
year,month,day=date.split("-")
weekday, total_day=monthrange(int(year), int(month))
data['date_from']="%s-%s-01"%(year,month)
data['date_to']="%s-%s-%s"%(year,month,total_day)
return data
def onchange_branch(self,context={}):
data=context['data']
data['department_id']=None
return data
def onchange_from(self,context={}):
data=context['data']
data['date_to']=data['date_from']
return data
def onchange_period(self,context={}):
data=context['data']
period_id=data['period_id']
period=get_model('clinic.period.line').browse(period_id)
data['date_from']=period.date_start
data['date_to']=period.date_stop
return data
def onchange_type(self,context={}):
data=context['data']
data['staff_id']=None
return data
ReportLaborCost.register()

View File

@ -58,6 +58,7 @@ class ClinicSetting(Model):
"cash_account_id": fields.Many2One("account.account","Cash Account",multi_company=True),
"income_account_id": fields.Many2One("account.account","Income Account",multi_company=True),
"import_account_id": fields.Many2One("account.account","Import Account",multi_company=True),
"hdcase_payment_account_id": fields.Many2One("account.account","HDCase Payment Account",multi_company=True),
'helper_categ_id': fields.Many2One("clinic.staff.categ","Helper Category"),
'base_salary_day': fields.Float("Base Salary Day"),
'next_date': fields.DateTime("Next Gen"),

View File

@ -1,3 +1,4 @@
from netforce.database import get_connection
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company, get_active_user, set_active_user
@ -5,37 +6,35 @@ class SickBed(Model):
_name="clinic.sickbed"
_string="Sickbed"
_key=['name','department_id','branch_id']
def _get_all(self,ids,context={}):
res={}
vals={}
db=get_connection()
for obj in self.browse(ids):
hd_case=None
#image=None
patient_id=None
image=None
date=''
set_active_user(1) #FIXME permission denined because of department of patient
if obj.hd_cases:
hd_case=sorted(obj.hd_cases, key=lambda a: a.id)[-1]
patient=hd_case.patient_id
patient_id=patient.id
image=patient.image
date=hd_case.date
res[obj.id]={
date=None
res=db.query("select id,patient_id,date from clinic_hd_case where sickbed_id=%s order by id desc limit 1"%(obj.id))
if res:
hdcase=res[0]
patient_id=hdcase['patient_id']
date=hdcase['date']
vals[obj.id]={
'patient_id': patient_id,
'image': image,
'date': date,
#'image': image,
}
set_active_user(get_active_user())
return res
return vals
_fields={
"name": fields.Char("Name",required=True,search=True),
"available": fields.Boolean("Available"),
'hd_cases': fields.One2Many("clinic.hd.case",'sickbed_id','HDCases'),
'company_id': fields.Many2One("company","Company"),
'patient_id': fields.Many2One("clinic.patient","Lasted Patient",function="_get_all",function_multi=True,domain=[['state','=','admit']]),
'image': fields.File("Image",function="_get_all",function_multi=True),
'date': fields.Date("Lasted Date",function="_get_all",function_multi=True),
'patient_id': fields.Many2One("clinic.patient","Lasted Patient",function="_get_all",function_multi=True, store=True, domain=[['state','=','admit']]),
'date': fields.Date("Lasted Date",function="_get_all",function_multi=True, store=True,),
#'image': fields.File("Image",function="_get_all",function_multi=True),
"state": fields.Selection([("available","Available"),("not_available","Not Available")],"Status"),
'sequence': fields.Integer("Sequence"),
'note': fields.Text("Note"),
@ -43,7 +42,7 @@ class SickBed(Model):
'department_id': fields.Many2One("clinic.department","Department",required=True, search=True),
'active': fields.Boolean("Active"),
}
def _get_branch(self,context={}):
user_id=get_active_user()
staffs=get_model("clinic.staff").search_browse([['user_id','=',user_id]])
@ -62,7 +61,7 @@ class SickBed(Model):
'branch_id': _get_branch,
'active': True,
}
_order="branch_id,department_id,sequence,name"
def copy(self,ids,context={}):
@ -78,7 +77,7 @@ class SickBed(Model):
},
'flash': 'Copy succesfully',
}
def write(self,ids,vals,**kw):
if 'available' in vals.keys():
if vals['available']:
@ -86,5 +85,11 @@ class SickBed(Model):
else:
vals['state']='not_available'
super().write(ids,vals,**kw)
self.function_store(ids)
def create(self, vals, context={}):
new_id=super().create(vals,context)
self.function_store([new_id])
return new_id
SickBed.register()

View File

@ -26,9 +26,12 @@ class Visit(Model):
for obj in self.browse(ids):
cycle=obj.cycle_id
color=cycle.color
patient=obj.patient_id
res[obj.id]={
'cycle_color': color,
'sequence': '%s-%s'%(obj.time_start[0:10],cycle.sequence), #date-sequence
'patient_name': patient.name,
'patient_type_id': patient.type_id.id,
}
return res
@ -54,6 +57,8 @@ class Visit(Model):
'note': fields.Text('Note'),
'branch_id': fields.Many2One("clinic.branch","Branch"),
'manual': fields.Boolean("Manual Tempolary Visit"),
"patient_name": fields.Char("Patient Name", function="_get_all", function_multi=True, store=True, search=True),
"patient_type_id": fields.Char("Patient Type", function="_get_all", function_multi=True, store=True, search=True),
}
def _get_number(self,context={}):

View File

@ -400,6 +400,7 @@ class VisitBoard(Model):
'date_from': utils.date2thai(date_from,format='%(d)s %(Tm)s %(By)s',lang="th_TH2"),
'date_to': utils.date2thai(date_to,format='%(d)s %(Tm)s %(By)s',lang="th_TH2"),
}
# TODO Delete the data if duplicate (date, patient, deparment)
return data
def onchange_date(self,context={}):

View File

@ -1,4 +1,4 @@
{{#view "page" title="Clinic Board"}}
{{#view "page" title="Nurse Board"}}
<div class="row">
<div class="col-sm-6">
<div class="nf-board-title">

View File

@ -0,0 +1,73 @@
{{#view "page" title="Ratchawat Board"}}
<div class="row">
<div class="col-sm-6">
<div class="nf-board-title">
<h3>{{t "Accounting"}}</h3>
</div>
<div style="margin-bottom:20px">
<div>
<a href="#name=report_hdcase_expense_summary">{{t "HDCase Expense Summary"}}</a>
</div>
<div>
<a href="#name=clinic_report_account_shop">{{t "RD Shop Expense"}}</a>
</div>
</div>
<div class="nf-board-title">
<h3>{{t "Matching"}}</h3>
</div>
<div style="margin-bottom:20px">
<div>
<a href="#name=clinic_payment_matching">{{t "Payment Matching"}}</a>
</div>
<div>
<a href="#name=clinic_matching_hdcase_acc">{{t "HD Cases Matching"}}</a>
</div>
</div>
<div class="nf-board-title">
<h3>{{t "Settings"}}</h3>
</div>
<div style="margin-bottom:20px">
<div>
<a href="#name=clinic_account_setting">{{t "Ratchawat Settings"}}</a>
</div>
<div>
<a href="#name=clinic_labor_cost">{{t "Labor Costs"}}</a>
</div>
<div>
<a href="#name=clinic_period">{{t "Pay Period"}}</a>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="nf-board-title">
<h3>{{t "Doctor/Nurse Cost"}}</h3>
</div>
<div style="margin-bottom:20px">
<div>
<a href="#name=clinic_report_labor_cost">{{t "Labor Costs"}}</a>
</div>
<div>
<a href="#name=clinic_report_labor_cost_summary">{{t "Labor Cost Summary"}}</a>
</div>
<div>
<a href="#name=clinic_report_labor_cost_detail">{{t "Labor Cost Detail"}}</a>
</div>
<div>
<a href="#name=clinic_report_labor_cost_sub_detail">{{t "Labor Cost Sub Detail"}}</a>
</div>
<div>
<a href="#name=clinic_report_labor_cost_daily">{{t "Labor Cost Daily"}}</a>
</div>
<div>
<a href="#name=clinic_report_labor_cost_overtime">{{t "Labor Cost Overtime"}}</a>
</div>
<div>
<a href="#name=clinic_compute_labor_cost">{{t "Recompute Cost"}}</a>
</div>
<div>
<a href="#name=clinic_print_wizard_labor_cost">{{t "Print All"}}</a>
</div>
</div>
</div>
</div>
{{/view}}

View File

@ -1,3 +1,24 @@
<style>
#myBtn {
display: none;
position: fixed;
bottom: 20px;
right: 30px;
z-index: 99;
border: none;
outline: none;
background-color: red;
color: white;
cursor: pointer;
padding: 15px;
border-radius: 10px;
}
#myBtn:hover {
background-color: #555;
}
</style>
<center>
<h2>
{{title}}
@ -13,9 +34,9 @@
<thead class="scroll-header">
<tr>
{{#ifeq reimbursable "no"}}
<th colspan="16" style="text-align:center">
{{else}}
<th colspan="14" style="text-align:center">
{{else}}
<th colspan="12" style="text-align:center">
{{/ifeq}}
{{#if ptype_id}}
<span >Total: {{total_qty}}</span>
@ -42,7 +63,9 @@
<th style="text-align:right">Misc.</th>
<th style="text-align:right">Dlz</th>
<th>Ref.Inv#</th>
<!--
<th>Picking#</th>
-->
{{else}}
<th>Cycle#</th>
<th>HD Case#</th>
@ -53,7 +76,9 @@
<th style="text-align:right">ค่ายา</th>
<th style="text-align:right">ค่าบริการฉีดยา</th>
<th>Inv#</th>
<!--
<th>Picking#</th>
-->
{{/ifeq}}
</tr>
</thead>
@ -78,21 +103,23 @@
{{/if}}
</td>
<td>{{epo_name}}</td>
<td style="text-align:right">{{currency fee zero=""}}</td>
<td style="text-align:right">{{currency mdc zero=""}}</td>
<td style="text-align:right">{{currency lab zero=""}}</td>
<td style="text-align:right">{{currency misc zero=""}}</td>
<td style="text-align:right">{{currency dlz_price zero=""}}</td>
<td style="text-align:right">{{fee}}</td>
<td style="text-align:right">{{mdc}}</td>
<td style="text-align:right">{{lab}}</td>
<td style="text-align:right">{{misc}}</td>
<td style="text-align:right">{{dlz_price}}</td>
<td>
{{#if inv_id}}
{{view "link" string=inv_ref action="cust_invoice" action_options="form_view_xml&cust_invoice_form&mode=form" active_id=inv_id}}
{{/if}}
</td>
<!--
<td>
{{#if pick_id}}
{{view "link" string=pick_ref action="pick_out" action_options="mode=form" active_id=pick_id}}
{{/if}}
</td>
-->
{{else}}
<td style="width:6%">{{cycle}}</td>
<td style="width:15%">
@ -101,9 +128,9 @@
<td style="width:20%">{{pname}}</td>
<td>{{ptype}}</td>
<td>{{epo_name}}</td>
<td style="text-align:right">{{currency fee zero=""}}</td>
<td style="text-align:right">{{currency mdc zero=""}}</td>
<td style="text-align:right">{{currency srv zero=""}}</td>
<td style="text-align:right">{{fee}}</td>
<td style="text-align:right">{{mdc}}</td>
<td style="text-align:right">{{srv}}</td>
{{#if inv_id}}
<td>
{{view "link" string=inv_number action="cust_invoice" action_options="form_view_xml&cust_invoice_form&mode=form" active_id=inv_id}}
@ -112,6 +139,7 @@
<td>
</td>
{{/if}}
<!--
<td>
{{#if pick_id}}
{{view "link" string=pick_ref action="pick_out" action_options="mode=form" active_id=pick_id}}
@ -119,6 +147,7 @@
-
{{/if}}
</td>
-->
{{/ifeq}}
</tr>
{{/each}}
@ -132,24 +161,42 @@
<th></th>
<th></th>
<th></th>
<th style="text-align:right">{{currency total_fee zero=""}}</th>
<th style="text-align:right">{{currency total_mdc zero=""}}</th>
<th style="text-align:right">{{currency total_lab zero=""}}</th>
<th style="text-align:right">{{currency total_misc zero=""}}</th>
<th style="text-align:right">{{currency total_dlz zero=""}}</th>
<th></th>
<th style="text-align:right">{{total_fee}}</th>
<th style="text-align:right">{{total_mdc}}</th>
<th style="text-align:right">{{total_lab}}</th>
<th style="text-align:right">{{total_misc}}</th>
<th style="text-align:right">{{total_dlz}}</th>
{{else}}
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th style="text-align:right">{{currency total_fee zero=""}}</th>
<th style="text-align:right">{{currency total_mdc zero=""}}</th>
<th style="text-align:right">{{currency total_srv zero=""}}</th>
<th></th>
<th style="text-align:right">{{total_fee}}</th>
<th style="text-align:right">{{total_mdc}}</th>
<th style="text-align:right">{{total_srv}}</th>
<th></th>
{{/ifeq}}
</tfoot>
</table>
<button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
<script>
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
document.getElementById("myBtn").style.display = "block";
} else {
document.getElementById("myBtn").style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
</script>

View File

@ -1,3 +1,24 @@
<style>
#myBtn {
display: none;
position: fixed;
bottom: 20px;
right: 30px;
z-index: 99;
border: none;
outline: none;
background-color: red;
color: white;
cursor: pointer;
padding: 15px;
border-radius: 10px;
}
#myBtn:hover {
background-color: #555;
}
</style>
<center>
<h2>
{{title}}
@ -21,9 +42,9 @@
<thead class="scroll-header">
<tr>
{{#ifeq reimbursable "no"}}
<th colspan="16" style="text-align:center">
<th colspan="17" style="text-align:center">
{{else}}
<th colspan="14" style="text-align:center">
<th colspan="15" style="text-align:center">
{{/ifeq}}
{{#if ptype_id}}
<span class="label label-default">Total: {{total_qty}}</span>
@ -53,7 +74,9 @@
<th>Misc.</th>
<th>Dlz</th>
<th>Ref.Inv#</th>
<!--
<th>Picking#</th>
-->
{{else}}
<th>Date</th>
<th>Cycle#</th>
@ -68,7 +91,9 @@
<th>ค่ายา</th>
<th>ค่าบริการฉีดยา</th>
<th>Inv#</th>
<!--
<th>Picking#</th>
-->
<th>แพทย์</th>
<th>พยาบาล</th>
{{/ifeq}}
@ -98,21 +123,23 @@
{{/if}}
</td>
<td>{{epo_name}}</td>
<td>{{currency fee zero=""}}</td>
<td>{{currency mdc zero=""}}</td>
<td>{{currency lab zero=""}}</td>
<td>{{currency misc zero=""}}</td>
<td>{{currency dlz_price zero=""}}</td>
<td>{{fee}}</td>
<td>{{mdc}}</td>
<td>{{lab}}</td>
<td>{{misc}}</td>
<td>{{dlz_price}}</td>
<td>
{{#if inv_id}}
{{view "link" string=inv_ref action="cust_invoice" action_options="form_view_xml&cust_invoice_form&mode=form" active_id=inv_id}}
{{/if}}
</td>
<!--
<td>
{{#if pick_id}}
{{view "link" string=pick_ref action="pick_out" action_options="mode=form" active_id=pick_id}}
{{/if}}
</td>
-->
{{else}}
<td style="width:10%">{{date}}</td>
<td style="width:6%">{{cycle}}</td>
@ -125,9 +152,9 @@
<td>{{ptype}}</td>
<td>{{hct}}</td>
<td>{{epo_name}}</td>
<td>{{currency fee zero=""}}</td>
<td>{{currency mdc zero=""}}</td>
<td>{{currency srv zero=""}}</td>
<td>{{fee}}</td>
<td>{{mdc}}</td>
<td>{{srv}}</td>
{{#if inv_id}}
<td>
{{view "link" string=inv_number action="cust_invoice" action_options="form_view_xml&cust_invoice_form&mode=form" active_id=inv_id}}
@ -136,6 +163,7 @@
<td>
</td>
{{/if}}
<!--
<td>
{{#if pick_id}}
{{view "link" string=pick_ref action="pick_out" action_options="mode=form" active_id=pick_id}}
@ -143,6 +171,7 @@
-
{{/if}}
</td>
-->
<td>{{dname}}</td>
<td>
{{view "link" string="View" action="clinic_cycle_item" action_options="mode=form" active_id=cycle_item_id}}
@ -163,11 +192,12 @@
<th></th>
<th></th>
<th></th>
<th>{{currency total_fee zero=""}}</th>
<th>{{currency total_mdc zero=""}}</th>
<th>{{currency total_lab zero=""}}</th>
<th>{{currency total_misc zero=""}}</th>
<th>{{currency total_dlz zero=""}}</th>
<th>{{total_fee}}</th>
<th>{{total_mdc}}</th>
<th>{{total_lab}}</th>
<th>{{total_misc}}</th>
<th>{{total_dlz}}</th>
<th></th>
<th></th>
{{else}}
<th></th>
@ -179,12 +209,33 @@
<th></th>
<th></th>
<th></th>
<th>{{currency total_fee zero=""}}</th>
<th>{{currency total_mdc zero=""}}</th>
<th>{{currency total_srv zero=""}}</th>
<th>{{total_fee}}</th>
<th>{{total_mdc}}</th>
<th>{{total_srv}}</th>
<th></th>
<th></th>
<th></th>
{{/ifeq}}
</tfoot>
</table>
<button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
<script>
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
document.getElementById("myBtn").style.display = "block";
} else {
document.getElementById("myBtn").style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
</script>

View File

@ -0,0 +1,168 @@
<center>
<h2>
{{title}}
</h2>
<h3>
{{parent_company_name}}&nbsp;{{company_name}}<br/>
</h3>
<h4>
From {{date_from}} To {{date_to}}
</h4>
</center>
<table class="table">
<thead class="scroll-header">
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</thead>
<tbody>
{{#each lines}}
<tr>
<td>{{topic}}</td>
<td>{{month}}</td>
<td>เท่ากับ</td>
{{#ifeq qty '0'}}
<td></td>
{{else}}
<td style="text-align:right;width:5%">
<a href='/ui#name={{link}}' target="_blank">{{qty}}</a>
</td>
{{/ifeq}}
<td style="text-align:center">{{unit}}</td>
</tr>
{{/each}}
</tbody>
</table>
<table class="table">
<thead>
<th>
<center>
<a href="/ui#name=clinic_report_recent_patient&defaults.date={{date}}&defaults.date_from={{date_from}}&defaults.date_to={{date_to}}&defaults.branch_id={{branch_id}}&defaults.department_id={{department_id}}">
รายชื่อผู้ป่วยรับใหม่
</a>
</center>
</th>
<th>
<center>
<a href="/ui#name=clinic_report_discontinue_patient&defaults.date={{date}}&defaults.date_from={{date_from}}&defaults.date_to={{date_to}}&defaults.branch_id={{branch_id}}&defaults.department_id={{department_id}}">
รายชื่อผู้ป่วยจำหน่าย
</a>
</center>
</th>
</thead>
<tr>
<td>
<table class="table">
<thead>
<th>#</th>
<th>วันที่</th>
<th>ชื่อ</th>
</thead>
<tbody>
{{#if recent_patients}}
{{#each recent_patients}}
<tr>
<td>{{no}}</td>
<td>{{reg_date}}</td>
<td>
{{view "link" string=name action="clinic_patient_move" action_options="mode=form" active_id=pid}}
</td>
<!--button delete ##TODO-->
<!--
<td>
<button type="button" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-remove"></span>
</button>
</td>
-->
</tr>
{{/each}}
{{else}}
<tr>
<td colspan="3">
No items to display.
</td>
</tr>
{{/if}}
</tbody>
<tfoot>
</tfoot>
</table>
</td>
<td style="width:50%">
<table class="table">
<thead>
<th>#</th>
<th>วันที่</th>
<th>ชื่อ</th>
</thead>
<tbody>
{{#if resign_patients}}
{{#each resign_patients}}
<tr>
<td>{{no}}</td>
<td>{{resign_date}}</td>
<td>
{{view "link" string=name action="clinic_patient_move" action_options="mode=form" active_id=pid}}
</td>
<!--button delete ##TODO-->
<!--
<td>
<button type="button" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-remove"></span>
</button>
</td>
-->
</tr>
{{/each}}
{{else}}
<tr>
<td colspan="3">
No items to display.
</td>
</tr>
{{/if}}
</tbody>
<tfoot>
</tfoot>
</table>
</td>
</tr>
<tr>
<td colspan="2">
<span>
<center>
<b>
<a href="/ui#name=clinic_report_medical_summary&defaults.date={{date}}&defaults.date_from={{date_from}}&defaults.date_to={{date_to}}&defaults.branch_id={{branch_id}}&defaults.department_id={{department_id}}&defaults.report_type={{report_type}}">รวมจำนวนยาที่ใช้ประจำเดือน</a>
</b>
</center>
</span>
<table class="table table-bordered">
<thead>
{{#each titles}}
<th>{{name}}</th>
{{/each}}
</thead>
<tbody>
{{#each medicals}}
<tr>
<td style="width:20%;">
<a href="/ui#name=product&active_id={{prod_id}}&mode=form"> {{prod_name}} </a>
</td>
{{#each sub_lines}}
<td style="text-align:center">
<a href="/ui#name=clinic_report_medical_detail&defaults.date_from={{time_start}}&defaults.date_to={{time_stop}}&defaults.types={{types}}&defaults.product_id={{product_id}}&defaults.product_categ_id={{product_categ_id}}&defaults.report_type={{../../report_type}}">{{qty}} </a>
</td>
{{/each}}
</tr>
{{/each}}
</tbody>
<tfoot>
</tfoot>
</table>
</td>
</tr>
</table>

View File

@ -40,7 +40,7 @@
<i class="glyphicon glyphicon-print"></i> Print</button>
{{else}}
<button class="btn btn-sm btn-default"
onclick="location.href='report?payment_id={{../payment_id}}&convert=pdf&refer_id={{../id}}&name=report_clinic_payment_form'">
onclick="location.href='report?payment_ids=[{{../payment_id}}]&convert=pdf&refer_id={{../id}}&name=report_clinic_payment_form'">
<i class="glyphicon glyphicon-print"></i> Print</button>
{{/if}}
</td>

View File

@ -1,7 +1,10 @@
redesign print payment & invoice from hdcase
- print payment
- direct payment
- invoice payment
==========================================
keep log:
patient_name, patient_type, walkin, location
migration:
match invoice less than 2015-06-30 to hdcase
===========================================
patient:
1.new
2. dispose
3. move