1 """GNUmed staff management widgets."""
2
3 __author__ = "K. Hilbert <Karsten.Hilbert@gmx.net>"
4 __license__ = "GPL v2 or later (details at http://www.gnu.org)"
5
6 import logging
7
8
9 import wx
10
11
12 from Gnumed.pycommon import gmTools
13 from Gnumed.pycommon import gmI18N
14 from Gnumed.pycommon import gmMatchProvider
15
16 from Gnumed.business import gmPerson
17 from Gnumed.business import gmStaff
18
19 from Gnumed.wxpython import gmGuiHelpers
20 from Gnumed.wxpython import gmAuthWidgets
21 from Gnumed.wxpython import gmPhraseWheel
22
23
24 _log = logging.getLogger('gm.ui')
25
26
39
40
42
44
45 gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs)
46
47 items = [
48 {'list_label': _('Public (no clinical or demographic access)'), 'field_label': _('public'), 'data': 'public', 'weight': 1},
49 {'list_label': _('Staff (demographic access only)'), 'field_label': _('staff (clerical)'), 'data': 'staff', 'weight': 1},
50 {'list_label': _('Doctor (full access)'), 'field_label': _('doctor'), 'data': 'doctor', 'weight': 1},
51 ]
52 mp = gmMatchProvider.cMatchProvider_FixedList(items)
53 mp.setThresholds(1, 2, 3)
54 mp.word_separators = None
55
56
57 self.matcher = mp
58 self.selection_only = True
59
60
61 from Gnumed.wxGladeWidgets import wxgEditStaffListDlg
62
64
66 wxgEditStaffListDlg.wxgEditStaffListDlg.__init__(self, *args, **kwds)
67
68 self._LCTRL_staff.InsertColumn(0, _('Alias'))
69 self._LCTRL_staff.InsertColumn(1, _('DB account'))
70 self._LCTRL_staff.InsertColumn(2, _('Role'))
71 self._LCTRL_staff.InsertColumn(3, _('Name'))
72 self._LCTRL_staff.InsertColumn(4, _('Comment'))
73 self._LCTRL_staff.InsertColumn(5, _('Status'))
74
75 self.__init_ui_data()
76
77
78
80 lbl_active = {True: _('active'), False: _('inactive')}
81 lbl_login = {True: _('can login'), False: _('can not login')}
82
83 self._LCTRL_staff.DeleteAllItems()
84 staff_list = gmStaff.get_staff_list()
85 pos = len(staff_list) + 1
86 for staff in staff_list:
87 row_num = self._LCTRL_staff.InsertStringItem(pos, label=staff['short_alias'])
88 self._LCTRL_staff.SetStringItem(index = row_num, col = 1, label = staff['db_user'])
89 self._LCTRL_staff.SetStringItem(index = row_num, col = 2, label = staff['l10n_role'])
90 title = gmTools.coalesce(staff['title'], '')
91 self._LCTRL_staff.SetStringItem(index = row_num, col = 3, label = '%s %s, %s' % (title, staff['lastnames'], staff['firstnames']))
92 self._LCTRL_staff.SetStringItem(index = row_num, col = 4, label = gmTools.coalesce(staff['comment'], ''))
93 self._LCTRL_staff.SetStringItem(index = row_num, col = 5, label = '%s / %s' % (lbl_active[bool(staff['is_active'])], lbl_login[bool(staff['can_login'])]))
94
95 if staff['is_active'] and staff['can_login']:
96
97 pass
98 elif not staff['is_active'] and not staff['can_login']:
99 self._LCTRL_staff.SetItemTextColour(row_num, col=wx.LIGHT_GREY)
100 else:
101 self._LCTRL_staff.SetItemTextColour(row_num, col=wx.NamedColour('RED'))
102
103 self._LCTRL_staff.SetItemData(item = row_num, data = staff['pk_staff'])
104
105 if len(staff_list) > 0:
106 self._LCTRL_staff.SetColumnWidth(col=0, width=wx.LIST_AUTOSIZE)
107 self._LCTRL_staff.SetColumnWidth(col=1, width=wx.LIST_AUTOSIZE_USEHEADER)
108 self._LCTRL_staff.SetColumnWidth(col=2, width=wx.LIST_AUTOSIZE)
109 self._LCTRL_staff.SetColumnWidth(col=3, width=wx.LIST_AUTOSIZE)
110 self._LCTRL_staff.SetColumnWidth(col=4, width=wx.LIST_AUTOSIZE)
111 self._LCTRL_staff.SetColumnWidth(col=5, width=wx.LIST_AUTOSIZE)
112
113
114 self._btn_save.Enable(False)
115 self._btn_delete.Enable(False)
116 self._btn_deactivate.Enable(False)
117 self._btn_activate.Enable(False)
118
119 self._TCTRL_name.SetValue('')
120 self._TCTRL_alias.SetValue('')
121 self._TCTRL_account.SetValue('')
122 self._PRW_user_role.SetText(value = u'', data = None)
123 self._TCTRL_comment.SetValue('')
124
125
126
128 self._btn_save.Enable(True)
129 self._btn_delete.Enable(True)
130 self._btn_deactivate.Enable(True)
131 self._btn_activate.Enable(True)
132
133 pk_staff = self._LCTRL_staff.GetItemData(self._LCTRL_staff.GetFirstSelected())
134 staff = gmStaff.cStaff(aPK_obj=pk_staff)
135 self._TCTRL_name.SetValue('%s.%s %s' % (staff['title'], staff['firstnames'], staff['lastnames']))
136 self._TCTRL_alias.SetValue(staff['short_alias'])
137 self._TCTRL_account.SetValue(staff['db_user'])
138 self._PRW_user_role.SetText(value = staff['l10n_role'], data = staff['role'], suppress_smarts = True)
139 self._TCTRL_comment.SetValue(gmTools.coalesce(staff['comment'], ''))
140
142 self._btn_save.Enable(False)
143 self._btn_delete.Enable(False)
144 self._btn_deactivate.Enable(False)
145 self._btn_activate.Enable(False)
146
147 self._TCTRL_name.SetValue('')
148 self._TCTRL_alias.SetValue('')
149 self._TCTRL_account.SetValue('')
150 self._PRW_user_role.SetText(value = u'', data = None)
151 self._TCTRL_comment.SetValue('')
152
162
172
185
217
218 from Gnumed.wxGladeWidgets import wxgAddPatientAsStaffDlg
219
221
225
226
227
238
239
240
243
293
294
295