|
@ -1,702 +0,0 @@
|
|
|
/**
|
|
|
* 消息端点。
|
|
|
*
|
|
|
* 此控制器处理点对点,组及消息消息。为三类消息提供发送及查询功能。
|
|
|
*/
|
|
|
"use strict";
|
|
|
|
|
|
let express = require('express');
|
|
|
let router = express.Router();
|
|
|
|
|
|
let http = require('http');
|
|
|
let log = require('../util/log.js');
|
|
|
let ObjectUtil = require("../util/object.util.js");
|
|
|
let ControllerUtil = require('../util/controller.util');
|
|
|
|
|
|
let Patient = require("../models/user/patient");
|
|
|
let Doctor = require('../models/user/doctor');
|
|
|
let Group = require('../models/group');
|
|
|
let Search = require('../models/search');
|
|
|
let Sessions = require('../models/sessions/sessions');
|
|
|
|
|
|
const APIv1 = require('../include/endpoints').APIv1;
|
|
|
const CONTENT_TYPES = require('../include/commons').CONTENT_TYPE;
|
|
|
const MAX_INT = require('../include/commons').MAX_INT;
|
|
|
const DEFAULT_PAGE_SIZE = require('../include/commons').DEFAULT_PAGE_SIZE;
|
|
|
|
|
|
//--------------------------------------------------------------//
|
|
|
//----------------------------消息发送----------------------------//
|
|
|
//--------------------------------------------------------------//
|
|
|
|
|
|
/**
|
|
|
* 发送System消息。
|
|
|
*
|
|
|
* 请求URL:
|
|
|
* /chats/sm
|
|
|
*
|
|
|
* 消息格式:
|
|
|
* {
|
|
|
* to: "Rose",
|
|
|
* title: "System Message",
|
|
|
* summary: "You have new job",
|
|
|
* contentType: "1",
|
|
|
* content: "The patient has been followed in the scheduler, please make new follow plan as soon as possible.",
|
|
|
* delay: 986123465
|
|
|
* }
|
|
|
*
|
|
|
* @param message
|
|
|
*/
|
|
|
router.post(APIv1.Chats.SM, function (req, res) {
|
|
|
// 检查消息体及消息格式是否正确
|
|
|
let message = req.body;
|
|
|
if (!ObjectUtil.isJsonObject(message)) {
|
|
|
throw {httpStatus: 406, message: 'Problems parsing JSON.'}
|
|
|
}
|
|
|
|
|
|
// 字段判断
|
|
|
let testing = ObjectUtil.fieldsCheck(message, "to", "title", "summary", "contentType", "content");
|
|
|
if (!testing.pass) {
|
|
|
throw {httpStatus: 406, message: testing.message}
|
|
|
}
|
|
|
|
|
|
// 消息处理
|
|
|
let doctor = new Doctor();
|
|
|
ControllerUtil.regModelEventHandler(doctor, res);
|
|
|
|
|
|
doctor.sendSystemMessage(message);
|
|
|
});
|
|
|
|
|
|
router.get(APIv1.Chats.TEST,function(req,res){
|
|
|
let test = req.query.test;
|
|
|
//http://192.168.131.107:3008/api/v1/chats/test?test=1&page=0&pagesize=10&user=3121&sessionId=testsessionmsg1
|
|
|
if(test==1){//获取会话消息列表
|
|
|
let page = req.query.page;
|
|
|
let pagesize = req.query.pagesize;
|
|
|
let user = req.query.user;
|
|
|
let sessionId =req.query.sessionId;
|
|
|
let sessions = new Sessions();
|
|
|
ControllerUtil.regModelEventHandler(sessions, res);
|
|
|
sessions.getMessages(sessionId,user,page,pagesize);
|
|
|
}
|
|
|
//http://192.168.131.107:3008/api/v1/chats/test?test=2&page=0&pagesize=10&user=3121
|
|
|
if(test==2){//获取用户会话
|
|
|
let sessions = new Sessions();
|
|
|
let page = req.query.page;
|
|
|
let pagesize = req.query.pagesize;
|
|
|
let user = req.query.user;
|
|
|
ControllerUtil.regModelEventHandler(sessions, res);
|
|
|
sessions.getUserSessions(user,page,pagesize);
|
|
|
}
|
|
|
//http://192.168.131.107:3008/api/v1/chats/test?test=3&sessionId=132312312&users=10,2,3&name=3121&sessionType=2
|
|
|
if(test==3){
|
|
|
let sessions = new Sessions();
|
|
|
ControllerUtil.regModelEventHandler(sessions, res);
|
|
|
let sessionId = req.query.sessionId;
|
|
|
let users = req.query.users;
|
|
|
let name = req.query.name;
|
|
|
let sessionType = req.query.sessionType;
|
|
|
sessions.createSession(sessionId,name,sessionType,users);
|
|
|
}
|
|
|
if(test==4){
|
|
|
let sessions = new Sessions();
|
|
|
ControllerUtil.regModelEventHandler(sessions, res);
|
|
|
let sessionId = req.query.sessionId;
|
|
|
let message ={};
|
|
|
message.contentType =1;
|
|
|
message.timestamp=new Date();
|
|
|
message.content ="test send message";
|
|
|
message.senderId="10";
|
|
|
message.senderName="test1";
|
|
|
sessions.saveMessageBySession(message,sessionId);
|
|
|
}
|
|
|
//http://192.168.131.107:3008/api/v1/chats/test?test=5&user=3121&sessionId=testsessionmsg1
|
|
|
if(test==5){
|
|
|
let sessions = new Sessions();
|
|
|
ControllerUtil.regModelEventHandler(sessions, res);
|
|
|
let sessionId = req.query.sessionId;
|
|
|
let user = req.query.user;
|
|
|
let type = req.query.type;
|
|
|
if(type==1){
|
|
|
//置顶
|
|
|
sessions.stickSession(sessionId,user);
|
|
|
}else{
|
|
|
//取消置顶
|
|
|
sessions.cancelStickSession(sessionId,user);
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 处理Private消息。处理流程分:
|
|
|
* 1 解析消息,并保存到数据库
|
|
|
* 2 更新消息统计数据
|
|
|
* 3 获取目标的状态并构建通知消息,如果用户在线就推送通知消息
|
|
|
*
|
|
|
* 请求URL:
|
|
|
* /chats/pm
|
|
|
*
|
|
|
* 消息格式:
|
|
|
* {
|
|
|
* from: sand,
|
|
|
* to: Rose,
|
|
|
* contentType: "1,2,3,4",
|
|
|
* content: "Please follow the patient as soon as possible."
|
|
|
* }
|
|
|
*
|
|
|
* @param message
|
|
|
*/
|
|
|
router.post(APIv1.Chats.PM, function (req, res) {
|
|
|
// 检查消息体及消息格式是否正确
|
|
|
let message = req.body;
|
|
|
if (!ObjectUtil.isJsonObject(message)) {
|
|
|
throw {httpStatus: 406, message: 'Problems parsing JSON.'}
|
|
|
}
|
|
|
|
|
|
// 字段判断
|
|
|
let testing = ObjectUtil.fieldsCheck(message, "from", "to", "contentType", "content");
|
|
|
if (!testing.pass) {
|
|
|
throw {httpStatus: 406, message: testing.message};
|
|
|
}
|
|
|
|
|
|
// 消息处理,患者与医生分开发送
|
|
|
Patient.isPatientCode(message.to,
|
|
|
function () {
|
|
|
let patient = new Patient();
|
|
|
ControllerUtil.regModelEventHandler(patient, res);
|
|
|
|
|
|
patient.sendMessage(message);
|
|
|
}, function () {
|
|
|
let doctor = new Doctor();
|
|
|
ControllerUtil.regModelEventHandler(doctor, res);
|
|
|
|
|
|
doctor.sendMessage(message);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 处理讨论组消息。
|
|
|
*
|
|
|
* 请求URL:
|
|
|
* /chats/gm
|
|
|
*
|
|
|
* 消息格式:
|
|
|
* {
|
|
|
* from: "sand", // 发送者id
|
|
|
* at: "Rose", // @人
|
|
|
* group: "DiscussionGroupId", // 所在组
|
|
|
* groupType: "1 or 2", // 组类型:行政团队或讨论组
|
|
|
* contentType: "1,2,3", // 内容类型
|
|
|
* content: "The patient mess me up" // 内容
|
|
|
* }
|
|
|
*
|
|
|
* @param message
|
|
|
*/
|
|
|
router.post(APIv1.Chats.GM, function (req, res) {
|
|
|
// 检查消息体及消息格式是否正确
|
|
|
let message = req.body;
|
|
|
|
|
|
if (!ObjectUtil.isJsonObject(message)) {
|
|
|
throw {httpStatus: 406, message: 'Problems parsing JSON.'};
|
|
|
}
|
|
|
|
|
|
// 字段判断
|
|
|
let testing = ObjectUtil.fieldsCheck(message, 'from', 'at', 'group', 'groupType', 'contentType', 'content');
|
|
|
if (!testing.pass) {
|
|
|
throw {httpStatus: 406, message: testing.message}
|
|
|
}
|
|
|
|
|
|
// 消息处理
|
|
|
let group = new Group();
|
|
|
ControllerUtil.regModelEventHandler(group, res);
|
|
|
|
|
|
group.sendMessage(message);
|
|
|
});
|
|
|
|
|
|
//--------------------------------------------------------------//
|
|
|
//----------------------------消息提取----------------------------//
|
|
|
//--------------------------------------------------------------//
|
|
|
|
|
|
/**
|
|
|
* 获取参与的聊天列表,包括:点对点,@我,参与的讨论组,系统消息等。
|
|
|
*
|
|
|
* 请求URL:
|
|
|
* /chats/list?user_id=sand
|
|
|
*/
|
|
|
router.get(APIv1.Chats.List, function (req, res) {
|
|
|
let userId = req.query.user_id;
|
|
|
if (userId === null) {
|
|
|
throw {httpStatus: 406, message: 'Missing fields.'};
|
|
|
}
|
|
|
|
|
|
let doctor = new Doctor();
|
|
|
ControllerUtil.regModelEventHandler(doctor, res);
|
|
|
|
|
|
doctor.getChatList(userId);
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 获取与患者的聊天列表,包括:P2P,参与的讨论组和行政团队。
|
|
|
*
|
|
|
* 请求URL:
|
|
|
* /chats/list/patient
|
|
|
*/
|
|
|
router.get(APIv1.Chats.ListWithPatient, function (req, res) {
|
|
|
let userId = req.query.user_id;
|
|
|
if (userId === null) {
|
|
|
throw {httpStatus: 406, message: 'Missing fields.'};
|
|
|
}
|
|
|
|
|
|
let doctor = new Doctor();
|
|
|
ControllerUtil.regModelEventHandler(doctor, res);
|
|
|
|
|
|
doctor.getChatsListWithPatient(userId);
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 获取与医生的聊天列表,包括:点对点,参与的讨论组。
|
|
|
*
|
|
|
* 请求URL:
|
|
|
* /chats/list/doctor
|
|
|
*/
|
|
|
router.get(APIv1.Chats.ListWithDoctor, function (req, res) {
|
|
|
let userId = req.query.user_id;
|
|
|
if (userId === null) {
|
|
|
throw {httpStatus: 406, message: 'Missing fields.'};
|
|
|
}
|
|
|
|
|
|
let doctor = new Doctor();
|
|
|
ControllerUtil.regModelEventHandler(doctor, res);
|
|
|
|
|
|
doctor.getChatListWithDoctor(userId);
|
|
|
});
|
|
|
|
|
|
|
|
|
router.get(APIv1.Chats.MsgAmount, function (req, res) {
|
|
|
let userId = req.query.user_id;
|
|
|
if (userId === null) {
|
|
|
throw {httpStatus: 406, message: 'Missing fields.'};
|
|
|
}
|
|
|
|
|
|
let doctor = new Doctor();
|
|
|
ControllerUtil.regModelEventHandler(doctor, res);
|
|
|
doctor.getChatListMsgAmount(userId);
|
|
|
});
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取最近聊天对象:包括患者,医生与讨论组。客户端自行根据需要提取患者、医生或讨论组数据。
|
|
|
*
|
|
|
* 请求URL:
|
|
|
* /chats/recent?user_id=0de7295862dd11e69faffa163e8aee56&days=7
|
|
|
*
|
|
|
* 参数:
|
|
|
* user_id: 用户ID
|
|
|
* target_type: 对象类型,1患者,2医生,3讨论组
|
|
|
* days: 最近天数,默认7天
|
|
|
*/
|
|
|
router.get(APIv1.Chats.Recent, function (req, res) {
|
|
|
let userId = req.query.user_id;
|
|
|
let days = req.query.days;
|
|
|
if (userId === null) {
|
|
|
throw {httpStatus: 406, message: 'Missing field: user_id'};
|
|
|
}
|
|
|
|
|
|
if (days === null) {
|
|
|
days = 7;
|
|
|
}
|
|
|
|
|
|
let doctor = new Doctor();
|
|
|
ControllerUtil.regModelEventHandler(doctor, res);
|
|
|
|
|
|
doctor.getRecentChatList(userId, days);
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 获取私信。倒序排列。
|
|
|
*
|
|
|
* 参数:
|
|
|
* user_id 必须,医生ID
|
|
|
* peer_id 必须,对方医生ID
|
|
|
* content_type 必须,消息类型
|
|
|
* message_start_id 可选,消息的起始ID,如果为空从最新的一条开始获取
|
|
|
* message_end_id 可选,消息的结束ID,如果为空从第一条开始获取
|
|
|
* count 可选,消息数量,如果不指定、小于零或大于50,默认为100条。若message_start_id与message_end_id均不为空,则此参数无效,方法是设置为10000条
|
|
|
* closed_interval 消息范围是否使用闭区间
|
|
|
*
|
|
|
* 请求URL:
|
|
|
* /chats/pm?user_id=sand&peer_id=Rose&content_type=2&message_start_id=10000&message_end_id=0&count=20&closed_interval=false
|
|
|
*/
|
|
|
router.get(APIv1.Chats.PM, function (req, res) {
|
|
|
let userId = req.query.user_id;
|
|
|
let peerId = req.query.peer_id;
|
|
|
let contentType = req.query.content_type;
|
|
|
let msgStartId = !req.query.message_start_id ? MAX_INT : parseInt(req.query.message_start_id);
|
|
|
let msgEndId = !req.query.message_end_id || req.query.message_end_id === 'null' ? 0 : parseInt(req.query.message_end_id);
|
|
|
let count = req.query.count === undefined ? DEFAULT_PAGE_SIZE : parseInt(req.query.count);
|
|
|
let closedInterval = (req.query.closed_interval != false && req.query.closed_interval === "true");
|
|
|
|
|
|
if (contentType !== undefined && parseInt(contentType) === CONTENT_TYPES.Image) count = DEFAULT_PAGE_SIZE;
|
|
|
|
|
|
if (req.query.message_start_id && req.query.message_end_id) count = 10000;
|
|
|
|
|
|
if (!userId) {
|
|
|
throw {httpStatus: 400, message: "Missing field: user_id."};
|
|
|
}
|
|
|
|
|
|
let doctor = new Doctor();
|
|
|
ControllerUtil.regModelEventHandler(doctor, res);
|
|
|
|
|
|
doctor.getPrivateMessages(userId, peerId, contentType, msgStartId, msgEndId, count, closedInterval);
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 获取未读私信。倒序排列。
|
|
|
*
|
|
|
* 参数:
|
|
|
* user_id 必须,医生ID
|
|
|
* peer_id 必须,对方医生ID
|
|
|
*
|
|
|
* 请求URL:
|
|
|
* /chats/pm/unread?user_id=sand&peer_id=Rose
|
|
|
*/
|
|
|
router.get(APIv1.Chats.PMUnread, function (req, res) {
|
|
|
let userId = req.query.user_id;
|
|
|
let peerId = req.query.peer_id;
|
|
|
|
|
|
if (userId === undefined) {
|
|
|
throw {httpStatus: 400, message: "Missing field: user_id."};
|
|
|
}
|
|
|
|
|
|
let doctor = new Doctor();
|
|
|
ControllerUtil.regModelEventHandler(doctor, res);
|
|
|
|
|
|
doctor.getUnreadPrivateMessages(userId, peerId);
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 按时间倒序获取群消息。
|
|
|
*
|
|
|
* 参数:
|
|
|
* user_id 必须,医生ID
|
|
|
* group_id 必须,组ID
|
|
|
* message_start_id 可选,消息的起始ID,如果为空从最新的一条开始获取
|
|
|
* count 可选,消息数量,如果不指定、小于零或大于50,默认为50条
|
|
|
*
|
|
|
* 请求URL:
|
|
|
* /chats/gm?user_id=D2016008240002&group_id=494&content_type=2&message_start_id=0&message_end_id=0&count=20
|
|
|
*/
|
|
|
router.get(APIv1.Chats.GM, function (req, res) {
|
|
|
let groupId = req.query.group_id;
|
|
|
let memberId = req.query.user_id;
|
|
|
let contentType = req.query.content_type;
|
|
|
let msgStartId = !req.query.message_start_id ? MAX_INT : parseInt(req.query.message_start_id);
|
|
|
let msgEndId = !req.query.message_end_id ? 0 : parseInt(req.query.message_end_id);
|
|
|
let count = req.query.count === undefined ? DEFAULT_PAGE_SIZE : parseInt(req.query.count);
|
|
|
|
|
|
if (groupId === undefined) {
|
|
|
throw {httpStatus: 400, message: "Missing field: group_id."};
|
|
|
}
|
|
|
|
|
|
if (contentType !== undefined && parseInt(contentType) === CONTENT_TYPES.Image) count = DEFAULT_PAGE_SIZE;
|
|
|
|
|
|
if (req.query.message_start_id && req.query.message_end_id) count = 100000;
|
|
|
|
|
|
let group = new Group();
|
|
|
ControllerUtil.regModelEventHandler(group, res);
|
|
|
|
|
|
group.getMessages(groupId, memberId, contentType, msgStartId, msgEndId, count);
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 获取未读群消息。
|
|
|
*
|
|
|
* 请求URL:
|
|
|
* /chats/gm/unread?group_id=discussionGroupId&user_id=sand
|
|
|
*/
|
|
|
router.get(APIv1.Chats.GMUnread, function (req, res) {
|
|
|
let memberId = req.query.user_id;
|
|
|
let groupId = req.query.group_id;
|
|
|
|
|
|
if (memberId === undefined) {
|
|
|
throw {httpStatus: 400, message: "Missing field: user_id."};
|
|
|
}
|
|
|
|
|
|
if (groupId === undefined) {
|
|
|
throw {httpStatus: 400, message: "Missing field: group_id."};
|
|
|
}
|
|
|
|
|
|
let group = new Group();
|
|
|
ControllerUtil.regModelEventHandler(group, res);
|
|
|
|
|
|
group.getUnreadMessages(groupId, memberId);
|
|
|
});
|
|
|
|
|
|
//--------------------------------------------------------------//
|
|
|
//----------------------------消息统计----------------------------//
|
|
|
//--------------------------------------------------------------//
|
|
|
|
|
|
/**
|
|
|
* 获取所有群组未读消息总数。
|
|
|
*
|
|
|
* 请求URL:
|
|
|
* /chats/gm/unread_count?user_id=sand
|
|
|
*
|
|
|
* 参数:
|
|
|
* user_id:医生ID
|
|
|
*/
|
|
|
router.get(APIv1.Chats.GMUnreadCount, function (req, res) {
|
|
|
let memberId = req.query.user_id;
|
|
|
if (memberId === null) {
|
|
|
throw {httpStatus: 406, message: 'Missing fields.'};
|
|
|
}
|
|
|
|
|
|
let group = new Group();
|
|
|
ControllerUtil.regModelEventHandler(group, res);
|
|
|
|
|
|
group.getUnreadMessageCount(memberId);
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 获取特定群组消息统计情况。
|
|
|
*
|
|
|
* /chats/gm/statistic?group_id=GGG&&user_id=sand
|
|
|
*
|
|
|
* 参数:
|
|
|
* user_id:信息所有者id
|
|
|
* group_id:群组id
|
|
|
*/
|
|
|
router.get(APIv1.Chats.GMStats, function (req, res) {
|
|
|
let memberId = req.query.user_id;
|
|
|
let groupId = req.query.group_id;
|
|
|
if (memberId === null || groupId === null) {
|
|
|
throw {httpStatus: 406, message: 'Miss fields.'};
|
|
|
}
|
|
|
|
|
|
let group = new Group();
|
|
|
ControllerUtil.regModelEventHandler(group, res);
|
|
|
|
|
|
group.getChatSummary(groupId, memberId);
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 获取与某人的私信统计。
|
|
|
*
|
|
|
* /chats/pm/statistic?user_id=sand&&peer_id=rose
|
|
|
*
|
|
|
* 参数:
|
|
|
* user_id:信息所有者id
|
|
|
* peer_id:聊天对端id
|
|
|
*/
|
|
|
router.get(APIv1.Chats.PMStats, function (req, res) {
|
|
|
let userId = req.query.user_id;
|
|
|
let peerId = req.query.peer_id;
|
|
|
if (userId == null || peerId == null) {
|
|
|
throw {httpStatus: 406, message: "Missing fields."};
|
|
|
}
|
|
|
|
|
|
let doctor = new Doctor();
|
|
|
ControllerUtil.regModelEventHandler(doctor, res);
|
|
|
|
|
|
doctor.getChatSummary(userId, peerId);
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 获取所有未读私信总数。
|
|
|
*
|
|
|
* /chats/pm/unread_count?user_id=sand
|
|
|
*
|
|
|
* 参数:
|
|
|
* uid:信息所有者id
|
|
|
*/
|
|
|
router.get(APIv1.Chats.PMUnreadCount, function (req, res) {
|
|
|
let userId = req.query.user_id;
|
|
|
|
|
|
let doctor = new Doctor();
|
|
|
ControllerUtil.regModelEventHandler(doctor, res);
|
|
|
|
|
|
doctor.getUnreadPrivateMessages(userId);
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 所有聊天消息未读数。
|
|
|
*
|
|
|
* 请求URL:
|
|
|
* /chats/chats/unread_count?user_id=sand
|
|
|
*
|
|
|
* 参数:
|
|
|
* user_id:信息所有者id
|
|
|
*/
|
|
|
router.get(APIv1.Chats.UnreadMsgCount, function (req, res) {
|
|
|
let userId = req.query.user_id;
|
|
|
if (userId === null) {
|
|
|
throw {httpStatus: 406, message: "Missing fields."};
|
|
|
}
|
|
|
|
|
|
let doctor = new Doctor();
|
|
|
ControllerUtil.regModelEventHandler(doctor, res);
|
|
|
|
|
|
doctor.getAllUnreadMessageCount(userId);
|
|
|
});
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 搜索患者相关的数据,包括患者信息与相关的私信记录。关键词不支持空格拆分。
|
|
|
*
|
|
|
* 请求URL:
|
|
|
* http://192.168.131.107:3000/api/v1/chats/search/patient?user_id=D2016008240003&user_role=3&keyword=fa
|
|
|
*
|
|
|
* 参数:
|
|
|
* keywords: 关键词
|
|
|
*/
|
|
|
router.get(APIv1.Chats.SearchAboutPatient, function (req, res) {
|
|
|
var userId = req.query.user_id;
|
|
|
var userRole = req.query.user_role;
|
|
|
var keyword = req.query.keyword;
|
|
|
|
|
|
if (!userId) throw {httpStatus: 406, message: "Missing fields: user_id."};
|
|
|
if (!userRole) throw {httpStatus: 406, message: "Missing fields: user_role."};
|
|
|
if (!keyword) throw {httpStatus: 406, message: "Missing fields: keyword."};
|
|
|
let search = new Search();
|
|
|
ControllerUtil.regModelEventHandler(search, res);
|
|
|
search.searchAboutPatient(userId, userRole, keyword);
|
|
|
});
|
|
|
/**
|
|
|
* 获取某个聊天的关键字搜索记录列表
|
|
|
* 请求URL:
|
|
|
*http://192.168.131.107:3000/api/v1/chats/search/patient/list?user_id=D2016008240003&keyword=f&group_id=e2b695b9daf74d0faeb90a304ae587a0&type=1
|
|
|
*/
|
|
|
router.get(APIv1.Chats.SearchAboutPatientList, function (req, res) {
|
|
|
var userId = req.query.user_id;
|
|
|
var groupId = req.query.group_id;
|
|
|
var keyword = req.query.keyword;
|
|
|
var type = req.query.type;
|
|
|
if (!userId) throw {httpStatus: 406, message: "Missing fields: user_id."};
|
|
|
if (!groupId) throw {httpStatus: 406, message: "Missing fields: group_id."};
|
|
|
if (!keyword) throw {httpStatus: 406, message: "Missing fields: keyword."};
|
|
|
if (!type) throw {httpStatus: 406, message: "Missing fields: type."};
|
|
|
let search = new Search();
|
|
|
ControllerUtil.regModelEventHandler(search, res);
|
|
|
search.searchAboutPatientList(userId, keyword,groupId,type);
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* http://192.168.131.107:3000/api/v1/chats/search/patient/all?user_id=D2016008240003&keyword=f&type=2&user_role=3
|
|
|
* 患者消息查询查看更多
|
|
|
*/
|
|
|
router.get(APIv1.Chats.SearchAbountPatientMore, function (req, res) {
|
|
|
var userId = req.query.user_id;
|
|
|
var keyword = req.query.keyword;
|
|
|
var type = req.query.type;
|
|
|
var userRole= req.query.user_role;
|
|
|
if (!userId) throw {httpStatus: 406, message: "Missing fields: user_id."};
|
|
|
if (!keyword) throw {httpStatus: 406, message: "Missing fields: keyword."};
|
|
|
if (!type) throw {httpStatus: 406, message: "Missing fields: type."};
|
|
|
if (!userRole) throw {httpStatus: 406, message: "Missing fields: userRole."};
|
|
|
let search = new Search();
|
|
|
ControllerUtil.regModelEventHandler(search, res);
|
|
|
search.searchAboutPatientAll(userId,userRole, keyword,type);
|
|
|
});
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 搜索医生相关的数据,包括医生信息与相关的聊天记录,包括私信与群信。
|
|
|
*
|
|
|
* 请求URL:
|
|
|
* /search/doctor?user_id=D2016008240003&keyword=黄
|
|
|
*
|
|
|
* 参数:
|
|
|
* keywords: 关键词
|
|
|
*/
|
|
|
router.get(APIv1.Chats.SearchAboutDoctor, function (req, res) {
|
|
|
let userId = req.query.user_id;
|
|
|
let keyword = req.query.keyword;
|
|
|
|
|
|
if (!userId) throw {httpStatus: 406, message: "Missing fields: user_id."};
|
|
|
if (!keyword) throw {httpStatus: 406, message: "Missing fields: keyword."};
|
|
|
|
|
|
let search = new Search();
|
|
|
ControllerUtil.regModelEventHandler(search, res);
|
|
|
|
|
|
search.searchAboutDoctor(userId, keyword);
|
|
|
});
|
|
|
/**
|
|
|
* http://192.168.131.107:3000/api/v1/chats/search/doctor/list?user_id=D2016008240003&keyword=%E9%BB%84&type=2
|
|
|
* 医生搜索查看更多
|
|
|
* type = 1 查询聊过的医生
|
|
|
* type = 2 查询群组标题和人员包含的群聊
|
|
|
* type = 3 查询聊天关键字
|
|
|
*/
|
|
|
router.get(APIv1.Chats.SearchAboutDoctorList, function (req, res) {
|
|
|
let userId = req.query.user_id;
|
|
|
let keyword = req.query.keyword;
|
|
|
let type = req.query.type;
|
|
|
if (!userId) throw {httpStatus: 406, message: "Missing fields: user_id."};
|
|
|
if (!keyword) throw {httpStatus: 406, message: "Missing fields: keyword."};
|
|
|
if (!type) throw {httpStatus: 406, message: "Missing fields: type."};
|
|
|
let search = new Search();
|
|
|
ControllerUtil.regModelEventHandler(search, res);
|
|
|
search.searchDoctorMore(userId, keyword,type);
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 查询医生聊天记录详情(单个聊天记录包含关键字的)
|
|
|
*http://192.168.131.107:3000/api/v1/chats/search/doctor/content/list?user_id=D2016008240003&keyword=f&type=2&groupcode=0381288df51b434795b6946bb63d90b8
|
|
|
*/
|
|
|
router.get(APIv1.Chats.SearchAbountDoctorContentDetail, function (req, res) {
|
|
|
let userId = req.query.user_id;
|
|
|
let keyword = req.query.keyword;
|
|
|
let type = req.query.type;
|
|
|
let groupcode = req.query.groupcode;
|
|
|
if (!userId) throw {httpStatus: 406, message: "Missing fields: user_id."};
|
|
|
if (!keyword) throw {httpStatus: 406, message: "Missing fields: keyword."};
|
|
|
if (!type) throw {httpStatus: 406, message: "Missing fields: type."};
|
|
|
if (!groupcode) throw {httpStatus: 406, message: "Missing fields: groupcode."};
|
|
|
let search = new Search();
|
|
|
ControllerUtil.regModelEventHandler(search, res);
|
|
|
search.searchDoctorContentDetail(userId, keyword,groupcode,type);
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取单条消息。
|
|
|
*
|
|
|
* URL:
|
|
|
* /chats/message?id=1234&type=1
|
|
|
*/
|
|
|
router.get(APIv1.Chats.Message, function (req, res) {
|
|
|
let messageId = req.query.id;
|
|
|
let messageType = req.query.type;
|
|
|
|
|
|
let doctor = new Doctor();
|
|
|
ControllerUtil.regModelEventHandler(doctor, res);
|
|
|
|
|
|
doctor.getMessage(messageId, messageType);
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 判断当前会话是否已经结束。
|
|
|
*
|
|
|
* 请求URL:
|
|
|
* /chats/pm/finished?user_id=sand&peer_id=rose
|
|
|
*/
|
|
|
router.get(APIv1.Chats.PMFinished, function (req, res) {
|
|
|
let doctorId = req.query.doctor_id;
|
|
|
let patientId = req.query.patient_id;
|
|
|
if (!doctorId) {
|
|
|
throw {httpStatus: 406, message: "Missing field: doctor_id"};
|
|
|
}
|
|
|
|
|
|
if (!patientId) {
|
|
|
throw {httpStatus: 406, message: "Missing field: patient_id"};
|
|
|
}
|
|
|
|
|
|
let doctor = new Doctor();
|
|
|
ControllerUtil.regModelEventHandler(doctor, res);
|
|
|
|
|
|
doctor.isConsultFinished(doctorId, patientId);
|
|
|
});
|
|
|
|
|
|
module.exports = router;
|