| Home | Trees | Indices | Help |
|
|---|
|
|
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
44
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 #--------------------------------------------------------
87
88 #--------------------------------------------------------
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 #--------------------------------------------------------
143
144 #--------------------------------------------------------
151
152 #--------------------------------------------------------
153 # internal API
154 #--------------------------------------------------------
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 #--------------------------------------------------------
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."""
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 #--------------------------------------------------------
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 #--------------------------------------------------------
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 #--------------------------------------------------------
298 event.Skip()
299
300 #--------------------------------------------------------
307
308 #--------------------------------------------------------
327
328 #--------------------------------------------------------
339
340 #--------------------------------------------------------
353
354 #--------------------------------------------------------
366
367 #--------------------------------------------------------
381
382 #--------------------------------------------------------
407
408 #--------------------------------------------------------
414
415 #--------------------------------------------------------
478
479 #--------------------------------------------------------
545
546 #--------------------------------------------------------
550
551 #--------------------------------------------------------
585
586 #--------------------------------------------------------
632
633 #--------------------------------------------------------
636
637 #--------------------------------------------------------
638 # internal API
639 #--------------------------------------------------------
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 #--------------------------------------------------------
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 #--------------------------------------------------------
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 #--------------------------------------------------------
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
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 #--------------------------------------------------------
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 #--------------------------------------------------------
766 #--------------------------------------------------------
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 #--------------------------------------------------------
783 #--------------------------------------------------------
787 #--------------------------------------------------------
794 #--------------------------------------------------------
818 #--------------------------------------------------------
827 #--------------------------------------------------------
842 #--------------------------------------------------------
843 # internal API
844 #--------------------------------------------------------
846 self._BTN_export_printouts.Enable(False)
847 #--------------------------------------------------------
848 # reget mixin API
849 #--------------------------------------------------------
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
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Thu May 10 01:55:20 2018 | http://epydoc.sourceforge.net |