5
5
# Copyright 2018 by it's authors.
6
6
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst.
7
7
8
- from Products . CMFCore . utils import getToolByName
8
+ from collections import OrderedDict
9
9
10
+ from Products .CMFCore .utils import getToolByName
10
11
from bika .health import bikaMessageFactory as _
11
12
from bika .health .permissions import *
12
13
from bika .lims import api
13
14
from bika .lims .browser .client import ClientContactsView
14
- from bika .lims .interfaces import IClient , ILabContact
15
+ from bika .lims .interfaces import IClient
16
+ from bika .lims .utils import get_link
17
+ from plone .memoize import view as viewcache
15
18
16
19
17
20
class DoctorsView (ClientContactsView ):
@@ -24,31 +27,36 @@ def __init__(self, context, request):
24
27
self .title = self .context .translate (_ ("Doctors" ))
25
28
self .icon = self .portal_url + "/++resource++bika.health.images/doctor_big.png"
26
29
self .description = ""
27
- self .show_sort_column = False
28
- self .show_select_row = False
29
- self .show_select_column = False
30
- self .pagesize = 50
31
30
32
- self .columns = {
33
- 'getDoctorID' : {'title' : _ ('Doctor ID' ),
34
- 'index' : 'getDoctorID' },
35
- 'getFullname' : {'title' : _ ('Full Name' ),
36
- 'index' : 'getFullname' },
37
- 'getEmailAddress' : {'title' : _ ('Email Address' )},
38
- 'getBusinessPhone' : {'title' : _ ('Business Phone' )},
39
- 'getMobilePhone' : {'title' : _ ('Mobile Phone' )},
40
- }
31
+ self .columns = OrderedDict ((
32
+ ("getDoctorID" , {
33
+ "title" : _ ('Doctor ID' ),
34
+ "index" : "getDoctorID" ,
35
+ "sortable" : True , }),
36
+ ("getFullname" , {
37
+ "title" : _ ("Full Name" ),
38
+ "index" : "getFullname" ,
39
+ "sortable" : True , }),
40
+ ("getPrimaryReferrer" , {
41
+ "title" : _ ("Primary Referrer" ),
42
+ "index" : "getPrimaryReferrerUID" ,
43
+ "sortable" : True , }),
44
+ ("Username" , {
45
+ "title" : _ ("User Name" ), }),
46
+ ("getEmailAddress" , {
47
+ "title" : _ ("Email Address" ), }),
48
+ ("getBusinessPhone" , {
49
+ "title" : _ ("Business Phone" ), }),
50
+ ("getMobilePhone" , {
51
+ "title" : _ ("MobilePhone" ), }),
52
+ ))
41
53
42
54
self .review_states = [
43
55
{'id' :'default' ,
44
56
'title' : _ ('Active' ),
45
57
'contentFilter' : {'inactive_state' : 'active' },
46
58
'transitions' : [],
47
- 'columns' : ['getDoctorID' ,
48
- 'getFullname' ,
49
- 'getEmailAddress' ,
50
- 'getBusinessPhone' ,
51
- 'getMobilePhone' ]},
59
+ 'columns' : self .columns .keys ()},
52
60
]
53
61
54
62
def __call__ (self ):
@@ -68,68 +76,50 @@ def __call__(self):
68
76
'title' : _ ('Dormant' ),
69
77
'contentFilter' : {'inactive_state' : 'inactive' },
70
78
'transitions' : [{'id' :'activate' }, ],
71
- 'columns' : ['getDoctorID' ,
72
- 'getFullname' ,
73
- 'getEmailAddress' ,
74
- 'getBusinessPhone' ,
75
- 'getMobilePhone' ]})
79
+ 'columns' : self .columns .keys ()})
76
80
self .review_states .append (
77
81
{'id' :'all' ,
78
82
'title' : _ ('All' ),
79
83
'contentFilter' :{},
80
84
'transitions' :[{'id' :'empty' }],
81
- 'columns' : ['getDoctorID' ,
82
- 'getFullname' ,
83
- 'getEmailAddress' ,
84
- 'getBusinessPhone' ,
85
- 'getMobilePhone' ]})
85
+ 'columns' : self .columns .keys ()})
86
86
stat = self .request .get ("%s_review_state" % self .form_id , 'default' )
87
87
self .show_select_column = stat != 'all'
88
- self ._apply_filter_by_client ()
89
- return super (DoctorsView , self ).__call__ ()
90
88
91
- def folderitems (self ):
92
- items = super (DoctorsView , self ).folderitems ()
93
- for x in range (len (items )):
94
- if not 'obj' in items [x ]:
95
- continue
96
- obj = items [x ]['obj' ]
97
- items [x ]['replace' ]['getDoctorID' ] = "<a href='%s'>%s</a>" % \
98
- (items [x ]['url' ], items [x ]['getDoctorID' ])
99
- items [x ]['replace' ]['getFullname' ] = "<a href='%s'>%s</a>" % \
100
- (items [x ]['url' ], items [x ]['getFullname' ])
101
-
102
- return items
103
-
104
- def _apply_filter_by_client (self ):
105
- """
106
- From the current user and the context, update the filter that will be
107
- used for filtering the Doctor's list.
108
- """
109
89
# If the current context is a Client, filter Doctors by Client UID
110
90
if IClient .providedBy (self .context ):
111
91
client_uid = api .get_uid (self .context )
112
92
self .contentFilter ['getPrimaryReferrerUID' ] = client_uid
113
- return
114
93
115
- # If the current user is a Client contact, filter the Doctors in
116
- # accordance. For the rest of users (LabContacts), the visibility of
117
- # the doctors depend on their permissions
118
- user = api .get_current_user ()
119
- roles = user .getRoles ()
120
- if 'Client' not in roles :
121
- return
94
+ # If the current user is a client contact, do not display the doctors
95
+ # assigned to other clients
96
+ elif self .get_user_client_uid ():
97
+ client_uid = self .get_user_client_uid ()
98
+ self .contentFilter ['getPrimaryReferrerUID' ] = [client_uid , None ]
122
99
123
- # Are we sure this a ClientContact?
124
- # May happen that this is a Plone member, w/o having a ClientContact
125
- # assigned or having a LabContact assigned... weird
126
- contact = api .get_user_contact (user )
127
- if not contact or ILabContact .providedBy (contact ):
128
- return
100
+ return super (DoctorsView , self ).__call__ ()
129
101
130
- # Is the parent from the Contact a Client?
131
- client = api .get_parent (contact )
132
- if not client or not IClient .providedBy (client ):
133
- return
134
- client_uid = api .get_uid (client )
135
- self .contentFilter ['getPrimaryReferrerUID' ] = client_uid
102
+ @viewcache .memoize
103
+ def get_user_client_uid (self , default = None ):
104
+ """Returns the id of the client the current user belongs to
105
+ """
106
+ client = api .get_current_client ()
107
+ if client :
108
+ return api .get_uid (client )
109
+ return default
110
+
111
+ def folderitem (self , obj , item , index ):
112
+ """Applies new properties to the item to be rendered
113
+ """
114
+ item = super (DoctorsView , self ).folderitem (obj , item , index )
115
+ url = item .get ("url" )
116
+ doctor_id = item .get ("getDoctorID" )
117
+ item ['replace' ]['getDoctorID' ] = get_link (url , value = doctor_id )
118
+ item ['getPrimaryReferrer' ] = ""
119
+ doctor = api .get_object (obj )
120
+ pri = doctor .getPrimaryReferrer ()
121
+ if pri :
122
+ pri_url = pri .absolute_url ()
123
+ pri = pri .Title ()
124
+ item ['replace' ]['getPrimaryReferrer' ] = get_link (pri_url , value = pri )
125
+ return item
0 commit comments