@wangyupu
2022-09-02T15:47:13.000000Z
字数 12069
阅读 34
数据测算
--一、数据准备
--1、原始表导入
--tb_cis_main_zk_2021条数1340122
select count(1) from tb_cis_main_zk_2021;
--kcub5条数7245016业务条数1340122
select count(1),count(distinct setl_id) from kcub5;
--kcub7总条数1784481业务条数696187
select count(1),count(distinct setl_id) from kcub7;
--bzml_2022条数11128
select count(1) from bzml_2022;
--tb_gzyb_dic_icd9条数13686
select count(1) from tb_gzyb_dic_icd9;
--2、数据质控
--校验是否存在无主诊断编码数据
select * from tb_cis_main_zk_2021 where pdlb in('2','5','11') and
ywxlh not in (select distinct setl_id from kcub5 where diag_name ='1');
--校验诊断表是否存在垃圾数据
select * from kcub5 where setl_id not in (select ywxlh from tb_cis_main_zk_2021);
--校验手术操作表是否存在垃圾数据
select * from kcub7 where setl_id not in (select ywxlh from tb_cis_main_zk_2021);
--校验诊断是否为有效诊断
select * from kcub5 where DIAG_CODE not in (select jbdm from tb_icd10_2021);
--校验手术操作表是否存在垃圾数据
select distinct OPRN_OPRT_CODE,OPRN_OPRT_NAME from kcub7 where OPRN_OPRT_CODE not in (select SSDM from tb_gzyb_dic_icd9)
and setl_id in (select ywxlh from tb_cis_main_zk_2021 where pdlb in('2','5','11'))
--修复手术操作
update kcub7
set OPRN_OPRT_CODE = decode(OPRN_OPRT_CODE,
'41.3101','41.3800x001',
'47.0101','47.0100',
'33.2201','33.2200',
'37.610101','37.6101',
'54.9804','54.9800',
'54.9801','54.9800',
'Z49.101','39.9500',
'67.0 01','67.0x00',
'88.550101','88.5500',
'73.0101','73.0100',
'39.950201','39.9501',
'69.9901','69.9900',
'54.2101','54.2100',
OPRN_OPRT_CODE)
where OPRN_OPRT_CODE in
('41.3101','33.2201','47.0101','37.610101','Z49.101','54.9801',
'54.9804','73.0101','67.0 01','88.550101','39.950201','69.9901','54.2101');
commit;
--3、数据准备
--创建诊断临时表
create table /*+ append parallel (degree 8) nologging */kcub5_hb as
SELECT /*+ append parallel (degree 8) nologging */
SETL_ID,
max(decode(MAINDIAG_FLAG,'1',decode(DIAG_CODE,'p59.901','P59.901',DIAG_CODE),'')) as zzdbm,
max(decode(MAINDIAG_FLAG,'1',DIAG_NAME,'')) as zzdmc,
listagg(DIAG_CODE,'+') within group(order by DIAG_CODE asc) as zdzhbm,
listagg(DIAG_NAME,'+') within group(order by DIAG_CODE asc) as zdzhmc
FROM kcub5
GROUP BY SETL_ID;
--创建手术操作临时表
create table /*+ append parallel (degree 8) nologging */kcub7_hb as
SELECT /*+ append parallel (degree 8) nologging */
t.SETL_ID,
listagg(t.OPRN_OPRT_CODE, '+') within group(order by t.OPRN_OPRT_CODE asc) as ssczzhbm,
listagg(t.OPRN_OPRT_NAME, '+') within group(order by t.OPRN_OPRT_CODE asc) as ssczzhmc,
listagg(decode(t.sslb,'手术','4','介入治疗','4','治疗性操作','3','诊断性操作','2','1'),'+') within group(order by t.OPRN_OPRT_CODE asc) as sslbzh
FROM (select DISTINCT a.SETL_ID, a.OPRN_OPRT_CODE,a.OPRN_OPRT_NAME,b.sslb from kcub7 a
left join tb_gzyb_dic_icd9 b on a.OPRN_OPRT_CODE = b.ssdm )t
GROUP BY t.SETL_ID
--创建病案首页测算主表
create table /*+ append parallel (degree 8) nologging */basy2021_cs as
SELECT a.YWXLH,
a.yljgdj,
a.sfzhm,
a.nl,
a.js_zyts,
a.js_zfy as zfy,
a.fzdm as fzdm_2021,
a.fzdm,
substr(b.zzdbm, 1,3) as zdbm_lm,
substr(b.zzdbm, 1,5) as zdbm_ym,
b.zzdbm,
b.zzdmc,
b.zdzhbm,
b.zdzhmc,
nvl(c.ssczzhbm,'n(y)'),
c.ssczzhmc,
c.sslbzh,
(case when c.sslbzh like '%4%' then '手术'
when c.sslbzh like '%3%2%' or sslbzh like '%2%3%' then '治疗+诊断'
when c.sslbzh like '%3%' then '治疗'
when c.sslbzh like '%2%' then '诊断'
when c.ssczzhbm is null then '无操作'
else '其它' end) as sslbmc
FROM tb_cis_main_zk_2021 a
LEFT JOIN kcub5_hb b on a.ywxlh = b.SETL_ID
LEFT JOIN kcub7_hb c on a.ywxlh = c.SETL_ID
where a.pdlb in('2','5','11');
alter table BASY2021_CS modify FZDM NVARCHAR2(1000);
update /*+ append parallel (degree 8) nologging */basy2021_cs set fzdm = '';
commit;
--更新病种目录权重系数
update bzml_2022 set bzqz='0.0';
commit;
merge /*+ append parallel 8 nologging */
into bzml_2022 a
using (select t.bzbm,
sum(decode(t.sslb,'手术',1,'介入治疗',1,0))||'.'||sum(decode(t.ssjb,'四级',1,0)) as bzqz
from (select a.*,b.ssdm,b.ssmc,b.ssjb,b.sslb from bzml_2022 a,tb_gzyb_dic_icd9 b
where instr(a.ssczzh||'+',b.ssdm||'+')>0) t
group by t.bzbm) b
on (a.bzbm=b.bzbm)
when matched then
update set a.bzqz = b.bzqz;
commit;
--三、多诊断入组规则
--规则1、多诊断保守治疗 622
merge /*+ append parallel 8 nologging */
into (select * from basy2021_cs where fzdm is null and ssczzhbm ='n(y)') a
using (select * from bzml_2022 where bzbm like '%+%:%n(y)') b
on (instr(b.zdzhbm, a.zdbm_ym) > 0
and instr(a.zdzhbm, substr(b.zdzhbm, 1, 5)) > 0
and instr(a.zdzhbm, substr(b.zdzhbm, 7, 5)) > 0)
when matched then
update set a.fzdm = b.bzbm;
commit;
--规则2、多诊断非保守治疗
--7430
select distinct sslbmc from basy2021_cs
merge /*+ append parallel 8 nologging */
into (select ywxlh,ssczzhbm,zdzhbm,zdbm_lm,sslbmc,fzdm from basy2021_cs where fzdm is null and sslbmc in('手术','治疗','诊断')) a
using (select t.ywxlh,listagg(t.bzbm, '/') as bzbm
from (select a.ywxlh,b.bzbm
from basy2021_cs a,
(select * from bzml_2022 where bzbm like '%+%:%' and ssczzh in('手术','治疗','诊断')) b
where a.fzdm is null
and instr(b.zdzhbm, a.zdbm_lm) > 0
and instr(a.zdzhbm, substr(b.zdzhbm, 1, 3)) > 0
and instr(a.zdzhbm, substr(b.zdzhbm, 5, 3)) > 0
and a.sslbmc=b.ssczzh)t
group by t.ywxlh) b
on (a.ywxlh=b.ywxlh)
when matched then
update set a.fzdm = b.bzbm;
commit;
--既有治疗又有诊断
merge /*+ append parallel 8 nologging */
into (select ywxlh,ssczzhbm,zdzhbm,zdbm_lm,sslbmc,fzdm from basy2021_cs where fzdm is null and sslbmc='治疗+诊断') a
using (select /*+ append parallel 8 nologging */t.ywxlh,
listagg(t.bzbm, '/') as bzbm from (
select a.ywxlh,b.bzbm,a.sslbmc, b.ssczzh
from basy2021_cs a, (select * from bzml_2022 where bzbm like '%+%治疗' or bzbm like '%+%诊断') b
where a.fzdm is null
and a.sslbmc='治疗+诊断'
and instr(b.zdzhbm, a.zdbm_lm) > 0
and instr(a.zdzhbm, substr(b.zdzhbm, 1, 3)) > 0
and instr(a.zdzhbm, substr(b.zdzhbm, 5, 3)) > 0
and instr(a.sslbmc, b.ssczzh) > 0 )t group by t.ywxlh) b
on (a.ywxlh=b.ywxlh)
when matched then
update set a.fzdm = b.bzbm;
commit;
select count(1) from basy2021_cs where fzdm is not null;
--四、核心病种入组规则
--规则2、精确匹配
merge /*+ append parallel 8 nologging */
into (select * from basy2021_cs where fzdm is null) a
using bzml_2022 b
on (a.zdbm_ym||':'||a.ssczzhbm=b.bzbm)
when matched then
update set a.fzdm = b.bzbm;
--规则3、模糊匹配
create table mhpp_tmp1 as
select /*+ append parallel (degree 8) nologging */a.*,b.bzbm,b.bzqz from basy2021_cs a,bzml_2022 b
where a.zdbm_ym=b.zdzhbm
and a.fzdm is null and a.ssczzhbm is not null
and instr(a.ssczzhbm,substr(b.ssczzh||'+',1,instr(b.ssczzh||'+','+',1,1)-1))>0
and instr(a.ssczzhbm,nvl( substr(b.ssczzh||'+',instr(b.ssczzh||'+','+',1,1)+1,instr(b.ssczzh||'+','+',1,2)-instr(b.ssczzh||'+','+',1,1)-1),'+'))>0
and instr(a.ssczzhbm,nvl( substr(b.ssczzh||'+',instr(b.ssczzh||'+','+',1,2)+1,instr(b.ssczzh||'+','+',1,3)-instr(b.ssczzh||'+','+',1,2)-1),'+'))>0
and instr(a.ssczzhbm,nvl( substr(b.ssczzh||'+',instr(b.ssczzh||'+','+',1,3)+1,instr(b.ssczzh||'+','+',1,4)-instr(b.ssczzh||'+','+',1,3)-1),'+'))>0
and instr(a.ssczzhbm,nvl( substr(b.ssczzh||'+',instr(b.ssczzh||'+','+',1,4)+1,instr(b.ssczzh||'+','+',1,5)-instr(b.ssczzh||'+','+',1,4)-1),'+'))>0
and instr(a.ssczzhbm,nvl( substr(b.ssczzh||'+',instr(b.ssczzh||'+','+',1,5)+1,instr(b.ssczzh||'+','+',1,6)-instr(b.ssczzh||'+','+',1,5)-1),'+'))>0
and instr(a.ssczzhbm,nvl( substr(b.ssczzh||'+',instr(b.ssczzh||'+','+',1,6)+1,instr(b.ssczzh||'+','+',1,7)-instr(b.ssczzh||'+','+',1,6)-1),'+'))>0
--200,179
merge /*+ append parallel 8 nologging */
into (select * from basy2021_cs where fzdm is null) a
using (select t.ywxlh, listagg(t.bzbm,'/') within group(order by t.bzbm asc) as rzbm from (
select a.* from mhpp_tmp1 a,
(select ywxlh,max(bzqz) as bzqz from mhpp_tmp1 group by ywxlh) b
where a.ywxlh=b.ywxlh and a.bzqz=b.bzqz) t group by t.ywxlh) b on (a.ywxlh=b.ywxlh)
when matched then
update set a.fzdm = b.rzbm;
commit;
--二级核心病种入组规则
--规则四:入不到上面规则的病历,按照以下规则入组
select count(1) from basy2021_cs where fzdm is not null;
merge /*+ append parallel 8 nologging */
into (select * from basy2021_cs where fzdm is null) a
using (select * from bzml_2022 ) b on (a.zdbm_lm||':'||a.sslbmc=b.bzbm)
when matched then
update set a.fzdm = b.bzbm;
commit;
----既有诊断又有操作
merge /*+ append parallel 8 nologging */
into (select * from basy2021_cs where fzdm is null) a
using (select t.ywxlh, listagg(t.bzbm,'/') within group(order by t.bzbm asc) as rzbm from (select a.*,b.bzbm from basy2021_cs a,bzml_2022 b where a.fzdm is null and a.sslbmc='治疗+诊断'
and a.zdbm_lm=b.zdzhbm and b.ssczzh in('治疗','诊断')) t group by ywxlh) b on (a.ywxlh=b.ywxlh)
when matched then
update set a.fzdm = b.rzbm;
commit;
---综合病种入组规则
select count(1) from basy2021_cs where fzdm is null;
--
merge /*+ append parallel 8 nologging */
into (select * from basy2021_cs where fzdm is null) a
using (select * from bzml_2022 where substr(bzbm,2,1)=':') b on (substr(a.zzdbm,1,1)||':'||a.sslbmc=b.bzbm)
when matched then
update set a.fzdm = b.bzbm;
commit;
----既有诊断又有操作
merge /*+ append parallel 8 nologging */
into (select * from basy2021_cs where fzdm is null) a
using (select t.ywxlh, listagg(t.bzbm,'/') within group(order by t.bzbm asc) as rzbm from (select a.*,b.bzbm from basy2021_cs a,bzml_2022 b where a.fzdm is null and a.sslbmc='治疗+诊断'
and substr(a.zzdbm,1,1)=b.zdzhbm and b.ssczzh in('治疗','诊断')) t group by ywxlh) b on (a.ywxlh=b.ywxlh)
when matched then
update set a.fzdm = b.rzbm;
commit;
select fzdm from basy2021_cs group by fzdm
select max(length(fzdm)-length(replace(fzdm,'/',''))) from basy2021_cs where fzdm like '%/%'
--拆分
create table cs_tmp1 as
select ywxlh,fzdm,zfy,
substr(fzdm,1,instr(fzdm,'/',1)-1) as fzdm1,
substr(fzdm,instr(fzdm||'/','/',1,1)+1,instr(fzdm||'/','/',1,2)-instr(fzdm|| '/','/',1, 1)-1) as fzdm2,
substr(fzdm,instr(fzdm||'/','/',1,2)+1,instr(fzdm||'/','/',1,3)-instr(fzdm|| '/','/',1, 2)-1) as fzdm3,
substr(fzdm,instr(fzdm||'/','/',1,3)+1,instr(fzdm||'/','/',1,4)-instr(fzdm|| '/','/',1, 3)-1) as fzdm4,
substr(fzdm,instr(fzdm||'/','/',1,4)+1,instr(fzdm||'/','/',1,5)-instr(fzdm|| '/','/',1, 4)-1) as fzdm5,
substr(fzdm,instr(fzdm||'/','/',1,5)+1,instr(fzdm||'/','/',1,6)-instr(fzdm|| '/','/',1, 5)-1) as fzdm6,
substr(fzdm,instr(fzdm||'/','/',1,6)+1,instr(fzdm||'/','/',1,7)-instr(fzdm|| '/','/',1, 6)-1) as fzdm7,
substr(fzdm,instr(fzdm||'/','/',1,7)+1,instr(fzdm||'/','/',1,8)-instr(fzdm|| '/','/',1, 7)-1) as fzdm8,
substr(fzdm,instr(fzdm||'/','/',1,8)+1,instr(fzdm||'/','/',1,9)-instr(fzdm|| '/','/',1, 8)-1) as fzdm9,
substr(fzdm,instr(fzdm||'/','/',1,9)+1,instr(fzdm||'/','/',1,10)-instr(fzdm|| '/','/',1, 9)-1) as fzdm10,
substr(fzdm,instr(fzdm||'/','/',1,10)+1,instr(fzdm||'/','/',1,11)-instr(fzdm|| '/','/',1, 10)-1) as fzdm11,
substr(fzdm,instr(fzdm||'/','/',1,11)+1,instr(fzdm||'/','/',1,12)-instr(fzdm|| '/','/',1, 11)-1) as fzdm12,
substr(fzdm,instr(fzdm||'/','/',1,12)+1,instr(fzdm||'/','/',1,13)-instr(fzdm|| '/','/',1, 12)-1) as fzdm13,
substr(fzdm,instr(fzdm||'/','/',1,13)+1,instr(fzdm||'/','/',1,14)-instr(fzdm|| '/','/',1, 13)-1) as fzdm14
from basy2021_cs where fzdm like '%/%';
drop table cs_tmp2 ;
create table cs_tmp2 as
select ywxlh,fzdm,zfy from basy2021_cs where fzdm not like '%/%'
union
select ywxlh,fzdm1 as fzdm,zfy from cs_tmp1 where fzdm1 is not null
union
select ywxlh,fzdm2 as fzdm,zfy from cs_tmp1 where fzdm2 is not null
union
select ywxlh,fzdm3 as fzdm,zfy from cs_tmp1 where fzdm3 is not null
union
select ywxlh,fzdm4 as fzdm,zfy from cs_tmp1 where fzdm4 is not null
union
select ywxlh,fzdm5 as fzdm,zfy from cs_tmp1 where fzdm5 is not null
union
select ywxlh,fzdm6 as fzdm,zfy from cs_tmp1 where fzdm6 is not null
union
select ywxlh,fzdm7 as fzdm,zfy from cs_tmp1 where fzdm7 is not null
union
select ywxlh,fzdm8 as fzdm,zfy from cs_tmp1 where fzdm8 is not null
union
select ywxlh,fzdm9 as fzdm,zfy from cs_tmp1 where fzdm9 is not null
union
select ywxlh,fzdm10 as fzdm,zfy from cs_tmp1 where fzdm10 is not null
union
select ywxlh,fzdm11 as fzdm,zfy from cs_tmp1 where fzdm11 is not null
union
select ywxlh,fzdm12 as fzdm,zfy from cs_tmp1 where fzdm12 is not null
union
select ywxlh,fzdm13 as fzdm,zfy from cs_tmp1 where fzdm13 is not null
union
select ywxlh,fzdm14 as fzdm,zfy from cs_tmp1 where fzdm14 is not null;
create table bzml_2022_tmp1 as
select a.*,nvl(a.分值,b.mnfz) as mnfz from bzml_2022 a
left join (select fzdm,round(avg(zfy)/14.32) as mnfz from cs_tmp2 group by fzdm) b
on a.bzbm = b.fzdm
---------------------------------------------------------.
drop table cs_tmp3
create table cs_tmp3 as
select a.*,abs(round(a.zfy/14.32)-b.mnfz) as fzce from cs_tmp2 a ,bzml_2022_tmp1 b where a.fzdm = b.bzbm;
drop table cs_tmp3
--随机入组逻辑
create table cs_tmp4 as
select *
from (select t.*,
row_number() over(partition by ywxlh order by dbms_random.random) as rn
from (select *
from cs_tmp3
where (ywxlh, fzce) in
(select ywxlh, min(fzce) from cs_tmp3 group by ywxlh)) t
order by ywxlh, dbms_random.random)
where rn = 1
drop table cs_tmp3
create table cs_tmp5 as
select *
from (select t.*,
row_number() over(partition by ywxlh order by dbms_random.random) as rn
from (select *
from cs_tmp3
where (ywxlh, fzce) in
(select ywxlh, min(fzce) from cs_tmp3 group by ywxlh)) t
order by ywxlh, dbms_random.random)
where rn = 1
---------------------
create table basy2021_cs_tmp1 as select * from basy2021_cs;
merge /*+ append parallel 8 nologging */
into (select * from basy2021_cs_tmp1 where fzdm like '%/%') a
using cs_tmp4 b on (a.ywxlh = b.ywxlh)
when matched then
update set a.fzdm = b.fzdm;
commit;
select * from (
select a.*,b.ls as ls2022,b.jcfy as jcfy2022,b.cv as cv2022
from bzml_2022 a
left join (select fzdm,
count(1) as ls,
STDDEV(zfy) / avg(zfy) as cv,
avg(zfy) as jcfy
from basy2021_cs_tmp1
group by fzdm) b
on a.bzbm = b.fzdm) t order by to_number(t.测算序号)
select fzdm,
count(1) as ls,
STDDEV(zfy) / avg(zfy) as cv,
avg(zfy) as jcfy,
max(decode(fzdm,'K35.8:47.0100',avg(zfy),'')) as jcfy1
from basy2021_cs_tmp1
group by fzdm