1
2 """GNUmed GUI client.
3
4 This contains the GUI application framework and main window
5 of the all signing all dancing GNUmed Python Reference
6 client. It relies on the <gnumed.py> launcher having set up
7 the non-GUI-related runtime environment.
8
9 This source code is protected by the GPL licensing scheme.
10 Details regarding the GPL are available at http://www.gnu.org
11 You may use and share it as long as you don't deny this right
12 to anybody else.
13
14 copyright: authors
15 """
16
17
18
19 __version__ = "$Revision: 1.487 $"
20 __author__ = "H. Herb <hherb@gnumed.net>,\
21 K. Hilbert <Karsten.Hilbert@gmx.net>,\
22 I. Haywood <i.haywood@ugrad.unimelb.edu.au>"
23 __license__ = 'GPL (details at http://www.gnu.org)'
24
25
26 import sys, time, os, cPickle, zlib, locale, os.path, datetime as pyDT, webbrowser, shutil, logging, urllib2
27
28
29
30
31 if not hasattr(sys, 'frozen'):
32 import wxversion
33 wxversion.ensureMinimal('2.8-unicode', optionsRequired=True)
34
35 try:
36 import wx
37 import wx.lib.pubsub
38 except ImportError:
39 print "GNUmed startup: Cannot import wxPython library."
40 print "GNUmed startup: Make sure wxPython is installed."
41 print 'CRITICAL ERROR: Error importing wxPython. Halted.'
42 raise
43
44
45
46 version = int(u'%s%s' % (wx.MAJOR_VERSION, wx.MINOR_VERSION))
47 if (version < 28) or ('unicode' not in wx.PlatformInfo):
48 print "GNUmed startup: Unsupported wxPython version (%s: %s)." % (wx.VERSION_STRING, wx.PlatformInfo)
49 print "GNUmed startup: wxPython 2.8+ with unicode support is required."
50 print 'CRITICAL ERROR: Proper wxPython version not found. Halted.'
51 raise ValueError('wxPython 2.8+ with unicode support not found')
52
53
54
55 from Gnumed.pycommon import gmCfg, gmPG2, gmDispatcher, gmGuiBroker, gmI18N
56 from Gnumed.pycommon import gmExceptions, gmShellAPI, gmTools, gmDateTime
57 from Gnumed.pycommon import gmHooks, gmBackendListener, gmCfg2, gmLog2
58
59 from Gnumed.business import gmPerson, gmClinicalRecord, gmSurgery, gmEMRStructItems
60
61 from Gnumed.exporters import gmPatientExporter
62
63 from Gnumed.wxpython import gmGuiHelpers, gmHorstSpace, gmEMRBrowser, gmDemographicsWidgets, gmEMRStructWidgets
64 from Gnumed.wxpython import gmStaffWidgets, gmMedDocWidgets, gmPatSearchWidgets, gmAllergyWidgets, gmListWidgets
65 from Gnumed.wxpython import gmFormWidgets, gmSnellen, gmProviderInboxWidgets, gmCfgWidgets, gmExceptionHandlingWidgets
66 from Gnumed.wxpython import gmTimer, gmMeasurementWidgets, gmNarrativeWidgets, gmPhraseWheel, gmMedicationWidgets
67
68 try:
69 _('dummy-no-need-to-translate-but-make-epydoc-happy')
70 except NameError:
71 _ = lambda x:x
72
73 _cfg = gmCfg2.gmCfgData()
74 _provider = None
75 _scripting_listener = None
76
77 _log = logging.getLogger('gm.main')
78 _log.info(__version__)
79 _log.info('wxPython GUI framework: %s %s' % (wx.VERSION_STRING, wx.PlatformInfo))
80
81
82 icon_serpent = \
83 """x\xdae\x8f\xb1\x0e\x83 \x10\x86w\x9f\xe2\x92\x1blb\xf2\x07\x96\xeaH:0\xd6\
84 \xc1\x85\xd5\x98N5\xa5\xef?\xf5N\xd0\x8a\xdcA\xc2\xf7qw\x84\xdb\xfa\xb5\xcd\
85 \xd4\xda;\xc9\x1a\xc8\xb6\xcd<\xb5\xa0\x85\x1e\xeb\xbc\xbc7b!\xf6\xdeHl\x1c\
86 \x94\x073\xec<*\xf7\xbe\xf7\x99\x9d\xb21~\xe7.\xf5\x1f\x1c\xd3\xbdVlL\xc2\
87 \xcf\xf8ye\xd0\x00\x90\x0etH \x84\x80B\xaa\x8a\x88\x85\xc4(U\x9d$\xfeR;\xc5J\
88 \xa6\x01\xbbt9\xceR\xc8\x81e_$\x98\xb9\x9c\xa9\x8d,y\xa9t\xc8\xcf\x152\xe0x\
89 \xe9$\xf5\x07\x95\x0cD\x95t:\xb1\x92\xae\x9cI\xa8~\x84\x1f\xe0\xa3ec"""
90
92 """GNUmed client's main windows frame.
93
94 This is where it all happens. Avoid popping up any other windows.
95 Most user interaction should happen to and from widgets within this frame
96 """
97
98 - def __init__(self, parent, id, title, size=wx.DefaultSize):
99 """You'll have to browse the source to understand what the constructor does
100 """
101 wx.Frame.__init__(self, parent, id, title, size, style = wx.DEFAULT_FRAME_STYLE)
102
103 self.__gb = gmGuiBroker.GuiBroker()
104 self.__pre_exit_callbacks = []
105 self.bar_width = -1
106 self.menu_id2plugin = {}
107
108 _log.info('workplace is >>>%s<<<', gmSurgery.gmCurrentPractice().active_workplace)
109
110 self.__setup_main_menu()
111 self.setup_statusbar()
112 self.SetStatusText(_('You are logged in as %s%s.%s (%s). DB account <%s>.') % (
113 gmTools.coalesce(_provider['title'], ''),
114 _provider['firstnames'][:1],
115 _provider['lastnames'],
116 _provider['short_alias'],
117 _provider['db_user']
118 ))
119
120 self.__set_window_title_template()
121 self.__update_window_title()
122 self.__set_window_icon()
123
124 self.__register_events()
125
126 self.LayoutMgr = gmHorstSpace.cHorstSpaceLayoutMgr(self, -1)
127 self.vbox = wx.BoxSizer(wx.VERTICAL)
128 self.vbox.Add(self.LayoutMgr, 10, wx.EXPAND | wx.ALL, 1)
129
130 self.SetAutoLayout(True)
131 self.SetSizerAndFit(self.vbox)
132
133
134
135
136
137 self.__set_GUI_size()
138
140
141 icon_bmp_data = wx.BitmapFromXPMData(cPickle.loads(zlib.decompress(icon_serpent)))
142 icon = wx.EmptyIcon()
143 icon.CopyFromBitmap(icon_bmp_data)
144 self.SetIcon(icon)
145
147 """Try to get previous window size from backend."""
148
149 cfg = gmCfg.cCfgSQL()
150
151
152 width = int(cfg.get2 (
153 option = 'main.window.width',
154 workplace = gmSurgery.gmCurrentPractice().active_workplace,
155 bias = 'workplace',
156 default = 800
157 ))
158
159
160 height = int(cfg.get2 (
161 option = 'main.window.height',
162 workplace = gmSurgery.gmCurrentPractice().active_workplace,
163 bias = 'workplace',
164 default = 600
165 ))
166
167 _log.debug('setting GUI size to [%s:%s]' % (width, height))
168 self.SetClientSize(wx.Size(width, height))
169
171 """Create the main menu entries.
172
173 Individual entries are farmed out to the modules.
174 """
175 global wx
176 self.mainmenu = wx.MenuBar()
177 self.__gb['main.mainmenu'] = self.mainmenu
178
179
180 menu_gnumed = wx.Menu()
181
182 self.menu_plugins = wx.Menu()
183 menu_gnumed.AppendMenu(wx.NewId(), _('&Go to plugin ...'), self.menu_plugins)
184
185 ID = wx.NewId()
186 menu_gnumed.Append(ID, _('Check for updates'), _('Check for new releases of the GNUmed client.'))
187 wx.EVT_MENU(self, ID, self.__on_check_for_updates)
188
189 item = menu_gnumed.Append(-1, _('Announce downtime'), _('Announce database maintenance downtime to all connected clients.'))
190 self.Bind(wx.EVT_MENU, self.__on_announce_maintenance, item)
191
192
193 menu_gnumed.AppendSeparator()
194
195
196 menu_config = wx.Menu()
197 menu_gnumed.AppendMenu(wx.NewId(), _('Preferences ...'), menu_config)
198
199
200 menu_cfg_db = wx.Menu()
201 menu_config.AppendMenu(wx.NewId(), _('Database ...'), menu_cfg_db)
202
203 ID = wx.NewId()
204 menu_cfg_db.Append(ID, _('Language'), _('Configure the database language'))
205 wx.EVT_MENU(self, ID, self.__on_configure_db_lang)
206
207 ID = wx.NewId()
208 menu_cfg_db.Append(ID, _('Welcome message'), _('Configure the database welcome message (all users).'))
209 wx.EVT_MENU(self, ID, self.__on_configure_db_welcome)
210
211
212 menu_cfg_client = wx.Menu()
213 menu_config.AppendMenu(wx.NewId(), _('Client parameters ...'), menu_cfg_client)
214
215 ID = wx.NewId()
216 menu_cfg_client.Append(ID, _('Export chunk size'), _('Configure the chunk size used when exporting BLOBs from the database.'))
217 wx.EVT_MENU(self, ID, self.__on_configure_export_chunk_size)
218
219 ID = wx.NewId()
220 menu_cfg_client.Append(ID, _('Temporary directory'), _('Configure the directory to use as scratch space for temporary files.'))
221 wx.EVT_MENU(self, ID, self.__on_configure_temp_dir)
222
223 item = menu_cfg_client.Append(-1, _('Email address'), _('The email address of the user for sending bug reports, etc.'))
224 self.Bind(wx.EVT_MENU, self.__on_configure_user_email, item)
225
226
227 menu_cfg_ui = wx.Menu()
228 menu_config.AppendMenu(wx.NewId(), _('User interface ...'), menu_cfg_ui)
229
230
231 menu_cfg_doc = wx.Menu()
232 menu_cfg_ui.AppendMenu(wx.NewId(), _('Document handling ...'), menu_cfg_doc)
233
234 ID = wx.NewId()
235 menu_cfg_doc.Append(ID, _('Review dialog'), _('Configure review dialog after document display.'))
236 wx.EVT_MENU(self, ID, self.__on_configure_doc_review_dialog)
237
238 ID = wx.NewId()
239 menu_cfg_doc.Append(ID, _('UUID display'), _('Configure unique ID dialog on document import.'))
240 wx.EVT_MENU(self, ID, self.__on_configure_doc_uuid_dialog)
241
242 ID = wx.NewId()
243 menu_cfg_doc.Append(ID, _('Empty documents'), _('Whether to allow saving documents without parts.'))
244 wx.EVT_MENU(self, ID, self.__on_configure_partless_docs)
245
246
247 menu_cfg_update = wx.Menu()
248 menu_cfg_ui.AppendMenu(wx.NewId(), _('Update handling ...'), menu_cfg_update)
249
250 ID = wx.NewId()
251 menu_cfg_update.Append(ID, _('Auto-check'), _('Whether to auto-check for updates at startup.'))
252 wx.EVT_MENU(self, ID, self.__on_configure_update_check)
253
254 ID = wx.NewId()
255 menu_cfg_update.Append(ID, _('Check scope'), _('When checking for updates, consider latest branch, too ?'))
256 wx.EVT_MENU(self, ID, self.__on_configure_update_check_scope)
257
258 ID = wx.NewId()
259 menu_cfg_update.Append(ID, _('URL'), _('The URL to retrieve version information from.'))
260 wx.EVT_MENU(self, ID, self.__on_configure_update_url)
261
262
263 menu_cfg_pat_search = wx.Menu()
264 menu_cfg_ui.AppendMenu(wx.NewId(), _('Patient search ...'), menu_cfg_pat_search)
265
266 ID = wx.NewId()
267 menu_cfg_pat_search.Append(ID, _('Birthday reminder'), _('Configure birthday reminder proximity interval.'))
268 wx.EVT_MENU(self, ID, self.__on_configure_dob_reminder_proximity)
269
270 ID = wx.NewId()
271 menu_cfg_pat_search.Append(ID, _('Immediate source activation'), _('Configure immediate activation of single external patient.'))
272 wx.EVT_MENU(self, ID, self.__on_configure_quick_pat_search)
273
274 ID = wx.NewId()
275 menu_cfg_pat_search.Append(ID, _('Initial plugin'), _('Configure which plugin to show right after patient activation.'))
276 wx.EVT_MENU(self, ID, self.__on_configure_initial_pat_plugin)
277
278
279 menu_cfg_soap_editing = wx.Menu()
280 menu_cfg_ui.AppendMenu(wx.NewId(), _('Progress notes handling ...'), menu_cfg_soap_editing)
281
282 ID = wx.NewId()
283 menu_cfg_soap_editing.Append(ID, _('Multiple new episodes'), _('Configure opening multiple new episodes on a patient at once.'))
284 wx.EVT_MENU(self, ID, self.__on_allow_multiple_new_episodes)
285
286
287 menu_cfg_ext_tools = wx.Menu()
288 menu_config.AppendMenu(wx.NewId(), _('External tools ...'), menu_cfg_ext_tools)
289
290 ID = wx.NewId()
291 menu_cfg_ext_tools.Append(ID, _('IFAP command'), _('Set the command to start IFAP.'))
292 wx.EVT_MENU(self, ID, self.__on_configure_ifap_cmd)
293
294 item = menu_cfg_ext_tools.Append(-1, _('MI/stroke risk calc cmd'), _('Set the command to start the CV risk calculator.'))
295 self.Bind(wx.EVT_MENU, self.__on_configure_acs_risk_calculator_cmd, item)
296
297 ID = wx.NewId()
298 menu_cfg_ext_tools.Append(ID, _('OOo startup time'), _('Set the time to wait for OpenOffice to settle after startup.'))
299 wx.EVT_MENU(self, ID, self.__on_configure_ooo_settle_time)
300
301 item = menu_cfg_ext_tools.Append(-1, _('Measurements URL'), _('URL for measurements encyclopedia.'))
302 self.Bind(wx.EVT_MENU, self.__on_configure_measurements_url, item)
303
304 item = menu_cfg_ext_tools.Append(-1, _('Drug data source'), _('Select the drug data source.'))
305 self.Bind(wx.EVT_MENU, self.__on_configure_drug_data_source, item)
306
307
308 menu_cfg_emr = wx.Menu()
309 menu_config.AppendMenu(wx.NewId(), _('EMR ...'), menu_cfg_emr)
310
311 item = menu_cfg_emr.Append(-1, _('Medication list template'), _('Select the template for printing a medication list.'))
312 self.Bind(wx.EVT_MENU, self.__on_cfg_medication_list_template, item)
313
314
315 menu_cfg_encounter = wx.Menu()
316 menu_cfg_emr.AppendMenu(wx.NewId(), _('Encounter ...'), menu_cfg_encounter)
317
318 ID = wx.NewId()
319 menu_cfg_encounter.Append(ID, _('Edit on patient change'), _('Edit encounter details on changing of patients.'))
320 wx.EVT_MENU(self, ID, self.__on_cfg_enc_pat_change)
321
322 ID = wx.NewId()
323 menu_cfg_encounter.Append(ID, _('Minimum duration'), _('Minimum duration of an encounter.'))
324 wx.EVT_MENU(self, ID, self.__on_cfg_enc_min_ttl)
325
326 ID = wx.NewId()
327 menu_cfg_encounter.Append(ID, _('Maximum duration'), _('Maximum duration of an encounter.'))
328 wx.EVT_MENU(self, ID, self.__on_cfg_enc_max_ttl)
329
330 ID = wx.NewId()
331 menu_cfg_encounter.Append(ID, _('Minimum empty age'), _('Minimum age of an empty encounter before considering for deletion.'))
332 wx.EVT_MENU(self, ID, self.__on_cfg_enc_empty_ttl)
333
334 ID = wx.NewId()
335 menu_cfg_encounter.Append(ID, _('Default type'), _('Default type for new encounters.'))
336 wx.EVT_MENU(self, ID, self.__on_cfg_enc_default_type)
337
338
339 menu_cfg_episode = wx.Menu()
340 menu_cfg_emr.AppendMenu(wx.NewId(), _('Episode ...'), menu_cfg_episode)
341
342 ID = wx.NewId()
343 menu_cfg_episode.Append(ID, _('Dormancy'), _('Maximum length of dormancy after which an episode will be considered closed.'))
344 wx.EVT_MENU(self, ID, self.__on_cfg_epi_ttl)
345
346
347 menu_master_data = wx.Menu()
348 menu_gnumed.AppendMenu(wx.NewId(), _('&Master data ...'), menu_master_data)
349
350 item = menu_master_data.Append(-1, _('Workplace profiles'), _('Manage the plugins to load per workplace.'))
351 self.Bind(wx.EVT_MENU, self.__on_configure_workplace, item)
352
353 item = menu_master_data.Append(-1, _('&Document types'), _('Manage the document types available in the system.'))
354 self.Bind(wx.EVT_MENU, self.__on_edit_doc_types, item)
355
356 item = menu_master_data.Append(-1, _('&Text expansions'), _('Manage keyword based text expansion macros.'))
357 self.Bind(wx.EVT_MENU, self.__on_manage_text_expansion, item)
358
359 item = menu_master_data.Append(-1, _('&Form templates'), _('Manage templates for forms and letters.'))
360 self.Bind(wx.EVT_MENU, self.__on_manage_form_templates, item)
361
362 item = menu_master_data.Append(-1, _('&Encounter types'), _('Manage encounter types.'))
363 self.Bind(wx.EVT_MENU, self.__on_manage_encounter_types, item)
364
365 item = menu_master_data.Append(-1, _('&Provinces'), _('Manage provinces (counties, territories, ...).'))
366 self.Bind(wx.EVT_MENU, self.__on_manage_provinces, item)
367
368 item = menu_master_data.Append(-1, _('Substances'), _('Manage substances in use.'))
369 self.Bind(wx.EVT_MENU, self.__on_manage_substances, item)
370
371 item = menu_master_data.Append(-1, _('Drugs'), _('Manage branded drugs.'))
372 self.Bind(wx.EVT_MENU, self.__on_manage_branded_drugs, item)
373
374 item = menu_master_data.Append(-1, _('Drug components'), _('View components of branded drugs.'))
375 self.Bind(wx.EVT_MENU, self.__on_manage_substances_in_brands, item)
376
377 item = menu_master_data.Append(-1, _('&Test types'), _('Show test/measurement types.'))
378 self.Bind(wx.EVT_MENU, self.__on_manage_test_types, item)
379
380 item = menu_master_data.Append(-1, _('&Meta test types'), _('Show meta test/measurement types.'))
381 self.Bind(wx.EVT_MENU, self.__on_manage_meta_test_types, item)
382
383 item = menu_master_data.Append(-1, _('Update LOINC'), _('Download and install LOINC reference data.'))
384 self.Bind(wx.EVT_MENU, self.__on_update_loinc, item)
385
386 item = menu_master_data.Append(-1, _('Update ATC'), _('Install ATC reference data.'))
387 self.Bind(wx.EVT_MENU, self.__on_update_atc, item)
388
389
390 menu_users = wx.Menu()
391 menu_gnumed.AppendMenu(wx.NewId(), _('&Users ...'), menu_users)
392
393 item = menu_users.Append(-1, _('&Add user'), _('Add a new GNUmed user'))
394 self.Bind(wx.EVT_MENU, self.__on_add_new_staff, item)
395
396 item = menu_users.Append(-1, _('&Edit users'), _('Edit the list of GNUmed users'))
397 self.Bind(wx.EVT_MENU, self.__on_edit_staff_list, item)
398
399
400 menu_gnumed.AppendSeparator()
401
402 item = menu_gnumed.Append(wx.ID_EXIT, _('E&xit\tAlt-X'), _('Close this GNUmed client.'))
403 self.Bind(wx.EVT_MENU, self.__on_exit_gnumed, item)
404
405 self.mainmenu.Append(menu_gnumed, '&GNUmed')
406
407
408 menu_patient = wx.Menu()
409
410 ID_CREATE_PATIENT = wx.NewId()
411 menu_patient.Append(ID_CREATE_PATIENT, _('Register person'), _("Register a new person with GNUmed"))
412 wx.EVT_MENU(self, ID_CREATE_PATIENT, self.__on_create_new_patient)
413
414
415
416
417 ID_LOAD_EXT_PAT = wx.NewId()
418 menu_patient.Append(ID_LOAD_EXT_PAT, _('Load external'), _('Load and possibly create person from an external source.'))
419 wx.EVT_MENU(self, ID_LOAD_EXT_PAT, self.__on_load_external_patient)
420
421 ID_DEL_PAT = wx.NewId()
422 menu_patient.Append(ID_DEL_PAT, _('Deactivate record'), _('Deactivate (exclude from search) person record in database.'))
423 wx.EVT_MENU(self, ID_DEL_PAT, self.__on_delete_patient)
424
425 item = menu_patient.Append(-1, _('&Merge persons'), _('Merge two persons into one.'))
426 self.Bind(wx.EVT_MENU, self.__on_merge_patients, item)
427
428 menu_patient.AppendSeparator()
429
430 ID_ENLIST_PATIENT_AS_STAFF = wx.NewId()
431 menu_patient.Append(ID_ENLIST_PATIENT_AS_STAFF, _('Enlist as user'), _('Enlist current person as GNUmed user'))
432 wx.EVT_MENU(self, ID_ENLIST_PATIENT_AS_STAFF, self.__on_enlist_patient_as_staff)
433
434
435 ID = wx.NewId()
436 menu_patient.Append(ID, _('Export to GDT'), _('Export demographics of currently active person into GDT file.'))
437 wx.EVT_MENU(self, ID, self.__on_export_as_gdt)
438
439 menu_patient.AppendSeparator()
440
441 self.mainmenu.Append(menu_patient, '&Person')
442 self.__gb['main.patientmenu'] = menu_patient
443
444
445 menu_emr = wx.Menu()
446 self.mainmenu.Append(menu_emr, _("&EMR"))
447 self.__gb['main.emrmenu'] = menu_emr
448
449
450 menu_emr_show = wx.Menu()
451 menu_emr.AppendMenu(wx.NewId(), _('Show as ...'), menu_emr_show)
452 self.__gb['main.emr_showmenu'] = menu_emr_show
453
454
455 item = menu_emr_show.Append(-1, _('Summary'), _('Show a high-level summary of the EMR.'))
456 self.Bind(wx.EVT_MENU, self.__on_show_emr_summary, item)
457
458
459 item = menu_emr.Append(-1, _('Search this EMR'), _('Search for data in the EMR of the active patient'))
460 self.Bind(wx.EVT_MENU, self.__on_search_emr, item)
461
462 item = menu_emr.Append(-1, _('Search all EMRs'), _('Search for data across the EMRs of all patients'))
463 self.Bind(wx.EVT_MENU, self.__on_search_across_emrs, item)
464
465
466 menu_emr_edit = wx.Menu()
467 menu_emr.AppendMenu(wx.NewId(), _('&Add / Edit ...'), menu_emr_edit)
468
469 item = menu_emr_edit.Append(-1, _('&Past history (health issue / PMH)'), _('Add a past/previous medical history item (health issue) to the EMR of the active patient'))
470 self.Bind(wx.EVT_MENU, self.__on_add_health_issue, item)
471
472
473
474
475 item = menu_emr_edit.Append(-1, _('&Allergies'), _('Manage documentation of allergies for the current patient.'))
476 self.Bind(wx.EVT_MENU, self.__on_manage_allergies, item)
477
478 item = menu_emr_edit.Append(-1, _('&Occupation'), _('Edit occupation details for the current patient.'))
479 self.Bind(wx.EVT_MENU, self.__on_edit_occupation, item)
480
481 item = menu_emr_edit.Append(-1, _('&Hospital stays'), _('Manage hospital stays.'))
482 self.Bind(wx.EVT_MENU, self.__on_manage_hospital_stays, item)
483
484 item = menu_emr_edit.Append(-1, _('&Procedures'), _('Manage procedures performed on the patient.'))
485 self.Bind(wx.EVT_MENU, self.__on_manage_performed_procedures, item)
486
487 item = menu_emr_edit.Append(-1, _('&Measurement(s)'), _('Add (a) measurement result(s) for the current patient.'))
488 self.Bind(wx.EVT_MENU, self.__on_add_measurement, item)
489
490
491
492
493
494
495
496 item = menu_emr.Append(-1, _('Start new encounter'), _('Start a new encounter for the active patient right now.'))
497 self.Bind(wx.EVT_MENU, self.__on_start_new_encounter, item)
498
499
500 item = menu_emr.Append(-1, _('View encounter list'), _('List all encounters including empty ones.'))
501 self.Bind(wx.EVT_MENU, self.__on_list_encounters, item)
502
503
504 menu_emr.AppendSeparator()
505
506 menu_emr_export = wx.Menu()
507 menu_emr.AppendMenu(wx.NewId(), _('Export as ...'), menu_emr_export)
508
509 ID_EXPORT_EMR_ASCII = wx.NewId()
510 menu_emr_export.Append (
511 ID_EXPORT_EMR_ASCII,
512 _('Text document'),
513 _("Export the EMR of the active patient into a text file")
514 )
515 wx.EVT_MENU(self, ID_EXPORT_EMR_ASCII, self.OnExportEMR)
516
517 ID_EXPORT_EMR_JOURNAL = wx.NewId()
518 menu_emr_export.Append (
519 ID_EXPORT_EMR_JOURNAL,
520 _('Journal'),
521 _("Export the EMR of the active patient as a chronological journal into a text file")
522 )
523 wx.EVT_MENU(self, ID_EXPORT_EMR_JOURNAL, self.__on_export_emr_as_journal)
524
525 ID_EXPORT_MEDISTAR = wx.NewId()
526 menu_emr_export.Append (
527 ID_EXPORT_MEDISTAR,
528 _('MEDISTAR import format'),
529 _("GNUmed -> MEDISTAR. Export progress notes of active patient's active encounter into a text file.")
530 )
531 wx.EVT_MENU(self, ID_EXPORT_MEDISTAR, self.__on_export_for_medistar)
532
533
534 menu_emr.AppendSeparator()
535
536
537 menu_paperwork = wx.Menu()
538
539 item = menu_paperwork.Append(-1, _('&Write letter'), _('Write a letter for the current patient.'))
540 self.Bind(wx.EVT_MENU, self.__on_new_letter, item)
541
542 self.mainmenu.Append(menu_paperwork, _('&Correspondence'))
543
544
545 self.menu_tools = wx.Menu()
546 self.__gb['main.toolsmenu'] = self.menu_tools
547 self.mainmenu.Append(self.menu_tools, _("&Tools"))
548
549 ID_DICOM_VIEWER = wx.NewId()
550 viewer = _('no viewer installed')
551 if os.access('/Applications/OsiriX.app/Contents/MacOS/OsiriX', os.X_OK):
552 viewer = u'OsiriX'
553 elif gmShellAPI.detect_external_binary(binary = 'aeskulap')[0]:
554 viewer = u'Aeskulap'
555 elif gmShellAPI.detect_external_binary(binary = 'amide')[0]:
556 viewer = u'AMIDE'
557 elif gmShellAPI.detect_external_binary(binary = 'xmedcon')[0]:
558 viewer = u'(x)medcon'
559 self.menu_tools.Append(ID_DICOM_VIEWER, _('DICOM viewer'), _('Start DICOM viewer (%s) for CD-ROM (X-Ray, CT, MR, etc). On Windows just insert CD.') % viewer)
560 wx.EVT_MENU(self, ID_DICOM_VIEWER, self.__on_dicom_viewer)
561 if viewer == _('no viewer installed'):
562 _log.info('neither of OsiriX / Aeskulap / AMIDE / xmedcon found, disabling "DICOM viewer" menu item')
563 self.menu_tools.Enable(id=ID_DICOM_VIEWER, enable=False)
564
565
566
567
568
569 ID = wx.NewId()
570 self.menu_tools.Append(ID, _('Snellen chart'), _('Display fullscreen snellen chart.'))
571 wx.EVT_MENU(self, ID, self.__on_snellen)
572
573 item = self.menu_tools.Append(-1, _('MI/stroke risk'), _('Acute coronary syndrome/stroke risk assessment.'))
574 self.Bind(wx.EVT_MENU, self.__on_acs_risk_assessment, item)
575
576 self.menu_tools.AppendSeparator()
577
578
579 menu_knowledge = wx.Menu()
580 self.__gb['main.knowledgemenu'] = menu_knowledge
581 self.mainmenu.Append(menu_knowledge, _('&Knowledge'))
582
583 menu_drug_dbs = wx.Menu()
584 menu_knowledge.AppendMenu(wx.NewId(), _('&Drug Resources'), menu_drug_dbs)
585
586 item = menu_drug_dbs.Append(-1, _('&Database'), _('Jump to the drug database configured as the default.'))
587 self.Bind(wx.EVT_MENU, self.__on_jump_to_drug_db, item)
588
589
590 ID_IFAP = wx.NewId()
591 menu_drug_dbs.Append(ID_IFAP, u'ifap', _('Start "ifap index PRAXIS" %s drug browser (Windows/Wine, Germany)') % gmTools.u_registered_trademark)
592 wx.EVT_MENU(self, ID_IFAP, self.__on_ifap)
593
594 menu_id = wx.NewId()
595 menu_drug_dbs.Append(menu_id, u'kompendium.ch', _('Show "kompendium.ch" drug database (online, Switzerland)'))
596 wx.EVT_MENU(self, menu_id, self.__on_kompendium_ch)
597
598
599
600
601 ID_MEDICAL_LINKS = wx.NewId()
602 menu_knowledge.Append(ID_MEDICAL_LINKS, _('Medical links (www)'), _('Show a page of links to useful medical content.'))
603 wx.EVT_MENU(self, ID_MEDICAL_LINKS, self.__on_medical_links)
604
605
606 self.menu_office = wx.Menu()
607
608 self.__gb['main.officemenu'] = self.menu_office
609 self.mainmenu.Append(self.menu_office, _('&Office'))
610
611
612 help_menu = wx.Menu()
613
614 ID = wx.NewId()
615 help_menu.Append(ID, _('GNUmed wiki'), _('Go to the GNUmed wiki on the web.'))
616 wx.EVT_MENU(self, ID, self.__on_display_wiki)
617
618 ID = wx.NewId()
619 help_menu.Append(ID, _('User manual (www)'), _('Go to the User Manual on the web.'))
620 wx.EVT_MENU(self, ID, self.__on_display_user_manual_online)
621
622 item = help_menu.Append(-1, _('Menu reference (www)'), _('View the reference for menu items on the web.'))
623 self.Bind(wx.EVT_MENU, self.__on_menu_reference, item)
624
625 menu_debugging = wx.Menu()
626 help_menu.AppendMenu(wx.NewId(), _('Debugging ...'), menu_debugging)
627
628 ID_SCREENSHOT = wx.NewId()
629 menu_debugging.Append(ID_SCREENSHOT, _('Screenshot'), _('Save a screenshot of this GNUmed client.'))
630 wx.EVT_MENU(self, ID_SCREENSHOT, self.__on_save_screenshot)
631
632 item = menu_debugging.Append(-1, _('Show log file'), _('Show the log file in text viewer.'))
633 self.Bind(wx.EVT_MENU, self.__on_show_log_file, item)
634
635 ID = wx.NewId()
636 menu_debugging.Append(ID, _('Backup log file'), _('Backup the content of the log to another file.'))
637 wx.EVT_MENU(self, ID, self.__on_backup_log_file)
638
639 ID = wx.NewId()
640 menu_debugging.Append(ID, _('Bug tracker'), _('Go to the GNUmed bug tracker on the web.'))
641 wx.EVT_MENU(self, ID, self.__on_display_bugtracker)
642
643 ID_UNBLOCK = wx.NewId()
644 menu_debugging.Append(ID_UNBLOCK, _('Unlock mouse'), _('Unlock mouse pointer in case it got stuck in hourglass mode.'))
645 wx.EVT_MENU(self, ID_UNBLOCK, self.__on_unblock_cursor)
646
647 item = menu_debugging.Append(-1, _('pgAdmin III'), _('pgAdmin III: Browse GNUmed database(s) in PostgreSQL server.'))
648 self.Bind(wx.EVT_MENU, self.__on_pgadmin3, item)
649
650
651
652
653 if _cfg.get(option = 'debug'):
654 ID_TOGGLE_PAT_LOCK = wx.NewId()
655 menu_debugging.Append(ID_TOGGLE_PAT_LOCK, _('Lock/unlock patient'), _('Lock/unlock patient - USE ONLY IF YOU KNOW WHAT YOU ARE DOING !'))
656 wx.EVT_MENU(self, ID_TOGGLE_PAT_LOCK, self.__on_toggle_patient_lock)
657
658 ID_TEST_EXCEPTION = wx.NewId()
659 menu_debugging.Append(ID_TEST_EXCEPTION, _('Test error handling'), _('Throw an exception to test error handling.'))
660 wx.EVT_MENU(self, ID_TEST_EXCEPTION, self.__on_test_exception)
661
662 ID = wx.NewId()
663 menu_debugging.Append(ID, _('Invoke inspector'), _('Invoke the widget hierarchy inspector (needs wxPython 2.8).'))
664 wx.EVT_MENU(self, ID, self.__on_invoke_inspector)
665 try:
666 import wx.lib.inspection
667 except ImportError:
668 menu_debugging.Enable(id = ID, enable = False)
669
670 help_menu.AppendSeparator()
671
672 help_menu.Append(wx.ID_ABOUT, _('About GNUmed'), "")
673 wx.EVT_MENU (self, wx.ID_ABOUT, self.OnAbout)
674
675 ID_CONTRIBUTORS = wx.NewId()
676 help_menu.Append(ID_CONTRIBUTORS, _('GNUmed contributors'), _('show GNUmed contributors'))
677 wx.EVT_MENU(self, ID_CONTRIBUTORS, self.__on_show_contributors)
678
679 item = help_menu.Append(-1, _('About database'), _('Show information about the current database.'))
680 self.Bind(wx.EVT_MENU, self.__on_about_database, item)
681
682 help_menu.AppendSeparator()
683
684
685 self.__gb['main.helpmenu'] = help_menu
686 self.mainmenu.Append(help_menu, _("&Help"))
687
688
689
690 self.SetMenuBar(self.mainmenu)
691
694
695
696
698 """register events we want to react to"""
699
700 wx.EVT_CLOSE(self, self.OnClose)
701 wx.EVT_QUERY_END_SESSION(self, self._on_query_end_session)
702 wx.EVT_END_SESSION(self, self._on_end_session)
703
704 gmDispatcher.connect(signal = u'post_patient_selection', receiver = self._on_post_patient_selection)
705 gmDispatcher.connect(signal = u'name_mod_db', receiver = self._on_pat_name_changed)
706 gmDispatcher.connect(signal = u'identity_mod_db', receiver = self._on_pat_name_changed)
707 gmDispatcher.connect(signal = u'statustext', receiver = self._on_set_statustext)
708 gmDispatcher.connect(signal = u'request_user_attention', receiver = self._on_request_user_attention)
709 gmDispatcher.connect(signal = u'db_maintenance_warning', receiver = self._on_db_maintenance_warning)
710 gmDispatcher.connect(signal = u'register_pre_exit_callback', receiver = self._register_pre_exit_callback)
711 gmDispatcher.connect(signal = u'plugin_loaded', receiver = self._on_plugin_loaded)
712
713 wx.lib.pubsub.Publisher().subscribe(listener = self._on_set_statustext_pubsub, topic = 'statustext')
714
715 gmPerson.gmCurrentPatient().register_pre_selection_callback(callback = self._pre_selection_callback)
716
717 - def _on_plugin_loaded(self, plugin_name=None, class_name=None, menu_name=None, menu_item_name=None, menu_help_string=None):
718
719 _log.debug('registering plugin with menu system')
720 _log.debug(' generic name: %s', plugin_name)
721 _log.debug(' class name: %s', class_name)
722 _log.debug(' specific menu: %s', menu_name)
723 _log.debug(' menu item: %s', menu_item_name)
724
725
726 item = self.menu_plugins.Append(-1, plugin_name, _('Raise plugin [%s].') % plugin_name)
727 self.Bind(wx.EVT_MENU, self.__on_raise_a_plugin, item)
728 self.menu_id2plugin[item.Id] = class_name
729
730
731 if menu_name is not None:
732 menu = self.__gb['main.%smenu' % menu_name]
733 item = menu.Append(-1, menu_item_name, menu_help_string)
734 self.Bind(wx.EVT_MENU, self.__on_raise_a_plugin, item)
735 self.menu_id2plugin[item.Id] = class_name
736
737 return True
738
740 gmDispatcher.send (
741 signal = u'display_widget',
742 name = self.menu_id2plugin[evt.Id]
743 )
744
746 wx.Bell()
747 wx.Bell()
748 wx.Bell()
749 _log.warning('unhandled event detected: QUERY_END_SESSION')
750 _log.info('we should be saving ourselves from here')
751 gmLog2.flush()
752 print "unhandled event detected: QUERY_END_SESSION"
753
755 wx.Bell()
756 wx.Bell()
757 wx.Bell()
758 _log.warning('unhandled event detected: END_SESSION')
759 gmLog2.flush()
760 print "unhandled event detected: END_SESSION"
761
763 if not callable(callback):
764 raise TypeError(u'callback [%s] not callable' % callback)
765
766 self.__pre_exit_callbacks.append(callback)
767
768 - def _on_set_statustext_pubsub(self, context=None):
769 wx.CallAfter(self.SetStatusText, context.data['msg'])
770 try:
771 if context.data['beep']:
772 wx.Bell()
773 except KeyError:
774 pass
775
776 - def _on_set_statustext(self, msg=None, loglevel=None, beep=True):
777
778 if msg is None:
779 msg = _('programmer forgot to specify status message')
780
781 if loglevel is not None:
782 _log.log(loglevel, msg.replace('\015', ' ').replace('\012', ' '))
783
784 wx.CallAfter(self.SetStatusText, msg)
785
786 if beep:
787 wx.Bell()
788
790 wx.CallAfter(self.__on_db_maintenance_warning)
791
793
794 self.SetStatusText(_('The database will be shut down for maintenance in a few minutes.'))
795 wx.Bell()
796 if not wx.GetApp().IsActive():
797 self.RequestUserAttention(flags = wx.USER_ATTENTION_ERROR)
798
799 gmHooks.run_hook_script(hook = u'db_maintenance_warning')
800
801 dlg = gmGuiHelpers.c2ButtonQuestionDlg (
802 None,
803 -1,
804 caption = _('Database shutdown warning'),
805 question = _(
806 'The database will be shut down for maintenance\n'
807 'in a few minutes.\n'
808 '\n'
809 'In order to not suffer any loss of data you\n'
810 'will need to save your current work and log\n'
811 'out of this GNUmed client.\n'
812 ),
813 button_defs = [
814 {
815 u'label': _('Close now'),
816 u'tooltip': _('Close this GNUmed client immediately.'),
817 u'default': False
818 },
819 {
820 u'label': _('Finish work'),
821 u'tooltip': _('Finish and save current work first, then manually close this GNUmed client.'),
822 u'default': True
823 }
824 ]
825 )
826 decision = dlg.ShowModal()
827 if decision == wx.ID_YES:
828 top_win = wx.GetApp().GetTopWindow()
829 wx.CallAfter(top_win.Close)
830
832 wx.CallAfter(self.__on_request_user_attention, msg, urgent)
833
835
836 if not wx.GetApp().IsActive():
837 if urgent:
838 self.RequestUserAttention(flags = wx.USER_ATTENTION_ERROR)
839 else:
840 self.RequestUserAttention(flags = wx.USER_ATTENTION_INFO)
841
842 if msg is not None:
843 self.SetStatusText(msg)
844
845 if urgent:
846 wx.Bell()
847
848 gmHooks.run_hook_script(hook = u'request_user_attention')
849
851 wx.CallAfter(self.__on_pat_name_changed)
852
854 self.__update_window_title()
855
857 wx.CallAfter(self.__on_post_patient_selection, **kwargs)
858
860 self.__update_window_title()
861 try:
862 gmHooks.run_hook_script(hook = u'post_patient_activation')
863 except:
864 gmDispatcher.send(signal = 'statustext', msg = _('Cannot run script after patient activation.'))
865 raise
866
868 return self.__sanity_check_encounter()
869
927
928
929
932
940
943
944
945
960
983
985 from Gnumed.wxpython import gmAbout
986 contribs = gmAbout.cContributorsDlg (
987 parent = self,
988 id = -1,
989 title = _('GNUmed contributors'),
990 size = wx.Size(400,600),
991 style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
992 )
993 contribs.ShowModal()
994 del contribs
995 del gmAbout
996
997
998
1000 """Invoked from Menu GNUmed / Exit (which calls this ID_EXIT handler)."""
1001 _log.debug('gmTopLevelFrame._on_exit_gnumed() start')
1002 self.Close(True)
1003 _log.debug('gmTopLevelFrame._on_exit_gnumed() end')
1004
1007
1009 send = gmGuiHelpers.gm_show_question (
1010 _('This will send a notification about database downtime\n'
1011 'to all GNUmed clients connected to your database.\n'
1012 '\n'
1013 'Do you want to send the notification ?\n'
1014 ),
1015 _('Announcing database maintenance downtime')
1016 )
1017 if not send:
1018 return
1019 gmPG2.send_maintenance_notification()
1020
1021
1022
1054
1067
1068 gmCfgWidgets.configure_string_option (
1069 message = _(
1070 'Some network installations cannot cope with loading\n'
1071 'documents of arbitrary size in one piece from the\n'
1072 'database (mainly observed on older Windows versions)\n.'
1073 '\n'
1074 'Under such circumstances documents need to be retrieved\n'
1075 'in chunks and reassembled on the client.\n'
1076 '\n'
1077 'Here you can set the size (in Bytes) above which\n'
1078 'GNUmed will retrieve documents in chunks. Setting this\n'
1079 'value to 0 will disable the chunking protocol.'
1080 ),
1081 option = 'horstspace.blob_export_chunk_size',
1082 bias = 'workplace',
1083 default_value = 1024 * 1024,
1084 validator = is_valid
1085 )
1086
1087
1088
1156
1160
1161
1162
1170
1171 gmCfgWidgets.configure_string_option (
1172 message = _(
1173 'When GNUmed cannot find an OpenOffice server it\n'
1174 'will try to start one. OpenOffice, however, needs\n'
1175 'some time to fully start up.\n'
1176 '\n'
1177 'Here you can set the time for GNUmed to wait for OOo.\n'
1178 ),
1179 option = 'external.ooo.startup_settle_time',
1180 bias = 'workplace',
1181 default_value = 2.0,
1182 validator = is_valid
1183 )
1184
1187
1199
1200 gmCfgWidgets.configure_string_option (
1201 message = _(
1202 'GNUmed will use this URL to access an encyclopedia of\n'
1203 'measurement/lab methods from within the measurments grid.\n'
1204 '\n'
1205 'You can leave this empty but to set it to a specific\n'
1206 'address the URL must be accessible now.'
1207 ),
1208 option = 'external.urls.measurements_encyclopedia',
1209 bias = 'user',
1210 default_value = u'http://www.laborlexikon.de',
1211 validator = is_valid
1212 )
1213
1226
1227 gmCfgWidgets.configure_string_option (
1228 message = _(
1229 'Enter the shell command with which to start the\n'
1230 'the ACS risk assessment calculator.\n'
1231 '\n'
1232 'GNUmed will try to verify the path which may,\n'
1233 'however, fail if you are using an emulator such\n'
1234 'as Wine. Nevertheless, starting the calculator\n'
1235 'will work as long as the shell command is correct\n'
1236 'despite the failing test.'
1237 ),
1238 option = 'external.tools.acs_risk_calculator_cmd',
1239 bias = 'user',
1240 validator = is_valid
1241 )
1242
1255
1256 gmCfgWidgets.configure_string_option (
1257 message = _(
1258 'Enter the shell command with which to start the\n'
1259 'the IFAP drug database.\n'
1260 '\n'
1261 'GNUmed will try to verify the path which may,\n'
1262 'however, fail if you are using an emulator such\n'
1263 'as Wine. Nevertheless, starting IFAP will work\n'
1264 'as long as the shell command is correct despite\n'
1265 'the failing test.'
1266 ),
1267 option = 'external.ifap-win.shell_command',
1268 bias = 'workplace',
1269 default_value = 'C:\Ifapwin\WIAMDB.EXE',
1270 validator = is_valid
1271 )
1272
1273
1274
1323
1324
1325
1342
1347
1348 gmCfgWidgets.configure_string_option (
1349 message = _(
1350 'When a patient is activated GNUmed checks the\n'
1351 "proximity of the patient's birthday.\n"
1352 '\n'
1353 'If the birthday falls within the range of\n'
1354 ' "today %s <the interval you set here>"\n'
1355 'GNUmed will remind you of the recent or\n'
1356 'imminent anniversary.'
1357 ) % u'\u2213',
1358 option = u'patient_search.dob_warn_interval',
1359 bias = 'user',
1360 default_value = '1 week',
1361 validator = is_valid
1362 )
1363
1365
1366 gmCfgWidgets.configure_boolean_option (
1367 parent = self,
1368 question = _(
1369 'When adding progress notes do you want to\n'
1370 'allow opening several unassociated, new\n'
1371 'episodes for a patient at once ?\n'
1372 '\n'
1373 'This can be particularly helpful when entering\n'
1374 'progress notes on entirely new patients presenting\n'
1375 'with a multitude of problems on their first visit.'
1376 ),
1377 option = u'horstspace.soap_editor.allow_same_episode_multiple_times',
1378 button_tooltips = [
1379 _('Yes, allow for multiple new episodes concurrently.'),
1380 _('No, only allow editing one new episode at a time.')
1381 ]
1382 )
1383
1429
1430
1431
1434
1448
1450 gmCfgWidgets.configure_boolean_option (
1451 parent = self,
1452 question = _(
1453 'Do you want GNUmed to show the encounter\n'
1454 'details editor when changing the active patient ?'
1455 ),
1456 option = 'encounter.show_editor_before_patient_change',
1457 button_tooltips = [
1458 _('Yes, show the encounter editor if it seems appropriate.'),
1459 _('No, never show the encounter editor even if it would seem useful.')
1460 ]
1461 )
1462
1467
1468 gmCfgWidgets.configure_string_option (
1469 message = _(
1470 'When a patient is activated GNUmed checks the\n'
1471 'chart for encounters lacking any entries.\n'
1472 '\n'
1473 'Any such encounters older than what you set\n'
1474 'here will be removed from the medical record.\n'
1475 '\n'
1476 'To effectively disable removal of such encounters\n'
1477 'set this option to an improbable value.\n'
1478 ),
1479 option = 'encounter.ttl_if_empty',
1480 bias = 'user',
1481 default_value = '1 week',
1482 validator = is_valid
1483 )
1484
1489
1490 gmCfgWidgets.configure_string_option (
1491 message = _(
1492 'When a patient is activated GNUmed checks the\n'
1493 'age of the most recent encounter.\n'
1494 '\n'
1495 'If that encounter is younger than this age\n'
1496 'the existing encounter will be continued.\n'
1497 '\n'
1498 '(If it is really old a new encounter is\n'
1499 ' started, or else GNUmed will ask you.)\n'
1500 ),
1501 option = 'encounter.minimum_ttl',
1502 bias = 'user',
1503 default_value = '1 hour 30 minutes',
1504 validator = is_valid
1505 )
1506
1511
1512 gmCfgWidgets.configure_string_option (
1513 message = _(
1514 'When a patient is activated GNUmed checks the\n'
1515 'age of the most recent encounter.\n'
1516 '\n'
1517 'If that encounter is older than this age\n'
1518 'GNUmed will always start a new encounter.\n'
1519 '\n'
1520 '(If it is very recent the existing encounter\n'
1521 ' is continued, or else GNUmed will ask you.)\n'
1522 ),
1523 option = 'encounter.maximum_ttl',
1524 bias = 'user',
1525 default_value = '6 hours',
1526 validator = is_valid
1527 )
1528
1537
1538 gmCfgWidgets.configure_string_option (
1539 message = _(
1540 'At any time there can only be one open (ongoing)\n'
1541 'episode for each health issue.\n'
1542 '\n'
1543 'When you try to open (add data to) an episode on a health\n'
1544 'issue GNUmed will check for an existing open episode on\n'
1545 'that issue. If there is any it will check the age of that\n'
1546 'episode. The episode is closed if it has been dormant (no\n'
1547 'data added, that is) for the period of time (in days) you\n'
1548 'set here.\n'
1549 '\n'
1550 "If the existing episode hasn't been dormant long enough\n"
1551 'GNUmed will consult you what to do.\n'
1552 '\n'
1553 'Enter maximum episode dormancy in DAYS:'
1554 ),
1555 option = 'episode.ttl',
1556 bias = 'user',
1557 default_value = 60,
1558 validator = is_valid
1559 )
1560
1591
1594
1609
1634
1646
1647 gmCfgWidgets.configure_string_option (
1648 message = _(
1649 'GNUmed can check for new releases being available. To do\n'
1650 'so it needs to load version information from an URL.\n'
1651 '\n'
1652 'The default URL is:\n'
1653 '\n'
1654 ' http://www.gnumed.de/downloads/gnumed-versions.txt\n'
1655 '\n'
1656 'but you can configure any other URL locally. Note\n'
1657 'that you must enter the location as a valid URL.\n'
1658 'Depending on the URL the client will need online\n'
1659 'access when checking for updates.'
1660 ),
1661 option = u'horstspace.update.url',
1662 bias = u'workplace',
1663 default_value = u'http://www.gnumed.de/downloads/gnumed-versions.txt',
1664 validator = is_valid
1665 )
1666
1684
1701
1712
1713 gmCfgWidgets.configure_string_option (
1714 message = _(
1715 'GNUmed can show the document review dialog after\n'
1716 'calling the appropriate viewer for that document.\n'
1717 '\n'
1718 'Select the conditions under which you want\n'
1719 'GNUmed to do so:\n'
1720 '\n'
1721 ' 0: never display the review dialog\n'
1722 ' 1: always display the dialog\n'
1723 ' 2: only if there is no previous review by me\n'
1724 '\n'
1725 'Note that if a viewer is configured to not block\n'
1726 'GNUmed during document display the review dialog\n'
1727 'will actually appear in parallel to the viewer.'
1728 ),
1729 option = u'horstspace.document_viewer.review_after_display',
1730 bias = u'user',
1731 default_value = 2,
1732 validator = is_valid
1733 )
1734
1748
1765
1767 dlg = gmSnellen.cSnellenCfgDlg()
1768 if dlg.ShowModal() != wx.ID_OK:
1769 return
1770
1771 frame = gmSnellen.cSnellenChart (
1772 width = dlg.vals[0],
1773 height = dlg.vals[1],
1774 alpha = dlg.vals[2],
1775 mirr = dlg.vals[3],
1776 parent = None
1777 )
1778 frame.CentreOnScreen(wx.BOTH)
1779
1780
1781 frame.Show(True)
1782
1783
1785 webbrowser.open (
1786 url = 'http://wiki.gnumed.de/bin/view/Gnumed/MedicalContentLinks#AnchorLocaleI%s' % gmI18N.system_locale_level['language'],
1787 new = False,
1788 autoraise = True
1789 )
1790
1793
1796
1798 webbrowser.open (
1799 url = 'http://www.kompendium.ch',
1800 new = False,
1801 autoraise = True
1802 )
1803
1804
1805
1807 wx.CallAfter(self.__save_screenshot)
1808 evt.Skip()
1809
1811
1812 time.sleep(0.5)
1813
1814 rect = self.GetRect()
1815
1816
1817 if sys.platform == 'linux2':
1818 client_x, client_y = self.ClientToScreen((0, 0))
1819 border_width = client_x - rect.x
1820 title_bar_height = client_y - rect.y
1821
1822 if self.GetMenuBar():
1823 title_bar_height /= 2
1824 rect.width += (border_width * 2)
1825 rect.height += title_bar_height + border_width
1826
1827 wdc = wx.ScreenDC()
1828 mdc = wx.MemoryDC()
1829 img = wx.EmptyBitmap(rect.width, rect.height)
1830 mdc.SelectObject(img)
1831 mdc.Blit (
1832 0, 0,
1833 rect.width, rect.height,
1834 wdc,
1835 rect.x, rect.y
1836 )
1837
1838
1839 fname = os.path.expanduser(os.path.join('~', 'gnumed', 'export', 'gnumed-screenshot-%s.png')) % pyDT.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
1840 img.SaveFile(fname, wx.BITMAP_TYPE_PNG)
1841 gmDispatcher.send(signal = 'statustext', msg = _('Saved screenshot to file [%s].') % fname)
1842
1844
1845 raise ValueError('raised ValueError to test exception handling')
1846
1848 import wx.lib.inspection
1849 wx.lib.inspection.InspectionTool().Show()
1850
1852 webbrowser.open (
1853 url = 'https://bugs.launchpad.net/gnumed/',
1854
1855 new = False,
1856 autoraise = True
1857 )
1858
1860 webbrowser.open (
1861 url = 'http://wiki.gnumed.de',
1862 new = False,
1863 autoraise = True
1864 )
1865
1867 webbrowser.open (
1868 url = 'http://wiki.gnumed.de/bin/view/Gnumed/GnumedManual#UserGuideInManual',
1869 new = False,
1870 autoraise = True
1871 )
1872
1874 webbrowser.open (
1875 url = 'http://wiki.gnumed.de/bin/view/Gnumed/MenuReference',
1876 new = False,
1877 autoraise = True
1878 )
1879
1886
1890
1893
1900
1905
1907 name = os.path.basename(gmLog2._logfile_name)
1908 name, ext = os.path.splitext(name)
1909 new_name = '%s_%s%s' % (name, pyDT.datetime.now().strftime('%Y-%m-%d_%H-%M-%S'), ext)
1910 new_path = os.path.expanduser(os.path.join('~', 'gnumed', 'logs'))
1911
1912 dlg = wx.FileDialog (
1913 parent = self,
1914 message = _("Save current log as..."),
1915 defaultDir = new_path,
1916 defaultFile = new_name,
1917 wildcard = "%s (*.log)|*.log" % _("log files"),
1918 style = wx.SAVE
1919 )
1920 choice = dlg.ShowModal()
1921 new_name = dlg.GetPath()
1922 dlg.Destroy()
1923 if choice != wx.ID_OK:
1924 return True
1925
1926 _log.warning('syncing log file for backup to [%s]', new_name)
1927 gmLog2.flush()
1928 shutil.copy2(gmLog2._logfile_name, new_name)
1929 gmDispatcher.send('statustext', msg = _('Log file backed up as [%s].') % new_name)
1930
1931
1932
1934 """This is the wx.EVT_CLOSE handler.
1935
1936 - framework still functional
1937 """
1938 _log.debug('gmTopLevelFrame.OnClose() start')
1939 self._clean_exit()
1940 self.Destroy()
1941 _log.debug('gmTopLevelFrame.OnClose() end')
1942 return True
1943
1949
1954
1962
1969
1976
1986
1994
2002
2010
2018
2026
2028 pat = gmPerson.gmCurrentPatient()
2029 if not pat.connected:
2030 gmDispatcher.send(signal = 'statustext', msg = _('Cannot show EMR summary. No active patient.'))
2031 return False
2032
2033 emr = pat.get_emr()
2034 dlg = wx.MessageDialog (
2035 parent = self,
2036 message = emr.format_statistics(),
2037 caption = _('EMR Summary'),
2038 style = wx.OK | wx.STAY_ON_TOP
2039 )
2040 dlg.ShowModal()
2041 dlg.Destroy()
2042 return True
2043
2046
2049
2051
2052 pat = gmPerson.gmCurrentPatient()
2053 if not pat.connected:
2054 gmDispatcher.send(signal = 'statustext', msg = _('Cannot export EMR journal. No active patient.'))
2055 return False
2056
2057 aWildcard = "%s (*.txt)|*.txt|%s (*)|*" % (_("text files"), _("all files"))
2058
2059 aDefDir = os.path.expanduser(os.path.join('~', 'gnumed', 'export', 'EMR', pat['dirname']))
2060 gmTools.mkdir(aDefDir)
2061
2062 fname = '%s-%s_%s.txt' % (_('emr-journal'), pat['lastnames'], pat['firstnames'])
2063 dlg = wx.FileDialog (
2064 parent = self,
2065 message = _("Save patient's EMR journal as..."),
2066 defaultDir = aDefDir,
2067 defaultFile = fname,
2068 wildcard = aWildcard,
2069 style = wx.SAVE
2070 )
2071 choice = dlg.ShowModal()
2072 fname = dlg.GetPath()
2073 dlg.Destroy()
2074 if choice != wx.ID_OK:
2075 return True
2076
2077 _log.debug('exporting EMR journal to [%s]' % fname)
2078
2079 exporter = gmPatientExporter.cEMRJournalExporter()
2080
2081 wx.BeginBusyCursor()
2082 try:
2083 fname = exporter.export_to_file(filename = fname)
2084 except:
2085 wx.EndBusyCursor()
2086 gmGuiHelpers.gm_show_error (
2087 _('Error exporting patient EMR as chronological journal.'),
2088 _('EMR journal export')
2089 )
2090 raise
2091 wx.EndBusyCursor()
2092
2093 gmDispatcher.send(signal = 'statustext', msg = _('Successfully exported EMR as chronological journal into file [%s].') % fname, beep=False)
2094
2095 return True
2096
2103
2113
2115 curr_pat = gmPerson.gmCurrentPatient()
2116 if not curr_pat.connected:
2117 gmDispatcher.send(signal = 'statustext', msg = _('Cannot export patient as GDT. No active patient.'))
2118 return False
2119
2120 enc = 'cp850'
2121 fname = os.path.expanduser(os.path.join('~', 'gnumed', 'export', 'xDT', 'current-patient.gdt'))
2122 curr_pat.export_as_gdt(filename = fname, encoding = enc)
2123 gmDispatcher.send(signal = 'statustext', msg = _('Exported demographics to GDT file [%s].') % fname)
2124
2127
2133
2141
2149
2152
2160
2164
2168
2171
2174
2177
2180
2183
2186
2189
2192
2195
2198
2200 """Cleanup helper.
2201
2202 - should ALWAYS be called when this program is
2203 to be terminated
2204 - ANY code that should be executed before a
2205 regular shutdown should go in here
2206 - framework still functional
2207 """
2208 _log.debug('gmTopLevelFrame._clean_exit() start')
2209
2210
2211 listener = gmBackendListener.gmBackendListener()
2212 try:
2213 listener.shutdown()
2214 except:
2215 _log.exception('cannot stop backend notifications listener thread')
2216
2217
2218 if _scripting_listener is not None:
2219 try:
2220 _scripting_listener.shutdown()
2221 except:
2222 _log.exception('cannot stop scripting listener thread')
2223
2224
2225 self.clock_update_timer.Stop()
2226 gmTimer.shutdown()
2227 gmPhraseWheel.shutdown()
2228
2229
2230 for call_back in self.__pre_exit_callbacks:
2231 try:
2232 call_back()
2233 except:
2234 print "*** pre-exit callback failed ***"
2235 print call_back
2236 _log.exception('callback [%s] failed', call_back)
2237
2238
2239 gmDispatcher.send(u'application_closing')
2240
2241
2242 gmDispatcher.disconnect(self._on_set_statustext, 'statustext')
2243
2244
2245 curr_width, curr_height = self.GetClientSizeTuple()
2246 _log.info('GUI size at shutdown: [%s:%s]' % (curr_width, curr_height))
2247 dbcfg = gmCfg.cCfgSQL()
2248 dbcfg.set (
2249 option = 'main.window.width',
2250 value = curr_width,
2251 workplace = gmSurgery.gmCurrentPractice().active_workplace
2252 )
2253 dbcfg.set (
2254 option = 'main.window.height',
2255 value = curr_height,
2256 workplace = gmSurgery.gmCurrentPractice().active_workplace
2257 )
2258
2259 if _cfg.get(option = 'debug'):
2260 print '---=== GNUmed shutdown ===---'
2261 print _('You have to manually close this window to finalize shutting down GNUmed.')
2262 print _('This is so that you can inspect the console output at your leisure.')
2263 print '---=== GNUmed shutdown ===---'
2264
2265
2266 gmExceptionHandlingWidgets.uninstall_wx_exception_handler()
2267
2268
2269 import threading
2270 _log.debug("%s active threads", threading.activeCount())
2271 for t in threading.enumerate():
2272 _log.debug('thread %s', t)
2273
2274 _log.debug('gmTopLevelFrame._clean_exit() end')
2275
2276
2277
2279
2280 if _cfg.get(option = 'slave'):
2281 self.__title_template = u'GMdS: %%(pat)s [%%(prov)s@%%(wp)s] (%s:%s)' % (
2282 _cfg.get(option = 'slave personality'),
2283 _cfg.get(option = 'xml-rpc port')
2284 )
2285 else:
2286 self.__title_template = u'GMd: %(pat)s [%(prov)s@%(wp)s]'
2287
2289 """Update title of main window based on template.
2290
2291 This gives nice tooltips on iconified GNUmed instances.
2292
2293 User research indicates that in the title bar people want
2294 the date of birth, not the age, so please stick to this
2295 convention.
2296 """
2297 args = {}
2298
2299 pat = gmPerson.gmCurrentPatient()
2300 if pat.connected:
2301
2302
2303
2304
2305
2306
2307 args['pat'] = u'%s %s %s (%s) #%d' % (
2308 gmTools.coalesce(pat['title'], u'', u'%.4s'),
2309
2310 pat['firstnames'],
2311 pat['lastnames'],
2312 pat.get_formatted_dob(format = '%x', encoding = gmI18N.get_encoding()),
2313 pat['pk_identity']
2314 )
2315 else:
2316 args['pat'] = _('no patient')
2317
2318 args['prov'] = u'%s%s.%s' % (
2319 gmTools.coalesce(_provider['title'], u'', u'%s '),
2320 _provider['firstnames'][:1],
2321 _provider['lastnames']
2322 )
2323
2324 args['wp'] = gmSurgery.gmCurrentPractice().active_workplace
2325
2326 self.SetTitle(self.__title_template % args)
2327
2328
2330 sb = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
2331 sb.SetStatusWidths([-1, 225])
2332
2333 self.clock_update_timer = wx.PyTimer(self._cb_update_clock)
2334 self._cb_update_clock()
2335
2336 self.clock_update_timer.Start(milliseconds = 1000)
2337
2339 """Displays date and local time in the second slot of the status bar"""
2340 t = time.localtime(time.time())
2341 st = time.strftime('%c', t).decode(gmI18N.get_encoding())
2342 self.SetStatusText(st,1)
2343
2345 """Lock GNUmed client against unauthorized access"""
2346
2347
2348
2349 return
2350
2352 """Unlock the main notebook widgets
2353 As long as we are not logged into the database backend,
2354 all pages but the 'login' page of the main notebook widget
2355 are locked; i.e. not accessible by the user
2356 """
2357
2358
2359
2360
2361
2362 return
2363
2365 wx.LayoutAlgorithm().LayoutWindow (self.LayoutMgr, self.nb)
2366
2368
2370
2371 self.__starting_up = True
2372
2373 gmExceptionHandlingWidgets.install_wx_exception_handler()
2374 gmExceptionHandlingWidgets.set_client_version(_cfg.get(option = 'client_version'))
2375
2376 _log.info('display: %s:%s' % (wx.SystemSettings.GetMetric(wx.SYS_SCREEN_X), wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y)))
2377
2378
2379 self.SetAppName(u'gnumed')
2380 self.SetVendorName(u'The GNUmed Development Community.')
2381 paths = gmTools.gmPaths(app_name = u'gnumed', wx = wx)
2382 paths.init_paths(wx = wx, app_name = u'gnumed')
2383
2384 if not self.__setup_prefs_file():
2385 return False
2386
2387 gmExceptionHandlingWidgets.set_sender_email(gmSurgery.gmCurrentPractice().user_email)
2388
2389 self.__guibroker = gmGuiBroker.GuiBroker()
2390 self.__setup_platform()
2391
2392 if not self.__establish_backend_connection():
2393 return False
2394
2395 if not _cfg.get(option = 'skip-update-check'):
2396 self.__check_for_updates()
2397
2398 if _cfg.get(option = 'slave'):
2399 if not self.__setup_scripting_listener():
2400 return False
2401
2402
2403 frame = gmTopLevelFrame(None, -1, _('GNUmed client'), (640,440))
2404 frame.CentreOnScreen(wx.BOTH)
2405 self.SetTopWindow(frame)
2406 frame.Show(True)
2407
2408 if _cfg.get(option = 'debug'):
2409 self.RedirectStdio()
2410 self.SetOutputWindowAttributes(title = _('GNUmed stdout/stderr window'))
2411
2412
2413 print '---=== GNUmed startup ===---'
2414 print _('redirecting STDOUT/STDERR to this log window')
2415 print '---=== GNUmed startup ===---'
2416
2417 self.__setup_user_activity_timer()
2418 self.__register_events()
2419
2420 wx.CallAfter(self._do_after_init)
2421
2422 return True
2423
2425 """Called internally by wxPython after EVT_CLOSE has been handled on last frame.
2426
2427 - after destroying all application windows and controls
2428 - before wx.Windows internal cleanup
2429 """
2430 _log.debug('gmApp.OnExit() start')
2431
2432 self.__shutdown_user_activity_timer()
2433
2434 if _cfg.get(option = 'debug'):
2435 self.RestoreStdio()
2436 sys.stdin = sys.__stdin__
2437 sys.stdout = sys.__stdout__
2438 sys.stderr = sys.__stderr__
2439
2440 _log.debug('gmApp.OnExit() end')
2441
2443 wx.Bell()
2444 wx.Bell()
2445 wx.Bell()
2446 _log.warning('unhandled event detected: QUERY_END_SESSION')
2447 _log.info('we should be saving ourselves from here')
2448 gmLog2.flush()
2449 print "unhandled event detected: QUERY_END_SESSION"
2450
2452 wx.Bell()
2453 wx.Bell()
2454 wx.Bell()
2455 _log.warning('unhandled event detected: END_SESSION')
2456 gmLog2.flush()
2457 print "unhandled event detected: END_SESSION"
2458
2469
2471 self.user_activity_detected = True
2472 evt.Skip()
2473
2475
2476 if self.user_activity_detected:
2477 self.elapsed_inactivity_slices = 0
2478 self.user_activity_detected = False
2479 self.elapsed_inactivity_slices += 1
2480 else:
2481 if self.elapsed_inactivity_slices >= self.max_user_inactivity_slices:
2482
2483 pass
2484
2485 self.user_activity_timer.Start(oneShot = True)
2486
2487
2488
2490 try:
2491 kwargs['originated_in_database']
2492 print '==> got notification from database "%s":' % kwargs['signal']
2493 except KeyError:
2494 print '==> received signal from client: "%s"' % kwargs['signal']
2495
2496 del kwargs['signal']
2497 for key in kwargs.keys():
2498 print ' [%s]: %s' % (key, kwargs[key])
2499
2501 print "wx.lib.pubsub message:"
2502 print msg.topic
2503 print msg.data
2504
2510
2512 self.user_activity_detected = True
2513 self.elapsed_inactivity_slices = 0
2514
2515 self.max_user_inactivity_slices = 15
2516 self.user_activity_timer = gmTimer.cTimer (
2517 callback = self._on_user_activity_timer_expired,
2518 delay = 2000
2519 )
2520 self.user_activity_timer.Start(oneShot=True)
2521
2523 try:
2524 self.user_activity_timer.Stop()
2525 del self.user_activity_timer
2526 except:
2527 pass
2528
2530 wx.EVT_QUERY_END_SESSION(self, self._on_query_end_session)
2531 wx.EVT_END_SESSION(self, self._on_end_session)
2532
2533
2534
2535
2536
2537 self.Bind(wx.EVT_ACTIVATE_APP, self._on_app_activated)
2538
2539 self.Bind(wx.EVT_MOUSE_EVENTS, self._on_user_activity)
2540 self.Bind(wx.EVT_KEY_DOWN, self._on_user_activity)
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2566
2568 """Handle all the database related tasks necessary for startup."""
2569
2570
2571 override = _cfg.get(option = '--override-schema-check', source_order = [('cli', 'return')])
2572
2573 from Gnumed.wxpython import gmAuthWidgets
2574 connected = gmAuthWidgets.connect_to_database (
2575 expected_version = gmPG2.map_client_branch2required_db_version[_cfg.get(option = 'client_branch')],
2576 require_version = not override
2577 )
2578 if not connected:
2579 _log.warning("Login attempt unsuccessful. Can't run GNUmed without database connection")
2580 return False
2581
2582
2583 try:
2584 global _provider
2585 _provider = gmPerson.gmCurrentProvider(provider = gmPerson.cStaff())
2586 except ValueError:
2587 account = gmPG2.get_current_user()
2588 _log.exception('DB account [%s] cannot be used as a GNUmed staff login', account)
2589 msg = _(
2590 'The database account [%s] cannot be used as a\n'
2591 'staff member login for GNUmed. There was an\n'
2592 'error retrieving staff details for it.\n\n'
2593 'Please ask your administrator for help.\n'
2594 ) % account
2595 gmGuiHelpers.gm_show_error(msg, _('Checking access permissions'))
2596 return False
2597
2598
2599 tmp = '%s%s %s (%s = %s)' % (
2600 gmTools.coalesce(_provider['title'], ''),
2601 _provider['firstnames'],
2602 _provider['lastnames'],
2603 _provider['short_alias'],
2604 _provider['db_user']
2605 )
2606 gmExceptionHandlingWidgets.set_staff_name(staff_name = tmp)
2607
2608
2609 surgery = gmSurgery.gmCurrentPractice()
2610 msg = surgery.db_logon_banner
2611 if msg.strip() != u'':
2612
2613 login = gmPG2.get_default_login()
2614 auth = u'\n%s\n\n' % (_('Database <%s> on <%s>') % (
2615 login.database,
2616 gmTools.coalesce(login.host, u'localhost')
2617 ))
2618 msg = auth + msg + u'\n\n'
2619
2620 dlg = gmGuiHelpers.c2ButtonQuestionDlg (
2621 None,
2622 -1,
2623 caption = _('Verifying database'),
2624 question = gmTools.wrap(msg, 60, initial_indent = u' ', subsequent_indent = u' '),
2625 button_defs = [
2626 {'label': _('Connect'), 'tooltip': _('Yes, connect to this database.'), 'default': True},
2627 {'label': _('Disconnect'), 'tooltip': _('No, do not connect to this database.'), 'default': False}
2628 ]
2629 )
2630 go_on = dlg.ShowModal()
2631 dlg.Destroy()
2632 if go_on != wx.ID_YES:
2633 _log.info('user decided to not connect to this database')
2634 return False
2635
2636
2637 self.__check_db_lang()
2638
2639 return True
2640
2642 """Setup access to a config file for storing preferences."""
2643
2644 paths = gmTools.gmPaths(app_name = u'gnumed', wx = wx)
2645
2646 candidates = []
2647 explicit_file = _cfg.get(option = '--conf-file', source_order = [('cli', 'return')])
2648 if explicit_file is not None:
2649 candidates.append(explicit_file)
2650
2651 candidates.append(os.path.join(paths.user_config_dir, 'gnumed.conf'))
2652 candidates.append(os.path.join(paths.local_base_dir, 'gnumed.conf'))
2653 candidates.append(os.path.join(paths.working_dir, 'gnumed.conf'))
2654
2655 prefs_file = None
2656 for candidate in candidates:
2657 try:
2658 open(candidate, 'a+').close()
2659 prefs_file = candidate
2660 break
2661 except IOError:
2662 continue
2663
2664 if prefs_file is None:
2665 msg = _(
2666 'Cannot find configuration file in any of:\n'
2667 '\n'
2668 ' %s\n'
2669 'You may need to use the comand line option\n'
2670 '\n'
2671 ' --conf-file=<FILE>'
2672 ) % '\n '.join(candidates)
2673 gmGuiHelpers.gm_show_error(msg, _('Checking configuration files'))
2674 return False
2675
2676 _cfg.set_option(option = u'user_preferences_file', value = prefs_file)
2677 _log.info('user preferences file: %s', prefs_file)
2678
2679 return True
2680
2682
2683 from socket import error as SocketError
2684 from Gnumed.pycommon import gmScriptingListener
2685 from Gnumed.wxpython import gmMacro
2686
2687 slave_personality = gmTools.coalesce (
2688 _cfg.get (
2689 group = u'workplace',
2690 option = u'slave personality',
2691 source_order = [
2692 ('explicit', 'return'),
2693 ('workbase', 'return'),
2694 ('user', 'return'),
2695 ('system', 'return')
2696 ]
2697 ),
2698 u'gnumed-client'
2699 )
2700 _cfg.set_option(option = 'slave personality', value = slave_personality)
2701
2702
2703 port = int (
2704 gmTools.coalesce (
2705 _cfg.get (
2706 group = u'workplace',
2707 option = u'xml-rpc port',
2708 source_order = [
2709 ('explicit', 'return'),
2710 ('workbase', 'return'),
2711 ('user', 'return'),
2712 ('system', 'return')
2713 ]
2714 ),
2715 9999
2716 )
2717 )
2718 _cfg.set_option(option = 'xml-rpc port', value = port)
2719
2720 macro_executor = gmMacro.cMacroPrimitives(personality = slave_personality)
2721 global _scripting_listener
2722 try:
2723 _scripting_listener = gmScriptingListener.cScriptingListener(port = port, macro_executor = macro_executor)
2724 except SocketError, e:
2725 _log.exception('cannot start GNUmed XML-RPC server')
2726 gmGuiHelpers.gm_show_error (
2727 aMessage = (
2728 'Cannot start the GNUmed server:\n'
2729 '\n'
2730 ' [%s]'
2731 ) % e,
2732 aTitle = _('GNUmed startup')
2733 )
2734 return False
2735
2736 return True
2737
2757
2759 if gmI18N.system_locale is None or gmI18N.system_locale == '':
2760 _log.warning("system locale is undefined (probably meaning 'C')")
2761 return True
2762
2763
2764 rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': u"select i18n.get_curr_lang() as lang"}])
2765 db_lang = rows[0]['lang']
2766
2767 if db_lang is None:
2768 _log.debug("database locale currently not set")
2769 msg = _(
2770 "There is no language selected in the database for user [%s].\n"
2771 "Your system language is currently set to [%s].\n\n"
2772 "Do you want to set the database language to '%s' ?\n\n"
2773 ) % (_provider['db_user'], gmI18N.system_locale, gmI18N.system_locale)
2774 checkbox_msg = _('Remember to ignore missing language')
2775 else:
2776 _log.debug("current database locale: [%s]" % db_lang)
2777 msg = _(
2778 "The currently selected database language ('%s') does\n"
2779 "not match the current system language ('%s').\n"
2780 "\n"
2781 "Do you want to set the database language to '%s' ?\n"
2782 ) % (db_lang, gmI18N.system_locale, gmI18N.system_locale)
2783 checkbox_msg = _('Remember to ignore language mismatch')
2784
2785
2786 if db_lang == gmI18N.system_locale_level['full']:
2787 _log.debug('Database locale (%s) up to date.' % db_lang)
2788 return True
2789 if db_lang == gmI18N.system_locale_level['country']:
2790 _log.debug('Database locale (%s) matches system locale (%s) at country level.' % (db_lang, gmI18N.system_locale))
2791 return True
2792 if db_lang == gmI18N.system_locale_level['language']:
2793 _log.debug('Database locale (%s) matches system locale (%s) at language level.' % (db_lang, gmI18N.system_locale))
2794 return True
2795
2796 _log.warning('database locale [%s] does not match system locale [%s]' % (db_lang, gmI18N.system_locale))
2797
2798
2799 ignored_sys_lang = _cfg.get (
2800 group = u'backend',
2801 option = u'ignored mismatching system locale',
2802 source_order = [('explicit', 'return'), ('local', 'return'), ('user', 'return'), ('system', 'return')]
2803 )
2804
2805
2806 if gmI18N.system_locale == ignored_sys_lang:
2807 _log.info('configured to ignore system-to-database locale mismatch')
2808 return True
2809
2810
2811 dlg = gmGuiHelpers.c2ButtonQuestionDlg (
2812 None,
2813 -1,
2814 caption = _('Checking database language settings'),
2815 question = msg,
2816 button_defs = [
2817 {'label': _('Set'), 'tooltip': _('Set your database language to [%s].') % gmI18N.system_locale, 'default': True},
2818 {'label': _("Don't set"), 'tooltip': _('Do not set your database language now.'), 'default': False}
2819 ],
2820 show_checkbox = True,
2821 checkbox_msg = checkbox_msg,
2822 checkbox_tooltip = _(
2823 'Checking this will make GNUmed remember your decision\n'
2824 'until the system language is changed.\n'
2825 '\n'
2826 'You can also reactivate this inquiry by removing the\n'
2827 'corresponding "ignore" option from the configuration file\n'
2828 '\n'
2829 ' [%s]'
2830 ) % _cfg.get(option = 'user_preferences_file')
2831 )
2832 decision = dlg.ShowModal()
2833 remember_ignoring_problem = dlg._CHBOX_dont_ask_again.GetValue()
2834 dlg.Destroy()
2835
2836 if decision == wx.ID_NO:
2837 if not remember_ignoring_problem:
2838 return True
2839 _log.info('User did not want to set database locale. Ignoring mismatch next time.')
2840 gmCfg2.set_option_in_INI_file (
2841 filename = _cfg.get(option = 'user_preferences_file'),
2842 group = 'backend',
2843 option = 'ignored mismatching system locale',
2844 value = gmI18N.system_locale
2845 )
2846 return True
2847
2848
2849 for lang in [gmI18N.system_locale_level['full'], gmI18N.system_locale_level['country'], gmI18N.system_locale_level['language']]:
2850 if len(lang) > 0:
2851
2852
2853 rows, idx = gmPG2.run_rw_queries (
2854 link_obj = None,
2855 queries = [{'cmd': u'select i18n.set_curr_lang(%s)', 'args': [lang]}],
2856 return_data = True
2857 )
2858 if rows[0][0]:
2859 _log.debug("Successfully set database language to [%s]." % lang)
2860 else:
2861 _log.error('Cannot set database language to [%s].' % lang)
2862 continue
2863 return True
2864
2865
2866 _log.info('forcing database language to [%s]', gmI18N.system_locale_level['country'])
2867 gmPG2.run_rw_queries(queries = [{
2868 'cmd': u'select i18n.force_curr_lang(%s)',
2869 'args': [gmI18N.system_locale_level['country']]
2870 }])
2871
2872 return True
2873
2875 try:
2876 kwargs['originated_in_database']
2877 print '==> got notification from database "%s":' % kwargs['signal']
2878 except KeyError:
2879 print '==> received signal from client: "%s"' % kwargs['signal']
2880
2881 del kwargs['signal']
2882 for key in kwargs.keys():
2883
2884 try: print ' [%s]: %s' % (key, kwargs[key])
2885 except: print 'cannot print signal information'
2886
2888
2889 try:
2890 print '==> received wx.lib.pubsub message: "%s"' % msg.topic
2891 print ' data: %s' % msg.data
2892 print msg
2893 except: print 'problem printing pubsub message information'
2894
2896
2897 if _cfg.get(option = 'debug'):
2898 gmDispatcher.connect(receiver = _signal_debugging_monitor)
2899 _log.debug('gmDispatcher signal monitor activated')
2900 wx.lib.pubsub.Publisher().subscribe (
2901 listener = _signal_debugging_monitor_pubsub,
2902 topic = wx.lib.pubsub.getStrAllTopics()
2903 )
2904 _log.debug('wx.lib.pubsub signal monitor activated')
2905
2906
2907
2908
2909 app = gmApp(redirect = False, clearSigInt = False)
2910 app.MainLoop()
2911
2912
2913
2914 if __name__ == '__main__':
2915
2916 from GNUmed.pycommon import gmI18N
2917 gmI18N.activate_locale()
2918 gmI18N.install_domain()
2919
2920 _log.info('Starting up as main module.')
2921 main()
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518