当前位置:文档之家› 分享获取医嘱组号的函数FUN_GET_CHAR

分享获取医嘱组号的函数FUN_GET_CHAR

每周一点医疗知识5:分享获取医嘱组号的函数FUN_GET_CHAR
大家好!
本期分享获取医嘱组号的函数FUN_GET_CHAR。

可能部分同事已经收到过之前分享的组合SQL,现加以改进,在查询met_ipm_order,MET_IPM_EXECDRUG,PHA_Com_ApplyOut三个表时可以通过本文分享的函数FUN_GET_CHAR取到医嘱组合符号,进而为大家在相关报表设计时省了很多前台代码量。
在此也呼吁大家都积极的分享一下好的东西,让大家都能很快的进步,让我们的整体作战能力快速提升。同时如果有什么疑难的问题可以发出来大家一起探讨。
一、使用实例:FUN_GET_CHAR(2,A.EXEC_SQN,'L')
二、效果预览:

三、函数FUN_GET_CHAR:
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
CREATE OR REPLACE FUNCTION "FUN_GET_CHAR"(par_table integer,
par_SEQ kyhis.met_ipm_order.mo_order%type,
par_flag varchar2)
return varchar2 is
/*-------------------------------------------------------------------------
|| 函数名称 获取医嘱组的符号
|| 功能描述 :可以查kyhis.met_ipm_order,kyhis.MET_IPM_EXECDRUG,kyhis.PHA_Com_ApplyOut
|| 减少前台代码量
|| 参数描述 :
|| par_table 传1表示直接查的医嘱表,传2可以是药品医嘱执行档或领药单表,暂不支持非药品医嘱执行档
|| par_SEQ 传1时请传mo_order,传2时请传Exec_Sqn
|| par_flag 'L','R',放左边还是放右边,执行下面的例子就知道了
|| 返回: 字符型 组的符号或''
||-------------------------------------------------------------------------
|| 作 者 :成忠祝 完成日期 :2013-04
|| 备注 :
||-------------------------------------------------------------------------*/
/*
例1:(kyhis.met_ipm_order)
select FUN_GET_CHAR(1,a.mo_order,'L') L,FUN_GET_CHAR(1,a.mo_order,'R') R,a.*
from kyhis.met_ipm_order a
where a.inpatient_no = 'ZY010*********'
order by https://www.doczj.com/doc/7c11153442.html,b_no,a.mo_order
记得排序一定是https://www.doczj.com/doc/7c11153442.html,b_no, a.mo_order
例2:(kyhis.MET_IPM_EXECDRUG)
select FUN_GET_CHAR(2,A.Exec_Sqn, 'L') L,FUN_GET_CHAR(2,A.Exec_Sqn, 'R') R,
https://www.doczj.com/doc/7c11153442.html,E_TIME,https://www.doczj.com/doc/7c11153442.html,b_no, A.MO_ORDER,
a.*
from kyhis.MET_IPM_EXECDRUG a
where A.INPATIENT_NO = 'ZY010*********'
order by https://www.doczj.com/doc/7c11153442.html,E_TIME,https://www.doczj.com/doc/7c11153442.html,b_no, A.MO_ORDER
记得排序
例3:(kyhis.PHA_Com_ApplyOut)
select FUN_GET_CHAR(2,A.EXEC_SQN,'L') L,FUN_GET_CHAR(2,A.EXEC_SQN,'R') R,a.*
from kyhis.PHA_Com_ApplyOut a,kyhis.MET_IPM_EXECDRUG c
where A.PATIENT_ID =

'ZY010*********'
and a.exec_sqn = c.exec_sqn(+)
order by https://www.doczj.com/doc/7c11153442.html,e_time,https://www.doczj.com/doc/7c11153442.html,B_NO,A.MO_ORDER
记得排序https://www.doczj.com/doc/7c11153442.html,e_time,https://www.doczj.com/doc/7c11153442.html,B_NO,A.MO_ORDER,没有https://www.doczj.com/doc/7c11153442.html,e_time排不准
--*/
Str_Cnt Integer;
Str_ID varchar2(20);
Str_Min_Order kyhis.met_ipm_order.mo_order%type;
Str_Max_Order kyhis.met_ipm_order.mo_order%type;
Str_Usetime date;
Str_Moorder kyhis.met_ipm_order.mo_order%type;
Str_PID kyhis.met_ipm_order.Inpatient_No%type;
Str_Comb_no kyhis.met_ipm_https://www.doczj.com/doc/7c11153442.html,b_no%type;
Result varchar2(2);
begin
Str_ID := par_SEQ;--先收下传入的东西
if par_table = 1 then--传1表示直接查的医嘱表
select count(1), min(b.mo_order), max(b.mo_order)
into Str_Cnt, Str_Min_Order, Str_Max_Order
from kyhis.met_ipm_order b
where https://www.doczj.com/doc/7c11153442.html,b_no = (select https://www.doczj.com/doc/7c11153442.html,b_no
from kyhis.met_ipm_order a
where a.mo_order = Str_ID); --kyhis.met_ipm_https://www.doczj.com/doc/7c11153442.html,b_no,kyhis.met_ipm_order.mo_order分别是单独的索引

end if;
if par_table = 2 then--传2可以是药品医嘱执行档或领药单表,暂不支持非药品医嘱执行档
--可以查kyhis.MET_IPM_EXECDRUG,kyhis.PHA_Com_ApplyOut
select https://www.doczj.com/doc/7c11153442.html,e_time,https://www.doczj.com/doc/7c11153442.html,b_no,c.mo_order,c.inpatient_no
into Str_Usetime,Str_Comb_no,Str_Moorder,Str_PID
from kyhis.MET_IPM_EXECDRUG c where c.exec_sqn = Str_ID;
select count(1), min(b.mo_order), max(b.mo_order)
into Str_Cnt, Str_Min_Order, Str_Max_Order
from kyhis.MET_IPM_EXECDRUG b
where b.inpatient_no = Str_PID
and https://www.doczj.com/doc/7c11153442.html,e_time = Str_Usetime
and https://www.doczj.com/doc/7c11153442.html,b_no = Str_Comb_no; --kyhis.MET_IPM_https://www.doczj.com/doc/7c11153442.html,e_time,kyhis.MET_IPM_https://www.doczj.com/doc/7c11153442.html,b_no的索引
Str_ID := Str_Moorder;
end if;
If Str_Cnt > 1 Then
if Str_ID = Str_Min_Order then
if par_flag = 'L' then
Result := '┏';
else
Result := '┓';
end if;
else
if Str_ID = Str_Max_Order then
if par_flag = 'L' then
Result := '┗';
else
Result := '┛';
end if;
else
Result := '┃';
end if;
end if;
else
Result := '';
end if;

return(Result);
end FUN_GET_CHAR;



每周一点医疗知识4:一步报表SQL中在指定位置插入自定义内容
大家好!
本期分享一步报表SQL中在指定位置插入自定义内容:
一、需求


其实用各种报表工具设计这个需求大家应该都没问题,但用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
select *
from (select '' 序号,

'' 日期,
'云南省肿瘤医院药品入库总表' 供应商,
'' 仓库,
'' 类别,
'' 购入金额,
1 rn --放第1行
from dual a
union all
select to_char(to_date('2013-03-01 00:00:00',
'yyyy-mm-dd hh24:mi:ss'),
'"日期:"yyyy"年"MM"月"dd"日 至 "') ||
to_char(to_date('2013-04-11 06:59:59',
'yyyy-mm-dd hh24:mi:ss'),
'yyyy"年"MM"月"dd"日"') 序号, --这个一定要学会,我们在网上没有搜索到这个最简的方法,感谢邱光琳提供
'' 日期,
'' 供应商,
'' 仓库,
'' 类别,
'页码:1/2' 购入金额,
2 rn --放第2行
from dual a
union all
select '序号' 序号,
'日期' 日期,
'供应商' 供应商,
'仓库' 仓库,
'类别' 类别,
'购入金额' 购入金额,
3 rn --放第3行
from dual a
union all
select '打印人:' 序号,
'' 日期,
'打印日期:' 供应商,
'' 仓库,
'' 类别,
'' 购入金额,
999999 rn --再大点也可以,保证排在最后就行
from dual a
union all
select 序号,
日期,
供应商,
仓库,
类别,
to_char(购入金额),
rownum * 10 rn --增加一列顺序号,固定现在的排序,乘以10(100也可以,有木有?)是为了在每两行之间空出10行了,这样明白了吧,就是要在任何位置留点空间插入我们的数据
from (select decode(日期,
'',
decode(供应商, '', '总计', '小计'),
ROW_NUMBER() OVER(PARTITION BY 供应商 ORDER BY 供应商,
仓库,
类别,
日期)) 序号,
日期,
供应商,
仓库,
类别,
购入金额
from (select to_char(trunc(a.in_date), 'yyyy-mm-dd') 日期,
fun_get_company_name(https://www.doczj.com/doc/7c11153442.html,pany_code) 供应商,
fun_get_dept_name(a.drug_dept_code) 仓库,
a.drug_type 类别,
sum(a.purchase_cost) 购入金额
from pha_com_input a
where a.i

n_date between
to_date('2013-03-01 00:00:00',
'yyyy-mm-dd hh24:mi:ss') and
to_date('2013-04-11 06:59:59',
'yyyy-mm-dd hh24:mi:ss')
and length(https://www.doczj.com/doc/7c11153442.html,pany_code) > 4
group by rollup(https://www.doczj.com/doc/7c11153442.html,pany_code,
a.drug_dept_code,
a.drug_type,
a.in_date))
where ((日期 is not null) or (日期 is null and 供应商 is null) or
(日期 is null and 供应商 is not null and 仓库 is null and
类别 is null))))
order by rn
三、结果预览


回顾前面3期的内容,我已经做到让你复制粘贴就可以看到结果了,这样都不掌握就是你绝对的损失了。




每周一点医疗知识3:一步报表、快速SQL、优化索引
大家好!
本周提供三点知识分享:
一、续上期疑问
1、如何做到相同的科室名只留一行科室
请执行下面的SQL,不管你信不信,反正我信了,以“科室”作为分区来处理,用到ROW_NUMBER() OVER,每个分区会从1开始计算“小序号”,为了让大家学习实现过程,我已分两层(红色、蓝色)。
SQL:
select decode(小序,1,科室,'') 科室,项目,金额,rownum,小序
from
(
select 科室,项目,金额,rownum,
ROW_NUMBER() OVER(PARTITION BY 科室 ORDER BY rownum desc,科室) 小序
from
(
select *
from
(
select 科室,decode(科室,'','总计',nvl(项目,'小计')) 项目,金额,rownum
from
(
select fun_get_dept_name(a.recipe_deptcode) 科室, a.item_name 项目, sum(a.tot_cost) 金额
from fin_ipb_itemlist a
where a.fee_date between
to_date('2013-03-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and
to_date('2013-03-01 06:59:59', 'yyyy-mm-dd hh24:mi:ss')
group by rollup(a.recipe_deptcode, a.item_name)
)
)
order by rownum desc
)
)
结果预览:



2、用SQL实现下图所示报表

看到上面的结果,我想这个报表需求应该会了吧!至于表头,页尾,大家学习过前面的应该可以自己弄进去的,提示:select 'XXX报表' from dual union all
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
select decode(日期,
'',
decode(供应商, '', '总计', '小计'),
ROW_NUMBER()
OVER(PARTITION BY 供应商 ORDER BY 供应商, 仓库, 类别, 日期)) 序号,
日期,
供应商,
仓库,
类别,
购入金额
from (select to_char(trunc(a.in_date), 'yyyy-mm-dd') 日期,
fun_get_company_name(https://www.doczj.com/doc/7c11153442.html,pany_code) 供应商,
fun_get_dept_name(a.drug_dept_code) 仓库,
a.drug_type

类别,
sum(a.purchase_cost) 购入金额
from pha_com_input a
where a.in_date between
to_date('2013-03-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and
to_date('2013-04-11 06:59:59', 'yyyy-mm-dd hh24:mi:ss')
and length(https://www.doczj.com/doc/7c11153442.html,pany_code) > 4
group by rollup(https://www.doczj.com/doc/7c11153442.html,pany_code,
a.drug_dept_code,
a.drug_type,
a.in_date))
where ((日期 is not null) or (日期 is null and 供应商 is null) or
(日期 is null and 供应商 is not null and 仓库 is null and 类别 is null))

部分结果预览:

二、根据表名快速生成SQL
不必多说,全选下面的内容,直接F8,查询后,请看结果,绝对又为亲省了很多事。
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
--自动生成查询、更新、插入 语句 脚本 ,by 成忠祝,刘勇,邹安兵
--更新语句
select 'update ' || t.table_name || ' a set ' ||
(select wm_concat('a.' || a.column_name || '=' || Chr(39) || '{' ||
Abs(Rownum - 1) || '}' || chr(39) || ' --' ||
https://www.doczj.com/doc/7c11153442.html,ments || Chr(13) || Chr(10))
from user_col_comments a
where a.table_name = t.table_name)
from user_col_comments t
where t.table_name = upper('com_employee')
and rownum = 1;
--插入语句
select 'insert into ' || t.table_name || '(' ||
(select wm_concat(a.column_name || ' --' || https://www.doczj.com/doc/7c11153442.html,ments || Chr(13) ||
Chr(10))
from user_col_comments a
where a.table_name = t.table_name) || ') values (' ||
(select wm_concat(Chr(39) || '{' || Abs(Rownum - 1) || '}' || Chr(39) ||
' --' || https://www.doczj.com/doc/7c11153442.html,ments || Chr(13) || Chr(10))
from user_col_comments a
where a.table_name = t.table_name) || ')'
from user_col_comments t
where t.table_name = upper('com_employee')
and rownum = 1;
--查询语句
Select (Select 'select ' ||
Wmsys.Wm_Concat('a.' || T.Column_Name || ' --' || https://www.doczj.com/doc/7c11153442.html,ments ||
Chr(13) || Chr(10))
From https://www.doczj.com/doc/7c11153442.html,er_Col_Comments t
Where T.Table_Name = A.Table_Name) || ' from ' || A.Table_Name ||
' a '
From User_Col_Comments a
Where A.Table_Name = Upper('com_employee')
And Rownum = 1;
--查询语句 ,备注字段
select (select 'select ' ||
wm_concat('a.' || t.column_name || ' as "' ||
substr(nvl(trim(https://www.doczj.com/doc/7c11153442.html,ments), '无备注'), 0, 15) || '"' ||
Chr(13) || Chr(10))
from https://www.doczj.com/doc/7c11153442.html,er_col_comments t
where t.table_name = a.table_name) || ' from ' || a.table_name ||
' a '
from user_col_comments a

where a.table_name = upper('com_employee')
and rownum = 1;
三、过度分配索引所引起的性能开销
评:
我们之前一直不知道哪些索引有用没,导致部分表的索引已经建立了大于5个索引。
大家想想,如果索引多了,就类似于一本书目录内容特别多,而内容相对少,没有必要,反而查起来更慢了,特别是数据不多的表。
根据经验,一张表的索引数建议不要超过8个,最好在6个以下。通过本文你可以学到如何找出性能开销大的索引。
作者:王新风
大家好!
今天发现有项目在医嘱分解,Insert,Update药品相关表时非常慢,也不是锁表所引起的. 查找发现很大的原因是因为索引引起的.
数据库事务由DML语句组成,而DML操作需要使用UNDO表空间来保存事务的回滚信息. 比如我们做一个Delete的时候,数据库中UNDO表空间需要保存当前删除记录的位置,还需要将原有记录的内容全部保存下,这样回滚时才能组成新的数据插入回数据库中.如果表中有索引,则操作同时需要在UNDO表空间保存索引相关的回滚信息. 索引的回滚开销往往远大于DML操作数据的开销. 所以咱们不能只要看见一个SQL查询的where条件中出现了某一列,就给这列加上个索引,虽然这个方法是能够让SQL运行得更快速,但是过度分配索引会严重影响关键表的性能,导致DML操作时性能底下.
下面这个sql语句可以查询计算出添加索引后的undo表空间开销和没有索引的undo表空间开销大小.
1
2
3
4
5
6
7
8
9
10
11
12
13
select b.sid, --会话编号
b.SERIAL#,
https://www.doczj.com/doc/7c11153442.html,ERNAME,
b.MACHINE,
b.sql_hash_value,
a.START_TIME, --事务启动时间
https://www.doczj.com/doc/7c11153442.html,ED_UBLK, --使用的UNDO块数
https://www.doczj.com/doc/7c11153442.html,ED_UREC, --使用的UNDO记录条数,是本文接下来的主要估算指标
a.START_UBAFIL, --使用的UNDO文件号
a.START_UBABLK --使用的UNDO起始块号
from v$transaction a, v$session b
where a.ses_addr = b.saddr
and b.sid = ?;
sid就是当前执行sql语句的回话ID.可以到plsql-->工具-->session中查看. 这个sql语句查询结果的USED_UREC可以看出执行一个DML语句时所占用的UNDO表空间记录大小.
而在咱们现在运行的系统中,可以使用如下sql语句打开所有索引的监视功能.
select 'alter index '||owner||'.'||index_name||' monitoring usage;' from dba_indexes where owner = 'khhis' //owner为当前数据库用户名.
执行上面sql语句生成的脚本,然后等待数据库上运行了足够多的SQL语句以后,可以查询新的V$OBJECT_USAGE视图.
select index_name, table_name, mon, used from V$OBJECT_USAGE
根据查出的used的值是YES或者NO,可以查出哪些索引是没有在使用的,可以找出这一部分索引删除掉.以减少数据库性能开销!

相关主题
文本预览
相关文档 最新文档