oracle 确定一个主要诊断和一组次要诊断

7vhp5slm  于 2023-04-29  发布在  Oracle
关注(0)|答案(2)|浏览(146)

我的要求:A组代码:

o   E16.2 
o   E16.1
o   E16.0
o   E11.649
o   E13.641
o   E10.649
o   E15
o   O24.913

患者必须有1个上述ICD代码和1个ICD代码低于B组代码

•   E08%
•   E09%
•   E10%
•   E11%
•   E13%

我的数据:

ID  DX_CODE VISIT_DT
1   E11     12/20/2015
1   E11.649 1/8/2016
1   E09     2/20/2017
2   E16.2   1/30/2014
2   E13     7/15/2016
3   E11.649 12/2/2018
3   E11.649 7/17/2019
3   E11.649 5/15/2020
4   E16.0   5/20/2021
4   E16.2   4/25/2022

我试着遵循:

SELECT DISTINCT t1.ID
FROM data_table t1
JOIN data_table t2 ON t1.ID = t2.ID
WHERE (t1.DX_CODE IN ('E16.2', 'E16.1', 'E16.0', 'E11.649', 'E13.641', 'E10.649', 'E15', 'O24.913'))
AND (t2.DX_CODE LIKE 'E08%' OR t2.DX_CODE LIKE 'E09%' OR t2.DX_CODE LIKE 'E10%' OR t2.DX_CODE LIKE 'E11%' OR t2.DX_CODE LIKE 'E13%');

我遇到的问题是:我得到的行中,患者多次访问时具有来自A组代码的dx代码(例如例如,E11.649两次),并且患者还具有来自多次就诊必须具有的列表的两个不同代码( www.example.com ,E16.2)。
有人能帮忙吗

niknxzdl

niknxzdl1#

您可以:

with data as (select distinct id, dx_code from data_table)
select p.*, s.*
from data p
join data s on s.id = p.id and s.dx_code <> p.dx_code
where p.dx_code in ('E16.2', 'E16.1', 'E16.0', 'E11.649', 
                    'E13.641', 'E10.649', 'E15', 'O24.913')
  and (s.DX_CODE LIKE 'E08%' OR s.DX_CODE LIKE 'E09%' OR s.DX_CODE LIKE 'E10%' 
    OR s.DX_CODE LIKE 'E11%' OR s.DX_CODE LIKE 'E13%')

结果:

ID  DX_CODE  ID  DX_CODE 
 --- -------- --- ------- 
 1   E11.649  1   E11     
 1   E11.649  1   E09     
 2   E16.2    2   E13

请参见db<>fiddle上的运行示例。

0qx6xfy6

0qx6xfy62#

您可以使用以下查询来执行此操作:

WITH CTE AS (
  SELECT DISTINCT t1.ID, t1.DX_CODE as DX_CODE_A, t2.DX_CODE as DX_CODE_B
  FROM data_table t1
  JOIN data_table t2 ON t1.ID = t2.ID
  WHERE (t1.DX_CODE IN ('E16.2', 'E16.1', 'E16.0', 'E11.649', 'E13.641', 'E10.649', 'E15', 'O24.913'))
  AND (t2.DX_CODE LIKE 'E08%' OR t2.DX_CODE LIKE 'E09%' OR t2.DX_CODE LIKE 'E10%' OR t2.DX_CODE LIKE 'E11%' OR t2.DX_CODE LIKE 'E13%')
)
select *
from CTE
where DX_CODE_A <> DX_CODE_B

相关问题