YzActOrderModifyService.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package thyyxxk.webserver.service.datamodify;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Service;
  8. import thyyxxk.webserver.config.exception.ExceptionEnum;
  9. import thyyxxk.webserver.dao.his.datamodify.YzActOrderDao;
  10. import thyyxxk.webserver.entity.ResultVo;
  11. import thyyxxk.webserver.entity.datamodify.TYzActOrderModify;
  12. import thyyxxk.webserver.entity.datamodify.YzActOrder;
  13. import thyyxxk.webserver.utils.ResultVoUtil;
  14. import thyyxxk.webserver.utils.StringUtil;
  15. import thyyxxk.webserver.utils.TokenUtil;
  16. import thyyxxk.webserver.websocket.WebSocketServer;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. /**
  20. * <p>
  21. * 医嘱修改服务类
  22. * </p>
  23. *
  24. * @author 肖蟾
  25. * @since 2021-03-08
  26. */
  27. @Service
  28. @Slf4j
  29. public class YzActOrderModifyService {
  30. private final YzActOrderDao dao;
  31. private static final String DATE_FORMAT = "yyyy-MM-dd HH:ss:mm";
  32. @Autowired
  33. public YzActOrderModifyService(YzActOrderDao dao) {
  34. this.dao = dao;
  35. }
  36. /**
  37. * 根据医嘱号 来查询 符合条件的数据
  38. *
  39. * @param param 医嘱号 和 住院号查询
  40. * @return 返回医嘱号和医嘱名称
  41. */
  42. public ResultVo<List<YzActOrder>> queryYz(YzActOrder param) {
  43. QueryWrapper<YzActOrder> qw = new QueryWrapper<>();
  44. log.info("医嘱修改申请查询 --> 医嘱号:{},住院号:{}", param.getActOrderNo(), param.getInpatientNo());
  45. if (param.getActOrderNo() != null) {
  46. qw.eq("a.act_order_no", param.getActOrderNo());
  47. }
  48. if (StringUtil.notBlank(param.getInpatientNo())) {
  49. qw.eq("a.inpatient_no", param.getInpatientNo());
  50. }
  51. List<YzActOrder> list = dao.listQueryYz(qw);
  52. if (list.size() > 0) {
  53. return ResultVoUtil.success(list);
  54. }
  55. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
  56. }
  57. /**
  58. * 提交医嘱修改申请 这里是多个医嘱修改
  59. *
  60. * @param param 提交申请的信息
  61. * @return 返回提示
  62. */
  63. public ResultVo<Boolean> yzModifyApply(TYzActOrderModify param) {
  64. log.info("申请医嘱修改 --> 申请人:{},数据:{}",
  65. TokenUtil.getTokenUserId(), JSON.toJSONStringWithDateFormat(param, DATE_FORMAT));
  66. List<TYzActOrderModify> insertList = new ArrayList<>();
  67. List<TYzActOrderModify> updateList = new ArrayList<>();
  68. for (TYzActOrderModify pojo : param.getList()) {
  69. if (dao.chaKansfCunZai(pojo.getActOrderNo()) == 0) {
  70. insertList.add(pojo);
  71. } else {
  72. updateList.add(pojo);
  73. }
  74. }
  75. if (insertList.size() > 0) {
  76. dao.yzActOrderModifyInsert(param, insertList);
  77. }
  78. if (updateList.size() > 0) {
  79. dao.yzActOrderModifyUpdate(param, updateList);
  80. }
  81. //这里是通知有权限的人
  82. sendMessage();
  83. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "申请成功,已通知审核人员。<br />可以在上方查看审核状态 (•‾̑⌣‾̑•)✧˖°");
  84. }
  85. /**
  86. * 根据 人员的 code 来查看他申请的医嘱
  87. *
  88. * @param code 编码
  89. * @return 返回这个人 申请修改的医嘱
  90. */
  91. public ResultVo<List<TYzActOrderModify>> chaKanZhuangTai(String code) {
  92. log.info("根据人员的code查询医嘱修改申请:{}", code);
  93. return ResultVoUtil.success(dao.queryZhuangTai(code));
  94. }
  95. /**
  96. * 单个医嘱修改
  97. *
  98. * @param param 要修改的信息
  99. * @return 返回提示成功
  100. */
  101. public ResultVo<String> danGeShenQing(TYzActOrderModify param) {
  102. param.setProposer(TokenUtil.getTokenUserId());
  103. log.info("申请医嘱修改 --> 申请人:{},数据:{}", param.getProposer(), JSON.toJSONStringWithDateFormat(param, DATE_FORMAT));
  104. if (dao.chaKansfCunZai(param.getActOrderNo()) == 0) {
  105. dao.danGeShenQingInsert(param);
  106. } else {
  107. dao.danGeShenQingUpdate(param);
  108. }
  109. sendMessage();
  110. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "申请成功,已通知审核人员。<br />可以在上方查看审核状态 (•‾̑⌣‾̑•)✧˖°");
  111. }
  112. /**
  113. * 通知有医嘱修改审核权限的人
  114. */
  115. private void sendMessage() {
  116. List<String> admins = dao.selectAdmins();
  117. JSONObject obj = new JSONObject();
  118. obj.put("name", "systemNotification");
  119. obj.put("message", String.format("用户【%s】提交了医嘱修改申请,请前往审核页面查看。", dao.getUserName(TokenUtil.getTokenUserId())));
  120. String message = obj.toJSONString();
  121. admins.forEach(code -> WebSocketServer.sendMessageByUserCode(code, message));
  122. }
  123. }