hd case detail

conv_bal
watcha.h 2015-02-05 00:19:45 +07:00
parent 280e663e0b
commit b1d8f317ac
7 changed files with 197 additions and 178 deletions

View File

@ -0,0 +1,8 @@
<action>
<field name="string">HD Case Report Detail</field>
<field name="view_cls">report</field>
<field name="model">clinic.report.hd.case.detail</field>
<field name="report_template">report_hd_case_detail</field>
<field name="report_template_xls">report_hd_case_detail</field>
<field name="menu">clinic_menu</field>
</action>

View File

@ -50,6 +50,7 @@
<item string="Reporting" perm="clinic_report"> <item string="Reporting" perm="clinic_report">
<item string="Visit Summary" action="clinic_report_visit"/> <item string="Visit Summary" action="clinic_report_visit"/>
<item string="HD Case Summary" action="clinic_report_hd_case_summary"/> <item string="HD Case Summary" action="clinic_report_hd_case_summary"/>
<item string="HD Case Detail" action="clinic_report_hd_case_detail"/>
<item string="Medical Summary" action="clinic_report_medical_summary"/> <item string="Medical Summary" action="clinic_report_medical_summary"/>
<item string="Recent Patient" action="clinic_report_recent_patient"/> <item string="Recent Patient" action="clinic_report_recent_patient"/>
<item string="Discontinue Patient" action="clinic_report_discontinue_patient"/> <item string="Discontinue Patient" action="clinic_report_discontinue_patient"/>

View File

@ -0,0 +1,9 @@
<form model="clinic.report.hd.case.detail">
<!--<field name="date" span="3" mode="month" onchange="onchange_date"/>-->
<field name="date_from" onchange="onchange_date_from" span="2"/>
<field name="date_to" span="2"/>
<field name="patient_id" span="2"/>
<field name="patient_type_id" span="2"/>
<field name="branch_id" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
</form>

View File

@ -63,7 +63,7 @@ from . import load_nurse_line
from . import report_clinic from . import report_clinic
from . import report_visit from . import report_visit
from . import report_hd_case_summary from . import report_hd_case_summary
#from . import report_hd_case_detail from . import report_hd_case_detail
from . import report_medical_summary from . import report_medical_summary
from . import report_recent_patient from . import report_recent_patient
from . import report_discontinue_patient from . import report_discontinue_patient

View File

@ -1,213 +1,152 @@
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 ReportHDCaseDetail(Model): class ReportHDCaseDetail(Model):
_name="clinic.report.hd.case.detail" _name="clinic.report.hd.case.detail"
_string="Hemodialysis Report Detail" _string="Report HDCase Detail"
_transient=True _transient=True
_fields={ _fields={
"date": fields.Date("Month", required=True), "date": fields.Date("Month"),
"date_from": fields.Date("From", required=True), "date_from": fields.Date("From", required=True),
"date_to": fields.Date("To", required=True), "date_to": fields.Date("To", required=True),
'patient_type_id': fields.Many2One("clinic.patient.type","Payers"),
'patient_id': fields.Many2One("clinic.patient","Patient"),
'branch_id': fields.Many2One("clinic.branch","Branch"),
'department_id': fields.Many2One("clinic.department","Department"),
} }
def _get_date_from(self,context={}): def _get_date_from(self,context={}):
year,month=time.strftime("%Y-%m").split("-") return time.strftime("%Y-%m-%d")
return '%s-%s-01'%(year,month)
def _get_date_to(self,context={}): def _get_date_to(self,context={}):
year,month,day=time.strftime("%Y-%m-%d").split("-") return time.strftime("%Y-%m-%d")
weekday, total_day=monthrange(int(year), int(month))
return "%s-%s-%s"%(year,month,total_day)
_defaults={ _defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"), 'date': lambda *a: time.strftime("%Y-%m-%d"),
'date_from': _get_date_from, 'date_from': _get_date_from,
'date_to': _get_date_to, 'date_to': _get_date_to,
} }
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)
date_from=time.strftime("%Y-%m-%d")
date=datetime.now().strftime("%Y-%m-%d") date_to=time.strftime("%Y-%m-%d")
year=int(date[0:4]) ptype_id=None
crr_month=int(date[5:7]) pid=None
weekday, crr_total_day=monthrange(year, crr_month) dpt_id=None
bid=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)
if ids: if ids:
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
date=obj.date 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 pid=obj.patient_id.id
year=int(date[0:4]) ptype_id=obj.patient_type_id.id
dpt_id=obj.department_id.id
prev_year=year bid=obj.branch_id.id
next_year=year lines=[]
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=[]
dom.append(["time_start",">=",time_start]) dom.append(['date','>=',date_from])
dom.append(["time_stop","<=",time_stop]) dom.append(['date','<=',date_to])
dom.append(["state","in",["completed","waiting_payment","paid"]]) if pid:
crr_total=len(get_model("clinic.hd.case").search(dom)) dom.append(['patient_id','=',pid])
items={} if ptype_id:
items['topic%s'%count]={ dom.append(['patient_type_id','=',ptype_id])
'month': month_str, if dpt_id:
'qty': crr_total or 0, dom.append(['department_id','=',dpt_id])
'action': 'clinic_hd_case', if bid:
'action_options': 'mode=list&search_domain=%s&tab_no=0'%replace_quote('%s'%dom), dom.append(['branch_id','=',bid])
}
count+=1
# number of patient from previous draft=0
dom=[] wait_treat=0
weekday, prev_total_day=monthrange(prev_year, prev_month) wait_pay=0
time_stop='%s-%s-%s'%(prev_year,str(prev_month).zfill(2),prev_total_day) in_progress=0
dom.append(['reg_date','<=',time_stop]) finish_treat=0
npatient=len(get_model("clinic.patient").search(dom)) cancel=0
dom=replace_quote('%s'%dom) paid=0
items['topic%s'%count]={ no=1
'month': prev_month_str, for hdcase in get_model("clinic.hd.case").search_browse(dom):
'qty': npatient or 0, state=hdcase.state
'action': 'clinic_patient', if state=='in_progress':
'action_options': 'mode=list&search_domain=%s'%dom, in_progress+=1
} elif state=='paid':
count+=1 paid+=1
elif state=='cancelled':
# new patient of this month cancel+=1
dom=[] elif state=='waiting_treatment':
weekday, crr_total_day=monthrange(prev_year, crr_month) wait_treat+=1
time_start='%s-%s-01'%(year,str(crr_month).zfill(2)) elif state=='waiting_payment':
time_stop='%s-%s-%s'%(year,str(crr_month).zfill(2),crr_total_day) wait_pay+=1
dom.append(['reg_date','>=',time_start]) elif state=='completed':
dom.append(['reg_date','<=',time_stop]) finish_treat+=1
new_patients=get_model('clinic.patient').search_browse(dom) else:
dom=replace_quote('%s'%dom) draft+=1
items['topic%s'%count]={
'month': month_str, epo=[]
'qty': len(new_patients) or 0, fee_amt=0
'action': 'clinic_patient', dlz_new='N'
'action_options': 'mode=list&search_domain=%s'%dom, for dlz in hdcase.dialyzers:
} if dlz.use_time==1:
count+=1 dlz_new='Y'
for line in hdcase.lines:
# number for patient who resign for this month prod=line.product_id
dom=[] categ=line.product_categ_id
time_start='%s-%s-01'%(year,str(crr_month).zfill(2)) if categ.code=='EPO':
time_stop='%s-%s-%s'%(year,str(crr_month).zfill(2),crr_total_day) epo.append(line.description or '')
dom.append(['resign_date','>=',time_start]) elif categ.code=='FEE':
dom.append(['resign_date','<=',time_stop]) fee_amt+=line.amount
dom.append(['active','=',False]) if not epo:
resign_patients=get_model('clinic.patient').search_browse(dom) epo='-'
del dom[-1] else:
dom=replace_quote('%s'%dom) epo=', '.join([e for e in epo])
items['topic%s'%count]={ patient=hdcase.patient_id
'month': month_str, rmb_amt=hdcase.rmb_amount or 0
'qty': len(resign_patients) or 0, more_amt=hdcase.due_amount or 0
'action': 'clinic_patient', rmb=0
'action_options': 'mode=list&search_domain=%s&tab_no=1'%dom, if rmb_amt > 0:
} rmb=1
count+=1 lines.append({
'no': no,
# all patient who are in hospital on select month 'number': hdcase.number or '',
dom=[] 'hd_case_id': hdcase.id or '',
weekday, crr_total_day=monthrange(year, crr_month) 'time_start': hdcase.time_start,
time_stop='%s-%s-%s'%(year,str(crr_month).zfill(2),crr_total_day) 'epo': epo,
dom.append(['reg_date','<=',time_stop]) 'patient_name': patient.name,
total_patient=get_model('clinic.patient').search_browse(dom) 'patient_id': patient.id,
dom=replace_quote('%s'%dom) 'patient_number': patient.number or '',
items['topic%s'%count]={ 'patient_type': patient.type_id.name or '',
'month': next_month_str, 'hct': hdcase.hct or 0,
'qty': len(total_patient) or 0, 'rmb': rmb,
'action': 'clinic_patient', 'more_amt': more_amt,
'action_options': 'mode=list&search_domain=%s'%dom, 'fee_amt': fee_amt,
} 'dlz_new': dlz_new,
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=[] no+=1
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) sub_title=''
dom.append(['reg_date','>=',time_start]) if bid:
dom.append(['reg_date','<=',time_stop]) sub_title+="%s "%(obj.branch_id.name or "")
dom.append(['type_id','=',ptype['id']]) if dpt_id:
npatients=get_model("clinic.patient").search(dom) sub_title+="%s "%(obj.department_id.name or "")
dom=replace_quote('%s'%dom)
items[tkey]={
'month': '',
'qty': len(npatients),
'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}
medicals=get_model("clinic.report.medical.summary").get_report_data(ids=[],context=context)
year=year+543
data={ data={
'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': company.name or "", 'company_name': company.name or "",
'parent_company_name': company.parent_id.name or "", 'parent_company_name': company.parent_id.name or "",
'lines': lines,
'date_from': date_from,
'date_to': date_to,
'sub_title': sub_title,
'draft': draft,
'wait_treat': wait_treat,
'wait_pay': wait_pay,
'in_progress': in_progress,
'cancel': cancel,
'paid': paid,
'finish_treat': finish_treat,
} }
return data return data
@ -220,4 +159,9 @@ class ReportHDCaseDetail(Model):
data['date_to']="%s-%s-%s"%(year,month,total_day) data['date_to']="%s-%s-%s"%(year,month,total_day)
return data return data
def onchange_date_from(self,context={}):
data=context['data']
data['date_to']=data['date_from']
return data
ReportHDCaseDetail.register() ReportHDCaseDetail.register()

View File

@ -0,0 +1,57 @@
<center>
<h3>
{{parent_company_name}}&nbsp;{{company_name}}
</h3>
<h4>
{{sub_title}}</br>
From {{date_from}} To {{date_to}}
</h4>
<h5>Draft: {{draft}} Waiting Treatment: {{wait_treat}}, In progress : {{in_progress}}, Finish Treatment: {{finish_treat}}, Waiting Payment: {{wait_pay}} Paid: {{paid}}, Cancelled: {{cancel}} </h5>
</center>
<table class="table">
<thead class="scroll-header">
<th>#</th>
<th>Number</th>
<th>BegHD</th>
<th>Epo</th>
<th>HN</th>
<th>Patient</th>
<th>Payers</th>
<th>DlzNew</th>
<th>HCT</th>
<th>Paychk</th>
<th>Amount</th>
<th>HDCharge</th>
</thead>
<tbody>
{{#if lines}}
{{#each lines}}
<tr>
<td>{{no}}</td>
<td>
{{view "link" string=number action="clinic_hd_case" action_options="mode=form" active_id=hd_case_id}}
</td>
<td>{{time_start}}</td>
<td>{{epo}}</td>
<td>{{patient_number}}</td>
<td>
{{view "link" string=patient_name action="clinic_patient" action_options="mode=form" active_id=patient_id}}
</td>
<td>{{patient_type}}</td>
<td>{{dlz_new}}</td>
<td>{{hct}}</td>
<td>{{rmb}}</td>
<td>{{more_amt}}</td>
<td>{{fee_amt}}</td>
</tr>
{{/each}}
{{else}}
<tr>
<td>
No items to display.
</td>
</tr>
{{/if}}
</tbody>
</table>