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
61
69
71 wx.CallAfter(self.__update_tags)
72
74 wx.CallAfter(self.__update_age_label)
75
77
78
79 wx.CallAfter(self.__on_post_patient_selection, **kwargs)
80
82 wx.CallAfter(self.__update_allergies)
83
84
85
87 self.__update_age_label()
88 self.__update_allergies()
89 self.__update_tags()
90
93
95
96 tt = _('Gender: %s (%s) - %s\n') % (
97 self.curr_pat.gender_symbol,
98 self.curr_pat['gender'],
99 self.curr_pat.gender_string
100 )
101 tt += _('Born: %s\n') % self.curr_pat.get_formatted_dob(format = '%d %b %Y', encoding = gmI18N.get_encoding())
102
103 if self.curr_pat['deceased'] is None:
104
105 if self.curr_pat.get_formatted_dob(format = '%m-%d') == pyDT.datetime.now(tz = gmDateTime.gmCurrentLocalTimezone).strftime('%m-%d'):
106 template = _('%s %s (%s today !)')
107 tt += _("\nToday is the patient's birtday !\n\n")
108 else:
109 template = u'%s %s (%s)'
110
111 tt += _('Age: %s\n') % self.curr_pat['medical_age']
112
113
114
115 age = template % (
116 gmPerson.map_gender2symbol[self.curr_pat['gender']],
117 self.curr_pat.get_formatted_dob(format = '%d %b %Y', encoding = gmI18N.get_encoding()),
118 self.curr_pat['medical_age']
119 )
120
121
122 if self.curr_pat['lastnames'] == u'Leibner':
123 if self.curr_pat['firstnames'] == u'Steffi':
124 if self.curr_pat['preferred'] == u'Wildfang':
125 age = u'%s %s' % (gmTools.u_black_heart, age)
126
127 else:
128
129 tt += _('Died: %s\n') % self.curr_pat['deceased'].strftime('%d.%b %Y').decode(gmI18N.get_encoding())
130 tt += _('At age: %s\n') % self.curr_pat['medical_age']
131
132 template = u'%s %s - %s (%s)'
133 age = template % (
134 gmPerson.map_gender2symbol[self.curr_pat['gender']],
135 self.curr_pat.get_formatted_dob(format = '%d.%b %Y', encoding = gmI18N.get_encoding()),
136 self.curr_pat['deceased'].strftime('%d.%b %Y').decode(gmI18N.get_encoding()),
137 self.curr_pat['medical_age']
138 )
139
140 if self.curr_pat['dob_is_estimated']:
141 tt += _(' (date of birth and age are estimated)\n')
142
143 self._LBL_age.SetLabel(age)
144 self._LBL_age.SetToolTipString(tt)
145
147
148 emr = self.curr_pat.get_emr()
149 state = emr.allergy_state
150
151
152 if state['last_confirmed'] is None:
153 confirmed = _('never')
154 else:
155 confirmed = state['last_confirmed'].strftime('%Y %B %d').decode(gmI18N.get_encoding())
156 tt = (state.state_string + (90 * u' '))[:90] + u'\n'
157 tt += _('last confirmed %s\n') % confirmed
158 tt += gmTools.coalesce(state['comment'], u'', _('Comment (%s): %%s') % state['modified_by'])
159 tt += u'\n'
160
161
162 tmp = []
163 for allergy in emr.get_allergies():
164
165 if allergy['type'] == 'allergy':
166 tmp.append(allergy['descriptor'][:10].strip() + gmTools.u_ellipsis)
167
168 if allergy['definite']:
169 certainty = _('definite')
170 else:
171 certainty = _('suspected')
172 reaction = gmTools.coalesce(allergy['reaction'], _('reaction not recorded'))
173 if len(reaction) > 50:
174 reaction = reaction[:50] + gmTools.u_ellipsis
175 tt += u'%s (%s, %s): %s\n' % (
176 allergy['descriptor'],
177 allergy['l10n_type'],
178 certainty,
179 reaction
180 )
181
182 if len(tmp) == 0:
183 tmp = state.state_symbol
184 else:
185 tmp = ','.join(tmp)
186
187 if state['last_confirmed'] is not None:
188 tmp += state['last_confirmed'].strftime(' (%x)')
189
190 self._TCTRL_allergies.SetValue(tmp)
191 self._TCTRL_allergies.SetToolTipString(tt)
192
193
194 if __name__ == "__main__":
195 wx.InitAllImageHandlers()
196 app = wxPyWidgetTester(size = (400, 200))
197 app.SetWidget(cMainTopPanel, -1)
198 app.SetWidget(cTopPanel, -1)
199 app.MainLoop()
200
201