| 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 #--------------------------------------------------------
138
139 #--------------------------------------------------------
146
147 #--------------------------------------------------------
148 # internal API
149 #--------------------------------------------------------
151
152 self._LBL_dir_is_empty.Label = ''
153 self._LBL_subdirectory.Label = ''
154
155 if self.__burn2cd:
156 self._LBL_existing_data.Hide()
157 self._BTN_browse_directory.Disable()
158 self._RBTN_include_data.Hide()
159 self._RBTN_remove_data.Hide()
160 self._CHBOX_include_directory.Show()
161 self._CHBOX_use_subdirectory.Hide()
162 self._LBL_subdirectory.Hide()
163 self._CHBOX_generate_metadata.Hide()
164 lines = [
165 _('Preparing patient media for burning onto CD / DVD'),
166 ''
167 ]
168 found, external_cmd = gmShellAPI.detect_external_binary('gm-burn_doc')
169 if not found:
170 lines.append(_('Script <gm-burn_doc(.bat)> not found.'))
171 lines.append('')
172 lines.append(_('Cannot attempt to burn patient media onto CD/DVD.'))
173 self._BTN_save.Disable()
174 else:
175 lines.append(_('Patient: %s') % self.__patient['description_gender'])
176 lines.append('')
177 lines.append(_('Number of items to export onto CD/DVD: %s\n') % self.__item_count)
178 self._LBL_header.Label = '\n'.join(lines)
179 return
180
181 lines = [
182 _('Preparing patient media for saving to disk (USB, harddrive).'),
183 '',
184 _('Patient: %s') % self.__patient['description_gender'],
185 '',
186 _('Number of items to export to disk: %s\n') % self.__item_count
187 ]
188 self._LBL_header.Label = '\n'.join(lines)
189 self._LBL_directory.Label = os.path.join(gmTools.gmPaths().home_dir, 'gnumed')
190 self.__refresh_dir_is_empty()
191
192 #--------------------------------------------------------
194 path = self._LBL_directory.Label.strip()
195 if path == '':
196 self._LBL_dir_is_empty.Label = ''
197 self._BTN_browse_directory.Disable()
198 self._CHBOX_include_directory.Disable()
199 return
200 is_empty = gmTools.dir_is_empty(directory = path)
201 if is_empty is None:
202 self._LBL_dir_is_empty.Label = _('(cannot check directory)')
203 self._BTN_browse_directory.Disable()
204 self._CHBOX_include_directory.Disable()
205 return
206 if is_empty is True:
207 self._LBL_dir_is_empty.Label = _('(directory appears empty)')
208 self._BTN_browse_directory.Disable()
209 self._CHBOX_include_directory.Disable()
210 return
211
212 msg = _('directory already contains data')
213 self._BTN_browse_directory.Enable()
214 self._CHBOX_include_directory.Enable()
215
216 if os.path.isfile(os.path.join(path, 'DICOMDIR')):
217 msg = _('%s\n- DICOM data') % msg
218
219 if os.path.isdir(os.path.join(path, 'documents')):
220 if len(os.listdir(os.path.join(path, 'documents'))) > 0:
221 msg = _('%s\n- additional documents') % msg
222
223 self._LBL_dir_is_empty.Label = msg
224 self.Layout()
225
226 #--------------------------------------------------------
228 if self._CHBOX_use_subdirectory.IsChecked():
229 self._RBTN_include_data.Disable()
230 self._RBTN_remove_data.Disable()
231 return
232
233 path = self._LBL_directory.Label.strip()
234 if path == '':
235 self._RBTN_include_data.Disable()
236 self._RBTN_remove_data.Disable()
237 return
238
239 is_empty = gmTools.dir_is_empty(directory = path)
240 if is_empty is None:
241 self._RBTN_include_data.Disable()
242 self._RBTN_remove_data.Disable()
243 return
244
245 if is_empty is True:
246 self._RBTN_include_data.Disable()
247 self._RBTN_remove_data.Disable()
248 return
249
250 self._RBTN_include_data.Enable()
251 self._RBTN_remove_data.Enable()
252
253 #============================================================
254 from Gnumed.wxGladeWidgets import wxgExportAreaPluginPnl
255
256 -class cExportAreaPluginPnl(wxgExportAreaPluginPnl.wxgExportAreaPluginPnl, gmRegetMixin.cRegetOnPaintMixin):
257 """Panel holding a number of items for further processing.
258
259 Acts on the current patient.
260
261 Used as notebook page."""
263 wxgExportAreaPluginPnl.wxgExportAreaPluginPnl.__init__(self, *args, **kwargs)
264 gmRegetMixin.cRegetOnPaintMixin.__init__(self)
265 self.__init_ui()
266 self.__register_interests()
267
268 #--------------------------------------------------------
269 # event handling
270 #--------------------------------------------------------
272 gmDispatcher.connect(signal = 'pre_patient_unselection', receiver = self._on_pre_patient_unselection)
273 # gmDispatcher.connect(signal = u'post_patient_selection', receiver = self._schedule_data_reget)
274 gmDispatcher.connect(signal = 'gm_table_mod', receiver = self._on_table_mod)
275
276 #--------------------------------------------------------
278 self._LCTRL_items.set_string_items([])
279
280 #--------------------------------------------------------
282 if kwargs['table'] != 'clin.export_item':
283 return
284 pat = gmPerson.gmCurrentPatient()
285 if not pat.connected:
286 return
287 if kwargs['pk_identity'] != pat.ID:
288 return
289 self._schedule_data_reget()
290
291 #--------------------------------------------------------
293 event.Skip()
294
295 #--------------------------------------------------------
302
303 #--------------------------------------------------------
322
323 #--------------------------------------------------------
334
335 #--------------------------------------------------------
348
349 #--------------------------------------------------------
361
362 #--------------------------------------------------------
376
377 #--------------------------------------------------------
402
403 #--------------------------------------------------------
409
410 #--------------------------------------------------------
473
474 #--------------------------------------------------------
540
541 #--------------------------------------------------------
545
546 #--------------------------------------------------------
580
581 #--------------------------------------------------------
627
628 #--------------------------------------------------------
631
632 #--------------------------------------------------------
633 # internal API
634 #--------------------------------------------------------
636 self._LCTRL_items.set_columns([_('By'), _('When'), _('Description')])
637
638 self._BTN_archive_items.Disable()
639
640 # there's no GetToolTipText() in wx2.8
641 self.__mail_script_exists, path = gmShellAPI.detect_external_binary(binary = r'gm-mail_doc')
642 if not self.__mail_script_exists:
643 self._BTN_mail_items.Disable()
644 tt = self._BTN_mail_items.GetToolTipText() + '\n\n' + _('<gm-mail_doc(.bat) not found>')
645 self._BTN_mail_items.SetToolTip(tt)
646
647 self.__fax_script_exists, path = gmShellAPI.detect_external_binary(binary = r'gm-fax_doc')
648 if not self.__fax_script_exists:
649 self._BTN_fax_items.Disable()
650 tt = self._BTN_fax_items.GetToolTipText() + '\n\n' + _('<gm-fax_doc(.bat) not found>')
651 self._BTN_fax_items.SetToolTip(tt)
652
653 self.__burn_script_exists, path = gmShellAPI.detect_external_binary(binary = r'gm-burn_doc')
654 if not self.__burn_script_exists:
655 self._BTN_burn_items.Disable()
656 tt = self._BTN_burn_items.GetToolTipText() + '\n\n' + _('<gm-burn_doc(.bat) not found>')
657 self._BTN_burn_items.SetToolTip(tt)
658
659 # make me and listctrl file drop targets
660 dt = gmGuiHelpers.cFileDropTarget(target = self)
661 self.SetDropTarget(dt)
662 dt = gmGuiHelpers.cFileDropTarget(on_drop_callback = self._drop_target_consume_filenames)
663 self._LCTRL_items.SetDropTarget(dt)
664
665 #--------------------------------------------------------
667 if soap.strip() == '':
668 return
669 emr = gmPerson.gmCurrentPatient().emr
670 epi = emr.add_episode(episode_name = 'administrative', is_open = False)
671 emr.add_clin_narrative (
672 soap_cat = None,
673 note = soap,
674 episode = epi
675 )
676
677 #--------------------------------------------------------
678 # file drop target API
679 #--------------------------------------------------------
681 pat = gmPerson.gmCurrentPatient()
682 if not pat.connected:
683 gmDispatcher.send(signal = 'statustext', msg = _('Cannot accept new documents. No active patient.'))
684 return
685
686 # dive into folders dropped onto us and extract files (one level deep only)
687 real_filenames = []
688 for pathname in filenames:
689 try:
690 files = os.listdir(pathname)
691 gmDispatcher.send(signal='statustext', msg=_('Extracting files from folder [%s] ...') % pathname)
692 for file in files:
693 fullname = os.path.join(pathname, file)
694 if not os.path.isfile(fullname):
695 continue
696 real_filenames.append(fullname)
697 except OSError:
698 real_filenames.append(pathname)
699
700 if not pat.export_area.add_files(real_filenames, hint = _('Drag&Drop')):
701 gmGuiHelpers.gm_show_error (
702 title = _('Adding files to export area'),
703 error = _('Cannot add (some of) the following files to the export area:\n%s ') % '\n '.join(real_filenames)
704 )
705 #--------------------------------------------------------
706 # reget mixin API
707 #
708 # remember to call
709 # self._schedule_data_reget()
710 # whenever you learn of data changes from database
711 # listener threads, dispatcher signals etc.
712 #--------------------------------------------------------
714 pat = gmPerson.gmCurrentPatient()
715 if not pat.connected:
716 return True
717
718 items = pat.export_area.items
719 self._LCTRL_items.set_string_items ([
720 [ i['created_by'],
721 gmDateTime.pydt_strftime(i['created_when'], '%Y %b %d %H:%M'),
722 i['description']
723 ] for i in items
724 ])
725 self._LCTRL_items.set_column_widths([wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE])
726 self._LCTRL_items.set_data(items)
727
728 self._LCTRL_items.SetFocus()
729
730 return True
731
732 #============================================================
733 from Gnumed.wxGladeWidgets import wxgPrintMgrPluginPnl
734
735 -class cPrintMgrPluginPnl(wxgPrintMgrPluginPnl.wxgPrintMgrPluginPnl, gmRegetMixin.cRegetOnPaintMixin):
736 """Panel holding print jobs.
737
738 Used as notebook page."""
739
741 wxgPrintMgrPluginPnl.wxgPrintMgrPluginPnl.__init__(self, *args, **kwargs)
742 gmRegetMixin.cRegetOnPaintMixin.__init__(self)
743 self.__init_ui()
744 self.__register_interests()
745 #--------------------------------------------------------
746 # event handling
747 #--------------------------------------------------------
749 gmDispatcher.connect(signal = 'pre_patient_unselection', receiver = self._on_pre_patient_unselection)
750 gmDispatcher.connect(signal = 'post_patient_selection', receiver = self._on_post_patient_selection)
751 gmDispatcher.connect(signal = 'gm_table_mod', receiver = self._on_table_mod)
752 #--------------------------------------------------------
754 self._RBTN_active_patient_only.Enable(False)
755 self._RBTN_all_patients.Value = True
756 self._BTN_export_printouts.Enable(False)
757 #--------------------------------------------------------
761 #--------------------------------------------------------
763 if kwargs['table'] != 'clin.export_item':
764 return
765 if self._RBTN_all_patients.Value is True:
766 self._schedule_data_reget()
767 return
768 pat = gmPerson.gmCurrentPatient()
769 if not pat.connected:
770 return
771 if kwargs['pk_identity'] != pat.ID:
772 return
773 self._schedule_data_reget()
774 #--------------------------------------------------------
778 #--------------------------------------------------------
782 #--------------------------------------------------------
789 #--------------------------------------------------------
813 #--------------------------------------------------------
822 #--------------------------------------------------------
837 #--------------------------------------------------------
838 # internal API
839 #--------------------------------------------------------
841 self._BTN_export_printouts.Enable(False)
842 #--------------------------------------------------------
843 # reget mixin API
844 #--------------------------------------------------------
846 if self._RBTN_all_patients.Value is True:
847 columns = [_('Patient'), _('Provider'), _('Description')]
848 printouts = gmExportArea.get_print_jobs(order_by = 'pk_identity, description')
849 items = [[
850 '%s, %s (%s)' % (
851 p['lastnames'],
852 p['firstnames'],
853 p['gender']
854 ),
855 p['created_by'],
856 p['description']
857 ] for p in printouts ]
858 else:
859 pat = gmPerson.gmCurrentPatient()
860 if pat.connected:
861 columns = [_('Provider'), _('Created'), _('Description')]
862 printouts = pat.export_area.get_printouts(order_by = 'created_when, description')
863 items = [[
864 p['created_by'],
865 gmDateTime.pydt_strftime(p['created_when'], '%Y %b %d %H:%M'),
866 p['description']
867 ] for p in printouts ]
868 else:
869 columns = [_('Patient'), _('Provider'), _('Description')]
870 printouts = gmExportArea.get_print_jobs(order_by = 'pk_identity, description')
871 items = [[
872 '%s, %s (%s)' % (
873 p['lastnames'],
874 p['firstnames'],
875 p['gender']
876 ),
877 p['created_by'],
878 p['description']
879 ] for p in printouts ]
880 self._LCTRL_printouts.set_columns(columns)
881 self._LCTRL_printouts.set_string_items(items)
882 self._LCTRL_printouts.set_column_widths([wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE])
883 self._LCTRL_printouts.set_data(printouts)
884 self._LCTRL_printouts.SetFocus()
885 return True
886
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Sun Aug 19 01:55:20 2018 | http://epydoc.sourceforge.net |