diff --git a/netforce_clinic/actions/clinic_report_cycle_setting.xml b/netforce_clinic/actions/clinic_report_cycle_setting.xml new file mode 100644 index 0000000..e205637 --- /dev/null +++ b/netforce_clinic/actions/clinic_report_cycle_setting.xml @@ -0,0 +1,8 @@ + + Report Cycle Setting + report + clinic.report.cycle.setting + report_cycle_setting + report_cycle_setting + clinic_menu + diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml index 42b66db..6f37415 100644 --- a/netforce_clinic/layouts/clinic_menu.xml +++ b/netforce_clinic/layouts/clinic_menu.xml @@ -45,6 +45,7 @@ + diff --git a/netforce_clinic/layouts/clinic_report_cycle_setting.xml b/netforce_clinic/layouts/clinic_report_cycle_setting.xml new file mode 100644 index 0000000..d5d2505 --- /dev/null +++ b/netforce_clinic/layouts/clinic_report_cycle_setting.xml @@ -0,0 +1,5 @@ +
+ + + + diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py index 2b18ad9..4e65f51 100644 --- a/netforce_clinic/models/__init__.py +++ b/netforce_clinic/models/__init__.py @@ -136,5 +136,6 @@ from . import num2word from . import province from . import change_visit from . import share_location +from . import report_cycle_setting #from . import district #from . import subdistrict diff --git a/netforce_clinic/models/report_cycle_setting.py b/netforce_clinic/models/report_cycle_setting.py new file mode 100644 index 0000000..b9e1e99 --- /dev/null +++ b/netforce_clinic/models/report_cycle_setting.py @@ -0,0 +1,154 @@ +from netforce.model import Model, fields, get_model + +class ReportCycleSetting(Model): + _name="clinic.report.cycle.setting" + _transient=True + + _fields={ + 'department_id': fields.Many2One("clinic.department","Department"), + 'branch_id': fields.Many2One("clinic.branch","Branch"), + 'cycle_id': fields.Many2One("clinic.cycle","Cycle"), + } + + def _get_branch(self,context={}): + res=get_model('select.company').get_select() + if res: + return res['branch_id'] + + def _get_department(self,context={}): + res=get_model('select.company').get_select() + if res: + if res.get("department_ids"): + return res['department_ids'][0] + else: + return res['department_id'] + + def default_get(self,field_names=None,context={},**kw): + defaults=context.get("defaults",{}) + branch_id=defaults.get('branch_id') + if branch_id: + branch_id=int(branch_id) + else: + branch_id=self._get_branch(context=context) + + department_id=defaults.get('department_id') + if department_id: + department_id=int(department_id) + else: + department_id=self._get_department(context=context) + res={ + 'branch_id': branch_id, + 'department_id': department_id, + } + print('report.cycle.item.setting', res) + return res + + def get_report_data(self,ids,context={}): + defaults=self.default_get(context=context) + department_id=defaults.get('department_id',None) + branch_id=defaults.get('branch_id',None) + cycle_id=defaults.get('cycle_id',None) + if ids: + obj=self.browse(ids)[0] + department_id=obj.department_id.id + branch_id=obj.branch_id.id + cycle_id=obj.cycle_id.id + pts={} + dom=[] + dom.append(['patient_id.state','=','admit']) + if department_id: + dom.append(['department_id','=',department_id]) + if cycle_id: + dom.append(['cycle_id','=',cycle_id]) + pcs=get_model("clinic.patient.cycle").search_browse(dom) + if not pcs: + # Create patient cycle with that department + for pt in get_model("clinic.patient").search_browse([['department_id','=',department_id]]): + if pt.walkin=='yes': + continue + for pc in pt.cycles: + vals={ + 'patient_id': pt.id, + 'department_id': pt.department_id.id, + 'cycle_id': pc.cycle_id.id, + 'day': pc.day, + } + res=get_model("clinic.patient.cycle").search([[ + ['patient_id','=',pt.id], + ['day','=',pc.day], + ['cycle_id','=',pc.cycle_id.id], + ['department_id','=', pt.department_id.id], + ]]) + if not res: + pcycle_id=get_model("clinic.patient.cycle").create(vals) + print("create ", pcycle_id) + else: + print("exist ", res) + pcs=get_model("clinic.patient.cycle").search_browse(dom) + if not pcs: + raise Exception("Please go to menu 'Patients -> Patient Cycles' and import data for %s"%(department_id)) + for pc in pcs: + patient=pc.patient_id + dpt=pc.department_id + branch=dpt.branch_id + if not branch: + continue + if branch_id and branch_id!=branch.id: + continue + key=(patient.id,dpt.id) + if not pts.get(key): + pts[key]={ + 'patient_name': patient.name, + 'department_name': dpt.name, + 'mon_cycle_id': None, + 'tue_cycle_id': None, + 'wed_cycle_id': None, + 'thu_cycle_id': None, + 'fri_cycle_id': None, + 'sat_cycle_id': None, + 'sun_cycle_id': None, + } + cycle=pc.cycle_id + day=pc.day or '' + if day=='mon': + pts[key]['mon_cycle_id']=cycle.name + elif day=='tue': + pts[key]['tue_cycle_id']=cycle.name + elif day=='wed': + pts[key]['wed_cycle_id']=cycle.name + elif day=='thu': + pts[key]['thu_cycle_id']=cycle.name + elif day=='fri': + pts[key]['fri_cycle_id']=cycle.name + elif day=='sat': + pts[key]['sat_cycle_id']=cycle.name + else: + pts[key]['sun_cycle_id']=cycle.name + + lines=[] + no=1 + for k, vals in pts.items(): + pt_id, dpt_id=k + if pt_id: + vals['patient_id']=pt_id + if not dpt_id: + pt=get_model("clinic.patient").browse(pt_id) + dpt_id=pt.department_id.id + if dpt_id: + vals['department_id']=dpt_id + vals['no']=no + lines.append(vals) + no+=1 + + data={ + 'lines': lines, + 'department_id': department_id, + } + return data + + def onchange_branch(self,context={}): + data=context['data'] + data['department_id']=None + return data + +ReportCycleSetting.register() diff --git a/netforce_clinic/reports/report_cycle_setting.xlsx b/netforce_clinic/reports/report_cycle_setting.xlsx new file mode 100644 index 0000000..2a18e2a Binary files /dev/null and b/netforce_clinic/reports/report_cycle_setting.xlsx differ diff --git a/netforce_clinic/templates/report_cycle_setting.hbs b/netforce_clinic/templates/report_cycle_setting.hbs new file mode 100644 index 0000000..b7b58ae --- /dev/null +++ b/netforce_clinic/templates/report_cycle_setting.hbs @@ -0,0 +1,41 @@ + + + + + + {{#unless department_id}} + + {{/unless}} + + + + + + + + + + {{#each lines }} + + + + {{#unless ../department_id}} + + {{/unless}} + + + + + + + + + {{/each}} + + + +
#PatientDepartmentMondayTuesdayWednesdayThursdayFridaySaturdaySunday
{{no}} + {{view "link" string=patient_name action="clinic_patient" action_options="mode=form" active_id=patient_id}} + {{department_name}}{{mon_cycle_id}}{{tue_cycle_id}}{{wed_cycle_id}}{{thu_cycle_id}}{{fri_cycle_id}}{{sat_cycle_id}}{{sun_cycle_id}}
diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt index 3ab75b6..610a64a 100644 --- a/netforce_clinic/todo.txt +++ b/netforce_clinic/todo.txt @@ -1,13 +1,2 @@ -> script: - - merge - - staff -> ok - - patient - -> explain nurse - กรณีแก้ไขรายชื่อหมอให้ดูรายชื่อแพทย์ให้ดี - -> note: - แก้ไขยาก หากมาเจอข้อผิดพลาดบางครั้ง - -> report K. boy - total qty of report_labor_cost_staff is not the same report_labor_cost +- show log for each model that use _log=True +- create report patient cycle setting -> link to patient to change cycle setting