【本期導讀】病歷組合查詢
病歷組合查詢這個模塊沒有遇到什么大的困難,主要是考慮的是怎么實現組合查詢這個功能,這里我是使用動態sql的方式,將查詢寫成一個視圖,然后根據組合查詢界面輸入的條件,生成sql,然后執行查詢,返回結果的顯示同“當天登記一覽表”模塊一樣。
組合查詢業務實現方法代碼:

病歷組合查詢
??1
????def?listPatientInfo(self,conditions={'idtype':'',
??2
?????????????????????????????????????????'identityid':'',
??3
?????????????????????????????????????????'patientid':'',
??4
?????????????????????????????????????????'name':'',
??5
?????????????????????????????????????????'sex':'',
??6
?????????????????????????????????????????'birthday':'',
??7
?????????????????????????????????????????'address':'',
??8
?????????????????????????????????????????'age':'',
??9
?????????????????????????????????????????'registrationid':'',
?10
?????????????????????????????????????????'diseases':'',
?11
?????????????????????????????????????????'description':'',
?12
?????????????????????????????????????????'suggestion':'',
?13
?????????????????????????????????????????'start':(),
?14
?????????????????????????????????????????'operator':'',
?15
?????????????????????????????????????????'regtime':(),
?16
?????????????????????????????????????????'meds':''}):
?17
????????"""
?18
????????病歷組合查詢
?19
????????"""
?20
?21
????????sql="""
?22
????????select?distinct?p.registrationid,p.patientid,p.idtype,p.identityid,p.patientname,
?23
????????????????p.birthday,p.sex,p.address,p.description,
?24
????????????????p.start,p.suggestion,p.operatorname,p.time
?25
????????from?v_patientinfo?p
?26
????????where?1=1?
?27
????????"""
?28
????????if?conditions.has_key('idtype'):
?29
????????????if?conditions.get('idtype')<>'':
?30
????????????????sql+="?and?p.idtype='%s'"?%?conditions.get('idtype')
?31
????????????????
?32
????????if?conditions.has_key('identityid'):
?33
????????????if?conditions.get('identityid')<>'':
?34
????????????????sql+="?and?p.identityid='%s'"?%?conditions.get('identityid')
?35
????????????????
?36
????????if?conditions.has_key('patientid'):
?37
????????????if?conditions.get('patientid')<>'':
?38
????????????????sql+="?and?p.patientid='%s'"?%?conditions.get('patientid')
?39
????????????????
?40
????????if?conditions.has_key('name'):
?41
????????????if?conditions.get('name')<>'':
?42
????????????????sql+="?and?p.patientname='%s'"?%?conditions.get('name')
?43
????????????????
?44
????????if?conditions.has_key('sex'):
?45
????????????if?conditions.get('sex')<>'':?????????????
?46
????????????????sql+="?and?p.sex=%s"?%??conditions.get('sex')
?47
????????????????
?48
????????if?conditions.has_key('birthday'):
?49
????????????if?conditions.get('birthday')<>'':
?50
????????????????sql+="?and?p.birthday='%s'"?%?conditions.get('birthday')
?51
????????????????
?52
????????if?conditions.has_key('address'):
?53
????????????if?conditions.get('address')<>'':
?54
????????????????sql+="?and?p.address?like?'%%%s%%'"?%?conditions.get('address')
?55
##TODO:按年齡查詢
?56
##????????if?conditions.has_key('age'):
?57
##????????????if?conditions.get('age')<>'':
?58
##????????????????sql+="?and?p.age='"+conditions.get('age')+"'"
?59
????????if?conditions.has_key('registrationid'):
?60
????????????if?conditions.get('registrationid')<>'':
?61
????????????????sql+="?and?p.registrationid='%s'"?%?conditions.get('registrationid')
?62
?63
????????if?conditions.has_key('diseases'):
?64
????????????if?conditions.get('diseases')<>'':
?65
????????????????sql+="?and?p.diseasetype='%s'"?%?conditions.get('diseases')
?66
????????????????
?67
????????if?conditions.has_key('description'):
?68
????????????if?conditions.get('description')<>'':
?69
????????????????sql+="?and?p.description?like?'%%%s%%'"?%?conditions.get('description')
?70
????????????????
?71
????????if?conditions.has_key('suggestion'):
?72
????????????if?conditions.get('suggestion')<>'':
?73
????????????????sql+="?and?p.suggestion?like?'%%%s%%'"?%?conditions.get('suggestion')
?74
????????????????
?75
????????if?conditions.has_key('start'):
?76
????????????if?conditions.get('start')<>():
?77
????????????????sql+="?and?p.start?between?'%s'?and?'%s'"?%?(conditions.get('start')[0],conditions.get('start')[1])
?78
????????????????
?79
????????if?conditions.has_key('meds'):
?80
????????????if?conditions.get('meds')<>'':
?81
????????????????sql+="?and?p.medname='%s'"?%?conditions.get('meds')
?82
?????????????????
?83
????????if?conditions.has_key('operator'):
?84
????????????if?conditions.get('operator')<>'':
?85
????????????????sql+="?and?p.operatorname='%s'"?%?conditions.get('operator')
?86
????????????????
?87
????????if?conditions.has_key('regtime'):
?88
????????????if?conditions.get('regtime')<>():
?89
????????????????sql+="?and?p.time?between?'%s'?and?'%s'"?%?(conditions.get('regtime')[0],conditions.get('regtime')[1])
?90
?91
????????sql+="?order?by?p.registrationid,p.patientid"????????????????
?92
????????result=self.execute(sql)
?93
?94
????????colname=('掛號','病人編號','證件類型','證件號碼','姓名',
?95
?????????????????'出生日期','性別','居住地址','病癥描述',
?96
?????????????????'生病時間','醫生建議','操作員','登記時間')
?97
????????total=('記錄數:',str(len(result))+"條",'','','','','','','','','','','')
?98
????????result.insert(0,colname)
?99
????????result.append(total)
100
????????return?result以下是組合查詢模塊截圖:



至此,病歷管理模塊基本功能完成
【下期提示】完成字典維護
病歷組合查詢這個模塊沒有遇到什么大的困難,主要是考慮的是怎么實現組合查詢這個功能,這里我是使用動態sql的方式,將查詢寫成一個視圖,然后根據組合查詢界面輸入的條件,生成sql,然后執行查詢,返回結果的顯示同“當天登記一覽表”模塊一樣。
組合查詢業務實現方法代碼:


??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

至此,病歷管理模塊基本功能完成
【下期提示】完成字典維護