ShouShuShenQingService.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. package thyyxxk.webserver.service.zhuyuanyisheng;
  2. import cn.hutool.extra.spring.SpringUtil;
  3. import com.alibaba.fastjson.JSON;
  4. import com.baomidou.dynamic.datasource.annotation.DS;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.baomidou.mybatisplus.core.metadata.IPage;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.stereotype.Service;
  10. import org.springframework.transaction.annotation.Transactional;
  11. import thyyxxk.webserver.config.exception.ExceptionEnum;
  12. import thyyxxk.webserver.constants.GetDateFormat;
  13. import thyyxxk.webserver.dao.his.zhuyuanyisheng.ShouShuShenQingDao;
  14. import thyyxxk.webserver.dao.his.zhuyuanyisheng.YiZhuLuRuDao;
  15. import thyyxxk.webserver.entity.ResultVo;
  16. import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
  17. import thyyxxk.webserver.entity.dictionary.CodeName;
  18. import thyyxxk.webserver.entity.zhuyuanyisheng.query.ChaXunJianChaHeJianYan;
  19. import thyyxxk.webserver.entity.zhuyuanyisheng.shoushu.OpRecord;
  20. import thyyxxk.webserver.entity.zhuyuanyisheng.shoushu.ShouShuFanHui;
  21. import thyyxxk.webserver.entity.zhuyuanyisheng.shoushu.XinZengShouShu;
  22. import thyyxxk.webserver.entity.zhuyuanyisheng.shoushu.ZdIcd9Cm3;
  23. import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.XinZhenYiZhu;
  24. import thyyxxk.webserver.service.PublicServer;
  25. import thyyxxk.webserver.utils.*;
  26. import java.util.*;
  27. /**
  28. * <p>
  29. * 描述: 手术申请
  30. * </p>
  31. *
  32. * @author xc
  33. * @date 2022-02-22 15:45
  34. */
  35. @Service
  36. @Slf4j
  37. public class ShouShuShenQingService {
  38. private final ShouShuShenQingDao dao;
  39. private final PublicServer publicServer;
  40. private final YiZhuLuRuDao yiZhuLuRuDao;
  41. private ShouShuShenQingService getThis() {
  42. return SpringUtil.getBean(this.getClass());
  43. }
  44. public ShouShuShenQingService(ShouShuShenQingDao dao, PublicServer publicServer, YiZhuLuRuDao yiZhuLuRuDao) {
  45. this.dao = dao;
  46. this.publicServer = publicServer;
  47. this.yiZhuLuRuDao = yiZhuLuRuDao;
  48. }
  49. /**
  50. * 获取手术的项目 在
  51. *
  52. * @param name 搜索名称
  53. * @param type 搜索类型
  54. * @return
  55. */
  56. @DS("his")
  57. public ResultVo<List<ZdIcd9Cm3>> obtainSurgicalItems(String name, Integer type) {
  58. return ResultVoUtil.success(dao.obtainSurgicalItems(StringUtil.isContainChinese(name), type));
  59. }
  60. @DS("his")
  61. public ResultVo<List<CodeName>> getDoctorByOpCode(String opCode) {
  62. return ResultVoUtil.success(dao.getDoctorByOpCode(opCode));
  63. }
  64. @DS("his")
  65. public ResultVo<Boolean> preoperativeDiscussion(String patNo, Integer times, Integer count) {
  66. int currentPatientOpCount = dao.currentPatientOpCount(patNo, times);
  67. currentPatientOpCount += count;
  68. int currentEmrPreoperativelyDiscussCount = dao.currentEmrPreoperativelyDiscussCount(patNo, times);
  69. if (currentPatientOpCount > currentEmrPreoperativelyDiscussCount) {
  70. return ResultVoUtil.success(true);
  71. }
  72. return ResultVoUtil.success(false);
  73. }
  74. public ResultVo<List<GetDropdownBox>> shouShuShenQingCeBianLan() {
  75. return ResultVoUtil.success(dao.shouShuShenQingCeBianLan());
  76. }
  77. public ResultVo<List<Map<String, String>>> huoQuShouShuMingCheng(String patNo, Integer times, String name) {
  78. return ResultVoUtil.success(dao.huoQuShouShuMing(patNo, times, StringUtil.isContainChinese(name)));
  79. }
  80. public ResultVo<IPage<OpRecord>> huoQuShouShu(ChaXunJianChaHeJianYan param) {
  81. IPage<OpRecord> page = new Page<>(param.getCurrentPage(), param.getPageSize(), param.getTotal() == 0);
  82. QueryWrapper<OpRecord> qw = new QueryWrapper<>();
  83. qw.select("op_name, op_datetime, status,record_id");
  84. qw.eq("inpatient_no", param.getPatNo());
  85. qw.eq("admiss_times", param.getTimes());
  86. if (StringUtil.notBlank(param.getStartTime())) {
  87. qw.ge("req_date", param.getStartTime());
  88. qw.le("req_date", param.getEndTime());
  89. }
  90. if (StringUtil.notBlank(param.getOrderName())) {
  91. qw.eq("op_name", param.getOrderName());
  92. }
  93. qw.ne("status", "d");
  94. dao.selectPage(page, qw);
  95. return ResultVoUtil.success(page);
  96. }
  97. public ResultVo<OpRecord> huoQuShouShuShenQingDaYing(String patNo, Integer times, Integer recordId) {
  98. OpRecord op = dao.daYingShouShu(patNo, times, recordId);
  99. if (op == null) {
  100. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该手术可能已经被删除了。");
  101. }
  102. try {
  103. EntityCopy.Copy(dao.daYingHuanZheXinXi(patNo, times), op);
  104. } catch (Exception e) {
  105. e.printStackTrace();
  106. }
  107. op.setAge(Objects.requireNonNull(DateUtil.calculateAge(DateUtil.parse(op.getBirthDate(), GetDateFormat.DATE), null)).toString());
  108. return ResultVoUtil.success(op);
  109. }
  110. public ResultVo<IPage<ShouShuFanHui>> fenLeiXiangQing(String code, String name, long total, long currentPage, long pageSize) {
  111. IPage<ShouShuFanHui> page = new Page<>(currentPage, pageSize, total == 0);
  112. page = dao.fenLeiXiangQing(page, code, StringUtil.isContainChinese(name));
  113. return ResultVoUtil.success(page);
  114. }
  115. /**
  116. * 远程搜索手术部位
  117. *
  118. * @param name 名字
  119. * @return 返回
  120. */
  121. @DS("his")
  122. public ResultVo<List<GetDropdownBox>> huoQuShouShuBuWei(String name) {
  123. if (StringUtil.isBlank(name)) {
  124. return ResultVoUtil.success(dao.huoQuShouShuBuWei(name));
  125. }
  126. return ResultVoUtil.success(dao.huoQuShouShuBuWei(StringUtil.isContainChinese(name)));
  127. }
  128. public ResultVo<Map<String, String>> xinZengShouShuShenQing(XinZengShouShu param) {
  129. if (ListUtil.isBlank(param.getList())) {
  130. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请先选择需要上传的数据。");
  131. }
  132. Map<String, String> map = new HashMap<>(param.getList().size());
  133. for (int i = 0; i < param.getList().size(); i++) {
  134. OpRecord item = param.getList().get(i);
  135. String error = applyForVerification(item);
  136. if (StringUtil.notBlank(error)) {
  137. if (StringUtil.isBlank(item.getOpName())) {
  138. item.setOpName("添加手术" + i);
  139. }
  140. map.put(item.getOpName(), error);
  141. }
  142. }
  143. if (!map.isEmpty()) {
  144. return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请修改有错误的手术申请", map);
  145. }
  146. publicServer.huanZheJieSuan(param.getInpatientNo(), param.getAdmissTimes());
  147. String userCode = TokenUtil.getTokenUserId();
  148. Integer shenQingCiShu = dao.shouShuShenQingCiShu(param.getInpatientNo(), param.getAdmissTimes());
  149. List<OpRecord> shenChengYiZhu = new ArrayList<>();
  150. List<String> content = new ArrayList<>();
  151. for (OpRecord item : param.getList()) {
  152. item.setRecordId(publicServer.huoQuShouShuHao());
  153. item.setActOrderNo(publicServer.getActOrderNo());
  154. item.setOpTimes(shenQingCiShu += 1);
  155. // 生成医嘱
  156. shenChengYiZhu.add(item);
  157. content.add(String.format("手术名称:<span style='color:#409eff'>【%s】</span><br>" +
  158. "手术时间:<span style='color:#409eff'>【%tF %<tT】</span><br>", item.getOpName(), item.getOpDatetime()));
  159. }
  160. log.info("上传数据:{}", JSON.toJSONString(param));
  161. XinZhenYiZhu huanZheXinXi = yiZhuLuRuDao.queryPatientInfo(param.getInpatientNo(), param.getAdmissTimes());
  162. // 生成手术
  163. getThis().generativeSurgery(param, userCode, shenChengYiZhu, huanZheXinXi);
  164. publicServer.faSongXiaoXi(huanZheXinXi, content, "新增手术", TokenUtil.getTokenUserId());
  165. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  166. }
  167. @Transactional(rollbackFor = Exception.class)
  168. public void generativeSurgery(XinZengShouShu param, String userCode, List<OpRecord> shenChengYiZhu, XinZhenYiZhu huanZheXinXi) {
  169. dao.chaRuShouShuYiSheng(param.getList());
  170. dao.chaRuShouShu(param.getList(), param.getInpatientNo(), param.getName(), param.getAdmissTimes(),
  171. huanZheXinXi.getDeptCode(), huanZheXinXi.getDeptCode(), userCode, param.getBedNo(), param.getAdmissWard());
  172. String yzCode = param.getGenerateRejectedOrders() ? "10399" : "06054";
  173. // 插入医嘱
  174. dao.chaRuYiZhu(shenChengYiZhu, huanZheXinXi, userCode, param.getExecDept(), yzCode);
  175. }
  176. public String applyForVerification(OpRecord param) {
  177. StringBuilder sb = new StringBuilder();
  178. if (StringUtil.isBlank(param.getOpCode())) {
  179. sb.append("手术编码不能为空。");
  180. }
  181. if (param.getOpDatetime() == null) {
  182. sb.append("手术时间不能为空。");
  183. } else if (DateUtil.shiJianDaXiao(param.getOpDatetime(), param.getApplyDate(), "<")) {
  184. sb.append("手术时间不能小于申请时间。");
  185. }
  186. if (StringUtil.isBlank(param.getDiagBeforeCode())) {
  187. sb.append("术前诊断不能为空。");
  188. }
  189. if (StringUtil.isBlank(param.getPartCode())) {
  190. sb.append("手术部位不能为空。");
  191. }
  192. if (StringUtil.isBlank(param.getDoctorZd())) {
  193. sb.append("主刀医生不能为空。");
  194. }
  195. if (StringUtil.isBlank(param.getOpScale())) {
  196. sb.append("手术等级不能为空。");
  197. }
  198. if (StringUtil.isBlank(param.getOrderName())) {
  199. sb.append("生成的医嘱名不能为空。");
  200. }
  201. return sb.toString();
  202. }
  203. public ResultVo<String> shanChuShouShu(Integer recordId) {
  204. OpRecord op = dao.shouShuXinXi(recordId);
  205. if (op == null) {
  206. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到该手术的信息。");
  207. }
  208. if (!"1".equals(op.getStatus().trim())) {
  209. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "无法删除该手术。");
  210. }
  211. dao.genXingShanChuBiaoZhi(recordId);
  212. log.info("删除手术==》操作人:{},申请单号:{}", TokenUtil.getTokenUserId(), recordId);
  213. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  214. }
  215. public ResultVo<String> addASurgicalSite(String name) {
  216. if (dao.repeatPartName(name)) {
  217. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "手术部位名称重复");
  218. }
  219. String maxCode = String.valueOf(dao.getTheMaximumSurgicalCode() + 1);
  220. String newCode = maxCode.length() > 1 ? maxCode : '0' + maxCode;
  221. dao.insertNewSurgicalSite(newCode, name, PingYinUtils.pyShouZiMuDaXie(name), PingYinUtils.getWBCode(name));
  222. log.info("新增手术部位==>操作人:{}", TokenUtil.getTokenUserId());
  223. return ResultVoUtil.success(newCode);
  224. }
  225. public ResultVo<String> removeSurgicalSite(String code) {
  226. dao.removeSurgicalSite(code);
  227. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  228. }
  229. }