| Trees | Indices | Help |
|
|---|
|
|
1 """GNUmed patient picture widget."""
2
3 #=====================================================================
4 # $Source: /cvsroot/gnumed/gnumed/gnumed/client/wxpython/gmPatPicWidgets.py,v $
5 # $Id: gmPatPicWidgets.py,v 1.33 2009/09/13 18:45:25 ncq Exp $
6 __version__ = "$Revision: 1.33 $"
7 __author__ = "R.Terry <rterry@gnumed.net>,\
8 I.Haywood <i.haywood@ugrad.unimelb.edu.au>,\
9 K.Hilbert <Karsten.Hilbert@gmx.net>"
10 __license__ = "GPL"
11
12 # standard lib
13 import sys, os, os.path, logging
14
15
16 # 3rd party
17 import wx, wx.lib.imagebrowser
18
19
20 # GNUmed
21 from Gnumed.pycommon import gmDispatcher, gmTools
22 from Gnumed.business import gmMedDoc, gmPerson
23 from Gnumed.wxpython import gmGuiHelpers
24
25
26 _log = logging.getLogger('gm.ui')
27 _log.info(__version__)
28
29 ID_AcquirePhoto = wx.NewId()
30 ID_ImportPhoto = wx.NewId()
31
32 #=====================================================================
34 """A patient picture control ready for display.
35 with popup menu to import/export
36 remove or Acquire from a device
37 """
39
40 # find assets
41 paths = gmTools.gmPaths(app_name = u'gnumed', wx = wx)
42 self.__fallback_pic_name = os.path.join(paths.system_app_data_dir, 'bitmaps', 'empty-face-in-bust.png')
43
44 # load initial dummy bitmap
45 img_data = wx.Image(self.__fallback_pic_name, wx.BITMAP_TYPE_ANY)
46 bmp_data = wx.BitmapFromImage(img_data)
47 del img_data
48 # good default: 50x54
49 self.desired_width = width
50 self.desired_height = height
51 wx.StaticBitmap.__init__(
52 self,
53 parent,
54 id,
55 bmp_data,
56 wx.Point(0, 0),
57 wx.Size(self.desired_width, self.desired_height)
58 )
59
60 self.__pat = gmPerson.gmCurrentPatient()
61
62 # pre-make menu
63 self.__photo_menu = wx.Menu()
64 ID = wx.NewId()
65 self.__photo_menu.Append(ID, _('Refresh from database'))
66 wx.EVT_MENU(self, ID, self._on_refresh_from_backend)
67 self.__photo_menu.AppendSeparator()
68 self.__photo_menu.Append(ID_AcquirePhoto, _("Acquire from imaging device"))
69 self.__photo_menu.Append(ID_ImportPhoto, _("Import from file"))
70
71 self.__register_events()
72 #-----------------------------------------------------------------
73 # event handling
74 #-----------------------------------------------------------------
76 # wxPython events
77 wx.EVT_RIGHT_UP(self, self._on_RightClick_photo)
78
79 wx.EVT_MENU(self, ID_AcquirePhoto, self._on_AcquirePhoto)
80 wx.EVT_MENU(self, ID_ImportPhoto, self._on_ImportPhoto)
81
82 # dispatcher signals
83 gmDispatcher.connect(receiver=self._on_post_patient_selection, signal = u'post_patient_selection')
84 #-----------------------------------------------------------------
86 if not self.__pat.connected:
87 gmDispatcher.send(signal='statustext', msg=_('No active patient.'))
88 return False
89 self.PopupMenu(self.__photo_menu, event.GetPosition())
90 #-----------------------------------------------------------------
93 #-----------------------------------------------------------------
95 """Import an existing photo."""
96
97 # get from file system
98 imp_dlg = wx.lib.imagebrowser.ImageDialog(parent = self, set_dir = os.path.expanduser('~'))
99 imp_dlg.Centre()
100 if imp_dlg.ShowModal() != wx.ID_OK:
101 return
102
103 self.__import_pic_into_db(fname = imp_dlg.GetFile())
104 self.__reload_photo()
105 #-----------------------------------------------------------------
107
108 # get from image source
109 from Gnumed.pycommon import gmScanBackend
110
111 fnames = gmScanBackend.acquire_pages_into_files (
112 delay = 5,
113 tmpdir = os.path.expanduser(os.path.join('~', '.gnumed', 'tmp')),
114 calling_window = self
115 )
116 if fnames is False:
117 gmGuiHelpers.gm_show_error (
118 aMessage = _('Patient photo could not be acquired from source.'),
119 aTitle = _('acquiring photo')
120 )
121 return
122 if len(fnames) == 0: # no pages scanned
123 return
124
125 self.__import_pic_into_db(fname=fnames[0])
126 self.__reload_photo()
127 #-----------------------------------------------------------------
128 # internal API
129 #-----------------------------------------------------------------
131
132 docs = gmMedDoc.search_for_document(patient_id = self.__pat.ID, type_id = gmMedDoc.MUGSHOT)
133 if len(docs) == 0:
134 emr = self.__pat.get_emr()
135 epi = emr.add_episode(episode_name=_('Administration'))
136 enc = emr.active_encounter
137 doc = gmMedDoc.create_document (
138 document_type = gmMedDoc.MUGSHOT,
139 episode = epi['pk_episode'],
140 encounter = enc['pk_encounter']
141 )
142 else:
143 doc = docs[0]
144
145 obj = doc.add_part(file=fname)
146 return True
147 #-----------------------------------------------------------------
149 """(Re)fetch patient picture from DB."""
150
151 doc_folder = self.__pat.get_document_folder()
152 photo = doc_folder.get_latest_mugshot()
153
154 if photo is None:
155 fname = None
156 # gmDispatcher.send(signal='statustext', msg=_('Cannot get most recent patient photo from database.'))
157 else:
158 fname = photo.export_to_file()
159
160 return self.__set_pic_from_file(fname)
161 #-----------------------------------------------------------------
163 if fname is None:
164 fname = self.__fallback_pic_name
165 try:
166 img_data = wx.Image(fname, wx.BITMAP_TYPE_ANY)
167 img_data.Rescale(self.desired_width, self.desired_height)
168 bmp_data = wx.BitmapFromImage(img_data)
169 except:
170 _log.exception('cannot set patient picture from [%s]', fname)
171 gmDispatcher.send(signal='statustext', msg=_('Cannot set patient picture from [%s].') % fname)
172 return False
173 del img_data
174 self.SetBitmap(bmp_data)
175 self.__pic_name = fname
176 return True
177 #-----------------------------------------------------------------
180
181 #====================================================
182 # main
183 #----------------------------------------------------
184 if __name__ == "__main__":
185 app = wx.PyWidgetTester(size = (200, 200))
186 app.SetWidget(cPatientPicture, -1)
187 app.MainLoop()
188 #====================================================
189 # $Log: gmPatPicWidgets.py,v $
190 # Revision 1.33 2009/09/13 18:45:25 ncq
191 # - no more get-active-encounter()
192 #
193 # Revision 1.32 2008/12/09 23:40:50 ncq
194 # - no more patient fk in doc_med
195 #
196 # Revision 1.31 2008/07/10 20:54:17 ncq
197 # - cleanup
198 #
199 # Revision 1.30 2008/07/07 13:43:17 ncq
200 # - current patient .connected
201 #
202 # Revision 1.29 2008/01/30 14:03:42 ncq
203 # - use signal names directly
204 # - switch to std lib logging
205 #
206 # Revision 1.28 2007/09/10 12:37:37 ncq
207 # - don't send signal on not finding patient pic
208 # a) it's quite obvious
209 # b) it might obscure more important messages
210 #
211 # Revision 1.27 2007/08/12 00:12:41 ncq
212 # - no more gmSignals.py
213 #
214 # Revision 1.26 2007/08/07 21:42:40 ncq
215 # - cPaths -> gmPaths
216 #
217 # Revision 1.25 2007/07/22 09:27:48 ncq
218 # - tmp/ now in .gnumed/
219 #
220 # Revision 1.24 2007/05/08 11:16:32 ncq
221 # - need to import gmTools
222 #
223 # Revision 1.23 2007/05/07 12:35:20 ncq
224 # - improve use of gmTools.cPaths()
225 #
226 # Revision 1.22 2007/04/23 01:10:58 ncq
227 # - add menu item to refresh from database
228 #
229 # Revision 1.21 2007/04/11 14:52:47 ncq
230 # - lots of cleanup
231 # - properly implement popup menu actions
232 #
233 # Revision 1.20 2006/12/21 16:54:32 ncq
234 # - inage handlers already inited
235 #
236 # Revision 1.19 2006/11/24 10:01:31 ncq
237 # - gm_beep_statustext() -> gm_statustext()
238 #
239 # Revision 1.18 2006/07/30 18:47:38 ncq
240 # - better comment
241 #
242 # Revision 1.17 2006/05/15 13:36:00 ncq
243 # - signal cleanup:
244 # - activating_patient -> pre_patient_selection
245 # - patient_selected -> post_patient_selection
246 #
247 # Revision 1.16 2006/04/29 19:47:36 ncq
248 # - improve commented out code :-)
249 #
250 # Revision 1.15 2006/01/13 13:52:17 ncq
251 # - create_document_part is gone, make comment on new way
252 #
253 # Revision 1.14 2006/01/01 20:38:03 ncq
254 # - properly use create_document()
255 #
256 # Revision 1.13 2005/09/28 21:27:30 ncq
257 # - a lot of wx2.6-ification
258 #
259 # Revision 1.12 2005/09/28 15:57:48 ncq
260 # - a whole bunch of wx.Foo -> wx.Foo
261 #
262 # Revision 1.11 2005/09/27 20:44:59 ncq
263 # - wx.wx* -> wx.*
264 #
265 # Revision 1.10 2005/09/26 18:01:51 ncq
266 # - use proper way to import wx26 vs wx2.4
267 # - note: THIS WILL BREAK RUNNING THE CLIENT IN SOME PLACES
268 # - time for fixup
269 #
270 # Revision 1.9 2005/08/08 08:07:11 ncq
271 # - cleanup
272 #
273 # Revision 1.8 2005/02/05 10:58:09 ihaywood
274 # fixed patient picture problem (gratutious use of a named parameter)
275 # more rationalisation of loggin in gmCfg
276 #
277 # Revision 1.7 2005/01/31 10:37:26 ncq
278 # - gmPatient.py -> gmPerson.py
279 #
280 # Revision 1.6 2004/10/11 20:18:17 ncq
281 # - GnuMed now sports a patient pic in the top panel
282 # - not loaded when changing patient (rather reverting to empty face)
283 # - use right-click context menu "refresh photo" manually
284 # - only Kirk has a picture so far
285 #
286 # Revision 1.5 2004/09/18 13:54:37 ncq
287 # - improve strings
288 #
289 # Revision 1.4 2004/08/20 13:23:43 ncq
290 # - aquire -> acquire
291 #
292 # Revision 1.3 2004/08/19 14:37:30 ncq
293 # - fix missing import
294 #
295 # Revision 1.2 2004/08/19 14:07:54 ncq
296 # - cleanup
297 # - add tooltip but doesn't work with wx.Bitmap
298 #
299 # Revision 1.1 2004/08/18 10:15:26 ncq
300 # - Richard is improving the patient picture
301 # - added popup menu
302 # - cleanups
303 #
304 # Revision 1.10 2004/06/13 22:31:48 ncq
305 # - gb['main.toolbar'] -> gb['main.top_panel']
306 # - self.internal_name() -> self.__class__.__name__
307 # - remove set_widget_reference()
308 # - cleanup
309 # - fix lazy load in _on_patient_selected()
310 # - fix lazy load in ReceiveFocus()
311 # - use self._widget in self.GetWidget()
312 # - override populate_with_data()
313 # - use gb['main.notebook.raised_plugin']
314 #
315 # Revision 1.9 2004/06/01 07:59:55 ncq
316 # - comments improved
317 #
318 # Revision 1.8 2004/05/28 08:57:08 shilbert
319 # - bugfix for wx.BitmapFromImage()
320 #
321 # Revision 1.7 2004/03/04 19:46:54 ncq
322 # - switch to package based import: from Gnumed.foo import bar
323 #
324 # Revision 1.6 2004/03/03 23:53:22 ihaywood
325 # GUI now supports external IDs,
326 # Demographics GUI now ALPHA (feature-complete w.r.t. version 1.0)
327 # but happy to consider cosmetic changes
328 #
329 # Revision 1.5 2004/03/03 14:53:16 ncq
330 # - comment on optimizing SQL for getting latest photo
331 #
332 # Revision 1.4 2004/03/03 05:24:01 ihaywood
333 # patient photograph support
334 #
335 # Revision 1.3 2003/11/17 10:56:38 sjtan
336 #
337 # synced and commiting.
338 #
339 # Revision 1.1 2003/10/23 06:02:39 sjtan
340 #
341 # manual edit areas modelled after r.terry's specs.
342 #
343 # Revision 1.2 2003/03/29 13:43:30 ncq
344 # - make standalone work, CVS keywords, general cleanup
345 # - change from wx.Panel to wx.StaticBitmap; load PNG, BMP, GIP automagically
346 # - alleviate sizer hell
347 #
348
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Tue Feb 9 04:01:59 2010 | http://epydoc.sourceforge.net |