|  | @ -27,15 +27,18 @@ class Search extends BaseModel{
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     searchAboutPatient(userId, userRole, keyword) {
 | 
	
		
			
				|  |  |         let self = this;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         searchRepo.searchPatients(userId, userRole, keyword, function (err, patients) {
 | 
	
		
			
				|  |  |             if (err) {
 | 
	
		
			
				|  |  |                 modelUtil.emitDbError(self.eventEmitter, "Search patient on basic information failed", err);
 | 
	
		
			
				|  |  |                 log.error("Search patient on basic information failed: ", err);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 res.status(500).send({message: "Search patient on basic information failed."});
 | 
	
		
			
				|  |  |                 return;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             let data = {patients: [], chats: []};
 | 
	
		
			
				|  |  |             for (let i = 0; i < patients.length; ++i) {
 | 
	
		
			
				|  |  |                 let patient = patients[i];
 | 
	
		
			
				|  |  |             var data = {patients: [], chats: []};
 | 
	
		
			
				|  |  |             for (var i = 0; i < patients.length; ++i) {
 | 
	
		
			
				|  |  |                 var patient = patients[i];
 | 
	
		
			
				|  |  |                 data.patients.push({
 | 
	
		
			
				|  |  |                     code: patient.code,
 | 
	
		
			
				|  |  |                     name: patient.name,
 | 
	
	
		
			
				|  | @ -47,36 +50,66 @@ class Search extends BaseModel{
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             searchRepo.searchPatientPM(userId, keyword, function (err, chats) {
 | 
	
		
			
				|  |  |                 if (err) {
 | 
	
		
			
				|  |  |                     modelUtil.emitDbError(self.eventEmitter, "Search patient on private messages failed", err);
 | 
	
		
			
				|  |  |                     log.error("Search patient on private messages failed: ", err);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     res.status(500).send({message: "Search patient on private messages failed."});
 | 
	
		
			
				|  |  |                     return;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 let lastPatientCode = '';
 | 
	
		
			
				|  |  |                 let lastPatient = {code: '', name: '', sex: '', avatar: '', messages: []};
 | 
	
		
			
				|  |  |                 for (let i = 0; i < chats.length; ++i) {
 | 
	
		
			
				|  |  |                     let chat = chats[i];
 | 
	
		
			
				|  |  |                     if (lastPatientCode !== chat.code) {
 | 
	
		
			
				|  |  |                         lastPatientCode = chat.code;
 | 
	
		
			
				|  |  |                         lastPatient.code = chat.code;
 | 
	
		
			
				|  |  |                         lastPatient.name = chat.name;
 | 
	
		
			
				|  |  |                         lastPatient.sex = chat.sex;
 | 
	
		
			
				|  |  |                         lastPatient.birthday = objectUtil.timestampToLong(chat.birthday);
 | 
	
		
			
				|  |  |                         lastPatient.avatar = chat.photo === null ? "" : chat.photo;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         data.chats.push(lastPatient);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     lastPatient.messages.push({
 | 
	
		
			
				|  |  |                         id: chat.msg_id,
 | 
	
		
			
				|  |  |                         content: chat.content
 | 
	
		
			
				|  |  |                     });
 | 
	
		
			
				|  |  |                 for (var i = 0; i < chats.length; ++i) {
 | 
	
		
			
				|  |  |                     var lastPatient = {code: '', name: '', sex: '', avatar: '',amount:'',content:'',chat:'',type:''};
 | 
	
		
			
				|  |  |                     var chat = chats[i];
 | 
	
		
			
				|  |  |                     console.log(JSON.stringify(chat));
 | 
	
		
			
				|  |  |                     lastPatient.code = chat.code;
 | 
	
		
			
				|  |  |                     lastPatient.name = chat.name;
 | 
	
		
			
				|  |  |                     lastPatient.sex = chat.sex;
 | 
	
		
			
				|  |  |                     lastPatient.birthday = objectUtil.timestampToLong(chat.birthday);
 | 
	
		
			
				|  |  |                     lastPatient.avatar = chat.photo === null ? "" : chat.photo;
 | 
	
		
			
				|  |  |                     lastPatient.amount = chat.amount;
 | 
	
		
			
				|  |  |                     lastPatient.chat = chat.chat;
 | 
	
		
			
				|  |  |                     lastPatient.content = chat.content;
 | 
	
		
			
				|  |  |                     lastPatient.type = chat.type;
 | 
	
		
			
				|  |  |                     data.chats.push(lastPatient);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 modelUtil.emitData(self.eventEmitter, data);
 | 
	
		
			
				|  |  |             });
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 过滤某个聊天组的详细信息
 | 
	
		
			
				|  |  |      * @param userId
 | 
	
		
			
				|  |  |      * @param keyword
 | 
	
		
			
				|  |  |      * @param groupId
 | 
	
		
			
				|  |  |      * @param type
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     searchAboutPatientList(userId, keyword,groupId,type){
 | 
	
		
			
				|  |  |         let self = this;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         searchRepo.searchPatientPMList(userId, keyword,groupId,type, function (err, chats) {
 | 
	
		
			
				|  |  |             var data = [];
 | 
	
		
			
				|  |  |             if (err) {
 | 
	
		
			
				|  |  |                 log.error("Search patient on private messages failed: ", err);
 | 
	
		
			
				|  |  |                 res.status(500).send({message: "Search patient on private messages failed."});
 | 
	
		
			
				|  |  |                 return;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             for (var i = 0; i < chats.length; ++i) {
 | 
	
		
			
				|  |  |                 var lastPatient = {code: '', name: '', sex: '', avatar: '',chat:'',content:''};
 | 
	
		
			
				|  |  |                 var chat = chats[i];
 | 
	
		
			
				|  |  |                 lastPatient.code = chat.code;
 | 
	
		
			
				|  |  |                 lastPatient.name = chat.name;
 | 
	
		
			
				|  |  |                 lastPatient.sex = chat.sex;
 | 
	
		
			
				|  |  |                 lastPatient.birthday = objectUtil.timestampToLong(chat.birthday);
 | 
	
		
			
				|  |  |                 lastPatient.avatar = chat.photo === null ? "" : chat.photo;
 | 
	
		
			
				|  |  |                 lastPatient.chat = chat.chat;
 | 
	
		
			
				|  |  |                 lastPatient.content=chat.content;
 | 
	
		
			
				|  |  |                 data.push(lastPatient);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             modelUtil.emitData(self.eventEmitter, data);
 | 
	
		
			
				|  |  |         })
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 搜索医生相关的数据,包括医生信息与相关的聊天记录,包括私信与群信。
 | 
	
		
			
				|  |  |      */
 |