123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- /**
- * 患者模型。
- */
- "use strict";
- let configFile = require('../include/commons').CONFIG_FILE;
- let config = require('../resources/config/' + configFile);
- let log = require("../util/log.js");
- let BaseModel = require('./base.model');
- let patientRepo = require('../repository/patient.repo');
- let objectUtil = require("../util/objectUtil.js");
- let clientCache = require('./socket.io/client.cache').clientCache();
- class Patient extends BaseModel{
- constructor() {
- super();
- }
- /**
- * 是否为患者代码。
- *
- * @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;
|