【发布时间】:2021-09-30 21:30:29
【问题描述】:
我正在使用 SQL Server 来解决分散的数据问题。我有几个生命体征,我正在研究一项措施,当 Vital_12 和 Vital_14 都被执行时,它是 MET。 NV 值不计算在内,因为它们的意思是“未记录”。一些生命体征记录在一个列中,而不是另一列,但我需要同时满足每项指标。
目标:捕获下面显示的行,其中 PCR_ID 在“PulseOximetry”和“respiratory_rate”列中输入了至少一个非 NV 值,以便我可以确定是否满足医疗保健措施。我正在考虑分区但不确定。
由于一个 PCR_ID 可以在一个呼叫中完成多个生命体征,我需要计算两个都完成的那些,而不是只完成一个而不是另一个的那些。 EMT 可以将这些记录在不同的行中,这是我的问题
所以,因为当两者都填写但不在同一行时,它确实计数。 我写了这段代码
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
Select Distinct P.PCR_ID,case when Convert(Int, P.ePatient_15) is not null and Convert(int,P.ePatient_16) =2516007 then
Convert(Int, P.ePatient_15 / 12) when Convert(Int, P.ePatient_15) is not null and Convert(int,P.ePatient_16) =2516001 then
Convert(Int, P.ePatient_15 / 365)when Convert(Int, P.ePatient_15) is not null and Convert(int,P.ePatient_16) =2516003 then
Convert(Int, P.ePatient_15 / 8,760)when Convert(Int, P.ePatient_15) is not null and Convert(int,P.ePatient_16) =2516005 then
Convert(Int, P.ePatient_15 / 524,600) Else P.ePatient_15 End As Age, P.ePatient_16 As Age_Units , CAST(LEFT(E.eTimes_03,10) AS DATE) As DateofCall,
Case When S.eSituation_11 Like '%I50%' Then 'Heart Failure, Unspecified'
When S.eSituation_11 Like '%J00%' Then 'AcuteNasopharyngitis'
When S.eSituation_11 Like '%J05%' Then 'Acute obstructive laryngitis and epiglottitis'
When S.eSituation_11 Like '%J18.9%' Then 'Pneumonia, unspecified organism' when S.eSituation_11 Like '%J20.9%'
then 'Pneumonia, unspecified organism' when S.eSituation_11 Like '%F41.1%'
then 'Pneumonia, unspecified organism' when S.eSituation_11 Like '%J44.1%'
then 'Generalized anxiety disorder' when S.eSituation_11 like '%J45.9%'then 'Chronic obstructive pulmonary disease (acute)exacerbation' when S.eSituation_11 Like '%J80%'
then 'Acute respiratory distress syndrome' when S.eSituation_11 Like '%J81%' then 'Pulmonary edema' when S.eSituation_11 Like '%J93.9%'
then 'Pneumothorax, unspecified' when S.eSituation_11 Like '%J96%' then 'Respiratory failure, unspecified' when S.eSituation_11 like'%J96%'
then 'Acute bronchospasm' when S.eSituation_11 like '%G40.909' then 'Epilepsy, unspecified, not intractable, without status epilepticus' when S.eSituation_11 like '%R05%'
then 'Cough' when S.eSituation_11 like '%R06%' then 'Abnormalities of breathing' when S.eSituation_11 ='J98.01' then 'Acute bronchospasm'
when S.eSituation_11 like '%R09.2%' then 'Respiratory arrest'
when S.eSituation_11 like '%T14.9%' then 'Unspecified Injury'
when S.eSituation_11 like '%T17.9%' then 'Foreign body in respiratory tract, part unspecified'
when S.eSituation_11 like '%R11.2' then 'Nausea with vomiting, unspecified'
when S.eSituation_11 like '%J11%' then 'Influenza due to unidentified influenza virus'Else S.eSituation_11 End As Primary_Impression,
Case When S.eSituation_12 Like '%I50%' Then 'Heart Failure, Unspecified'
When S.eSituation_12 Like '%J00%' Then 'AcuteNasopharyngitis' When S.eSituation_12 Like '%J05%' Then 'Acute obstructive laryngitis and epiglottitis'
When S.eSituation_12 Like '%J18.9%' Then 'Pneumonia, unspecified organism' when S.eSituation_12 Like '%J20.9%'
then 'Pneumonia, unspecified organism' when S.eSituation_12 Like '%J44.1%'
then 'Acute bronchitis, unspecified' when S.eSituation_12 like '%J45.9%'then 'Chronic obstructive pulmonary disease (acute)exacerbation' when S.eSituation_12 Like '%J80%'
then 'Acute respiratory distress syndrome' when S.eSituation_12 Like '%J81%' then 'Pulmonary edema' when S.eSituation_12 Like '%J93.9%'
then 'Pneumothorax, unspecified' when S.eSituation_12 Like '%J96%' then 'Respiratory failure, unspecified' when S.eSituation_12 like'%J96%'
then 'Acute bronchospasm' when S.eSituation_12 like '%J98.01%' then 'Respiratory disorder, unspecified' when S.eSituation_12 like '%R05%'
then 'Cough' when S.eSituation_12 like '%R06%' then 'Abnormalities of breathing' when S.eSituation_12 like '%R09.2%' then 'Respiratory arrest'
when S.eSituation_12 like '%T14.9%' then 'Unspecified Injury'
when S.eSituation_12 like '%R11.2' then 'Nausea with vomiting, unspecified'
when S.eSituation_12 Like '%J44.1%' then 'Generalized anxiety disorder' when S.eSituation_12
like '%T17.9%' then 'Foreign body in respiratory tract, part unspecified' when S.eSituation_11
like '%J11%' then 'Influenza due to unidentified influenza virus'
when S.eSituation_12 ='J98.01' then 'Acute bronchospasm'
when S.eSituation_12 like '%G40.909' then 'Epilepsy, unspecified, not intractable, without status epilepticus' Else S.eSituation_12 End As Secondary_Impression,
D.dAgency_03 as GMR_Agency, D.dAgency_02 as Agency_ID,
P.ePatient_15 AS AGE, P.ePatient_16 As Age_Units,V.eVitals_12 As Pulse_Oximetry, V.eVitals_14 As Respiratory_Rate,
Case when (V.eVitals_12 is null and V.eVitals_14 is null) or (V.eVitals_12 LIKE '%NV%' and V.eVitals_14 Like '%NV%')
Then '-1' Else 'Include' END As Partial_Vitals
FROM eSituation S
Join eResponse R ON S.PCR_ID = R.PCR_ID
Join ePatient P on S.PCR_ID = P.PCR_ID
Join eVitals V on S.PCR_ID = V.PCR_ID
Join eTimes E on S.PCR_ID = E.PCR_ID
left join dAgency D on S.PCR_ID = D.PCR_ID
Where
(/*eVitals_12 NOT LIKE '%NV=7701003%'
AND V.eVitals_12 Not Like '%NV=7701001%'
AND */eVitals_12 IS NOT NULL
AND
/*eVitals_14 NOT LIKE '%NV=7701003%' AnD
eVitals_14 NOT LIKE '%NV=7701001%'
AND */eVitals_14 IS NOT NULL )
AND
((
P.ePatient_15 NOT LIKE '%NV=%' AND P.ePatient_15 is not null AND P.ePatient_16 is not null and P.ePatient_16 NOT LIKE '%NV=%'
AND Convert(Int,P.ePatient_15) <= 18 AND Convert(Int,P.ePatient_16) = 2516009 and not Convert (Int, P.ePatient_15) > 18
)
OR
(
P.ePatient_15 NOT LIKE '%NV=%' AND P.ePatient_16 NOT LIKE '%NV=%' and P.ePatient_15 IS NOT NULL AND P.ePatient_16 IS NOT NULL AND
P.ePatient_16 in ('2516001','2516003','2516005','2516007')))
AND
(
S.eSituation_11 NOT LIKE '%NV=%' AND S.eSituation_11 IS NOT NULL AND S.eSituation_12 IS NOT NULL AND S.eSituation_12 NOT LIKE '%NV=%'
AND S.eSituation_11 NOT LIKE '%RO%'
AND S.eSituation_11 in ('I50.9','J00','J05','J18.9','J20.9','J44.1','J45.901','J80','J81','J93.9','J96','J98.01','R05','R0','R06')
OR
S.eSituation_12 IN('I50.9','J00','J05','J18.9','J20.9','J44.1','J45.901','J80','J81','J93.9','J96','J98.01','R05','R06','R0', 'R09.2','T17.9'))
AND
(
R.eResponse_05 NOT LIKE '%NV=%' AND R.eResponse_05 IS not Null AND
R.eResponse_05 = '2205001' and R.eResponse_05 not like '%2205005%'
AND
D.dAgency_03 is not null and D.dAgency_03 NOT LIKE '%NV=%'
And E.eTimes_03 is not null AND E.eTimes_03 >= '2019-01-01' )
现在在这里查看结果:(NV 值 = 未记录)
PCR_ID Pulse_Oximetry Respiratory_Rate Partial_Vitals
011acd11602446a08ac919375c36f9ff 98 30 Include
011acd11602446a08ac919375c36f9ff 99 30 Include
011acd11602446a08ac919375c36f9ff 99 34 Include
011acd11602446a08ac919375c36f9ff 99 44 Include
0180f79087774621ba273d09929a71df 86 52 Include
0180f79087774621ba273d09929a71df 97 18 Include
0180f79087774621ba273d09929a71df 97 22 Include
0180f79087774621ba273d09929a71df 98 15 Include
01842d8cfe3541049425fea0555c672d 100 30 Include
01842d8cfe3541049425fea0555c672d 99 NV=7701003 Include
01c2c338c40d41a585099b545f89b226 100 30 Include
01c2c338c40d41a585099b545f89b226 90 30 Include
01c2c338c40d41a585099b545f89b226 98 30 Include
01c2c338c40d41a585099b545f89b226 100 30 Include
01c2c338c40d41a585099b545f89b226 90 30 Include
01c2c338c40d41a585099b545f89b226 98 30 Include
02b795683d804bd18936495fc7d1819d 87 20 Include
02b795683d804bd18936495fc7d1819d 96 18 Include
02b795683d804bd18936495fc7d1819d 97 20 Include
02b795683d804bd18936495fc7d1819d 97 24 Include
02f37ecf0030424caafde5e85e71bc76 88 40 Include
02f37ecf0030424caafde5e85e71bc76 94 40 Include
0334ba78e86343f4946edf4aea0214a7 100 16 Include
0334ba78e86343f4946edf4aea0214a7 100 19 Include
0334ba78e86343f4946edf4aea0214a7 99 26 Include
0334ba78e86343f4946edf4aea0214a7 NV=7701003 NV=7701003 -1
03bd5ca76efa4152ae1e876452c30e19 98 28 Include
03ec5e9e98aa4f909b3aa9d69cef8922 98 40 Include
03ec5e9e98aa4f909b3aa9d69cef8922 98 42 Include
03ec5e9e98aa4f909b3aa9d69cef8922 98 48 Include
03ec5e9e98aa4f909b3aa9d69cef8922 98 40 Include
03ec5e9e98aa4f909b3aa9d69cef8922 98 42 Include
03ec5e9e98aa4f909b3aa9d69cef8922 98 48 Include
0427d5a2e273425fa724f64a56fb93ea 100 36 Include
0427d5a2e273425fa724f64a56fb93ea 100 40 Include
0427d5a2e273425fa724f64a56fb93ea NV=7701003 NV=7701003 -1
043e2bcd23684213afdae0059ecea344-9890A20200824211443334 100 40 Include
043e2bcd23684213afdae0059ecea344-9890A20200824211443334 95 40 Include
043e2bcd23684213afdae0059ecea344-9890A20200824211443334 96 42 Include
043e2bcd23684213afdae0059ecea344-9890A20200824211443334 97 38 Include
043e2bcd23684213afdae0059ecea344-9890A20200824211443334 NV=7701003 NV=7701003 -1
043e2bcd23684213afdae0059ecea344-9890A20200825100942340 100 40 Include
043e2bcd23684213afdae0059ecea344-9890A20200825100942340 95 40 Include
043e2bcd23684213afdae0059ecea344-9890A20200825100942340 96 42 Include
043e2bcd23684213afdae0059ecea344-9890A20200825100942340 97 38 Include
043e2bcd23684213afdae0059ecea344-9890A20200825100942340 NV=7701003 NV=7701003 -1
04554aa5c05246eba3512245fe69c331 97 34 Include
04554aa5c05246eba3512245fe69c331 97 NV=7701003 Include
04554aa5c05246eba3512245fe69c331 98 33 Include
04946d009336477a98833091604eaed0 90 22 Include
04946d009336477a98833091604eaed0 95 15 Include
04946d009336477a98833091604eaed0 98 18 Include
04fda20a5830496a89ef35ddc13b114d 95 18 Include
04fda20a5830496a89ef35ddc13b114d 98 18 Include
05090120b3374c1f850ec263b23e5e16-238298836117918 98 22 Include
050f82a8797a47e694faa6a5e611a544 97 20 Include
050f82a8797a47e694faa6a5e611a544 98 28 Include
050f82a8797a47e694faa6a5e611a544 99 32 Include
05b71453d3464835b9129c67345b3827 92 NV=7701003 Include
05b71453d3464835b9129c67345b3827 95 32 Include
06018fe90348405a8991cb5c5a3fb66d 98 55 Include
06018fe90348405a8991cb5c5a3fb66d 98 58 Include
06cd52b794504ca3b8d95e3740a10748 97 50 Include
06cd52b794504ca3b8d95e3740a10748 98 40 Include
06cd52b794504ca3b8d95e3740a10748 99 50 Include
07b4b23d7c434fdd9b1725251b4d38af 97 28 Include
07b4b23d7c434fdd9b1725251b4d38af 99 28 Include
084e300971cd4493b8d2b8d205dd8f8c 100 18 Include
091e8704652b411da33d35afcbc6c224 100 30 Include
091e8704652b411da33d35afcbc6c224 99 30 Include
098718fc059547039bec78dd0965bbf2 97 NV=7701003 Include
098718fc059547039bec78dd0965bbf2 98 NV=7701003 Include
09d1b129d388428d923517853581eb7d 99 40 Include
09d1b129d388428d923517853581eb7d 99 60 Include
09d1b129d388428d923517853581eb7d 99 40 Include
09d1b129d388428d923517853581eb7d 99 60 Include
09dabde283a6434f976d1290c65b7de2 95 23 Include
09dabde283a6434f976d1290c65b7de2 99 24 Include
0a8ac77f9c104d1788b25fc4bb97fee9 100 26 Include
0a8ac77f9c104d1788b25fc4bb97fee9 95 30 Include
0ad4d67c75b64266a85f226ab4636983 96 NV=7701003 Include
0ad4d67c75b64266a85f226ab4636983 98 NV=7701003 Include
0ad4d67c75b64266a85f226ab4636983 99 16 Include
0ad4d67c75b64266a85f226ab4636983 99 NV=7701003 Include
0ad4d67c75b64266a85f226ab4636983 NV=7701003 NV=7701003 -1
0ad4d67c75b64266a85f226ab4636983 96 NV=7701003 Include
0ad4d67c75b64266a85f226ab4636983 98 NV=7701003 Include
0ad4d67c75b64266a85f226ab4636983 99 16 Include
0ad4d67c75b64266a85f226ab4636983 99 NV=7701003 Include
0ad4d67c75b64266a85f226ab4636983 NV=7701003 NV=7701003 -1
0aec4b6aa0784326a26fc0f0f34598ef 97 20 Include
0b2ebf66a9a2441a81429e5f78f5a11f 99 24 Include
0b70878094944947a5873d446e6e5d58 54 23 Include
0b70878094944947a5873d446e6e5d58 59 18 Include
0b70878094944947a5873d446e6e5d58 61 19 Include
0b70878094944947a5873d446e6e5d58 68 18 Include
0b70878094944947a5873d446e6e5d58 68 32 Include
0b70878094944947a5873d446e6e5d58 77 17 Include
0b70878094944947a5873d446e6e5d58 91 24 Include
0b70878094944947a5873d446e6e5d58 93 25 Include
0b70878094944947a5873d446e6e5d58 NV=7701003 NV=7701003 -1
0ba1bba70415458ebd5b0edb00917516 100 27 Include
0ba1bba70415458ebd5b0edb00917516 89 28 Include
0ba1bba70415458ebd5b0edb00917516 97 36 Include
0ba9dc304d574859b565a91fdadef619 97 20 Include
0ba9dc304d574859b565a91fdadef619 98 14 Include
0ba9dc304d574859b565a91fdadef619 99 16 Include
0ba9dc304d574859b565a91fdadef619 99 NV=7701003 Include
0ba9dc304d574859b565a91fdadef619 97 20 Include
0ba9dc304d574859b565a91fdadef619 98 14 Include
0ba9dc304d574859b565a91fdadef619 99 16 Include
0ba9dc304d574859b565a91fdadef619 99 NV=7701003 Include
0beb24df85ab4fd6b21b28f0d1d93eb7-9491A20200826151457334 100 24 Include
0beb24df85ab4fd6b21b28f0d1d93eb7-9491A20200826151457334 NV=7701003 NV=7701003 -1
0beb24df85ab4fd6b21b28f0d1d93eb7-9491A20200826151914340 100 24 Include
0beb24df85ab4fd6b21b28f0d1d93eb7-9491A20200826151914340 NV=7701003 NV=7701003 -1
0c0c69f7e97340678159504a9ad3dce8 96 48 Include
0c0c69f7e97340678159504a9ad3dce8 97 44 Include
0c0c69f7e97340678159504a9ad3dce8 98 30 Include
0c0c69f7e97340678159504a9ad3dce8 98 44 Include
0c27c2a11f3d4fd5a4b4103e46ecf786 100 28 Include
0c6177e09bc2442fa3c6ed023b41b755 98 30 Include
0d1d10533934412ebd2d1543c34b9b4e 89 30 Include
0d1d10533934412ebd2d1543c34b9b4e 92 NV=7701003 Include
0d1d10533934412ebd2d1543c34b9b4e 93 NV=7701003 Include
0d1d10533934412ebd2d1543c34b9b4e 94 NV=7701003 Include
0d1d10533934412ebd2d1543c34b9b4e 95 NV=7701003 Include
0d1d10533934412ebd2d1543c34b9b4e 97 NV=7701003 Include
0d1d10533934412ebd2d1543c34b9b4e 98 NV=7701003 Include
0d2d9ec024384584b01971c994746276 100 NV=7701003 Include
0d2d9ec024384584b01971c994746276 98 18 Include
0d3085f20a2741379d8570a52c279cca 100 NV=7701003 Include
0d3085f20a2741379d8570a52c279cca 98 32 Include
0d3085f20a2741379d8570a52c279cca NV=7701003 32 Include
0db5169e04e6415e9044283d8b632984 100 69 Include
0db5169e04e6415e9044283d8b632984 97 58 Include
0db5169e04e6415e9044283d8b632984 97 64 Include
0db5169e04e6415e9044283d8b632984 97 76 Include
0e9929a9b20542579a2eeb911166facf 100 NV=7701003 Include
0e9929a9b20542579a2eeb911166facf 99 26 Include
0eb0db228a0d4941b0864e5a1105279a 100 12 Include
0eb0db228a0d4941b0864e5a1105279a 100 14 Include
0eb0db228a0d4941b0864e5a1105279a 100 NV=7701003 Include
0eb0db228a0d4941b0864e5a1105279a 48 NV=7701003 Include
0eb0db228a0d4941b0864e5a1105279a 83 13 Include
0eb0db228a0d4941b0864e5a1105279a 98 11 Include
0eb0db228a0d4941b0864e5a1105279a 99 25 Include
0ec7b7bd3d9b4289aa85674811cb8b04 98 26 Include
0ec7b7bd3d9b4289aa85674811cb8b04 NV=7701003 28 Include
0f610287eac042e083cf53b1369234e1 97 20 Include
0f610287eac042e083cf53b1369234e1 97 NV=7701003 Include
0f610287eac042e083cf53b1369234e1 98 26 Include
0f610287eac042e083cf53b1369234e1 98 NV=7701003 Include
0f610287eac042e083cf53b1369234e1 99 NV=7701003 Include
0f610287eac042e083cf53b1369234e1 97 20 Include
0f610287eac042e083cf53b1369234e1 97 NV=7701003 Include
0f610287eac042e083cf53b1369234e1 98 26 Include
0f610287eac042e083cf53b1369234e1 98 NV=7701003 Include
0f610287eac042e083cf53b1369234e1 99 NV=7701003 Include
0f7ad14ef8a3431aa6589790fbfdf0bc 100 24 Include
0f7ad14ef8a3431aa6589790fbfdf0bc 100 26 Include
0fbdbef9614d4a3eaac37cda1c3738c3 95 28 Include
0fbdbef9614d4a3eaac37cda1c3738c3 96 28 Include
0fe72efced9e41fabea66a0bd49b4be2 100 26 Include
0fe72efced9e41fabea66a0bd49b4be2 93 NV=7701003 Include
0fe72efced9e41fabea66a0bd49b4be2 95 26 Include
0fe72efced9e41fabea66a0bd49b4be2 95 35 Include
0fe72efced9e41fabea66a0bd49b4be2 NV=7701003 16 Include
0fe72efced9e41fabea66a0bd49b4be2 NV=7701003 31 Include
0fe72efced9e41fabea66a0bd49b4be2 NV=7701003 NV=7701003 -1
100a0d37b4284218a2659621957c406d 99 20 Include
101165b34dad46f4b0986b4e3046d96d 100 22 Include
101165b34dad46f4b0986b4e3046d96d 100 24 Include
1021ee5be07a45cfa2ca25d7d7169f13 98 28 Include
1021ee5be07a45cfa2ca25d7d7169f13 99 26 Include
1057df631f3b4ed4a33f8399172ffc9e 98 18 Include
1057df631f3b4ed4a33f8399172ffc9e 98 25 Include
1057df631f3b4ed4a33f8399172ffc9e 98 18 Include
1057df631f3b4ed4a33f8399172ffc9e 98 25 Include
10e38582171b48f394d89b35f33fb6dd 96 18 Include
10f0103c9a0b473bac1a4b6f1a5dba67 100 16 Include
10f0103c9a0b473bac1a4b6f1a5dba67 96 14 Include
10f0103c9a0b473bac1a4b6f1a5dba67 97 18 Include
10f0103c9a0b473bac1a4b6f1a5dba67 98 13 Include
10f0103c9a0b473bac1a4b6f1a5dba67 98 18 Include
10f0103c9a0b473bac1a4b6f1a5dba67 99 14 Include
I wrote a basic `CASE WHEN` statement here:
CASE
WHEN (V.eVitals_12 IS NULL AND V.eVitals_14 IS NULL) OR
(V.eVitals_12 LIKE '%NV%' AND V.eVitals_14 LIKE '%NV%')
THEN '-1'
ELSE 'Include'
END As Partial_Vitals,
COUNT(*) AS Count
我需要将此应用于每个PCR_ID。
【问题讨论】:
-
请不要使用图片。将表格作为文本粘贴到您的请求中。而且您在图像中显示的数据没有标题,所以我不知道它实际显示的是什么。如果你只是用预期的结果编了一个小例子,最好的办法是。最后:你问这个 DBMS 是什么?你在使用 MySQL 吗?甲骨文? SQL 服务器? ...
-
包含每个潜在条件的至少一个结果的样本数据会很有帮助。此外,用通俗易懂的语言解释你的逻辑,不依赖于读者知道你的列名和代码缩写的含义,也会有很长的路要走。
-
补充 Thorsten 所说的,听起来您是在医疗保健领域工作。如果是这样,请不要在您的问题中添加真实的患者数据;而是创建一个minimal reproducible example。
-
现在有一个 case 语句应该滚动到一个表中并使用 LIKE 连接..
-
@APH 是的,它是医疗数据,我输入了我现在正在做的事情,但缺少最终的 SQL 代码,并尝试了 Intersect 和一些子查询,但它没有解决我的问题。
标签: sql sql-server tsql case-when