diff --git a/netforce_clinic/actions/clinic_share_location.xml b/netforce_clinic/actions/clinic_share_location.xml
new file mode 100644
index 0000000..ba67009
--- /dev/null
+++ b/netforce_clinic/actions/clinic_share_location.xml
@@ -0,0 +1,6 @@
+
+ Share Location
+ form_popup
+ clinic.share.location
+ _popup
+
diff --git a/netforce_clinic/layouts/clinic_patient_form.xml b/netforce_clinic/layouts/clinic_patient_form.xml
index fabca02..7549ce7 100644
--- a/netforce_clinic/layouts/clinic_patient_form.xml
+++ b/netforce_clinic/layouts/clinic_patient_form.xml
@@ -2,7 +2,7 @@
@@ -17,6 +17,7 @@
+
@@ -95,6 +96,7 @@
-->
+
diff --git a/netforce_clinic/layouts/clinic_share_location.xml b/netforce_clinic/layouts/clinic_share_location.xml
new file mode 100644
index 0000000..8da396c
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_share_location.xml
@@ -0,0 +1,20 @@
+
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index a3c962e..2b18ad9 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -135,5 +135,6 @@ from . import report_thai_wht_certif
from . import num2word
from . import province
from . import change_visit
+from . import share_location
#from . import district
#from . import subdistrict
diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py
index c2ac3c8..becc123 100644
--- a/netforce_clinic/models/patient.py
+++ b/netforce_clinic/models/patient.py
@@ -74,9 +74,6 @@ class Patient(Model):
dpt_codes=set()
# main department
dpt_codes.update({obj.department_id.code})
- # hd department
- for dpt in obj.departments:
- dpt_codes.update({dpt.code})
# cycle settings
for cline in obj.cycles:
dpt_codes.update({cline.department_id.code})
@@ -178,9 +175,8 @@ class Patient(Model):
"vascular_acc": fields.Many2One("clinic.vascular.access","Vascular Ac."),
'state': fields.Selection([['admit','Admit'],['dispose','Dispose']],'State'),
'walkin': fields.Selection([['yes','Yes'],['no','No']],"Walkin"),
- 'departments': fields.Many2Many("clinic.department","Departments"),
'department_names': fields.Text("Departments",function="_get_department_names"),
- 'location': fields.Char("Location",function="_get_location",store=True), #to filter
+ 'location': fields.Char("Location"), #to filter
}
def _get_number(self,context={}):
@@ -275,7 +271,6 @@ class Patient(Model):
}
_sql_constraints=("clinic_patient_key_uniq","unique(name_check)","name should be unique"),
- #_order="reg_date desc"
def check_idcard(self,card_type,idcard=''):
res=True
diff --git a/netforce_clinic/models/share_location.py b/netforce_clinic/models/share_location.py
new file mode 100644
index 0000000..e240967
--- /dev/null
+++ b/netforce_clinic/models/share_location.py
@@ -0,0 +1,107 @@
+from netforce.access import get_active_user, set_active_user
+from netforce.model import Model, fields, get_model
+from netforce.database import get_connection
+
+
+class ShareLocation(Model):
+ _name="clinic.share.location"
+ _transient=True
+ _select_patient=None
+
+ _fields={
+ 'patient_id': fields.Many2One("clinic.patient","Patient",required=True),
+ 'location': fields.Char("Location",required=True),
+ "loc_select": fields.Selection([],"Departments"),
+ }
+
+ def get_location_user(self,patient_id=None,patient_only=False):
+ user_id=get_active_user()
+ user=get_model('base.user').browse(user_id)
+ department=user.department_id
+ loc=[]
+ if department and not patient_only:
+ loc.append(department.code)
+ if patient_id:
+ patient=get_model('clinic.patient').browse(patient_id)
+ self._select_patient=patient.id
+ department=patient.department_id
+ loc.append(department.code)
+ return loc
+
+ def default_get(self,field_names=None,context={},**kw):
+ refer_id=context.get("refer_id")
+ patient_id=None
+ location=''
+ if refer_id:
+ patient_id=int(refer_id)
+ patient=get_model('clinic.patient').browse(patient_id)
+ location=patient.location or ''
+ uloc=self.get_location_user(patient.id)
+ new_loc=[]
+ for loc_code in location.split(","):
+ if loc_code in uloc:
+ continue
+ new_loc.append(loc_code)
+ location=','.join(new_loc)
+ res={
+ 'patient_id': patient_id,
+ 'location': location,
+ }
+ return res
+
+ def get_location(self,context={}):
+ user_id=get_active_user()
+ uloc=self.get_location_user(self._select_patient)
+ set_active_user(1)
+ res=get_model("clinic.department").search_read([],["code","name"])
+ set_active_user(user_id)
+ return [(r["code"],'%s [%s]'%(r['name'],r["code"])) for r in res if r['code'] not in uloc]
+
+ def onchange_location(self,context={}):
+ data=context['data']
+ location=data['location'] or ''
+ location=location.split(",")+[data['loc_select'] or '']
+ sloc=list(set(location))
+ data['location']=','.join([loc for loc in sloc if loc])
+ return data
+
+ def do_share(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ patient=obj.patient_id
+ uloc=self.get_location_user(patient.id,patient_only=True)
+ new_loc=uloc
+ for loc_code in obj.location.split(","):
+ res=get_model('clinic.department').search([['code','=',loc_code]])
+ if not res:
+ raise Exception("Department code %s not found!"%(loc_code))
+ new_loc.append(loc_code)
+ main_loc=patient.department_id.code
+ if main_loc not in new_loc:
+ raise Exception("Can not delete main department %s"%(main_loc))
+ #TODO check user location
+ location=','.join(new_loc)
+ db=get_connection()
+ db.execute("update clinic_patient set location=%s where id=%s",location,patient.id)
+ return {
+ 'next': {
+ 'name': 'clinic_patient',
+ 'mode': 'form',
+ 'active_id': patient.id,
+ },
+ }
+
+ def do_clear(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ obj.write({
+ 'location': '',
+ })
+ return {
+ 'next': {
+ 'name': 'clinic_share_location',
+ 'mode': 'form',
+ 'active_id': ids[0],
+ },
+ }
+
+ShareLocation.register()
+