diff --git a/netforce_clinic/actions/clinic_report_account_hd_case_summary.xml b/netforce_clinic/actions/clinic_report_account_hd_case_summary.xml index e28ceed..c1e7d3a 100644 --- a/netforce_clinic/actions/clinic_report_account_hd_case_summary.xml +++ b/netforce_clinic/actions/clinic_report_account_hd_case_summary.xml @@ -4,5 +4,5 @@ clinic.report.account.hd.case.summary report_account_hd_case_summary report_account_hd_case_summary - clinic_menu + account_menu diff --git a/netforce_clinic/layouts/clinic_patient_type_form.xml b/netforce_clinic/layouts/clinic_patient_type_form.xml index 6696343..f615690 100644 --- a/netforce_clinic/layouts/clinic_patient_type_form.xml +++ b/netforce_clinic/layouts/clinic_patient_type_form.xml @@ -13,7 +13,17 @@ + + + + + + diff --git a/netforce_clinic/layouts/clinic_patient_type_list.xml b/netforce_clinic/layouts/clinic_patient_type_list.xml index 89f2137..ca3b1bf 100644 --- a/netforce_clinic/layouts/clinic_patient_type_list.xml +++ b/netforce_clinic/layouts/clinic_patient_type_list.xml @@ -2,5 +2,6 @@ + diff --git a/netforce_clinic/models/patient_type.py b/netforce_clinic/models/patient_type.py index 47910ad..c8f9d2e 100644 --- a/netforce_clinic/models/patient_type.py +++ b/netforce_clinic/models/patient_type.py @@ -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={ diff --git a/netforce_clinic/models/report_account_hd_case_summary.py b/netforce_clinic/models/report_account_hd_case_summary.py index d5468e2..3b0b526 100644 --- a/netforce_clinic/models/report_account_hd_case_summary.py +++ b/netforce_clinic/models/report_account_hd_case_summary.py @@ -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 diff --git a/netforce_clinic/models/utils.py b/netforce_clinic/models/utils.py index 5b92446..b900fbf 100644 --- a/netforce_clinic/models/utils.py +++ b/netforce_clinic/models/utils.py @@ -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) diff --git a/netforce_clinic/templates/report_account_hd_case_summary.hbs b/netforce_clinic/templates/report_account_hd_case_summary.hbs index 8386652..b148e24 100644 --- a/netforce_clinic/templates/report_account_hd_case_summary.hbs +++ b/netforce_clinic/templates/report_account_hd_case_summary.hbs @@ -11,34 +11,61 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + {{#each lines}} - - - - + + + + - - - + + + - + {{/each}} + + + + + + + + + + + + +
#วันที่รอบHD Caseชื่อ-นามสกุลสิทธิ์ค่าฟอกค่ายาค่าฉีดยาแพทย์พยาบาล
+ {{#each types}} + {{name}}: {{qty}} + {{/each}} + Total: {{total_qty}} +
#วันที่รอบHD Caseชื่อ-นามสกุลสิทธิ์ค่าฟอกค่ายาค่าฉีดยาแพทย์พยาบาล
{{no}}{{date}}{{cycle}}{{hd_case}}{{pname}}{{date}}{{cycle}} + {{view "link" string=number action="clinic_hd_case" action_options="mode=form" active_id=hdcase_id}} + {{pname}} {{ptype}}{{fee}}{{epo}}{{srv}}{{currency fee zero=""}}{{currency epo zero=""}}{{currency srv zero=""}} {{dname}}{{nnames}} + {{view "link" string="View" action="clinic_cycle_item" action_options="mode=form" active_id=cycle_item_id}} +
{{currency total_fee zero=""}}{{currency total_epo zero=""}}{{currency total_srv zero=""}}