ผู้เขียน หัวข้อ: กรองผู้ป่วย DM ที่ยังไม่เคยรับยาบางตัว แบบวันที่มาล่าสุด  (อ่าน 3967 ครั้ง)

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

ออฟไลน์ Bluebird

  • Hero Member
  • *****
  • กระทู้: 1,062
  • Respect: +2
    • ดูรายละเอียด
    • โรงพยาบาลระแงะ จังหวัดนราธิวาส
ห้องยาต้อง
ผู้ป่วย DM อายุ 50 ปีขึ้นไป ที่ยังไม่เคยได้รับยา (ระบุ icode 1000038,1530003)
โดยจะเอา
1.HN
2.ชื่อสกุล
3.อายุ
4.ค่า FBS/DTX
5.มาล่าสุด
6.นัดครั้งต่อไป

select pt.hn, concat(pt.pname,pt.fname,"  ",pt.lname) as fullname,pt.cid,pt.birthday,ov.age_y,ov.vstdate,oa.nextdate
from ovstdiag ovst
left outer join patient pt on pt.hn=ovst.hn
left outer join vn_stat ov on ov.vn=ovst.vn
left outer join opitemrece op on op.vn=ov.vn
left outer join oapp oa on oa.vn=ov.vn
where  ov.vstdate between "2011-10-01" and "2012-04-30"
and ov.age_y>=50
and (ovst.icd10 >= "E10" and ovst.icd10 <= "E148")
and op.icode not in ("1530003","1000038")


ส่วนท้ายต้องใช้ Group by hn หรืออะไรครับ
ใช้ Group by hn จะออกมาเป็นวันแรกที่มา ไม่ใช่วันล่าสุดครับ

นักวิชาการคอมพิวเตอร์ โรงพยาบาลระแงะ  จังหวัดนราธิวาส
www.rangaehospital.com

เริ่มใช้งานระบบ 1 ตุลาคม 2550
Server     :  HP Proliant DL180G6 RAM 16Gb. 
Replicate  : DELL PowerEdge 1800   RAM 16 Gb.
MySQL 5.5.31
OS CentOS 5 64bit
HOSxP Version : 3.59.4.27(ตาม Version ที่ออกใหม่ล่าสุด)

ออฟไลน์ golf_win

  • Hero Member
  • *****
  • กระทู้: 3,481
  • Respect: +112
    • ดูรายละเอียด
select pt.hn, concat(pt.pname,pt.fname,"  ",pt.lname) as fullname,pt.cid,pt.birthday,ov.age_y,max(ov.vstdate) as last_vstdate,max(oa.nextdate) as last_nextdate
from ovstdiag ovst
left outer join patient pt on pt.hn=ovst.hn
left outer join vn_stat ov on ov.vn=ovst.vn
left outer join opitemrece op on op.vn=ov.vn
left outer join oapp oa on oa.vn=ov.vn
where  ov.vstdate between "2011-10-01" and "2012-04-30"
and ov.age_y>=50
and (ovst.icd10 >= "E10" and ovst.icd10 <= "E148")
and op.icode not in ("1530003","1000038")
group by pt.hn
« แก้ไขครั้งสุดท้าย: พฤษภาคม 18, 2012, 19:24:08 PM โดย golf_win »
โรงพยาบาลเจ็ดเสมียน จังหวัดราชบุรี
Start 19-1-51    35 station
HOSxP  3.59.5.18 Activate License
Tel. 032-305096-7 ต่อ 118
Web. http://csmhos.thaiddns.com:8080
         http://csmhos.thaieasydns.com:8080