Ver código fonte

Merge branch 'dev' of linzhuo/im.doctor into dev

sand 8 anos atrás
pai
commit
4aa3492739

+ 22 - 6
src/doctor/endpoints/chats.endpoint.js

@ -468,25 +468,41 @@ router.get(APIv1.Chats.UnreadMsgCount, function (req, res) {
 * 搜索患者相关的数据,包括患者信息与相关的私信记录。关键词不支持空格拆分。
 * 搜索患者相关的数据,包括患者信息与相关的私信记录。关键词不支持空格拆分。
 *
 *
 * 请求URL:
 * 请求URL:
 *  /search/patient?user_id=3b723bb8699a11e69f7c005056850d66&user_role=1&keyword=庄
 *  http://192.168.131.107:3000/api/v1/chats/search/patient?user_id=D2016008240003&user_role=3&keyword=fa
 *
 *
 * 参数:
 * 参数:
 *  keywords: 关键词
 *  keywords: 关键词
 */
 */
router.get(APIv1.Chats.SearchAboutPatient, function (req, res) {
router.get(APIv1.Chats.SearchAboutPatient, function (req, res) {
    let userId = req.query.user_id;
    let userRole = req.query.user_role;
    let keyword = req.query.keyword;
    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 (!userId) throw {httpStatus: 406, message: "Missing fields: user_id."};
    if (!userRole) throw {httpStatus: 406, message: "Missing fields: user_role."};
    if (!userRole) throw {httpStatus: 406, message: "Missing fields: user_role."};
    if (!keyword) throw {httpStatus: 406, message: "Missing fields: keyword."};
    if (!keyword) throw {httpStatus: 406, message: "Missing fields: keyword."};
    let search = new Search();
    let search = new Search();
    controllerUtil.regModelEventHandler(search, res);
    controllerUtil.regModelEventHandler(search, res);
    search.searchAboutPatient(userId, userRole, keyword);
    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);
});
/**
/**
 * 搜索医生相关的数据,包括医生信息与相关的聊天记录,包括私信与群信。
 * 搜索医生相关的数据,包括医生信息与相关的聊天记录,包括私信与群信。

+ 1 - 0
src/doctor/include/endpoints.js

@ -19,6 +19,7 @@ const APIv1 = {
        Recent: '/recent',
        Recent: '/recent',
        SearchAboutPatient: '/search/patient',
        SearchAboutPatient: '/search/patient',
        SearchAboutPatientList:'/search/patient/list',
        SearchAboutDoctor: '/search/doctor',
        SearchAboutDoctor: '/search/doctor',
        // 所有未读消息数
        // 所有未读消息数

+ 58 - 25
src/doctor/models/search.js

@ -27,15 +27,18 @@ class Search extends BaseModel{
     */
     */
    searchAboutPatient(userId, userRole, keyword) {
    searchAboutPatient(userId, userRole, keyword) {
        let self = this;
        let self = this;
        searchRepo.searchPatients(userId, userRole, keyword, function (err, patients) {
        searchRepo.searchPatients(userId, userRole, keyword, function (err, patients) {
            if (err) {
            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;
                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({
                data.patients.push({
                    code: patient.code,
                    code: patient.code,
                    name: patient.name,
                    name: patient.name,
@ -47,36 +50,66 @@ class Search extends BaseModel{
            searchRepo.searchPatientPM(userId, keyword, function (err, chats) {
            searchRepo.searchPatientPM(userId, keyword, function (err, chats) {
                if (err) {
                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;
                    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);
                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);
        })
    }
    /**
    /**
     * 搜索医生相关的数据,包括医生信息与相关的聊天记录,包括私信与群信。
     * 搜索医生相关的数据,包括医生信息与相关的聊天记录,包括私信与群信。
     */
     */

Diferenças do arquivo suprimidas por serem muito extensas
+ 39 - 6
src/doctor/repository/search.repo.js