14
« เมื่อ: มิถุนายน 04, 2012, 22:01:12 PM »
ดันกระทู้คุณ Monalisa ครับ
ผมลองทดสอบและปรับใหม่ ตามบริบทโรงพยาบาลแล้ว โอเคเลยครับ
ส่วนฟิลด์ IncDrug ไม่ต้องส่งมาก็ได้ เพราะแฟ้ม Data ของ อ.สุกิจ จะรวมให้เอง (inco3+inc04+inc17)
แนบที่ปรับครับ
++++++++++++++OPD
set @hosp = '10948';
set @start_date = '2011-10-01';
set @end_date = '2012-03-31';
select @hosp as hcode,
v.vn, v.hn, pt.pname, pt.fname, pt.lname,
pt.birthday,
pt.sex,
v.vstdate,
pty.name as pttypename,
v.pdx, v.dx0, v.dx1, v.dx2, v.dx3, v.dx4, v.dx5,
v.op0, v.op1, v.op2, v.op3, v.op4, v.op5,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income in ('01') and op.vn=v.vn) as inc01,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income in ('02') and op.vn=v.vn) as inc02,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.icode like('1%') and op.vn=v.vn) as inc03,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.icode like('0%') and op.vn=v.vn) as inc04,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income = '05' and op.vn=v.vn) as inc05,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income = '06' and op.vn=v.vn) as inc06,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income in ('07') and op.vn=v.vn) as inc07,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income in ('08') and op.vn=v.vn) as inc08,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income in ('09') and op.vn=v.vn) as inc09,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income = '10' and op.vn=v.vn) as inc10,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income in ('11') and op.vn=v.vn) as inc11,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income in ('12') and op.icode not in('3000976','3000977','3903762','3908398','3900441','3904537','3904538','3904538','3904539','3908311','3908313','39083127','3908386')and op.vn=v.vn) as inc12,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income = '13' and op.vn=v.vn) as inc13,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income = '14' and op.vn=v.vn) as inc14,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income = '15' and op.vn=v.vn) as inc15,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.icode in('3000976','3000977','3903762','3908398','3900441','3904537','3904538','3904538','3904539','3908311','3908313','39083127','3908386') and op.vn=v.vn) as inc16,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.icode like('1%**') and op.vn=v.vn) as inc17,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.icode like('1%') and op.vn=v.vn) as incDrug
from vn_stat v
left JOIN patient pt on pt.hn=v.hn
left join pttype pty on pty.pttype=v.pttype
left join doctor dc on dc.code=v.dx_doctor
where v.vstdate between @start_date and @end_date
and v.income<>'0.00'
++++++++++++++++++++IPD
set @hosp = '10948';
set @start_date = '2011-10-01';
set @end_date = '2012-03-31';
select @hosp as hcode,
i.vn, i.hn,pt.pname, pt.fname, pt.lname,
pt.birthday,
pt.sex,
pty.name as pttypename,i.regdate,i.dchdate,w.name as wardname,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,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income in ('01') and op.an=i.an) as inc01,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income in ('02') and op.an=i.an) as inc02,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.icode like('1%') and op.item_type <> 'H' and op.an=i.an) as inc03,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.icode like('1%') and op.item_type = 'H' and op.an=i.an) as inc04,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income = '05' and op.an=i.an) as inc05,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income = '06' and op.an=i.an) as inc06,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income in ('07') and op.an=i.an) as inc07,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income in ('08') and op.an=i.an) as inc08,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income in ('09') and op.an=i.an) as inc09,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income = '10' and op.an=i.an) as inc10,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income in ('11') and op.an=i.an) as inc11,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income in ('12') and op.icode not in('3000976','3000977','3903762','3908398','3900441','3904537','3904538','3904538','3904539','3908311','3908313','39083127','3908386')and op.an=i.an) as inc12,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income = '13' and op.an=i.an) as inc13,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income = '14' and op.an=i.an) as inc14,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.income = '15' and op.an=i.an) as inc15,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.icode in('3000976','3000977','3903762','3908398','3900441','3904537','3904538','3904538','3904539','3908311','3908313','39083127','3908386') and op.an=i.an) as inc16,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.icode like('1%**') and op.an=i.an) as inc17,
(select IFNULL(sum(sum_price), '0.00') from opitemrece op where op.icode like('1%') and op.an=i.an) as incDrug
from ipt i
left join patient pt on pt.hn=i.hn
left join ward w on w.ward=i.ward
left join an_stat a on a.an=i.an
left join pttype pty on pty.pttype=i.pttype
where i.regdate between @start_date and @end_date
and a.income<>'0.00'