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
28
30
31 gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs)
32
33 items = [
34 {'list_label': _('Public (no clinical or demographic access)'), 'field_label': _('public'), 'data': 'public', 'weight': 1},
35 {'list_label': _('Staff (demographic access only)'), 'field_label': _('staff (clerical)'), 'data': 'staff', 'weight': 1},
36 {'list_label': _('Doctor (full access)'), 'field_label': _('doctor'), 'data': 'doctor', 'weight': 1},
37 ]
38 mp = gmMatchProvider.cMatchProvider_FixedList(items)
39 mp.setThresholds(1, 2, 3)
40 mp.word_separators = None
41
42
43 self.matcher = mp
44 self.selection_only = True
45
46
47 from Gnumed.wxGladeWidgets import wxgEditStaffListDlg
48
50
52 wxgEditStaffListDlg.wxgEditStaffListDlg.__init__(self, *args, **kwds)
53
54 self._LCTRL_staff.InsertColumn(0, _('Alias'))
55 self._LCTRL_staff.InsertColumn(1, _('DB account'))
56 self._LCTRL_staff.InsertColumn(2, _('Role'))
57 self._LCTRL_staff.InsertColumn(3, _('Name'))
58 self._LCTRL_staff.InsertColumn(4, _('Comment'))
59 self._LCTRL_staff.InsertColumn(5, _('Status'))
60
61 self.__init_ui_data()
62
63
64
66 lbl_active = {True: _('active'), False: _('inactive')}
67 lbl_login = {True: _('can login'), False: _('can not login')}
68
69 self._LCTRL_staff.DeleteAllItems()
70 staff_list = gmStaff.get_staff_list()
71 pos = len(staff_list) + 1
72 for staff in staff_list:
73 row_num = self._LCTRL_staff.InsertStringItem(pos, label=staff['short_alias'])
74 self._LCTRL_staff.SetStringItem(index = row_num, col = 1, label = staff['db_user'])
75 self._LCTRL_staff.SetStringItem(index = row_num, col = 2, label = staff['l10n_role'])
76 title = gmTools.coalesce(staff['title'], '')
77 self._LCTRL_staff.SetStringItem(index = row_num, col = 3, label = '%s %s, %s' % (title, staff['lastnames'], staff['firstnames']))
78 self._LCTRL_staff.SetStringItem(index = row_num, col = 4, label = gmTools.coalesce(staff['comment'], ''))
79 self._LCTRL_staff.SetStringItem(index = row_num, col = 5, label = '%s / %s' % (lbl_active[bool(staff['is_active'])], lbl_login[bool(staff['can_login'])]))
80
81 if staff['is_active'] and staff['can_login']:
82
83 pass
84 elif not staff['is_active'] and not staff['can_login']:
85 self._LCTRL_staff.SetItemTextColour(row_num, col=wx.LIGHT_GREY)
86 else:
87 self._LCTRL_staff.SetItemTextColour(row_num, col=wx.NamedColour('RED'))
88
89 self._LCTRL_staff.SetItemData(item = row_num, data = staff['pk_staff'])
90
91 if len(staff_list) > 0:
92 self._LCTRL_staff.SetColumnWidth(col=0, width=wx.LIST_AUTOSIZE)
93 self._LCTRL_staff.SetColumnWidth(col=1, width=wx.LIST_AUTOSIZE_USEHEADER)
94 self._LCTRL_staff.SetColumnWidth(col=2, width=wx.LIST_AUTOSIZE)
95 self._LCTRL_staff.SetColumnWidth(col=3, width=wx.LIST_AUTOSIZE)
96 self._LCTRL_staff.SetColumnWidth(col=4, width=wx.LIST_AUTOSIZE)
97 self._LCTRL_staff.SetColumnWidth(col=5, width=wx.LIST_AUTOSIZE)
98
99
100 self._btn_save.Enable(False)
101 self._btn_delete.Enable(False)
102 self._btn_deactivate.Enable(False)
103 self._btn_activate.Enable(False)
104
105 self._TCTRL_name.SetValue('')
106 self._TCTRL_alias.SetValue('')
107 self._TCTRL_account.SetValue('')
108 self._PRW_user_role.SetText(value = u'', data = None)
109 self._TCTRL_comment.SetValue('')
110
111
112
114 self._btn_save.Enable(True)
115 self._btn_delete.Enable(True)
116 self._btn_deactivate.Enable(True)
117 self._btn_activate.Enable(True)
118
119 pk_staff = self._LCTRL_staff.GetItemData(self._LCTRL_staff.GetFirstSelected())
120 staff = gmStaff.cStaff(aPK_obj=pk_staff)
121 self._TCTRL_name.SetValue('%s.%s %s' % (staff['title'], staff['firstnames'], staff['lastnames']))
122 self._TCTRL_alias.SetValue(staff['short_alias'])
123 self._TCTRL_account.SetValue(staff['db_user'])
124 self._PRW_user_role.SetText(value = staff['l10n_role'], data = staff['role'], suppress_smarts = True)
125 self._TCTRL_comment.SetValue(gmTools.coalesce(staff['comment'], ''))
126
128 self._btn_save.Enable(False)
129 self._btn_delete.Enable(False)
130 self._btn_deactivate.Enable(False)
131 self._btn_activate.Enable(False)
132
133 self._TCTRL_name.SetValue('')
134 self._TCTRL_alias.SetValue('')
135 self._TCTRL_account.SetValue('')
136 self._PRW_user_role.SetText(value = u'', data = None)
137 self._TCTRL_comment.SetValue('')
138
148
158
171
203
204 from Gnumed.wxGladeWidgets import wxgAddPatientAsStaffDlg
205
207
211
212
213
224
225
226
229
279
280
281