diff --git a/netforce_clinic/actions/clinic_hd_case_print.xml b/netforce_clinic/actions/clinic_hd_case_print.xml new file mode 100644 index 0000000..6867f7c --- /dev/null +++ b/netforce_clinic/actions/clinic_hd_case_print.xml @@ -0,0 +1,6 @@ + + form_view + clinic.hd.case.print + clinic_hd_case_print + clinic_menu + diff --git a/netforce_clinic/actions/clinic_print_hd_case_summary.xml b/netforce_clinic/actions/clinic_print_hd_case_summary.xml new file mode 100644 index 0000000..389cd1e --- /dev/null +++ b/netforce_clinic/actions/clinic_print_hd_case_summary.xml @@ -0,0 +1,6 @@ + + report_odt2 + clinic.hd.case.print + get_report_data + hd_case_summary_pdf + diff --git a/netforce_clinic/layouts/clinic_cycle_item_form.xml b/netforce_clinic/layouts/clinic_cycle_item_form.xml index 2ce57dd..f05f0c2 100644 --- a/netforce_clinic/layouts/clinic_cycle_item_form.xml +++ b/netforce_clinic/layouts/clinic_cycle_item_form.xml @@ -20,8 +20,8 @@ - - + + diff --git a/netforce_clinic/layouts/clinic_hd_case_print.xml b/netforce_clinic/layouts/clinic_hd_case_print.xml new file mode 100644 index 0000000..41d2ecd --- /dev/null +++ b/netforce_clinic/layouts/clinic_hd_case_print.xml @@ -0,0 +1,11 @@ +
+ + + + + + + diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml index 7f2aeb4..5eb30a6 100644 --- a/netforce_clinic/layouts/clinic_menu.xml +++ b/netforce_clinic/layouts/clinic_menu.xml @@ -48,6 +48,7 @@ + diff --git a/netforce_clinic/layouts/clinic_report_hd_case_summary.xml b/netforce_clinic/layouts/clinic_report_hd_case_summary.xml index 5a4be2a..ce1f391 100644 --- a/netforce_clinic/layouts/clinic_report_hd_case_summary.xml +++ b/netforce_clinic/layouts/clinic_report_hd_case_summary.xml @@ -4,4 +4,5 @@ + diff --git a/netforce_clinic/layouts/clinic_staff_form.xml b/netforce_clinic/layouts/clinic_staff_form.xml index 56e9440..ec929b3 100644 --- a/netforce_clinic/layouts/clinic_staff_form.xml +++ b/netforce_clinic/layouts/clinic_staff_form.xml @@ -35,8 +35,8 @@ - - + + diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py index cbeb309..9979dc5 100644 --- a/netforce_clinic/models/__init__.py +++ b/netforce_clinic/models/__init__.py @@ -37,6 +37,7 @@ from . import hd_case_popup_discontinue from . import hd_case_popup_dlz from . import hd_case_payment from . import hd_case_dialyzer +from . import hd_case_print from . import dialyzer from . import cycle from . import cycle_item diff --git a/netforce_clinic/models/hd_case_print.py b/netforce_clinic/models/hd_case_print.py new file mode 100644 index 0000000..bbe5e19 --- /dev/null +++ b/netforce_clinic/models/hd_case_print.py @@ -0,0 +1,268 @@ +import time +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 HDCasePrint(Model): + _name="clinic.hd.case.print" + _transient=True + + _fields={ + "date": fields.Date("Month"), + "date_from": fields.Date("From", required=True), + "date_to": fields.Date("To", required=True), + } + + 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("-") + weekday, total_day=monthrange(int(year), int(month)) + date_from=defaults.get('date_from','%s-%s-01'%(year,month)) + date_to=defaults.get('date_to',"%s-%s-%s"%(year,month,total_day)) + res={ + 'date': date, + 'date_from': date_from, + 'date_to': date_to, + } + return res + + def onchange_date(self,context={}): + data=context['data'] + date=data['date'] + year,month,day=date.split("-") + weekday, total_day=monthrange(int(year), int(month)) + data['date_from']="%s-%s-01"%(year,month) + data['date_to']="%s-%s-%s"%(year,month,total_day) + return data + + def get_data(self,context={}): + return + + 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) + 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']) + 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), + } + 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]) + 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 "" + elif branch_id: + branch=get_model("clinic.branch").browse(branch_id) + sub_name="(%s)" % branch.name or "" + data={ + '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 "", + } + return data + +HDCasePrint.register() diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py index 297e1a7..298d5b3 100644 --- a/netforce_clinic/models/patient.py +++ b/netforce_clinic/models/patient.py @@ -172,7 +172,8 @@ class Patient(Model): return b_ids[0] _defaults={ - "number": _get_number, + #"number": _get_number, + "number": "", "reg_date": lambda *a: time.strftime("%Y-%m-%d"), "company_id": lambda *a: get_active_company(), 'branch_id': _get_branch, diff --git a/netforce_clinic/models/report_cycle_item.py b/netforce_clinic/models/report_cycle_item.py index af70a26..3e42de5 100644 --- a/netforce_clinic/models/report_cycle_item.py +++ b/netforce_clinic/models/report_cycle_item.py @@ -1,4 +1,5 @@ import time +from calendar import monthrange from netforce.model import Model,fields,get_model from netforce.access import get_active_company diff --git a/netforce_clinic/models/report_hd_case_summary.py b/netforce_clinic/models/report_hd_case_summary.py index d1325b7..b754912 100644 --- a/netforce_clinic/models/report_hd_case_summary.py +++ b/netforce_clinic/models/report_hd_case_summary.py @@ -272,5 +272,19 @@ class ReportHDCaseSummary(Model): data=context['data'] data['department_id']=None return data + + def get_report_data2(self,context={}): + data={} + return data + + def run_report(self,ids,context={}): + return { + 'next': { + 'name': 'clinic_print_hd_case_summary', + 'refer_id': ids[0], + 'action_options': 'convert=pdf', + } + } + ReportHDCaseSummary.register() diff --git a/netforce_clinic/reports/hd_case_summary_pdf.odt b/netforce_clinic/reports/hd_case_summary_pdf.odt new file mode 100644 index 0000000..db963d3 Binary files /dev/null and b/netforce_clinic/reports/hd_case_summary_pdf.odt differ diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt index 2b7201c..7105875 100644 --- a/netforce_clinic/todo.txt +++ b/netforce_clinic/todo.txt @@ -1,56 +1,2 @@ -todo: - - multi department access *** - - merge staff same name but different department - - doctor นายแพทย์ ทวีชัย - - tick - 1. create profile for all department + branch (2) - - create sharing setting for all model - - branch - - deparment - - patient - - patient cycle - - cycle item - - visit - - hd case - - dialyzer - - shop - - sickbed - - staff - - staff rotation : only manager nurse - - reports - - P Moo cycle item -> ok - - P อ้วน - - claim - - not claim - - patient - - create/ update visit - - matching payment - - get hn from account setting - - new feature HN - - split invoice (fee & another) - - schedule job - - create visit next month - - - run script - - update level's nurse -> ok - - report k. boy (sub detail) -> ok - - ** update accounting - - link ref -> ok - - bug -> ok - - wht (david) -> p yui test - -=============================== - - - compute labor cost - - update level -> ok - - set patient_id with domain state=='admit' -> ok - convbal -> not yet (wait yui) -> ok but have to update memo - post 10,000 invoices per one time -> ask david - patient & staff - - split name -> not yet - staff have multi department -> added but set have to set permission - - many2many - show epo(yes) in list of hd case ->ok - matching payment > ok - create contact from staff -> ok - script to clear invoice -> ok +report cycle item : + - sunanna can not see