CaoYaoYiZhuServer.java 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. package thyyxxk.webserver.service.zhuyuanyisheng;
  2. import com.alibaba.fastjson.JSON;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.springframework.stereotype.Service;
  8. import thyyxxk.webserver.config.exception.ExceptionEnum;
  9. import thyyxxk.webserver.constants.GetDateFormat;
  10. import thyyxxk.webserver.dao.his.zhuyuanyisheng.CaoYaoYiZhuDao;
  11. import thyyxxk.webserver.dao.his.zhuyuanyisheng.YiZhuLuRuDao;
  12. import thyyxxk.webserver.entity.ResultVo;
  13. import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
  14. import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.CaoYaoChaXunTiaoJian;
  15. import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.YzActOrderCy;
  16. import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.YzActOrderCyDetail;
  17. import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.YzOrderPatternCy;
  18. import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.XinZhenYiZhu;
  19. import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.YiZhuMingChen;
  20. import thyyxxk.webserver.service.PublicServer;
  21. import thyyxxk.webserver.utils.*;
  22. import java.math.BigDecimal;
  23. import java.util.ArrayList;
  24. import java.util.List;
  25. /**
  26. * <p>
  27. * 描述:
  28. * </p>
  29. *
  30. * @author xc
  31. * @date 2022-02-26 08:39
  32. */
  33. @Service
  34. @Slf4j
  35. public class CaoYaoYiZhuServer {
  36. private final CaoYaoYiZhuDao dao;
  37. private final PublicServer publicServer;
  38. private final YiZhuLuRuDao yiZhuLuRuDao;
  39. public CaoYaoYiZhuServer(CaoYaoYiZhuDao dao, PublicServer publicServer, YiZhuLuRuDao yiZhuLuRuDao) {
  40. this.dao = dao;
  41. this.publicServer = publicServer;
  42. this.yiZhuLuRuDao = yiZhuLuRuDao;
  43. }
  44. public ResultVo<IPage<YzActOrderCy>> huoQuCaoYaoShuJu(CaoYaoChaXunTiaoJian param) {
  45. IPage<YzActOrderCy> page = new Page<>(param.getCurrentPage(), param.getPageSize(), param.getTotal() == 0);
  46. QueryWrapper<?> qw = new QueryWrapper<>();
  47. qw.eq("inpatient_no", param.getPatNo());
  48. qw.eq("admiss_times", param.getTimes());
  49. if (param.getShiFouFaYao()) {
  50. qw.eq("status_flag", "4");
  51. } else {
  52. qw.le("status_flag", "3");
  53. }
  54. if (StringUtil.notBlank(param.getStartTime())) {
  55. qw.ge("input_date", param.getStartTime());
  56. qw.le("input_date", param.getEndTime());
  57. }
  58. dao.huoQuCaoYaoShuJu(page, qw);
  59. for (YzActOrderCy item : page.getRecords()) {
  60. item.setDaiJianFei(item.getQuantityDj().multiply(item.getOrderJeDj()));
  61. item.setJiaGe(item.getQuantity().multiply(item.getOrderJe()));
  62. item.setZongJia(item.getDaiJianFei().add(item.getJiaGe()));
  63. }
  64. return ResultVoUtil.success(page);
  65. }
  66. public ResultVo<List<YzActOrderCyDetail>> huoQuChaoYaoMingXi(BigDecimal orderNo) {
  67. return ResultVoUtil.success(dao.huoQuChaoYaoMingXi(orderNo));
  68. }
  69. public ResultVo<List<GetDropdownBox>> fuYongFangFa() {
  70. return ResultVoUtil.success(dao.fuYongFangFa());
  71. }
  72. public ResultVo<IPage<YiZhuMingChen>> huoQuCaoYao(String queryName, Integer groupNo, long currentPage, long pageSize, long total) {
  73. IPage<YiZhuMingChen> page = new Page<>(currentPage, pageSize, total == 0);
  74. String name = StringUtil.englishToCapital(queryName);
  75. QueryWrapper<?> qw = new QueryWrapper<>();
  76. qw.and(QueryWrapper -> QueryWrapper
  77. .like("py_code", name)
  78. .or()
  79. .like("name", name)
  80. .or()
  81. .like("d_code", name)
  82. .or()
  83. .like("code", name)
  84. )
  85. .eq("group_no", groupNo);
  86. dao.huoQuCaoYao(page, qw);
  87. return ResultVoUtil.success(page);
  88. }
  89. public ResultVo<IPage<YzOrderPatternCy>> huoQuMuBan(String queryName, String deptCode, long currentPage, long pageSize, long total) {
  90. IPage<YzOrderPatternCy> page = new Page<>(currentPage, pageSize, total == 0);
  91. String name = StringUtil.englishToCapital(queryName);
  92. QueryWrapper<?> qw = new QueryWrapper<>();
  93. qw.and(QueryWrapper -> QueryWrapper
  94. .like("py_code", name)
  95. .or()
  96. .like("d_code", name)
  97. .or()
  98. .like("pattern_name", name)
  99. );
  100. if (publicServer.noNeedRule(1, 38)) {
  101. qw.eq("dept_code", deptCode);
  102. }
  103. qw.groupBy("pattern_name");
  104. dao.huoQuMuBan(page, qw);
  105. return ResultVoUtil.success(page);
  106. }
  107. public ResultVo<List<YzOrderPatternCy>> muBanXiangQing(String name, String deptCode) {
  108. return ResultVoUtil.success(dao.muBanXiangQing(name, deptCode));
  109. }
  110. public ResultVo<Boolean> chongFuMuBanMing(String name) {
  111. return ResultVoUtil.success(dao.chongFuMuBanMing(name) > 1);
  112. }
  113. public ResultVo<String> cunMuBan(YzOrderPatternCy param) {
  114. log.info("插入模板草药模板:{}", JSON.toJSONString(param));
  115. dao.chaRuMuBan(param.getList(), param.getPatternName(), TokenUtil.getTokenUserId(),
  116. PingYinUtils.pyShouZiMuDaXie(param.getPatternName()), PingYinUtils.getWBCode(param.getPatternName()),
  117. param.getDeptCode());
  118. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  119. }
  120. public ResultVo<String> baoCunCaoYao(YzActOrderCy param) {
  121. log.info("上传的数据:{}", JSON.toJSONString(param));
  122. if (ListUtil.isBlank(param.getList())) {
  123. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请先选择需要上传的数据。");
  124. }
  125. publicServer.huanZheJieSuan(param.getInpatientNo(), param.getAdmissTimes());
  126. BigDecimal sum = new BigDecimal(0);
  127. for (YzActOrderCyDetail item : param.getList()) {
  128. sum = sum.add(item.getQuantity().multiply(item.getRetprice()));
  129. }
  130. param.setOrderJe(sum);
  131. param.setInputId(TokenUtil.getTokenUserId());
  132. param.setOrderJeDj(dao.huoQuDaiJianFei());
  133. param.setPageNo(publicServer.getTheDrugListNo());
  134. XinZhenYiZhu huanZheXinXi = yiZhuLuRuDao.huoQuHuanZheXinXi(param.getInpatientNo(), param.getAdmissTimes());
  135. param.setOrderNo(BigDecimal.valueOf(publicServer.getActOrderNo()));
  136. dao.chaRuCaoYaoYiZhu(param, huanZheXinXi.getDeptCode(), huanZheXinXi.getDeptCode(), huanZheXinXi.getSmallDept());
  137. dao.chaRuCaoYaoXiangQing(param.getList(), param.getOrderNo());
  138. dao.chaRuYiZhu(param, "草药医嘱:" + param.getOrderName() + param.getQuantity() + "剂", huanZheXinXi.getDeptCode(), huanZheXinXi.getDeptCode(), huanZheXinXi.getSmallDept(), publicServer.getInfantFlag(huanZheXinXi.getInpatientNo()));
  139. List<String> content = new ArrayList<>();
  140. content.add(String.format("草药医嘱名:<span style='color:#409eff'>【%s】</span><br>" +
  141. "剂数:<span style='color:#409eff'>【%s】</span><br>" +
  142. "患者名:<span style='color:#409eff'>【%s】<br></span>" +
  143. "床位:<span style='color:#409eff'>【%s】</span>", param.getOrderName(), param.getQuantity().toString(), huanZheXinXi.getName(), huanZheXinXi.getBedNo()));
  144. publicServer.faSongXiaoXi(huanZheXinXi, content, "新增草药医嘱", TokenUtil.getTokenUserId());
  145. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  146. }
  147. /**
  148. * 删除草药模板
  149. * 管理员和有医嘱模板编辑,权限的可以直接删除
  150. * 科室主任有权限删除本科室的模板
  151. *
  152. * @param name 模板名称
  153. * @param deptCode 科室编码
  154. * @return 返回提示
  155. */
  156. public ResultVo<String> shanChuMuBan(String name, String deptCode) {
  157. YzOrderPatternCy mb = dao.caoYaoMuBanXiangQing(name);
  158. List<Integer> rolse = publicServer.getRoleCode().getData();
  159. // 如果有这个权限直接删除
  160. if (publicServer.noNeedRule(rolse, YiZhuPublic.MU_BAN_BIAN_JI_QUAN_XIAN)) {
  161. // 本人创建的也可以直接删除
  162. if (mb.getCreateId().equals(TokenUtil.getTokenUserId())) {
  163. return shanChuCaoYaoMuBan(name);
  164. }
  165. // 科主任 可以删除自己科室的模板
  166. if (publicServer.needRule(rolse, YiZhuPublic.KE_ZHU_REN_BIAN_MA)) {
  167. if (mb.getDeptCode().trim().equals(deptCode)) {
  168. return shanChuCaoYaoMuBan(name);
  169. }
  170. }
  171. } else {
  172. return shanChuCaoYaoMuBan(name);
  173. }
  174. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有权限删除。");
  175. }
  176. private ResultVo<String> shanChuCaoYaoMuBan(String name) {
  177. dao.shanChuMuBan(name);
  178. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  179. }
  180. public ResultVo<String> shanChuCaoYao(String patNo, Integer times, BigDecimal orderNo) {
  181. YzActOrderCy cy = dao.caoYaoXinXi(patNo, times, orderNo);
  182. if (cy == null) {
  183. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有查询到原来的信息。");
  184. }
  185. if (!cy.getStatusFlag().trim().equals("1")) {
  186. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该草药无法删除。");
  187. }
  188. log.info("删除草药==》操作人:{},数据:{}", TokenUtil.getTokenUserId(), JSON.toJSONStringWithDateFormat(cy, GetDateFormat.DATE_TIME));
  189. dao.genXingCaoYaoShanChuBiaoZhi(patNo, times, orderNo);
  190. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  191. }
  192. }