diff --git a/netforce_clinic/actions/clinic_patient_move.xml b/netforce_clinic/actions/clinic_patient_move.xml new file mode 100644 index 0000000..4200bed --- /dev/null +++ b/netforce_clinic/actions/clinic_patient_move.xml @@ -0,0 +1,6 @@ + + Patient Movement + multi_view + clinic.patient.move + clinic_menu + diff --git a/netforce_clinic/actions/report_hdcase_summary.xml b/netforce_clinic/actions/report_hdcase_summary.xml new file mode 100644 index 0000000..9b44bff --- /dev/null +++ b/netforce_clinic/actions/report_hdcase_summary.xml @@ -0,0 +1,9 @@ + + HDCase Summary(v2) + report + report.hdcase.summary + report_hdcase_summary + report_hdcase_summary + 1 + clinic_menu + diff --git a/netforce_clinic/layouts/clinic_hd_case_form.xml b/netforce_clinic/layouts/clinic_hd_case_form.xml index 7eddc49..295163e 100644 --- a/netforce_clinic/layouts/clinic_hd_case_form.xml +++ b/netforce_clinic/layouts/clinic_hd_case_form.xml @@ -23,6 +23,7 @@ + diff --git a/netforce_clinic/layouts/clinic_hd_case_list.xml b/netforce_clinic/layouts/clinic_hd_case_list.xml index 92bb743..bc97346 100644 --- a/netforce_clinic/layouts/clinic_hd_case_list.xml +++ b/netforce_clinic/layouts/clinic_hd_case_list.xml @@ -2,7 +2,7 @@ - + diff --git a/netforce_clinic/layouts/clinic_hd_case_search.xml b/netforce_clinic/layouts/clinic_hd_case_search.xml index 5acd5a9..5fca032 100644 --- a/netforce_clinic/layouts/clinic_hd_case_search.xml +++ b/netforce_clinic/layouts/clinic_hd_case_search.xml @@ -3,6 +3,7 @@ + diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml index 875bc87..a4ec7a4 100644 --- a/netforce_clinic/layouts/clinic_menu.xml +++ b/netforce_clinic/layouts/clinic_menu.xml @@ -12,6 +12,7 @@ +
@@ -45,6 +46,7 @@ + diff --git a/netforce_clinic/layouts/clinic_shop_list.xml b/netforce_clinic/layouts/clinic_shop_list.xml index 9e3ed09..7efc4e0 100644 --- a/netforce_clinic/layouts/clinic_shop_list.xml +++ b/netforce_clinic/layouts/clinic_shop_list.xml @@ -4,9 +4,8 @@ - - - + + diff --git a/netforce_clinic/layouts/clinic_visit_form.xml b/netforce_clinic/layouts/clinic_visit_form.xml index a6c7967..dcc2949 100644 --- a/netforce_clinic/layouts/clinic_visit_form.xml +++ b/netforce_clinic/layouts/clinic_visit_form.xml @@ -22,6 +22,7 @@ + diff --git a/netforce_clinic/layouts/clinic_visit_list.xml b/netforce_clinic/layouts/clinic_visit_list.xml index a10b8f5..85eb20b 100644 --- a/netforce_clinic/layouts/clinic_visit_list.xml +++ b/netforce_clinic/layouts/clinic_visit_list.xml @@ -5,7 +5,7 @@ - + diff --git a/netforce_clinic/layouts/clinic_visit_search.xml b/netforce_clinic/layouts/clinic_visit_search.xml index 0f28c42..c86b6fa 100644 --- a/netforce_clinic/layouts/clinic_visit_search.xml +++ b/netforce_clinic/layouts/clinic_visit_search.xml @@ -2,6 +2,7 @@ + diff --git a/netforce_clinic/layouts/patient_move_form.xml b/netforce_clinic/layouts/patient_move_form.xml new file mode 100644 index 0000000..7c470f2 --- /dev/null +++ b/netforce_clinic/layouts/patient_move_form.xml @@ -0,0 +1,8 @@ +
+ + + + + + + diff --git a/netforce_clinic/layouts/patient_move_list.xml b/netforce_clinic/layouts/patient_move_list.xml new file mode 100644 index 0000000..65bd5ad --- /dev/null +++ b/netforce_clinic/layouts/patient_move_list.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/netforce_clinic/layouts/report_hdcase_summary.xml b/netforce_clinic/layouts/report_hdcase_summary.xml new file mode 100644 index 0000000..1698705 --- /dev/null +++ b/netforce_clinic/layouts/report_hdcase_summary.xml @@ -0,0 +1,5 @@ +
+ + + + diff --git a/netforce_clinic/migrations/__init__.py b/netforce_clinic/migrations/__init__.py index d5e40e0..7dbe024 100644 --- a/netforce_clinic/migrations/__init__.py +++ b/netforce_clinic/migrations/__init__.py @@ -15,4 +15,6 @@ from . import clinic_setting #from . import reimport10to15 #from . import add_missing_dlz # pending #from . import validate_cycle_item -from . import update_line_amount +#from . import update_line_amount +#from . import store_patient_name +from . import patient_move diff --git a/netforce_clinic/migrations/patient_move.py b/netforce_clinic/migrations/patient_move.py new file mode 100644 index 0000000..12ac1f3 --- /dev/null +++ b/netforce_clinic/migrations/patient_move.py @@ -0,0 +1,23 @@ +import time +import csv +import xlrd + +from netforce.model import get_model +from netforce import migration +from netforce.access import set_active_user, set_active_company +from netforce.database import get_connection + +class PatientMove(migration.Migration): + _name="clinic.patient.move" + _version="2.12.6" + + def migrate(self): + set_active_company(1) + set_active_user(1) + datenow=time.strftime("%Y-%m-%d") + datenow='2017-05-01' + get_model('clinic.patient.move').auto_get_data(context={'date': datenow}) + #for patient in get_model("clinic.patient").search_browse([],order="department_id"): + #print(patient.name, patient.location, patient.department_id.name) + +PatientMove.register() diff --git a/netforce_clinic/migrations/store_patient_name.py b/netforce_clinic/migrations/store_patient_name.py new file mode 100644 index 0000000..d18ca5c --- /dev/null +++ b/netforce_clinic/migrations/store_patient_name.py @@ -0,0 +1,26 @@ +import csv +import xlrd + +from netforce.model import get_model +from netforce import migration +from netforce.access import set_active_user, set_active_company +from netforce.database import get_connection + +class Migration(migration.Migration): + _name="clinic.store.patient.name" + _version="2.12.6" + + def migrate(self): + set_active_company(1) + set_active_user(1) + + #ids=get_model("clinic.hd.case").search([]) + #get_model("clinic.hd.case").function_store(ids) + + ids=get_model("clinic.visit").search([]) + get_model("clinic.visit").function_store(ids) + + ids=get_model("clinic.shop").search([]) + get_model("clinic.shop").function_store(ids) + +Migration.register() diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py index 37b40fe..6835288 100644 --- a/netforce_clinic/models/__init__.py +++ b/netforce_clinic/models/__init__.py @@ -148,3 +148,4 @@ from . import payment_matching from . import create_invoice_payment from . import report_stock_card from . import report_receipt_summary +from . import report_hdcase_summary diff --git a/netforce_clinic/models/account_invoice.py b/netforce_clinic/models/account_invoice.py index fccc873..9051976 100644 --- a/netforce_clinic/models/account_invoice.py +++ b/netforce_clinic/models/account_invoice.py @@ -31,8 +31,16 @@ class AccountInvoice(Model): 'patient_id': fields.Many2One("clinic.patient","Patient",function="_get_patient", function_multi=True,store=True,search=True), 'patient_type_id': fields.Many2One("clinic.patient.type","Patient Type",function="_get_patient", function_multi=True,store=True,search=True), 'create_invoice_id': fields.Many2One("create.invoice.payment","Create Invoice Payment"), + 'patient_name': fields.Char("Patient Name", function="_get_patient_name", store=True), } + def _get_patient_name(self, ids, context={}): + res={} + for obj in self.browse(ids): + patient=obj.patient_id + res[obj.id]=patient.name + return res + def _get_number(self,context={}): defaults=context.get("defaults") if defaults: # XXX diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index 1d65184..332c0a1 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -298,8 +298,16 @@ class HDCase(Model): 'company_id': fields.Many2One("company","Company"), 'branch_id': fields.Many2One("clinic.branch","Branch"), 'check_dlz': fields.Boolean("Check Dialyzer"), + 'patient_name': fields.Char("Patient Name", function="_get_patient_name", store=True, search=True), } + def _get_patient_name(self, ids, context={}): + res={} + for obj in self.browse(ids): + patient=obj.patient_id + res[obj.id]=patient.name + return res + def _get_number(self,context={}): while 1: seq_id=get_model("sequence").find_sequence(type="clinic_hdcase",context=context) diff --git a/netforce_clinic/models/patient_move.py b/netforce_clinic/models/patient_move.py index 992c736..84722a3 100644 --- a/netforce_clinic/models/patient_move.py +++ b/netforce_clinic/models/patient_move.py @@ -1,17 +1,179 @@ import time +from datetime import datetime +from calendar import monthrange -from netforce.model import Model, fields +from netforce.model import Model, fields, get_model +from netforce.access import get_active_user, set_active_user + +from . import utils class PatientMove(Model): _name="clinic.patient.move" + + def get_all(self, ids, context={}): + res={} + for obj in self.browse(ids): + res[obj.id]={ + 'date_move': obj.date.split(" ")[0], + } + return res + + _fields={ - 'patient_id': fields.Many2One('clinic.patient','Patient'), - 'date': fields.DateTime("Date"), - 'location_id': fields.Many2One("clinic.department","Department"), + 'patient_id': fields.Many2One('clinic.patient','Patient',search=True), + 'date': fields.DateTime("Date", required=True,search=True), + 'date_move': fields.Date("Date Move", function="get_all", function_multi=True, store=True), + 'location_from_id': fields.Many2One("clinic.department","Location From",search=True), + 'location_to_id': fields.Many2One("clinic.department","Location To",search=True), + "state": fields.Selection([['normal','Normal'],['new','New'],['dispose','Dispose']], "State"), + 'note': fields.Text("Note",search=True), } _defaults={ 'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"), + 'state': 'normal', } -PatientMove() + def get_data(self, date, department_id, context={}): + if not date: + raise Exception("Missing date!") + y,m,d=date.split("-") + y=int(y) + m=int(m) + weekday, day_month=monthrange(y, m) + + cond1=[ + ['date','>=','%s-%s-01 00:00:00'%(y,str(m).zfill(2))], + ['date','<=','%s-%s-%s 23:59:59'%(y,str(m).zfill(2),day_month)], + ['location_to_id','=', department_id], + ] + cond=cond1+[['state','=','normal']] + ids=self.search(cond) + prev_month=len(ids) + + cond=cond1+[['state','=','new']] + ids=self.search(cond) + current_month=len(ids) + current_items=[] + for index, val in enumerate(self.read(ids)): + val['no']=index+1 + current_items.append(val) + + + cond=cond1+[['state','=','dispose']] + ids=self.search(cond) + dispose_month=len(ids) + dispose_items=[] + for index, val in enumerate(self.read(ids)): + val['no']=index+1 + dispose_items.append(val) + + next_month=prev_month+current_month-dispose_month + + prev_m=m-1 + if prev_m <= 0: + prev_m=1 + next_m=m+1 + if next_m > 12: + next_m=1 + + prev_month_thai=utils.MONTHS['th_TH'][prev_m] + current_month_thai=utils.MONTHS['th_TH'][m] + dispose_month_thai=utils.MONTHS['th_TH'][m] + next_month_thai=utils.MONTHS['th_TH'][next_m] + + res={ + 'prev_month': prev_month, + 'prev_month_thai': prev_month_thai, + + 'current_month': current_month, + 'current_month_thai': current_month_thai, + 'current_items': current_items, + + 'dispose_month': dispose_month, + 'dispose_month_thai': dispose_month_thai, + 'dispose_items': dispose_items, + + 'next_month': next_month, + 'next_month_thai': next_month_thai, + } + return res + + def auto_get_data(self, context={}): + user_id=get_active_user() + set_active_user(1) + + date=context.get("date") + if not date: + raise Exception("Missing date!") + y,m,d=date.split("-") + weekday, day_month=monthrange(int(y), int(m)) + cond=[ + ['date','>=','%s-%s-01 00:00:00'%(y,m)], + ['date','<=','%s-%s-%s 23:59:59'%(y,m,day_month)], + ] + res=self.search(cond) + + # copy data from previous month + if not res: + y=int(y) + m=int(m)-1 + if m<=0: + m=1 + y-=1 + + weekday, day_month=monthrange(int(y), int(m)) + cond=[ + ['date','>=','%s-%s-01 00:00:00'%(y,m)], + ['date','<=','%s-%s-%s 23:59:59'%(y,m,day_month)], + ] + res=self.search_browse(cond) + for obj in res: + if obj.state=='dispose': + continue + vals={ + 'location_from_id': obj.location_from_id.id, + 'location_to_id': obj.location_to_id.id, + 'patient_id': obj.patient_id.id, + 'date': date, + } + self.create(vals) + # copy from patient + if not res: + cond=[ + ['walkin','=','no'], + ['dispose','=',False], + ] + locations={ + 'LS-FL1': 1, + 'LS-FL2': 2, + 'LS-FL3': 3, + 'SS-FL3': 4, + 'SS-FL4': 5, + } + for obj in get_model("clinic.patient").search_browse(cond): + if not obj.location: + continue + locs=obj.location.split(",") + vals={ + 'location_from_id': locations[locs[0]], #first + 'location_to_id': locations[locs[-1]], #last + 'patient_id': obj.id, + 'note': obj.note, + 'date': date, + } + self.create(vals) + + set_active_user(user_id) + + def create(self, vals, **kw): + new_id=super().create(vals,**kw) + self.function_store([new_id]) + return new_id + + def write(self, ids, vals, **kw): + super().write(ids, vals, **kw) + self.function_store(ids) + + +PatientMove.register() diff --git a/netforce_clinic/models/report_hdcase_summary.py b/netforce_clinic/models/report_hdcase_summary.py new file mode 100644 index 0000000..3b989b8 --- /dev/null +++ b/netforce_clinic/models/report_hdcase_summary.py @@ -0,0 +1,95 @@ +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 ReportHDCaseSummaryV2(Model): + _name="report.hdcase.summary" + _trasient=True + + _fields={ + "month": fields.Date("Month"), + "branch_id": fields.Many2One("clinic.branch","Branch"), + "department_id": fields.Many2One("clinic.department","Department"), + } + + def default_get(self,field_names=None,context={},**kw): + vals={ + "month": time.strftime("%Y-%m-%d"), + } + select_dpt=get_model('select.company').get_select() + if select_dpt: + vals.update({ + "branch_id": select_dpt['branch_id'], + "department_id": select_dpt['department_id'], + }) + return vals + + def get_report_data(self, ids, context={}): + defaults=self.default_get(context=context) + + month=defaults.get("month") + + + y,m,d=month.split("-") + + branch_id=defaults.get("branch_id") + department_id=defaults.get("department_id") + + if ids: + obj=self.browse(ids)[0] + branch_id=obj.branch_id.id + department_id=obj.department_id.id + month=obj.month + y,m,d=month.split("-") + + #auto gen at the fist time of that month + get_model("clinic.patient.move").auto_get_data(context={'date': month}) + + crr_month=m + weekday, total_day=monthrange(int(y), int(m)) + date_from="-".join([y,m,"01"]) + date_to="-".join([y,m,str(total_day)]) + + cond=[ + ['date','>=',date_from], + ['date','<=',date_to], + ['state','in',["waiting_payment","paid"]], + + ] + #if branch_id: + #cond.append([ + #'branch_id','=',branch_id, + #]) + if department_id: + cond.append([ + 'department_id','=',department_id, + ]) + + hdcase_ids=get_model("clinic.hd.case").search(cond) + + company_id=get_active_company() + company=get_model("company").browse(company_id) + department=get_model("clinic.department").browse(department_id) + + year_thai=utils.date2thai(month, lang='th_TH').split("-")[0] + month_thai=utils.MONTHS['th_TH'][int(crr_month)] + + data={ + 'company_name': company.name, + 'department_name': department.name, + 'month_thai': month_thai, + 'year_thai': year_thai, + 'total_hdcase': len(hdcase_ids), + } + data2=get_model("clinic.patient.move").get_data(date=month, department_id=department_id) + data.update(data2) + + from pprint import pprint + pprint(data) + return data + +ReportHDCaseSummaryV2.register() diff --git a/netforce_clinic/models/shop.py b/netforce_clinic/models/shop.py index bd57718..e22ddbd 100644 --- a/netforce_clinic/models/shop.py +++ b/netforce_clinic/models/shop.py @@ -62,10 +62,18 @@ class Shop(Model): 'hd_case_call': fields.Boolean("HD Case Call"), 'note': fields.Text("Note"), "payment_lines": fields.One2Many("clinic.shop.payment","shop_id","Payment Lines"), + 'patient_name': fields.Char("Patient Name", function="_get_patient_name", store=True, search=True), } _order="date desc" + def _get_patient_name(self, ids, context={}): + res={} + for obj in self.browse(ids): + patient=obj.patient_id + res[obj.id]=patient.name + return res + def _get_related(self,context={}): related_id=None if context.get('refer_id'): diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py index 074fb11..ea401a0 100644 --- a/netforce_clinic/models/visit.py +++ b/netforce_clinic/models/visit.py @@ -54,8 +54,16 @@ class Visit(Model): 'note': fields.Text('Note'), 'branch_id': fields.Many2One("clinic.branch","Branch"), 'manual': fields.Boolean("Manual Tempolary Visit"), + 'patient_name': fields.Char("Patient Name", function="_get_patient_name", store=True, search=True), } + def _get_patient_name(self, ids, context={}): + res={} + for obj in self.browse(ids): + patient=obj.patient_id + res[obj.id]=patient.name + return res + def _get_number(self,context={}): while 1: seq_type='clinic_visit' diff --git a/netforce_clinic/reports/report_hdcase_summary.xlsx b/netforce_clinic/reports/report_hdcase_summary.xlsx new file mode 100644 index 0000000..8a209fd Binary files /dev/null and b/netforce_clinic/reports/report_hdcase_summary.xlsx differ diff --git a/netforce_clinic/templates/report_hdcase_summary.hbs b/netforce_clinic/templates/report_hdcase_summary.hbs new file mode 100644 index 0000000..e7c4af2 --- /dev/null +++ b/netforce_clinic/templates/report_hdcase_summary.hbs @@ -0,0 +1,86 @@ + +
+

+ HDCase Summary (V2) +

+

+ {{company_name}} + {{department_name}} +

+

+ ประจำเดือน {{month_thai}} {{year_thai}} +

+
+ + + + + + + + + + + + + + + + + + + + + + + +
จำนวนครั้งการทำ Hemodialysis{{month_thai}}เท่ากับ{{total_hdcase}}ครั้ง
จำนวนผู้ป่วยยกมาจากเดือน{{prev_month_thai}}เท่ากับ{{prev_month}}ครั้ง
จำนวนผู้ป่วยรับใหม่เดือน{{current_month_thai}}เท่ากับ{{current_month}}ครั้ง
จำนวนผู้ป่วยจำหน่ายเดือน{{dispose_month_thai}}เท่ากับ{{dispose_month}}ครั้ง
จำนวนผู้ป่วยยกไปเดือน{{next_month_thai}}เท่ากับ{{next_month}}ครั้ง
+ +
+
+

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

+ + + + + + + + {{#each current_items}} + + + + + + {{/each}} + +
No.วันที่ชื่อ
{{no}}{{date_move}}{{patient_id.1.}}
+
+
+

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

+ + + + + + + + {{#each dispose_items}} + + + + + + {{/each}} + +
No.วันที่ชื่อ
{{no}}{{date_move}}{{patient_id.1.}}
+
+