【本期导读】病历组合查询
病历组合查询这个模块没有遇到什么大的困难,主要是考虑的是怎么实现组合查询这个功能,这里我是使用动态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 以下是组合查询模块截图:
至此,病历管理模块基本功能完成
【下期提示】完成字典维护