From c933fb12805c97f4bae4f3d01a270f58450a419d Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Mon, 10 Nov 2014 12:10:39 +0700 Subject: [PATCH] report hd summary --- .../actions/clinic_report_hd_case_summary.xml | 2 +- .../layouts/clinic_hd_case_search.xml | 1 + .../layouts/clinic_patient_form.xml | 1 + .../layouts/clinic_patient_list.xml | 1 + .../layouts/clinic_report_medical_summary.xml | 4 +- netforce_clinic/models/patient.py | 6 +- .../models/report_hd_case_summary.py | 138 +++++++++++------- .../models/report_medical_summary.py | 26 +++- .../templates/report_hd_case_summary.hbs | 10 +- 9 files changed, 130 insertions(+), 59 deletions(-) diff --git a/netforce_clinic/actions/clinic_report_hd_case_summary.xml b/netforce_clinic/actions/clinic_report_hd_case_summary.xml index 6b99d6b..30dd520 100644 --- a/netforce_clinic/actions/clinic_report_hd_case_summary.xml +++ b/netforce_clinic/actions/clinic_report_hd_case_summary.xml @@ -1,5 +1,5 @@ - HD Report Summary + HD Case Report Summary report clinic.report.hd.case.summary report_hd_case_summary diff --git a/netforce_clinic/layouts/clinic_hd_case_search.xml b/netforce_clinic/layouts/clinic_hd_case_search.xml index 5e28e08..aed7f9f 100644 --- a/netforce_clinic/layouts/clinic_hd_case_search.xml +++ b/netforce_clinic/layouts/clinic_hd_case_search.xml @@ -4,4 +4,5 @@ + diff --git a/netforce_clinic/layouts/clinic_patient_form.xml b/netforce_clinic/layouts/clinic_patient_form.xml index 79e3378..f2041f8 100644 --- a/netforce_clinic/layouts/clinic_patient_form.xml +++ b/netforce_clinic/layouts/clinic_patient_form.xml @@ -88,6 +88,7 @@ + diff --git a/netforce_clinic/layouts/clinic_patient_list.xml b/netforce_clinic/layouts/clinic_patient_list.xml index 776bce0..2e62a45 100644 --- a/netforce_clinic/layouts/clinic_patient_list.xml +++ b/netforce_clinic/layouts/clinic_patient_list.xml @@ -6,6 +6,7 @@ + diff --git a/netforce_clinic/layouts/clinic_report_medical_summary.xml b/netforce_clinic/layouts/clinic_report_medical_summary.xml index 3486eac..f8a9445 100644 --- a/netforce_clinic/layouts/clinic_report_medical_summary.xml +++ b/netforce_clinic/layouts/clinic_report_medical_summary.xml @@ -1,5 +1,3 @@
- - - + diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py index 9dc156e..10f98ac 100644 --- a/netforce_clinic/models/patient.py +++ b/netforce_clinic/models/patient.py @@ -76,11 +76,12 @@ class Patient(Model): "hd_cases": fields.One2Many("clinic.hd.case","patient_id","HD Cases"), "partner_id": fields.Many2One("partner","Contact"), "dialyzers": fields.One2Many("clinic.dialyzer","patient_id","Dialyzers"), - "active":fields.Boolean("Mark as discountinue"), + "active":fields.Boolean("Uncheck as discountinue", search=True), 'note': fields.Text("Note"), 'categ_id': fields.Many2One("clinic.patient.categ","Category"), 'doctor_id': fields.Many2One("clinic.personal","Doctor",domain=[['type','=','doctor']]), "documents": fields.One2Many("document","related_id","Documents"), + 'resign_date': fields.Date("Resign Date"), } def _get_number(self,context={}): @@ -197,6 +198,9 @@ class Patient(Model): super().delete(ids) def write(self,ids,vals,**kw): + if 'active' in vals.keys(): + if not vals['active']: + vals['resign_date']=time.strftime("%Y-%m-%d") for obj in self.browse(ids): partner_id=obj.partner_id if not partner_id: diff --git a/netforce_clinic/models/report_hd_case_summary.py b/netforce_clinic/models/report_hd_case_summary.py index 8a89807..22d278a 100644 --- a/netforce_clinic/models/report_hd_case_summary.py +++ b/netforce_clinic/models/report_hd_case_summary.py @@ -1,4 +1,5 @@ import time +import urllib.parse as urllib from datetime import datetime from calendar import monthrange @@ -47,103 +48,140 @@ class ReportHDCaseSummary(Model): 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("'","\"") + + # number of hd case of this month dom=[] 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) - dom.append(['time_start','>=', time_start]) - dom.append(['time_stop','<=',time_stop]) - dom.append(['state','=','completed']) + 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)) items={} items['topic1']={ 'month': month_str, - 'amount': crr_total, - 'date_from': time_start[0:10], - 'date_to': time_stop[0:10], - 'link': True, + 'qty': crr_total or 0, + 'action': 'clinic_hd_case', + 'action_options': 'mode=list&search_domain=%s'%replace_quote('%s'%dom), } - # number patient from previous month + # number of patient from previous 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)) + dom=replace_quote('%s'%dom) items['topic2']={ 'month': prev_month_str, - 'amount': npatient or 0.0, - 'date_from': '', - 'date_to': '', - 'link': False, + 'qty': npatient or 0, + 'action': 'clinic_patient', + 'action_options': 'mode=list&search_domain=%s'%dom, } # 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 and company_id=%s",time_start,time_stop,company_id) + 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['topic3']={ 'month': month_str, - 'amount': len(new_patients) or 0.0, - 'date_from': '', - 'date_to': '', - 'link': False, + 'qty': len(new_patients) or 0, + 'action': 'clinic_patient', + 'action_options': 'mode=list&search_domain=%s'%dom, } # 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 and company_id=%s",time_start,time_stop,company_id) + 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['topic4']={ 'month': month_str, - 'amount': len(resign_patients) or 0.0, - 'date_from': '', - 'date_to': '', - 'link': False, + 'qty': len(resign_patients) or 0, + 'action': 'clinic_patient', + 'action_options': 'mode=list&search_domain=%s&tab_no=1'%dom, } - # all patient who are in hospital now + + # 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) - npatients=db.query("select id, name, note from clinic_patient where active=true and reg_date <=%s and company_id=%s",time_stop,company_id) + dom.append(['reg_date','<=',time_stop]) + total_patient=get_model('clinic.patient').search_browse(dom) + dom=replace_quote('%s'%dom) items['topic5']={ 'month': next_month_str, - 'amount': len(npatients), - 'date_from': '', - 'date_to': '', - 'link': False, + 'qty': len(total_patient) or 0, + 'action': 'clinic_patient', + 'action_options': 'mode=list&search_domain=%s'%dom, } - npatients=get_model("clinic.patient").search([['type','=','sc']]) + # all patient who are sc in hospital on select 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(['reg_date','>=',time_start]) + dom.append(['reg_date','<=',time_stop]) + dom.append(['type','=','sc']) + npatients=get_model("clinic.patient").search(dom) + dom=replace_quote('%s'%dom) items['topic6']={ 'month': '', - 'amount': len(npatients), - 'date_from': '', - 'date_to': '', - 'link': False, + 'qty': len(npatients), + 'action': 'clinic_patient', + 'action_options': 'mode=list&search_domain=%s&tab_no=2'%dom, } - npatients=get_model("clinic.patient").search([['type','=','nhso']]) + + # all patient who are nhso in hospital on select 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(['reg_date','>=',time_start]) + dom.append(['reg_date','<=',time_stop]) + dom.append(['type','=','nhso']) + npatients=get_model("clinic.patient").search(dom) + dom=replace_quote('%s'%dom) items['topic7']={ 'month':'', - 'amount': len(npatients), - 'date_from': '', - 'date_to': '', - 'link': False, + 'qty': len(npatients), + 'action': 'clinic_patient', + 'action_options': 'mode=list&search_domain=%s&tab_no=3'%dom, } - npatients=get_model("clinic.patient").search([['type','in',['personal','others']]]) + + # all patient who are other in hospital on select 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(['reg_date','>=',time_start]) + dom.append(['reg_date','<=',time_stop]) + dom.append(['type','=','personal']) + npatients=get_model("clinic.patient").search(dom) + dom=replace_quote('%s'%dom) items['topic8']={ 'month': '', - 'amount': len(npatients), - 'date_from': '', - 'date_to': '', - 'link': False, + 'qty': len(npatients), + 'action': 'clinic_patient', + 'action_options': 'mode=list&search_domain=%s&tab_no=4'%dom, } - lines=[] index=1 for item in items: diff --git a/netforce_clinic/models/report_medical_summary.py b/netforce_clinic/models/report_medical_summary.py index 6eee771..8312ebc 100644 --- a/netforce_clinic/models/report_medical_summary.py +++ b/netforce_clinic/models/report_medical_summary.py @@ -1,7 +1,9 @@ import time +from calendar import monthrange from netforce.model import Model,fields,get_model from netforce.access import get_active_company +from . import utils class ReportMedicalSummary(Model): _name="clinic.report.medical.summary" @@ -17,8 +19,30 @@ class ReportMedicalSummary(Model): } def get_report_data(self,ids,context={}): - obj=self.browse(ids)[0] + date=time.strftime("%Y-%m-%d") + defaults=context.get('defaults') + if defaults: + date=defaults['date'] + year=int(date[0:4]) + month=int(date[5:7]) + weekday, total_day=monthrange(year, month) + + dom=[] + dom.append([['state','=','completed']]) + dom.append([['time_start','>=','%s-%s-01 00:00:00'%(year,month)]]) + dom.append([['time_stop','<=','%s-%s-%s 23:59:59'%(year,month,total_day)]]) + print("dom ", dom) + products=[] + for hd_case in get_model('clinic.hd.case').search_browse(dom): + print("="*30) + for line in hd_case.lines: + prod=line.product_id + if line.type=='fee': + continue + if prod.type=='service': + continue + company_id=get_active_company() company=get_model('company').browse(company_id) data={ diff --git a/netforce_clinic/templates/report_hd_case_summary.hbs b/netforce_clinic/templates/report_hd_case_summary.hbs index 2f057a0..7c9d5c9 100644 --- a/netforce_clinic/templates/report_hd_case_summary.hbs +++ b/netforce_clinic/templates/report_hd_case_summary.hbs @@ -23,10 +23,14 @@ {{topic}} {{month}} เท่ากับ - {{#if link}} - {{amount}} + {{#if qty}} + + {{view "link" string=qty action=action action_options=action_options}} + {{else}} - {{amount}} + + 0 + {{/if}} {{unit}}