diff --git a/netforce_clinic/layouts/clinic_staff_form.xml b/netforce_clinic/layouts/clinic_staff_form.xml
index 090cbdb..30411c6 100644
--- a/netforce_clinic/layouts/clinic_staff_form.xml
+++ b/netforce_clinic/layouts/clinic_staff_form.xml
@@ -74,15 +74,31 @@
-
-
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/netforce_clinic/models/cycle_item_line.py b/netforce_clinic/models/cycle_item_line.py
index 39eb443..729899a 100644
--- a/netforce_clinic/models/cycle_item_line.py
+++ b/netforce_clinic/models/cycle_item_line.py
@@ -4,12 +4,25 @@ class CycleItemLine(Model):
_name="clinic.cycle.item.line"
_string="Cycle Item Nurse"
+ def _get_all(self,ids,context={}):
+ res={}
+ for obj in self.browse(ids):
+ citem=obj.cycle_item_id
+ pt_total=len([hdcase for hdcase in citem.hd_cases if hdcase.state in ('waiting_payment','paid')])
+ res[obj.id]={
+ 'cstate': citem.state,
+ 'pt_total': pt_total,
+ }
+ return res
+
_fields={
'cycle_item_id': fields.Many2One("clinic.cycle.item", "Cycle Item"),
'level_id': fields.Many2One("clinic.staff.level", "Level",),
'nurse_id': fields.Many2One("clinic.staff",'Nurse',domain=[['type','=','nurse']]),
'department_id': fields.Many2One("clinic.department","Department"),
"state": fields.Selection([["part_time","Part Time"],["full_time","Full Time"]],"Working Status",search=True),
+ "cstate": fields.Selection([("draft","Draft"),('pending','Pending'),("validated","Validated")],"Status",function="_get_all",function_multi=True),
+ "pt_total": fields.Integer("Patients",function="_get_all",function_multi=True),
'categ_id': fields.Many2One("clinic.staff.categ",'Category',domain=[['type','=','nurse']]),
}
diff --git a/netforce_clinic/models/report_labor_cost_summary.py b/netforce_clinic/models/report_labor_cost_summary.py
index af5b61a..043dcbe 100644
--- a/netforce_clinic/models/report_labor_cost_summary.py
+++ b/netforce_clinic/models/report_labor_cost_summary.py
@@ -40,6 +40,8 @@ class ReportLaborCostSummary(Model):
branch_id=defaults.get("branch_id")
categ_id=defaults.get("categ_id")
cycle_id=defaults.get("cycle_id")
+ if cycle_id:
+ cycle_id=int(cycle_id)
if categ_id:
categ_id=int(categ_id)
if branch_id:
@@ -63,9 +65,9 @@ class ReportLaborCostSummary(Model):
'department_id': department_id or None,
'branch_id': branch_id or None,
'only_value': True,
- 'categ_id': categ_id,
- 'level_id': level_id,
- 'cycle_id': cycle_id,
+ 'categ_id': categ_id or None,
+ 'level_id': level_id or None,
+ 'cycle_id': cycle_id or None,
}
print('res ', res)
return res
@@ -113,8 +115,9 @@ class ReportLaborCostSummary(Model):
dom.append(['labor_cost_id.cycle_item_id.cycle_id','=',cycle_id])
staffs={}
citems={}
- print('>> dom: ', dom)
+ print('--> dom: ', dom)
total_hdcase=0
+
for line in get_model("clinic.labor.cost.line").search_browse(dom):
lcost=line.labor_cost_id
citem=lcost.cycle_item_id
diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py
index 5b1a0f9..d93798c 100644
--- a/netforce_clinic/models/setting.py
+++ b/netforce_clinic/models/setting.py
@@ -161,16 +161,107 @@ class ClinicSetting(Model):
if user_id !=1:
print("Only admin!!")
return
- #path='/tmp/test'
- #self.update_pcycle(path,['ls1.csv','ls2.csv','ls3.csv'])
+ pts={}
+ for pt in get_model("clinic.patient").search_browse([]):
+ name='%s %s'%(pt.first_name or "", pt.last_name or "")
+ if not pts.get(name):
+ pts[name]=[]
+ pts[name].append({
+ 'id': pt.id,
+ 'name': name,
+ 'date': pt.reg_date,
+ 'branch_id': pt.department_id.id,
+ })
+ sts={}
+ for st in get_model("clinic.staff").search_browse([]):
+ name='%s %s'%(st.first_name or '', st.last_name or '')
+ if not sts.get(name):
+ sts[name]=[]
+ sts[name].append({
+ 'id': st.id,
+ 'name': name,
+ 'branch_id': st.department_id.id,
+ 'type': st.type,
+ 'date': st.date,
+ })
+
+ print('='*50, 'staffs duplicate')
+ for st, vals in sts.items():
+ vals=sorted(vals,key=lambda x: x['date'])
+ count=len(vals)
+ if count > 1:
+ print("z"*50)
+ id_lines=[]
+ no=0
+ for val in vals:
+ no+=1
+ staff_id=val['id']
+ staff_type=val['type']
+ if staff_type=='nurse':
+ res=get_model("clinic.cycle.item.line").search_browse([['nurse_id','=',staff_id]])
+ if len(res)<=0:
+ print('nurse zero delete ', st)
+ get_model('clinic.staff').delete([staff_id])
+ else:
+ print('merge nurse... ', st, staff_id, val['date'], val['branch_id'], len(res))
+ print('no ', no, len(vals), len(res))
+ if no==len(vals):
+ print("--> ", staff_id, id_lines)
+ for id_line in id_lines:
+ for rec in get_model("clinic.cycle.item.line").search_browse([['nurse_id','=',id_line]]):
+ rec.write({
+ 'nurse_id': staff_id,
+ })
+ dom=[
+ ['type','=','nurse'],
+ ['staff_id','=',id_line],
+ ]
+ for lcost in get_model("clinic.labor.cost.line").search_browse(dom):
+ lcost.write({
+ 'staff_id': staff_id,
+ })
+ id_lines.append(staff_id)
+ elif staff_type=='doctor':
+ res=get_model("clinic.hd.case.staff").search_browse([['staff_id','=',staff_id]])
+ if len(res)<=0:
+ print('doctor zero delete ', st)
+ get_model('clinic.staff').delete([staff_id])
+ else:
+ print('merge doctor... ', st, staff_id, val['date'], val['branch_id'], len(res))
+ if no==len(vals):
+ print("--> ", staff_id, id_lines)
+ db=get_connection()
+ for id_line in id_lines:
+ for rec in get_model("clinic.hd.case.staff").search_browse([['staff_id','=',id_line]]):
+ rec.write({
+ 'staff_id': staff_id,
+ })
+ hdcase=rec.hd_case_id
+ vs=hdcase.visit_id
+ #vs.write({
+ #'doctor_id': staff_id,
+ #})
+ db.execute("update clinic_visit set doctor_id=%s where id=%s",staff_id,vs.id)
+ pt=hdcase.patient_id
+ #pt.write({
+ #'doctor_id': staff_id,
+ #})
+ db.execute("update clinic_patient set doctor_id=%s where id=%s",staff_id,pt.id)
+ citem=hdcase.cycle_item_id
+ dom=[
+ ['type','=','doctor'],
+ ['staff_id','=',id_line],
+ ['labor_cost_id.cycle_item_id','=',citem.id],
+ ]
+ for lcost in get_model("clinic.labor.cost.line").search_browse(dom):
+ lcost.write({
+ 'staff_id': staff_id,
+ })
+ id_lines.append(staff_id)
+ print("z"*50)
###TODO remove douplicate patient
###TODO remove douplicate staff
###TODO remove douplicate visit
- obj=self.browse(ids)[0]
- for ap_line in obj.account_patients:
- pt=ap_line.patient_id
- if not pt:
- ap_line.delete()
print("Done!")
def multi_department(self,ids,context={}):
diff --git a/netforce_clinic/models/staff.py b/netforce_clinic/models/staff.py
index 49b118e..6c86876 100644
--- a/netforce_clinic/models/staff.py
+++ b/netforce_clinic/models/staff.py
@@ -108,6 +108,22 @@ class Staff(Model):
res[obj.id]=','.join([dpt.name for dpt in obj.departments])
set_active_user(user_id)
return res
+
+ def _get_all(self,ids,context={}):
+ res={}
+ for obj in self.browse(ids):
+ pt_ids=[]
+ if obj.type=='doctor':
+ pt_ids=get_model("clinic.patient").search([['doctor_id','=',obj.id]])
+ elif obj.type=='nurse':
+ p=set()
+ for cline in obj.cycle_item_lines:
+ citem=cline.cycle_item_id
+ for hdcase in citem.hd_cases:
+ p.update({hdcase.patient_id.id})
+ pt_ids=list(p)
+ res[obj.id]=pt_ids
+ return res
_fields={
'employee_id': fields.Many2One("hr.employee","Employee"),
@@ -135,7 +151,8 @@ class Staff(Model):
"prof_license_expiry" : fields.Date("Expired License"),
"birthday": fields.Date("BirthDay",search=True),
"department_id": fields.Many2One("clinic.department", "Department",search=True),
- "patients": fields.One2Many("clinic.patient","doctor_id","Patients"),
+ #"patients": fields.One2Many("clinic.patient","doctor_id","Patients"),
+ "patients": fields.Many2Many("clinic.patient","Patients",function="_get_all"),
"addresses": fields.One2Many("address","staff_id","Addresses"),
"comments": fields.One2Many("message","related_id","Comments"),
"nurse_visits": fields.One2Many("clinic.visit","nurse_id","Visits"),
@@ -160,7 +177,7 @@ class Staff(Model):
'cycle_id': fields.Many2One('clinic.cycle','Last Cycle',function="_get_cycle"),
"hd_case_staffs": fields.One2Many("clinic.hd.case.staff","staff_id","HD Cases"),
"hd_cases": fields.Many2Many("clinic.hd.case","HD Cases",function="_get_hdcase"), # not need to use (it's slow to load)
- "cycle_item_nurses": fields.One2Many("clinic.cycle.item.line","nurse_id","Cycle Items"),
+ "cycle_item_lines": fields.One2Many("clinic.cycle.item.line","nurse_id","Cycle Items"),
'branch_id': fields.Many2One("clinic.branch","Branch", search=True),
"partner_id": fields.Many2One("partner","Contact"),
'departments': fields.Many2Many("clinic.department","Departments"),
diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt
index 4df99c9..9495a53 100644
--- a/netforce_clinic/todo.txt
+++ b/netforce_clinic/todo.txt
@@ -1,6 +1,15 @@
> script:
merge staff, patient
+ source => destination
+ - step:
+ > patient:
+ 1. copy:
+ - properties
+ - visit
+ - hdcases
+ - dialyzers
+ 2. delete old one
+ > staff:
+
> invoice payment on rd shop
-> report:
- improve cycle item report