public class GuaHaoDao {
public ResultSet guahaoList(Connection con,PageBean pageBean,Patient patient,GuaHao guahao, String s_bGhDate, String s_eGhDate)throws Exception{
StringBuffer sb=new StringBuffer("SELECT * FROM t_ghinfo g ,t_patient p ,t_user u WHERE p.userId=u.userId AND g.patientId=p.patientId");
if(patient.getUserId()!=-1){
sb.append(" and p.userId = '"+patient.getUserId()+"'");
}
if(StringUtil.isNotEmpty(guahao.getPatientName())){
sb.append(" and p.patientName like '%"+guahao.getPatientName()+"%'");
}
if(StringUtil.isNotEmpty(patient.getSex())){
sb.append(" and p.sex ='"+patient.getSex()+"'");
}
if(StringUtil.isNotEmpty(s_bGhDate)){
sb.append(" and TO_DAYS(g.date)>=TO_DAYS('"+s_bGhDate+"')");
}
if(StringUtil.isNotEmpty(s_eGhDate)){
sb.append(" and TO_DAYS(g.date)<=TO_DAYS('"+s_eGhDate+"')");
}
if(StringUtil.isNotEmpty(guahao.getOfficeName())){
sb.append(" and g.officeName ='"+guahao.getOfficeName()+"'");
}
//分页
if(pageBean!=null){
sb.append(" limit "+pageBean.getStart()+","+pageBean.getRows());
}
PreparedStatement pstmt=con.prepareStatement(sb.toString());
return pstmt.executeQuery();
}
/**
* 获取数据总条数
* @param con
* @param grade
* @return
* @throws Exception
*/
public int guahaoCount(Connection con,Patient patient, GuaHao guahao, String s_bGhDate, String s_eGhDate)throws Exception{
StringBuffer sb=new StringBuffer("select count(*) as total from t_ghinfo g ,t_patient p ,t_user u WHERE p.userId=u.userId AND g.patientId=p.patientId");
if(patient.getUserId()!=-1){
sb.append(" and p.userId = '"+patient.getUserId()+"'");
}
if(StringUtil.isNotEmpty(guahao.getPatientName())){
sb.append(" and p.patientName like '%"+guahao.getPatientName()+"%'");
}
if(StringUtil.isNotEmpty(patient.getSex())){
sb.append(" and p.sex ='"+patient.getSex()+"'");
}
if(StringUtil.isNotEmpty(s_bGhDate)){
sb.append(" and TO_DAYS(g.date)>=TO_DAYS('"+s_bGhDate+"')");
}
if(StringUtil.isNotEmpty(s_eGhDate)){
sb.append(" and TO_DAYS(g.date)<=TO_DAYS('"+s_eGhDate+"')");
}
if(StringUtil.isNotEmpty(guahao.getOfficeName())){
sb.append(" and g.officeName ='"+guahao.getOfficeName()+"'");
}
PreparedStatement pstmt=con.prepareStatement(sb.toString());
ResultSet rs=pstmt.executeQuery();
if(rs.next()){
return rs.getInt("total");
}else{
return 0;
}
}