patient.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * 患者模型。
  3. */
  4. "use strict";
  5. let configFile = require('../include/commons').CONFIG_FILE;
  6. let config = require('../resources/config/' + configFile);
  7. let log = require("../util/log.js");
  8. let BaseModel = require('./base.model');
  9. let patientRepo = require('../repository/patient.repo');
  10. let objectUtil = require("../util/objectUtil.js");
  11. let clientCache = require('./socket.io/client.cache').clientCache();
  12. class Patient extends BaseModel{
  13. constructor() {
  14. super();
  15. }
  16. /**
  17. * 是否为患者代码。
  18. *
  19. * @param code
  20. * @param passedCallback 测试通过回调
  21. * @param failedCallback 测试失败回调
  22. */
  23. isPatientCode(code, passedCallback, failedCallback) {
  24. patientRepo.isPatientCode(code, function (err, result) {
  25. if (err) {
  26. log.error('Send message to patient failed: ', err);
  27. return;
  28. }
  29. if (result[0].c > 0) {
  30. passedCallback();
  31. } else {
  32. failedCallback();
  33. }
  34. });
  35. }
  36. /**
  37. * 向患者发送消息。
  38. *
  39. * @param patientId 患者ID
  40. * @param message 消息
  41. */
  42. sendMessage(patientId, message) {
  43. let patientClient = clientCache.findById(patientId);
  44. if (!patientClient) {
  45. log.warn("User is not online, user id: ", patientId);
  46. return;
  47. }
  48. patientClient.socketServer.sockets.emit('message', message);
  49. };
  50. }
  51. module.exports = Patient;