BMS-HOSxP Community
HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: nan_it ที่ พฤศจิกายน 11, 2010, 10:59:06 AM
-
ผมเขียนคำสั่งดึงคนไข้ที่เบาหวานอย่างเดียว ไม่ทราบว่าถูกมั้ยครับ แนะนำหน่อยครับ
select distinct(ov.hn),ov.*
from vn_stat ov ,patient pt ,ovst ovst
where ov.vn=ovst.vn and pt.hn=ov.hn and ov.vstdate between "2009-10-01" and "2010-09-30" and ov.hn=pt.hn
and ( (ov.pdx >= "E10" and ov.pdx <= "E149")
or (ov.dx0 >= "E10" and ov.dx0 <= "E149" )
or (ov.dx1 >= "E10" and ov.dx1 <= "E149")
or (ov.dx2 >= "E10" and ov.dx2 <= "E149")
or (ov.dx3 >= "E10" and ov.dx3 <= "E149")
or (ov.dx4 >= "E10" and ov.dx4 <= "E149")
or (ov.dx5 >= "E10" and ov.dx5 <= "E149") )
and ov.dx0 <> "I10"
and ov.dx1 <> "I10"
and ov.pdx <> "I10"
and ov.dx2 <> "I10"
and ov.dx3 <> "I10"
and ov.dx4 <> "I10"
and ov.dx5 <> "I10"
-
select distinct(o.icd10),if(o.icd10 between "e10" and "e109" ,"IDM","NIDM") as dmtype,o.hn,count(o.vn) as cntvn ,concat(p.pname,p.fname," ",p.lname) as ptname,p.cid,concat(p.addrpart,"ËÁÙè",p.moopart) as mo,if(t.full_name is null,"äÁ辺·ÕèÍÂÙè",t.full_name) as taddress,min(o.vstdate) as minvst
, (select o1.icd10 from ovstdiag o1 where o.hn=o1.hn and (o1.icd10="e103" or o1.icd10="e113" or o1.icd10="e123" or o1.icd10="e133" or o1.icd10="e143" ) limit 1) as DM_with_Ophthalmic
, (select o1.icd10 from ovstdiag o1 where o.hn=o1.hn and (o1.icd10="e102" or o1.icd10="e112" or o1.icd10="e122" or o1.icd10="e132" or o1.icd10="e142" ) limit 1) as DM_with_Renel
, (select o1.icd10 from ovstdiag o1 where o.hn=o1.hn and (o1.icd10="e104" or o1.icd10="e114" or o1.icd10="e124" or o1.icd10="e134" or o1.icd10="e144" ) limit 1) as DM_with_Neurological
, (select o1.icd10 from ovstdiag o1 where o.hn=o1.hn and (o1.icd10="e105" or o1.icd10="e115" or o1.icd10="e125" or o1.icd10="e135" or o1.icd10="e145" ) limit 1) as DM_with_Peripheral
, (select o1.icd10 from ovstdiag o1 where o.hn=o1.hn and (o1.icd10="e107" or o1.icd10="e117" or o1.icd10="e127" or o1.icd10="e137" or o1.icd10="e147" ) limit 1) as DM_with_Multiple
, (select o1.icd10 from ovstdiag o1 where o.hn=o1.hn and (o1.icd10="e108" or o1.icd10="e118" or o1.icd10="e128" or o1.icd10="e138" or o1.icd10="e148" ) limit 1) as DM_with_Unspecified
, (select o1.icd10 from ovstdiag o1 where o.hn=o1.hn and (o1.icd10="e106" or o1.icd10="e116" or o1.icd10="e126" or o1.icd10="e136" or o1.icd10="e146" ) limit 1) as DM_with_Other
from ovstdiag o
left outer join patient p on p.hn=o.hn
Left Outer Join thaiaddress t ON t.addressid=concat(p.chwpart,p.amppart,p.tmbpart)
where o.icd10 between "e10" and "e149" group by o.hn
เอามาจากในนี้แหละครับ
-
ที่ อ. ให้มามันรวมคนไข้ที่เป็น HT ด้วยครับ ที่ผมลองเขียนคือ ทั้ง pdx dx0 dx1 dx2 dx3 dx4 dx5 ต้องเป็นรหัส e10 ถึง e149 ครับ ไม่รวม I10 ถึง I159
-
select dm.hn,p.pname,p.fname,p.lname,dm.lastdate
from (select o.hn,max(o.vstdate) lastdate
from ovstdiag o
where o.icd10 between 'E10' and 'E1499'
group by o.hn) dm
left join (select o.hn
from ovstdiag o
where o.icd10 between 'I10' and 'I1599'
group by o.hn) ht on dm.hn=ht.hn
left join patient p on dm.hn=p.hn
where ht.hn is null
-
select dm.hn,p.pname,p.fname,p.lname,dm.lastdate
from (select o.hn,max(o.vstdate) lastdate
from ovstdiag o
where o.icd10 between 'E10' and 'E1499'
group by o.hn) dm
left join (select o.hn
from ovstdiag o
where o.icd10 between 'I10' and 'I1599'
group by o.hn) ht on dm.hn=ht.hn
left join patient p on dm.hn=p.hn
where ht.hn is null
คำสั่งที่ให้มารันไม่ได้ครับ ฟ้อง hos.dm don't exit ครับ
-
ถ้าหากว่าเอาจากรหัสโรคก็น่าจะถูกครับเพราะว่าเท่าที่ดูเงื่อนไขคือเอาคนไข้ที่ถูวินิจฉัยว่าเป็นรหัส E
ทุกประเภท Diag ครับ
เพราะเหมือนคำสั่งที่ผมลองเขียนครับ
select * from vn_stat v
left outer join patient p on v.hn=p.hn
left outer join ovst o on v.vn=o.vn
where v.vstdate between "2009-10-01" and "2010-09-30"
and ( (v.pdx between "E10" and "E149")
or (v.dx0 between "E10" and "E149" )
or (v.dx1 between "E10" and "E149")
or (v.dx2 between "E10" and "E149")
or (v.dx3 between "E10" and "E149")
or (v.dx4 between "E10" and "E149")
or (v.dx5 between "E10" and "E149") )
and v.dx0 <> "I10"
and v.dx1 <> "I10"
and v.pdx <> "I10"
and v.dx2 <> "I10"
and v.dx3 <> "I10"
and v.dx4 <> "I10"
and v.dx5 <> "I10"