From 27bf15311fb602ff44eb7a02f60666483924383e Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Mon, 10 Nov 2014 18:33:01 +0700 Subject: [PATCH] xxxx --- .../clinic_report_discontinue_patient.xml | 4 +- .../layouts/clinic_report_new_patient.xml | 4 +- netforce_clinic/models/patient.py | 2 +- netforce_clinic/models/personal_categ.py | 6 +++ .../models/report_discontinue_patient.py | 35 ++++++++++++++ .../models/report_hd_case_summary.py | 6 +-- .../models/report_medical_summary.py | 46 ++++++++++++++++--- netforce_clinic/models/report_new_patient.py | 32 +++++++++++++ .../templates/report_discontinue_patient.hbs | 12 +++-- .../templates/report_medical_summary.hbs | 18 ++++---- .../templates/report_new_patient.hbs | 42 +++++++++-------- 11 files changed, 159 insertions(+), 48 deletions(-) diff --git a/netforce_clinic/layouts/clinic_report_discontinue_patient.xml b/netforce_clinic/layouts/clinic_report_discontinue_patient.xml index 95478a3..27869f8 100644 --- a/netforce_clinic/layouts/clinic_report_discontinue_patient.xml +++ b/netforce_clinic/layouts/clinic_report_discontinue_patient.xml @@ -1,5 +1,3 @@
- - - + diff --git a/netforce_clinic/layouts/clinic_report_new_patient.xml b/netforce_clinic/layouts/clinic_report_new_patient.xml index eda9518..bcfd736 100644 --- a/netforce_clinic/layouts/clinic_report_new_patient.xml +++ b/netforce_clinic/layouts/clinic_report_new_patient.xml @@ -1,5 +1,3 @@
- - - + diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py index 10f98ac..9666265 100644 --- a/netforce_clinic/models/patient.py +++ b/netforce_clinic/models/patient.py @@ -105,7 +105,7 @@ class Patient(Model): _defaults={ - "type": "mg", + "type": "sc", "reg_date": lambda *a: time.strftime("%Y-%m-%d"), "number": _get_number, "company_id": lambda *a: get_active_company(), diff --git a/netforce_clinic/models/personal_categ.py b/netforce_clinic/models/personal_categ.py index 4928687..b8dc716 100644 --- a/netforce_clinic/models/personal_categ.py +++ b/netforce_clinic/models/personal_categ.py @@ -1,4 +1,5 @@ from netforce.model import Model, fields +from netforce.access import get_active_company class PersonalCategory(Model): _name="clinic.personal.categ" @@ -8,6 +9,11 @@ class PersonalCategory(Model): "name": fields.Char("Name",required=True,search=True), "type": fields.Selection([("doctor","Doctor"),("nurse","Nurse"),('other','Other')],"Type"), 'parent_id': fields.Many2One("clinic.personal.categ","Parent"), + 'company_id': fields.Many2One("company","Company"), + } + + _defaults={ + "company_id": lambda *a: get_active_company(), } PersonalCategory.register() diff --git a/netforce_clinic/models/report_discontinue_patient.py b/netforce_clinic/models/report_discontinue_patient.py index c8a6b66..6e5c749 100644 --- a/netforce_clinic/models/report_discontinue_patient.py +++ b/netforce_clinic/models/report_discontinue_patient.py @@ -1,8 +1,11 @@ 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 ReportDiscontinuePatient(Model): _name="clinic.report.discontinue.patient" _string="Report Discontinue Patient" @@ -19,10 +22,42 @@ class ReportDiscontinuePatient(Model): def get_report_data(self,ids,context={}): company_id=get_active_company() company=get_model('company').browse(company_id) + year, month=time.strftime("%Y-%m").split("-") + if ids: + obj=self.browse(ids)[0] + year,month,day=obj.date.split("-") + # new patient of this month + year=int(year) + month=int(month) + dom=[] + weekday, total_day=monthrange(year, month) + dom=[] + time_start='%s-%s-01'%(year,str(month).zfill(2)) + time_stop='%s-%s-%s'%(year,str(month).zfill(2),total_day) + dom.append(['resign_date','>=',time_start]) + dom.append(['resign_date','<=',time_stop]) + dom.append(['active','=',False]) + records=get_model('clinic.patient').search_browse(dom) + lines=[] + no=1 + for record in records: + lines.append({ + 'no': no, + 'pid': record.id, + 'name': record.name or '', + 'note': record.note or '', + }) + no+=1 + + month_str=utils.MONTHS['th_TH'][month] data={ 'company_name': company.name or "", 'parent_company_name': company.parent_id.name or "", + 'lines': lines, + 'month': month_str, + 'year': year, } + return data ReportDiscontinuePatient.register() diff --git a/netforce_clinic/models/report_hd_case_summary.py b/netforce_clinic/models/report_hd_case_summary.py index 22d278a..5ca7906 100644 --- a/netforce_clinic/models/report_hd_case_summary.py +++ b/netforce_clinic/models/report_hd_case_summary.py @@ -4,7 +4,6 @@ import urllib.parse as urllib from datetime import datetime from calendar import monthrange from netforce.model import Model, fields, get_model -from netforce.database import get_connection from netforce.access import get_active_company from . import utils @@ -23,7 +22,6 @@ class ReportHDCaseSummary(Model): } def get_report_data(self,ids,context={}): - db=get_connection() company_id=get_active_company() company=get_model("company").browse(company_id) @@ -218,8 +216,8 @@ class ReportHDCaseSummary(Model): 'month': month_str, 'year': year, 'lines': lines, - 'new_patient_lines': new_patient_lines, - 'resign_patient_lines': resign_patient_lines, + #'new_patient_lines': new_patient_lines, + #'resign_patient_lines': resign_patient_lines, 'company_name': company.name or "", 'parent_company_name': company.parent_id.name or "", } diff --git a/netforce_clinic/models/report_medical_summary.py b/netforce_clinic/models/report_medical_summary.py index 8312ebc..c7156e5 100644 --- a/netforce_clinic/models/report_medical_summary.py +++ b/netforce_clinic/models/report_medical_summary.py @@ -31,24 +31,58 @@ class ReportMedicalSummary(Model): 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=[] + products={} + for prod in get_model("product").search_browse([['type','=','stock']]): + products[prod.code]={} + for patient_type in ('sc','nhso','personal'): + products[prod.code][patient_type]={ + 'qty': 0, + 'name': prod.name, + 'code': prod.code, + } + for hd_case in get_model('clinic.hd.case').search_browse(dom): - print("="*30) + patient_type=hd_case.patient_id.type for line in hd_case.lines: prod=line.product_id - if line.type=='fee': - continue - if prod.type=='service': + if line.type=='fee' or prod.type=='service': continue + products[prod.code][patient_type]['qty']+=line.qty + + lines=[] + + for prod, records in products.items(): + line={ + 'prod_name': records['sc']['name'], # XXX + } + for patient_type in ('sc','nhso','personal'): + line.update({ + patient_type: records[patient_type]['qty'], + }) + lines.append(line) company_id=get_active_company() company=get_model('company').browse(company_id) + month_str=utils.MONTHS['th_TH'][month] + + lines=sorted(lines, key=lambda x: x['prod_name']) + titles={ + 'prod_name': 'ชื่อยา', + 'sc': utils.PATIENT_TYPE['sc'], + 'nhso': utils.PATIENT_TYPE['nhso'], + 'personal': utils.PATIENT_TYPE['personal'], + } data={ 'company_name': company.name or "", 'parent_company_name': company.parent_id.name or "", + 'titles': titles, + 'lines': lines, + 'month': month_str, + 'year': year, } + data.update(titles) + return data ReportMedicalSummary.register() diff --git a/netforce_clinic/models/report_new_patient.py b/netforce_clinic/models/report_new_patient.py index 5278f09..763eec4 100644 --- a/netforce_clinic/models/report_new_patient.py +++ b/netforce_clinic/models/report_new_patient.py @@ -1,8 +1,11 @@ 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 ReportNewPatient(Model): _name="clinic.report.new.patient" _string="Report New Patient" @@ -19,9 +22,38 @@ class ReportNewPatient(Model): def get_report_data(self,ids,context={}): company_id=get_active_company() company=get_model('company').browse(company_id) + year, month=time.strftime("%Y-%m").split("-") + if ids: + obj=self.browse(ids)[0] + year,month,day=obj.date.split("-") + # new patient of this month + year=int(year) + month=int(month) + dom=[] + weekday, total_day=monthrange(year, month) + time_start='%s-%s-01'%(year,str(month).zfill(2)) + time_stop='%s-%s-%s'%(year,str(month).zfill(2),total_day) + dom.append(['reg_date','>=',time_start]) + dom.append(['reg_date','<=',time_stop]) + records=get_model('clinic.patient').search_browse(dom) + lines=[] + no=1 + for record in records: + lines.append({ + 'no': no, + 'name': record.name or '', + 'pid': record.id, + 'note': record.note or '', + }) + no+=1 + + month_str=utils.MONTHS['th_TH'][month] data={ 'company_name': company.name or "", 'parent_company_name': company.parent_id.name or "", + 'lines': lines, + 'month': month_str, + 'year': year, } return data diff --git a/netforce_clinic/templates/report_discontinue_patient.hbs b/netforce_clinic/templates/report_discontinue_patient.hbs index 4fcc918..b6d56a5 100644 --- a/netforce_clinic/templates/report_discontinue_patient.hbs +++ b/netforce_clinic/templates/report_discontinue_patient.hbs @@ -7,6 +7,7 @@ ประจำเดือน {{month}} {{year}} +{{#if lines}} @@ -16,12 +17,17 @@ {{#each lines}} - - - + + + {{/each}}
#
{{no}} + {{view "link" string=name action="clinic_patient" action_options="mode=form" active_id=pid}} + {{note}}
+{{else}} + No items to display. +{{/if}} diff --git a/netforce_clinic/templates/report_medical_summary.hbs b/netforce_clinic/templates/report_medical_summary.hbs index cc52b83..0386d71 100644 --- a/netforce_clinic/templates/report_medical_summary.hbs +++ b/netforce_clinic/templates/report_medical_summary.hbs @@ -9,20 +9,18 @@ - - - - - + + + + {{#each lines}} - - - - - + + + + {{/each}} diff --git a/netforce_clinic/templates/report_new_patient.hbs b/netforce_clinic/templates/report_new_patient.hbs index 63f045d..9d8384a 100644 --- a/netforce_clinic/templates/report_new_patient.hbs +++ b/netforce_clinic/templates/report_new_patient.hbs @@ -7,21 +7,27 @@ ประจำเดือน {{month}} {{year}} -
ยาประเภทการรักษาucซื้อรวม{{prod_name}}{{sc}}{{nhso}}{{personal}}
{{prod_name}}{{sc}}{{nhso}}{{personal}}
- - - - - - - {{#each lines}} - - - - - - {{/each}} - - - -
#ชื่อหมายเหตุ
{{no}}{{name}}{{note}}
+{{#if lines}} + + + + + + + + {{#each lines}} + + + + + + {{/each}} + + + +
#ชื่อหมายเหตุ
{{no}} + {{view "link" string=name action="clinic_patient" action_options="mode=form" active_id=pid}} + {{note}}
+{{else}} + No items to display. +{{/if}}