@@ -94,7 +94,24 @@ def get_clients_vocabulary(self):
9494 # Allow to change the client if there are no ARs associated
9595 client = self .getPrimaryReferrer ()
9696 if not client :
97- return DisplayList ([('' , '' )])
97+ # Maybe all Batches and ARs assigned to this Doctor belong to
98+ # the same Client.. If so, just assign this client by default
99+ client_uids = map (lambda ar : ar .getClientUID ,
100+ self .getAnalysisRequests ())
101+ client_uids = list (set (client_uids ))
102+ if len (client_uids ) > 1 :
103+ # More than one client assigned!
104+ return DisplayList ([('' , '' )])
105+ clients = map (lambda batch : batch .getClient (),
106+ self .getBatches (full_objects = True ))
107+ client_uids += map (lambda client : api .get_uid (client ), clients )
108+ client_uids = list (set (client_uids ))
109+ if len (client_uids ) > 1 :
110+ # More than one client assigned!
111+ return DisplayList ([('' , '' )])
112+
113+ client = api .get_object_by_uid (client_uids [0 ])
114+
98115 return DisplayList ([(api .get_uid (client ), client .Title ())])
99116
100117 # If the current user is a client contact, do not display other clients
0 commit comments