Package Gnumed :: Package wxpython :: Module gmExportAreaWidgets
[frames] | no frames]

Source Code for Module Gnumed.wxpython.gmExportAreaWidgets

  1  """GNUmed patient export area widgets.""" 
  2  #================================================================ 
  3  __author__ = "Karsten.Hilbert@gmx.net" 
  4  __license__ = "GPL v2 or later" 
  5   
  6  # std lib 
  7  import sys 
  8  import logging 
  9  import os.path 
 10  import shutil 
 11   
 12   
 13  # 3rd party 
 14  import wx 
 15   
 16   
 17  # GNUmed libs 
 18  if __name__ == '__main__': 
 19          sys.path.insert(0, '../../') 
 20   
 21  from Gnumed.pycommon import gmDispatcher 
 22  from Gnumed.pycommon import gmTools 
 23  from Gnumed.pycommon import gmMimeLib 
 24  from Gnumed.pycommon import gmDateTime 
 25  from Gnumed.pycommon import gmPrinting 
 26  from Gnumed.pycommon import gmShellAPI 
 27  from Gnumed.pycommon import gmNetworkTools 
 28   
 29  from Gnumed.business import gmPerson 
 30  from Gnumed.business import gmExportArea 
 31   
 32  from Gnumed.wxpython import gmRegetMixin 
 33  from Gnumed.wxpython import gmGuiHelpers 
 34  from Gnumed.wxpython import gmDocumentWidgets 
 35   
 36   
 37  _log = logging.getLogger('gm.ui') 
 38   
 39   
 40  #============================================================ 
 41  from Gnumed.wxGladeWidgets import wxgCreatePatientMediaDlg 
 42   
43 -class cCreatePatientMediaDlg(wxgCreatePatientMediaDlg.wxgCreatePatientMediaDlg):
44
45 - def __init__(self, *args, **kwargs):
46 self.__burn2cd = False 47 try: 48 self.__burn2cd = kwargs['burn2cd'] 49 del kwargs['burn2cd'] 50 except KeyError: 51 pass 52 if self.__burn2cd: 53 _log.debug('planning to burn export area items to CD/DVD') 54 else: 55 _log.debug('planning to save export area items to disk') 56 self.__patient = kwargs['patient'] 57 del kwargs['patient'] 58 self.__item_count = kwargs['item_count'] 59 del kwargs['item_count'] 60 wxgCreatePatientMediaDlg.wxgCreatePatientMediaDlg.__init__(self, *args, **kwargs) 61 62 self.__init_ui()
63 64 #-------------------------------------------------------- 65 # event handling 66 #--------------------------------------------------------
67 - def _on_select_directory_button_pressed(self, event):
68 event.Skip() 69 if self.__burn2cd: 70 msg = _('Select a directory for inclusion into the patient CD / DVD.') 71 else: 72 msg = _('Select a directory in which to create the patient media.') 73 def_path = self._LBL_directory.Label 74 dlg = wx.DirDialog ( 75 self, 76 message = msg, 77 defaultPath = def_path 78 ) 79 choice = dlg.ShowModal() 80 path = dlg.GetPath() 81 dlg.Destroy() 82 if choice != wx.ID_OK: 83 return 84 self._LBL_directory.Label = path 85 self.__refresh_dir_is_empty() 86 self.__refresh_include_or_remove_existing_data()
87 88 #--------------------------------------------------------
89 - def _on_use_subdirectory_changed(self, event):
90 event.Skip() 91 92 self.__refresh_include_or_remove_existing_data() 93 94 if self._CHBOX_use_subdirectory.IsChecked(): 95 self._LBL_subdirectory.Label = '%s/%s-###' % ( 96 self._LBL_directory.Label, 97 self.__patient.subdir_name 98 ) 99 return 100 101 self._LBL_subdirectory.Label = ''
102 103 #--------------------------------------------------------
104 - def _on_save_button_pressed(self, event):
105 event.Skip() 106 107 print("Is modal ? ->", self.IsModal()) 108 109 if self.__burn2cd: 110 print("EndModal on burn2cd=True") 111 self.EndModal(wx.ID_SAVE) 112 113 if self._CHBOX_use_subdirectory.IsChecked() is True: 114 print("EndModal on use_subdir=True") 115 self.EndModal(wx.ID_SAVE) 116 print("after EndModal !!") 117 118 path = self._LBL_directory.Label 119 120 if gmTools.dir_is_empty(path) is True: 121 print("EndModal on dir_is_empty=True") 122 self.EndModal(wx.ID_SAVE) 123 124 if self._RBTN_remove_data.Value is True: 125 really_remove_existing_data = gmGuiHelpers.gm_show_question ( 126 title = _('Creating patient media'), 127 question = _( 128 'Really delete any existing data under\n' 129 '\n' 130 ' [%s]\n' 131 '\n' 132 'from disk ?\n' 133 '\n' 134 '(this operation is generally not reversible)' 135 ) % path 136 ) 137 if really_remove_existing_data is False: 138 return 139 140 print("Is modal ? ->", self.IsModal()) 141 print("now calling EndModal(wx.ID_SAVE)") 142 self.EndModal(wx.ID_SAVE)
143 144 #--------------------------------------------------------
145 - def _on_browse_directory_button_pressed(self, event):
146 event.Skip() 147 path = self._LBL_directory.Label.strip() 148 if path == '': 149 return 150 gmMimeLib.call_viewer_on_file(path, block = False)
151 152 #-------------------------------------------------------- 153 # internal API 154 #--------------------------------------------------------
155 - def __init_ui(self):
156 157 self._LBL_dir_is_empty.Label = '' 158 self._LBL_subdirectory.Label = '' 159 160 if self.__burn2cd: 161 self._LBL_existing_data.Hide() 162 self._BTN_browse_directory.Disable() 163 self._RBTN_include_data.Hide() 164 self._RBTN_remove_data.Hide() 165 self._CHBOX_include_directory.Show() 166 self._CHBOX_use_subdirectory.Hide() 167 self._LBL_subdirectory.Hide() 168 self._CHBOX_generate_metadata.Hide() 169 lines = [ 170 _('Preparing patient media for burning onto CD / DVD'), 171 '' 172 ] 173 found, external_cmd = gmShellAPI.detect_external_binary('gm-burn_doc') 174 if not found: 175 lines.append(_('Script <gm-burn_doc(.bat)> not found.')) 176 lines.append('') 177 lines.append(_('Cannot attempt to burn patient media onto CD/DVD.')) 178 self._BTN_save.Disable() 179 else: 180 lines.append(_('Patient: %s') % self.__patient['description_gender']) 181 lines.append('') 182 lines.append(_('Number of items to export onto CD/DVD: %s\n') % self.__item_count) 183 self._LBL_header.Label = '\n'.join(lines) 184 return 185 186 lines = [ 187 _('Preparing patient media for saving to disk (USB, harddrive).'), 188 '', 189 _('Patient: %s') % self.__patient['description_gender'], 190 '', 191 _('Number of items to export to disk: %s\n') % self.__item_count 192 ] 193 self._LBL_header.Label = '\n'.join(lines) 194 self._LBL_directory.Label = os.path.join(gmTools.gmPaths().home_dir, 'gnumed') 195 self.__refresh_dir_is_empty()
196 197 #--------------------------------------------------------
198 - def __refresh_dir_is_empty(self):
199 path = self._LBL_directory.Label.strip() 200 if path == '': 201 self._LBL_dir_is_empty.Label = '' 202 self._BTN_browse_directory.Disable() 203 self._CHBOX_include_directory.Disable() 204 return 205 is_empty = gmTools.dir_is_empty(directory = path) 206 if is_empty is None: 207 self._LBL_dir_is_empty.Label = _('(cannot check directory)') 208 self._BTN_browse_directory.Disable() 209 self._CHBOX_include_directory.Disable() 210 return 211 if is_empty is True: 212 self._LBL_dir_is_empty.Label = _('(directory appears empty)') 213 self._BTN_browse_directory.Disable() 214 self._CHBOX_include_directory.Disable() 215 return 216 217 msg = _('directory already contains data') 218 self._BTN_browse_directory.Enable() 219 self._CHBOX_include_directory.Enable() 220 221 if os.path.isfile(os.path.join(path, 'DICOMDIR')): 222 msg = _('%s\n- DICOM data') % msg 223 224 if os.path.isdir(os.path.join(path, 'documents')): 225 if len(os.listdir(os.path.join(path, 'documents'))) > 0: 226 msg = _('%s\n- additional documents') % msg 227 228 self._LBL_dir_is_empty.Label = msg 229 self.Layout()
230 231 #--------------------------------------------------------
233 if self._CHBOX_use_subdirectory.IsChecked(): 234 self._RBTN_include_data.Disable() 235 self._RBTN_remove_data.Disable() 236 return 237 238 path = self._LBL_directory.Label.strip() 239 if path == '': 240 self._RBTN_include_data.Disable() 241 self._RBTN_remove_data.Disable() 242 return 243 244 is_empty = gmTools.dir_is_empty(directory = path) 245 if is_empty is None: 246 self._RBTN_include_data.Disable() 247 self._RBTN_remove_data.Disable() 248 return 249 250 if is_empty is True: 251 self._RBTN_include_data.Disable() 252 self._RBTN_remove_data.Disable() 253 return 254 255 self._RBTN_include_data.Enable() 256 self._RBTN_remove_data.Enable()
257 258 #============================================================ 259 from Gnumed.wxGladeWidgets import wxgExportAreaPluginPnl 260
261 -class cExportAreaPluginPnl(wxgExportAreaPluginPnl.wxgExportAreaPluginPnl, gmRegetMixin.cRegetOnPaintMixin):
262 """Panel holding a number of items for further processing. 263 264 Acts on the current patient. 265 266 Used as notebook page."""
267 - def __init__(self, *args, **kwargs):
268 wxgExportAreaPluginPnl.wxgExportAreaPluginPnl.__init__(self, *args, **kwargs) 269 gmRegetMixin.cRegetOnPaintMixin.__init__(self) 270 self.__init_ui() 271 self.__register_interests()
272 273 #-------------------------------------------------------- 274 # event handling 275 #--------------------------------------------------------
276 - def __register_interests(self):
277 gmDispatcher.connect(signal = 'pre_patient_unselection', receiver = self._on_pre_patient_unselection) 278 # gmDispatcher.connect(signal = u'post_patient_selection', receiver = self._schedule_data_reget) 279 gmDispatcher.connect(signal = 'gm_table_mod', receiver = self._on_table_mod)
280 281 #--------------------------------------------------------
283 self._LCTRL_items.set_string_items([])
284 285 #--------------------------------------------------------
286 - def _on_table_mod(self, *args, **kwargs):
287 if kwargs['table'] != 'clin.export_item': 288 return 289 pat = gmPerson.gmCurrentPatient() 290 if not pat.connected: 291 return 292 if kwargs['pk_identity'] != pat.ID: 293 return 294 self._schedule_data_reget()
295 296 #--------------------------------------------------------
297 - def _on_list_item_selected(self, event):
298 event.Skip()
299 300 #--------------------------------------------------------
301 - def _on_show_item_button_pressed(self, event):
302 event.Skip() 303 item = self._LCTRL_items.get_selected_item_data(only_one = True) 304 if item is None: 305 return 306 item.display_via_mime(block = False)
307 308 #--------------------------------------------------------
309 - def _on_add_items_button_pressed(self, event):
310 event.Skip() 311 dlg = wx.FileDialog ( 312 parent = self, 313 message = _("Select files to add to the export area"), 314 defaultDir = os.path.expanduser(os.path.join('~', 'gnumed')), 315 style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST | wx.FD_MULTIPLE | wx.FD_PREVIEW 316 ) 317 choice = dlg.ShowModal() 318 fnames = dlg.GetPaths() 319 dlg.Destroy() 320 if choice != wx.ID_OK: 321 return 322 if not gmPerson.gmCurrentPatient().export_area.add_files(fnames): 323 gmGuiHelpers.gm_show_error ( 324 title = _('Adding files to export area'), 325 error = _('Cannot add (some of) the following files to the export area:\n%s ') % '\n '.join(fnames) 326 )
327 328 #--------------------------------------------------------
329 - def _on_add_from_archive_button_pressed(self, event):
330 event.Skip() 331 selected_docs = gmDocumentWidgets.manage_documents ( 332 parent = self, 333 msg = _('Select the documents to be put into the export area:'), 334 single_selection = False 335 ) 336 if selected_docs is None: 337 return 338 gmPerson.gmCurrentPatient().export_area.add_documents(documents = selected_docs)
339 340 #--------------------------------------------------------
341 - def _on_clipboard_items_button_pressed(self, event):
342 event.Skip() 343 clip = gmGuiHelpers.clipboard2file(check_for_filename = True) 344 if clip is None: 345 return 346 if clip is False: 347 return 348 if not gmPerson.gmCurrentPatient().export_area.add_file(filename = clip, hint = _('clipboard')): 349 gmGuiHelpers.gm_show_error ( 350 title = _('Loading clipboard item (saved to file) into export area'), 351 error = _('Cannot add the following clip to the export area:\n%s ') % clip 352 )
353 354 #--------------------------------------------------------
355 - def _on_scan_items_button_pressed(self, event):
356 event.Skip() 357 scans = gmDocumentWidgets.acquire_images_from_capture_device(calling_window = self) 358 if scans is None: 359 return 360 361 if not gmPerson.gmCurrentPatient().export_area.add_files(scans, _('scan')): 362 gmGuiHelpers.gm_show_error ( 363 title = _('Scanning files into export area'), 364 error = _('Cannot add (some of) the following scans to the export area:\n%s ') % '\n '.join(fnames) 365 )
366 367 #--------------------------------------------------------
368 - def _on_remove_items_button_pressed(self, event):
369 event.Skip() 370 items = self._LCTRL_items.get_selected_item_data(only_one = False) 371 if len(items) == 0: 372 return 373 really_delete = gmGuiHelpers.gm_show_question ( 374 title = _('Deleting document from export area.'), 375 question = _('Really remove %s selected document(s)\nfrom the patient export area ?') % len(items) 376 ) 377 if not really_delete: 378 return 379 for item in items: 380 gmExportArea.delete_export_item(pk_export_item = item['pk_export_item'])
381 382 #--------------------------------------------------------
383 - def _on_print_items_button_pressed(self, event):
384 event.Skip() 385 items = self._LCTRL_items.get_selected_item_data(only_one = False) 386 if len(items) == 0: 387 return 388 389 files2print = [] 390 for item in items: 391 files2print.append(item.save_to_file()) 392 393 if len(files2print) == 0: 394 return 395 396 jobtype = 'export_area' 397 printed = gmPrinting.print_files(filenames = files2print, jobtype = jobtype) 398 if not printed: 399 gmGuiHelpers.gm_show_error ( 400 aMessage = _('Error printing documents.'), 401 aTitle = _('Printing [%s]') % jobtype 402 ) 403 return False 404 405 self.save_soap_note(soap = _('Printed:\n - %s') % '\n - '.join([ i['description'] for i in items ])) 406 return True
407 408 #--------------------------------------------------------
409 - def _on_remote_print_button_pressed(self, event):
410 event.Skip() 411 items = self._LCTRL_items.get_selected_item_data(only_one = False) 412 for item in items: 413 item.is_print_job = True
414 415 #--------------------------------------------------------
416 - def _on_save_items_button_pressed(self, event):
417 event.Skip() 418 419 items = self._LCTRL_items.get_selected_item_data(only_one = False) 420 if len(items) == 0: 421 items = self._LCTRL_items.get_item_data() 422 423 if len(items) == 0: 424 return 425 426 pat = gmPerson.gmCurrentPatient() 427 dlg = cCreatePatientMediaDlg (self, -1, burn2cd = False, patient = pat, item_count = len(items)) 428 print("calling dlg.ShowModal()") 429 choice = dlg.ShowModal() 430 print("after returning from dlg.ShowModal()") 431 if choice != wx.ID_SAVE: 432 dlg.Destroy() 433 return 434 435 use_subdir = dlg._CHBOX_use_subdirectory.IsChecked() 436 path = dlg._LBL_directory.Label.strip() 437 remove_existing_data = dlg._RBTN_remove_data.Value is True 438 generate_metadata = dlg._CHBOX_generate_metadata.IsChecked() 439 dlg.Destroy() 440 if use_subdir: 441 path = gmTools.mk_sandbox_dir ( 442 prefix = '%s-' % pat.subdir_name, 443 base_dir = path 444 ) 445 else: 446 if remove_existing_data is True: 447 if gmTools.rm_dir_content(path) is False: 448 gmGuiHelpers.gm_show_error ( 449 title = _('Creating patient media'), 450 error = _('Cannot remove content from\n [%s]') % path 451 ) 452 return False 453 454 exp_area = pat.export_area 455 if generate_metadata: 456 export_dir = exp_area.export(base_dir = path, items = items) 457 else: 458 export_dir = exp_area.dump_items_to_disk(base_dir = path, items = items) 459 460 self.save_soap_note(soap = _('Saved to [%s]:\n - %s') % ( 461 export_dir, 462 '\n - '.join([ i['description'] for i in items ]) 463 )) 464 465 msg = _('Saved documents into directory:\n\n %s') % export_dir 466 browse_index = gmGuiHelpers.gm_show_question ( 467 title = _('Creating patient media'), 468 question = msg + '\n\n' + _('Browse patient data pack ?'), 469 cancel_button = False 470 ) 471 if browse_index: 472 if generate_metadata: 473 gmNetworkTools.open_url_in_browser(url = 'file://%s' % os.path.join(export_dir, 'index.html')) 474 else: 475 gmMimeLib.call_viewer_on_file(export_dir, block = False) 476 477 return True
478 479 #--------------------------------------------------------
480 - def _on_burn_items_button_pressed(self, event):
481 event.Skip() 482 483 # anything to do ? 484 found, external_cmd = gmShellAPI.detect_external_binary('gm-burn_doc') 485 if not found: 486 return 487 items = self._LCTRL_items.get_selected_item_data(only_one = False) 488 if len(items) == 0: 489 items = self._LCTRL_items.get_item_data() 490 if len(items) == 0: 491 return 492 493 pat = gmPerson.gmCurrentPatient() 494 dlg = cCreatePatientMediaDlg(self, -1, burn2cd = True, patient = pat, item_count = len(items)) 495 choice = dlg.ShowModal() 496 if choice != wx.ID_SAVE: 497 return 498 path2include = dlg._LBL_directory.Label.strip() 499 include_selected_dir = dlg._CHBOX_include_directory.IsChecked() 500 dlg.Destroy() 501 502 # do the export 503 base_dir = None 504 if include_selected_dir: 505 if gmTools.dir_is_empty(path2include) is False: 506 base_dir = gmTools.get_unique_filename(suffix = '.iso') 507 try: 508 shutil.copytree(path2include, base_dir) 509 except shutil.Error: 510 _log.exception('cannot copy include directory [%s] -> [%s]', path2include, base_dir) 511 return 512 513 export_dir = gmPerson.gmCurrentPatient().export_area.export(base_dir = base_dir, items = items, with_metadata = True) 514 if export_dir is None: 515 return 516 517 # burn onto media 518 cmd = '%s %s' % (external_cmd, export_dir) 519 if os.name == 'nt': 520 blocking = True 521 else: 522 blocking = False 523 success = gmShellAPI.run_command_in_shell ( 524 command = cmd, 525 blocking = blocking 526 ) 527 if not success: 528 gmGuiHelpers.gm_show_error ( 529 aMessage = _('Error burning documents to CD/DVD.'), 530 aTitle = _('Burning documents') 531 ) 532 return 533 534 self.save_soap_note(soap = _('Burned onto CD/DVD:\n - %s') % '\n - '.join([ i['description'] for i in items ])) 535 536 browse_index = gmGuiHelpers.gm_show_question ( 537 title = _('Creating patient media'), 538 question = _('Browse patient data pack ?'), 539 cancel_button = False 540 ) 541 if browse_index: 542 gmNetworkTools.open_url_in_browser(url = 'file://%s' % os.path.join(export_dir, 'index.html')) 543 544 return True
545 546 #--------------------------------------------------------
547 - def _on_archive_items_button_pressed(self, event):
548 print("Event handler '_on_archive_items_button_pressed' not implemented!") 549 event.Skip()
550 551 #--------------------------------------------------------
552 - def _on_mail_items_button_pressed(self, event):
553 event.Skip() 554 555 items = self._LCTRL_items.get_selected_item_data(only_one = False) 556 if len(items) == 0: 557 return True 558 559 found, external_cmd = gmShellAPI.detect_external_binary('gm-mail_doc') 560 if not found: 561 return False 562 563 files2mail = [] 564 for item in items: 565 files2mail.append(item.save_to_file()) 566 567 cmd = '%s %s' % (external_cmd, ' '.join(files2mail)) 568 if os.name == 'nt': 569 blocking = True 570 else: 571 blocking = False 572 success = gmShellAPI.run_command_in_shell ( 573 command = cmd, 574 blocking = blocking 575 ) 576 if not success: 577 gmGuiHelpers.gm_show_error ( 578 aMessage = _('Error mailing documents.'), 579 aTitle = _('Mailing documents') 580 ) 581 return False 582 583 self.save_soap_note(soap = _('Mailed:\n - %s') % '\n - '.join([ i['description'] for i in items ])) 584 return True
585 586 #--------------------------------------------------------
587 - def _on_fax_items_button_pressed(self, event):
588 event.Skip() 589 590 items = self._LCTRL_items.get_selected_item_data(only_one = False) 591 if len(items) == 0: 592 return 593 594 found, external_cmd = gmShellAPI.detect_external_binary('gm-fax_doc') 595 if not found: 596 return False 597 598 files2fax = [] 599 for item in items: 600 files2fax.append(item.save_to_file()) 601 602 fax_number = wx.GetTextFromUser ( 603 _('Please enter the fax number here !\n\n' 604 'It can be left empty if the external\n' 605 'fax software knows how to get the number.'), 606 caption = _('Faxing documents'), 607 parent = self, 608 centre = True 609 ) 610 611 cmd = '%s "%s" %s' % (external_cmd, fax_number, ' '.join(files2fax)) 612 if os.name == 'nt': 613 blocking = True 614 else: 615 blocking = False 616 success = gmShellAPI.run_command_in_shell ( 617 command = cmd, 618 blocking = blocking 619 ) 620 if not success: 621 gmGuiHelpers.gm_show_error ( 622 aMessage = _('Error faxing documents to\n\n %s') % fax_number, 623 aTitle = _('Faxing documents') 624 ) 625 return False 626 627 self.save_soap_note(soap = _('Faxed to [%s]:\n - %s') % ( 628 fax_number, 629 '\n - '.join([ i['description'] for i in items ]) 630 )) 631 return True
632 633 #--------------------------------------------------------
634 - def repopulate_ui(self):
635 self._populate_with_data()
636 637 #-------------------------------------------------------- 638 # internal API 639 #--------------------------------------------------------
640 - def __init_ui(self):
641 self._LCTRL_items.set_columns([_('By'), _('When'), _('Description')]) 642 643 self._BTN_archive_items.Disable() 644 645 # there's no GetToolTipText() in wx2.8 646 self.__mail_script_exists, path = gmShellAPI.detect_external_binary(binary = r'gm-mail_doc') 647 if not self.__mail_script_exists: 648 self._BTN_mail_items.Disable() 649 tt = self._BTN_mail_items.GetToolTipText() + '\n\n' + _('<gm-mail_doc(.bat) not found>') 650 self._BTN_mail_items.SetToolTip(tt) 651 652 self.__fax_script_exists, path = gmShellAPI.detect_external_binary(binary = r'gm-fax_doc') 653 if not self.__fax_script_exists: 654 self._BTN_fax_items.Disable() 655 tt = self._BTN_fax_items.GetToolTipText() + '\n\n' + _('<gm-fax_doc(.bat) not found>') 656 self._BTN_fax_items.SetToolTip(tt) 657 658 self.__burn_script_exists, path = gmShellAPI.detect_external_binary(binary = r'gm-burn_doc') 659 if not self.__burn_script_exists: 660 self._BTN_burn_items.Disable() 661 tt = self._BTN_burn_items.GetToolTipText() + '\n\n' + _('<gm-burn_doc(.bat) not found>') 662 self._BTN_burn_items.SetToolTip(tt) 663 664 # make me and listctrl file drop targets 665 dt = gmGuiHelpers.cFileDropTarget(target = self) 666 self.SetDropTarget(dt) 667 dt = gmGuiHelpers.cFileDropTarget(on_drop_callback = self._drop_target_consume_filenames) 668 self._LCTRL_items.SetDropTarget(dt)
669 670 #--------------------------------------------------------
671 - def save_soap_note(self, soap=None):
672 if soap.strip() == '': 673 return 674 emr = gmPerson.gmCurrentPatient().emr 675 epi = emr.add_episode(episode_name = 'administrative', is_open = False) 676 emr.add_clin_narrative ( 677 soap_cat = None, 678 note = soap, 679 episode = epi 680 )
681 682 #-------------------------------------------------------- 683 # file drop target API 684 #--------------------------------------------------------
685 - def _drop_target_consume_filenames(self, filenames):
686 pat = gmPerson.gmCurrentPatient() 687 if not pat.connected: 688 gmDispatcher.send(signal = 'statustext', msg = _('Cannot accept new documents. No active patient.')) 689 return 690 691 # dive into folders dropped onto us and extract files (one level deep only) 692 real_filenames = [] 693 for pathname in filenames: 694 try: 695 files = os.listdir(pathname) 696 gmDispatcher.send(signal='statustext', msg=_('Extracting files from folder [%s] ...') % pathname) 697 for file in files: 698 fullname = os.path.join(pathname, file) 699 if not os.path.isfile(fullname): 700 continue 701 real_filenames.append(fullname) 702 except OSError: 703 real_filenames.append(pathname) 704 705 if not pat.export_area.add_files(real_filenames, hint = _('Drag&Drop')): 706 gmGuiHelpers.gm_show_error ( 707 title = _('Adding files to export area'), 708 error = _('Cannot add (some of) the following files to the export area:\n%s ') % '\n '.join(real_filenames) 709 )
710 #-------------------------------------------------------- 711 # reget mixin API 712 # 713 # remember to call 714 # self._schedule_data_reget() 715 # whenever you learn of data changes from database 716 # listener threads, dispatcher signals etc. 717 #--------------------------------------------------------
718 - def _populate_with_data(self):
719 pat = gmPerson.gmCurrentPatient() 720 if not pat.connected: 721 return True 722 723 items = pat.export_area.items 724 self._LCTRL_items.set_string_items ([ 725 [ i['created_by'], 726 gmDateTime.pydt_strftime(i['created_when'], '%Y %b %d %H:%M'), 727 i['description'] 728 ] for i in items 729 ]) 730 self._LCTRL_items.set_column_widths([wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE]) 731 self._LCTRL_items.set_data(items) 732 733 self._LCTRL_items.SetFocus() 734 735 return True
736 737 #============================================================ 738 from Gnumed.wxGladeWidgets import wxgPrintMgrPluginPnl 739
740 -class cPrintMgrPluginPnl(wxgPrintMgrPluginPnl.wxgPrintMgrPluginPnl, gmRegetMixin.cRegetOnPaintMixin):
741 """Panel holding print jobs. 742 743 Used as notebook page.""" 744
745 - def __init__(self, *args, **kwargs):
746 wxgPrintMgrPluginPnl.wxgPrintMgrPluginPnl.__init__(self, *args, **kwargs) 747 gmRegetMixin.cRegetOnPaintMixin.__init__(self) 748 self.__init_ui() 749 self.__register_interests()
750 #-------------------------------------------------------- 751 # event handling 752 #--------------------------------------------------------
753 - def __register_interests(self):
754 gmDispatcher.connect(signal = 'pre_patient_unselection', receiver = self._on_pre_patient_unselection) 755 gmDispatcher.connect(signal = 'post_patient_selection', receiver = self._on_post_patient_selection) 756 gmDispatcher.connect(signal = 'gm_table_mod', receiver = self._on_table_mod)
757 #--------------------------------------------------------
759 self._RBTN_active_patient_only.Enable(False) 760 self._RBTN_all_patients.Value = True 761 self._BTN_export_printouts.Enable(False)
762 #--------------------------------------------------------
763 - def _on_post_patient_selection(self):
764 self._RBTN_active_patient_only.Enable(True) 765 self._BTN_export_printouts.Enable(True)
766 #--------------------------------------------------------
767 - def _on_table_mod(self, *args, **kwargs):
768 if kwargs['table'] != 'clin.export_item': 769 return 770 if self._RBTN_all_patients.Value is True: 771 self._schedule_data_reget() 772 return 773 pat = gmPerson.gmCurrentPatient() 774 if not pat.connected: 775 return 776 if kwargs['pk_identity'] != pat.ID: 777 return 778 self._schedule_data_reget()
779 #--------------------------------------------------------
780 - def _on_all_patients_selected(self, event):
781 event.Skip() 782 self._schedule_data_reget()
783 #--------------------------------------------------------
784 - def _on_active_patient_only_selected(self, event):
785 event.Skip() 786 self._schedule_data_reget()
787 #--------------------------------------------------------
788 - def _on_view_button_pressed(self, event):
789 event.Skip() 790 printout = self._LCTRL_printouts.get_selected_item_data(only_one = True) 791 if printout is None: 792 return 793 printout.display_via_mime(block = False)
794 #--------------------------------------------------------
795 - def _on_print_button_pressed(self, event):
796 event.Skip() 797 printouts = self._LCTRL_printouts.get_selected_item_data(only_one = False) 798 if len(printouts) == 0: 799 return 800 801 files2print = [] 802 for printout in printouts: 803 files2print.append(printout.save_to_file()) 804 805 if len(files2print) == 0: 806 return 807 808 jobtype = 'print_manager' 809 printed = gmPrinting.print_files(filenames = files2print, jobtype = jobtype) 810 if not printed: 811 gmGuiHelpers.gm_show_error ( 812 aMessage = _('Error printing documents.'), 813 aTitle = _('Printing [%s]') % jobtype 814 ) 815 return False 816 817 return True
818 #--------------------------------------------------------
819 - def _on_export_button_pressed(self, event):
820 event.Skip() 821 pat = gmPerson.gmCurrentPatient() 822 if not pat.connected: 823 return 824 printouts = self._LCTRL_printouts.get_selected_item_data(only_one = False) 825 for printout in printouts: 826 printout.is_print_job = False
827 #--------------------------------------------------------
828 - def _on_delete_button_pressed(self, event):
829 event.Skip() 830 printouts = self._LCTRL_printouts.get_selected_item_data(only_one = False) 831 if len(printouts) == 0: 832 return 833 if len(printouts) > 1: 834 really_delete = gmGuiHelpers.gm_show_question ( 835 title = _('Deleting document from export area.'), 836 question = _('Really remove %s selected document(s)\nfrom the patient export area ?') % len(printouts) 837 ) 838 if not really_delete: 839 return 840 for printout in printouts: 841 gmExportArea.delete_export_item(pk_export_item = printout['pk_export_item'])
842 #-------------------------------------------------------- 843 # internal API 844 #--------------------------------------------------------
845 - def __init_ui(self):
846 self._BTN_export_printouts.Enable(False)
847 #-------------------------------------------------------- 848 # reget mixin API 849 #--------------------------------------------------------
850 - def _populate_with_data(self):
851 if self._RBTN_all_patients.Value is True: 852 columns = [_('Patient'), _('Provider'), _('Description')] 853 printouts = gmExportArea.get_print_jobs(order_by = 'pk_identity, description') 854 items = [[ 855 '%s, %s (%s)' % ( 856 p['lastnames'], 857 p['firstnames'], 858 p['gender'] 859 ), 860 p['created_by'], 861 p['description'] 862 ] for p in printouts ] 863 else: 864 pat = gmPerson.gmCurrentPatient() 865 if pat.connected: 866 columns = [_('Provider'), _('Created'), _('Description')] 867 printouts = pat.export_area.get_printouts(order_by = 'created_when, description') 868 items = [[ 869 p['created_by'], 870 gmDateTime.pydt_strftime(p['created_when'], '%Y %b %d %H:%M'), 871 p['description'] 872 ] for p in printouts ] 873 else: 874 columns = [_('Patient'), _('Provider'), _('Description')] 875 printouts = gmExportArea.get_print_jobs(order_by = 'pk_identity, description') 876 items = [[ 877 '%s, %s (%s)' % ( 878 p['lastnames'], 879 p['firstnames'], 880 p['gender'] 881 ), 882 p['created_by'], 883 p['description'] 884 ] for p in printouts ] 885 self._LCTRL_printouts.set_columns(columns) 886 self._LCTRL_printouts.set_string_items(items) 887 self._LCTRL_printouts.set_column_widths([wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE]) 888 self._LCTRL_printouts.set_data(printouts) 889 self._LCTRL_printouts.SetFocus() 890 return True
891