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="report_template">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>

View File

@ -13,7 +13,17 @@
<field name="company_id" invisible="1"/>
</tab>
<tab string="Other">
<field name="color"/>
<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>
</tabs>
</form>

View File

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

View File

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

View File

@ -1,12 +1,9 @@
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
from . import utils
class ReportAccountHDCaseSummary(Model):
_name="clinic.report.account.hd.case.summary"
@ -23,241 +20,149 @@ class ReportAccountHDCaseSummary(Model):
'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("-")
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)
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"),
'date_from': _get_date_from,
'date_to': _get_date_to,
}
date_from=defaults.get('date_from','%s-%s-01'%(year,month))
date_to=defaults.get('date_to',"%s-%s-%s"%(year,month,total_day))
branch_id=defaults.get('branch_id',None)
print('defaults ', defaults)
if branch_id:
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={}):
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)
branch_id=None
department_id=None
time_start='%s-%s-01 00:00:00'%(year,str(crr_month).zfill(2))
time_stop='%s-%s-%s 23:59:59'%(year,str(crr_month).zfill(2),crr_total_day)
defaults=self.default_get(context=context)
date_from=defaults.get("date_from")
date_to=defaults.get("date_to")
date=defaults.get("date")
branch_id=defaults.get("branch_id")
department_id=defaults.get("department_id")
ptype_id=None
reimbursable=''
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
time_start='%s 00:00:00'%obj.date_from
time_stop='%s 23:59:59'%obj.date_to
year=int(date[0:4])
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 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'])
date_from=obj.date_from
date_to=obj.date_to
ptype_id=obj.ptype_id.id
reimbursable=obj.reimbursable
dom=[
['date','>=', date_from],
['date','<=', date_to],
]
if ptype_id:
dom.append(['patient_type_id','=',ptype_id])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
crr_total=len(get_model("clinic.hd.case").search(dom))
items={}
items['topic%s'%count]={
'month': month_str,
'qty': crr_total or 0,
'action': 'clinic_hd_case',
'action_options': 'mode=list&search_domain=%s&tab_no=0'%replace_quote('%s'%dom),
if reimbursable=='yes':
dom.append(['state','in',['waiting_payment']])
elif reimbursable=='no':
dom.append(['state','in',['paid']])
else:
dom.append(['state','in',['completed','waiting_payment','paid']])
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
# number of patient from previous
dom=[]
weekday, prev_total_day=monthrange(prev_year, prev_month)
time_stop='%s-%s-%s'%(prev_year,str(prev_month).zfill(2),prev_total_day)
dom.append(['reg_date','<=',time_stop])
if branch_id:
dom.append(['branch_id','=',branch_id])
for code, item in items.items():
vals.update({
code: sum([t['amount'] for t in item])
})
lines.append(vals)
company_name=company.name or ""
if department_id:
dom.append(['department_id','=',department_id])
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 ""
company_name+=' (%s)'%get_model('clinic.department').browse(department_id).name or ""
elif branch_id:
branch=get_model("clinic.branch").browse(branch_id)
sub_name="(%s)" % branch.name or ""
company_name+=' (%s)'%get_model('clinic.branch').browse(branch_id).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={
'company_name': company_name,
'branch_id': branch_id,
'department_id': department_id,
'date': date,
'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': medicals['lines'],
'titles': medicals['titles'],
'company_name': '%s %s'% (company.name or "", sub_name),
'parent_company_name': company.parent_id.name or "",
'date_from': date_from,
'date_to': date_to,
'lines': slines,
'total_fee': total_fee,
'total_srv': total_srv,
'total_epo': total_epo,
'total_qty': total_qty,
'types': types,
}
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>
<table class="table">
<thead class="scroll-header">
<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>
<th colspan="11" style="text-align:center">
{{#each types}}
<span class="label label-{{color}}">{{name}}: {{qty}}</span>
{{/each}}
<span class="label label-default">Total: {{total_qty}}</span>
</th>
</tr>
<tr>
<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>
<tbody>
{{#each lines}}
<tr>
<td>{{no}}</td>
<td>{{date}}</td>
<td>{{cycle}}</td>
<td>{{hd_case}}</td>
<td>{{pname}}</td>
<td style="width:8%">{{date}}</td>
<td style="width:6%">{{cycle}}</td>
<td style="width:9%">
{{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>{{fee}}</td>
<td>{{epo}}</td>
<td>{{srv}}</td>
<td>{{currency fee zero=""}}</td>
<td>{{currency epo zero=""}}</td>
<td>{{currency srv zero=""}}</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>
{{/each}}
</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>