| 
					
				 | 
			
			
				@ -30,7 +30,7 @@ exports.findOneMessage = function (messageId, handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				exports.findOnePatientMessage = function (messageId,handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    imRepo.execQuery({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "sql": "SELECT m.*,d.name,d.photo FROM msg_p2p m, wlyy.wlyy_doctor d, wlyy.wlyy_patient p WHERE m.from_uid = d. CODE AND m.to_uid = p. CODE AND m.msg_id =?", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "sql": "SELECT m.*,d.name,d.photo FROM msg_p2p m, ydf.ydf_doctor d, ydf.ydf_patient p WHERE m.from_uid = d.id AND m.to_uid = p.id AND m.msg_id =?", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "args": [messageId], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "handler": handler 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    }); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -71,15 +71,15 @@ exports.findAllP2PWithDoctor = function (userId, handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //    "FROM (SELECT DISTINCT CASE WHEN ms1.timestamp > ms2.timestamp THEN ms1.id ELSE ms2.id END id " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //    "      FROM msg_statistic ms1, msg_statistic ms2 " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //    "      WHERE ms1.from_gid IS NULL AND ms2.from_gid IS NULL " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //    "            AND ms1.uid = ms2.peer_uid AND ms1.peer_uid = ms2.uid) x, msg_statistic ms3, wlyy.wlyy_doctor d " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //    "            AND ms1.uid = ms2.peer_uid AND ms1.peer_uid = ms2.uid) x, msg_statistic ms3, ydf.ydf_doctor d " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //    "WHERE x.id = ms3.id AND ms3.last_content_type in (1,2,3,5,6) AND " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //    "(ms3.uid = ? AND ms3.peer_uid = d.code) GROUP BY d.code, d.name ORDER BY ms3.timestamp DESC"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    var sql ="SELECT d. CODE as code, d. NAME as name,  d.sex, d.photo, s.last_content_type, s.last_content, s. TIMESTAMP as timestamp, s.new_msg_count " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "FROM msg_p2p p, wlyy.wlyy_doctor d, msg_statistic s " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "WHERE (( p.from_uid = d. CODE AND p.to_uid = ? ) OR ( p.to_uid = d. CODE AND p.from_uid = ? )) " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    var sql ="SELECT d. id as code, d. NAME as name,  d.sex, d.photo, s.last_content_type, s.last_content, s. TIMESTAMP as timestamp, s.new_msg_count " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "FROM msg_p2p p, ydf.ydf_doctor d, msg_statistic s " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "WHERE (( p.from_uid = d. id AND p.to_uid = ? ) OR ( p.to_uid = d. id AND p.from_uid = ? )) " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "AND s.from_gid IS NULL AND s.uid = ? " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "AND s.peer_uid = d. CODE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "GROUP BY d. NAME, d. CODE, d.hospital_name, d.job_name, d.sex, d.photo ORDER BY p.msg_id DESC" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "AND s.peer_uid = d. id " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "GROUP BY d. NAME, d. id, d.hospital_name, d.job_name, d.sex, d.photo ORDER BY p.msg_id DESC" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    imRepo.execQuery({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "sql": sql, 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -96,21 +96,14 @@ exports.findAllP2PWithDoctor = function (userId, handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				exports.findAllP2PWithPatient = function (userId, handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //var sql = "SELECT p.code, p.name, p.birthday, p.sex, p.photo, ms.last_content_type, ms.last_content, ms.timestamp, ms.new_msg_count " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //    "FROM msg_statistic ms, wlyy.wlyy_patient p " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //    "FROM msg_statistic ms, ydf.ydf_patient p " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //    "WHERE ms.msg_type = 1 AND ms.last_content_type in (1,2,3,5,6) " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //    "AND ((ms.from_uid = ? AND ms.uid = p.code) OR (ms.uid = ? AND ms.from_uid = p.code)) ORDER BY ms.timestamp"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    var sql="SELECT p1. CODE as code , p1. NAME as name, p1.birthday, p1.sex, p1.photo, w.last_content, w.last_content_type, w. TIMESTAMP as timestamp, w.new_msg_count " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "FROM msg_p2p p, wlyy.wlyy_patient p1, msg_statistic w " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "WHERE (( p.to_uid = p1.`code` AND p.from_uid = ? ) OR ( p.from_uid = p1.`code` AND p.to_uid = ? )) " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "AND w.last_content_type IN (0,1, 2, 3, 4, 5, 6) AND w.uid = ? AND w.peer_uid = p1.`code` AND w.from_gid IS NULL " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "GROUP BY p1. CODE, p1. NAME, p1.birthday, p1.sex, p1.photo " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "union all " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "SELECT p1. CODE AS code, p1. NAME AS name, p1.birthday, p1.sex, p1.photo, w.last_content, t.type, w. TIMESTAMP AS timestamp, w.new_msg_count " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "FROM msg_p2p p, wlyy.wlyy_patient p1, msg_statistic w, wlyy.wlyy_consult_team t " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "WHERE (( p.to_uid = p1.`code` AND p.from_uid = ? ) OR ( p.from_uid = p1.`code` AND p.to_uid = ? )) " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "AND w.last_content_type = 7 AND t.type = 6 " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "AND (( t.patient = p.from_uid AND t.doctor = p.to_uid ) OR ( t.patient = p.to_uid AND t.doctor = p.from_uid )) " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "AND w.uid = ? AND w.peer_uid = p1.`code` AND w.from_gid IS NULL GROUP BY p1. CODE, p1. NAME, p1.birthday, p1.sex, p1.photo;"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    var sql="SELECT p1. id as code , p1. NAME as name, p1.birthday, p1.sex, p1.photo, w.last_content, w.last_content_type, w. TIMESTAMP as timestamp, w.new_msg_count " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "FROM msg_p2p p, ydf.ydf_patient p1, msg_statistic w " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "WHERE (( p.to_uid = p1.`id` AND p.from_uid = ? ) OR ( p.from_uid = p1.`id` AND p.to_uid = ? )) " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "AND w.last_content_type IN (0,1, 2, 3, 4, 5, 6,7) AND w.uid = ? AND w.peer_uid = p1.`id` AND w.from_gid IS NULL " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             "GROUP BY p1. id, p1. NAME, p1.birthday, p1.sex, p1.photo " ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    imRepo.execQuery({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "sql": sql, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "args": [userId, userId,userId,userId, userId,userId], 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -136,15 +129,4 @@ exports.findUnread = function(from, to, start, count, handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "args": [from, to, start, count], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "handler": handler 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				exports.isCurrentSessionFinished = function (doctorId, patientId, handler) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    var sql = "SELECT c.consult consult_id, case when c.end_msg_id is not null then 1 else 0 end finished " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "FROM wlyy.wlyy_consult_team c where c.doctor=? and c.patient = ? ORDER BY id DESC LIMIT 1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    imRepo.execQuery({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "sql": sql, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "args": [doctorId, patientId], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        "handler": handler 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				}; 
			 |