select i.vn, i.hn,i.icode,i.qty,d.units,
if(i.drugusage<>"",concat(u.name1, ' ', u.name2, ' ', u.name3),concat(u1.name1, ' ', u1.name2, ' ', u1.name3)) as usuge
from opitemrece i
left join drugitems d on d.icode=i.icode
left join drugusage u on u.drugusage=i.drugusage
left join sp_use u1 on u1.sp_use=i.sp_use
left join ovstdiag o on o.vn = i.vn
left join patient pt on pt.hn = i.hn
where
(o.icd10 in ("+icd+") or o.icd103 in ("+icd+"))
and pt.hn=o.hn and pt.cid <> '' and SUBSTR(pt.cid,1) <> 0
and o.vstdate BETWEEN '2012-05-01' and '2012-05-18'
and i.income='03' and i.vn is not null
group by i.vn