Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Commit a92ce6b

Browse files
authored
Doctors assigned to other clients are listed when logged as Client (#102)
* Filter doctors by current's user client If the current user is a Client contact, only the doctors assigned to the same client and those that do not have any client assigned are displayed. If user is from the lab, no filtering is applied. If the current context of the listing is Client, only doctors assigned to same client are displayed. * Cleanup folderitems function from Doctors view * Cleanup Doctors listing view Dependencies: senaite/senaite.core#1012 * Hide doctors from other clients when logged as client * Don't display doctors from other clients in AR Add Dependencies: senaite/senaite.core#1014 In AR Add form, do not display doctors from other client than the one selected, but include those that do not have any client assigned * Don't display doctors from other clients in AR Add Dependencies: senaite/senaite.core#1014 In AR Add form, do not display doctors from other client than the one selected, but include those that do not have any client assigned * Do not display doctors from other clients in Case Add view * Add Primary Referrer column in Doctor listings
1 parent e5e7ee7 commit a92ce6b

File tree

5 files changed

+112
-89
lines changed

5 files changed

+112
-89
lines changed

CHANGES.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Changelog
66

77
**Added**
88

9+
- #102 Add Primary Referrer column in Doctor listings
910
- #85 Allow client contact to list/add/edit Batches from its own Client
1011
- #83 Allow client contact to create and edit Doctors
1112

@@ -18,7 +19,8 @@ Changelog
1819

1920
**Fixed**
2021

21-
- #102 All Samples are listed inside Case context
22+
- #102 Doctors assigned to other clients are listed when logged as Client
23+
- #103 All Samples are listed inside Case context
2224
- #99 Traceback when publishing health results from inside a client
2325
- #97 Traceback accessing Doctor samples when user is not Manager, LabManager or LabClerk
2426
- #82 Inconsistent behavior with health' skins priority over core's

bika/health/browser/doctors/folder_view.py

+60-70
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
# Copyright 2018 by it's authors.
66
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst.
77

8-
from Products.CMFCore.utils import getToolByName
8+
from collections import OrderedDict
99

10+
from Products.CMFCore.utils import getToolByName
1011
from bika.health import bikaMessageFactory as _
1112
from bika.health.permissions import *
1213
from bika.lims import api
1314
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
1518

1619

1720
class DoctorsView(ClientContactsView):
@@ -24,31 +27,36 @@ def __init__(self, context, request):
2427
self.title = self.context.translate(_("Doctors"))
2528
self.icon = self.portal_url + "/++resource++bika.health.images/doctor_big.png"
2629
self.description = ""
27-
self.show_sort_column = False
28-
self.show_select_row = False
29-
self.show_select_column = False
30-
self.pagesize = 50
3130

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+
))
4153

4254
self.review_states = [
4355
{'id':'default',
4456
'title': _('Active'),
4557
'contentFilter': {'inactive_state': 'active'},
4658
'transitions': [],
47-
'columns': ['getDoctorID',
48-
'getFullname',
49-
'getEmailAddress',
50-
'getBusinessPhone',
51-
'getMobilePhone']},
59+
'columns': self.columns.keys()},
5260
]
5361

5462
def __call__(self):
@@ -68,68 +76,50 @@ def __call__(self):
6876
'title': _('Dormant'),
6977
'contentFilter': {'inactive_state': 'inactive'},
7078
'transitions': [{'id':'activate'}, ],
71-
'columns': ['getDoctorID',
72-
'getFullname',
73-
'getEmailAddress',
74-
'getBusinessPhone',
75-
'getMobilePhone']})
79+
'columns': self.columns.keys()})
7680
self.review_states.append(
7781
{'id':'all',
7882
'title': _('All'),
7983
'contentFilter':{},
8084
'transitions':[{'id':'empty'}],
81-
'columns': ['getDoctorID',
82-
'getFullname',
83-
'getEmailAddress',
84-
'getBusinessPhone',
85-
'getMobilePhone']})
85+
'columns': self.columns.keys()})
8686
stat = self.request.get("%s_review_state"%self.form_id, 'default')
8787
self.show_select_column = stat != 'all'
88-
self._apply_filter_by_client()
89-
return super(DoctorsView, self).__call__()
9088

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-
"""
10989
# If the current context is a Client, filter Doctors by Client UID
11090
if IClient.providedBy(self.context):
11191
client_uid = api.get_uid(self.context)
11292
self.contentFilter['getPrimaryReferrerUID'] = client_uid
113-
return
11493

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]
12299

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__()
129101

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

bika/health/browser/doctors/getdoctors.py

+41-18
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
# Copyright 2018 by it's authors.
66
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst.
77

8-
from Products.CMFCore.utils import getToolByName
9-
from bika.health import bikaMessageFactory as _
10-
from bika.health.permissions import *
11-
from bika.lims import bikaMessageFactory as _b
12-
from bika.lims.browser import BrowserView
13-
from operator import itemgetter
148
import json
9+
from operator import itemgetter
10+
1511
import plone
12+
from bika.lims import api
13+
from bika.lims.browser import BrowserView
14+
from bika.lims.interfaces import ILabContact, IClient
1615

1716

1817
class ajaxGetDoctors(BrowserView):
@@ -25,21 +24,27 @@ def __call__(self):
2524
nr_rows = self.request['rows']
2625
sord = self.request['sord']
2726
sidx = self.request['sidx']
28-
2927
rows = []
3028

31-
pc = self.portal_catalog
32-
proxies = pc(portal_type="Doctor")
33-
for doctor in proxies:
34-
doctor = doctor.getObject()
35-
if self.portal_workflow.getInfoFor(doctor, 'inactive_state', 'active') == 'inactive':
29+
query = dict(portal_type="Doctor", inactive_state="active")
30+
client = self.get_current_client()
31+
if client:
32+
# Search those Doctors that are assigned to the same client or
33+
# that do not have any client assigned
34+
query["getPrimaryReferrerUID"] = [api.get_uid(client), None]
35+
36+
doctors = api.search(query, 'portal_catalog')
37+
for doctor in doctors:
38+
doctor_id = doctor.id
39+
doctor_title = doctor.Title
40+
search_val = ('{} {}'.format(doctor_id, doctor_title)).lower()
41+
if searchTerm not in search_val:
3642
continue
37-
if doctor.Title().lower().find(searchTerm) > -1 \
38-
or doctor.getDoctorID().lower().find(searchTerm) > -1:
39-
rows.append({'Title': doctor.Title() or '',
40-
'DoctorID': doctor.getDoctorID(),
41-
'DoctorSysID': doctor.id,
42-
'DoctorUID': doctor.UID()})
43+
44+
rows.append({'Title': doctor.Title() or '',
45+
'DoctorID': doctor.getDoctorID(),
46+
'DoctorSysID': doctor.id,
47+
'DoctorUID': doctor.UID()})
4348

4449
rows = sorted(rows, cmp=lambda x, y: cmp(x.lower(), y.lower()), key = itemgetter(sidx and sidx or 'Title'))
4550
if sord == 'desc':
@@ -52,3 +57,21 @@ def __call__(self):
5257
'rows': rows[(int(page) - 1) * int(nr_rows): int(page) * int(nr_rows)]}
5358

5459
return json.dumps(ret)
60+
61+
def get_current_client(self, default=None):
62+
"""Returns the client the current user belongs to
63+
"""
64+
user = api.get_current_user()
65+
roles = user.getRoles()
66+
if 'Client' not in roles:
67+
return default
68+
69+
contact = api.get_user_contact(user)
70+
if not contact or ILabContact.providedBy(contact):
71+
return default
72+
73+
client = api.get_parent(contact)
74+
if not client or not IClient.providedBy(client):
75+
return default
76+
77+
return client

bika/health/static/js/bika.health.analysisrequest.add.js

+6
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,12 @@ function HealthAnalysisRequestAddView() {
298298
if (element.length > 0) {
299299
filter_combogrid(element[0], "getParentUID", clientuid);
300300
}
301+
302+
// Doctor searches
303+
element = $("#Doctor-" + col);
304+
if (element.length > 0) {
305+
filter_combogrid(element[0], "getPrimaryReferrerUID", [clientuid, null]);
306+
}
301307
}
302308
}
303309

bika/health/static/js/bika.health.batch.js

+2
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ function HealthBatchEditView() {
202202
// client inside patient-related combos
203203
applyFilter($("#Patient"), 'getPrimaryReferrerUID', rcuid);
204204
applyFilter($("#ClientPatientID"), 'getPrimaryReferrerUID', rcuid);
205+
// Also, show only the Doctors that are not from a different client
206+
applyFilter($("#Doctor"), 'getPrimaryReferrerUID', [rcuid, null]);
205207
}
206208

207209
// By default, get the referrer uids from the form itself. If the form is

0 commit comments

Comments
 (0)