chats.endpoint.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /**
  2. * 消息端点。
  3. *
  4. * 此控制器处理点对点,组及消息消息。为三类消息提供发送及查询功能。
  5. */
  6. "use strict";
  7. let express = require('express');
  8. let router = express.Router();
  9. let http = require('http');
  10. let log = require('../util/log.js');
  11. let ObjectUtil = require("../util/object.util.js");
  12. let ControllerUtil = require('../util/controller.util');
  13. let Patient = require("../models/user/patient");
  14. let Doctor = require('../models/user/doctor');
  15. let Group = require('../models/group');
  16. let Search = require('../models/search');
  17. let Sessions = require('../models/sessions/sessions');
  18. const APIv1 = require('../include/endpoints').APIv1;
  19. const CONTENT_TYPES = require('../include/commons').CONTENT_TYPE;
  20. const MAX_INT = require('../include/commons').MAX_INT;
  21. const DEFAULT_PAGE_SIZE = require('../include/commons').DEFAULT_PAGE_SIZE;
  22. //--------------------------------------------------------------//
  23. //----------------------------消息发送----------------------------//
  24. //--------------------------------------------------------------//
  25. /**
  26. * 发送System消息。
  27. *
  28. * 请求URL:
  29. * /chats/sm
  30. *
  31. * 消息格式:
  32. * {
  33. * to: "Rose",
  34. * title: "System Message",
  35. * summary: "You have new job",
  36. * contentType: "1",
  37. * content: "The patient has been followed in the scheduler, please make new follow plan as soon as possible.",
  38. * delay: 986123465
  39. * }
  40. *
  41. * @param message
  42. */
  43. router.post(APIv1.Chats.SM, function (req, res) {
  44. // 检查消息体及消息格式是否正确
  45. let message = req.body;
  46. if (!ObjectUtil.isJsonObject(message)) {
  47. throw {httpStatus: 406, message: 'Problems parsing JSON.'}
  48. }
  49. // 字段判断
  50. let testing = ObjectUtil.fieldsCheck(message, "to", "title", "summary", "contentType", "content");
  51. if (!testing.pass) {
  52. throw {httpStatus: 406, message: testing.message}
  53. }
  54. // 消息处理
  55. let doctor = new Doctor();
  56. ControllerUtil.regModelEventHandler(doctor, res);
  57. doctor.sendSystemMessage(message);
  58. });
  59. router.get(APIv1.Chats.TEST,function(req,res){
  60. let test = req.query.test;
  61. //http://192.168.131.107:3008/api/v1/chats/test?test=1&page=0&pagesize=10&user=3121&sessionId=testsessionmsg1
  62. if(test==1){//获取会话消息列表
  63. let page = req.query.page;
  64. let pagesize = req.query.pagesize;
  65. let user = req.query.user;
  66. let sessionId =req.query.sessionId;
  67. let sessions = new Sessions();
  68. ControllerUtil.regModelEventHandler(sessions, res);
  69. sessions.getMessages(sessionId,user,page,pagesize);
  70. }
  71. //http://192.168.131.107:3008/api/v1/chats/test?test=2&page=0&pagesize=10&user=3121
  72. if(test==2){//获取用户会话
  73. let sessions = new Sessions();
  74. let page = req.query.page;
  75. let pagesize = req.query.pagesize;
  76. let user = req.query.user;
  77. ControllerUtil.regModelEventHandler(sessions, res);
  78. sessions.getUserSessions(user,page,pagesize);
  79. }
  80. //http://192.168.131.107:3008/api/v1/chats/test?test=3&sessionId=132312312&users=10,2,3&name=3121&sessionType=2
  81. if(test==3){
  82. let sessions = new Sessions();
  83. ControllerUtil.regModelEventHandler(sessions, res);
  84. let sessionId = req.query.sessionId;
  85. let users = req.query.users;
  86. let name = req.query.name;
  87. let sessionType = req.query.sessionType;
  88. sessions.createSession(sessionId,name,sessionType,users);
  89. }
  90. if(test==4){
  91. let sessions = new Sessions();
  92. ControllerUtil.regModelEventHandler(sessions, res);
  93. let sessionId = req.query.sessionId;
  94. let message ={};
  95. message.contentType =1;
  96. message.timestamp=new Date();
  97. message.content ="test send message";
  98. message.senderId="10";
  99. message.senderName="test1";
  100. sessions.saveMessageBySession(message,sessionId);
  101. }
  102. //http://192.168.131.107:3008/api/v1/chats/test?test=5&user=3121&sessionId=testsessionmsg1
  103. if(test==5){
  104. let sessions = new Sessions();
  105. ControllerUtil.regModelEventHandler(sessions, res);
  106. let sessionId = req.query.sessionId;
  107. let user = req.query.user;
  108. let type = req.query.type;
  109. if(type==1){
  110. //置顶
  111. sessions.stickSession(sessionId,user);
  112. }else{
  113. //取消置顶
  114. sessions.cancelStickSession(sessionId,user);
  115. }
  116. }
  117. })
  118. /**
  119. * 处理Private消息。处理流程分:
  120. * 1 解析消息,并保存到数据库
  121. * 2 更新消息统计数据
  122. * 3 获取目标的状态并构建通知消息,如果用户在线就推送通知消息
  123. *
  124. * 请求URL:
  125. * /chats/pm
  126. *
  127. * 消息格式:
  128. * {
  129. * from: sand,
  130. * to: Rose,
  131. * contentType: "1,2,3,4",
  132. * content: "Please follow the patient as soon as possible."
  133. * }
  134. *
  135. * @param message
  136. */
  137. router.post(APIv1.Chats.PM, function (req, res) {
  138. // 检查消息体及消息格式是否正确
  139. let message = req.body;
  140. if (!ObjectUtil.isJsonObject(message)) {
  141. throw {httpStatus: 406, message: 'Problems parsing JSON.'}
  142. }
  143. // 字段判断
  144. let testing = ObjectUtil.fieldsCheck(message, "from", "to", "contentType", "content");
  145. if (!testing.pass) {
  146. throw {httpStatus: 406, message: testing.message};
  147. }
  148. // 消息处理,患者与医生分开发送
  149. Patient.isPatientCode(message.to,
  150. function () {
  151. let patient = new Patient();
  152. ControllerUtil.regModelEventHandler(patient, res);
  153. patient.sendMessage(message);
  154. }, function () {
  155. let doctor = new Doctor();
  156. ControllerUtil.regModelEventHandler(doctor, res);
  157. doctor.sendMessage(message);
  158. });
  159. });
  160. /**
  161. * 处理讨论组消息。
  162. *
  163. * 请求URL:
  164. * /chats/gm
  165. *
  166. * 消息格式:
  167. * {
  168. * from: "sand", // 发送者id
  169. * at: "Rose", // @人
  170. * group: "DiscussionGroupId", // 所在组
  171. * groupType: "1 or 2", // 组类型:行政团队或讨论组
  172. * contentType: "1,2,3", // 内容类型
  173. * content: "The patient mess me up" // 内容
  174. * }
  175. *
  176. * @param message
  177. */
  178. router.post(APIv1.Chats.GM, function (req, res) {
  179. // 检查消息体及消息格式是否正确
  180. let message = req.body;
  181. if (!ObjectUtil.isJsonObject(message)) {
  182. throw {httpStatus: 406, message: 'Problems parsing JSON.'};
  183. }
  184. // 字段判断
  185. let testing = ObjectUtil.fieldsCheck(message, 'from', 'at', 'group', 'groupType', 'contentType', 'content');
  186. if (!testing.pass) {
  187. throw {httpStatus: 406, message: testing.message}
  188. }
  189. // 消息处理
  190. let group = new Group();
  191. ControllerUtil.regModelEventHandler(group, res);
  192. group.sendMessage(message);
  193. });
  194. //--------------------------------------------------------------//
  195. //----------------------------消息提取----------------------------//
  196. //--------------------------------------------------------------//
  197. /**
  198. * 获取参与的聊天列表,包括:点对点,@我,参与的讨论组,系统消息等。
  199. *
  200. * 请求URL:
  201. * /chats/list?user_id=sand
  202. */
  203. router.get(APIv1.Chats.List, function (req, res) {
  204. let userId = req.query.user_id;
  205. if (userId === null) {
  206. throw {httpStatus: 406, message: 'Missing fields.'};
  207. }
  208. let doctor = new Doctor();
  209. ControllerUtil.regModelEventHandler(doctor, res);
  210. doctor.getChatList(userId);
  211. });
  212. /**
  213. * 获取与患者的聊天列表,包括:P2P,参与的讨论组和行政团队。
  214. *
  215. * 请求URL:
  216. * /chats/list/patient
  217. */
  218. router.get(APIv1.Chats.ListWithPatient, function (req, res) {
  219. let userId = req.query.user_id;
  220. if (userId === null) {
  221. throw {httpStatus: 406, message: 'Missing fields.'};
  222. }
  223. let doctor = new Doctor();
  224. ControllerUtil.regModelEventHandler(doctor, res);
  225. doctor.getChatsListWithPatient(userId);
  226. });
  227. /**
  228. * 获取与医生的聊天列表,包括:点对点,参与的讨论组。
  229. *
  230. * 请求URL:
  231. * /chats/list/doctor
  232. */
  233. router.get(APIv1.Chats.ListWithDoctor, function (req, res) {
  234. let userId = req.query.user_id;
  235. if (userId === null) {
  236. throw {httpStatus: 406, message: 'Missing fields.'};
  237. }
  238. let doctor = new Doctor();
  239. ControllerUtil.regModelEventHandler(doctor, res);
  240. doctor.getChatListWithDoctor(userId);
  241. });
  242. router.get(APIv1.Chats.MsgAmount, function (req, res) {
  243. let userId = req.query.user_id;
  244. if (userId === null) {
  245. throw {httpStatus: 406, message: 'Missing fields.'};
  246. }
  247. let doctor = new Doctor();
  248. ControllerUtil.regModelEventHandler(doctor, res);
  249. doctor.getChatListMsgAmount(userId);
  250. });
  251. /**
  252. * 获取最近聊天对象:包括患者,医生与讨论组。客户端自行根据需要提取患者、医生或讨论组数据。
  253. *
  254. * 请求URL:
  255. * /chats/recent?user_id=0de7295862dd11e69faffa163e8aee56&days=7
  256. *
  257. * 参数:
  258. * user_id: 用户ID
  259. * target_type: 对象类型,1患者,2医生,3讨论组
  260. * days: 最近天数,默认7天
  261. */
  262. router.get(APIv1.Chats.Recent, function (req, res) {
  263. let userId = req.query.user_id;
  264. let days = req.query.days;
  265. if (userId === null) {
  266. throw {httpStatus: 406, message: 'Missing field: user_id'};
  267. }
  268. if (days === null) {
  269. days = 7;
  270. }
  271. let doctor = new Doctor();
  272. ControllerUtil.regModelEventHandler(doctor, res);
  273. doctor.getRecentChatList(userId, days);
  274. });
  275. /**
  276. * 获取私信。倒序排列。
  277. *
  278. * 参数:
  279. * user_id 必须,医生ID
  280. * peer_id 必须,对方医生ID
  281. * content_type 必须,消息类型
  282. * message_start_id 可选,消息的起始ID,如果为空从最新的一条开始获取
  283. * message_end_id 可选,消息的结束ID,如果为空从第一条开始获取
  284. * count 可选,消息数量,如果不指定、小于零或大于50,默认为100条。若message_start_id与message_end_id均不为空,则此参数无效,方法是设置为10000条
  285. * closed_interval 消息范围是否使用闭区间
  286. *
  287. * 请求URL:
  288. * /chats/pm?user_id=sand&peer_id=Rose&content_type=2&message_start_id=10000&message_end_id=0&count=20&closed_interval=false
  289. */
  290. router.get(APIv1.Chats.PM, function (req, res) {
  291. let userId = req.query.user_id;
  292. let peerId = req.query.peer_id;
  293. let contentType = req.query.content_type;
  294. let msgStartId = !req.query.message_start_id ? MAX_INT : parseInt(req.query.message_start_id);
  295. let msgEndId = !req.query.message_end_id || req.query.message_end_id === 'null' ? 0 : parseInt(req.query.message_end_id);
  296. let count = req.query.count === undefined ? DEFAULT_PAGE_SIZE : parseInt(req.query.count);
  297. let closedInterval = (req.query.closed_interval != false && req.query.closed_interval === "true");
  298. if (contentType !== undefined && parseInt(contentType) === CONTENT_TYPES.Image) count = DEFAULT_PAGE_SIZE;
  299. if (req.query.message_start_id && req.query.message_end_id) count = 10000;
  300. if (!userId) {
  301. throw {httpStatus: 400, message: "Missing field: user_id."};
  302. }
  303. let doctor = new Doctor();
  304. ControllerUtil.regModelEventHandler(doctor, res);
  305. doctor.getPrivateMessages(userId, peerId, contentType, msgStartId, msgEndId, count, closedInterval);
  306. });
  307. /**
  308. * 获取未读私信。倒序排列。
  309. *
  310. * 参数:
  311. * user_id 必须,医生ID
  312. * peer_id 必须,对方医生ID
  313. *
  314. * 请求URL:
  315. * /chats/pm/unread?user_id=sand&peer_id=Rose
  316. */
  317. router.get(APIv1.Chats.PMUnread, function (req, res) {
  318. let userId = req.query.user_id;
  319. let peerId = req.query.peer_id;
  320. if (userId === undefined) {
  321. throw {httpStatus: 400, message: "Missing field: user_id."};
  322. }
  323. let doctor = new Doctor();
  324. ControllerUtil.regModelEventHandler(doctor, res);
  325. doctor.getUnreadPrivateMessages(userId, peerId);
  326. });
  327. /**
  328. * 按时间倒序获取群消息。
  329. *
  330. * 参数:
  331. * user_id 必须,医生ID
  332. * group_id 必须,组ID
  333. * message_start_id 可选,消息的起始ID,如果为空从最新的一条开始获取
  334. * count 可选,消息数量,如果不指定、小于零或大于50,默认为50条
  335. *
  336. * 请求URL:
  337. * /chats/gm?user_id=D2016008240002&group_id=494&content_type=2&message_start_id=0&message_end_id=0&count=20
  338. */
  339. router.get(APIv1.Chats.GM, function (req, res) {
  340. let groupId = req.query.group_id;
  341. let memberId = req.query.user_id;
  342. let contentType = req.query.content_type;
  343. let msgStartId = !req.query.message_start_id ? MAX_INT : parseInt(req.query.message_start_id);
  344. let msgEndId = !req.query.message_end_id ? 0 : parseInt(req.query.message_end_id);
  345. let count = req.query.count === undefined ? DEFAULT_PAGE_SIZE : parseInt(req.query.count);
  346. if (groupId === undefined) {
  347. throw {httpStatus: 400, message: "Missing field: group_id."};
  348. }
  349. if (contentType !== undefined && parseInt(contentType) === CONTENT_TYPES.Image) count = DEFAULT_PAGE_SIZE;
  350. if (req.query.message_start_id && req.query.message_end_id) count = 100000;
  351. let group = new Group();
  352. ControllerUtil.regModelEventHandler(group, res);
  353. group.getMessages(groupId, memberId, contentType, msgStartId, msgEndId, count);
  354. });
  355. /**
  356. * 获取未读群消息。
  357. *
  358. * 请求URL:
  359. * /chats/gm/unread?group_id=discussionGroupId&user_id=sand
  360. */
  361. router.get(APIv1.Chats.GMUnread, function (req, res) {
  362. let memberId = req.query.user_id;
  363. let groupId = req.query.group_id;
  364. if (memberId === undefined) {
  365. throw {httpStatus: 400, message: "Missing field: user_id."};
  366. }
  367. if (groupId === undefined) {
  368. throw {httpStatus: 400, message: "Missing field: group_id."};
  369. }
  370. let group = new Group();
  371. ControllerUtil.regModelEventHandler(group, res);
  372. group.getUnreadMessages(groupId, memberId);
  373. });
  374. //--------------------------------------------------------------//
  375. //----------------------------消息统计----------------------------//
  376. //--------------------------------------------------------------//
  377. /**
  378. * 获取所有群组未读消息总数。
  379. *
  380. * 请求URL:
  381. * /chats/gm/unread_count?user_id=sand
  382. *
  383. * 参数:
  384. * user_id:医生ID
  385. */
  386. router.get(APIv1.Chats.GMUnreadCount, function (req, res) {
  387. let memberId = req.query.user_id;
  388. if (memberId === null) {
  389. throw {httpStatus: 406, message: 'Missing fields.'};
  390. }
  391. let group = new Group();
  392. ControllerUtil.regModelEventHandler(group, res);
  393. group.getUnreadMessageCount(memberId);
  394. });
  395. /**
  396. * 获取特定群组消息统计情况。
  397. *
  398. * /chats/gm/statistic?group_id=GGG&&user_id=sand
  399. *
  400. * 参数:
  401. * user_id:信息所有者id
  402. * group_id:群组id
  403. */
  404. router.get(APIv1.Chats.GMStats, function (req, res) {
  405. let memberId = req.query.user_id;
  406. let groupId = req.query.group_id;
  407. if (memberId === null || groupId === null) {
  408. throw {httpStatus: 406, message: 'Miss fields.'};
  409. }
  410. let group = new Group();
  411. ControllerUtil.regModelEventHandler(group, res);
  412. group.getChatSummary(groupId, memberId);
  413. });
  414. /**
  415. * 获取与某人的私信统计。
  416. *
  417. * /chats/pm/statistic?user_id=sand&&peer_id=rose
  418. *
  419. * 参数:
  420. * user_id:信息所有者id
  421. * peer_id:聊天对端id
  422. */
  423. router.get(APIv1.Chats.PMStats, function (req, res) {
  424. let userId = req.query.user_id;
  425. let peerId = req.query.peer_id;
  426. if (userId == null || peerId == null) {
  427. throw {httpStatus: 406, message: "Missing fields."};
  428. }
  429. let doctor = new Doctor();
  430. ControllerUtil.regModelEventHandler(doctor, res);
  431. doctor.getChatSummary(userId, peerId);
  432. });
  433. /**
  434. * 获取所有未读私信总数。
  435. *
  436. * /chats/pm/unread_count?user_id=sand
  437. *
  438. * 参数:
  439. * uid:信息所有者id
  440. */
  441. router.get(APIv1.Chats.PMUnreadCount, function (req, res) {
  442. let userId = req.query.user_id;
  443. let doctor = new Doctor();
  444. ControllerUtil.regModelEventHandler(doctor, res);
  445. doctor.getUnreadPrivateMessages(userId);
  446. });
  447. /**
  448. * 所有聊天消息未读数。
  449. *
  450. * 请求URL:
  451. * /chats/chats/unread_count?user_id=sand
  452. *
  453. * 参数:
  454. * user_id:信息所有者id
  455. */
  456. router.get(APIv1.Chats.UnreadMsgCount, function (req, res) {
  457. let userId = req.query.user_id;
  458. if (userId === null) {
  459. throw {httpStatus: 406, message: "Missing fields."};
  460. }
  461. let doctor = new Doctor();
  462. ControllerUtil.regModelEventHandler(doctor, res);
  463. doctor.getAllUnreadMessageCount(userId);
  464. });
  465. /**
  466. * 搜索患者相关的数据,包括患者信息与相关的私信记录。关键词不支持空格拆分。
  467. *
  468. * 请求URL:
  469. * http://192.168.131.107:3000/api/v1/chats/search/patient?user_id=D2016008240003&user_role=3&keyword=fa
  470. *
  471. * 参数:
  472. * keywords: 关键词
  473. */
  474. router.get(APIv1.Chats.SearchAboutPatient, function (req, res) {
  475. var userId = req.query.user_id;
  476. var userRole = req.query.user_role;
  477. var keyword = req.query.keyword;
  478. if (!userId) throw {httpStatus: 406, message: "Missing fields: user_id."};
  479. if (!userRole) throw {httpStatus: 406, message: "Missing fields: user_role."};
  480. if (!keyword) throw {httpStatus: 406, message: "Missing fields: keyword."};
  481. let search = new Search();
  482. ControllerUtil.regModelEventHandler(search, res);
  483. search.searchAboutPatient(userId, userRole, keyword);
  484. });
  485. /**
  486. * 获取某个聊天的关键字搜索记录列表
  487. * 请求URL:
  488. *http://192.168.131.107:3000/api/v1/chats/search/patient/list?user_id=D2016008240003&keyword=f&group_id=e2b695b9daf74d0faeb90a304ae587a0&type=1
  489. */
  490. router.get(APIv1.Chats.SearchAboutPatientList, function (req, res) {
  491. var userId = req.query.user_id;
  492. var groupId = req.query.group_id;
  493. var keyword = req.query.keyword;
  494. var type = req.query.type;
  495. if (!userId) throw {httpStatus: 406, message: "Missing fields: user_id."};
  496. if (!groupId) throw {httpStatus: 406, message: "Missing fields: group_id."};
  497. if (!keyword) throw {httpStatus: 406, message: "Missing fields: keyword."};
  498. if (!type) throw {httpStatus: 406, message: "Missing fields: type."};
  499. let search = new Search();
  500. ControllerUtil.regModelEventHandler(search, res);
  501. search.searchAboutPatientList(userId, keyword,groupId,type);
  502. });
  503. /**
  504. * http://192.168.131.107:3000/api/v1/chats/search/patient/all?user_id=D2016008240003&keyword=f&type=2&user_role=3
  505. * 患者消息查询查看更多
  506. */
  507. router.get(APIv1.Chats.SearchAbountPatientMore, function (req, res) {
  508. var userId = req.query.user_id;
  509. var keyword = req.query.keyword;
  510. var type = req.query.type;
  511. var userRole= req.query.user_role;
  512. if (!userId) throw {httpStatus: 406, message: "Missing fields: user_id."};
  513. if (!keyword) throw {httpStatus: 406, message: "Missing fields: keyword."};
  514. if (!type) throw {httpStatus: 406, message: "Missing fields: type."};
  515. if (!userRole) throw {httpStatus: 406, message: "Missing fields: userRole."};
  516. let search = new Search();
  517. ControllerUtil.regModelEventHandler(search, res);
  518. search.searchAboutPatientAll(userId,userRole, keyword,type);
  519. });
  520. /**
  521. * 搜索医生相关的数据,包括医生信息与相关的聊天记录,包括私信与群信。
  522. *
  523. * 请求URL:
  524. * /search/doctor?user_id=D2016008240003&keyword=黄
  525. *
  526. * 参数:
  527. * keywords: 关键词
  528. */
  529. router.get(APIv1.Chats.SearchAboutDoctor, function (req, res) {
  530. let userId = req.query.user_id;
  531. let keyword = req.query.keyword;
  532. if (!userId) throw {httpStatus: 406, message: "Missing fields: user_id."};
  533. if (!keyword) throw {httpStatus: 406, message: "Missing fields: keyword."};
  534. let search = new Search();
  535. ControllerUtil.regModelEventHandler(search, res);
  536. search.searchAboutDoctor(userId, keyword);
  537. });
  538. /**
  539. * http://192.168.131.107:3000/api/v1/chats/search/doctor/list?user_id=D2016008240003&keyword=%E9%BB%84&type=2
  540. * 医生搜索查看更多
  541. * type = 1 查询聊过的医生
  542. * type = 2 查询群组标题和人员包含的群聊
  543. * type = 3 查询聊天关键字
  544. */
  545. router.get(APIv1.Chats.SearchAboutDoctorList, function (req, res) {
  546. let userId = req.query.user_id;
  547. let keyword = req.query.keyword;
  548. let type = req.query.type;
  549. if (!userId) throw {httpStatus: 406, message: "Missing fields: user_id."};
  550. if (!keyword) throw {httpStatus: 406, message: "Missing fields: keyword."};
  551. if (!type) throw {httpStatus: 406, message: "Missing fields: type."};
  552. let search = new Search();
  553. ControllerUtil.regModelEventHandler(search, res);
  554. search.searchDoctorMore(userId, keyword,type);
  555. });
  556. /**
  557. * 查询医生聊天记录详情(单个聊天记录包含关键字的)
  558. *http://192.168.131.107:3000/api/v1/chats/search/doctor/content/list?user_id=D2016008240003&keyword=f&type=2&groupcode=0381288df51b434795b6946bb63d90b8
  559. */
  560. router.get(APIv1.Chats.SearchAbountDoctorContentDetail, function (req, res) {
  561. let userId = req.query.user_id;
  562. let keyword = req.query.keyword;
  563. let type = req.query.type;
  564. let groupcode = req.query.groupcode;
  565. if (!userId) throw {httpStatus: 406, message: "Missing fields: user_id."};
  566. if (!keyword) throw {httpStatus: 406, message: "Missing fields: keyword."};
  567. if (!type) throw {httpStatus: 406, message: "Missing fields: type."};
  568. if (!groupcode) throw {httpStatus: 406, message: "Missing fields: groupcode."};
  569. let search = new Search();
  570. ControllerUtil.regModelEventHandler(search, res);
  571. search.searchDoctorContentDetail(userId, keyword,groupcode,type);
  572. });
  573. /**
  574. * 获取单条消息。
  575. *
  576. * URL:
  577. * /chats/message?id=1234&type=1
  578. */
  579. router.get(APIv1.Chats.Message, function (req, res) {
  580. let messageId = req.query.id;
  581. let messageType = req.query.type;
  582. let doctor = new Doctor();
  583. ControllerUtil.regModelEventHandler(doctor, res);
  584. doctor.getMessage(messageId, messageType);
  585. });
  586. /**
  587. * 判断当前会话是否已经结束。
  588. *
  589. * 请求URL:
  590. * /chats/pm/finished?user_id=sand&peer_id=rose
  591. */
  592. router.get(APIv1.Chats.PMFinished, function (req, res) {
  593. let doctorId = req.query.doctor_id;
  594. let patientId = req.query.patient_id;
  595. if (!doctorId) {
  596. throw {httpStatus: 406, message: "Missing field: doctor_id"};
  597. }
  598. if (!patientId) {
  599. throw {httpStatus: 406, message: "Missing field: patient_id"};
  600. }
  601. let doctor = new Doctor();
  602. ControllerUtil.regModelEventHandler(doctor, res);
  603. doctor.isConsultFinished(doctorId, patientId);
  604. });
  605. module.exports = router;