ถ้า unitcost แบบใหม่ผมเขียนแบบนี้ครับ จึงจะตรงตามต้องการตามโปรแกรมครับ (เปลี่ยนรหัส รพ.เอานะครับ)
- Script ดึง IPD Data
SELECT "11056" as hcode,a.an,p.hn,a.vn,p.pname,p.fname,p.lname,p.birthday,p.sex,a.regdate,a.dchdate,w.name as wardname,s.name as pttypename,a.los,i.drg,i.rw,i.adjrw,a.pdx,
a.dx0,a.dx1,a.dx2,a.dx3,a.dx4,a.dx5,a.op0,a.op1,a.op2,a.op3,a.op4,a.op5,a.op6,a.inc16 as inc01,a.inc08 as inc02 ,a.inc12 as inc03,0 as inc04,0 as inc05,a.inc02 as inc06,a.inc01 as inc07,a.inc04 as inc08,a.inc05 as inc09,a.inc09 as inc10,a.inc06 as inc11,a.inc14 as inc12,a.inc11 as inc13,a.inc13 as inc14,0 as inc15,a.inc17 as inc16,0 as inc17 from an_stat a
left JOIN patient p on p.hn=a.hn
left JOIN ward w on w.ward=a.ward
LEFT JOIN pttype pty on pty.pttype=a.pttype
left JOIN pcode s on s.code=pty.pcode
LEFT JOIN ipt i ON i.an=a.an
WHERE a.dchdate BETWEEN '2010-10-01' and '2011-09-30'
- Script ดึง OPD Data
SELECT "11056" as hcode,a.vn,p.hn,a.cid,p.pname,p.fname,p.lname,p.birthday,p.sex,a.vstdate,s.name as pttypename,a.pdx,
a.dx0,a.dx1,a.dx2,a.dx3,a.dx4,a.dx5,a.op0,a.op1,a.op2,a.op3,a.op4,a.op5,a.inc16 as inc01,a.inc08 as inc02 ,a.inc12 as inc03,0 as inc04,0 as inc05,a.inc02 as inc06,a.inc01 as inc07,a.inc04 as inc08,a.inc05 as inc09,a.inc09 as inc10,a.inc06 as inc11,a.inc14 as inc12,a.inc11 as inc13,a.inc13 as inc14,0 as inc15,a.inc17 as inc16,0 as inc17
from vn_stat a
left JOIN patient p on p.hn=a.hn
LEFT JOIN pttype pty on pty.pttype=a.pttype
left JOIN pcode s on s.code=pty.pcode
WHERE a.vstdate BETWEEN '2010-10-01' and '2011-09-30'