report hd summary for accounting

conv_bal
watcha.h@almacom.co.th 2015-03-11 13:51:55 +07:00
parent 191e0b7941
commit d79fe4cddc
7 changed files with 203 additions and 237 deletions

View File

@ -4,5 +4,5 @@
<field name="model">clinic.report.account.hd.case.summary</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">report_account_hd_case_summary</field>
<field name="report_template_xls">report_account_hd_case_summary</field> <field name="report_template_xls">report_account_hd_case_summary</field>
<field name="menu">clinic_menu</field> <field name="menu">account_menu</field>
</action> </action>

View File

@ -13,7 +13,17 @@
<field name="company_id" invisible="1"/> <field name="company_id" invisible="1"/>
</tab> </tab>
<tab string="Other"> <tab string="Other">
<field name="color"/>
<field name="hct_include"/> <field name="hct_include"/>
<group span="6" columns="1">
<template>
<div>
<p></p>
<b>Color Info: </b><a href="http://getbootstrap.com/components/#labels">http://getbootstrap.com/components/#labels</a></div>
</template>
</group>
<group span="6" columns="1">
</group>
</tab> </tab>
</tabs> </tabs>
</form> </form>

View File

@ -2,5 +2,6 @@
<field name="name"/> <field name="name"/>
<field name="code"/> <field name="code"/>
<field name="contact_id"/> <field name="contact_id"/>
<field name="color"/>
<field name="default"/> <field name="default"/>
</list> </list>

View File

@ -13,6 +13,7 @@ class PatientType(Model):
'default': fields.Boolean("Default"), 'default': fields.Boolean("Default"),
'hct_include': fields.Boolean("HCT Include"), 'hct_include': fields.Boolean("HCT Include"),
'company_id': fields.Many2One("company","Company"), 'company_id': fields.Many2One("company","Company"),
'color': fields.Char("Color"),
} }
_defaults={ _defaults={

View File

@ -1,12 +1,9 @@
import time import time
import urllib.parse as urllib
from datetime import datetime
from calendar import monthrange from calendar import monthrange
from netforce.model import Model, fields, get_model from netforce.model import Model, fields, get_model
from netforce.access import get_active_company from netforce.access import get_active_company
from . import utils
class ReportAccountHDCaseSummary(Model): class ReportAccountHDCaseSummary(Model):
_name="clinic.report.account.hd.case.summary" _name="clinic.report.account.hd.case.summary"
@ -23,241 +20,149 @@ class ReportAccountHDCaseSummary(Model):
'reimbursable': fields.Selection([['yes','Yes'],['no','No']],'Reimbursable'), 'reimbursable': fields.Selection([['yes','Yes'],['no','No']],'Reimbursable'),
} }
def _get_date_from(self,context={}): def default_get(self,field_names=None,context={},**kw):
defaults=context.get("defaults",{})
date=defaults.get('date',time.strftime("%Y-%m-%d"))
year,month=time.strftime("%Y-%m").split("-") 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)) weekday, total_day=monthrange(int(year), int(month))
return "%s-%s-%s"%(year,month,total_day) date_from=defaults.get('date_from','%s-%s-01'%(year,month))
date_to=defaults.get('date_to',"%s-%s-%s"%(year,month,total_day))
_defaults={ branch_id=defaults.get('branch_id',None)
'date': lambda *a: time.strftime("%Y-%m-%d"), print('defaults ', defaults)
'date_from': _get_date_from, if branch_id:
'date_to': _get_date_to, branch_id=int(branch_id)
} department_id=defaults.get('department_id',None)
if department_id:
department_id=int(department_id)
res={
'date': date,
'date_from': date_from,
'date_to': date_to,
'branch_id': branch_id,
'department_id': department_id,
}
return res
def get_report_data(self,ids,context={}): def get_report_data(self,ids,context={}):
company_id=get_active_company() company_id=get_active_company()
company=get_model("company").browse(company_id) company=get_model("company").browse(company_id)
defaults=self.default_get(context=context)
date=datetime.now().strftime("%Y-%m-%d") date_from=defaults.get("date_from")
year=int(date[0:4]) date_to=defaults.get("date_to")
crr_month=int(date[5:7]) date=defaults.get("date")
weekday, crr_total_day=monthrange(year, crr_month) branch_id=defaults.get("branch_id")
branch_id=None department_id=defaults.get("department_id")
department_id=None ptype_id=None
time_start='%s-%s-01 00:00:00'%(year,str(crr_month).zfill(2)) reimbursable=''
time_stop='%s-%s-%s 23:59:59'%(year,str(crr_month).zfill(2),crr_total_day)
if ids: if ids:
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
branch_id=obj.branch_id.id branch_id=obj.branch_id.id
department_id=obj.department_id.id department_id=obj.department_id.id
date=obj.date date=obj.date
crr_month=int(date[5:7]) #XXX date_from=obj.date_from
time_start='%s 00:00:00'%obj.date_from date_to=obj.date_to
time_stop='%s 23:59:59'%obj.date_to ptype_id=obj.ptype_id.id
year=int(date[0:4]) reimbursable=obj.reimbursable
dom=[
prev_year=year ['date','>=', date_from],
next_year=year ['date','<=', date_to],
prev_month=crr_month-1 ]
next_month=crr_month+1 if ptype_id:
if crr_month==1: dom.append(['patient_type_id','=',ptype_id])
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 encode_url(dom):
dom='%s'%dom
dom=urllib.quote(dom.encode('utf-8'))
return dom
def replace_quote(dom=""):
return dom.replace("'","\"")
count=1
# number of hd case of this month
dom=[]
dom.append(["time_start",">=",time_start])
dom.append(["time_stop","<=",time_stop])
dom.append(["state","in",["completed","waiting_payment","paid"]])
dom.append(['patient_id.walkin','=','no'])
if branch_id: if branch_id:
dom.append(['branch_id','=',branch_id]) dom.append(['branch_id','=',branch_id])
if department_id: if department_id:
dom.append(['department_id','=',department_id]) dom.append(['department_id','=',department_id])
crr_total=len(get_model("clinic.hd.case").search(dom)) if reimbursable=='yes':
items={} dom.append(['state','in',['waiting_payment']])
items['topic%s'%count]={ elif reimbursable=='no':
'month': month_str, dom.append(['state','in',['paid']])
'qty': crr_total or 0, else:
'action': 'clinic_hd_case', dom.append(['state','in',['completed','waiting_payment','paid']])
'action_options': 'mode=list&search_domain=%s&tab_no=0'%replace_quote('%s'%dom), print('dom ', dom)
lines=[]
for hdcase in get_model("clinic.hd.case").search_browse(dom):
items={}
for line in hdcase.lines:
amt=line.amount or 0
categ=line.product_categ_id
code=(categ.code or "").lower()
if not code in items.keys():
items[code]=[]
items[code].append({
'amount': amt,
})
patient=hdcase.patient_id
ptype=hdcase.patient_type_id
cycle=hdcase.cycle_id
cycle_item=hdcase.cycle_item_id
vals={
'hdcase_id': hdcase.id,
'number': hdcase.number or "",
'date': hdcase.date,
'hct': hdcase.hct or 0,
'ptype': ptype.name or "",
'ptype_color': ptype.color or "default",
'dname': hdcase.doctor_id.name or "",
'cycle': cycle.name or "",
'pname': patient.name,
'cseq': cycle.sequence or 0,
'cycle_item_id': cycle_item.id,
} }
count+=1 for code, item in items.items():
vals.update({
# number of patient from previous code: sum([t['amount'] for t in item])
dom=[] })
weekday, prev_total_day=monthrange(prev_year, prev_month) lines.append(vals)
time_stop='%s-%s-%s'%(prev_year,str(prev_month).zfill(2),prev_total_day) company_name=company.name or ""
dom.append(['reg_date','<=',time_stop])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id: if department_id:
dom.append(['department_id','=',department_id]) company_name+=' (%s)'%get_model('clinic.department').browse(department_id).name or ""
npatient=len(get_model("clinic.patient").search(dom))
dom=replace_quote('%s'%dom)
items['topic%s'%count]={
'month': prev_month_str,
'qty': npatient or 0,
'action': 'clinic_patient',
'action_options': 'mode=list&search_domain=%s'%dom,
}
count+=1
# new patient of this month
dom=[]
weekday, crr_total_day=monthrange(prev_year, crr_month)
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)
dom.append(['reg_date','>=',time_start])
dom.append(['reg_date','<=',time_stop])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
new_patients=get_model('clinic.patient').search_browse(dom)
dom=replace_quote('%s'%dom)
items['topic%s'%count]={
'month': month_str,
'qty': len(new_patients) or 0,
'action': 'clinic_patient',
'action_options': 'mode=list&search_domain=%s'%dom,
}
count+=1
# number for patient who resign for this month
dom=[]
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)
dom.append(['resign_date','>=',time_start])
dom.append(['resign_date','<=',time_stop])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
resign_patients_qty=0
resign_patients=[]
for pt in get_model('clinic.patient').search_browse(dom):
resign_patients_qty+=1
resign_patients.append(pt.name)
del dom[-1]
dom=replace_quote('%s'%dom)
items['topic%s'%count]={
'month': month_str,
'qty': resign_patients_qty,
'action': 'clinic_patient',
'action_options': 'mode=list&search_domain=%s&tab_no=2'%dom,
}
count+=1
# all patient who are in hospital on select month
dom=[]
weekday, crr_total_day=monthrange(year, crr_month)
time_stop='%s-%s-%s'%(year,str(crr_month).zfill(2),crr_total_day)
dom.append(['reg_date','<=',time_stop])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
total_patient=get_model('clinic.patient').search_browse(dom)
dom=replace_quote('%s'%dom)
total_patient_qty=len(total_patient) or 0
items['topic%s'%count]={
'month': next_month_str,
'qty': total_patient_qty-resign_patients_qty,
'action': 'clinic_patient',
'action_options': 'mode=list&search_domain=%s'%dom,
}
count+=1
topics=utils.TOPICS
for ptype in get_model("clinic.patient.type").search_read([[]],['name']):
tkey='topic%s'%count
topics.update({
tkey:{
'name': ptype['name'],
'unit': 'คน',
}
})
dom=[]
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)
dom.append(['reg_date','<=',time_stop])
dom.append(['type_id','=',ptype['id']])
dom.append(['name','not in', resign_patients])
npatients_qty=0
for pt in get_model("clinic.patient").search(dom):
npatients_qty+=1
dom=replace_quote('%s'%dom)
items[tkey]={
'month': '',
'qty': npatients_qty,
'action': 'clinic_patient',
'action_options': 'mode=list&search_domain=%s'%dom,
}
count+=1
lines=[]
index=1
for item in items:
topic='topic%s'%index
name=utils.TOPICS[topic]['name']
unit=utils.TOPICS[topic]['unit']
line=items[topic]
line['topic']=name
line['unit']=unit
lines.append(line)
index+=1
context['defaults']={
'date': date,
'branch_id': branch_id,
'department_id': department_id,
}
medicals=get_model("clinic.report.medical.summary").get_report_data(ids=[],context=context)
year=year+543
sub_name=''
if department_id:
dpt=get_model("clinic.department").browse(department_id)
sub_name="(%s)" % dpt.name or ""
elif branch_id: elif branch_id:
branch=get_model("clinic.branch").browse(branch_id) company_name+=' (%s)'%get_model('clinic.branch').browse(branch_id).name or ""
sub_name="(%s)" % branch.name or "" total_fee=0
total_srv=0
total_epo=0
slines=[]
no=1
ptypes={}
for line in sorted(lines, key=lambda x: (x['date'],x['cseq'])):
ptype=line['ptype'] or ""
if ptype not in ptypes.keys():
ptypes[ptype]={
'qty': 0,
'color': line['ptype_color'] or "default",
}
ptypes[ptype]['qty']+=1
total_fee+=line.get('fee',0)
total_srv+=line.get('srv',0)
total_epo+=line.get('epo',0)
line['no']=no
slines.append(line)
no+=1
types=[]
total_qty=0
for name, vals in ptypes.items():
qty=vals['qty'] or 0
total_qty+=qty
color=vals['color'] or "default"
types.append({
'name': name,
'qty': qty,
'color': color,
})
data={ data={
'company_name': company_name,
'branch_id': branch_id, 'branch_id': branch_id,
'department_id': department_id, 'department_id': department_id,
'date': date, 'date': date,
'month': month_str, 'date_from': date_from,
'year': year, 'date_to': date_to,
'lines': lines, 'lines': slines,
'recent_patients': get_model("clinic.report.recent.patient").get_report_data(ids=[],context=context)['lines'], 'total_fee': total_fee,
'resign_patients': get_model("clinic.report.discontinue.patient").get_report_data(ids=[],context=context)['lines'], 'total_srv': total_srv,
'medicals': medicals['lines'], 'total_epo': total_epo,
'titles': medicals['titles'], 'total_qty': total_qty,
'company_name': '%s %s'% (company.name or "", sub_name), 'types': types,
'parent_company_name': company.parent_id.name or "",
} }
return data return data

View File

@ -251,3 +251,25 @@ def date2thai(date, format='%(BY)s-%(m)s-%(d)s', lang='th_TH'):
def htmlcolor(r, g, b):
#ex: htmlcolor(250,0,0) => '#fa0000'
def _chkarg(a):
if isinstance(a, int): # clamp to range 0--255
if a < 0:
a = 0
elif a > 255:
a = 255
elif isinstance(a, float): # clamp to range 0.0--1.0 and convert to integer 0--255
if a < 0.0:
a = 0
elif a > 1.0:
a = 255
else:
a = int(round(a*255))
else:
raise ValueError('Arguments must be integers or floats.')
return a
r = _chkarg(r)
g = _chkarg(g)
b = _chkarg(b)
return '#{:02x}{:02x}{:02x}'.format(r,g,b)

View File

@ -11,34 +11,61 @@
</center> </center>
<table class="table"> <table class="table">
<thead class="scroll-header"> <thead class="scroll-header">
<th>#</th> <tr>
<th>วันที่</th> <th colspan="11" style="text-align:center">
<th>รอบ</th> {{#each types}}
<th>HD Case</th> <span class="label label-{{color}}">{{name}}: {{qty}}</span>
<th>ชื่อ-นามสกุล</th> {{/each}}
<th>สิทธิ์</th> <span class="label label-default">Total: {{total_qty}}</span>
<th>ค่าฟอก</th> </th>
<th>ค่ายา</th> </tr>
<th>ค่าฉีดยา</th> <tr>
<th>แพทย์</th> <th>#</th>
<th>พยาบาล</th> <th>วันที่</th>
<th>รอบ</th>
<th>HD Case</th>
<th>ชื่อ-นามสกุล</th>
<th>สิทธิ์</th>
<th>ค่าฟอก</th>
<th>ค่ายา</th>
<th>ค่าฉีดยา</th>
<th>แพทย์</th>
<th>พยาบาล</th>
</tr>
</thead> </thead>
<tbody> <tbody>
{{#each lines}} {{#each lines}}
<tr> <tr>
<td>{{no}}</td> <td>{{no}}</td>
<td>{{date}}</td> <td style="width:8%">{{date}}</td>
<td>{{cycle}}</td> <td style="width:6%">{{cycle}}</td>
<td>{{hd_case}}</td> <td style="width:9%">
<td>{{pname}}</td> {{view "link" string=number action="clinic_hd_case" action_options="mode=form" active_id=hdcase_id}}
</td>
<td style="width:20%">{{pname}}</td>
<td>{{ptype}}</td> <td>{{ptype}}</td>
<td>{{fee}}</td> <td>{{currency fee zero=""}}</td>
<td>{{epo}}</td> <td>{{currency epo zero=""}}</td>
<td>{{srv}}</td> <td>{{currency srv zero=""}}</td>
<td>{{dname}}</td> <td>{{dname}}</td>
<td>{{nnames}}</td> <td>
{{view "link" string="View" action="clinic_cycle_item" action_options="mode=form" active_id=cycle_item_id}}
</td>
</tr> </tr>
{{/each}} {{/each}}
</tbody> </tbody>
<tfoot>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>{{currency total_fee zero=""}}</th>
<th>{{currency total_epo zero=""}}</th>
<th>{{currency total_srv zero=""}}</th>
<th></th>
<th></th>
</tfoot>
</table> </table>