select rfo.refer_date,rfo.refer_time,ov.hn,concat_ws(" ",pt.pname,pt.fname,pt.lname) ptname,icd.name dxname,doctor.name,
rc.name rfrcause,ov.o_refer_dep,concat_ws(" ",hc.hosptype,hc.name) tohosname
from ovst ov
left outer join patient pt on pt.hn=ov.hn
left outer join rfrcs rc on rc.rfrcs=ov.rfrocs
left outer join doctor on ov.doctor=doctor.code
left outer join referout rfo on rfo.vn=ov.vn
left outer join hospcode hc on hc.hospcode=ov.rfrolct
left outer join ovstdiag dx on dx.hn=ov.hn and dx.vstdate=ov.vstdate and dx.vsttime=ov.vsttime and dx.diagtype="1"
left outer join icd101 icd on icd.code=dx.icd10
where ov.vstdate >="2007-01-01" and ov.vstdate<="2007-03-28"
and ov.rfrolct="10692"
order by rfo.refer_date,rfo.refer_time,pt.fname