BMS-HOSxP Community
HOSxP => Report Exchange => ข้อความที่เริ่มโดย: yokyai ที่ พฤษภาคม 20, 2013, 11:36:19 AM
-
กรณีที่ทำระยะเวลารอคอยแยกตามช่วงแต่ละจุดบริการ อาจจะมีผู้ป่วยไม่ได้รับบริการบางจุด เช่น ผู้ป่วยรวมทั้งหมด 100 คน ไม่รอรับยา 50 คน ต้องการเฉลี่ยโดยไม่นับรวม 50คนที่ไม่รอรับยาครับ ขอบคุณครับ
-
คงต้องเพิ่มกำหนดเงื่อนไข ต้องเป็น vn ที่ผานห้องยา ครับ จะได้มีถึง 50 คน ก่อนนำมาเฉลีย
-
นี่เป็นตัวอย่างรายงานครับพี่เกื้อ แต่ว่าตรงช่องที่คำนวณเวลาของแต่ละจุดบริการจะมีค่าว่างๆออกมา เราเพราะคนไข้ไม่ผ่านจุดนั้น จะไม่นำตรงนี้มาคำนวณเวลาเฉลี่ยจะทำอย่างไรครับ ขอบคุณครับ
-
อาจ ต้อง vn ที่ช่องที่ต้องการ is not null ครับ กำหนดไปเลย ว่า time ในช่องกำหนด <>"" and is not null
-
ทำไปในเงื่อนไขหลักๆไม่ได้ครับ จะตัดคนไข้ทิ้งไปเยอะ แต่สงสัยคงต้องใส่ใน variable ครับ พบปัญหาเพิ่มเติมคือว่าถ้าเลือกช่วงเวลามากๆหลายๆวันจะขึ้น range check error
-
ทำไปในเงื่อนไขหลักๆไม่ได้ครับ จะตัดคนไข้ทิ้งไปเยอะ แต่สงสัยคงต้องใส่ใน variable ครับ พบปัญหาเพิ่มเติมคือว่าถ้าเลือกช่วงเวลามากๆหลายๆวันจะขึ้น range check error
กลุ่มเป้าหมายสำคัญ คือ กล่มที่ได้รับบริการ...ครบอย่างน้อยกี่ขึ้นตอน นั่นคือ คำตอบ ของการออกแบบชุดคำสั่ง ถ้าบอกว่า จะเอาผ่านห้องยา ว่า ทุกรายเฉลี่ยรับบริการกี่นาที ตั้งแต่เข้ามารพ. ต้องยอมตัดข้อมูลส่วนที่ไม่ได้ไปรับยาออกครับ มิเช่นนั้น เวลาเฉลี่ยต่อราย จะคลาดเคลื่อน แต่ควรวิเคราะห์แบบรายเดือน หรือ รายไตรมาส ครับ..เฉพาะวันทำการ ห้ามเอา vstdate ที่ตรงกับวันในตาราง holiday เพราะจะคลาดเคลื่อนสูงครับ
-
select time_format(sec_to_time(sum(time_to_sec(service3))),"%H:%i:%s") from service_time
where vstdate between "2011-10-01" and "2011-10-31"
เขียนคำสั่งแบบนี้ ถ้าใช้แค่ sum สามารถรวมได้ แต่จะแปลงกลับมาเป็นชั่วโมงนาทีจะออกมาเป็น 838:59:59 ครับ เป็นกับหลายๆฟิลด์ครับ ขอบคุณครับ ไม่แน่ใจว่าทำอะไรผิดหรือเปล่า
-
select time_format(sec_to_time(sum(time_to_sec(service3))),"%H:%i:%s") from service_time
where vstdate between "2011-10-01" and "2011-10-31"
เขียนคำสั่งแบบนี้ ถ้าใช้แค่ sum สามารถรวมได้ แต่จะแปลงกลับมาเป็นชั่วโมงนาทีจะออกมาเป็น 838:59:59 ครับ เป็นกับหลายๆฟิลด์ครับ ขอบคุณครับ ไม่แน่ใจว่าทำอะไรผิดหรือเปล่า
select time_format(sec_to_time(sum(time_to_sec(service3))/3600),"%H:%i:%s") from service_time
where vstdate between "2011-10-01" and "2011-10-31" กรณีนี้หารด้วย 3600 จะได้ชั่วโมงออกมา เหมือนจะได้คำตอบด้วยตัวเอง พยายามค้นหาหลายสูตรมากมายนะครับ แต่ผิดถูกอย่างไรอยากรบกวนพี่ๆช่วยอธิบายหลักการและเหตุผลเพิ่มเติมให้ด้วยครับ เผื่อจะได้เข้าใจมากกว่านี้ ขอบคุณครับ
-
เงื่อนไขที่เขียน สรุปว่า วันหยุดเสาร์ อาทิตย์ หรือ นักขัตฤกษ์ ก็จะนับใช่ไหมคัรบ อย่างนั้น ระยะเวลารอคอยก็จะน้อยลง เพราะชัด ๆ ว่า ว่าหยุด บริการได้เร็วกว่าวันธรรมดา ด้วยจำนวนผู้รับบริการ และลักษณะบริการที่ไม่สามารถซับซ้อนได้ นอกจากนัดมา F/U ในวันทำการ ครับ
-
ตอนนี้ได้คำตอบของการหาเวลาแล้วครับ แล้วก็แยกแต่ละช่วงเวลาอย่างละเอียดต่อไป รอบนี้จะเหนื่อยครั้งเดียว และจะส่งเข้ามาให้พี่ๆช่วยตรวจอีกครั้งครับ
-
set @d1="2011-10-01";
set @d2="2012-09-30";
select month(v.vstdate) as "VMONTH",v.vstdate,v.vn,v.hn
,count(v.vn) as "CountVisitAll"
,e.CountVisitER,e.ErTime
,la.CountVisitLab,la.LabReceiveTime,la.LabReportTime,la.LabAllTime
,x.CountVisitXray,x.XrayExaminedTime
,ss.*
,s1.*
from vn_stat v
left join (select vn as "ssvn",month(vstdate) as "MONTH",vstdate
,sum(if(service3_dep is not null and service4_dep is not null
and service5_dep is not null
and service6_dep is not null
and service7_dep is not null
and service11_dep is not null
and service12_dep is not null
and service19_dep is not null
and service7_dep="019",1,0)) as "CountVisitAllProcess"
,sum(if(service3_dep is not null
and service4_dep is not null
and service5_dep is not null
and service6_dep is not null
and service7_dep is null
and service11_dep is not null
and service12_dep is not null
and service19_dep is not null
and service19_dep="030",1,null)) as "CountVisittoRx"
,sum(if(service3_dep is not null
and service4_dep is not null
and service5_dep is not null
and service6_dep is null
and service7_dep is null
and service11_dep is not null
and service12_dep is not null
and service19_dep is null,1,null)) as "CountVisittoExam"
,sum(if(service3_dep is not null
and service4_dep is not null
and service5_dep is null
and service6_dep is null
and service7_dep is null
and service11_dep is not null
and service12_dep is null
and service19_dep is null,1,null)) as "CountVisittoScreen"
from service_time
where vstdate between @d1 and @d2
group by MONTH) ss on ss.ssvn=v.vn
left join(select vn as "evn",vstdate,month(vstdate) as "EMONTH",count(vn) as "CountVisitER"
,sec_to_time(mod(sum(timediff(finish_time,enter_er_time)),86400)) as "ErTime"
from er_regist
where vstdate between @d1 and @d2 group by EMONTH) e on e.vstdate=v.vstdate
left join(select vn as "lavn",hn as "lahn",order_date,count(vn) as "CountVisitLab",month(order_date) as "LMONTH"
,sec_to_time(mod(sum(timediff(receive_time,order_time)),86400)) as "LabReceiveTime"
,sec_to_time(mod(sum(timediff(report_time,receive_time)),86400)) as "LabReportTime"
,sec_to_time(mod(sum(timediff(report_time,order_time)),86400)) as "LabAllTime"
from lab_head
where order_date between @d1 and @d2 group by LMONTH) la on la.order_date=v.vstdate
left join(select vn as "xvn",month(request_date) as "XMONTH",vn,request_date,examined_date,report_date,count(vn) as "CountVisitXray"
,sec_to_time(abs(timediff(examined_time,request_time))) as "XrayExaminedTime"
from xray_report
where request_date between @d1 and @d2
group by XMONTH) x on x.request_date=v.vstdate
left join(select vn as "vn1",vstdate,month(vstdate) as "SMONTH"
,sec_to_time(mod(abs(sum(time_to_sec(service3)-time_to_sec(service20))),86400)) as totaltimetoregist
,sec_to_time(mod(abs(sum(time_to_sec(service4)-time_to_sec(service3))),86400)) as waitforscreen
,sec_to_time(mod(abs(sum(time_to_sec(service11)-time_to_sec(service4))),86400)) as totaltimetoscreen
,sec_to_time(mod(abs(sum(time_to_sec(service5)-time_to_sec(service11))),86400)) as waitfordoctor
,sec_to_time(mod(abs(sum(time_to_sec(service12)-time_to_sec(service5))),86400)) as totaltimetodoctor
,sec_to_time(mod(abs(sum(time_to_sec(service6)-time_to_sec(service12))),86400)) as waitforrx
,sec_to_time(mod(abs(sum(time_to_sec(service19)-time_to_sec(service6))),86400)) as totaltimetorxmode2
,sec_to_time(mod(abs(sum(time_to_sec(service7)-time_to_sec(service19))),86400)) as totaltimetofinance
,sec_to_time(mod(abs(sum(time_to_sec(service12)-time_to_sec(service3))),86400)) as vsttimetofinishexam
,sec_to_time(mod(abs(sum(time_to_sec(service19)-time_to_sec(service3))),86400)) as vsttimetofinishrx
,sec_to_time(mod(abs(sum(time_to_sec(service7)-time_to_sec(service3))),86400)) as vsttimetofinishfinance
,sec_to_time(mod(abs(sum(time_to_sec(service19)-time_to_sec(service6))),86400)) as finishexamtostartrx
,sec_to_time(mod(abs(sum(time_to_sec(service19)-time_to_sec(service12))),86400)) as finishexamtofinishrx
from service_time
where vstdate between @d1 and @d2
group by SMONTH) s1 on v.vn=s1.vn1
left join service_time s on v.vn=s.vn
where v.vstdate between @d1 and @d2
group by VMONTH
แบบนี้ไม่มี Range Check Error แต่อาจจะผิดพลาดได้กรณีค่าตัวลบอาจมากกว่าตัวตั้งต้องลองทดสอบทีละรายการต่อไปครับ แต่เบื้องต้นได้มาแบบนี้ครับ แปลกจริงครับบางตาราง JOIN ด้วย VN ไม่มีค่าต้อง JOIN ด้วย date ที่เป็นเงื่อนไขแทนครับ ตอนนี้เหลือตรงแลบที่อาจจะต้องแก้ไขการ JOIN และเพิ่ม LEFT JOIN มาอีกจะลองดู แล้วจะรบกวนให้ช่วยทำสอบครับว่าถูกต้องหรือเปล่าครับ ขอบคุณครับ
-
รบกวนเจ้าของรายงานอีกนิดนะครับ ผมมือใหม่ SQL ครับ ยังไม่ชำนาญจะขอรบกวนนิดนึงครับ ว่า
ถ้าในช่อง "รวมเวลารับบริการ" เราจะนับได้เปล่าครับ ว่า รวมแล้ว ใครใช้ เาลา เกินกำหนด 1ชั่วโมง 30 นาที กี่ คน ไม่เกินเวลาที่กำหลดกี่คน แยกมาสรุปท้ายรายงานนะครับ ต้องทำยังไงครับ