/** * 患者模型。 */ "use strict"; let configFile = require('../include/commons').CONFIG_FILE; let config = require('../resources/config/' + configFile); let log = require("../util/log.js"); let patientRepo = require('../repository/patient.repo'); let objectUtil = require("../util/objectUtil.js"); let clientCache = require('./socket.io/client.cache').clientCache(); class Patient { constructor() { } /** * 是否为患者代码。 * * @param code * @param passedCallback 测试通过回调 * @param failedCallback 测试失败回调 */ isPatientCode(code, passedCallback, failedCallback) { patientRepo.isPatientCode(code, function (err, result) { if (err) { log.error('Send message to patient failed: ', err); return; } if (result[0].c > 0) { passedCallback(); } else { failedCallback(); } }); } /** * 向患者发送消息。 * * @param patientId 患者ID * @param message 消息 */ sendMessage(patientId, message) { let patientClient = clientCache.findById(patientId); if (!patientClient) { log.warn("User is not online, user id: ", patientId); return; } patientClient.socketServer.sockets.emit('message', message); }; } module.exports = Patient;