【本期导读】
完成病人资料修改模块
终于有空学习python了,五一放了七天假,回家看了看,原来世界每个角落天天都在变化,就连生我养我的那个小村庄也有较大的变化,差点不记得回家的路了。
本以为这个小系统不会耗费太多时间的,可是一路做下来发现实际应用中还是会遇到很多困难的。最新几天看了看病人资料登记的代码,发现不够简洁,结构不太好,于是花了两天时间整理了一下,抽象出一个病案管理的基类,然后登记,修改,查询都继承这个基类,只是这些子类的有些方法需要重写父类方法以便适应不同的业务过程。重构后的病安管理模块代码如下:
病历管理模块
1#!/usr/bin/python
2# -*- coding: UTF-8 -*-
3# $Id: PatientManage.py 39 2006-05-16 09:40:52Z Administrator $
4"""
5病历管理界面
6"""
7import wx
8import wx.lib.scrolledpanel as scroll
9
10import globals
11import MessageService
12import PatientManageService as PMS
13import DictionaryService as DS
14
15class PatientManagePanelBase(scroll.ScrolledPanel):
16 """
17 病历管理基类
18 """
19
20 def __init__(self,parent,editable=True):
21 scroll.ScrolledPanel.__init__(self,parent,wx.ID_ANY)
22 self.SetupScrolling()
23 self.SetAutoLayout(1)
24 self.SetBackgroundColour(self.GetParent().GetBackgroundColour())
25
26 self.dic=DS.DictionaryService()
27 self.pm=PMS.PatientManageService()
28
29 self.ShowBasicInfo()
30 self.ShowDiseaseHistory()
31 self.ShowPrescription()
32 self.ShowControlPanel()
33
34 self.sizer=wx.BoxSizer(wx.VERTICAL)
35 self.sizer.Add(self.patientSizer, 0, wx.TOP|wx.LEFT, 3)
36 self.sizer.Add(self.centersizer, 0, wx.TOP|wx.LEFT, 3)
37 self.sizer.Add(self.controlsizer, 0, wx.TOP|wx.LEFT, 3)
38 self.SetSizer(self.sizer)
39
40 self.SetEditable(editable)
41
42 def controls(self):
43 controls={self.txtName:"患者姓名",
44 self.cbIdType:"证件类型",
45 self.txtId:"证件号码",
46 self.txtAddress:"患者联系地址",
47 self.cbSex:"性别",
48 self.txtDisease:"病症详细信息",
49 self.txtSuggestion:"医生建议"}
50 return controls.items()
51
52 def SetEditable(self,editable=True):
53## self.lblNew.Show(editable)
54 controls=[self.cbIdType,self.txtPatientId,self.txtId,self.txtName,self.cbSex,self.dpcBirthday,self.txtAge,self.txtAddress,
55 self.diseaseType,self.txtDisease,self.dpcStart,self.txtSuggestion,
56 self.meds,
57 self.cbOperator
58 ]
59 for control in controls:
60 control.Enable(editable)
61
62 def InitBasicInfo(self,idType=[],sex=[]):
63 self.idType=idType
64 self.sex=sex
65
66 def ShowBasicInfo(self):
67 """
68 病人基本信息
69 """
70 self.InitBasicInfo()
71
72 #证件类型
73 self.cbIdType = wx.ComboBox(self, wx.ID_ANY,"",(0,0),
74 (80, -1), self.idType,
75 wx.CB_DROPDOWN
76 )
77
78 #证件号码
79 self.txtId=wx.TextCtrl(self, wx.ID_ANY, "", size=(150, -1))
80 #病人编号
81 self.txtPatientId=wx.TextCtrl(self, wx.ID_ANY, "", size=(150, -1))
82 #self.txtPatientId.SetEditable(False)
83 self.lblNew = wx.StaticText(self, wx.ID_ANY, "新")
84 self.lblNew.SetForegroundColour( "Blue" )
85 self.lblNew.SetFont(wx.Font(13, wx.SWISS, wx.NORMAL, wx.BOLD))
86
87 idsSizer = wx.BoxSizer(wx.HORIZONTAL)
88
89 idsSizer.Add(self.cbIdType, 0, wx.TOP|wx.LEFT, 3)
90 idsSizer.Add(self.txtId, 0, wx.TOP|wx.LEFT,3)
91 idsSizer.Add((150,0))
92 idsSizer.Add(self.txtPatientId, 0, wx.TOP|wx.LEFT,3)
93 idsSizer.Add(self.lblNew, 0, wx.TOP|wx.LEFT,3)
94 #姓名
95 lblName = wx.StaticText(self, wx.ID_ANY, "姓名:")
96 self.txtName=wx.TextCtrl(self, wx.ID_ANY, "", size=(100, -1))
97 self.txtId.SetFocus()
98 #性别
99 lblSex = wx.StaticText(self, wx.ID_ANY, "性别:")
100 self.cbSex = wx.ComboBox(self, wx.ID_ANY, "",(0,0),
101 (40, -1), self.sex,
102 wx.CB_DROPDOWN
103 )
104 #出生日期
105 lblBirthday = wx.StaticText(self, wx.ID_ANY, "出生日期:")
106 self.dpcBirthday = wx.DatePickerCtrl(self, size=(120,-1),
107 style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
108 #年龄
109 lblAge = wx.StaticText(self, wx.ID_ANY, "年龄:")
110 self.txtAge=wx.TextCtrl(self, wx.ID_ANY, "", size=(40, -1))
111 self.txtAge.SetEditable(False)
112 lblUnit = wx.StaticText(self, wx.ID_ANY, "周岁")
113 lblUnit.SetFont(wx.Font(13, wx.SWISS, wx.NORMAL, wx.BOLD))
114 #家庭地址
115 lblAddress = wx.StaticText(self, wx.ID_ANY, "家庭地址:")
116 self.txtAddress=wx.TextCtrl(self, wx.ID_ANY, "", size=(475, -1))
117
118 addresssizer=wx.BoxSizer(wx.HORIZONTAL)
119 addresssizer.Add(lblAddress, 0, wx.TOP|wx.LEFT, 3)
120 addresssizer.Add(self.txtAddress, 0, wx.TOP|wx.LEFT, 3)
121
122 infosizer = wx.BoxSizer(wx.HORIZONTAL)
123 infosizer.Add(lblName, 0, wx.TOP|wx.LEFT|wx.ALIGN_CENTER,3)
124 infosizer.Add(self.txtName, 0, wx.TOP|wx.LEFT|wx.ALIGN_CENTER,3)
125 infosizer.Add((10,0))
126 infosizer.Add(lblSex, 0, wx.TOP|wx.LEFT|wx.ALIGN_CENTER, 3)
127 infosizer.Add(self.cbSex, 0, wx.TOP|wx.LEFT|wx.ALIGN_CENTER, 3)
128 infosizer.Add((20,0))
129 infosizer.Add(lblBirthday, 0, wx.TOP|wx.LEFT|wx.ALIGN_CENTER,3)
130 infosizer.Add(self.dpcBirthday, 0, wx.TOP|wx.LEFT|wx.ALIGN_CENTER,3)
131 infosizer.Add(lblAge, 0, wx.TOP|wx.LEFT|wx.ALIGN_CENTER,3)
132 infosizer.Add(self.txtAge, 0, wx.TOP|wx.LEFT|wx.ALIGN_CENTER,3)
133 infosizer.Add(lblUnit, 0, wx.TOP|wx.LEFT|wx.ALIGN_CENTER,3)
134
135 infobox = wx.StaticBox(self, wx.ID_ANY,"病人基本信息")
136 self.patientSizer = wx.StaticBoxSizer(infobox,wx.VERTICAL)
137
138 self.patientSizer.Add(idsSizer, 0, wx.TOP|wx.LEFT, 10)
139 self.patientSizer.Add(infosizer, 0, wx.TOP|wx.LEFT, 10)
140 self.patientSizer.Add(addresssizer, 0, wx.TOP|wx.LEFT, 10)
141
142 self.BindEventBasicInfo()
143
144 def BindEventBasicInfo(self):
145 pass
146
147 def InitDiseaseHistory(self,diseaseList=[]):
148 self.diseaseList=diseaseList
149
150 def ShowDiseaseHistory(self):
151 """
152 病历信息
153 """
154 self.InitDiseaseHistory()
155
156 #挂号
157 lblRegId=wx.StaticText(self, wx.ID_ANY, "挂号:")
158 self.txtRegId=wx.TextCtrl(self, wx.ID_ANY, "", size=(150, -1))
159 #病症列表
160 lblDiseaseType=wx.StaticText(self, wx.ID_ANY, "请选择患病情况:")
161 self.diseaseType = wx.CheckListBox(self, wx.ID_ANY, (80, 50), (150,60), self.diseaseList)
162 #病症描述
163 lblDisease=wx.StaticText(self, wx.ID_ANY, "病症详细描述:")
164 self.txtDisease=wx.TextCtrl(self, wx.ID_ANY, "", size=(200, 60))
165 #病症开始时间
166 lblStart=wx.StaticText(self, wx.ID_ANY, "病症开始时间:")
167 self.dpcStart= wx.DatePickerCtrl(self, size=(120,-1),
168 style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
169 #医生建议
170 lblSuggestion=wx.StaticText(self, wx.ID_ANY, "医生建议:")
171 self.txtSuggestion=wx.TextCtrl(self, wx.ID_ANY, "", size=(200, 60))
172
173 diseasebox = wx.StaticBox(self, wx.ID_ANY,"病历信息")
174 self.diseasesizer = wx.StaticBoxSizer(diseasebox,wx.VERTICAL)
175
176 self.diseasesizer.Add(lblRegId, 0, wx.TOP|wx.LEFT, 3)
177 self.diseasesizer.Add(self.txtRegId, 0, wx.TOP|wx.LEFT, 3)
178 self.diseasesizer.Add(lblDiseaseType, 0, wx.TOP|wx.LEFT, 3)
179 self.diseasesizer.Add(self.diseaseType, 0, wx.TOP|wx.LEFT, 3)
180 self.diseasesizer.Add(lblDisease, 0, wx.TOP|wx.LEFT, 3)
181 self.diseasesizer.Add(self.txtDisease, 0, wx.TOP|wx.LEFT, 3)
182 self.diseasesizer.Add(lblStart, 0, wx.TOP|wx.LEFT, 3)
183 self.diseasesizer.Add(self.dpcStart, 0, wx.TOP|wx.LEFT, 3)
184 self.diseasesizer.Add(lblSuggestion, 0, wx.TOP|wx.LEFT,3)
185 self.diseasesizer.Add(self.txtSuggestion, 0, wx.TOP|wx.LEFT, 3)
186
187 self.BindEventDiseaseHistory()
188
189 def BindEventDiseaseHistory(self):
190 pass
191
192 def InitPrescription(self,medsList=[]):
193 self.medsList=medsList
194
195 def ShowPrescription(self):
196 """
197 处方信息
198 """
199 self.InitPrescription()
200
201 lblmed=wx.StaticText(self, wx.ID_ANY, "【请在使用的药品前打勾】", (45, 15))
202 self.meds = wx.CheckListBox(self, wx.ID_ANY, (80, 50), (150,303), self.medsList)
203 #处方
204 #药品 TODO:支持多条记录,可从库存中选择
205 medicinebox = wx.StaticBox(self, wx.ID_ANY,"处方")
206 medicinesizer = wx.StaticBoxSizer(medicinebox,wx.VERTICAL)
207 medicinesizer.Add(lblmed,0,wx.TOP|wx.LEFT, 3)
208 medicinesizer.Add(self.meds,0,wx.TOP|wx.LEFT, 3)
209
210 self.lblDes=wx.StaticText(self, wx.ID_ANY,"")
211 self.lblDes.SetFont(wx.Font(15, wx.SWISS, wx.NORMAL, wx.BOLD))
212 descsizer= wx.BoxSizer(wx.HORIZONTAL)
213 descsizer.Add(self.lblDes, 0, wx.TOP|wx.LEFT, 3)
214
215 self.centersizer= wx.BoxSizer(wx.HORIZONTAL)
216 self.centersizer.Add(self.diseasesizer, 0, wx.TOP|wx.LEFT, 3)
217 self.centersizer.Add(medicinesizer, 0, wx.TOP|wx.LEFT, 3)
218 self.centersizer.Add(descsizer, 0, wx.TOP|wx.LEFT, 3)
219
220 self.BindEventPrescription()
221
222 def BindEventPrescription(self):
223 pass
224
225 def InitControlPanel(self,operator=[]):
226 self.operator=operator
227
228 def ShowControlPanel(self):
229 """
230 控制面板
231 """
232 self.InitControlPanel()
233
234 #登记人
235 lblOperator = wx.StaticText(self, wx.ID_ANY, "登记人:")
236 self.cbOperator = wx.ComboBox(self, wx.ID_ANY, globals.username,(0,0),
237 (95, -1), self.operator,
238 wx.CB_DROPDOWN)
239 #『登记』按钮
240 self.btnAdd=wx.Button(self, wx.ID_ANY, "登记&A")
241 #『取消』按钮
242 self.btnCancel=wx.Button(self, wx.ID_ANY, "取消&C")
243
244 controlbox = wx.StaticBox(self, wx.ID_ANY,"")
245
246 self.controlsizer = wx.StaticBoxSizer(controlbox,wx.HORIZONTAL)
247 self.controlsizer.Add(lblOperator, 0, wx.TOP|wx.LEFT|wx.ALIGN_CENTER, 3)
248 self.controlsizer.Add(self.cbOperator, 0, wx.TOP|wx.LEFT|wx.ALIGN_CENTER, 3)
249 self.controlsizer.Add((270,0))
250 self.controlsizer.Add(self.btnAdd, 0, wx.TOP|wx.LEFT|wx.ALIGN_CENTER, 3)
251 self.controlsizer.Add(self.btnCancel, 0, wx.TOP|wx.LEFT|wx.ALIGN_CENTER, 3)
252
253 self.BindEventControlPanel()
254
255 def BindEventControlPanel(self):
256 pass
257
258 def OnDpcStartEvtChar(self,event):
259 pass
260
261 def OnTxtSuggestionEvtChar(self,event):
262 pass
263
264 def OnTxtDiseaseEvtChar(self,event):
265 pass
266
267 def OnTxtIdEvtChar(self,event):
268 pass
269
270 def OnTxtNameEvtChar(self,event):
271 pass
272
273 def OnCbSexEvtChar(self,event):
274 pass
275
276 def OnDpcBirthdayEvtChar(self,event):
277 pass
278
279 def OnTxtAddressEvtChar(self,event):
280 pass
281
282 def OnTxtRegIdEvtChar(self,event):
283 pass
284
285 def OnTxtPatientIdEvtChar(self,event):
286 pass
287
288 def EvtBirthdayChange(self,event):
289 pass
290
291 def EvtListBox(self,event):
292 pass
293
294 def EvtCheckListBox(self,event):
295 pass
296
297 def OnBtnAdd(self,event):
298 pass
299
300 def OnBtnCancel(self,event):
301 pass
302
303class PatientManageModifyPanel(PatientManagePanelBase):
304 """
305 病历修改
306 """
307 def __init__(self,parent):
308 PatientManagePanelBase.__init__(self,parent,False)
309 self.btnAdd.SetLabel("修改(&M)")
310 self.txtPatientId.SetEditable(False)
311
312 def InitBasicInfo(self):
313 self.idType=self.pm.listAllIdTypes()
314 self.sex=['男','女']
315
316 def InitDiseaseHistory(self):
317 self.diseaseList=self.dic.listAllAvailableDiseaseTypeName()
318
319 def InitPrescription(self):
320 self.medsList = self.dic.listAllAvailableGoodsName()
321
322 def InitControlPanel(self):
323 self.operator=self.pm.listAllOperatorNames()
324
325 def BindEventDiseaseHistory(self):
326 self.txtRegId.Bind(wx.EVT_CHAR, self.OnTxtRegIdEvtChar)
327 self.txtDisease.Bind(wx.EVT_CHAR, self.OnTxtDiseaseEvtChar)
328 self.dpcStart.Bind(wx.EVT_CHAR, self.OnDpcStartEvtChar)
329 self.txtSuggestion.Bind(wx.EVT_CHAR, self.OnTxtSuggestionEvtChar)
330
331 def BindEventPrescription(self):
332 self.Bind(wx.EVT_LISTBOX, self.EvtListBox,self.meds)
333 self.Bind(wx.EVT_CHECKLISTBOX, self.EvtCheckListBox,self.meds)
334
335 def BindEventControlPanel(self):
336 self.Bind(wx.EVT_BUTTON,self.OnBtnAdd,self.btnAdd)
337 self.Bind(wx.EVT_BUTTON,self.OnBtnCancel,self.btnCancel)
338
339 def OnDpcStartEvtChar(self,event):
340 if event.GetKeyCode()==13:
341 self.txtSuggestion.SetFocus()
342
343 event.Skip()
344
345 def OnTxtSuggestionEvtChar(self,event):
346 if event.GetKeyCode()==13:
347 self.meds.SetFocus()
348 self.meds.SetSelection(0)
349 event.Skip()
350
351 def OnTxtDiseaseEvtChar(self,event):
352 if event.GetKeyCode()==13:
353 self.dpcStart.SetFocus()
354
355 event.Skip()
356
357 def OnBtnAdd(self,event):
358 #print self.GetCheckedMeds()
359 if self.CheckInfo()==False:
360 return
361 else:
362 self.SavePatientInfo()
363
364 def SavePatientInfo(self):
365 """
366 保存信息
367 """
368 prescription=self.GetCheckedMeds()
369 diseases=self.GetCheckedDiseases()
370
371 patientInfo={}
372 patientInfo.__setitem__("idtype",unicode(self.cbIdType.GetValue()).encode('cp936'))
373 patientInfo.__setitem__("identityid",unicode(self.txtId.GetValue()).encode('cp936'))
374 patientInfo.__setitem__("patientid",unicode(self.txtPatientId.GetValue()).encode('cp936'))
375 patientInfo.__setitem__("name",unicode(self.txtName.GetValue()).encode('cp936'))
376 patientInfo.__setitem__("sex",unicode(self.cbSex.GetValue()).encode('cp936'))
377 patientInfo.__setitem__("birthday",unicode(self.dpcBirthday.GetValue().Format('%Y-%m-%d')).encode('cp936'))
378 patientInfo.__setitem__("address",unicode(self.txtAddress.GetValue()).encode('cp936'))
379 patientInfo.__setitem__("description",unicode(self.txtDisease.GetValue()).encode('cp936'))
380 patientInfo.__setitem__("start",unicode(self.dpcStart.GetValue().Format('%Y-%m-%d')).encode('cp936'))
381 patientInfo.__setitem__("suggestion",unicode(self.txtSuggestion.GetValue()).encode('cp936'))
382 patientInfo.__setitem__("operator",unicode(self.cbOperator.GetValue()).encode('cp936'))
383 patientInfo.__setitem__("registrationid",unicode(self.txtRegId.GetValue()).encode('cp936'))
384 patientInfo.__setitem__("diseases",diseases)
385 patientInfo.__setitem__("meds",prescription)
386
387 try:
388 self.pm.updatePatientInfo(patientInfo)
389 MessageService.MessageBox(self,"修改成功!",wx.GetApp().GetAppName())
390 self.ClearUI()
391
392 except Exception,errormsg:
393 MessageService.MessageBox(self,"出错了,详细信息如下:\n"+str(errormsg),wx.GetApp().GetAppName())
394 def OnBtnCancel(self,event):
395 self.ClearUI()
396
397 def CheckInfo(self):
398 for name,value in self.controls():
399 if name.GetValue()=="":
400 MessageService.MessageBox(self,"请输入"+value+"!",wx.GetApp().GetAppName())
401 name.SetFocus()
402 return False
403 else:
404 return True
405
406 def ClearUI(self):
407 for name,value in self.controls():
408 name.SetValue("")
409 self.txtRegId.SetFocus()
410
411 def FillData(self,dic):
412 """
413 填充控件
414 """
415 d=wx.DateTime()
416
417 self.cbIdType.SetValue(dic.get('idtype'))
418 self.txtId.SetValue(dic.get('identityid'))
419 self.txtPatientId.SetValue(dic.get('patientid'))
420 self.txtName.SetValue(dic.get('name'))
421 self.cbSex.SetValue(dic.get('sex'))
422
423 list=dic.get('birthday').split('-')
424 d.Set(int(list[2]),int(list[1])-1,int(list[0]))
425 self.dpcBirthday.SetValue(d)
426
427 self.txtAddress.SetValue(dic.get('address'))
428 self.txtDisease.SetValue(dic.get('description'))
429
430 list=dic.get('start').split('-')
431 d.Set(int(list[2]),int(list[1])-1,int(list[0]))
432 self.dpcStart.SetValue(d)
433
434 self.txtSuggestion.SetValue(dic.get('suggestion'))
435 self.cbOperator.SetValue(dic.get('operator'))
436
437 self.diseaseType.Set(self.diseaseList)
438 for item in dic.get('diseases'):
439## print item
440 for i in self.diseaseList:
441## print i
442 if item==i:
443 self.diseaseType.Check(self.diseaseList.index(i),True)
444
445 self.meds.Set(self.medsList)
446 for item in dic.get('meds'):
447 for i in self.medsList:
448 if item==i:
449 self.meds.Check(self.medsList.index(i),True)
450
451 def OnTxtRegIdEvtChar(self,event):
452 if event.GetKeyCode()==13:
453 try:
454 ##按挂号调出相应信息,返回字典
455 vals=self.pm.getPatientInfo(self.txtRegId.GetValue())
456 self.lblNew.Show(False)
457 self.SetEditable(True)
458 ##填充控件
459 self.FillData(vals)
460
461 except IndexError:
462 MessageService.MessageBox(self,"该挂号没有登记",wx.GetApp().GetAppName())
463 except Exception,msg:
464 MessageService.MessageBox(self,"异常错误,详细信息如下:\n"+str(msg),wx.GetApp().GetAppName())
465
466 event.Skip()
467
468 def EvtListBox(self,event):
469 try:
470 #注意汉字编码
471 self.lblDes.SetLabel(
472 self.dic.getGoodsDescByFName
473 (
474 unicode(event.GetString()).encode('cp936')
475 )
476 )
477 except Exception,msg:
478 self.lblDes="[没有说明]"
479
480 def GetCheckedMeds(self):
481 checked=[]
482 row=()
483 for i in range(0,self.meds.GetCount()):
484 if self.meds.IsChecked(i):
485 row=(
486 unicode(self.txtRegId.GetValue()).encode('cp936'),
487 self.dic.getGoodsIdByFName(unicode(self.meds.GetString(i)).encode('cp936'))
488 )
489 checked.append(row)
490
491 return tuple(checked)
492
493 def GetCheckedDiseases(self):
494 checked=[]
495 row=()
496 for i in range(0,self.diseaseType.GetCount()):
497 if self.diseaseType.IsChecked(i):
498 row=(
499 unicode(self.txtRegId.GetValue()).encode('cp936'),
500 self.dic.getDiseaseTypeIdByName(unicode(self.diseaseType.GetString(i)).encode('cp936'))
501 )
502 checked.append(row)
503 return tuple(checked)
504class PatientManageSearchPanel(PatientManagePanelBase):
505 """
506 病历查询,TODO
507 """
508 def __init__(self,parent):
509 PatientManagePanelBase.__init__(self,parent)
510
511class PatientManageRegPanel(PatientManagePanelBase):
512 """
513 病历登记
514 """
515 def __init__(self,parent):
516 PatientManagePanelBase.__init__(self,parent)
517
518 def InitBasicInfo(self):
519 self.idType=self.pm.listAllIdTypes()
520 self.sex=['男','女']
521
522 def InitDiseaseHistory(self):
523 self.diseaseList=self.dic.listAllAvailableDiseaseTypeName()
524
525 def InitPrescription(self):
526 self.medsList = self.dic.listAllAvailableGoodsName()
527
528 def InitControlPanel(self):
529 self.operator=self.pm.listAllOperatorNames()
530
531 def BindEventBasicInfo(self):
532 self.txtId.Bind(wx.EVT_CHAR, self.OnTxtIdEvtChar)
533 self.txtPatientId.Bind(wx.EVT_CHAR, self.OnTxtPatientIdEvtChar)
534 self.txtName.Bind(wx.EVT_CHAR, self.OnTxtNameEvtChar)
535 self.cbSex.Bind(wx.EVT_CHAR, self.OnCbSexEvtChar)
536 self.dpcBirthday.Bind(wx.EVT_CHAR, self.OnDpcBirthdayEvtChar)
537 self.txtAddress.Bind(wx.EVT_CHAR, self.OnTxtAddressEvtChar)
538 self.Bind(wx.EVT_DATE_CHANGED,self.EvtBirthdayChange,self.dpcBirthday)
539
540 def BindEventDiseaseHistory(self):
541 self.txtRegId.Bind(wx.EVT_CHAR, self.OnTxtRegIdEvtChar)
542 self.txtDisease.Bind(wx.EVT_CHAR, self.OnTxtDiseaseEvtChar)
543 self.dpcStart.Bind(wx.EVT_CHAR, self.OnDpcStartEvtChar)
544 self.txtSuggestion.Bind(wx.EVT_CHAR, self.OnTxtSuggestionEvtChar)
545
546 def BindEventPrescription(self):
547 self.Bind(wx.EVT_LISTBOX, self.EvtListBox,self.meds)
548 self.Bind(wx.EVT_CHECKLISTBOX, self.EvtCheckListBox,self.meds)
549
550 def BindEventControlPanel(self):
551 self.Bind(wx.EVT_BUTTON,self.OnBtnAdd,self.btnAdd)
552 self.Bind(wx.EVT_BUTTON,self.OnBtnCancel,self.btnCancel)
553
554 def OnDpcStartEvtChar(self,event):
555 if event.GetKeyCode()==13:
556 self.txtSuggestion.SetFocus()
557
558 event.Skip()
559
560 def OnTxtSuggestionEvtChar(self,event):
561 if event.GetKeyCode()==13:
562 self.meds.SetFocus()
563 self.meds.SetSelection(0)
564 event.Skip()
565
566 def OnTxtDiseaseEvtChar(self,event):
567 if event.GetKeyCode()==13:
568 self.dpcStart.SetFocus()
569
570 event.Skip()
571
572 def OnTxtIdEvtChar(self,event):
573 if event.GetKeyCode()==13:
574 self.txtPatientId.SetFocus()
575
576 event.Skip()
577
578 def OnTxtNameEvtChar(self,event):
579 if event.GetKeyCode()==13:
580 self.cbSex.SetFocus()
581 event.Skip()
582
583 def OnCbSexEvtChar(self,event):
584 if event.GetKeyCode()==13:
585 self.dpcBirthday.SetFocus()
586 event.Skip()
587
588 def OnDpcBirthdayEvtChar(self,event):
589 if event.GetKeyCode()==13:
590 self.txtAddress.SetFocus()
591 event.Skip()
592
593 def OnTxtAddressEvtChar(self,event):
594 if event.GetKeyCode()==13:
595 self.txtRegId.SetFocus()
596
597 event.Skip()
598
599 def OnTxtRegIdEvtChar(self,event):
600 if event.GetKeyCode()==13:
601 try:
602 self.txtRegId.SetValue(str(self.pm.genRegisterID()))
603 self.txtDisease.SetFocus()
604 except Exception,msg:
605 MessageService.MessageBox(self,"生成失败,详细信息如下:\n"+str(msg),wx.GetApp().GetAppName())
606
607 def OnTxtPatientIdEvtChar(self,event):
608
609 if event.GetKeyCode()==13:
610 try:
611 self.txtPatientId.SetValue(str(self.pm.genPatientID()))
612 self.txtName.SetFocus()
613 except Exception,msg:
614 MessageService.MessageBox(self,"生成失败,详细信息如下:\n"+str(msg),wx.GetApp().GetAppName())
615
616 def EvtBirthdayChange(self,event):
617 self.txtAge.SetValue(str(wx.DateTime.Now()-self.dpcBirthday.GetValue()))
618
619 def EvtListBox(self,event):
620 try:
621 #注意汉字编码
622 self.lblDes.SetLabel(
623 self.dic.getGoodsDescByFName
624 (
625 unicode(event.GetString()).encode('cp936')
626 )
627 )
628 except Exception,msg:
629 self.lblDes="[没有说明]"
630
631 def GetCheckedMeds(self):
632 checked=[]
633 row=()
634 for i in range(0,self.meds.GetCount()):
635 if self.meds.IsChecked(i):
636 row=(
637 unicode(self.txtRegId.GetValue()).encode('cp936'),
638 self.dic.getGoodsIdByFName(unicode(self.meds.GetString(i)).encode('cp936'))
639 )
640 checked.append(row)
641
642 return tuple(checked)
643
644 def GetCheckedDiseases(self):
645 checked=[]
646 row=()
647 for i in range(0,self.diseaseType.GetCount()):
648 if self.diseaseType.IsChecked(i):
649 row=(
650 unicode(self.txtRegId.GetValue()).encode('cp936'),
651 self.dic.getDiseaseTypeIdByName(unicode(self.diseaseType.GetString(i)).encode('cp936'))
652 )
653 checked.append(row)
654 return tuple(checked)
655
656 def OnBtnAdd(self,event):
657 #print self.GetCheckedMeds()
658 if self.CheckInfo()==False:
659 return
660 else:
661 self.SavePatientInfo()
662
663 def SavePatientInfo(self):
664
665 try:
666 #注意汉字编码
667 idtype=self.dic.getIdTypeIdByName(
668 unicode(self.cbIdType.GetValue()).encode('cp936')
669 )
670 except IndexError,msg:
671 MessageService.MessageBox(self,"请选择证件类型!",wx.GetApp().GetAppName())
672 self.cbIdType.SetFocus()
673 return
674 except Exception,errormsg:
675 MessageService.MessageBox(self,"出错了,详细信息如下:\n"+str(msg),wx.GetApp().GetAppName())
676
677 try:
678 #注意汉字编码
679 operator=self.dic.getOperatorIdByName(unicode(self.cbOperator.GetValue()).encode('cp936'))
680 except IndexError,msg:
681 MessageService.MessageBox(self,"选择登记人!",wx.GetApp().GetAppName())
682 self.cbOperator.SetFocus()
683 return
684 except Exception,errormsg:
685 MessageService.MessageBox(self,"出错了,详细信息如下:\n"+str(msg),wx.GetApp().GetAppName())
686
687 if unicode(self.cbSex.GetValue()).encode('cp936')=="男":
688 patientSex=1
689 elif unicode(self.cbSex.GetValue()).encode('cp936')=="女":
690 patientSex=0
691 else:
692 patientSex=None
693
694 basicInfo= (
695 (
696 self.txtPatientId.GetValue(),
697 unicode(self.txtName.GetValue()).encode('cp936'),
698 locals().get('patientSex'),
699 self.dpcBirthday.GetValue().Format('%Y-%m-%d'),
700 locals().get('idtype'),
701 unicode(self.txtId.GetValue()).encode('cp936'),
702 unicode(self.txtAddress.GetValue()).encode('cp936'),
703 locals().get('operator')
704 ),
705 )
706
707 diseaseHistory=(
708 (
709 unicode(self.txtRegId.GetValue()).encode('cp936'),
710 unicode(self.txtPatientId.GetValue()).encode('cp936'),
711 unicode(self.txtDisease.GetValue()).encode('cp936'),
712 self.dpcStart.GetValue().Format('%Y-%m-%d'),
713 unicode(self.txtSuggestion.GetValue()).encode('cp936'),
714 locals().get('operator')
715 ),
716 )
717 prescription=self.GetCheckedMeds()
718 diseases=self.GetCheckedDiseases()
719
720 patientInfo=[basicInfo,diseaseHistory,prescription,diseases]
721
722 try:
723 self.pm.regPatientInfo(patientInfo)
724 MessageService.MessageBox(self,"登记成功!",wx.GetApp().GetAppName())
725 self.ClearUI()
726
727 except Exception,errormsg:
728 MessageService.MessageBox(self,"出错了,详细信息如下:\n"+str(errormsg),wx.GetApp().GetAppName())
729 def OnBtnCancel(self,event):
730 self.ClearUI()
731
732 def CheckInfo(self):
733 for name,value in self.controls():
734 if name.GetValue()=="":
735 MessageService.MessageBox(self,"请输入"+value+"!",wx.GetApp().GetAppName())
736 name.SetFocus()
737 return False
738 else:
739 return True
740
741 def ClearUI(self):
742 for name,value in self.controls():
743 name.SetValue("")
744 self.txtName.SetFocus()
745
746class PatientManageFrame(wx.Frame):
747 def __init__(self,parent):
748 wx.Frame.__init__(self,parent,wx.ID_ANY)
749 panel=PatientManageRegPanel(self)
750
751class LoginApp(wx.App):
752 def __init__(self):
753 import sys
754 wx.App.__init__(self,True,"PatientManager.log")
755 self.SetAppName("test")
756 """
757 测试
758 """
759 def OnInit(self):
760 frame=PatientManageFrame(None)
761 frame.Show()
762 return True
763
764if __name__=='__main__':
765 app=LoginApp()
766 app.MainLoop()
767
768 在做病历管理模块时主要遇到以下几个问题:
1.如何把list转成tuple
2.把日期字符串转成wx.DateTime类型
3.计算两个wx.DateTime类型值之间的相隔年数
第1个问题很简单,只是一开始我不知道,起初一直在找tuple是不是有添加项目的方法,可是没找到,然后又找list是不是有方法转成tuple,又没找到,最后才终于发现原来直接强制转换就可以了,如:
l=[1,3,4]
t=tuple(l)
原来list转为tuple就这么简单。
关于第2个问题,一开始也是在查wxPython的API文档,可是没有查到能直接把日期字符串转成wx.DateTime类型的方法,最后只能先解析日期字符串,然后再用Set方法把这个字符串中的日期信息写入wx.DateTime实例。
现在只剩下第3个问题还没有找到更好的解决办法,还是先留在这里,然后边做边想办法
-----------------------
【下期提示】完成当天登记信息一览