8 лет назад
Родитель
Сommit
0a21081a44

+ 13 - 0
src/doctor/endpoints/chats.endpoint.js

@ -208,6 +208,19 @@ router.get(APIv1.Chats.ListWithPatient, function (req, res) {
    doctor.getChatsListWithPatient(userId);
});
router.get(APIv1.Chats.ListWithSystem, 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.getSystemMsgList(userId);
});
/**
 * 获取与医生的聊天列表,包括:点对点,参与的讨论组。
 *

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

@ -16,6 +16,7 @@ const APIv1 = {
        List: "/list",
        ListWithPatient: "/list/patient",
        ListWithDoctor: "/list/doctor",
        ListWithSystem:"/list/system",
        MsgAmount:"/msg/amount",
        Recent: '/recent',
        SearchAboutPatient: '/search/patient',

+ 208 - 64
src/doctor/models/doctor.js

@ -245,7 +245,7 @@ class Doctor extends BaseModel {
                return;
            }
            let chats = {patients: [], doctors: [], groups: []};
            let chats = {patients: [], doctors: [], groups: [],systems:[]};
            for (let i = 0; i < patients.length; i++) {
                let patient = patients[i];
                chats.patients.push({
@ -300,8 +300,107 @@ class Doctor extends BaseModel {
                                timestamp: objectUtil.timestampToLong(group.timestamp)
                            });
                        }
                        modelUtil.emitData(self.eventEmitter, chats);
                        //系统消息 type 1
                        smRepo.getLastMessageByType(userId,"302,303,304,305,401,402,403,404,405",function(err,res){
                            if (err) {
                                modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                                return;
                            }
                            let system={lastContent:"",czrq:"",amount:"0",title:"系统消息",type:"1"};
                            if(res.length>0){
                                system.lastContent = res[0]["lastContent"];
                                system.czrq = res[0]["czrq"];
                            }
                            smRepo.getMessagesAmountByType(userId,"302,303,304,305,401,402,403,404,405",function(err,res){
                                if (err) {
                                    modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                                    return;
                                }
                                system.amount=res[0]["amount"];
                                chats.systems.push(system);
                                //审核处理 type 2
                                smRepo.getLastMessageByType(userId,"301",function(err,res){
                                    if (err) {
                                        modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                                        return;
                                    }
                                    let audit={lastContent:"",czrq:"",amount:"0",title:"审核处理",type:"2"};
                                    if(res.length>0){
                                        audit.lastContent = res[0]["lastContent"];
                                        audit.czrq = res[0]["czrq"];
                                    }
                                    smRepo.getMessagesAmountByType(userId,"301",function(err,res){
                                        if (err) {
                                            modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                                            return;
                                        }
                                        audit.amount=res[0]["amount"];
                                        chats.systems.push(audit);
                                        //在线咨询 type 3
                                        smRepo.getLastMessageByType(userId,"101",function(err,res){
                                            if (err) {
                                                modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                                                return;
                                            }
                                            let consult={lastContent:"",czrq:"",amount:"0",title:"在线咨询",type:"3"};
                                            if(res.length>0){
                                                consult.lastContent = res[0]["lastContent"];
                                                consult.czrq = res[0]["czrq"];
                                            }
                                            smRepo.getMessagesAmountByType(userId,"101",function(err,res){
                                                if (err) {
                                                    modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                                                    return;
                                                }
                                                consult.amount=res[0]["amount"];
                                                chats.systems.push(consult);
                                                //预约就诊 type 4
                                                smRepo.getLastMessageByType(userId,"201",function(err,res){
                                                    if (err) {
                                                        modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                                                        return;
                                                    }
                                                    let appo={lastContent:"",czrq:"",amount:"0",title:"预约就诊",type:"4"};
                                                    if(res.length>0){
                                                        appo.lastContent = res[0]["lastContent"];
                                                        appo.czrq = res[0]["czrq"];
                                                    }
                                                    smRepo.getMessagesAmountByType(userId,"201",function(err,res){
                                                        if (err) {
                                                            modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                                                            return;
                                                        }
                                                        appo.amount=res[0]["amount"];
                                                        chats.systems.push(appo);
                                                        //反馈意见 type 5
                                                        smRepo.getLastMessageByType(userId,"501",function(err,res){
                                                            if (err) {
                                                                modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                                                                return;
                                                            }
                                                            let view={lastContent:"",czrq:"",amount:"0",title:"反馈意见",type:"5"};
                                                            if(res.length>0){
                                                                view.lastContent = res[0]["lastContent"];
                                                                view.czrq = res[0]["czrq"];
                                                            }
                                                            smRepo.getMessagesAmountByType(userId,"501",function(err,res){
                                                                if (err) {
                                                                    modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                                                                    return;
                                                                }
                                                                view.amount=res[0]["amount"];
                                                                chats.systems.push(view);
                                                                modelUtil.emitData(self.eventEmitter, chats);
                                                            });
                                                        })
                                                    });
                                                })
                                            });
                                        })
                                    });
                                })
                            });
                        })
                    });
                });
        });
@ -368,39 +467,117 @@ class Doctor extends BaseModel {
                                timestamp: objectUtil.timestampToLong(group.timestamp)
                            });
                        }
                        smRepo.getAppoList(userId,function(err,appo){
                    });
            });
        });
    }
    getSystemMsgList(userId){
        let self = this;
        let chats = {systems:[]};
        smRepo.getLastMessageByType(userId,"302,303,304,305,401,402,403,404,405",function(err,res){
            if (err) {
                modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                return;
            }
            let system={lastContent:"",czrq:"",amount:"0",title:"系统消息",type:"1"};
            if(res.length>0){
                system.lastContent = res[0]["lastContent"];
                system.czrq = objectUtil.timestampToLong(res[0]["czrq"]);
            }
            smRepo.getMessagesAmountByType(userId,"302,303,304,305,401,402,403,404,405",function(err,res){
                if (err) {
                    modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                    return;
                }
                system.amount=res[0]["amount"];
                chats.systems.push(system);
                //审核处理 type 2
                smRepo.getLastMessageByType(userId,"301",function(err,res){
                    if (err) {
                        modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                        return;
                    }
                    let audit={lastContent:"",czrq:"",amount:"0",title:"审核处理",type:"2"};
                    if(res.length>0){
                        audit.lastContent = res[0]["lastContent"];
                        audit.czrq = objectUtil.timestampToLong(res[0]["czrq"]);
                    }
                    smRepo.getMessagesAmountByType(userId,"301",function(err,res){
                        if (err) {
                            modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                            return;
                        }
                        audit.amount=res[0]["amount"];
                        chats.systems.push(audit);
                        //在线咨询 type 3
                        smRepo.getLastMessageByType(userId,"101",function(err,res){
                            if (err) {
                                modelUtil.emitDbError(self.eventEmitter, 'Get group list with doctor failed', err);
                                modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                                return;
                            }
                            var appoArray=[];
                            var appolist={};
                            appolist.newMessageCount = appo.length;
                            appolist.lastContent = appo[0].lastContent;
                            appoArray.push(appolist);
                            chats.system.appo = appoArray;
                            smRepo.getSystemList(userId,function(err,sys){
                            let consult={lastContent:"",czrq:"",amount:"0",title:"在线咨询",type:"3"};
                            if(res.length>0){
                                consult.lastContent = res[0]["lastContent"];
                                consult.czrq = objectUtil.timestampToLong(res[0]["czrq"]);
                            }
                            smRepo.getMessagesAmountByType(userId,"101",function(err,res){
                                if (err) {
                                    modelUtil.emitDbError(self.eventEmitter, 'Get group list with doctor failed', err);
                                    modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                                    return;
                                }
                                var sysarry=[];
                                var syslist={};
                                syslist.newMessageCount = sys.length;
                                if(sys.length>0){
                                 syslist.lastContent = sys[0].lastContent;
                                }else{
                                    syslist.lastContent="";
                                }
                                sysarry.push(syslist)
                                chats.system.sysInfo = sysarry;
                                modelUtil.emitData(self.eventEmitter, chats);
                            })
                                consult.amount=res[0]["amount"];
                                chats.systems.push(consult);
                                //预约就诊 type 4
                                smRepo.getLastMessageByType(userId,"201",function(err,res){
                                    if (err) {
                                        modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                                        return;
                                    }
                                    let appo={lastContent:"",czrq:"",amount:"0",title:"预约就诊",type:"4"};
                                    if(res.length>0){
                                        appo.lastContent = res[0]["lastContent"];
                                        appo.czrq = objectUtil.timestampToLong(res[0]["czrq"]);
                                    }
                                    smRepo.getMessagesAmountByType(userId,"201",function(err,res){
                                        if (err) {
                                            modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                                            return;
                                        }
                                        appo.amount=res[0]["amount"];
                                        chats.systems.push(appo);
                                        //反馈意见 type 5
                                        smRepo.getLastMessageByType(userId,"501",function(err,res){
                                            if (err) {
                                                modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                                                return;
                                            }
                                            let view={lastContent:"",czrq:"",amount:"0",title:"反馈意见",type:"5"};
                                            if(res.length>0){
                                                view.lastContent = res[0]["lastContent"];
                                                view.czrq = objectUtil.timestampToLong(res[0]["czrq"]);
                                            }
                                            smRepo.getMessagesAmountByType(userId,"501",function(err,res){
                                                if (err) {
                                                    modelUtil.emitDbError(self.eventEmitter, 'Get getLastMessageByType list with doctor failed', err);
                                                    return;
                                                }
                                                view.amount=res[0]["amount"];
                                                chats.systems.push(view);
                                                modelUtil.emitData(self.eventEmitter, chats);
                                            });
                                        })
                                    });
                                })
                            });
                        })
                    });
                })
            });
        });
        })
    }
    
    
    /**
     * 获取与患者的聊天列表。
     */
@ -413,7 +590,7 @@ class Doctor extends BaseModel {
                return;
            }
            let chats = {patients: [], groups: []};
            let chats = {patients: []};
            for (let i = 0; i < patients.length; i++) {
                let patient = patients[i];
                chats.patients.push({
@ -428,32 +605,7 @@ class Doctor extends BaseModel {
                    timestamp: objectUtil.timestampToLong(patient.timestamp)
                });
            }
            gmRepo.findAllGroupsWithPatient(userId, function (err, groups) {
                if (err) {
                    modelUtil.emitDbError(self.eventEmitter, 'Get group list with patient failed', err);
                    return;
                }
                for (let i = 0; i < groups.length; i++) {
                    let group = groups[i];
                    // 过滤掉医生间的求助团队
                    if (group.group_type === 2) continue;
                    chats.groups.push({
                        code: group.code,
                        name: group.name,
                        groupType: group.msg_type,
                        newMessageCount: group.new_msg_count,
                        lastContentType: group.last_content_type,
                        lastContent: group.last_content,
                        timestamp: objectUtil.timestampToLong(group.timestamp)
                    });
                }
                modelUtil.emitData(self.eventEmitter, chats);
            })
            modelUtil.emitData(self.eventEmitter, chats);
        });
    }
@ -562,22 +714,14 @@ class Doctor extends BaseModel {
                    }
                    chats.patient  = patientAmount;
                    smRepo.getAppoList(userId,function(err, res){
                    smRepo.getMessagesAmountByType(userId,"101,201,301,302,303,304,401,402,403,404,405,501",function(err, res){
                        if (err) {
                            modelUtil.emitDbError(self.eventEmitter, 'Get chat list with patient failed', err);
                            return;
                        }else{
                            chats.appo  = res.length;
                        }
                        smRepo.getSystemList(userId,function(err,res){
                            if (err) {
                                modelUtil.emitDbError(self.eventEmitter, 'Get chat list with patient failed', err);
                                return;
                            }else{
                                chats.sysInfo  = res.length;
                            }
                            chats.sysInfo = res[0]['amount'];
                            modelUtil.emitData(self.eventEmitter, chats);
                        })
                        }
                    })
                });
            });

+ 3 - 3
src/doctor/repository/group.repo.js

@ -62,9 +62,9 @@ exports.getMembersAvatar = function (groups, handler) {
     "WHERE m.doctor_code = d.code AND m.team_id IN (" + groups + ") GROUP BY m.team_id";*/
    var sql = "SELECT * FROM("+
        "SELECT m.team_id g_code, d.code code, d.name name, d.photo photo, 'doctor' type " +
        "FROM ydf_doctor_team_member m, wlyy_doctor d " +
        "WHERE m.doctor_code = d.code AND m.team_id IN (" + groups + ") " +
        "SELECT m.team_id g_code, d.id code, d.name name, d.photo photo, 'doctor' type " +
        "FROM ydf_doctor_team_member m, ydf_doctor d " +
        "WHERE m.doctor_code = d.id AND m.team_id IN (" + groups + ") " +
        ") x ORDER BY x.g_code";
    wlyyRepo.execQuery({

+ 6 - 6
src/doctor/repository/system.msg.repo.js

@ -11,17 +11,17 @@ exports.save = function(to, contentType, title, summary, content, handler) {
    });
};
exports.getSystemList=function(userId, handler){
    let sql ="select m.content as lastContent FROM ydf_message m  where  m.receiver = ? and m.sender<>? and m.type in(301,302,303,304,305) and m.readonly =1  order by m.czrq desc";
exports.getLastMessageByType = function (userId,type, handler) {
    var sql="select m.content as lastContent,m.czrq FROM ydf_message m  where  m.type in ("+type+")  and m.readonly = 1 and m.receiver = ?  order by m.czrq desc limit 0,1" ;
    imRepo.execQuery({
        "sql": sql,
        "args": [userId,userId],
        "args": [userId],
        "handler": handler
    });
}
};
exports.getAppoList = function (userId, handler) {
    var sql="select m.content as lastContent FROM ydf_message m,ydf_appointment a where m.appointment_id = a.id and a.`status` = 0 and m.type=201 and m.receiver = ?  order by m.czrq desc " ;
exports.getMessagesAmountByType = function (userId,type, handler) {
    var sql="select count(1) as amount  FROM ydf_message m  where  m.readonly = 1 and m.type in ("+type+") and m.receiver = ?  order by m.czrq desc " ;
    imRepo.execQuery({
        "sql": sql,
        "args": [userId],