select o1.*,v1.*,s.*,pe.*,concat(p.pname,p.fname,' ',p.lname) as patient_name,
p.drugallergy,p.clinic as patient_clinic,p.nationality,p.hometel as pt_tel,
p2.pttype as pttype_pttype,p2.name as pttype_name,p2.pcode as pttype_pcode,
p2.requirecode as pttype_requirecode,p2.require_hcode as pttype_require_hcode,
oo.vn as observe_vn,oo.observe_id,oo.send_date_time as observe_intime,
oo.leave_date_time as observe_outtime,oo.symptom as observe_symptom,
oo.nurse_activity as observe_activity,oo.note as observe_note,
oo.ward as observe_ward,pp.name as pt_priority_name,pw.name as pt_walk_name,
concat(help3_icode,' # ',if(help3_qty is null,'',help3_qty)) as help3_drug_name,
iaq.vn as admit_vn,w1.name as admit_ward,es.vn as eye_vn,es.*,s.vn as opdscreen_vn ,opd_ill_history.cc_persist_disease ,visit_note.ptnote,do.name as doctor,op.name as labstaff
from ovst o1
left outer join vn_stat v1 on v1.vn = o1.vn
left outer join lab_head lh on lh.vn=o1.vn
left outer join opdscreen s on s.vn = o1.vn
left outer join pe_image pe on pe.vn = o1.vn
left outer join opd_observe oo on oo.vn = o1.vn
left outer join patient p on p.hn = o1.hn
left outer join doctor do on do.code=lh.doctor_code
left outer join opduser op on op.loginname=lh.reporter_name and op.lab_staff="Y"
left outer join pttype p2 on p2.pttype = v1.pttype
left outer join pt_priority pp on pp.id = o1.pt_priority
left outer join pt_walk pw on pw.walk_id = s.walk_id
left outer join ipt_admit_queue iaq on iaq.vn = o1.vn
left outer join ward w1 on w1.ward = iaq.request_ward
left outer join eye_screen es on es.vn = o1.vn
left outer join opd_ill_history ON o1.hn = opd_ill_history.hn
left outer join visit_note on o1.vn = visit_note.vn
where o1.vn = "540304080246"