diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml
index 5eb30a6..7d5d17d 100644
--- a/netforce_clinic/layouts/clinic_menu.xml
+++ b/netforce_clinic/layouts/clinic_menu.xml
@@ -6,9 +6,9 @@
-
-
-
+
+
+
-
@@ -20,7 +20,7 @@
-
+
diff --git a/netforce_clinic/layouts/clinic_patient_form.xml b/netforce_clinic/layouts/clinic_patient_form.xml
index bbcf467..4fa913a 100644
--- a/netforce_clinic/layouts/clinic_patient_form.xml
+++ b/netforce_clinic/layouts/clinic_patient_form.xml
@@ -15,10 +15,10 @@
-
-
+
+
@@ -72,11 +72,28 @@
-
+
+
+
+
+
+
Note: "Cycle" ที่ระบุไว้ที่หน้านี้ จะเป็นข้อมูลต้นทางที่ระบบจะนำไปสร้าง Visit ล่วงหน้า
+
+
+
+
+
+
+
+
Note: "Location" คือ สถานที่ที่ผู้ป่วยสามารถรับการรักษา ซึ่งระบุได้มากกว่า 1 ที่
+
+
+
+
diff --git a/netforce_clinic/layouts/clinic_select_company.xml b/netforce_clinic/layouts/clinic_select_company.xml
index 5e185b6..989d858 100644
--- a/netforce_clinic/layouts/clinic_select_company.xml
+++ b/netforce_clinic/layouts/clinic_select_company.xml
@@ -1,5 +1,5 @@
-
+
diff --git a/netforce_clinic/layouts/clinic_visit_form.xml b/netforce_clinic/layouts/clinic_visit_form.xml
index de11f77..0294756 100644
--- a/netforce_clinic/layouts/clinic_visit_form.xml
+++ b/netforce_clinic/layouts/clinic_visit_form.xml
@@ -14,8 +14,8 @@
-
-
+
+
diff --git a/netforce_clinic/models/base_user.py b/netforce_clinic/models/base_user.py
index cff4715..37c0014 100644
--- a/netforce_clinic/models/base_user.py
+++ b/netforce_clinic/models/base_user.py
@@ -5,6 +5,7 @@ class User(Model):
_fields={
'department_profile_id': fields.Many2One("clinic.department.profile","Department Profile"),
'department_id': fields.Many2One("clinic.department","Current Department"),
+ 'department_include': fields.Selection([['yes','Yes'],['no','No']],"Include"),
}
User.register()
diff --git a/netforce_clinic/models/make_apt.py b/netforce_clinic/models/make_apt.py
index cecdbe2..b559c4b 100644
--- a/netforce_clinic/models/make_apt.py
+++ b/netforce_clinic/models/make_apt.py
@@ -286,6 +286,35 @@ class MakeAPT(Model):
if patient.department_id:
department_id=patient.department_id.id
line['department_id']=department_id
+
+ #line_vals={}
+ #for cycle in patient.cycles:
+ #cycle_id=cycle.cycle_id.id
+ #day=cycle.day
+ #dpt=cycle.department_id
+ #key=dpt.id
+ #if dpt.id not in line_vals.keys():
+ #line_vals[key]={}
+ #vals=line_vals[key]
+ #if day=='mon':
+ #vals['mon_cycle_id']=cycle_id
+ #elif day=='tue':
+ #vals['tue_cycle_id']=cycle_id
+ #elif day=='wed':
+ #vals['wed_cycle_id']=cycle_id
+ #elif day=='thu':
+ #vals['thu_cycle_id']=cycle_id
+ #elif day=='fri':
+ #vals['fri_cycle_id']=cycle_id
+ #elif day=='sat':
+ #vals['sat_cycle_id']=cycle_id
+ #elif day=='sun':
+ #vals['sun_cycle_id']=cycle_id
+ #print("="*50)
+ #for line,vals in line_vals.items():
+ #print(line, vals)
+ #print("="*50)
+
for cycle in patient.cycles:
cycle_id=cycle.cycle_id.id
day=cycle.day
diff --git a/netforce_clinic/models/select_company.py b/netforce_clinic/models/select_company.py
index 2a27dea..0d9b028 100644
--- a/netforce_clinic/models/select_company.py
+++ b/netforce_clinic/models/select_company.py
@@ -1,19 +1,16 @@
from netforce.model import Model, fields, get_model
-from netforce.access import get_active_user, set_active_user
-from netforce.database import get_connection
+from netforce.access import get_active_user, set_active_user, get_active_company
class SelectCompany(Model):
_inherit="select.company"
_fields={
- "department": fields.Selection([],"Deparment")
+ "department": fields.Selection([],"Department"),
}
def _get_department(self,context={}):
user_id=get_active_user()
- dpt_name=None
- for staff in get_model("clinic.staff").search_browse([['user_id','=',user_id]]):
- dpt=staff.department_id
- dpt_name=dpt.name
+ user=get_model("base.user").browse(user_id)
+ dpt_name=user.department_id.name or ""
return dpt_name
_defaults={
@@ -39,14 +36,114 @@ class SelectCompany(Model):
set_active_user(user_id)
return [(r["name"],r["name"]) for r in res]
+ def check_profile(self,ids,context={}):
+ user_id=get_active_user()
+ user=get_model("base.user").browse(user_id)
+ dpt_profile=user.department_profile_id
+ if not dpt_profile:
+ raise Exception("Missing department profile! Please contact admin.")
+ set_active_user(1)
+ for obj in self.browse(ids):
+ code=dpt_profile.name or ''
+ pf_ids=get_model('profile').search(['code','=',code])
+ if pf_ids:
+ print("Profile %s is already exist"%(code))
+ set_active_user(user_id)
+ return pf_ids[0]
+ except_perms=['Clinic Menu Settings','Clinic Staff Tab Accounting']
+ other_perms=[]
+ for otp in get_model('permission').search_read(['name','ilike','clinic'],['name']):
+ name=otp['name']
+ if name in except_perms:
+ continue
+ other_perms.append(otp['id'])
+ except_model=['clinic.cycle','clinic.department']
+ perms=[]
+ for model in get_model('model').search_read([['name','ilike','clinic']],['name']):
+ vals={
+ 'model_id': model['id'],
+ 'perm_read': True,
+ 'perm_create': True,
+ 'perm_write': True,
+ 'perm_delete': True,
+ }
+ name=model['name']
+ if name in except_model:
+ vals['perm_create']=False
+ vals['perm_write']=False
+ vals['perm_delete']=False
+ perms.append(('create', vals))
+ profile_id=get_model('profile').create({
+ 'perms': perms,
+ 'code': code,
+ 'name': code,
+ 'perms': perms,
+ 'other_perms': [('set',other_perms)],
+ 'login_company_id': get_active_company(),
+ 'home_action': 'clinic_visit_board',
+ })
+ print("create profile %s"%(code))
+ set_active_user(user_id)
+ return profile_id
+
+ def share_profile(self,ids,context={}):
+ #rule: branch_code-deparment_code
+ profile_id=context.get('profile_id')
+ if not profile_id:
+ raise Exception("Profile not found")
+ models=[
+ ['clinic.patient','location','ilike'],
+ ['clinic.patient.cycle','department_id.code','='],
+ ['clinic.staff','location','ilike'],
+ ['clinic.staff.rotation','department_id.code','='],
+ ['clinic.visit','department_id.code','='],
+ ['clinic.hd.case','department_id.code','='],
+ ['clinic.cycle.item','department_id.code','='],
+ ['clinic.sickbed','department_id.code','='],
+ ['clinic.shop','department_id.code','='],
+ ['clinic.dialyzer','department_id.code','='],
+ ['clinic.schedule','department_id.code','='],
+ ]
+
+ user_id=get_active_user()
+ user=get_model("base.user").browse(user_id)
+ dpt_profile=user.department_profile_id
+ dpt_codes=[dpt.code for dpt in dpt_profile.departments]
+ exist_model=[]
+ for obj in self.browse(ids):
+ for sa in get_model('share.access').search_browse([]):
+ for pf in sa.profiles:
+ if profile_id==pf.id:
+ exist_model.append(sa.model_id.name)
+ break
+ # create new
+ for model,field_dom, op in models:
+ if model in exist_model:
+ print('already exist ', model)
+ continue
+ for model_id in get_model("model").search(['name','=',model]):
+ dom=[]
+ dom='["or",%s]'%(', '.join(['["%s","%s","%s"]'%(field_dom,op,dpt_code) for dpt_code in dpt_codes]))
+ print('dom ', dom)
+ get_model('share.access').create({
+ 'model_id': model_id,
+ 'profiles': [['set',[profile_id]]],
+ 'default_access': 'custom',
+ 'filter_type': 'rw',
+ 'select_profile': 'include',
+ 'domain': dom,
+ })
+ return profile_id
+ print("Done!")
+
def select(self,ids,context={}):
user_id=get_active_user()
if user_id==1:
return
+ user=get_model('base.user').browse(user_id)
obj=self.browse(ids)[0]
if obj.department:
- user=get_model('base.user').browse(user_id)
- set_active_user(1)
+ # set to main profile of that user
for dpt in get_model("clinic.department").search_browse([["name","=",obj.department]]):
user.write({
'department_id': dpt.id, #current department
@@ -60,7 +157,13 @@ class SelectCompany(Model):
user.write({
'profile_id': pf_id,
})
- set_active_user(user_id)
+ else:
+ context['profile_id']=obj.check_profile(context=context)
+ pf_id=obj.share_profile(context=context)
+ user.write({
+ 'department_id': None, #all include department
+ 'profile_id': pf_id,
+ })
res=super().select(ids,context)
return res
diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py
index 8d5a5dc..13a3749 100644
--- a/netforce_clinic/models/setting.py
+++ b/netforce_clinic/models/setting.py
@@ -149,18 +149,14 @@ class ClinicSetting(Model):
if user_id !=1:
print("Only admin!!")
return
- # update
- db=get_connection()
- res=db.query("select id, day from clinic_patient_cycle")
- for r in res:
- day=r['day'] or ""
- if day.isdigit():
- pc=get_model('clinic.patient.cycle').browse(r['id'])
- pc.write({
- 'day': DAYS[int(r['day'])],
- })
+
+ files=['Patients_Data_LS1.csv','Patients_Data_LS2.csv','Patients_Data_LS3.csv']
+ self.update_patient_file(files)
+ print("Done!")
return
- ### remove douplicate visit
+ ###TODO remove douplicate patient
+ ###TODO remove douplicate staff
+ ###TODO remove douplicate visit
visits={}
for visit in get_model("clinic.visit").search_browse([]):
key='%s-%s'%(visit.visit_date, visit.patient_id.id)
@@ -319,7 +315,6 @@ class ClinicSetting(Model):
for sr in get_model(model_name).search_read(dom,['name']):
res[sr['name']]=sr['id']
return res
-
vasculars=get_dicts('clinic.vascular.access')
cycles=get_dicts('clinic.cycle')
titles=get_dicts('clinic.name.title')
@@ -389,7 +384,6 @@ class ClinicSetting(Model):
'vascular_acc': valc,
'department_id': dpt,
}
-
print(" update patient data")
for patient_id, vals in datas.items():
if not patient_id:
@@ -401,7 +395,13 @@ class ClinicSetting(Model):
pass
if not vals['card_no']:
vals['card_no']='/'
+ else:
+ vals['card_no']=''.join([x for x in vals['card_no'] if x.isdigit()])
+ # recheck
+ if not vals['card_no']:
+ vals['card_no']='/'
pvals=vals.copy()
+ print(pvals)
get_model("clinic.patient").browse(int(patient_id)).write(pvals)
print("Done!")
diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py
index 055a198..99b1f23 100644
--- a/netforce_clinic/models/visit.py
+++ b/netforce_clinic/models/visit.py
@@ -325,38 +325,28 @@ class Visit(Model):
data=context['data']
patient_id=data['patient_id']
patient=get_model("clinic.patient").browse(patient_id)
+ doctor=patient.doctor_id
visits=self.search_browse([['patient_id','=',patient_id]],order="number desc")
if visits:
visit=visits[0]
- doctor=visit.doctor_id
department_id=None
if visit.department_id:
department_id=visit.department_id.id
elif patient.department_id:
department_id=patient.department_id.id
-
branch_id=None
if visit.branch_id:
branch_id=visit.branch_id.id
elif patient.branch_id:
branch_id=patient.branch_id.id
- print("branch_id ", branch_id)
- data['doctor_id']=doctor.id
data['department_id']=department_id
data['branch_id']=branch_id
-
- if not patient.doctor_id:
- patient.write({
- 'doctor_id': doctor.id,
- })
else:
- doctor=patient.doctor_id
department=patient.department_id
branch=patient.branch_id
- data['doctor_id']=doctor.id
data['department_id']=department.id
data['branch_id']=branch.id
-
+ data['doctor_id']=doctor.id
return data
def copy(self,ids,context={}) :
@@ -493,4 +483,13 @@ class Visit(Model):
'state': 'pending',
})
+
+ def onchange_department(self,context={}):
+ data=context['data']
+ dpt_id=data['department_id']
+ if dpt_id:
+ dpt=get_model("clinic.department").browse(dpt_id)
+ data['branch_id']=dpt.branch_id.id
+ return data
+
Visit.register()
diff --git a/netforce_clinic/templates/clinic_page.hbs b/netforce_clinic/templates/clinic_page.hbs
index e94704a..2d53b83 100644
--- a/netforce_clinic/templates/clinic_page.hbs
+++ b/netforce_clinic/templates/clinic_page.hbs
@@ -28,9 +28,6 @@
-