diff --git a/netforce_clinic/actions/clinic_report_cycle_item.xml b/netforce_clinic/actions/clinic_report_cycle_item.xml new file mode 100644 index 0000000..2392ba9 --- /dev/null +++ b/netforce_clinic/actions/clinic_report_cycle_item.xml @@ -0,0 +1,8 @@ + + Report Cycle Item + report + clinic.report.cycle.item + report_cycle_item + report_cycle_item + clinic_menu + diff --git a/netforce_clinic/fixme.txt b/netforce_clinic/fixme.txt new file mode 100644 index 0000000..6d18960 --- /dev/null +++ b/netforce_clinic/fixme.txt @@ -0,0 +1 @@ +dom=[['patient_id.field_bool','=',True]] => not working diff --git a/netforce_clinic/layouts/clinic_cycle_item_form.xml b/netforce_clinic/layouts/clinic_cycle_item_form.xml index 4b3f75f..1d5e393 100644 --- a/netforce_clinic/layouts/clinic_cycle_item_form.xml +++ b/netforce_clinic/layouts/clinic_cycle_item_form.xml @@ -26,7 +26,7 @@ - + @@ -34,7 +34,7 @@ - Note: HD Case State Accepted: 'Finish Treatment', 'Waiting Payment', 'Paid'. + Note: State Accept: 'Finish Treatment', 'Waiting Payment', 'Paid'. diff --git a/netforce_clinic/layouts/clinic_cycle_item_list.xml b/netforce_clinic/layouts/clinic_cycle_item_list.xml index 1d01a99..5f8ec6d 100644 --- a/netforce_clinic/layouts/clinic_cycle_item_list.xml +++ b/netforce_clinic/layouts/clinic_cycle_item_list.xml @@ -4,8 +4,8 @@ - + diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml index 8f460b9..7f2aeb4 100644 --- a/netforce_clinic/layouts/clinic_menu.xml +++ b/netforce_clinic/layouts/clinic_menu.xml @@ -46,7 +46,7 @@ - + diff --git a/netforce_clinic/layouts/clinic_patient_form.xml b/netforce_clinic/layouts/clinic_patient_form.xml index 9a729fc..264c32e 100644 --- a/netforce_clinic/layouts/clinic_patient_form.xml +++ b/netforce_clinic/layouts/clinic_patient_form.xml @@ -19,7 +19,7 @@ - + diff --git a/netforce_clinic/layouts/clinic_report_cycle_item.xml b/netforce_clinic/layouts/clinic_report_cycle_item.xml new file mode 100644 index 0000000..8f0d04c --- /dev/null +++ b/netforce_clinic/layouts/clinic_report_cycle_item.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + Note: Cycle Item State Should Be 'Validated'. + + + + + + diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py index ec985ca..2d3a25a 100644 --- a/netforce_clinic/models/__init__.py +++ b/netforce_clinic/models/__init__.py @@ -64,6 +64,7 @@ from . import load_nurse from . import load_nurse_line from . import report_clinic from . import report_visit +from . import report_cycle_item from . import report_hd_case_summary from . import report_hd_case_detail from . import report_medical_summary diff --git a/netforce_clinic/models/cycle_item.py b/netforce_clinic/models/cycle_item.py index 8d1d8f0..c612d16 100644 --- a/netforce_clinic/models/cycle_item.py +++ b/netforce_clinic/models/cycle_item.py @@ -98,7 +98,10 @@ class CycleItem(Model): def validate(self,ids,context={}): obj=self.browse(ids)[0] for hdcase in obj.hd_cases: - if hdcase.state not in ('completed','waiting_payment','paid'): + state=hdcase.state + if state=='cancelled': + continue + if state not in ('completed','waiting_payment','paid'): raise Exception('Invalidate cycle item %s: HD Case %s is not completed' % (obj.name, hdcase.patient_id.name)) for obj_id in ids: lcost_ids=get_model("clinic.labor.cost").search([['cycle_item_id','=',obj_id]]) @@ -148,7 +151,7 @@ class CycleItem(Model): nurse_id=line['nurse_id'] nurse=get_model('clinic.staff').browse(nurse_id) line['level_id']=nurse.level_id.id - line['categ_id']=nurse.categ_id #XXX + line['categ_id']=nurse.categ_id.id return data def view_schedule(self,ids,context={}): diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py index 706f8a9..71f1bfc 100644 --- a/netforce_clinic/models/patient.py +++ b/netforce_clinic/models/patient.py @@ -132,7 +132,7 @@ class Patient(Model): 'cycles': fields.One2Many("clinic.patient.cycle","patient_id", "Cycles"), "vascular_acc": fields.Many2One("clinic.vascular.access","Vascular Ac."), 'state': fields.Selection([['admit','Admit'],['dispose','Dispose']],'State'), - 'is_walkin': fields.Boolean("Walk In"), + 'walkin': fields.Selection([['yes','Yes'],['no','No']],"Walk In"), } def _get_number(self,context={}): @@ -180,6 +180,7 @@ class Patient(Model): 'type_id': _get_type, "active" : True, 'state': 'admit', + 'walkin': 'no', } _sql_constraints=("clinic_patient_key_uniq","unique(name_check,branch_id)","name should be unique"), diff --git a/netforce_clinic/models/report_cycle_item.py b/netforce_clinic/models/report_cycle_item.py new file mode 100644 index 0000000..077a215 --- /dev/null +++ b/netforce_clinic/models/report_cycle_item.py @@ -0,0 +1,118 @@ +import time + +from netforce.model import Model,fields,get_model +from netforce.access import get_active_company + +from . import utils + +class ReportCycleItem(Model): + _name="clinic.report.cycle.item" + _string="Report Cycle Item" + _transient=True + + _fields={ + "date": fields.Date("Month"), + "date_from": fields.Date("From", required=True), + "date_to": fields.Date("To", required=True), + "cycle_id": fields.Many2One("clinic.cycle","Cycle"), + 'branch_id': fields.Many2One("clinic.branch","Branch"), + 'department_id': fields.Many2One("clinic.department","Department"), + } + + def default_get(self,field_names=None,context={},**kw): + defaults=context.get("defaults",{}) + date=defaults.get('date',time.strftime("%Y-%m-%d")) + year,month=time.strftime("%Y-%m").split("-") + date_from=defaults.get('date_from','%s-%s-01'%(year,month)) + date_to=defaults.get('date_to','%s-%s-01'%(year,month)) + res={ + 'date': date, + 'date_from': date_from, + 'date_to': date_to, + } + return res + + def get_report_data(self,ids,context={}): + company_id=get_active_company() + company=get_model('company').browse(company_id) + defaults=self.default_get(context=context) + date_from=defaults.get("date_from") + date_to=defaults.get("date_to") + month=date_from.split("-")[1] + branch_id=None + department_id=None + cycle_id=None + if ids: + obj=self.browse(ids)[0] + month=obj.date_from.split("-")[1] + date_from=obj.date_from + date_to=obj.date_to + branch_id=obj.branch_id.id + department_id=obj.department_id.id + cycle_id=obj.cycle_id.id + # new patient of this month + dom=[] + dom.append(['date','>=',date_from]) + dom.append(['date','<=',date_to]) + dom.append(['state','=','validated']) + if cycle_id: + dom.append(['cycle_id','=',cycle_id]) + if branch_id: + dom.append(['branch_id','=',branch_id]) + if department_id: + dom.append(['department_id','=',department_id]) + no=1 + lines=[] + for citem in get_model('clinic.cycle.item').search_browse(dom): + for hdcase in citem.hd_cases: + patient=hdcase.patient_id + ptype=patient.type_id + doctor=hdcase.doctor_id + cycle=hdcase.cycle_id + dpt=hdcase.department_id + lines.append({ + 'no': no, + 'pname': patient.name or '', + 'pid': patient.id or '', + 'hn': patient.hn_no, + 'did': doctor.id, + 'dname': doctor.name or "", + #'date': utils.date2thai(hdcase.date or '',format='%(Td)s %(d)s/%(m)s/%(BY)s'), + 'date': hdcase.date, + 'epo': hdcase.epo, + 'cname': cycle.name or '', + 'cid': citem.id or '', + 'hct': hdcase.hct or 0, + 'tname': ptype.name or '', + 'tid': ptype.id, + 'dpt_id': dpt.id, + 'dpt_name': dpt.name or "", + }) + no+=1 + month_str=utils.MONTHS['th_TH'][int(month)] + company_name=company.name or "" + if department_id: + department=get_model("clinic.department").browse(department_id) + company_name+=" ("+department.name+")" + elif branch_id: + branch=get_model("clinic.branch").browse(branch_id) + company_name+=" ("+branch.name+")" + data={ + 'company_name': company_name or "", + 'lines': lines, + 'month': month_str, + 'date_from': date_from, + 'date_to': date_to, + } + 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 + +ReportCycleItem.register() diff --git a/netforce_clinic/models/report_hd_case_summary.py b/netforce_clinic/models/report_hd_case_summary.py index f2fc4b5..d1325b7 100644 --- a/netforce_clinic/models/report_hd_case_summary.py +++ b/netforce_clinic/models/report_hd_case_summary.py @@ -87,11 +87,11 @@ class ReportHDCaseSummary(Model): dom.append(["time_start",">=",time_start]) dom.append(["time_stop","<=",time_stop]) dom.append(["state","in",["completed","waiting_payment","paid"]]) + dom.append(['patient_id.walkin','=','no']) if branch_id: dom.append(['branch_id','=',branch_id]) if department_id: dom.append(['department_id','=',department_id]) - print('>> dom ', dom) crr_total=len(get_model("clinic.hd.case").search(dom)) items={} items['topic%s'%count]={ diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py index 40df4af..0207570 100644 --- a/netforce_clinic/models/setting.py +++ b/netforce_clinic/models/setting.py @@ -136,34 +136,12 @@ class ClinicSetting(Model): if user_id !=1: print("Only admin!!") return - #obj=self.browse(ids)[0] + obj=self.browse(ids)[0] #obj.update_staff_department() #obj.remove_rotation() - #obj.update_staff_level() + obj.update_staff_level() #obj.update_cycle_item_level() - for st in get_model("clinic.staff").search_browse([]): - st.write({ - 'note': ' ', - }) print("Done!") - return - - lines=[] - for pt in get_model("clinic.patient").search_browse([['state','=','admit']]): - partner_id=None - if pt.partner_id: - partner_id=pt.partner_id.id - vals={ - 'patient_id': pt.id, - 'partner_id': partner_id, - 'type_id': pt.type_id.id, - } - lines.append(('create',vals)) - obj=self.browse(ids)[0] - obj.write({ - 'account_patients': lines, - }) - return def update_staff_department(self,ids,context={}): user_id=get_active_user() @@ -198,17 +176,6 @@ class ClinicSetting(Model): if user_id !=1: print("Only admin!!") return - for citem in get_model("clinic.cycle.item").search_browse([]): - for line in citem.lines: - nurse=line.nurse_id - categ_id=nurse.categ_id.id - level_id=nurse.level_id - line.write({ - 'categ_id': categ_id, - 'level_id': level_id, - }) - print("Done!") - return # run below before above! import csv f=open("/tmp/update_rotation.csv","r") @@ -236,8 +203,21 @@ class ClinicSetting(Model): 'level_id': level_id, 'categ_id': categ_id, }) - #print(line) + #force update level, category store + for staff in get_model("clinic.staff").search_browse([]): + staff.write({ + 'note': ' ', + }) + for citem in get_model("clinic.cycle.item").search_browse([]): + for line in citem.lines: + nurse=line.nurse_id + categ_id=nurse.categ_id + level_id=nurse.level_id + line.write({ + 'categ_id': categ_id.id, + 'level_id': level_id.id, + }) print("Done!") return diff --git a/netforce_clinic/reports/report_cycle_item.xlsx b/netforce_clinic/reports/report_cycle_item.xlsx new file mode 100644 index 0000000..b1edd9c Binary files /dev/null and b/netforce_clinic/reports/report_cycle_item.xlsx differ diff --git a/netforce_clinic/templates/report_cycle_item.hbs b/netforce_clinic/templates/report_cycle_item.hbs new file mode 100644 index 0000000..1821fc1 --- /dev/null +++ b/netforce_clinic/templates/report_cycle_item.hbs @@ -0,0 +1,41 @@ + + สรุปรอบการรักษา + + {{company_name}} + + + ระหว่างวันที่ {{date_from}} ถึง {{date_to}} + + + + + # + วันที่ + รอบ + HN + ผู้ป่วย + สิทธ์ + ชั้น + แพทย์ + EPO + HCT + + + {{#each lines }} + + {{no}} + {{date}} + {{cname}} + {{hn}} + {{pname}} + {{tname}} + {{dpt_name}} + {{dname}} + {{epo}} + {{hct}} + + {{/each}} + + + + diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt index e85ecd7..86df208 100644 --- a/netforce_clinic/todo.txt +++ b/netforce_clinic/todo.txt @@ -17,8 +17,17 @@ todo: - sickbed - staff - staff rotation : only manager nurse + - reports + - P Moo cycle item + - P อ้วน + - patient + - update + - new feature + - slit invoice (fee & another) + - schedule job + - create visit next month - run script - - update level's nurse + - update level's nurse -> ok - report k. boy (sub detail) -> ok - ** update accounting - link ref -> ok