patient.js 1.4 KB

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