BMS-HOSxP Community
HOSxP => แจ้งปัญหา / ขอความช่วยเหลือ => ข้อความที่เริ่มโดย: Guitar-hero ที่ ธันวาคม 13, 2013, 09:03:47 AM
-
คือผมเขียน SQL แปรผล ค่าแลป GFR แต่ติดอยู่นิดนึงครับ ว่าในคนไข้บางคนมีการตรวจ GFR ในเดือนนั้นมากกว่า 1 ครั้ง โดยผมต้องการแสดงข้อมูลผล GFR โดยมีเงื่อนไขอยู่ว่า ให้แสดงผล GFR เป็นรายคน ไม่ใช่รายครั้ง และต้องเป็น การตรวจ lab GFR ครั้งล่าสุด ผมติดอยู่ตรงที่ดึงข้อมูลการตรวจ ครั้งล่าสุด อ่ะครับ รบกวนท่านผู้รู้แนะนำหน่อยครับ
นี่คือ SQL ที่ผมเขียนครับ
select
lh.lab_order_number,lh.vn,lh.hn,lh.order_date,lh.report_date,lh.department ,
cl.clinic,cl.other_chronic_text ,lo.lab_items_code, lo.lab_order_result,
concat(pt.pname,pt.fname,' ',pt.lname) as pt_name,
(
SELECT CASE
WHEN (lo.lab_order_result >=90) THEN '1'
WHEN (lo.lab_order_result >=60 AND lo.lab_order_result <=89.99) THEN '2'
WHEN (lo.lab_order_result >=30 AND lo.lab_order_result <=59.99) THEN '3A'
WHEN (lo.lab_order_result >=15 AND lo.lab_order_result <=29.99) THEN '4'
ELSE '5' END
) AS lab_order_result_report
from lab_head lh
left outer join clinicmember cl on cl.hn = lh.hn
left outer join lab_order lo on lo.lab_order_number = lh.lab_order_number
left outer join patient pt on pt.hn = lh.hn
where lh.report_date between "2013-10-01" and "2013-10-31" and
cl.clinic="001" and cl.clinic_member_status_id="3"
and lo.lab_items_code="3248" GROUP BY lh.hn
-
select a.*,concat(pt.pname,pt.fname,' ',pt.lname) ptname
,s.vstdate,s.creatinine,s.egfr
,if (egfr>=90,'1'
,if (egfr>=60,'2'
,if (egfr>=30,'3'
,if (egfr>=15,'4'
,if (egfr>0,'5',''))))) stage
from (select max(s.vn) vn,c.hn
from clinicmember c
left join opdscreen s on c.hn=s.hn
where s.vstdate between '2013-10-01' and '2013-12-31'
and c.clinic=001
and c.clinic_member_status_id=1
and s.creatinine>0
group by c.hn) a
left join patient pt on pt.hn=a.hn
left join opdscreen s on a.vn=s.vn
ถ้าเอาผล creatinine จาก opdscreen หล่ะ
-
ตาราง ovst_gfr ก็น่าสนใจนะครับ
select * from ovst_gfr join ด้วย vn จาก opdscreen หรือ hn เฉพาะที่เป็นเบาหวานหรือความดัน ไม่น่าจะนำมาจากทุก HN ครับ เน้นตารางนี้เพราะมีแค่เรื่อง ของ Creatinin,CKD-EPI, eGFR
-
เยี่ยมเลยครับ อ.เกื้อ
-
ทำยังไงให้มีข้อมูลในตาราง ovst_gfr นี้ครับ
-
ทำยังไงให้มีข้อมูลในตาราง ovst_gfr นี้ครับ
------------------------------
น่าจะต้องมีการเปิด popup gfr ให้แสดง หรือทำงาน ก่อนครับ ข้อมูลถึงจะถูกบันทึกลงในตาราง ovst_gfr
http://hosxp.net/index.php?option=com_smf&Itemid=28&topic=29226.msg244230#msg244230
-
max(lh.order_date) เอา lh.vn ออก ก็น่าจะได้ครั้งล่าสุดแล้วนะครับ