From b892f5540832c8c2f38e80c55b7548771fa5c319 Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Tue, 4 Nov 2014 23:10:23 +0700 Subject: [PATCH] report summary --- netforce_clinic/layouts/clinic_menu.xml | 3 - netforce_clinic/models/__init__.py | 2 - .../models/report_hd_case_summary.py | 175 ++++++++++-------- netforce_clinic/models/utils.py | 9 + .../templates/report_hd_case_detail.hbs | 27 ++- .../templates/report_hd_case_summary.hbs | 22 +-- 6 files changed, 129 insertions(+), 109 deletions(-) diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml index b8144e6..38e872f 100644 --- a/netforce_clinic/layouts/clinic_menu.xml +++ b/netforce_clinic/layouts/clinic_menu.xml @@ -39,12 +39,9 @@
-
- - " diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py index 63423e0..26ef3cb 100644 --- a/netforce_clinic/models/__init__.py +++ b/netforce_clinic/models/__init__.py @@ -34,8 +34,6 @@ from . import gen_visit_line from . import report_clinic from . import report_hd_case_detail from . import report_hd_case_summary -from . import report_hd_case_medical -from . import report_hd_case_payment from . import fin_setting from . import import_data_mg from . import import_data_nhso diff --git a/netforce_clinic/models/report_hd_case_summary.py b/netforce_clinic/models/report_hd_case_summary.py index 64b2074..e7bc58e 100644 --- a/netforce_clinic/models/report_hd_case_summary.py +++ b/netforce_clinic/models/report_hd_case_summary.py @@ -3,6 +3,7 @@ import time from datetime import datetime from calendar import monthrange from netforce.model import Model, fields, get_model +from netforce.database import get_connection from . import utils @@ -20,6 +21,7 @@ class ReportHDCaseSummary(Model): } def get_report_data(self,ids,context={}): + db=get_connection() for item in get_model("company").search_browse([]): company_name=item.name @@ -27,99 +29,118 @@ class ReportHDCaseSummary(Model): if ids: obj=self.browse(ids)[0] date=obj.date + year=int(date[0:4]) + prev_year=year + next_year=year crr_month=int(date[5:7]) 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 - year=int(date[0:4]) 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] - dom=[] - weekday, prev_total_day=monthrange(year, prev_month) - prev_time_start='2014-%s-01 00:00:00'%(str(prev_month).zfill(2)) - prev_time_stop='2014-%s-%s 23:59:59'%(str(prev_month).zfill(2),prev_total_day) - dom.append(['time_start','>=', prev_time_start]) - dom.append(['time_stop','<=',prev_time_stop]) - prev_total=len(get_model("clinic.hd.case").search(dom)) - + # number of hd case of this month dom=[] weekday, crr_total_day=monthrange(year, crr_month) - crr_time_start='2014-%s-01 00:00:00'%(str(crr_month).zfill(2)) - crr_time_stop='2014-%s-%s 23:59:59'%(str(crr_month).zfill(2),crr_total_day) - dom.append(['time_start','>=', crr_time_start]) - dom.append(['time_stop','<=',crr_time_stop]) + 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) + dom.append(['time_start','>=', time_start]) + dom.append(['time_stop','<=',time_stop]) + dom.append(['state','=','completed']) crr_total=len(get_model("clinic.hd.case").search(dom)) - - dom=[] - weekday, next_total_day=monthrange(year, next_month) - next_time_start='2014-%s-01 00:00:00'%(str(next_month).zfill(2)) - next_time_stop='2014-%s-%s 23:59:59'%(str(next_month).zfill(2),next_total_day) - dom.append(['time_start','>=', next_time_start]) - dom.append(['time_stop','<=',next_time_stop]) - next_total=len(get_model("clinic.hd.case").search(dom)) - - items={ - 'topic1': { + items={} + items['topic1']={ 'month': month_str, 'amount': crr_total, - 'date_from': crr_time_start[0:10], - 'date_to': crr_time_stop[0:10], - }, - 'topic2': - { + 'date_from': time_start[0:10], + 'date_to': time_stop[0:10], + 'link': True, + } + + # number patient from previous month + dom=[] + weekday, prev_total_day=monthrange(prev_year, prev_month) + #time_start='%s-%s-01'%(prev_year,str(prev_month).zfill(2)) + time_stop='%s-%s-%s'%(prev_year,str(prev_month).zfill(2),prev_total_day) + #dom.append(['reg_date','>=', time_start]) + dom.append(['reg_date','<=',time_stop]) + npatient=len(get_model("clinic.patient").search(dom)) + items['topic2']={ 'month': prev_month_str, - 'amount': prev_total, - 'date_from': prev_time_start[0:10], - 'date_to': prev_time_stop[0:10], - }, - 'topic3': - { - 'month': month_str, - 'amount': next_total, - 'date_from': next_time_start[0:10], - 'date_to': next_time_stop[0:10], - }, - 'topic4': - { - 'month': month_str, - 'amount': 'N/A', + 'amount': npatient or 0.0, 'date_from': '', 'date_to': '', - }, - 'topic5': - { + 'link': False, + } + + # new patient of this month + dom=[] + weekday, crr_total_day=monthrange(prev_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) + new_patients=db.query("select id, name, note from clinic_patient where active=true and create_time >=%s and create_time <=%s",time_start,time_stop) + items['topic3']={ + 'month': month_str, + 'amount': len(new_patients) or 0.0, + 'date_from': '', + 'date_to': '', + 'link': False, + } + + # number for patient who resign for this 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) + resign_patients=db.query("select id, name, note from clinic_patient where active=false and write_time >=%s and write_time <=%s",time_start,time_stop) + items['topic4']={ + 'month': month_str, + 'amount': len(resign_patients) or 0.0, + 'date_from': '', + 'date_to': '', + 'link': False, + } + # all patient who are in hospital now + dom=[] + weekday, crr_total_day=monthrange(year, crr_month) + time_stop='%s-%s-%s'%(year,str(crr_month).zfill(2),crr_total_day) + npatients=db.query("select id, name, note from clinic_patient where active=true and reg_date <=%s",time_stop) + items['topic5']={ 'month': next_month_str, - 'amount': 'N/A', + 'amount': len(npatients), 'date_from': '', 'date_to': '', - }, - 'topic6': - { + 'link': False, + } + + npatients=get_model("clinic.patient").search([['type','=','sc']]) + items['topic6']={ 'month': '', - 'amount': '', + 'amount': len(npatients), 'date_from': '', 'date_to': '', - }, - 'topic7': - { + 'link': False, + } + npatients=get_model("clinic.patient").search([['type','=','nhso']]) + items['topic7']={ 'month':'', - 'amount': '', + 'amount': len(npatients), 'date_from': '', 'date_to': '', - }, - 'topic8': - { + 'link': False, + } + npatients=get_model("clinic.patient").search([['type','in',['personal','others']]]) + items['topic8']={ 'month': '', - 'amount': '', + 'amount': len(npatients), 'date_from': '', 'date_to': '', - }, + 'link': False, } lines=[] @@ -134,28 +155,32 @@ class ReportHDCaseSummary(Model): lines.append(line) index+=1 - new_pt_lines=[] - for i in range(3): - new_pt_lines.append({ - 'no': i+1, - 'name': 'xxxxx', - 'note': '', + new_patient_lines=[] + index=1 + for new_patient in new_patients: + new_patient_lines.append({ + 'no': index, + 'name': new_patient['name'] or "", + 'note': new_patient['note'] or "", }) + index+=1 - resign_pt_lines=[] - for i in range(5): - resign_pt_lines.append({ - 'no': i+1, - 'name': 'xxxxx', - 'note': '', + resign_patient_lines=[] + index=1 + for resign_patient in resign_patients: + resign_patient_lines.append({ + 'no': index, + 'name': resign_patient['name'], + 'note': resign_patient['note'], }) + index+=1 data={ 'month': month_str, 'year': year, 'lines': lines, - 'new_pt_lines': new_pt_lines, - 'resign_pt_lines': resign_pt_lines, + 'new_patient_lines': new_patient_lines, + 'resign_patient_lines': resign_patient_lines, 'company_name': company_name, } return data diff --git a/netforce_clinic/models/utils.py b/netforce_clinic/models/utils.py index 826c402..77bb040 100644 --- a/netforce_clinic/models/utils.py +++ b/netforce_clinic/models/utils.py @@ -5,6 +5,15 @@ DAYS={ 'th_TH': ['จันทร์', 'อังคาร', 'พุธ', 'พ MONTHS={ 'th_TH': [None, 'มกราคม', 'กุมภาพันธ์', 'มีนาคม', 'เมษายน', 'พฤษภาคม', 'มิถุนายน', 'กรกฎาคม', 'สิงหาคม', 'กันยายน', 'ตุลาคม', 'พฤศจิกายน', 'ธันวาคม'] , 'en_US': [None, 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] } + +PATIENT_TYPE={ + "mg":"Medical Government", + "sc":"ปกส.", + "nhso":"สปกส.", + "personal": "จ่ายเอง", + "others": "อื่นๆ", +} + TOPICS={ 'topic1': {'name': 'จำนวนครั้งการทำ Hemodialysis', 'unit': 'ครั้ง'}, 'topic2': {'name': 'จำนวนผู้ป่วยยกมาจากเดือน', 'unit': 'คน'}, diff --git a/netforce_clinic/templates/report_hd_case_detail.hbs b/netforce_clinic/templates/report_hd_case_detail.hbs index 5985b4b..d1f7a95 100644 --- a/netforce_clinic/templates/report_hd_case_detail.hbs +++ b/netforce_clinic/templates/report_hd_case_detail.hbs @@ -1,11 +1,11 @@
-

Detail of the Hemodialysis

-

[{{company_name}}]

+

รายละเอียดการทำ Hemodialysis

+

ศูนย์ไตเทียมราชวัตร {{company_name}}

{{#if same_date}} - As at {{fmt_date date_from}} + ณ วันที่ {{fmt_date date_from}} {{else}} - From {{fmt_date date_from}} to {{fmt_date date_to}} + ตั้งแต่ {{fmt_date date_from}} ถึง {{fmt_date date_to}} {{/if}}

@@ -13,28 +13,25 @@ - Cycle + รอบ - Patient + ผู้ป่วย - Patient Type + ประเภท - HD Fee + ค่าธรรมเนียม - RC.No + HD.No Dialyzer - Doctor - - - Nurse + หมอ @@ -49,7 +46,7 @@ {{/if}} {{#if no_patient}} - TOTAL + ทั้งหมด {{no_patient}} {{else}} @@ -64,13 +61,11 @@ {{rc_no}} {{dialyzer_number}} {{doctor_name}} - {{nurse_name}} {{/each}} - diff --git a/netforce_clinic/templates/report_hd_case_summary.hbs b/netforce_clinic/templates/report_hd_case_summary.hbs index da047d0..4ab98d0 100644 --- a/netforce_clinic/templates/report_hd_case_summary.hbs +++ b/netforce_clinic/templates/report_hd_case_summary.hbs @@ -23,7 +23,11 @@ {{topic}} {{month}} เท่ากับ - {{amount}} + {{#if link}} + {{amount}} + {{else}} + {{amount}} + {{/if}} {{unit}} {{/each}} @@ -35,15 +39,11 @@ - - - {{#each new_pt_lines}} + {{#each new_patient_lines}} - - - + {{/each}} @@ -77,15 +77,11 @@

รายชื่อผู้ป่วยรับใหม่

{{no}}{{name}}{{note}}{{no}}. {{name}} {{note}}
- - - {{#each resign_pt_lines}} + {{#each resign_patient_lines}} - - - + {{/each}}

รายชื่อผู้ป่วยจำหน่าย

{{no}}{{name}}{{note}}{{no}}. {{name}} {{note}}