BMS-HOSxP Community

HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: Bluebird ที่ มิถุนายน 06, 2012, 22:47:42 PM

หัวข้อ: คำสั่ง กรองผู้ป่วยเบาหวาน ที่ยังไม่เคยได้รับยา Aspirin
เริ่มหัวข้อโดย: Bluebird ที่ มิถุนายน 06, 2012, 22:47:42 PM
ตัวอย่าง
คำสั่ง กรองผู้ป่วยชาย อายุ 50 ปีขึ้นไป ที่เป็นเบาหวาน ได้รับยา Aspirin
select ov.hn,pt.cid,concat(pt.pname,pt.fname," ",pt.lname) as ptname,pt.birthday,max(ov.age_y) as age,
pt.death,pt.deathday,max(ov.vstdate) as vstdate,max(op.nextdate) nextdate,concat(od.icd10," : ",ic.name) as diag,
concat(pt.addrpart," ËÁÙè ",pt.moopart," µ.",t3.name," Í.",t2.name," ¨.",t1.name) as fulladdressname,d.name as doctor_diag,
concat(dr.name," ",dr.strength) as drug
from ovstdiag od
left outer join vn_stat ov on ov.vn=od.vn
left outer join patient pt on pt.hn=ov.hn
left outer join icd101 ic on ic.code=od.icd10
left outer join thaiaddress t1 on t1.chwpart=pt.chwpart
and t1.amppart="00" and t1.tmbpart="00"
left outer join thaiaddress t2 on t2.chwpart=pt.chwpart
and t2.amppart=pt.amppart and t2.tmbpart="00"
left outer join thaiaddress t3 on t3.chwpart=pt.chwpart
and t3.amppart=pt.amppart and t3.tmbpart=pt.tmbpart
left outer join doctor d on d.code=od.doctor
left outer join oapp op on op.vn=ov.vn
left outer join opitemrece opi on opi.vn=ov.vn
left outer join drugitems dr on dr.icode=opi.icode
where pt.sex=1
and ov.age_y>=50
and od.icd10 >= "E10" and od.icd10 <= "E149"
and ov.vstdate between "2011-10-01" and "2012-05-31"
and opi.icode in('1000038','1530003','1481232')
group by ov.hn


แต่สิ่งที่แพทย์ต้องการคือ ผู้ป่วยชาย อายุ 50 ปีขึ้นไป ที่เป็นเบาหวาน ที่ไม่เคยได้รับยา Aspirin
หัวข้อ: Re: คำสั่ง กรองผู้ป่วยเบาหวาน ที่ยังไม่เคยได้รับยา Aspirin
เริ่มหัวข้อโดย: golf_win ที่ มิถุนายน 07, 2012, 07:04:17 AM
ลองใช้ not in
หัวข้อ: Re: คำสั่ง กรองผู้ป่วยเบาหวาน ที่ยังไม่เคยได้รับยา Aspirin
เริ่มหัวข้อโดย: Bluebird ที่ มิถุนายน 07, 2012, 08:40:45 AM
ลองใช้ not in


ลองใช้ not in แล้ว
ปรากฏว่าจะดึง ผู้ป่วย เบาหวาน ที ไม่ได้รับยา  aspirin ณ visit นั้น   พอไปเช็ด ปรากฏว่า รายชื่อที่ออกมา บางคนก็เคยได้รับยา Aspirin แล้ว แต่ visit ต่าง กัน 
หัวข้อ: Re: คำสั่ง กรองผู้ป่วยเบาหวาน ที่ยังไม่เคยได้รับยา Aspirin
เริ่มหัวข้อโดย: golf_win ที่ มิถุนายน 07, 2012, 09:01:05 AM
คงต้องใช้ variable มาเทียบการใช้ยาโดยเปรียบเทียบจากวันที่ใช้ยา
หัวข้อ: Re: คำสั่ง กรองผู้ป่วยเบาหวาน ที่ยังไม่เคยได้รับยา Aspirin
เริ่มหัวข้อโดย: waradmin01 ที่ มิถุนายน 08, 2012, 00:38:51 AM
SET @DM_clinic :="001";
SET @STD := "2010-10-01";
SET @EDD := "2012-05-31";

select vs.hn,concat(pt.pname,pt.fname," ",pt.lname)as pt_name,pt.sex,max(vs.age_y) as age

from  vn_stat vs

join (Select hn from clinicmember where clinic = @DM_clinic) cm on cm.hn=vs.hn

left join (select hn from opitemrece where vstdate between @STD and @EDD and icode in ("1000038","1530003","1481232")
group by hn) opi on opi.hn=cm.hn
left join patient pt on pt.hn=cm.hn

where pt.sex = 1 and opi.hn is null and vs.vstdate between @STD and @EDD
group by vs.hn
having age > 49

ขึ้นต้นให้แค่นี้นะครับ ที่เหลือน่าจะต่อยอดได้ พวก Left join เพื่อเอาค่ามาแสดง