BMS-HOSxP Community

HOSxP => แจ้งปัญหา / ขอความช่วยเหลือ => ข้อความที่เริ่มโดย: snhos ที่ กันยายน 28, 2009, 13:11:57 PM

หัวข้อ: ฝากดูคำสั่งคิวรี่ให้หน่อยถูกหรือเปล่าครับ
เริ่มหัวข้อโดย: snhos ที่ กันยายน 28, 2009, 13:11:57 PM
คือผมต้องการ หาคนไข้ที่ต้องเป็นทั้งเบาหวาน  และความดัน 
1.
select o1.hn from ovstdiag o1 join   ovstdiag o2 on o2.hn=o1.hn
where o1.icd10  in('E100','E101','E102','E103','E104','E105','E106','E107','E108','E109',
'E110','E111','E112','E113','E114','E115','E116','E117','E118','E119')
and o2.icd10='I10'   group by o1.hn

2.
SELECT hn
FROM (SELECT hn FROM ovstdiag where icd10  in('E100','E101','E102','E103','E104','E105','E106','E107','E108','E109',
'E110','E111','E112','E113','E114','E115','E116','E117','E118','E119')

union all     SELECT hn FROM ovstdiag where icd10='I10') ovstdiag
GROUP BY hn
HAVING COUNT(*)>1

อันไหนถูก  และควรจะใช้อันไหน
ขอบคุณครับ
หัวข้อ: Re: ฝากดูคำสั่งคิวรี่ให้หน่อยถูกหรือเปล่าครับ
เริ่มหัวข้อโดย: redfireball ที่ กันยายน 28, 2009, 15:24:09 PM
select distinct o1.hn
from ovstdiag o1 join   ovstdiag o2 on o2.hn=o1.hn
where
o1.hn in
(
select distinct o4.hn
from ovstdiag o4 join ovstdiag o5 on o4.hn=o5.hn
where o5.icd10='I10'
)
and o1.icd10  in('E100','E101','E102','E103','E104','E105','E106','E107','E108','E109',
'E110','E111','E112','E113','E114','E115','E116','E117','E118','E119')
ประมาณนี้เปล่าครับ  ??? ???
หัวข้อ: Re: ฝากดูคำสั่งคิวรี่ให้หน่อยถูกหรือเปล่าครับ
เริ่มหัวข้อโดย: pop_hosxp ที่ กันยายน 28, 2009, 15:38:09 PM
ขอลองส่งเข้าประกวดครับ ไม่รู้ถูกหรือเปล่า ;D ;D ;D

select distinct hn from vn_stat where (pdx like "E1%" and dx0="I10") or (pdx="I10" and dx0 like "E1%")
หัวข้อ: Re: ฝากดูคำสั่งคิวรี่ให้หน่อยถูกหรือเปล่าครับ
เริ่มหัวข้อโดย: snhos ที่ กันยายน 28, 2009, 15:42:01 PM
mysql  มันมีคำสั่ง  เกี่ยวกับการ intersec ได้ไหมครับ
หัวข้อ: Re: ฝากดูคำสั่งคิวรี่ให้หน่อยถูกหรือเปล่าครับ
เริ่มหัวข้อโดย: woravet ที่ กันยายน 28, 2009, 16:09:22 PM
select p.hn,p.pname,p.fname,p.lname
,o1.icd10 as 'dm'
,o2.icd10 as 'ht'
,min(o1.vstdate) as firstdate
,max(o1.vstdate) as lastdate
from patient p
left join ovstdiag o1 on o1.hn=p.hn
left join ovstdiag o2 on o1.vn=o2.vn
where o1.icd10 between 'e10' and 'e1499'
and o2.icd10 between 'i10' and 'i1599'
and o1.vstdate between '2008-10-1' and '2009-9-30'
group by p.hn
order by p.hn
ประมาณนี้
หัวข้อ: Re: ฝากดูคำสั่งคิวรี่ให้หน่อยถูกหรือเปล่าครับ
เริ่มหัวข้อโดย: snhos ที่ กันยายน 29, 2009, 08:44:35 AM
ขอบคุณ  คุณ woravet มากคำสั่งใช้ได้ดีที่เดี่ยว  ผมได้ไปปรับแก้  ตรง
o1.vn=o2.vn
เป็น
o2.hn=p.hn
เหตุผลก็เพราะว่า  คนที่เป็นเบาหวานและความดัน  ไม่จำต้องถูกลงวินิจฉัยในวันเดียวกัน หรือใน visit เดี่ยวกัน
เช่น  เมื่อเดือนที่แล้วมาตรวจแพทย์ลงวินิจฉัย  เป็น เบาหวานอย่างเดียว
พอมาตรวจอีกเดือนถัดมาแพทย์ลงวินิจฉัย  เป็น ความดันอย่างเดียว 
ก็ให้สรุปว่าคนนี้เป็นทั้งเบาหวานและความดันครับ
ขอบคุณทุกท่านครับ
หัวข้อ: Re: ฝากดูคำสั่งคิวรี่ให้หน่อยถูกหรือเปล่าครับ
เริ่มหัวข้อโดย: snhos ที่ กันยายน 29, 2009, 09:10:33 AM
เพิ่มเติมครับ  ไปแก้มาสด ๆ
เพื่อต้องการให้ทราบวันแรกของกัน วินิจฉัยโรคนั้น ๆ ด้วยครับ
select p.hn,p.pname,p.fname,p.lname
,o1.icd10 as 'dm'
,o2.icd10 as 'ht'
,min(o1.vstdate) as date_dm
,min(o2.vstdate) as date_ht
from patient p
 left outer join ovstdiag o1 on o1.hn=p.hn
left outer join ovstdiag o2 on o2.hn=o1.hn
where o1.icd10 between 'e100' and 'e119'
and o2.icd10 between 'i10' and 'i10'
and o1.vstdate between '2008-06-01' and '2008-09-30'
and o2.vstdate between '2008-06-01' and '2008-09-30'

group by p.hn
order by  o1.vstdate