|  | @ -1530,4 +1530,397 @@ public class DoctorSchemeService extends BaseService{
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         return list;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> getTrackPatientIndexCountList(String doctor,Integer teamCode,String type,String startDate,String endDate,String keyword,Integer page,Integer size){
 | 
	
		
			
				|  |  |         startDate = startDate+" 00:00:00";
 | 
	
		
			
				|  |  |         endDate = endDate + " 23:59:59";
 | 
	
		
			
				|  |  |         // /血糖查询
 | 
	
		
			
				|  |  |         if("1".equals(type)){
 | 
	
		
			
				|  |  |             List<Map<String,Object>> list = jdbcTemplate.queryForList(getXTTrackPatientIndexCountListSql(doctor,teamCode,startDate,endDate,keyword, page, size));
 | 
	
		
			
				|  |  |             return list;
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             List<Map<String,Object>> list = jdbcTemplate.queryForList(getXYTrackPatientIndexCountListSql(doctor,teamCode,startDate,endDate,keyword, page, size));
 | 
	
		
			
				|  |  |             return list;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public String getXTTrackPatientIndexCountListSql(String doctor,Integer teamCode,String startDate,String endDate,String keyword,Integer page,Integer size){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sql = "SELECT  " +
 | 
	
		
			
				|  |  |                 " tt1.patient_code, " +
 | 
	
		
			
				|  |  |                 " tt1.highCount, " +
 | 
	
		
			
				|  |  |                 " tt2.lowCount, " +
 | 
	
		
			
				|  |  |                 " tt3.stdCount, " +
 | 
	
		
			
				|  |  |                 " p.`name`, " +
 | 
	
		
			
				|  |  |                 " IFNULL(year( from_days( datediff( now(), p.birthday))),'未知') age, " +
 | 
	
		
			
				|  |  |                 " p.photo, " +
 | 
	
		
			
				|  |  |                 " p.idcard " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 "( " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 " SELECT " +
 | 
	
		
			
				|  |  |                 " t1.patient_code, " +
 | 
	
		
			
				|  |  |                 " t2.total + t1.total AS highCount " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 " ( " +
 | 
	
		
			
				|  |  |                 "  SELECT " +
 | 
	
		
			
				|  |  |                 "   t.patient_code, " +
 | 
	
		
			
				|  |  |                 "   IFNULL(pid.total, 0) AS total " +
 | 
	
		
			
				|  |  |                 "  FROM " +
 | 
	
		
			
				|  |  |                 "   ( " +
 | 
	
		
			
				|  |  |                 "    SELECT " +
 | 
	
		
			
				|  |  |                 "     tp.patient_code " +
 | 
	
		
			
				|  |  |                 "    FROM " +
 | 
	
		
			
				|  |  |                 "     wlyy_track_patient tp " +
 | 
	
		
			
				|  |  |                 "    WHERE " +
 | 
	
		
			
				|  |  |                 "     tp.del = '1' " +
 | 
	
		
			
				|  |  |                 "    AND tp.doctor_code = '"+doctor+"' " +
 | 
	
		
			
				|  |  |                 "    AND tp.team_code = " +teamCode+
 | 
	
		
			
				|  |  |                 "   ) t " +
 | 
	
		
			
				|  |  |                 "  LEFT JOIN ( " +
 | 
	
		
			
				|  |  |                 "   SELECT " +
 | 
	
		
			
				|  |  |                 "    i. USER, " +
 | 
	
		
			
				|  |  |                 "    COUNT(1) AS total " +
 | 
	
		
			
				|  |  |                 "   FROM " +
 | 
	
		
			
				|  |  |                 "    device.wlyy_patient_health_index i " +
 | 
	
		
			
				|  |  |                 "   WHERE " +
 | 
	
		
			
				|  |  |                 "    i.del = '1' " +
 | 
	
		
			
				|  |  |                 "   AND i.type = 1 " +
 | 
	
		
			
				|  |  |                 "   AND i.value2 IN (2, 4, 6) " +
 | 
	
		
			
				|  |  |                 "   AND i.value1 > 7.8 " +
 | 
	
		
			
				|  |  |                 "   AND i.i.record_date >='"+startDate+"'" +
 | 
	
		
			
				|  |  |                 "   AND i.i.record_date <='"+endDate+"'" +
 | 
	
		
			
				|  |  |                 "   GROUP BY " +
 | 
	
		
			
				|  |  |                 "    i. USER " +
 | 
	
		
			
				|  |  |                 "  ) pid ON pid. USER = t.patient_code " +
 | 
	
		
			
				|  |  |                 " ) t1  " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 " JOIN  " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 " ( " +
 | 
	
		
			
				|  |  |                 " SELECT " +
 | 
	
		
			
				|  |  |                 "  t.patient_code, " +
 | 
	
		
			
				|  |  |                 "  IFNULL(pid.total, 0) AS total " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 "  ( " +
 | 
	
		
			
				|  |  |                 "   SELECT " +
 | 
	
		
			
				|  |  |                 "    tp.patient_code " +
 | 
	
		
			
				|  |  |                 "   FROM " +
 | 
	
		
			
				|  |  |                 "    wlyy_track_patient tp " +
 | 
	
		
			
				|  |  |                 "   WHERE " +
 | 
	
		
			
				|  |  |                 "    tp.del = '1' " +
 | 
	
		
			
				|  |  |                 "   AND tp.doctor_code = '"+doctor+"' " +
 | 
	
		
			
				|  |  |                 "   AND tp.team_code =" +teamCode+
 | 
	
		
			
				|  |  |                 "  ) t " +
 | 
	
		
			
				|  |  |                 " LEFT JOIN ( " +
 | 
	
		
			
				|  |  |                 "  SELECT " +
 | 
	
		
			
				|  |  |                 "   i. USER, " +
 | 
	
		
			
				|  |  |                 "   COUNT(1) AS total " +
 | 
	
		
			
				|  |  |                 "  FROM " +
 | 
	
		
			
				|  |  |                 "   device.wlyy_patient_health_index i " +
 | 
	
		
			
				|  |  |                 "  WHERE " +
 | 
	
		
			
				|  |  |                 "   i.del = '1' " +
 | 
	
		
			
				|  |  |                 "  AND i.type = 1 " +
 | 
	
		
			
				|  |  |                 "  AND i.value2 IN (1, 3, 5, 7) " +
 | 
	
		
			
				|  |  |                 "  AND i.value1 > 6.1 " +
 | 
	
		
			
				|  |  |                 "  AND i.i.record_date >='"+startDate+"'" +
 | 
	
		
			
				|  |  |                 "  AND i.i.record_date <='"+endDate+"'" +
 | 
	
		
			
				|  |  |                 "  GROUP BY " +
 | 
	
		
			
				|  |  |                 "   i. USER " +
 | 
	
		
			
				|  |  |                 " ) pid ON pid. USER = t.patient_code " +
 | 
	
		
			
				|  |  |                 ") t2 ON t1.patient_code = t2.patient_code " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 ") tt1  " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 " JOIN  " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 "( " +
 | 
	
		
			
				|  |  |                 "  SELECT " +
 | 
	
		
			
				|  |  |                 " t1.patient_code, " +
 | 
	
		
			
				|  |  |                 " t1.total + t2.total AS lowCount " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 " ( " +
 | 
	
		
			
				|  |  |                 "  SELECT " +
 | 
	
		
			
				|  |  |                 "   t.patient_code, " +
 | 
	
		
			
				|  |  |                 "   IFNULL(pid.total, 0) AS total " +
 | 
	
		
			
				|  |  |                 "  FROM " +
 | 
	
		
			
				|  |  |                 "   ( " +
 | 
	
		
			
				|  |  |                 "    SELECT " +
 | 
	
		
			
				|  |  |                 "     tp.patient_code " +
 | 
	
		
			
				|  |  |                 "    FROM " +
 | 
	
		
			
				|  |  |                 "     wlyy_track_patient tp " +
 | 
	
		
			
				|  |  |                 "    WHERE " +
 | 
	
		
			
				|  |  |                 "     tp.del = '1' " +
 | 
	
		
			
				|  |  |                 "    AND tp.doctor_code = '"+doctor+"' " +
 | 
	
		
			
				|  |  |                 "    AND tp.team_code =  " +teamCode+
 | 
	
		
			
				|  |  |                 "   ) t " +
 | 
	
		
			
				|  |  |                 "  LEFT JOIN ( " +
 | 
	
		
			
				|  |  |                 "   SELECT " +
 | 
	
		
			
				|  |  |                 "    i. USER, " +
 | 
	
		
			
				|  |  |                 "    COUNT(1) AS total " +
 | 
	
		
			
				|  |  |                 "   FROM " +
 | 
	
		
			
				|  |  |                 "    device.wlyy_patient_health_index i " +
 | 
	
		
			
				|  |  |                 "   WHERE " +
 | 
	
		
			
				|  |  |                 "    i.del = '1' " +
 | 
	
		
			
				|  |  |                 "   AND i.type = 1 " +
 | 
	
		
			
				|  |  |                 "   AND i.value2 IN (2, 4, 6) " +
 | 
	
		
			
				|  |  |                 "   AND i.value1 < 4.4 " +
 | 
	
		
			
				|  |  |                 "  AND i.i.record_date >='"+startDate+"'" +
 | 
	
		
			
				|  |  |                 "  AND i.i.record_date <='"+endDate+"'" +
 | 
	
		
			
				|  |  |                 "   GROUP BY " +
 | 
	
		
			
				|  |  |                 "    i. USER " +
 | 
	
		
			
				|  |  |                 "  ) pid ON pid. USER = t.patient_code " +
 | 
	
		
			
				|  |  |                 " ) t1  " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 " JOIN  " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 "( " +
 | 
	
		
			
				|  |  |                 " SELECT " +
 | 
	
		
			
				|  |  |                 "  t.patient_code, " +
 | 
	
		
			
				|  |  |                 "  IFNULL(pid.total, 0) AS total " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 "  ( " +
 | 
	
		
			
				|  |  |                 "   SELECT " +
 | 
	
		
			
				|  |  |                 "    tp.patient_code " +
 | 
	
		
			
				|  |  |                 "   FROM " +
 | 
	
		
			
				|  |  |                 "    wlyy_track_patient tp " +
 | 
	
		
			
				|  |  |                 "   WHERE " +
 | 
	
		
			
				|  |  |                 "    tp.del = '1' " +
 | 
	
		
			
				|  |  |                 "   AND tp.doctor_code = '"+doctor+"' " +
 | 
	
		
			
				|  |  |                 "   AND tp.team_code =  " +teamCode+
 | 
	
		
			
				|  |  |                 "  ) t " +
 | 
	
		
			
				|  |  |                 " LEFT JOIN ( " +
 | 
	
		
			
				|  |  |                 "  SELECT " +
 | 
	
		
			
				|  |  |                 "   i. USER, " +
 | 
	
		
			
				|  |  |                 "   COUNT(1) AS total " +
 | 
	
		
			
				|  |  |                 "  FROM " +
 | 
	
		
			
				|  |  |                 "   device.wlyy_patient_health_index i " +
 | 
	
		
			
				|  |  |                 "  WHERE " +
 | 
	
		
			
				|  |  |                 "   i.del = '1' " +
 | 
	
		
			
				|  |  |                 "  AND i.type = 1 " +
 | 
	
		
			
				|  |  |                 "  AND i.value2 IN (1, 3, 5, 7) " +
 | 
	
		
			
				|  |  |                 "  AND i.value1 < 3.9 " +
 | 
	
		
			
				|  |  |                 "  AND i.i.record_date >='"+startDate+"'" +
 | 
	
		
			
				|  |  |                 "  AND i.i.record_date <='"+endDate+"'" +
 | 
	
		
			
				|  |  |                 "  GROUP BY " +
 | 
	
		
			
				|  |  |                 "   i. USER " +
 | 
	
		
			
				|  |  |                 " ) pid ON pid. USER = t.patient_code " +
 | 
	
		
			
				|  |  |                 ") t2 ON t1.patient_code = t2.patient_code " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 ") tt2 ON tt1.patient_code = tt2.patient_code  " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 "JOIN  " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 "( " +
 | 
	
		
			
				|  |  |                 "   " +
 | 
	
		
			
				|  |  |                 " SELECT " +
 | 
	
		
			
				|  |  |                 " t1.patient_code, " +
 | 
	
		
			
				|  |  |                 " t1.total + t2.total AS stdCount " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 " ( " +
 | 
	
		
			
				|  |  |                 "  SELECT " +
 | 
	
		
			
				|  |  |                 "   t.patient_code, " +
 | 
	
		
			
				|  |  |                 "   IFNULL(pid.total, 0) AS total " +
 | 
	
		
			
				|  |  |                 "  FROM " +
 | 
	
		
			
				|  |  |                 "   ( " +
 | 
	
		
			
				|  |  |                 "    SELECT " +
 | 
	
		
			
				|  |  |                 "     tp.patient_code " +
 | 
	
		
			
				|  |  |                 "    FROM " +
 | 
	
		
			
				|  |  |                 "     wlyy_track_patient tp " +
 | 
	
		
			
				|  |  |                 "    WHERE " +
 | 
	
		
			
				|  |  |                 "     tp.del = '1' " +
 | 
	
		
			
				|  |  |                 "    AND tp.doctor_code = '"+doctor+"' " +
 | 
	
		
			
				|  |  |                 "    AND tp.team_code = " +teamCode +
 | 
	
		
			
				|  |  |                 "   ) t " +
 | 
	
		
			
				|  |  |                 "  LEFT JOIN ( " +
 | 
	
		
			
				|  |  |                 "   SELECT " +
 | 
	
		
			
				|  |  |                 "    i. USER, " +
 | 
	
		
			
				|  |  |                 "    COUNT(1) AS total " +
 | 
	
		
			
				|  |  |                 "   FROM " +
 | 
	
		
			
				|  |  |                 "    device.wlyy_patient_health_index i " +
 | 
	
		
			
				|  |  |                 "   WHERE " +
 | 
	
		
			
				|  |  |                 "    i.del = '1' " +
 | 
	
		
			
				|  |  |                 "   AND i.type = 1 " +
 | 
	
		
			
				|  |  |                 "   AND i.value2 IN (2, 4, 6) " +
 | 
	
		
			
				|  |  |                 "   AND i.value1 >= 4.4 " +
 | 
	
		
			
				|  |  |                 "   AND i.value1 <= 7.8 " +
 | 
	
		
			
				|  |  |                 "  AND i.i.record_date >='"+startDate+"'" +
 | 
	
		
			
				|  |  |                 "  AND i.i.record_date <='"+endDate+"'" +
 | 
	
		
			
				|  |  |                 "   GROUP BY " +
 | 
	
		
			
				|  |  |                 "    i. USER " +
 | 
	
		
			
				|  |  |                 "  ) pid ON pid. USER = t.patient_code " +
 | 
	
		
			
				|  |  |                 " ) t1  " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 " JOIN  " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 " ( " +
 | 
	
		
			
				|  |  |                 " SELECT " +
 | 
	
		
			
				|  |  |                 "  t.patient_code, " +
 | 
	
		
			
				|  |  |                 "  IFNULL(pid.total, 0) AS total " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 "  ( " +
 | 
	
		
			
				|  |  |                 "   SELECT " +
 | 
	
		
			
				|  |  |                 "    tp.patient_code " +
 | 
	
		
			
				|  |  |                 "   FROM " +
 | 
	
		
			
				|  |  |                 "    wlyy_track_patient tp " +
 | 
	
		
			
				|  |  |                 "   WHERE " +
 | 
	
		
			
				|  |  |                 "    tp.del = '1' " +
 | 
	
		
			
				|  |  |                 "   AND tp.doctor_code = '"+doctor+"' " +
 | 
	
		
			
				|  |  |                 "   AND tp.team_code = " +teamCode+
 | 
	
		
			
				|  |  |                 "  ) t " +
 | 
	
		
			
				|  |  |                 " LEFT JOIN ( " +
 | 
	
		
			
				|  |  |                 "  SELECT " +
 | 
	
		
			
				|  |  |                 "   i. USER, " +
 | 
	
		
			
				|  |  |                 "   COUNT(1) AS total " +
 | 
	
		
			
				|  |  |                 "  FROM " +
 | 
	
		
			
				|  |  |                 "   device.wlyy_patient_health_index i " +
 | 
	
		
			
				|  |  |                 "  WHERE " +
 | 
	
		
			
				|  |  |                 "   i.del = '1' " +
 | 
	
		
			
				|  |  |                 "  AND i.type = 1 " +
 | 
	
		
			
				|  |  |                 "  AND i.value2 IN (1, 3, 5, 7) " +
 | 
	
		
			
				|  |  |                 "  AND i.value1 >= 3.9 " +
 | 
	
		
			
				|  |  |                 "  AND i.value1 <= 6.1 " +
 | 
	
		
			
				|  |  |                 "  AND i.i.record_date >='"+startDate+"'" +
 | 
	
		
			
				|  |  |                 "  AND i.i.record_date <='"+endDate+"'" +
 | 
	
		
			
				|  |  |                 "  GROUP BY " +
 | 
	
		
			
				|  |  |                 "   i. USER " +
 | 
	
		
			
				|  |  |                 " ) pid ON pid. USER = t.patient_code " +
 | 
	
		
			
				|  |  |                 " ) t2 ON t1.patient_code = t2.patient_code " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 " )tt3 ON tt1.patient_code = tt3.patient_code " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 " JOIN wlyy_patient p On tt1.patient_code =p.code";
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(keyword)){
 | 
	
		
			
				|  |  |             Patient p = patientDao.findByIdcard(keyword);
 | 
	
		
			
				|  |  |             if(p!=null){
 | 
	
		
			
				|  |  |                 sql =sql + " WHERE p.idcard ='"+keyword+"'";
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 sql =sql + " WHERE p.name like '%"+keyword+"%' ";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql += " ORDER BY highCount DESC LIMIT "+(page-1)*size+","+size;
 | 
	
		
			
				|  |  |         return sql ;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public String getXYTrackPatientIndexCountListSql(String doctor,Integer teamCode,String startDate,String endDate,String keyword,Integer page,Integer size){
 | 
	
		
			
				|  |  |         String sql ="SELECT  " +
 | 
	
		
			
				|  |  |                 " t1.patient_code, " +
 | 
	
		
			
				|  |  |                 " t1.total AS lowCount, " +
 | 
	
		
			
				|  |  |                 " t2.total AS stdCount, " +
 | 
	
		
			
				|  |  |                 " t3.total AS highCount, " +
 | 
	
		
			
				|  |  |                 " p.`name`, " +
 | 
	
		
			
				|  |  |                 " IFNULL(year( from_days( datediff( now(), p.birthday))),'未知') age, " +
 | 
	
		
			
				|  |  |                 " p.photo " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 " " +
 | 
	
		
			
				|  |  |                 " ( " +
 | 
	
		
			
				|  |  |                 "  SELECT " +
 | 
	
		
			
				|  |  |                 "   t.patient_code, " +
 | 
	
		
			
				|  |  |                 "   IFNULL(pid.total, 0) AS total " +
 | 
	
		
			
				|  |  |                 "  FROM " +
 | 
	
		
			
				|  |  |                 "   ( " +
 | 
	
		
			
				|  |  |                 "    SELECT " +
 | 
	
		
			
				|  |  |                 "     tp.patient_code " +
 | 
	
		
			
				|  |  |                 "    FROM " +
 | 
	
		
			
				|  |  |                 "     wlyy_track_patient tp " +
 | 
	
		
			
				|  |  |                 "    WHERE " +
 | 
	
		
			
				|  |  |                 "     tp.del = '1' " +
 | 
	
		
			
				|  |  |                 "   AND tp.doctor_code = '"+doctor+"' " +
 | 
	
		
			
				|  |  |                 "   AND tp.team_code = " +teamCode+
 | 
	
		
			
				|  |  |                 "   ) t " +
 | 
	
		
			
				|  |  |                 "  LEFT JOIN ( " +
 | 
	
		
			
				|  |  |                 "   SELECT " +
 | 
	
		
			
				|  |  |                 "    i. USER, " +
 | 
	
		
			
				|  |  |                 "    COUNT(1) AS total " +
 | 
	
		
			
				|  |  |                 "   FROM " +
 | 
	
		
			
				|  |  |                 "    device.wlyy_patient_health_index i " +
 | 
	
		
			
				|  |  |                 "   WHERE " +
 | 
	
		
			
				|  |  |                 "    i.del = '1' " +
 | 
	
		
			
				|  |  |                 "   AND i.type = 2 " +
 | 
	
		
			
				|  |  |                 "   AND i.value1 < 90 " +
 | 
	
		
			
				|  |  |                 "  AND i.i.record_date >='"+startDate+"'" +
 | 
	
		
			
				|  |  |                 "  AND i.i.record_date <='"+endDate+"'" +
 | 
	
		
			
				|  |  |                 "   GROUP BY " +
 | 
	
		
			
				|  |  |                 "    i. USER " +
 | 
	
		
			
				|  |  |                 "  ) pid ON pid. USER = t.patient_code " +
 | 
	
		
			
				|  |  |                 " ) t1  " +
 | 
	
		
			
				|  |  |                 " JOIN " +
 | 
	
		
			
				|  |  |                 " ( " +
 | 
	
		
			
				|  |  |                 "  SELECT " +
 | 
	
		
			
				|  |  |                 "   t.patient_code, " +
 | 
	
		
			
				|  |  |                 "   IFNULL(pid.total, 0) AS total " +
 | 
	
		
			
				|  |  |                 "  FROM " +
 | 
	
		
			
				|  |  |                 "   ( " +
 | 
	
		
			
				|  |  |                 "    SELECT " +
 | 
	
		
			
				|  |  |                 "     tp.patient_code " +
 | 
	
		
			
				|  |  |                 "    FROM " +
 | 
	
		
			
				|  |  |                 "     wlyy_track_patient tp " +
 | 
	
		
			
				|  |  |                 "    WHERE " +
 | 
	
		
			
				|  |  |                 "     tp.del = '1' " +
 | 
	
		
			
				|  |  |                 "   AND tp.doctor_code = '"+doctor+"' " +
 | 
	
		
			
				|  |  |                 "   AND tp.team_code = " +teamCode+
 | 
	
		
			
				|  |  |                 "   ) t " +
 | 
	
		
			
				|  |  |                 "  LEFT JOIN ( " +
 | 
	
		
			
				|  |  |                 "   SELECT " +
 | 
	
		
			
				|  |  |                 "    i. USER, " +
 | 
	
		
			
				|  |  |                 "    COUNT(1) AS total " +
 | 
	
		
			
				|  |  |                 "   FROM " +
 | 
	
		
			
				|  |  |                 "    device.wlyy_patient_health_index i " +
 | 
	
		
			
				|  |  |                 "   WHERE " +
 | 
	
		
			
				|  |  |                 "    i.del = '1' " +
 | 
	
		
			
				|  |  |                 "   AND i.type = 2 " +
 | 
	
		
			
				|  |  |                 "   AND i.value1 >= 90 " +
 | 
	
		
			
				|  |  |                 "   AND i.value1 <=139 " +
 | 
	
		
			
				|  |  |                 "  AND i.i.record_date >='"+startDate+"'" +
 | 
	
		
			
				|  |  |                 "  AND i.i.record_date <='"+endDate+"'" +
 | 
	
		
			
				|  |  |                 "   GROUP BY " +
 | 
	
		
			
				|  |  |                 "    i. USER " +
 | 
	
		
			
				|  |  |                 "  ) pid ON pid. USER = t.patient_code " +
 | 
	
		
			
				|  |  |                 "  " +
 | 
	
		
			
				|  |  |                 " ) t2 ON t1.patient_code = t2.patient_code " +
 | 
	
		
			
				|  |  |                 " JOIN  " +
 | 
	
		
			
				|  |  |                 " ( " +
 | 
	
		
			
				|  |  |                 "  SELECT " +
 | 
	
		
			
				|  |  |                 "   t.patient_code, " +
 | 
	
		
			
				|  |  |                 "   IFNULL(pid.total, 0) AS total " +
 | 
	
		
			
				|  |  |                 "  FROM " +
 | 
	
		
			
				|  |  |                 "   ( " +
 | 
	
		
			
				|  |  |                 "    SELECT " +
 | 
	
		
			
				|  |  |                 "     tp.patient_code " +
 | 
	
		
			
				|  |  |                 "    FROM " +
 | 
	
		
			
				|  |  |                 "     wlyy_track_patient tp " +
 | 
	
		
			
				|  |  |                 "    WHERE " +
 | 
	
		
			
				|  |  |                 "     tp.del = '1' " +
 | 
	
		
			
				|  |  |                 "   AND tp.doctor_code = '"+doctor+"' " +
 | 
	
		
			
				|  |  |                 "   AND tp.team_code = " +teamCode+
 | 
	
		
			
				|  |  |                 "   ) t " +
 | 
	
		
			
				|  |  |                 "  LEFT JOIN ( " +
 | 
	
		
			
				|  |  |                 "   SELECT " +
 | 
	
		
			
				|  |  |                 "    i. USER, " +
 | 
	
		
			
				|  |  |                 "    COUNT(1) AS total " +
 | 
	
		
			
				|  |  |                 "   FROM " +
 | 
	
		
			
				|  |  |                 "    device.wlyy_patient_health_index i " +
 | 
	
		
			
				|  |  |                 "   WHERE " +
 | 
	
		
			
				|  |  |                 "    i.del = '1' " +
 | 
	
		
			
				|  |  |                 "   AND i.type = 2 " +
 | 
	
		
			
				|  |  |                 "   AND i.value1 >139 " +
 | 
	
		
			
				|  |  |                 "  AND i.i.record_date >='"+startDate+"'" +
 | 
	
		
			
				|  |  |                 "  AND i.i.record_date <='"+endDate+"'" +
 | 
	
		
			
				|  |  |                 "   GROUP BY " +
 | 
	
		
			
				|  |  |                 "    i. USER " +
 | 
	
		
			
				|  |  |                 "  ) pid ON pid. USER = t.patient_code " +
 | 
	
		
			
				|  |  |                 " ) t3 ON t1.patient_code = t3.patient_code " +
 | 
	
		
			
				|  |  |                 " JOIN wlyy_patient p ON t1.patient_code = p.`code`";
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(keyword)){
 | 
	
		
			
				|  |  |             Patient p = patientDao.findByIdcard(keyword);
 | 
	
		
			
				|  |  |             if(p!=null){
 | 
	
		
			
				|  |  |                 sql =sql + " WHERE p.idcard ='"+keyword+"'";
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 sql =sql + " WHERE p.name like '%"+keyword+"%' ";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql += " ORDER BY highCount DESC LIMIT "+(page-1)*size+","+size;
 | 
	
		
			
				|  |  |         return sql;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |