1
2
3
4 __author__ = "R.Terry <rterry@gnumed.net>, I.Haywood <i.haywood@ugrad.unimelb.edu.au>, K.Hilbert <Karsten.Hilbert@gmx.net>"
5 __license__ = "GPL v2 or later"
6
7
8 import sys, os.path, datetime as pyDT, logging
9
10
11 import wx
12
13
14 from Gnumed.pycommon import gmGuiBroker, gmDispatcher, gmTools, gmCfg2, gmDateTime, gmI18N
15 from Gnumed.business import gmPerson, gmEMRStructItems, gmAllergy
16 from Gnumed.wxpython import gmGuiHelpers
17 from Gnumed.wxpython import gmDemographicsWidgets
18 from Gnumed.wxpython import gmAllergyWidgets
19 from Gnumed.wxpython import gmPatSearchWidgets
20 from Gnumed.wxpython import gmEMRStructWidgets
21 from Gnumed.wxpython import gmPatPicWidgets
22
23
24 _log = logging.getLogger('gm.ui')
25
26
27 from Gnumed.wxGladeWidgets import wxgTopPnl
28
30
41
43 cfg = gmCfg2.gmCfgData()
44 if cfg.get(option = 'slave'):
45 self._TCTRL_patient_selector.SetEditable(0)
46 self._TCTRL_patient_selector.SetToolTip(None)
47
49
50 wx.EVT_LEFT_DCLICK(self._TCTRL_allergies, self._on_allergies_dclicked)
51
52
53 gmDispatcher.connect(signal = u'post_patient_selection', receiver = self._on_post_patient_selection)
54 gmDispatcher.connect(signal = u'allg_mod_db', receiver = self._on_allergies_change)
55 gmDispatcher.connect(signal = u'allg_state_mod_db', receiver = self._on_allergies_change)
56 gmDispatcher.connect(signal = u'name_mod_db', receiver = self._on_name_identity_change)
57 gmDispatcher.connect(signal = u'identity_mod_db', receiver = self._on_name_identity_change)
58 gmDispatcher.connect(signal = u'identity_tag_mod_db', receiver = self._on_tag_change)
59
60 gmDispatcher.connect(signal = u'focus_patient_search', receiver = self._on_focus_patient_search)
61
62
63
71
73 wx.CallAfter(self.__update_tags)
74
76 wx.CallAfter(self.__update_age_label)
77
79
80
81 wx.CallAfter(self.__on_post_patient_selection, **kwargs)
82
84 wx.CallAfter(self.__update_allergies)
85
87 wx.CallAfter(self._TCTRL_patient_selector.SetFocus)
88
89
90
92 self.__update_age_label()
93 self.__update_allergies()
94 self.__update_tags()
95
98
100
101 tt = _('Gender: %s (%s) - %s\n') % (
102 self.curr_pat.gender_symbol,
103 self.curr_pat['gender'],
104 self.curr_pat.gender_string
105 )
106 tt += _('Born: %s\n') % self.curr_pat.get_formatted_dob(format = '%d %b %Y', encoding = gmI18N.get_encoding())
107
108 if self.curr_pat['deceased'] is None:
109
110 if self.curr_pat.get_formatted_dob(format = '%m-%d') == pyDT.datetime.now(tz = gmDateTime.gmCurrentLocalTimezone).strftime('%m-%d'):
111 template = _('%s %s (%s today !)')
112 tt += _("\nToday is the patient's birtday !\n\n")
113 else:
114 template = u'%s %s (%s)'
115
116 tt += _('Age: %s\n') % self.curr_pat['medical_age']
117
118
119
120 age = template % (
121 gmPerson.map_gender2symbol[self.curr_pat['gender']],
122 self.curr_pat.get_formatted_dob(format = '%d %b %Y', encoding = gmI18N.get_encoding()),
123 self.curr_pat['medical_age']
124 )
125
126
127 if self.curr_pat['lastnames'] == u'Leibner':
128 if self.curr_pat['firstnames'] == u'Steffi':
129 if self.curr_pat['preferred'] == u'Wildfang':
130 age = u'%s %s' % (gmTools.u_black_heart, age)
131
132 else:
133
134 tt += _('Died: %s\n') % self.curr_pat['deceased'].strftime('%d.%b %Y').decode(gmI18N.get_encoding())
135 tt += _('At age: %s\n') % self.curr_pat['medical_age']
136
137 template = u'%s %s - %s (%s)'
138 age = template % (
139 gmPerson.map_gender2symbol[self.curr_pat['gender']],
140 self.curr_pat.get_formatted_dob(format = '%d.%b %Y', encoding = gmI18N.get_encoding()),
141 self.curr_pat['deceased'].strftime('%d.%b %Y').decode(gmI18N.get_encoding()),
142 self.curr_pat['medical_age']
143 )
144
145 if self.curr_pat['dob_is_estimated']:
146 tt += _(' (date of birth and age are estimated)\n')
147
148 self._LBL_age.SetLabel(age)
149 self._LBL_age.SetToolTipString(tt)
150
152
153 emr = self.curr_pat.get_emr()
154 state = emr.allergy_state
155
156
157 if state['last_confirmed'] is None:
158 confirmed = _('never')
159 else:
160 confirmed = state['last_confirmed'].strftime('%Y %B %d').decode(gmI18N.get_encoding())
161 tt = (state.state_string + (90 * u' '))[:90] + u'\n'
162 tt += _('last confirmed %s\n') % confirmed
163 tt += gmTools.coalesce(state['comment'], u'', _('Comment (%s): %%s') % state['modified_by'])
164 tt += u'\n'
165
166
167 tmp = []
168 for allergy in emr.get_allergies():
169
170 if allergy['type'] == 'allergy':
171 tmp.append(allergy['descriptor'][:10].strip() + gmTools.u_ellipsis)
172
173 if allergy['definite']:
174 certainty = _('definite')
175 else:
176 certainty = _('suspected')
177 reaction = gmTools.coalesce(allergy['reaction'], _('reaction not recorded'))
178 if len(reaction) > 50:
179 reaction = reaction[:50] + gmTools.u_ellipsis
180 tt += u'%s (%s, %s): %s\n' % (
181 allergy['descriptor'],
182 allergy['l10n_type'],
183 certainty,
184 reaction
185 )
186
187 if len(tmp) == 0:
188 tmp = state.state_symbol
189 else:
190 tmp = ','.join(tmp)
191
192 if state['last_confirmed'] is not None:
193 tmp += state['last_confirmed'].strftime(' (%x)')
194
195 self._TCTRL_allergies.SetValue(tmp)
196 self._TCTRL_allergies.SetToolTipString(tt)
197
198
199 if __name__ == "__main__":
200 wx.InitAllImageHandlers()
201 app = wxPyWidgetTester(size = (400, 200))
202 app.SetWidget(cMainTopPanel, -1)
203 app.SetWidget(cTopPanel, -1)
204 app.MainLoop()
205
206