[关闭]
@wangyupu 2022-09-02T15:47:13.000000Z 字数 12069 阅读 34

广州项目2021最新入组逻辑及数据测算

数据测算


  1. --一、数据准备
  2. --1、原始表导入
  3. --tb_cis_main_zk_2021条数1340122
  4. select count(1) from tb_cis_main_zk_2021;
  5. --kcub5条数7245016业务条数1340122
  6. select count(1),count(distinct setl_id) from kcub5;
  7. --kcub7总条数1784481业务条数696187
  8. select count(1),count(distinct setl_id) from kcub7;
  9. --bzml_2022条数11128
  10. select count(1) from bzml_2022;
  11. --tb_gzyb_dic_icd9条数13686
  12. select count(1) from tb_gzyb_dic_icd9;
  13. --2、数据质控
  14. --校验是否存在无主诊断编码数据
  15. select * from tb_cis_main_zk_2021 where pdlb in('2','5','11') and
  16. ywxlh not in (select distinct setl_id from kcub5 where diag_name ='1');
  17. --校验诊断表是否存在垃圾数据
  18. select * from kcub5 where setl_id not in (select ywxlh from tb_cis_main_zk_2021);
  19. --校验手术操作表是否存在垃圾数据
  20. select * from kcub7 where setl_id not in (select ywxlh from tb_cis_main_zk_2021);
  21. --校验诊断是否为有效诊断
  22. select * from kcub5 where DIAG_CODE not in (select jbdm from tb_icd10_2021);
  23. --校验手术操作表是否存在垃圾数据
  24. select distinct OPRN_OPRT_CODE,OPRN_OPRT_NAME from kcub7 where OPRN_OPRT_CODE not in (select SSDM from tb_gzyb_dic_icd9)
  25. and setl_id in (select ywxlh from tb_cis_main_zk_2021 where pdlb in('2','5','11'))
  26. --修复手术操作
  27. update kcub7
  28. set OPRN_OPRT_CODE = decode(OPRN_OPRT_CODE,
  29. '41.3101','41.3800x001',
  30. '47.0101','47.0100',
  31. '33.2201','33.2200',
  32. '37.610101','37.6101',
  33. '54.9804','54.9800',
  34. '54.9801','54.9800',
  35. 'Z49.101','39.9500',
  36. '67.0 01','67.0x00',
  37. '88.550101','88.5500',
  38. '73.0101','73.0100',
  39. '39.950201','39.9501',
  40. '69.9901','69.9900',
  41. '54.2101','54.2100',
  42. OPRN_OPRT_CODE)
  43. where OPRN_OPRT_CODE in
  44. ('41.3101','33.2201','47.0101','37.610101','Z49.101','54.9801',
  45. '54.9804','73.0101','67.0 01','88.550101','39.950201','69.9901','54.2101');
  46. commit;
  47. --3、数据准备
  48. --创建诊断临时表
  49. create table /*+ append parallel (degree 8) nologging */kcub5_hb as
  50. SELECT /*+ append parallel (degree 8) nologging */
  51. SETL_ID,
  52. max(decode(MAINDIAG_FLAG,'1',decode(DIAG_CODE,'p59.901','P59.901',DIAG_CODE),'')) as zzdbm,
  53. max(decode(MAINDIAG_FLAG,'1',DIAG_NAME,'')) as zzdmc,
  54. listagg(DIAG_CODE,'+') within group(order by DIAG_CODE asc) as zdzhbm,
  55. listagg(DIAG_NAME,'+') within group(order by DIAG_CODE asc) as zdzhmc
  56. FROM kcub5
  57. GROUP BY SETL_ID;
  58. --创建手术操作临时表
  59. create table /*+ append parallel (degree 8) nologging */kcub7_hb as
  60. SELECT /*+ append parallel (degree 8) nologging */
  61. t.SETL_ID,
  62. listagg(t.OPRN_OPRT_CODE, '+') within group(order by t.OPRN_OPRT_CODE asc) as ssczzhbm,
  63. listagg(t.OPRN_OPRT_NAME, '+') within group(order by t.OPRN_OPRT_CODE asc) as ssczzhmc,
  64. listagg(decode(t.sslb,'手术','4','介入治疗','4','治疗性操作','3','诊断性操作','2','1'),'+') within group(order by t.OPRN_OPRT_CODE asc) as sslbzh
  65. FROM select DISTINCT a.SETL_ID, a.OPRN_OPRT_CODE,a.OPRN_OPRT_NAME,b.sslb from kcub7 a
  66. left join tb_gzyb_dic_icd9 b on a.OPRN_OPRT_CODE = b.ssdm t
  67. GROUP BY t.SETL_ID
  68. --创建病案首页测算主表
  69. create table /*+ append parallel (degree 8) nologging */basy2021_cs as
  70. SELECT a.YWXLH,
  71. a.yljgdj,
  72. a.sfzhm,
  73. a.nl,
  74. a.js_zyts,
  75. a.js_zfy as zfy,
  76. a.fzdm as fzdm_2021,
  77. a.fzdm,
  78. substr(b.zzdbm, 1,3) as zdbm_lm,
  79. substr(b.zzdbm, 1,5) as zdbm_ym,
  80. b.zzdbm,
  81. b.zzdmc,
  82. b.zdzhbm,
  83. b.zdzhmc,
  84. nvl(c.ssczzhbm,'n(y)'),
  85. c.ssczzhmc,
  86. c.sslbzh,
  87. (case when c.sslbzh like '%4%' then '手术'
  88. when c.sslbzh like '%3%2%' or sslbzh like '%2%3%' then '治疗+诊断'
  89. when c.sslbzh like '%3%' then '治疗'
  90. when c.sslbzh like '%2%' then '诊断'
  91. when c.ssczzhbm is null then '无操作'
  92. else '其它' end) as sslbmc
  93. FROM tb_cis_main_zk_2021 a
  94. LEFT JOIN kcub5_hb b on a.ywxlh = b.SETL_ID
  95. LEFT JOIN kcub7_hb c on a.ywxlh = c.SETL_ID
  96. where a.pdlb in('2','5','11');
  97. alter table BASY2021_CS modify FZDM NVARCHAR2(1000);
  98. update /*+ append parallel (degree 8) nologging */basy2021_cs set fzdm = '';
  99. commit;
  100. --更新病种目录权重系数
  101. update bzml_2022 set bzqz='0.0';
  102. commit;
  103. merge /*+ append parallel 8 nologging */
  104. into bzml_2022 a
  105. using (select t.bzbm,
  106. sum(decode(t.sslb,'手术',1,'介入治疗'1,0))||'.'||sum(decode(t.ssjb,'四级',1,0)) as bzqz
  107. from (select a.*,b.ssdm,b.ssmc,b.ssjb,b.sslb from bzml_2022 a,tb_gzyb_dic_icd9 b
  108. where instr(a.ssczzh||'+',b.ssdm||'+')>0) t
  109. group by t.bzbm) b
  110. on (a.bzbm=b.bzbm)
  111. when matched then
  112. update set a.bzqz = b.bzqz;
  113. commit;
  114. --三、多诊断入组规则
  115. --规则1、多诊断保守治疗 622
  116. merge /*+ append parallel 8 nologging */
  117. into (select * from basy2021_cs where fzdm is null and ssczzhbm ='n(y)') a
  118. using (select * from bzml_2022 where bzbm like '%+%:%n(y)') b
  119. on (instr(b.zdzhbm, a.zdbm_ym) > 0
  120. and instr(a.zdzhbm, substr(b.zdzhbm, 1, 5)) > 0
  121. and instr(a.zdzhbm, substr(b.zdzhbm, 7, 5)) > 0)
  122. when matched then
  123. update set a.fzdm = b.bzbm;
  124. commit;
  125. --规则2、多诊断非保守治疗
  126. --7430
  127. select distinct sslbmc from basy2021_cs
  128. merge /*+ append parallel 8 nologging */
  129. into (select ywxlh,ssczzhbm,zdzhbm,zdbm_lm,sslbmc,fzdm from basy2021_cs where fzdm is null and sslbmc in('手术','治疗','诊断')) a
  130. using (select t.ywxlh,listagg(t.bzbm, '/') as bzbm
  131. from (select a.ywxlh,b.bzbm
  132. from basy2021_cs a,
  133. (select * from bzml_2022 where bzbm like '%+%:%' and ssczzh in('手术','治疗','诊断')) b
  134. where a.fzdm is null
  135. and instr(b.zdzhbm, a.zdbm_lm) > 0
  136. and instr(a.zdzhbm, substr(b.zdzhbm, 1, 3)) > 0
  137. and instr(a.zdzhbm, substr(b.zdzhbm, 5, 3)) > 0
  138. and a.sslbmc=b.ssczzht
  139. group by t.ywxlh) b
  140. on (a.ywxlh=b.ywxlh)
  141. when matched then
  142. update set a.fzdm = b.bzbm;
  143. commit;
  144. --既有治疗又有诊断
  145. merge /*+ append parallel 8 nologging */
  146. into (select ywxlh,ssczzhbm,zdzhbm,zdbm_lm,sslbmc,fzdm from basy2021_cs where fzdm is null and sslbmc='治疗+诊断') a
  147. using (select /*+ append parallel 8 nologging */t.ywxlh,
  148. listagg(t.bzbm, '/') as bzbm from (
  149. select a.ywxlh,b.bzbm,a.sslbmc, b.ssczzh
  150. from basy2021_cs a, (select * from bzml_2022 where bzbm like '%+%治疗' or bzbm like '%+%诊断') b
  151. where a.fzdm is null
  152. and a.sslbmc='治疗+诊断'
  153. and instr(b.zdzhbm, a.zdbm_lm) > 0
  154. and instr(a.zdzhbm, substr(b.zdzhbm, 1, 3)) > 0
  155. and instr(a.zdzhbm, substr(b.zdzhbm, 5, 3)) > 0
  156. and instr(a.sslbmc, b.ssczzh) > 0 t group by t.ywxlh) b
  157. on (a.ywxlh=b.ywxlh)
  158. when matched then
  159. update set a.fzdm = b.bzbm;
  160. commit;
  161. select count(1) from basy2021_cs where fzdm is not null;
  162. --四、核心病种入组规则
  163. --规则2、精确匹配
  164. merge /*+ append parallel 8 nologging */
  165. into (select * from basy2021_cs where fzdm is null) a
  166. using bzml_2022 b
  167. on (a.zdbm_ym||':'||a.ssczzhbm=b.bzbm)
  168. when matched then
  169. update set a.fzdm = b.bzbm;
  170. --规则3、模糊匹配
  171. create table mhpp_tmp1 as
  172. select /*+ append parallel (degree 8) nologging */a.*,b.bzbm,b.bzqz from basy2021_cs a,bzml_2022 b
  173. where a.zdbm_ym=b.zdzhbm
  174. and a.fzdm is null and a.ssczzhbm is not null
  175. and instr(a.ssczzhbm,substr(b.ssczzh||'+',1,instr(b.ssczzh||'+','+',1,1)-1))>0
  176. 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
  177. 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
  178. 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
  179. 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
  180. 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
  181. 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
  182. --200,179
  183. merge /*+ append parallel 8 nologging */
  184. into (select * from basy2021_cs where fzdm is null) a
  185. using (select t.ywxlh, listagg(t.bzbm,'/') within group(order by t.bzbm asc) as rzbm from (
  186. select a.* from mhpp_tmp1 a,
  187. (select ywxlh,max(bzqz) as bzqz from mhpp_tmp1 group by ywxlh) b
  188. where a.ywxlh=b.ywxlh and a.bzqz=b.bzqz) t group by t.ywxlh) b on (a.ywxlh=b.ywxlh)
  189. when matched then
  190. update set a.fzdm = b.rzbm;
  191. commit;
  192. --二级核心病种入组规则
  193. --规则四:入不到上面规则的病历,按照以下规则入组
  194. select count(1) from basy2021_cs where fzdm is not null;
  195. merge /*+ append parallel 8 nologging */
  196. into (select * from basy2021_cs where fzdm is null) a
  197. using (select * from bzml_2022 ) b on (a.zdbm_lm||':'||a.sslbmc=b.bzbm)
  198. when matched then
  199. update set a.fzdm = b.bzbm;
  200. commit;
  201. ----既有诊断又有操作
  202. merge /*+ append parallel 8 nologging */
  203. into (select * from basy2021_cs where fzdm is null) a
  204. 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='治疗+诊断'
  205. and a.zdbm_lm=b.zdzhbm and b.ssczzh in('治疗','诊断')) t group by ywxlh b on (a.ywxlh=b.ywxlh)
  206. when matched then
  207. update set a.fzdm = b.rzbm;
  208. commit;
  209. ---综合病种入组规则
  210. select count(1) from basy2021_cs where fzdm is null;
  211. --
  212. merge /*+ append parallel 8 nologging */
  213. into (select * from basy2021_cs where fzdm is null) a
  214. using (select * from bzml_2022 where substr(bzbm,2,1)=':') b on (substr(a.zzdbm,1,1)||':'||a.sslbmc=b.bzbm)
  215. when matched then
  216. update set a.fzdm = b.bzbm;
  217. commit;
  218. ----既有诊断又有操作
  219. merge /*+ append parallel 8 nologging */
  220. into (select * from basy2021_cs where fzdm is null) a
  221. 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='治疗+诊断'
  222. and substr(a.zzdbm,1,1)=b.zdzhbm and b.ssczzh in('治疗','诊断')) t group by ywxlh b on (a.ywxlh=b.ywxlh)
  223. when matched then
  224. update set a.fzdm = b.rzbm;
  225. commit;
  226. select fzdm from basy2021_cs group by fzdm
  227. select max(length(fzdm)-length(replace(fzdm,'/',''))) from basy2021_cs where fzdm like '%/%'
  228. --拆分
  229. create table cs_tmp1 as
  230. select ywxlh,fzdm,zfy,
  231. substr(fzdm,1,instr(fzdm,'/',1)-1) as fzdm1,
  232. substr(fzdm,instr(fzdm||'/','/',1,1)+1,instr(fzdm||'/','/',1,2)-instr(fzdm|| '/','/',1, 1)-1) as fzdm2,
  233. substr(fzdm,instr(fzdm||'/','/',1,2)+1,instr(fzdm||'/','/',1,3)-instr(fzdm|| '/','/',1, 2)-1) as fzdm3,
  234. substr(fzdm,instr(fzdm||'/','/',1,3)+1,instr(fzdm||'/','/',1,4)-instr(fzdm|| '/','/',1, 3)-1) as fzdm4,
  235. substr(fzdm,instr(fzdm||'/','/',1,4)+1,instr(fzdm||'/','/',1,5)-instr(fzdm|| '/','/',1, 4)-1) as fzdm5,
  236. substr(fzdm,instr(fzdm||'/','/',1,5)+1,instr(fzdm||'/','/',1,6)-instr(fzdm|| '/','/',1, 5)-1) as fzdm6,
  237. substr(fzdm,instr(fzdm||'/','/',1,6)+1,instr(fzdm||'/','/',1,7)-instr(fzdm|| '/','/',1, 6)-1) as fzdm7,
  238. substr(fzdm,instr(fzdm||'/','/',1,7)+1,instr(fzdm||'/','/',1,8)-instr(fzdm|| '/','/',1, 7)-1) as fzdm8,
  239. substr(fzdm,instr(fzdm||'/','/',1,8)+1,instr(fzdm||'/','/',1,9)-instr(fzdm|| '/','/',1, 8)-1) as fzdm9,
  240. substr(fzdm,instr(fzdm||'/','/',1,9)+1,instr(fzdm||'/','/',1,10)-instr(fzdm|| '/','/',1, 9)-1) as fzdm10,
  241. substr(fzdm,instr(fzdm||'/','/',1,10)+1,instr(fzdm||'/','/',1,11)-instr(fzdm|| '/','/',1, 10)-1) as fzdm11,
  242. substr(fzdm,instr(fzdm||'/','/',1,11)+1,instr(fzdm||'/','/',1,12)-instr(fzdm|| '/','/',1, 11)-1) as fzdm12,
  243. substr(fzdm,instr(fzdm||'/','/',1,12)+1,instr(fzdm||'/','/',1,13)-instr(fzdm|| '/','/',1, 12)-1) as fzdm13,
  244. substr(fzdm,instr(fzdm||'/','/',1,13)+1,instr(fzdm||'/','/',1,14)-instr(fzdm|| '/','/',1, 13)-1) as fzdm14
  245. from basy2021_cs where fzdm like '%/%';
  246. drop table cs_tmp2 ;
  247. create table cs_tmp2 as
  248. select ywxlh,fzdm,zfy from basy2021_cs where fzdm not like '%/%'
  249. union
  250. select ywxlh,fzdm1 as fzdm,zfy from cs_tmp1 where fzdm1 is not null
  251. union
  252. select ywxlh,fzdm2 as fzdm,zfy from cs_tmp1 where fzdm2 is not null
  253. union
  254. select ywxlh,fzdm3 as fzdm,zfy from cs_tmp1 where fzdm3 is not null
  255. union
  256. select ywxlh,fzdm4 as fzdm,zfy from cs_tmp1 where fzdm4 is not null
  257. union
  258. select ywxlh,fzdm5 as fzdm,zfy from cs_tmp1 where fzdm5 is not null
  259. union
  260. select ywxlh,fzdm6 as fzdm,zfy from cs_tmp1 where fzdm6 is not null
  261. union
  262. select ywxlh,fzdm7 as fzdm,zfy from cs_tmp1 where fzdm7 is not null
  263. union
  264. select ywxlh,fzdm8 as fzdm,zfy from cs_tmp1 where fzdm8 is not null
  265. union
  266. select ywxlh,fzdm9 as fzdm,zfy from cs_tmp1 where fzdm9 is not null
  267. union
  268. select ywxlh,fzdm10 as fzdm,zfy from cs_tmp1 where fzdm10 is not null
  269. union
  270. select ywxlh,fzdm11 as fzdm,zfy from cs_tmp1 where fzdm11 is not null
  271. union
  272. select ywxlh,fzdm12 as fzdm,zfy from cs_tmp1 where fzdm12 is not null
  273. union
  274. select ywxlh,fzdm13 as fzdm,zfy from cs_tmp1 where fzdm13 is not null
  275. union
  276. select ywxlh,fzdm14 as fzdm,zfy from cs_tmp1 where fzdm14 is not null;
  277. create table bzml_2022_tmp1 as
  278. select a.*,nvl(a.分值,b.mnfz) as mnfz from bzml_2022 a
  279. left join (select fzdm,round(avg(zfy)/14.32) as mnfz from cs_tmp2 group by fzdm) b
  280. on a.bzbm = b.fzdm
  281. ---------------------------------------------------------.
  282. drop table cs_tmp3
  283. create table cs_tmp3 as
  284. 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;
  285. drop table cs_tmp3
  286. --随机入组逻辑
  287. create table cs_tmp4 as
  288. select *
  289. from (select t.*,
  290. row_number() over(partition by ywxlh order by dbms_random.random) as rn
  291. from (select *
  292. from cs_tmp3
  293. where (ywxlh, fzce) in
  294. (select ywxlh, min(fzce) from cs_tmp3 group by ywxlh)) t
  295. order by ywxlh, dbms_random.random)
  296. where rn = 1
  297. drop table cs_tmp3
  298. create table cs_tmp5 as
  299. select *
  300. from (select t.*,
  301. row_number() over(partition by ywxlh order by dbms_random.random) as rn
  302. from (select *
  303. from cs_tmp3
  304. where (ywxlh, fzce) in
  305. (select ywxlh, min(fzce) from cs_tmp3 group by ywxlh)) t
  306. order by ywxlh, dbms_random.random)
  307. where rn = 1
  308. ---------------------
  309. create table basy2021_cs_tmp1 as select * from basy2021_cs;
  310. merge /*+ append parallel 8 nologging */
  311. into (select * from basy2021_cs_tmp1 where fzdm like '%/%') a
  312. using cs_tmp4 b on (a.ywxlh = b.ywxlh)
  313. when matched then
  314. update set a.fzdm = b.fzdm;
  315. commit;
  316. select * from (
  317. select a.*,b.ls as ls2022,b.jcfy as jcfy2022,b.cv as cv2022
  318. from bzml_2022 a
  319. left join (select fzdm,
  320. count(1) as ls,
  321. STDDEV(zfy) / avg(zfy) as cv,
  322. avg(zfy) as jcfy
  323. from basy2021_cs_tmp1
  324. group by fzdm) b
  325. on a.bzbm = b.fzdm) t order by to_number(t.测算序号)
  326. select fzdm,
  327. count(1) as ls,
  328. STDDEV(zfy) / avg(zfy) as cv,
  329. avg(zfy) as jcfy,
  330. max(decode(fzdm,'K35.8:47.0100',avg(zfy),'')) as jcfy1
  331. from basy2021_cs_tmp1
  332. group by fzdm
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注