From b1d8f317ac6e126adf8976305e19e9cf9e09d792 Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Thu, 5 Feb 2015 00:19:45 +0700 Subject: [PATCH] hd case detail --- .../actions/clinic_report_hd_case_detail.xml | 8 + netforce_clinic/layouts/clinic_menu.xml | 1 + .../layouts/clinic_report_hd_case_detail.xml | 9 + netforce_clinic/models/__init__.py | 2 +- .../models/report_hd_case_detail.py | 298 +++++++----------- .../reports/report_hd_case_detail.xlsx | Bin 0 -> 5302 bytes .../templates/report_hd_case_detail.hbs | 57 ++++ 7 files changed, 197 insertions(+), 178 deletions(-) create mode 100644 netforce_clinic/actions/clinic_report_hd_case_detail.xml create mode 100644 netforce_clinic/layouts/clinic_report_hd_case_detail.xml create mode 100644 netforce_clinic/reports/report_hd_case_detail.xlsx create mode 100644 netforce_clinic/templates/report_hd_case_detail.hbs diff --git a/netforce_clinic/actions/clinic_report_hd_case_detail.xml b/netforce_clinic/actions/clinic_report_hd_case_detail.xml new file mode 100644 index 0000000..45b9796 --- /dev/null +++ b/netforce_clinic/actions/clinic_report_hd_case_detail.xml @@ -0,0 +1,8 @@ + + HD Case Report Detail + report + clinic.report.hd.case.detail + report_hd_case_detail + report_hd_case_detail + clinic_menu + diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml index 74acb7e..2e61255 100644 --- a/netforce_clinic/layouts/clinic_menu.xml +++ b/netforce_clinic/layouts/clinic_menu.xml @@ -50,6 +50,7 @@ + diff --git a/netforce_clinic/layouts/clinic_report_hd_case_detail.xml b/netforce_clinic/layouts/clinic_report_hd_case_detail.xml new file mode 100644 index 0000000..e62e2ed --- /dev/null +++ b/netforce_clinic/layouts/clinic_report_hd_case_detail.xml @@ -0,0 +1,9 @@ +
+ + + + + + + + diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py index 6bb3ef8..d654bac 100644 --- a/netforce_clinic/models/__init__.py +++ b/netforce_clinic/models/__init__.py @@ -63,7 +63,7 @@ from . import load_nurse_line from . import report_clinic from . import report_visit 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_recent_patient from . import report_discontinue_patient diff --git a/netforce_clinic/models/report_hd_case_detail.py b/netforce_clinic/models/report_hd_case_detail.py index b4d4ca7..9985e3a 100644 --- a/netforce_clinic/models/report_hd_case_detail.py +++ b/netforce_clinic/models/report_hd_case_detail.py @@ -1,213 +1,152 @@ 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.model import Model,fields,get_model from netforce.access import get_active_company -from . import utils class ReportHDCaseDetail(Model): _name="clinic.report.hd.case.detail" - _string="Hemodialysis Report Detail" + _string="Report HDCase Detail" _transient=True _fields={ - "date": fields.Date("Month", required=True), + "date": fields.Date("Month"), "date_from": fields.Date("From", 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={}): - year,month=time.strftime("%Y-%m").split("-") - return '%s-%s-01'%(year,month) + return time.strftime("%Y-%m-%d") 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 time.strftime("%Y-%m-%d") _defaults={ - 'date': lambda *a: time.strftime("%Y-%m-%d"), + 'date': lambda *a: time.strftime("%Y-%m-%d"), 'date_from': _get_date_from, 'date_to': _get_date_to, } 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) - - 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) + company=get_model('company').browse(company_id) + date_from=time.strftime("%Y-%m-%d") + date_to=time.strftime("%Y-%m-%d") + ptype_id=None + pid=None + dpt_id=None + bid=None if ids: obj=self.browse(ids)[0] - date=obj.date - 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 + date_from=obj.date_from + date_to=obj.date_to + pid=obj.patient_id.id + ptype_id=obj.patient_type_id.id + dpt_id=obj.department_id.id + bid=obj.branch_id.id + lines=[] dom=[] - dom.append(["time_start",">=",time_start]) - dom.append(["time_stop","<=",time_stop]) - dom.append(["state","in",["completed","waiting_payment","paid"]]) - 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), - } - count+=1 + dom.append(['date','>=',date_from]) + dom.append(['date','<=',date_to]) + if pid: + dom.append(['patient_id','=',pid]) + if ptype_id: + dom.append(['patient_type_id','=',ptype_id]) + if dpt_id: + dom.append(['department_id','=',dpt_id]) + if bid: + dom.append(['branch_id','=',bid]) - # 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]) - 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]) - 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]) - dom.append(['active','=',False]) - resign_patients=get_model('clinic.patient').search_browse(dom) - del dom[-1] - dom=replace_quote('%s'%dom) - items['topic%s'%count]={ - 'month': month_str, - 'qty': len(resign_patients) or 0, - 'action': 'clinic_patient', - 'action_options': 'mode=list&search_domain=%s&tab_no=1'%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]) - total_patient=get_model('clinic.patient').search_browse(dom) - dom=replace_quote('%s'%dom) - items['topic%s'%count]={ - 'month': next_month_str, - 'qty': len(total_patient) or 0, - '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': 'คน', - } + draft=0 + wait_treat=0 + wait_pay=0 + in_progress=0 + finish_treat=0 + cancel=0 + paid=0 + no=1 + for hdcase in get_model("clinic.hd.case").search_browse(dom): + state=hdcase.state + if state=='in_progress': + in_progress+=1 + elif state=='paid': + paid+=1 + elif state=='cancelled': + cancel+=1 + elif state=='waiting_treatment': + wait_treat+=1 + elif state=='waiting_payment': + wait_pay+=1 + elif state=='completed': + finish_treat+=1 + else: + draft+=1 + + epo=[] + fee_amt=0 + dlz_new='N' + for dlz in hdcase.dialyzers: + if dlz.use_time==1: + dlz_new='Y' + for line in hdcase.lines: + prod=line.product_id + categ=line.product_categ_id + if categ.code=='EPO': + epo.append(line.description or '') + elif categ.code=='FEE': + fee_amt+=line.amount + if not epo: + epo='-' + else: + epo=', '.join([e for e in epo]) + patient=hdcase.patient_id + rmb_amt=hdcase.rmb_amount or 0 + more_amt=hdcase.due_amount or 0 + rmb=0 + if rmb_amt > 0: + rmb=1 + lines.append({ + 'no': no, + 'number': hdcase.number or '', + 'hd_case_id': hdcase.id or '', + 'time_start': hdcase.time_start, + 'epo': epo, + 'patient_name': patient.name, + 'patient_id': patient.id, + 'patient_number': patient.number or '', + 'patient_type': patient.type_id.name or '', + 'hct': hdcase.hct or 0, + 'rmb': rmb, + 'more_amt': more_amt, + 'fee_amt': fee_amt, + 'dlz_new': dlz_new, }) - 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_start]) - dom.append(['reg_date','<=',time_stop]) - dom.append(['type_id','=',ptype['id']]) - npatients=get_model("clinic.patient").search(dom) - 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 + no+=1 + + sub_title='' + if bid: + sub_title+="%s "%(obj.branch_id.name or "") + if dpt_id: + sub_title+="%s "%(obj.department_id.name or "") 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 "", '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 @@ -220,4 +159,9 @@ class ReportHDCaseDetail(Model): data['date_to']="%s-%s-%s"%(year,month,total_day) return data + def onchange_date_from(self,context={}): + data=context['data'] + data['date_to']=data['date_from'] + return data + ReportHDCaseDetail.register() diff --git a/netforce_clinic/reports/report_hd_case_detail.xlsx b/netforce_clinic/reports/report_hd_case_detail.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..f32520861593d1935f3c09a7bc45205acce65c6a GIT binary patch literal 5302 zcmaJ_2Q*x3*VcOrBYGz!!5Ezg5uIT4-g_MxJxZ=VdKW_Ueho%+8KM&<5kU~5M(;xO z-{k)HCSShqW}mgroOi9W_niHly`T3v8?1tf1wg~Y!$Tv9l9fmM$q28n&7d~U?m%AD z8J_f3852Ynu@exL;OAXWDQo=_3452R81P5>;H8B~1|N-QfL{onVObGwyi(x7kciCl z8FJgNQCSL6@{n@FyD@R+)P4myB*z1DEMOe>R`-Qrgm|de z6R(ep^Ite6sycP@5rywuP|6>7E8$wjh$3U8t1iBw_h>A<>k>{Hue%E5r86S1*?gD$ zZsMR-@$0%^>^iJVh6txTA1kcA+Y1jFbg{iPPoq1OKRaj75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gp_{%>!XcYFcxDm%_3!B0)ZICvgKN3lt?v$bkkTG@UQKGK zHfY9rgLzW(Su4ehli`mz&pk%<}x}-X^`xTRVN&Pz1=sV-~8+ylU?(>UoHK>L8o~&~E3V z!t^*K2-{u?@fiR~%M*rav!ujj-xy6pEMIT@SSsg!?0AMP%g6idAGgHz2~oi80JaIIuhX`;riFk1 z_Pp^kFjf$#4GI~T!~wNVJ~Fvuf4QXq%X=DR`by1cp4jB%a?D<7_t|gm$<#YcwQ(v< zzsuj2Xzf)H$abt74XD9pN)Zyur;)~|wkYCviJcYRI3(dR7?k**O(rNrnPp*MMGvWhVh%aX<461Kqc_C z8mLD!Zg=NiKVxy{<RRhmEU;nYOQ+jk^g7TV#r=`uETIGfJJx(xD!7mJhDD>~VaNkL6kR#!FquCoMd# z7)zWL{b4RsT^zcAww=X~8gC3f*GXk1}(4}k;@KbOPx9Za`>XfQ&4ePOAC`KZ r#6O( +

+ {{parent_company_name}} {{company_name}} +

+

+ {{sub_title}}
+ From {{date_from}} To {{date_to}} +

+
Draft: {{draft}} Waiting Treatment: {{wait_treat}}, In progress : {{in_progress}}, Finish Treatment: {{finish_treat}}, Waiting Payment: {{wait_pay}} Paid: {{paid}}, Cancelled: {{cancel}}
+ + + + + + + + + + + + + + + + + + {{#if lines}} + {{#each lines}} + + + + + + + + + + + + + + + {{/each}} + {{else}} + + + + {{/if}} + +
#NumberBegHDEpoHNPatientPayersDlzNewHCTPaychkAmountHDCharge
{{no}} + {{view "link" string=number action="clinic_hd_case" action_options="mode=form" active_id=hd_case_id}} + {{time_start}}{{epo}}{{patient_number}} + {{view "link" string=patient_name action="clinic_patient" action_options="mode=form" active_id=patient_id}} + {{patient_type}}{{dlz_new}}{{hct}}{{rmb}}{{more_amt}}{{fee_amt}}
+ No items to display. +
+