==========DM ล้วน======
select dm_all.hn,pname,fname,lname,birthday,addrpart,moopart,tmbpart,amppart,chwpart from
(select pt.hn,pt.pname,pt.fname,pt.lname,pt.birthday,pt.addrpart,pt.moopart,pt.tmbpart,pt.amppart,pt.chwpart
from clinicmember c
left outer join patient pt on pt.hn=c.hn
where c.clinic="001" and pt.death<>"Y") as dm_all
left outer join (select hn from clinicmember where clinic="002")as ht on ht.hn=dm_all.hn
where ht.hn is null
=======DM+HT==
select dm_all.hn,pname,fname,lname,birthday,addrpart,moopart,tmbpart,amppart,chwpart from(
select pt.hn,pt.pname,pt.fname,pt.lname,pt.birthday,pt.addrpart,pt.moopart,pt.tmbpart,pt.amppart,pt.chwpart
from clinicmember c
left outer join patient pt on pt.hn=c.hn
where c.clinic="001" and pt.death<>"Y") as dm_all
inner join (select hn from clinicmember where clinic="002")as ht on ht.hn=dm_all.hn
=======กลุ่มโรคแทรกอื่นๆ==========
select distinct pt.hn from clinicmember c
left outer join patient pt on pt.hn=c.hn
left outer join ovstdiag d on c.hn=d.hn
where c.clinic="001" and pt.death<>"Y"
and (icd10="N189" or icd10="I259" or icd10="I48" or icd10="E113" or icd10="H360")
เอา กลุ่ม 1,2,3 มา join กับตัวนี้
==============HBA1C_2
SELECT
lh.hn,lo.lab_items_code,GROUP_CONCAT(lo.lab_order_result ORDER BY lh.order_date)AS zz,
SUBSTRING_INDEX(GROUP_CONCAT(lo.lab_order_result ORDER BY lh.order_date),',',1)AS A1C_1,
IF((1 + LENGTH(GROUP_CONCAT(lo.lab_order_result ORDER BY lh.order_date))-
LENGTH(REPLACE(GROUP_CONCAT(lo.lab_order_result ORDER BY lh.order_date), ',', '')))>1,
SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(lo.lab_order_result ORDER BY lh.order_date),',',2),',',-1),'')AS A1C_2,
IF((1 + LENGTH(GROUP_CONCAT(lo.lab_order_result ORDER BY lh.order_date))-
LENGTH(REPLACE(GROUP_CONCAT(lo.lab_order_result ORDER BY lh.order_date), ',', '')))>2,
SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(lo.lab_order_result ORDER BY lh.order_date),',',3),',',-1),'')AS A1C_3,
IF((1 + LENGTH(GROUP_CONCAT(lo.lab_order_result ORDER BY lh.order_date))-
LENGTH(REPLACE(GROUP_CONCAT(lo.lab_order_result ORDER BY lh.order_date), ',', '')))>3,
SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(lo.lab_order_result ORDER BY lh.order_date),',',4),',',-1),'')AS A1C_4
FROM lab_head lh
LEFT OUTER JOIN lab_order lo ON lh.lab_order_number=lo.lab_order_number
WHERE lo.lab_items_code="193"
AND lh.hn IN(
SELECT pt.hn FROM clinicmember c
LEFT OUTER JOIN patient pt ON pt.hn=c.hn
WHERE c.clinic="001" AND pt.death<>"Y")
AND lh.order_date BETWEEN"2014-11-01"AND"2015-10-30"
AND lab_order_result <>""
GROUP BY lh.hn
===================
วันพุธที่ 4 พฤศจิกายน พ.ศ. 2558
วันอังคารที่ 3 พฤศจิกายน พ.ศ. 2558
นับประชากรตามtype
SELECT
village.village_moo,
village.village_name,
sum(IF(person.house_regist_type_id=1,1,0)) as typearea1,
sum(IF(person.house_regist_type_id=2,1,0)) as typearea2,
sum(IF(person.house_regist_type_id=3,1,0)) as typearea3,
sum(IF(person.house_regist_type_id=4,1,0)) as typearea4
FROM
person
INNER JOIN village ON person.village_id = village.village_id
GROUP BY village.village_name
village.village_moo,
village.village_name,
sum(IF(person.house_regist_type_id=1,1,0)) as typearea1,
sum(IF(person.house_regist_type_id=2,1,0)) as typearea2,
sum(IF(person.house_regist_type_id=3,1,0)) as typearea3,
sum(IF(person.house_regist_type_id=4,1,0)) as typearea4
FROM
person
INNER JOIN village ON person.village_id = village.village_id
GROUP BY village.village_name
วันพฤหัสบดีที่ 29 ตุลาคม พ.ศ. 2558
10 อันดับโรคที่มีค่ารักาษาเยอะสุด hosxp
OPD
select a.pdx,count(a.pdx) as pdx_count ,i.name as icdname ,sum(income) as sum
from vn_stat a
left outer join icd101 i on i.code=a.main_pdx
where a.vstdate between '2014-10-01' and '2015-09-30'
and a.pdx<>'' and a.pdx is not null
group by a.pdx,i.name
order by sum(income) desc
limit 10
IPD
select pdx,name ,count(an),sum(income)/count(an),sum(income) as sumtotal
from an_stat a,icd101 i
where a.dchdate between '2014-10-01' and '2015-09-30'
and a.pdx = i.code
group by pdx
order by sumtotal desc
limit 10
select a.pdx,count(a.pdx) as pdx_count ,i.name as icdname ,sum(income) as sum
from vn_stat a
left outer join icd101 i on i.code=a.main_pdx
where a.vstdate between '2014-10-01' and '2015-09-30'
and a.pdx<>'' and a.pdx is not null
group by a.pdx,i.name
order by sum(income) desc
limit 10
IPD
select pdx,name ,count(an),sum(income)/count(an),sum(income) as sumtotal
from an_stat a,icd101 i
where a.dchdate between '2014-10-01' and '2015-09-30'
and a.pdx = i.code
group by pdx
order by sumtotal desc
limit 10
วันจันทร์ที่ 13 กรกฎาคม พ.ศ. 2558
วันพฤหัสบดีที่ 2 เมษายน พ.ศ. 2558
ย้ายข้อมูลลงฐานใหม่ SQL 2008
ทดสอบย้ายระบบและฐานข้อมูล ความเสี่ยง ไปเครื่องใหม ย้าย database sql server 2008 ตามขั้นตอนนี้
เพื่อความปลอดภัยให้ทำการCopy ฐานข้อมูลของเครื่องเก่าไว้ก่อน โดยไปที่ C:\Program Files\Microsoft SQL Server\MSSQL10.(ชื่อserver)\MSSQL\DATA แล้วไปcopy ฐานข้อมูลไว้ตามชื่อฐานข้อมูล copyไว้ทั้งสองไฟล์ (.ldf,.mdf)
ให้สร้าง User ใน sql server 2008 เครื่องใหม่ไว้ก่อน แล้วสร้าง database ตามชื่อที่ต้องการ Import เข้ามา(เครื่องใหม่)
*การสร้าง user ขึ้นมาใหม่ ให้ไปที่ Security –> Login –> คลิกขวา Add new login–> ตรง General ใส่ Username และ Password ให้ไปที่ Tab Server Role ต่อ แล้วให้ติ๊กถูกหมดทุกข้อ
ทำการ สร้างฐานข้อมูลในเครื่องใหม่ก่อนโดยใช้ชื่อฐานข้อมูลเดียวกันในที่นี้คือdbRisk
ไปที่ฐานข้อมูลเก่า dbRisk คลิกขวา –> tasks –> generate script –> เลือกฐานข้อมูล reservation_system ให้ติ๊กถูกช่อง script all object in the select all database –> ตรง Output ให้เลือก Script to new query window –> เมื่อเสร็จก็จะได้ Script ที่จะใช้สำหรับสร้างตารางและโครงสร้างต่างๆ
ไปที่ฐานข้อมูลใหม่ให้เปิดหน้า Script ขึ้นมา วางScript แล้วให้ทำการ Execute Script
ไปที่เครื่องใหม่ให้ ให้เปิดโปรแกรม Import and Export Data (64 bit) เมื่อเปิดโปรแกรมให้เลือกต้นทางที่จะทำการ Export –> เลือกปลายที่จะทำการ Import –> เลือก Copy Data From One Or More Table Or Views –> เลือก table ทั้งหมด กด Edit Mappings ส่วน Destination schema name เลือก dbo ติ๊กถูก (Delete rows in existing destination tables ข้อมูลฝั่งDesinationจะหาย) , Enable identity insert –> Run immediately กด Finish
เสร็จสิ้นในส่วนนำข้อมูลจาก SQL Server มาใช้สามารถเช็คฐานข้อมูลใหม่ดูในแต่ละตารางว่ามาครบหรือไม่
Credit : http://km.phuket.psu.ac.th/?p=483
วันอังคารที่ 10 กุมภาพันธ์ พ.ศ. 2558
sql ต่างๆ
เบาหวาน
select p.hn,p.cid as ID,concat(p.pname,p.fname)as Name, p.lname as Last_n,concat(DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),p.birthday)),"%Y")+0, " ปี") as age,p.sex,if(p.sex="1","ชาย","หญิง")as Sex, DATE_FORMAT(DATE_ADD(p.birthday, INTERVAL 543 YEAR),"%m/%d/%Y") as BirthD
from ovstdiag o
left join ovst ov on o.vn=ov.vn
left join opdscreen op on o.vn=op.vn
left join patient p on o.hn=p.hn
where o.icd10 in("E119","E113") and p.death<>"Y" and DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),p.birthday)),"%Y")+0 >="60" and p.sex ="2"
and p.moopart IN("01","1","02","2","03","3","04","4","05","5","06","6","07","7","10","11","12") and p.tmbpart in("02","2") and p.amppart ="16" and p.chwpart ="47"
group by o.hn
คำนวนหาอายุวันเดือนปี
select pt.birthday,curdate(),
timestampdiff(year,pt.birthday,curdate()) as age_y,
timestampdiff(month,pt.birthday,curdate())-(timestampdiff(year,pt.birthday,curdate())*12) as age_m,
timestampdiff(day,date_add(pt.birthday,interval (timestampdiff(month,pt.birthday,curdate())) month),curdate()) as age_d
from patient pt
where pt.hn='0051709'
นับผู้ป่วย7สีในคลินิกเบาหวาน คำนวนจากค่า fbs
SELECT COUNT(DISTINCT(opdscreen.hn)) FROM opdscreen
LEFT OUTER JOIN patient ON opdscreen.hn=patient.hn
Where (opdscreen.fbs BETWEEN '125' and '154')
and opdscreen.hn in(Select distinct(clinicmember.hn) from clinicmember where clinicmember.clinic='001' )
and opdscreen.vstdate between '2014-10-01' and '2014-10-31'
นับผู้ป่วย7สีในคลินิกเบาหวาน คำนวนจากค่า ความดัน
SELECT COUNT(DISTINCT(opdscreen.hn)) FROM opdscreen
LEFT OUTER JOIN patient ON opdscreen.hn=patient.hn
Where ((opdscreen.bps BETWEEN '110' and '120') and (opdscreen.bpd BETWEEN '60' and '89'))
and opdscreen.hn in(Select distinct(clinicmember.hn) from clinicmember where clinicmember.clinic='001' )
and opdscreen.vstdate between '2014-10-01' and '2014-10-31'
คัดกรองต้อกระจก 60 ปีขึ้นไป
select pt.hn,ov.vn,pt.pname,pt.fname,pt.lname,pt.birthday,pt.informaddr,ov.pdx,ov.dx_doctor,ov.dx0,ov.dx1,ov.age_y,ov.vstdate,pt.type_area
from vn_stat ov ,patient pt ,ovst ovst
where ov.vn=ovst.vn and pt.hn=ov.hn and ov.vstdate between "2014-10-01" and "2014-12-30" and ov.hn=pt.hn
and ov.age_y>= 60
and ov.age_y<= 200
and ( (ov.pdx >= "Z010" and ov.pdx <= "Z010")
or (ov.dx0 >= "H540" and ov.dx0 <= "H545")
)
ผู้ป่วย 60-69 ปี ชื่อที่อยู่ type 1,3
SELECT person.cid,person.pname,person.fname,person.lname,person.house_regist_type_id,person.birthdate,person.patient_hn,
person.age_y,person.discharge_date,sex.`name` AS sex,CONCAT(house.address,' หมู่ ',village.village_moo) AS BAN,thaiaddress.full_name
,person.death
FROM
person
INNER JOIN house ON person.house_id = house.house_id
INNER JOIN village ON person.village_id = village.village_id
INNER JOIN thaiaddress ON thaiaddress.addressid = village.address_id
INNER JOIN sex ON person.sex = sex.`code`
WHERE
person.age_y BETWEEN "60" AND "69" AND
person.death = "N" AND village.village_moo <> "0" AND
house_regist_type_id in("1","3") order by village.village_moo,person.age_y ASC
นับจำนวนประชากรแยก ช-ญ
SELECT t1.village_id,t1.village_name,t2.hh AS "ËÅѧ¤ÒàÃ×͹",
MAX(IF(sex='1',cc,NULL))AS "ªÒÂ",
MAX(IF(sex='2',cc,NULL))AS "ËÔ§"
FROM(
SELECT p.village_id,v.village_name,COUNT(sex)AS cc,sex FROM person p
LEFT OUTER JOIN village v ON v.village_id=p.village_id
WHERE p.house_regist_type_id IN('1','3')AND p.village_id<>'99'AND p.person_discharge_id='9'
GROUP BY p.sex, p.village_id )AS t1
INNER JOIN (SELECT h.village_id,COUNT(address)AS hh FROM house h
LEFT OUTER JOIN village v ON v.village_id=h.village_id
WHERE h.village_id <>'99'
GROUP BY h.village_id)AS t2 ON t2.village_id=t1.village_id
GROUP BY village_id
select p.hn,p.cid as ID,concat(p.pname,p.fname)as Name, p.lname as Last_n,concat(DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),p.birthday)),"%Y")+0, " ปี") as age,p.sex,if(p.sex="1","ชาย","หญิง")as Sex, DATE_FORMAT(DATE_ADD(p.birthday, INTERVAL 543 YEAR),"%m/%d/%Y") as BirthD
from ovstdiag o
left join ovst ov on o.vn=ov.vn
left join opdscreen op on o.vn=op.vn
left join patient p on o.hn=p.hn
where o.icd10 in("E119","E113") and p.death<>"Y" and DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),p.birthday)),"%Y")+0 >="60" and p.sex ="2"
and p.moopart IN("01","1","02","2","03","3","04","4","05","5","06","6","07","7","10","11","12") and p.tmbpart in("02","2") and p.amppart ="16" and p.chwpart ="47"
group by o.hn
คำนวนหาอายุวันเดือนปี
select pt.birthday,curdate(),
timestampdiff(year,pt.birthday,curdate()) as age_y,
timestampdiff(month,pt.birthday,curdate())-(timestampdiff(year,pt.birthday,curdate())*12) as age_m,
timestampdiff(day,date_add(pt.birthday,interval (timestampdiff(month,pt.birthday,curdate())) month),curdate()) as age_d
from patient pt
where pt.hn='0051709'
นับผู้ป่วย7สีในคลินิกเบาหวาน คำนวนจากค่า fbs
SELECT COUNT(DISTINCT(opdscreen.hn)) FROM opdscreen
LEFT OUTER JOIN patient ON opdscreen.hn=patient.hn
Where (opdscreen.fbs BETWEEN '125' and '154')
and opdscreen.hn in(Select distinct(clinicmember.hn) from clinicmember where clinicmember.clinic='001' )
and opdscreen.vstdate between '2014-10-01' and '2014-10-31'
นับผู้ป่วย7สีในคลินิกเบาหวาน คำนวนจากค่า ความดัน
SELECT COUNT(DISTINCT(opdscreen.hn)) FROM opdscreen
LEFT OUTER JOIN patient ON opdscreen.hn=patient.hn
Where ((opdscreen.bps BETWEEN '110' and '120') and (opdscreen.bpd BETWEEN '60' and '89'))
and opdscreen.hn in(Select distinct(clinicmember.hn) from clinicmember where clinicmember.clinic='001' )
and opdscreen.vstdate between '2014-10-01' and '2014-10-31'
คัดกรองต้อกระจก 60 ปีขึ้นไป
select pt.hn,ov.vn,pt.pname,pt.fname,pt.lname,pt.birthday,pt.informaddr,ov.pdx,ov.dx_doctor,ov.dx0,ov.dx1,ov.age_y,ov.vstdate,pt.type_area
from vn_stat ov ,patient pt ,ovst ovst
where ov.vn=ovst.vn and pt.hn=ov.hn and ov.vstdate between "2014-10-01" and "2014-12-30" and ov.hn=pt.hn
and ov.age_y>= 60
and ov.age_y<= 200
and ( (ov.pdx >= "Z010" and ov.pdx <= "Z010")
or (ov.dx0 >= "H540" and ov.dx0 <= "H545")
)
ผู้ป่วย 60-69 ปี ชื่อที่อยู่ type 1,3
SELECT person.cid,person.pname,person.fname,person.lname,person.house_regist_type_id,person.birthdate,person.patient_hn,
person.age_y,person.discharge_date,sex.`name` AS sex,CONCAT(house.address,' หมู่ ',village.village_moo) AS BAN,thaiaddress.full_name
,person.death
FROM
person
INNER JOIN house ON person.house_id = house.house_id
INNER JOIN village ON person.village_id = village.village_id
INNER JOIN thaiaddress ON thaiaddress.addressid = village.address_id
INNER JOIN sex ON person.sex = sex.`code`
WHERE
person.age_y BETWEEN "60" AND "69" AND
person.death = "N" AND village.village_moo <> "0" AND
house_regist_type_id in("1","3") order by village.village_moo,person.age_y ASC
นับจำนวนประชากรแยก ช-ญ
SELECT t1.village_id,t1.village_name,t2.hh AS "ËÅѧ¤ÒàÃ×͹",
MAX(IF(sex='1',cc,NULL))AS "ªÒÂ",
MAX(IF(sex='2',cc,NULL))AS "ËÔ§"
FROM(
SELECT p.village_id,v.village_name,COUNT(sex)AS cc,sex FROM person p
LEFT OUTER JOIN village v ON v.village_id=p.village_id
WHERE p.house_regist_type_id IN('1','3')AND p.village_id<>'99'AND p.person_discharge_id='9'
GROUP BY p.sex, p.village_id )AS t1
INNER JOIN (SELECT h.village_id,COUNT(address)AS hh FROM house h
LEFT OUTER JOIN village v ON v.village_id=h.village_id
WHERE h.village_id <>'99'
GROUP BY h.village_id)AS t2 ON t2.village_id=t1.village_id
GROUP BY village_id
วันศุกร์ที่ 16 มกราคม พ.ศ. 2558
การแก้ไขPassword โปรแกรมHosXp ด้วยตัวเอง
ในการเปลี่ยนข้อมูลนั้นด้วยตนเองในHosxp สามารถทำได้ดังนี้
1. ไปที่เมนู System > Show User Information
2.เมื่อเลือกแล้วระบบจะให้ทำการใส่รหัส ซึ่งก็คือpassword ที่เราล็อกอิน Hosxp ปัจจุบัน 3.จะเข้าสู่หน้าเมนูข้อมูลส่วนบุคคล จากนั้นท่านสามารถเปลี่ยน password เมื่อทำการแก้ไขแล้วให้กดบันทึก เป็นอันเสร็จสิ้นการเปลี่ยนpassword ครับ
1. ไปที่เมนู System > Show User Information
2.เมื่อเลือกแล้วระบบจะให้ทำการใส่รหัส ซึ่งก็คือpassword ที่เราล็อกอิน Hosxp ปัจจุบัน 3.จะเข้าสู่หน้าเมนูข้อมูลส่วนบุคคล จากนั้นท่านสามารถเปลี่ยน password เมื่อทำการแก้ไขแล้วให้กดบันทึก เป็นอันเสร็จสิ้นการเปลี่ยนpassword ครับ
สมัครสมาชิก:
ความคิดเห็น (Atom)



