diff --git a/netforce_clinic/actions/clinic_report_visit.xml b/netforce_clinic/actions/clinic_report_visit.xml new file mode 100644 index 0000000..de52702 --- /dev/null +++ b/netforce_clinic/actions/clinic_report_visit.xml @@ -0,0 +1,8 @@ + + Report Visit + report + clinic.report.visit + report_visit + report_visit + clinic_menu + diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml index 2d3b9e0..ff172e4 100644 --- a/netforce_clinic/layouts/clinic_menu.xml +++ b/netforce_clinic/layouts/clinic_menu.xml @@ -49,6 +49,7 @@ + diff --git a/netforce_clinic/layouts/clinic_report_visit.xml b/netforce_clinic/layouts/clinic_report_visit.xml new file mode 100644 index 0000000..fe0b2e7 --- /dev/null +++ b/netforce_clinic/layouts/clinic_report_visit.xml @@ -0,0 +1,7 @@ +
+ + + + + + diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py index 1cbd276..db1214a 100644 --- a/netforce_clinic/models/__init__.py +++ b/netforce_clinic/models/__init__.py @@ -59,6 +59,7 @@ from . import schedule_copy from . import load_nurse from . import load_nurse_line from . import report_clinic +from . import report_visit from . import report_hd_case_summary from . import report_medical_summary from . import report_recent_patient diff --git a/netforce_clinic/models/report_visit.py b/netforce_clinic/models/report_visit.py new file mode 100644 index 0000000..9ee2155 --- /dev/null +++ b/netforce_clinic/models/report_visit.py @@ -0,0 +1,114 @@ +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 ReportVisit(Model): + _name="clinic.report.visit" + _string="Report Visit" + _transient=True + + _fields={ + "date": fields.Date("Month"), + "date_from": fields.Date("From", required=True), + "date_to": fields.Date("To", required=True), + "patient_id": fields.Many2One("clinic.patient","Patient"), + "doctor_id": fields.Many2One("clinic.staff","Doctor",domain=[['type','=','doctor']]), + } + + def _get_date_from(self,context={}): + year,month=time.strftime("%Y-%m").split("-") + return '%s-%s-01'%(year,month) + + def _get_date_to(self,context={}): + year,month,day=time.strftime("%Y-%m-%d").split("-") + weekday, total_day=monthrange(int(year), int(month)) + return "%s-%s-%s"%(year,month,total_day) + + _defaults={ + 'date': lambda *a: time.strftime("%Y-%m-%d"), + 'date_from': _get_date_from, + 'date_to': _get_date_to, + } + + 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("-") + weekday, total_day=monthrange(int(year), int(month)) + time_start='%s-%s-01'%(year,str(month).zfill(2)) + time_stop='%s-%s-%s'%(year,str(month).zfill(2),total_day) + + defaults=context.get('defaults') + if defaults: + year,month,day=defaults['date'].split("-") + weekday, total_day=monthrange(int(year), int(month)) + time_start='%s-%s-01'%(year,str(month).zfill(2)) + time_stop='%s-%s-%s'%(year,str(month).zfill(2),total_day) + patient_id=None + doctor_id=None + if ids: + obj=self.browse(ids)[0] + month=obj.date_from.split("-")[1] + time_start=obj.date_from + time_stop=obj.date_to + patient_id=obj.patient_id.id + doctor_id=obj.doctor_id.id + # new patient of this month + dom=[] + dom.append(['visit_date','>=',time_start]) + dom.append(['visit_date','<=',time_stop]) + if patient_id: + dom.append(['patient_id','=',patient_id]) + if doctor_id: + dom.appen(['doctor_id','=',doctor_id]) + + records=get_model('clinic.visit').search_browse(dom) + lines=[] + no=1 + for record in records: + lines.append({ + 'no': no, + 'vid': record.id, + 'cid': record.cycle_id.id, + 'cname': record.cycle_id.name or "", + 'pid': record.patient_id.id or '', + 'pname': record.patient_id.name or '', + 'tname': record.patient_id.type_id.name or '', + 'tid': record.patient_id.type_id.id or '', + 'did': record.doctor_id.id, + 'dname': record.doctor_id.name or "", + 'date': record.visit_date or '', + 'note': record.note or '', + }) + no+=1 + + month_str=utils.MONTHS['th_TH'][int(month)] + start=int(time_start[8:10]) + stop=int(time_stop[8:10]) + diff=stop-start + data={ + 'company_name': company.name or "", + 'parent_company_name': company.parent_id.name or "", + 'lines': lines, + 'month': month_str, + 'from': time_start, + 'to': time_stop, + 'is_duration': diff+1 < total_day, + 'year': year, + } + return data + + def onchange_date(self,context={}): + data=context['data'] + date=data['date'] + year,month,day=date.split("-") + weekday, total_day=monthrange(int(year), int(month)) + data['date_from']="%s-%s-01"%(year,month) + data['date_to']="%s-%s-%s"%(year,month,total_day) + return data + +ReportVisit.register() diff --git a/netforce_clinic/reports/report_visit.xlsx b/netforce_clinic/reports/report_visit.xlsx new file mode 100644 index 0000000..879078a Binary files /dev/null and b/netforce_clinic/reports/report_visit.xlsx differ diff --git a/netforce_clinic/templates/report_visit.hbs b/netforce_clinic/templates/report_visit.hbs new file mode 100644 index 0000000..0063263 --- /dev/null +++ b/netforce_clinic/templates/report_visit.hbs @@ -0,0 +1,41 @@ +
+ +
+ + + + + + + + + + + + {{#each lines }} + + + + + + + + + + {{/each}} + + + +
#วันที่รอบผู้ป่วยสิทธ์แพทย์หมายเหตุ
{{no}}{{date}}{{cname}}{{pname}}{{tname}}{{dname}}{{note}}
diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt index 1e667e3..397125f 100644 --- a/netforce_clinic/todo.txt +++ b/netforce_clinic/todo.txt @@ -12,7 +12,6 @@ report: - doctor detail (for accounting) - patient visit - sharing setting - filter by branch - patient -> ok