String evTable = "select * from erp_visit erv " +
"where erv.DISCHARGE_DATE_TIME is null and erv.patient_id=?1 and rownum=1 " +
"order by erv.ACCEPT_DATE_TIME desc";
String sql = "select pmi.patient_id,ev.visit_no,pmi.name,pmi.sex,pmi.date_of_birth,pmi.next_of_kin,pmi.next_of_kin_phone," +
"ev.dise_level_code,ev.discipline_code,ev.green_channel,ev.arrival_date_time," +
"ov.identity,ov.charge_type,ov.visit_dept_code," +
"pa.outp_prepayments " +
"from pat_master_index pmi,outp_visit ov,(" + evTable + ") ev,prepayment_account pa " +
"where ev.patient_id=pmi.patient_id " +
"and ev.visit_no=ov.visit_no " +
"and pmi.patient_id=pa.patient_id";