From 973fafa5d408fa0ea9db7e79934ae1fb46053b47 Mon Sep 17 00:00:00 2001 From: "chayut.s" Date: Mon, 20 Oct 2014 16:03:17 +0700 Subject: [PATCH] report --- .../layouts/clinic_hd_case_form.xml | 4 +- netforce_clinic/models/__init__.py | 5 +- netforce_clinic/models/hd_case.py | 30 ++-- netforce_clinic/models/report_hd_detail.py | 152 +++++++++++++++++ netforce_clinic/models/report_hd_madical.py | 153 ++++++++++++++++++ netforce_clinic/models/report_hd_summary.py | 145 +++++++++++++++++ netforce_clinic/models/visit.py | 2 +- 7 files changed, 475 insertions(+), 16 deletions(-) create mode 100644 netforce_clinic/models/report_hd_detail.py create mode 100644 netforce_clinic/models/report_hd_madical.py create mode 100644 netforce_clinic/models/report_hd_summary.py diff --git a/netforce_clinic/layouts/clinic_hd_case_form.xml b/netforce_clinic/layouts/clinic_hd_case_form.xml index d03cdb9..7bdc242 100644 --- a/netforce_clinic/layouts/clinic_hd_case_form.xml +++ b/netforce_clinic/layouts/clinic_hd_case_form.xml @@ -26,8 +26,10 @@ - + + + diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py index a58cdde..51e1022 100644 --- a/netforce_clinic/models/__init__.py +++ b/netforce_clinic/models/__init__.py @@ -30,8 +30,9 @@ from . import file_sheet from . import cycle from . import gen_visit from . import gen_visit_line -from . import report_hd_dialy -from . import report_hd_monthly +from . import report_hd_detail +from . import report_hd_summary from . import payment from . import payment_line from . import input_data +from . import report_hd_madical diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index 95df288..5a32949 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -1,6 +1,6 @@ import time -from datetime import datetime +from datetime import datetime from netforce.model import Model, fields, get_model from netforce.utils import get_data_path from netforce.access import get_active_user,set_active_user @@ -22,6 +22,7 @@ class HDcase(Model): res[obj.id]=total_time return res + _fields={ "number": fields.Char("Number",required=True,search=True), "time_start": fields.DateTime("Time start",required=True,search=True), @@ -41,9 +42,9 @@ class HDcase(Model): "epo_tn" : fields.Char("EpoTn (Drug name)"), "epo_unit" : fields.Integer("EpoUnit (Unit of Used drug)"), "hct": fields.Integer("HCT %", required=True), + "hct_alert" : fields.Char("",function="onchange_hct",readonly=True,function_multi=True), "check_goverment_pay" : fields.Boolean("The Government Pay"), "check_personal_pay" : fields.Boolean("Pay yourself"), - "hct": fields.Integer("HCT %(>39)"), "state": fields.Selection([("draft","Draft"),("in_progress","In Progress"),("completed","Completed"),("discountinued","Discountinued"),("in_completed","In completed")],"Status",required=True), "dialyzers": fields.One2Many("clinic.dialyzer.line","hd_case_id","Dialyzers"), "lines": fields.One2Many("clinic.hd.case.line","hd_case_id","Lines"), @@ -95,8 +96,7 @@ class HDcase(Model): "time_stop": lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"), 'nurse_id': _get_nurse, "number": _get_number, - "company_id": lambda *a: get_active_company(), - "fee": 1500, + "company_id": lambda *a: get_active_company() } _order="date desc,number desc" @@ -171,13 +171,6 @@ class HDcase(Model): data['total']=total return data - def onchange_hct(self,context={}): - data=context['data'] - hct=data['hct'] - if(hct<=39): - data['hct']=0 - return data - def cancelled(self,ids,context={}): obj=self.browse(ids)[0] obj.write({" state":"cancelled"}) @@ -460,6 +453,19 @@ class HDcase(Model): else: data['fee']=0.0 return data + + def onchange_hct(self,context={}): + data=context['data'] + hct_alert=data.get("hct","") + if(hct_alert<=36): + data['hct_alert']="Reimbursement of medicines : 1,125/Week" + elif(36<=hct_alert<=39): + data['hct_alert']="Reimbursement of medicines : 750/Week" + elif(hct_alert>39): + data['hct_alert']="Can not be drawn" + else: + data['hct_alert']="" + return data def undo(self,ids,context={}): obj=self.browse(ids)[0] @@ -484,6 +490,6 @@ class HDcase(Model): 'active_id': obj.id, }, 'flash': '%s has been undo'%obj.number, - } + } HDcase.register() diff --git a/netforce_clinic/models/report_hd_detail.py b/netforce_clinic/models/report_hd_detail.py new file mode 100644 index 0000000..9ee6aec --- /dev/null +++ b/netforce_clinic/models/report_hd_detail.py @@ -0,0 +1,152 @@ +import time +import pprint + +from netforce.model import Model, fields, get_model + +class ReportHDDetail(Model): + _name="clinic.report.hd.detail" + _string="Hemodialysis Report Detail" + _transient=True + + _fields={ + "patient_id" : fields.Many2One("clinic.patient","Patient"), + "doctor_id" : fields.Many2One("clinic.doctor","Doctor"), + "nurse_id" : fields.Many2One("clinic.nurse","Nurse"), + "date_from": fields.Date("From"), + "date_to": fields.Date("To"), + "cycle_id": fields.Many2One("clinic.cycle","Cycle"), + } + + _defaults={ + 'date_from': lambda *a: time.strftime("%Y-%m-%d"), + 'date_to': lambda *a: time.strftime("%Y-%m-%d"), + } + + _order="cycle_id desc" + + + def get_report_data(self,ids,context={}): + # context=> dict + # inside context => keys => defaults => type => dict + # dict => key: value => '', 1, [], {} + # context['default'] => defaults(dict) => key => inside key => value => '2014-10-22' + date_from=time.strftime("%Y-%m-%d") + date_to=time.strftime("%Y-%m-%d") + # print('date_from ',date_from) + defaults=context.get("defaults") + if defaults: + if defaults.get("date_from"): + date_from=defaults['date_from'] + if defaults.get("date_to"): + date_to=defaults['date_to'] + # date_to=context['date_to'] + # default => key => dataults + # date_from=context['date_from'] + # print(context['date_from']) + #'2014-10-13' + # print('date_from ',date_from) + # print('date_to ',date_to) + PATIENT_TYPE={ + "mg":"Medical Government", + "sc":"Social Security", + "nhso":"NHSO (30฿)", + "personal": "Personal", + "others": "Others", + } + + dom=[] + dom.append(['state','=','completed']) + if ids: + obj=self.browse(ids)[0] + if obj.date_from: + date_from=obj.date_from + if obj.date_to: + date_to=obj.date_to + if obj.cycle_id: + dom.append([ + 'cycle_id','=',obj.cycle_id.id, + ]) + if obj.patient_id: + dom.append([ + 'patient_id','=',obj.patient_id.id, + ]) + if obj.doctor_id: + dom.append([ + 'doctor_id','=',obj.doctor_id.id, + ]) + + dom.append(['time_start', ">=", date_from+" 00:00:00"]) + dom.append(['time_stop',"<=", date_to+" 23:59:59"]) + lines=[] + cycles=[] + index=0 + no_patient=0 + for hd_case in get_model("clinic.hd.case").search_browse(dom,order="cycle_id.sequence"): + patient_type=hd_case.patient_id.type + patient_type=PATIENT_TYPE.get(patient_type) + #dialyzer_name=hd_case.dialyzers.id + #dialyzer_name=DIALYZER_NAME.get(dialyzer_name) + cycle_name=hd_case.cycle_id.name or "" + show_cycle=False + if not cycle_name in cycles: + cycles.append(cycle_name) + show_cycle=True + vals={ + 'color': 'success', + 'show_cycle': False, + 'cycle' : "", + 'patient': "", + 'no_patient': no_patient, + 'patient_type' : "", + 'doctor' : "", + 'total' : "", + 'rc_no' : "", + 'dialyzer_name' : "", + 'nurse' : "", + } + lines.append(vals) + no_patient=1 + else: + no_patient+=1 + index+=1 + vals={ + 'show_cycle': show_cycle, + 'cycle' : cycle_name, + 'patient': hd_case.patient_id.name, + 'patient_type' : patient_type, + 'no_patient': 0, + 'doctor' : hd_case.doctor_id.name, + 'total' : hd_case.total, + 'rc_no' : hd_case.number, + 'dialyzer_name' : 'DZ-xxx', + 'nurse' : hd_case.nurse_id.name, + } + lines.append(vals) + + # XXX + if lines: + vals={ + 'color': 'success', + 'show_cycle': False, + 'cycle' : "", + 'patient': "", + 'no_patient': no_patient, + 'patient_type' : "", + 'doctor' : "", + 'total' : "", + 'rc_no' : "", + 'dialyzer_name' : "", + 'nurse' : "", + } + lines.append(vals) + #XXX + del lines[0] + data={ + 'lines': lines, + 'same_date': date_from==date_to, + 'date_from': date_from, + 'date_to': date_to, + } + return data + +ReportHDDetail.register() diff --git a/netforce_clinic/models/report_hd_madical.py b/netforce_clinic/models/report_hd_madical.py new file mode 100644 index 0000000..b316a13 --- /dev/null +++ b/netforce_clinic/models/report_hd_madical.py @@ -0,0 +1,153 @@ +import time + +from datetime import datetime +from calendar import monthrange +from netforce.model import Model,fields + +class ReportHDMadical(Model): + _name="clinic.report.hd.madical" + _string="Hemodialysis Report Madical Summary" + _transient=True + + _fields={ + "date": fields.Date("Month", required=True), + } + + _defaults={ + 'date': lambda *a: time.strftime("%Y-%m-%d"), + } + + def get_report_data(self,ids,context={}): + date=datetime.now().strftime("%Y-%m-%d") + #datemonth=datetime.now().strftime("%m") + if ids: + obj=self.browse(ids)[0] + date=obj.date + year=int(date[0:4]) + month=int(date[5:7]) + month_str=datetime.strptime(date,'%Y-%m-%d').strftime("%B") + + next_month = str(month + 1) + if next_month == 13: + next_month = 12 + #next_month_str=datetime.strptime(next_month,'%m').strftime("%B") + previous_month = str(month - 1) + if previous_month == 0: + previous_month = 12 + #previous_month_str=datetime.strptime(previous_month,'%m').strftime("%B") + + #madical=get_model("clinic.hd.case.gm.line").search_browse() + #patients_mg=get_model("clinic.patient").search_browse(['type','=','mg']) + + weekday, total_day=monthrange(year, month) + time_start='2014-%s-01 00:00:00'%(month) + time_stop='2014-%s-%s 23:59:59'%(month,total_day) + + dom=[] + dom.append(['state','=','completed']) + dom.append(['time_start','>=',time_start]) + dom.append(['time_stop','<=',time_stop]) + #hd_cases=get_model("clinic.hd.case.gm.line").search_browse(dom) + + lines=[ + { + 'madical' : 'H4', + 'sc': '437', + 'uc': '', + 'buy' : '4', + 'total' : '441', + }, + { + 'madical' : 'H2', + 'sc': '', + 'uc': '', + 'buy' : '', + 'total' : '', + }, + { + 'madical' : 'Epr4', + 'sc': '216', + 'uc': '', + 'buy' : '', + 'total' : '216', + }, + { + 'madical' : 'Epr2', + 'sc': '', + 'uc': '', + 'buy' : '', + 'total' : '', + }, + { + 'madical' : 'Epk4', + 'sc': '70', + 'uc': '', + 'buy' : '', + 'total' : '70', + }, + { + 'madical' : 'Epk2', + 'sc': '', + 'uc': '', + 'buy' : '', + 'total' : '', + }, + { + 'madical' : 'Epg4', + 'sc': '98', + 'uc': '', + 'buy' : '', + 'total' : '98', + }, + { + 'madical' : 'Epg2', + 'sc': '', + 'uc': '', + 'buy' : '', + 'total' : '', + }, + { + 'madical' : 'Rng4', + 'sc': '34', + 'uc': '', + 'buy' : '9', + 'total' : '43', + }, + { + 'madical' : 'Rng2', + 'sc': '', + 'uc': '', + 'buy' : '', + 'total' : '', + }, + { + 'madical' : 'Epi4', + 'sc': '264', + 'uc': '', + 'buy' : '9', + 'total' : '43', + }, + { + 'madical' : 'Epi2', + 'sc': '', + 'uc': '', + 'buy' : '', + 'total' : '', + }, + { + 'madical' : 'Vnf', + 'sc': '', + 'uc': '', + 'buy' : '', + 'total' : '', + }, + ] + + data={ + 'month': month_str, + 'year': year, + 'lines': lines, + } + return data + +ReportHDMadical.register() diff --git a/netforce_clinic/models/report_hd_summary.py b/netforce_clinic/models/report_hd_summary.py new file mode 100644 index 0000000..bd4d8ce --- /dev/null +++ b/netforce_clinic/models/report_hd_summary.py @@ -0,0 +1,145 @@ +import time + +from datetime import datetime +from calendar import monthrange +from netforce.model import Model, fields, get_model + +class ReportHDSummary(Model): + _name="clinic.report.hd.summary" + _string="Hemodialysis Report Summary" + _transient=True + + _fields={ + "date": fields.Date("Month", required=True), + } + + _defaults={ + 'date': lambda *a: time.strftime("%Y-%m-%d"), + } + + def get_report_data(self,ids,context={}): + date=datetime.now().strftime("%Y-%m-%d") + dom=[] + if ids: + obj=self.browse(ids)[0] + date=obj.date + + month=int(date[5:7]) + year=int(date[0:4]) + weekday, total_day=monthrange(year, month) + #date_from="%s-%s-01"%(year,month) + #date_to="%s-%s-%s"%(year,month,total_day) + month_str=datetime.strptime(date,'%Y-%m-%d').strftime("%B") + next_month = str(month + 1) + if next_month == 13: + next_month = 12 + next_month_str=datetime.strptime(next_month,'%m').strftime("%B") + + previous_month = month-1 + if previous_month == 0: + previous_month = 12 + #tip previous_month=str(month-1 == 0 and 12 or month) + previous_month_str=datetime.strptime('%s'%previous_month,'%m').strftime("%B") + + patients=get_model("clinic.patient").search_browse(['type','=','All']) + patients_mg=get_model("clinic.patient").search_browse(['type','=','mg']) + patients_sc=get_model("clinic.patient").search_browse(['type','=','sc']) + patients_nhso=get_model("clinic.patient").search_browse(['type','=','nhso']) + patients_pn=get_model("clinic.patient").search_browse(['type','=','personal']) + + new_patients=len(patients) + + time_start='2014-%s-01'%(month) # 2014-10-20 + time_stop='2014-%s-%s'%(month,total_day) + + dom=[] + dom.append(['state','=','completed']) + dom.append(['time_start','>=',time_start]) + dom.append(['time_stop','<=',time_stop]) + cur_total_case=len(get_model("clinic.hd.case").search(dom)) + + weekday, prev_total_day=monthrange(year, previous_month) + time_start_pre='2014-%s-01'%(previous_month) # 2014-10-20 + time_stop_pre='2014-%s-%s'%(previous_month,prev_total_day) + + dom=[] + dom.append(['state','=','completed']) + dom.append(['time_start','>=',time_start_pre]) + dom.append(['time_stop','<=',time_stop_pre]) + prev_total_case=len(get_model("clinic.hd.case").search(dom)) + + lines=[ + { + 'topic': 'The number of times the Hemodialysis', + 'month': month_str, + 'amount': cur_total_case, + 'date_from': time_start, + 'date_to': time_stop, + }, + { + 'topic':'The number of cases brought', + 'month': previous_month_str, + 'amount': prev_total_case, + 'date_from': time_start_pre, + 'date_to': time_stop_pre, + }, + { + 'topic':'Number of new patients', + 'month': month_str, + 'amount': new_patients, + 'date_from': time_start, + 'date_to': time_stop, + }, + { + 'topic':'Number of patients discharged', + 'month': month_str, + 'amount': 'N/A', + 'date_from': time_start, + 'date_to': time_stop, + }, + { + 'topic':'The number of cases brought', + 'month': next_month_str, + 'amount': 0, + 'date_from': time_start, + 'date_to': time_stop, + }, + { + 'topic':'Number of patients withdrawn Social Security', + 'month': '', + 'amount': len(patients_sc), + 'date_from': "", + 'date_to': "", + }, + { + 'topic':'Number of patients withdrawn Medical Government', + 'month':'', + 'amount': len(patients_mg), + 'date_from': "", + 'date_to': "", + }, + { + 'topic':'Number of patients withdrawn NHSO(30B)', + 'month':'', + 'amount': len(patients_nhso), + 'date_from': "", + 'date_to': "", + }, + { + 'topic':'Many patients pay themselves', + 'month': '', + 'amount': len(patients_pn), + 'date_from': "", + 'date_to': "", + }, + ] + + data={ + 'month': month_str, + 'year': year, + 'lines': lines, + } + #print("data", data) + return data + +ReportHDSummary.register() diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py index af14153..962f045 100644 --- a/netforce_clinic/models/visit.py +++ b/netforce_clinic/models/visit.py @@ -13,7 +13,7 @@ class Visit(Model): _name_field="number" _multi_company=True - def _get_visit_date(self,ids,context): + def _get_visit_date(self,ids,context={}): res={} for obj in self.browse(ids): res[obj.id]=obj.time_start[0:10]