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 0000000..f325208 Binary files /dev/null and b/netforce_clinic/reports/report_hd_case_detail.xlsx differ diff --git a/netforce_clinic/templates/report_hd_case_detail.hbs b/netforce_clinic/templates/report_hd_case_detail.hbs new file mode 100644 index 0000000..4130787 --- /dev/null +++ b/netforce_clinic/templates/report_hd_case_detail.hbs @@ -0,0 +1,57 @@ +
+

+ {{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. +
+