File: gmPregWidgets.py

package info (click to toggle)
gnumed-client 1.8.23%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 36,536 kB
  • sloc: python: 127,070; javascript: 6,113; sh: 1,195; xml: 36; makefile: 33
file content (621 lines) | stat: -rw-r--r-- 21,792 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
"""GNUmed pregnancy related dates widgets.
"""
#====================================================================
__author__ = "M. Bonert, R. Terry, I. Haywood, K.Hilbert"
__licence__ = "GPL v2 or later"


import sys
import datetime as pydt


import wx


from Gnumed.pycommon import gmDateTime
from Gnumed.pycommon import gmTools
from Gnumed.business import gmClinicalCalculator
from Gnumed.wxpython import gmGuiHelpers

#====================================================================
def calculate_edc(parent=None, patient=None):

	if parent is None:
		parent = wx.GetApp().GetTopWindow()

	dlg = cEdcCalculatorDlg(parent, -1)
	prev_edc = None
	if patient.connected:
		prev_edc = patient.emr.EDC
		dlg.patient = patient
		dlg.EDC = prev_edc
	action = dlg.ShowModal()
	new_edc = dlg.EDC
	dlg.DestroyLater()

	# cancelled ?
	if action != wx.ID_SAVE:
		return

	# but have we got a patient ?
	if not patient.connected:
		return

	# ignore setting EDC from NULL to NULL
	if (new_edc is None) and (prev_edc is None):
		return

	# setting from X to NULL -> is a deletion intended ?
	# (prev_edc MUST be not None due to the previous condition)
	if new_edc is None:
		delete_edc = gmGuiHelpers.gm_show_question (
			title = _('Editing EDC'),
			question = _(
				'Really delete the EDC documented previously ?\n'
				'\n'
				' EDC: %s'
			) % gmDateTime.pydt_strftime(prev_edc, '%Y %b %d'),
			cancel_button = False
		)
		if not delete_edc:
			return

	patient.emr.EDC = new_edc

#====================================================================
from Gnumed.wxGladeWidgets import wxgEdcCalculatorDlg

class cEdcCalculatorDlg(wxgEdcCalculatorDlg.wxgEdcCalculatorDlg):

	def __init__(self, *args, **kwds):
		wxgEdcCalculatorDlg.wxgEdcCalculatorDlg.__init__(self, *args, **kwds)
		self.__calc = gmClinicalCalculator.cClinicalCalculator()
		self.__init_ui()
	#----------------------------------------------------------------
	def __init_ui(self):
		edc = self.__calc.get_EDC(lmp = None, nullipara = self._CHBOX_first_pregnancy.GetValue())
		txt = _(
			'Algorithm: %s\n'
			'\n'
			'Source: %s'
		) % (
			edc.formula_name,
			edc.formula_source
		)
		self._TCTRL_algo.SetValue(txt)
		self._PRW_lmp.add_callback_on_selection(self._on_lmp_selected)
		self._PRW_edc.add_callback_on_modified(self._on_edc_modified)

		self._PRW_lmp.SetFocus()
	#----------------------------------------------------------------
	def _on_lmp_selected(self, data):
		self.__recalculate()
	#----------------------------------------------------------------
	def _on_edc_modified(self):
		self._PRW_lmp.SetData(None)
		self._TCTRL_details.SetValue('')
	#----------------------------------------------------------------
	def _on_first_pregnancy_toggled(self, event):
		event.Skip()
		self.__recalculate()
	#----------------------------------------------------------------
	def _on_lmp_picked_in_calendar(self, event):
		event.Skip()
		self._PRW_lmp.SetData(gmDateTime.wxDate2py_dt(wxDate = self._CALCTRL.Date))
		self.__recalculate()
	#----------------------------------------------------------------
	def _on_save_button_pressed(self, event):
		event.Skip()
		if self.__calc.patient is None:
			return False
		if self._PRW_edc.is_valid_timestamp(empty_is_valid = True):
			self.EndModal(wx.ID_SAVE)
			return True
		return False
	#----------------------------------------------------------------
	def __recalculate(self):
		lmp = self._PRW_lmp.date
		if lmp is None:
			self._PRW_edc.SetData(None)
			self._TCTRL_details.SetValue('')
			return

		edc = self.__calc.get_EDC(lmp = lmp, nullipara = self._CHBOX_first_pregnancy.GetValue())

		self._PRW_edc.SetData(edc.numeric_value)
		details = ''
		now = gmDateTime.pydt_now_here()
		# Beulah Hunter, 375 days (http://www.reference.com/motif/health/longest-human-pregnancy-on-record)
		if (lmp < now) and (edc.numeric_value > (now + pydt.timedelta(days = 380))):
			age = now - lmp
			weeks, days = divmod(age.days, 7)
			week = weeks
			if days > 0:
				week = weeks + 1
			month, tmp = divmod(age.days, 28)
			if days > 0:
				month += 1
			details += _(
				'Current age of pregnancy (%s):\n'
				' day %s = %s weeks %s days = week %s = month %s\n\n'
			) % (
				gmDateTime.pydt_strftime(now, '%Y %b %d'),
				age.days,
				int(weeks),
				int(days),
				week,
				month
			)

		details += edc.format (
			left_margin = 1,
			width = 50,
			with_formula = False,
			with_warnings = True,
			with_variables = True,
			with_sub_results = True,
			return_list = False
		)
		self._TCTRL_details.SetValue(details)
	#----------------------------------------------------------------
	# properties
	#----------------------------------------------------------------
	def _get_EDC(self):
		return self._PRW_edc.date

	def _set_EDC(self, edc):
		self._PRW_edc.SetData(edc)
		self._PRW_lmp.SetData(None)
		self._TCTRL_details.SetValue('')

	EDC = property(_get_EDC, _set_EDC)
	#----------------------------------------------------------------
	def _set_patient(self, patient):
		self.__calc.patient = patient

	patient = property(lambda x:x, _set_patient)

#====================================================================
#====================================================================
# old code
#====================================================================
#====================================================================
#====================================================================
import math, zlib, random, string, os.path


import wx.lib.rcsizer

"""
Calculates from LMP:
 - EDC
 - 18th week ultrasound scan

Naegele's rule is easy for manual calculation, but a pain to code
Enter Haywood's rule ;-), human gestation is defined as 24192000 seconds.
(Ian, can you please explain a bit more ?)

TODO:
ideally, tool should query backend for parity, race, etc. for exact measurement
"""


LMP_FIELD = 0
US_FIELD = 1

ID_LMP = wx.NewId()
ID_DUE = wx.NewId()
ID_DAY = wx.NewId()
ID_WEEK = wx.NewId()
ID_MENU = wx.NewId()

GESTATION = 24192000
WEEK = 604800
DAY = 86400
US18_52 = 10886400	# 18 weeks in seconds (for 18/52 Ultrasound)

#====================================================================
class cPregCalcFrame (wx.Frame):
	"""
	The new pregnancy calculator.
	"""

	#TODO
	# IMPROVE removal of time from txt_lmp, txtedc, txtdue (?)
	#	see: def PurgeTime(self, date):
	#
	# explore idea of 'status bar' across bottom -- something to make
	# 	clear how to use the calculator
	#
	# change the set-up of the RowColSizer(), shrink the size of the 'Weeks' & 'Days' fields
	#	make column on right side of preg. calc. more compact
	#
	# clean-up the names of the variables (some could be named more descriptively)
	#
	# add ability to type in LMP and Scan Date with keyboard (as opposed to only clicking on calendar)
	#	make movement between fields possible with 'tab' & 'enter'

	def __init__ (self, parent):
		myStyle = wx.MINIMIZE_BOX | wx.CAPTION | wx.ALIGN_CENTER | \
			wx.ALIGN_CENTER_VERTICAL | wx.TAB_TRAVERSAL | wx.STAY_ON_TOP
		wx.Frame.__init__(self, parent, -1, _("Pregnancy Calculator"), style=myStyle)

		# initialization of variables used in the control & calculation
		self.xfer_cal_date_to=LMP_FIELD	# controls which variable (LMP or Ultrasound) a calendar event changes
					# (if == 0): {calendar selection modifies LMP}
					# (if == 1): {calendar selection modifies Ultrasound Date}

		self.ustxt=wx.DateTime_Today()	# avoids problem - one would have if the user clicked on
						# ultrasound date
						# BONUS: makes the preg. calculator useful for EDC calcs given
						# 	a date and the gestation time

		# get icon
		if __name__ == '__main__':
			png_fname = os.path.join('..', 'bitmaps', 'preg_calculator.png')
		else:
			from Gnumed.pycommon import gmGuiBroker
			gb = gmGuiBroker.GuiBroker()
			png_fname = os.path.join(gb['gnumed_dir'], 'bitmaps', 'preg_calculator.png')
		icon = wx.Icon()
		icon.LoadFile(png_fname, wx.BITMAP_TYPE_PNG)
		self.SetIcon(icon)

		szr_rc = wx.lib.rcsizer.RowColSizer()

		#------------------------------
		# sizer holding the 'LMP' stuff
		#------------------------------
		label = wx.StaticText(self,-1,_("LMP"),size = (50,20))	#label Lmp
		label.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL,wx.NORMAL,False,''))
		label.SetForegroundColour(wx.Colour(0,0,0))

		self.txt_lmp = wx.TextCtrl(self,-1,"",size=(100,20))  	# text for lmp
		self.txt_lmp.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL,wx.NORMAL,False,''))
		self.txt_lmp.SetToolTip(wx.ToolTip(_("Click on calendar to enter the last menstrual period date")))
		tiplmp=self.txt_lmp.GetToolTip()

		szr_row1 = wx.BoxSizer(wx.HORIZONTAL)
		szr_row1.Add(self.txt_lmp,1,wx.EXPAND|wx.ALL,2)
		wx.EVT_SET_FOCUS(self.txt_lmp, self.OnSetFocus_lmp)

		szr_lmp = wx.BoxSizer(wx.HORIZONTAL)
		szr_lmp.Add(label, 1, 0, 0)
		szr_lmp.Add((10,1),0,0)
		szr_rc.Add(szr_lmp, flag=wx.EXPAND, row=0, col=1)
		szr_rc.Add(szr_row1, flag=wx.EXPAND, row=0, col=2, colspan=5)
		#------------------------------
		# sizer holding the 'Gest.' stuff
		#------------------------------
		label = wx.StaticText(self,-1,_("Gest."),size = (50,20))
		label.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL,wx.NORMAL,False,''))
		label.SetForegroundColour(wx.Colour(0,0,0))

		self.txtgest = wx.TextCtrl(self,-1,"",size=(100,20))
		self.txtgest.Enable(False)
		self.txtgest.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL,wx.NORMAL,False,''))
		self.txtgest_szr  = wx.BoxSizer(wx.HORIZONTAL)
		self.txtgest_szr.Add(self.txtgest,1,wx.EXPAND|wx.ALL,2)

		szr_gest = wx.BoxSizer(wx.HORIZONTAL)
		szr_gest.Add(label, 1, 0, 0)
		szr_gest.Add((10,1),0,0)
		szr_rc.Add(szr_gest, flag=wx.EXPAND, row=1, col=1)
		szr_rc.Add(self.txtgest_szr, flag=wx.EXPAND, row=1, col=2, colspan=5)

		#------------------------------
		# sizer holding the 'EDC' stuff
		#------------------------------
		label = wx.StaticText(self,-1,_("EDC"),size = (50,20))
		label.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL,wx.NORMAL,False,''))
		label.SetForegroundColour(wx.Colour(0,0,0))

		self.txtedc = wx.TextCtrl(self,-1,"",size=(100,20))
		self.txtedc.Enable(False)
		self.txtedc.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL,wx.NORMAL,False,''))
		szr_txtedc = wx.BoxSizer(wx.HORIZONTAL)
		szr_txtedc.Add(self.txtedc,1,wx.EXPAND|wx.ALL,2)
		szr_edc = wx.BoxSizer(wx.HORIZONTAL)
		szr_edc.Add(label,1,0,0)
		szr_edc.Add((10,1),0,0)
		szr_rc.Add(szr_edc, flag=wx.EXPAND, row=2, col=1)
		szr_rc.Add(szr_txtedc, flag=wx.EXPAND, row=2, col=2, colspan=5)

		#------------------------------
		# "Ultrasound Scan" label
		#------------------------------
		us_label = wx.StaticText(self,-1,_("18 Week Ultrasound Scan"),size = (200,20))
		us_label.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.BOLD,False,''))
		us_label.SetForegroundColour(wx.Colour(50,50,204))
		szr_backgrnd_18WkScanDue = wx.BoxSizer(wx.VERTICAL)
		szr_backgrnd_18WkScanDue.Add((1,3), 0)
		szr_backgrnd_18WkScanDue.Add(us_label,1,wx.EXPAND,1)
		szr_rc.Add(szr_backgrnd_18WkScanDue, flag=wx.ALIGN_CENTRE_HORIZONTAL, row=3, col=2, colspan=5)
		#------------------------------
		# sizer holding the 'Due' stuff
		#------------------------------
		label = wx.StaticText(self,-1,_("Due"),size = (100,20))
		label.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL,wx.NORMAL,False,''))
		label.SetForegroundColour(wx.Colour(0,0,0))

		self.txtdue = wx.TextCtrl(self,-1,"",size=(100,20))
		self.txtdue.Enable(False)
		self.txtdue.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL,wx.NORMAL,False,''))
		self.szr_txtdue  = wx.BoxSizer(wx.HORIZONTAL)
		self.szr_txtdue.Add(self.txtdue,1,wx.EXPAND|wx.ALL,2)
		szr_due = wx.BoxSizer(wx.HORIZONTAL)
		szr_due.Add(label,1,0,0)
		szr_due.Add((10,1),0,0)
		szr_rc.Add(szr_due, flag=wx.EXPAND, row=4, col=1)
		szr_rc.Add(self.szr_txtdue, flag=wx.EXPAND, row=4, col=2, colspan=5)

		#------------------------------
		# "Ultrasound Scan - Revised EDC" label
		#------------------------------
		rev_edc_label = wx.StaticText(self,-1,_("Ultrasound Scan - Revised EDC"),size = (300,20))
		rev_edc_label.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.BOLD,False,''))
		rev_edc_label.SetForegroundColour(wx.Colour(50,50,204))
		szr_backgrnd_RevEDCLabel = wx.BoxSizer(wx.VERTICAL)
		szr_backgrnd_RevEDCLabel.Add((1,3), 0)
		szr_backgrnd_RevEDCLabel.Add(rev_edc_label,1,wx.EXPAND,1)
		szr_rc.Add(szr_backgrnd_RevEDCLabel, flag=wx.ALIGN_CENTRE_HORIZONTAL, row=5, col=2, colspan=5)

		#------------------------------
		# sizer holding the 'newedc' stuff
		#------------------------------
		label1 = wx.StaticText(self,-1,_("Scan Date"),size = (25,20))
		label1.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL,wx.NORMAL,False,''))
		label1.SetForegroundColour(wx.Colour(0,0,0))
		self.txtdate = wx.TextCtrl(self,-1,"",size=(25,20))
		self.txtdate.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL,wx.NORMAL,False,''))
		self.txtdate.SetToolTip(wx.ToolTip(_("Click on this field and then the ultrasound scan date on the calendar")))
		tipdue=self.txtdate.GetToolTip()
		wx.ToolTip_Enable(1)
		self.szr_txtdate  = wx.BoxSizer(wx.HORIZONTAL)
		self.szr_txtdate.Add(self.txtdate,1,wx.EXPAND|wx.ALL,2)
		wx.EVT_SET_FOCUS(self.txtdate, self.OnSetFocus_USDate)

		szr_label1 = wx.BoxSizer(wx.HORIZONTAL)
		szr_label1.Add(label1,1,0,0)
		szr_label1.Add((10,1),0,0)
		szr_rc.Add(szr_label1, flag=wx.EXPAND, row=6, col=1)
		szr_rc.Add(self.szr_txtdate, flag=wx.EXPAND, row=6, col=2, colspan=5)

		#------------------------------

		label2 = wx.StaticText(self,-1,_("Weeks"),size = (25,20))
		label2.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL,wx.NORMAL,False,''))
		label2.SetForegroundColour(wx.Colour(0,0,0))
		self.txtweeks = wx.SpinCtrl (self, -1, value = "0", min = 0, max = 42)
		wx.EVT_SPINCTRL (self.txtweeks ,self.txtweeks.GetId(), self.EvtText_calcnewedc)
		self.txtweeks.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL,wx.NORMAL,False,''))
		self.szr_txtweeks  = wx.BoxSizer(wx.HORIZONTAL)
		self.szr_txtweeks.Add(self.txtweeks,1,wx.EXPAND|wx.ALL,2)

		label3 = wx.StaticText(self,-1,_("Days"),size = (25,20))
		label3.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL,wx.NORMAL,False,''))
		label3.SetForegroundColour(wx.Colour(0,0,0))
		self.txtdays = wx.SpinCtrl (self, -1, value = "0", min = 0, max = 6)
		wx.EVT_SPINCTRL (self.txtdays ,self.txtdays.GetId(), self.EvtText_calcnewedc)
		self.txtdays.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL,wx.NORMAL,False,''))
		self.szr_txtdays  = wx.BoxSizer(wx.HORIZONTAL)
		self.szr_txtdays.Add(self.txtdays,1,wx.EXPAND|wx.ALL,2)

		szr_label2 = wx.BoxSizer(wx.HORIZONTAL)
		szr_label2.Add(label2,1,wx.ALIGN_CENTRE_VERTICAL,0)
		szr_label2.Add((10,1),0,0)
		szr_label3 = wx.BoxSizer(wx.HORIZONTAL)
		szr_label3.Add((10,1),0,0)
		szr_label3.Add(label3,1,wx.ALIGN_CENTRE_VERTICAL,0)
		szr_label3.Add((10,1),0,0)
		szr_rc.Add(szr_label2, flag=wx.EXPAND, row=7, col=1)
		szr_rc.Add(self.szr_txtweeks, flag=wx.EXPAND, row=7, col=2, colspan=2)
		szr_rc.Add(szr_label3, flag=wx.EXPAND, row=7, col=4)
		szr_rc.Add(self.szr_txtdays, flag=wx.EXPAND, row=7, col=5, colspan=2)

		#------------------------------
		# sizer holding the new (or revised) 'EDC' stuff
		#------------------------------
		label = wx.StaticText(self,-1,_("Rev EDC"),size = (100,20))
		label.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL,wx.NORMAL,False,''))
		label.SetForegroundColour(wx.Colour(0,0,0))

		self.txtnewedc = wx.TextCtrl(self,-1,"",size=(100,20))
		self.txtnewedc.Enable(False)
		self.txtnewedc.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL,wx.NORMAL,False,''))
		self.szr_txtnewedc  = wx.BoxSizer(wx.HORIZONTAL)
		self.szr_txtnewedc.Add(self.txtnewedc,1,wx.EXPAND|wx.ALL,2)
		szr_label=wx.BoxSizer(wx.HORIZONTAL)
		szr_label.Add(label,1,0,0)
		szr_label.Add((10,1),0,0)
		szr_rc.Add(szr_label, flag=wx.EXPAND, row=8, col=1)
		szr_rc.Add(self.szr_txtnewedc, flag=wx.EXPAND, row=8, col=2, colspan=5)
		self.btnPrint = wx.Button(self,1011,_('&Print'))
		self.btnSave = wx.Button(self,1011,_('&Save'))
		szr_buttons = wx.BoxSizer(wx.HORIZONTAL)
		szr_buttons.Add(self.btnPrint,0,wx.EXPAND)
		szr_buttons.Add(self.btnSave,0,wx.EXPAND)
		szr_rc.Add(szr_buttons, flag=wx.EXPAND,row=9, col=3, colspan=4)
		#------------------------------
		# Sizer holding stuff on the right
		#------------------------------
		szr_main_rt = wx.BoxSizer(wx.VERTICAL)
		szr_main_rt.Add(szr_rc)
		wx.EVT_BUTTON(self,1010,self.EvtReset)
		wx.EVT_BUTTON(self,1011,self.EvtPrint)
		wx.EVT_BUTTON(self,1012,self.EvtSave)
		#------------------------------
		# Add calendar (stuff on the left)
		#------------------------------
		self.lmp_cal = wx.calendar.CalendarCtrl (self, ID_LMP,style = wx.RAISED_BORDER)
		wx.calendar.EVT_CALENDAR_SEL_CHANGED(self.lmp_cal, ID_LMP, self.OnCalcByLMP)

		szr_main_lf = wx.BoxSizer(wx.VERTICAL)
		szr_main_lf.Add(self.lmp_cal,0,wx.ALIGN_CENTRE_HORIZONTAL)
		btn_reset = wx.Button(self, 1010, _('&Reset'))
		#szr_main_lf.Add(5,0,5)
		szr_main_lf.Add(btn_reset,0,wx.EXPAND)

		#--------------------------------------
		# Super-sizer holds all the stuff above
		#--------------------------------------
		szr_main_top= wx.BoxSizer(wx.HORIZONTAL)
		szr_main_top.Add(szr_main_lf,0,0)
		szr_main_top.Add((15,0),0,0)
		szr_main_top.Add(szr_main_rt,0,0)
		#szr_main_top.Add(15,1,0,0)

		#------------------------------
		# Put everything together in one big sizer
		#------------------------------
		szr_main= wx.BoxSizer(wx.HORIZONTAL)
		szr_main.Add(szr_main_top,1,wx.EXPAND|wx.ALL,10)
		self.SetSizer (szr_main)
		self.SetAutoLayout (1)
		szr_main.Fit (self)

		wx.EVT_CLOSE (self, self.OnClose )

	#-----------------------------------------
	def OnCalcByLMP (self, event):

		if(self.xfer_cal_date_to==LMP_FIELD):
			# we do this the "UNIX Way" -- all dates are converted into seconds
			# since midnight 1 Jan, 1970.
			# .GetDate().GetTicks() returns time at 5AM.  The -18000 second
			#	correction adjusts LMP to 12AM ??? NOT NEEDED
			#	is it possible there is a BUG in the wxPython
			#	Day Light Savings/Standard Time Calc?

			#LMP = self.lmp_cal.GetDate ().GetTicks () - 18000 	# Standard Time Fix (?)
			self.lmp = self.lmp_cal.GetDate ().GetTicks ()		# Correct for Day Light Saving Time
			today = wx.DateTime_Today().GetTicks()
			due = self.lmp + GESTATION
			gest = today - self.lmp
			self.ultrasound18_52 = self.lmp + US18_52

			# -----------------
			# FIXME: use gmDateInput in gmDateTimeInput.py
			lmp_txt = wx.DateTime()			# FIXME? - change format of date (?)
			lmp_txt.SetTimeT(self.lmp)
			self.txt_lmp.SetValue(self.PurgeTime(lmp_txt))

			# -----------------
			gest_week = gest / WEEK
			gest_day = (gest % WEEK) / DAY
			if(gest_day==1):
				days_label=_('day')
			else:
				days_label=_('days')
			if(gest_week==1):
				weeks_label=_('week')
			else:
				weeks_label=_('weeks')
#			txtgest_str = "%s %s, %s %s" % (gest_week, weeks_label, gest_day, days_label)
			txtgest_str=str(gest_week)+" "+weeks_label+", "+str(gest_day)+" "+days_label
			self.txtgest.SetValue(txtgest_str)

			# -----------------
			edctxt = wx.DateTime()
			edctxt.SetTimeT(due)
			self.txtedc.SetValue(self.PurgeTime(edctxt))

			# -----------------
			self.ustxt = wx.DateTime()
			self.ustxt.SetTimeT(self.ultrasound18_52)
			self.txtdue.SetValue(self.PurgeTime(self.ustxt))

		else:
			# set Ultrasound Date
			self.usdate = self.lmp_cal.GetDate ().GetTicks ()
			usdatetxt = wx.DateTime()	# FIXME? - change format of date
			usdatetxt.SetTimeT(self.usdate)
			self.txtdate.SetValue(self.PurgeTime(usdatetxt))

			# recalculate 'Rev EDC' if Ultrasound Scan Date is changed
			if( self.txtnewedc.GetValue() !=""):
				self.EvtText_calcnewedc(self)

	#-----------------------------------------
	def EvtText_calcnewedc (self, event):
		try:
			weeks=self.txtweeks.GetValue()
			days=self.txtdays.GetValue()

			# get date of ultrasound
			newedc=self.usdate+GESTATION-WEEK*weeks-DAY*days

			wx.D=wx.DateTime()
			wx.D.SetTimeT(newedc)
			self.txtnewedc.SetValue(self.PurgeTime(wx.D))
		except Exception:
			pass	# error handling - FIXME is 'try' statement necessary (?)

	#-----------------------------------------
	def EvtReset(self, event):
		# reset variables
		self.txt_lmp.SetValue("")
		self.txtgest.SetValue("")
		self.txtedc.SetValue("")
		self.txtdue.SetValue("")

		self.txtdate.SetValue("")
		self.ustxt=wx.DateTime_Today()

		self.txtweeks.SetValue(0)			# FIXME - MAKE IT RESET TO BLANK?
		self.txtdays.SetValue(0)
		self.txtnewedc.SetValue("")

		self.xfer_cal_date_to=LMP_FIELD
		self.lmp_cal.SetDate(wx.DateTime_Today())	# reset Calendar to current date

	#-----------------------------------------
	def EvtPrint(self, event):
		pass 					# TODO
	#-----------------------------------------
	def EvtSave(self, event):
		pass 					# TODO
	#-----------------------------------------
	#def EvtHandout(self, event):
	#	pass 					# TODO
	#-------------------------------------------
	def OnClose (self, event):
		self.Destroy ()

	#-------------------------------------------
	def PurgeTime(self, date):			# a not so elegant way of removing the time
		time_loc=string.find(str(date),":00:00")
		date_str=str(date)
		return date_str[:(time_loc-3)]

	#-------------------------------------------
	def OnSetFocus_lmp (self, event):
		self.xfer_cal_date_to=LMP_FIELD
		event.Skip()				# required so wxTextCtrl box is selected

	#-------------------------------------------
	def OnSetFocus_USDate (self, event):
		self.lmp_cal.SetDate(self.ustxt)	# flip calendar to 18/52 date
		self.xfer_cal_date_to=US_FIELD
		event.Skip()



#====================================================================
# Main
#====================================================================
if __name__ == '__main__':
	# set up dummy app
	class TestApp (wx.App):
		def OnInit (self):
			frame = cPregCalcFrame(None)
			frame.Show(1)
			return 1
	#---------------------
	import gettext
	_ = gettext.gettext
	gettext.textdomain ('gnumed')
	app = TestApp()
	app.MainLoop()

#=====================================================================