JianYanJianChaShenQingService.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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.core.metadata.OrderItem;
  8. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.springframework.stereotype.Service;
  11. import org.springframework.transaction.annotation.Transactional;
  12. import thyyxxk.webserver.config.exception.BizException;
  13. import thyyxxk.webserver.config.exception.ExceptionEnum;
  14. import thyyxxk.webserver.constants.Capacity;
  15. import thyyxxk.webserver.dao.his.zhuyuanyisheng.JianYanJianChaDao;
  16. import thyyxxk.webserver.dao.his.zhuyuanyisheng.YiZhuLuRuDao;
  17. import thyyxxk.webserver.entity.ResultVo;
  18. import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
  19. import thyyxxk.webserver.entity.login.UserInfo;
  20. import thyyxxk.webserver.entity.zhuyuanyisheng.jianyanjiancha.*;
  21. import thyyxxk.webserver.entity.zhuyuanyisheng.query.ChaXunJianChaHeJianYan;
  22. import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.PatientTemp;
  23. import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.XinZhenYiZhu;
  24. import thyyxxk.webserver.service.PublicServer;
  25. import thyyxxk.webserver.service.redislike.RedisLikeService;
  26. import thyyxxk.webserver.utils.*;
  27. import java.lang.reflect.Field;
  28. import java.nio.channels.NonWritableChannelException;
  29. import java.util.*;
  30. import java.util.stream.Collectors;
  31. /**
  32. * <p>
  33. * 描述: 住院医生,检查申请
  34. * </p>
  35. *
  36. * @author xc
  37. * @date 2022-02-10 15:37
  38. */
  39. @Service
  40. @Slf4j
  41. public class JianYanJianChaShenQingService {
  42. private final JianYanJianChaDao dao;
  43. private final PublicServer publicServer;
  44. private final YiZhuLuRuDao yiZhuLuRuDao;
  45. private final RedisLikeService realtimeService;
  46. private JianYanJianChaShenQingService getThis() {
  47. return SpringUtil.getBean(this.getClass());
  48. }
  49. public JianYanJianChaShenQingService(JianYanJianChaDao dao, PublicServer publicServer, YiZhuLuRuDao yiZhuLuRuDao, RedisLikeService realtimeService) {
  50. this.dao = dao;
  51. this.publicServer = publicServer;
  52. this.yiZhuLuRuDao = yiZhuLuRuDao;
  53. this.realtimeService = realtimeService;
  54. }
  55. /*-------------------------------------------------------------- 下面是检查的逻辑 -----------------------------------------------------------------------------------------------------*/
  56. /**
  57. * 获取检验检查的名字
  58. *
  59. * @param name 姓名
  60. * @param patNo 住院号
  61. * @param times 住院次数
  62. * @param bedNo 床位
  63. * @param reqType 2-检验 3-检查
  64. * @return 返回数据
  65. */
  66. public ResultVo<List<Map<String, String>>> huoQuJianYanJianChaMing(String name, String patNo, Integer times, String bedNo, String reqType) {
  67. return ResultVoUtil.success(dao.huoQuJianJianChaMing(patNo, times, bedNo, StringUtil.isContainChinese(name), reqType));
  68. }
  69. /**
  70. * 获取检查申请
  71. *
  72. * @param param 检查申请
  73. * @return 返回数据
  74. */
  75. public ResultVo<List<YshYjReq>> huoQuJianChaShenQing(ChaXunJianChaHeJianYan param) {
  76. QueryWrapper<?> qw = new QueryWrapper<>();
  77. qw.eq("inpatient_no", param.getPatNo());
  78. qw.eq("admiss_times", param.getTimes());
  79. qw.eq("req_type", "3");
  80. if (StringUtil.notBlank(param.getOrderName())) {
  81. qw.like("order_name", param.getOrderName());
  82. }
  83. if (StringUtil.notBlank(param.getStartTime())) {
  84. qw.ge("start_time", param.getStartTime())
  85. .le("start_time", param.getEndTime());
  86. }
  87. qw.orderByDesc("req_date");
  88. List<YshYjReq> list = dao.huoQuJianChaShenQingV2(qw);
  89. return ResultVoUtil.success(list);
  90. }
  91. public ResultVo<Map<String, Object>> huoQuShengQingXiangQing(Integer reqNo) {
  92. YshYjReq req = dao.huoQuShengQingXiangQing(reqNo);
  93. if (req == null) {
  94. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_HTML_ERROR, "没有查询到有效信息,可能已经被删除了。");
  95. }
  96. Map<String, Object> map = new HashMap<>();
  97. StringBuilder zhuYiShiXiang = new StringBuilder();
  98. JcZdClass jc = dao.daYingXiangQing(req.getOrderType());
  99. if (req.getReqType().trim().equals("2") && req.getClasses() != null && req.getClasses().equals("038")) {
  100. jc = new JcZdClass();
  101. jc.setComm("病理检验申请单");
  102. } else if (req.getReqType().trim().equals("2")) {
  103. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "非病理无序打印");
  104. }
  105. // 获取患者的住址和性别
  106. PatientTemp patient = dao.huoQuHuanZheXinXi(req.getInpatientNo());
  107. req.setSex(patient.getSex());
  108. // 地址
  109. req.setHomeStreet(patient.getHomeStreet());
  110. //联系电话
  111. req.setHomeTel(patient.getHomeTel());
  112. // 医保身份
  113. req.setResponceTypeName(dao.huoQuHuanZheShenFen(req.getInpatientNo()));
  114. map.put("title", jc.getComm());
  115. Field[] fields = jc.getClass().getDeclaredFields();
  116. for (Field field : fields) {
  117. field.setAccessible(true);
  118. // 输出属性名和属性值
  119. try {
  120. String key = field.getName();
  121. Object value = EntityStringTrim.getFieldValue(jc, key);
  122. if (key.startsWith("comment") && StringUtil.notBlank((String) value)) {
  123. zhuYiShiXiang.append(((String) value).trim()).append("\n");
  124. }
  125. } catch (Exception e) {
  126. e.printStackTrace();
  127. }
  128. }
  129. map.put("mattersNeedingAttention", zhuYiShiXiang.toString());
  130. map.put("data", req);
  131. return ResultVoUtil.success(map);
  132. }
  133. /**
  134. * 获取检查
  135. *
  136. * @return
  137. */
  138. public ResultVo<List<JcZdClass>> getCheckNewApplication() {
  139. return ResultVoUtil.success(dao.getCheckNewApplication());
  140. }
  141. /**
  142. * @param itemType 3-检查 2-检验
  143. * @param templateType 2 个人 3 科室模板
  144. * @return
  145. */
  146. public ResultVo<List<JcZdClass>> getTemplate(Integer itemType, Integer templateType) {
  147. QueryWrapper<?> qw = new QueryWrapper<>();
  148. qw.eq("c.req_type", itemType);
  149. if (templateType == 2) {
  150. qw.eq("c.op_id", TokenUtil.getTokenUserId());
  151. } else {
  152. UserInfo info = realtimeService.getUserInfoByToken();
  153. qw.eq("c.tc_exec", info.getDeptCode());
  154. }
  155. List<JcZdClass> parentNode = dao.getTemplate(qw);
  156. Map<String, JcZdClass> map = parentNode
  157. .stream()
  158. .collect(Collectors.toMap(JcZdClass::getCode, a -> a, (k1, k2) -> k1));
  159. List<Map<String, String>> tempContent = dao.selectTemplateContent(qw);
  160. tempContent.forEach(item -> {
  161. JcZdClass jcZdClass = map.get(item.get("tc_no"));
  162. if (jcZdClass != null) {
  163. if (jcZdClass.getList() == null) {
  164. jcZdClass.setList(new ArrayList<>());
  165. }
  166. jcZdClass.getList().add(item);
  167. }
  168. });
  169. return ResultVoUtil.success(parentNode);
  170. }
  171. /**
  172. * 查询检查检验分类
  173. *
  174. * @param total 总条数
  175. * @param currentPage 当前页
  176. * @param leiXing 类型 1-新申请 2-个人 3-科室
  177. * @param jianCha true 检查 false 检验
  178. * @return 返回分页数据
  179. */
  180. @Deprecated
  181. public ResultVo<IPage<JcZdClass>> jianChaJianYanFenLei(long total, long currentPage, Integer leiXing, Boolean jianCha) {
  182. IPage<JcZdClass> page = new Page<>();
  183. if (leiXing == 1) {
  184. if (jianCha) {
  185. if (total == 0) {
  186. page.setTotal(dao.jianChaMingTiaoShu());
  187. }
  188. page.setRecords(dao.jianChaMing(currentPage));
  189. } else {
  190. page = new Page<>(currentPage, 20, total == 0);
  191. page = dao.jianYanFenLei(page);
  192. return ResultVoUtil.success(page);
  193. }
  194. } else {
  195. page = new Page<>(currentPage, 20, total == 0);
  196. page = dao.jianChaJianYanMuBan(page, leiXing, TokenUtil.getTokenUserId(), jianCha ? "3" : "2");
  197. }
  198. return ResultVoUtil.success(page);
  199. }
  200. /**
  201. * 删除检查或检验模板
  202. *
  203. * @param code 要删除的模板 code
  204. * @param deptCode 当前患者的科室编码
  205. * @return 返回提示
  206. */
  207. public ResultVo<String> shanShuJianChaMuBan(String code, String deptCode) {
  208. ZyTcYj yj = dao.jianChaLuRuRen(code);
  209. if (yj == null) {
  210. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找对应的记录可能已经被删除了。");
  211. }
  212. if (jianChaMuBanPanDuan(yj.getOpId(), yj.getTcExec(), deptCode)) {
  213. dao.shanChuJianChaMuBan(code);
  214. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  215. }
  216. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有权限执行这个操作。");
  217. }
  218. /**
  219. * 检查模板的判断
  220. *
  221. * @param opId 录入人
  222. * @param tcExec 模板的科室
  223. * @param deptCode 当前用户的科室
  224. * @return boolean
  225. */
  226. public boolean jianChaMuBanPanDuan(String opId, String tcExec, String deptCode) {
  227. List<Integer> userRole = publicServer.getRoleCode().getData();
  228. // 医务部
  229. if (userRole.contains(38)) {
  230. return true;
  231. }
  232. // 科主任 可以删除自己科室任意模板
  233. if (userRole.contains(11) && tcExec.trim().equals(deptCode)) {
  234. return true;
  235. }
  236. // 普通的只能删除自己的
  237. return opId.trim().equals(TokenUtil.getTokenUserId());
  238. }
  239. /**
  240. * 获取说明,模板的一下信息
  241. *
  242. * @param name 根据说明模板来 搜索
  243. * @param fenLei 分类
  244. * @param total 总数
  245. * @param currentPage 当前页
  246. * @return 返回提示
  247. */
  248. public ResultVo<IPage<YshZdYjTemplate>> huoMuShuoMingMuBan(String name, Integer fenLei, long total, long currentPage) {
  249. Page<YshZdYjTemplate> page = new Page<>(currentPage, 20, total == 0);
  250. page = dao.huoQuShuoMingMuBan(page, StringUtil.isContainChinese(name), fenLei, TokenUtil.getTokenUserId());
  251. return ResultVoUtil.success(page);
  252. }
  253. /**
  254. * 对于说明模板的操作
  255. *
  256. * @param param 说明模板的内容
  257. * @return 返回提示
  258. */
  259. @Transactional(rollbackFor = Exception.class)
  260. public ResultVo<String> shouMingMuBanChaoZuo(YshZdYjTemplate param) {
  261. switch (param.getLeiXing()) {
  262. case "修改":
  263. return xiuGaiMuBan(param, dao.muBanShuJu(param.getCode()));
  264. case "删除":
  265. return shanChuMuBan(dao.muBanShuJu(param.getCode()));
  266. case "新增":
  267. return xinZengShouMingMuBan(param);
  268. default:
  269. return ResultVoUtil.success();
  270. }
  271. }
  272. /**
  273. * 修改说明模板
  274. *
  275. * @param param 修改的数据
  276. * @param mb 原来的数据
  277. * @return 返回提示
  278. */
  279. private ResultVo<String> xiuGaiMuBan(YshZdYjTemplate param, YshZdYjTemplate mb) {
  280. if (publicServer.noNeedRule(38)) {
  281. if (!TokenUtil.getTokenUserId().equals(mb.getOpId().trim())) {
  282. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该模板创建人不是你,无法操作。");
  283. }
  284. }
  285. dao.genXingShouMingMuBan(param.getJcText(), param.getName(),
  286. PingYinUtils.pyShouZiMuDaXie(param.getName()),
  287. PingYinUtils.getWBCode(param.getName()), param.getCode());
  288. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  289. }
  290. /**
  291. * 删除说明模板
  292. *
  293. * @param mb 通过数据库查找 原来的模板
  294. * @return 返回提示
  295. */
  296. private ResultVo<String> shanChuMuBan(YshZdYjTemplate mb) {
  297. List<Integer> userRole = publicServer.getRoleCode().getData();
  298. if (publicServer.noNeedRule(userRole, 38)) {
  299. if (TokenUtil.getTokenUserId().equals(mb.getOpId().trim()) || (userRole.contains(11) && mb.getDeptCode().trim().equals(mb.getUserDeptCode().trim()))) {
  300. dao.shanChuShouMingMuBan(mb.getCode());
  301. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  302. } else {
  303. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有权限修改。");
  304. }
  305. }
  306. dao.shanChuShouMingMuBan(mb.getCode());
  307. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  308. }
  309. /**
  310. * 新增说明模板
  311. *
  312. * @param param 新增的数据
  313. * @return 返回提示
  314. */
  315. private ResultVo<String> xinZengShouMingMuBan(YshZdYjTemplate param) {
  316. if (param.getWhFlag().trim().equals("3") && publicServer.noNeedRule(38)) {
  317. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有权限创建全院模板。");
  318. }
  319. param.setCode(publicServer.getYjTemplateNo().toString());
  320. param.setPyCode(PingYinUtils.pyShouZiMuDaXie(param.getName(), 8));
  321. param.setDCode(PingYinUtils.getWBCode(param.getName(), 8));
  322. param.setOpId(TokenUtil.getTokenUserId());
  323. dao.xinZengShouMingMuBan(param);
  324. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  325. }
  326. /**
  327. * 搜索临床诊断
  328. *
  329. * @param name 搜索的名字
  330. * @return 返回搜索的数据
  331. */
  332. @DS("his")
  333. public ResultVo<List<GetDropdownBox>> diagnosisInOurHospital(String name) {
  334. return ResultVoUtil.success(dao.diagnosisInOurHospital(StringUtil.isContainChinese(name)));
  335. }
  336. /**
  337. * 判断检查模板是否有重复的
  338. *
  339. * @param name 名称
  340. * @return 返回有没有
  341. */
  342. public ResultVo<Boolean> jianChaJianYanMuBanMing(String name, String reqType) {
  343. return ResultVoUtil.success(dao.huoQuJianChaJianYanChongFuMuBanMing(name, TokenUtil.getTokenUserId(), reqType).size() > 0);
  344. }
  345. /**
  346. * 保存检查或检验模板
  347. *
  348. * @param param 数据
  349. * @return 返回提示
  350. */
  351. @Transactional(rollbackFor = Exception.class)
  352. public ResultVo<String> baoCunJianChaJianYanMuBan(ZyTcYj param) {
  353. param.setOpId(TokenUtil.getTokenUserId());
  354. param.setTcNo(publicServer.huoQuJianYanJianChaXuHao().toString());
  355. param.setPyCode(PingYinUtils.pyShouZiMuDaXie(param.getTcName(), 8));
  356. param.setDCode(PingYinUtils.getWBCode(param.getTcName(), 8));
  357. List<String> yuanShuJu = dao.huoQuJianChaJianYanChongFuMuBanMing(param.getTcName(), param.getOpId(), param.getReqType());
  358. if (ListUtil.notBlank(yuanShuJu)) {
  359. for (String s : yuanShuJu) {
  360. dao.shanChuJianChaMuBan(s);
  361. }
  362. }
  363. dao.chaRuJCJYMuBan(param);
  364. dao.chaRuJCJYMuBanNeiRong(param.getList(), param.getTcNo(), param.getReqType().trim());
  365. log.info("模板数据:{}", JSON.toJSONString(param.getList()));
  366. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  367. }
  368. public ResultVo<String> baoCunJianYanJianCha(TianJiaJianChaJianYan param) {
  369. if (ListUtil.isBlank(param.getList())) {
  370. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请选择需要保存的数据。");
  371. }
  372. XinZhenYiZhu huanZheXinXi = yiZhuLuRuDao.queryPatientInfo(param.getInpatientNo(), param.getAdmissTimes());
  373. publicServer.huanZheJieSuan(param.getInpatientNo(), param.getAdmissTimes());
  374. List<String> xm = new ArrayList<>();
  375. int index = 1;
  376. List<String> content = new ArrayList<>();
  377. StringBuilder cuoWuXinXi = new StringBuilder();
  378. for (YshYjReq item : param.getList()) {
  379. if (StringUtil.notBlank(item.getJzFlag()) && "0".equals(item.getJzFlag())) {
  380. item.setJzFlag(null);
  381. }
  382. if (StringUtil.notBlank(item.getYbSelfFlag()) && "0".equals(item.getYbSelfFlag())) {
  383. item.setYbSelfFlag(null);
  384. }
  385. if (StringUtil.isBlank(item.getOrderCode())) {
  386. cuoWuXinXi.append(baoCunCuoWuXinXi(index, "项目编码不能为空"));
  387. }
  388. if (StringUtil.isBlank(item.getOrderName())) {
  389. cuoWuXinXi.append(baoCunCuoWuXinXi(index, "项目名称不能为空"));
  390. }
  391. if (item.getStartTime() == null) {
  392. cuoWuXinXi.append(baoCunCuoWuXinXi(index, "检查时间不能为空"));
  393. } else if (DateUtil.shiJianDaXiao(huanZheXinXi.getAdmissDate(), item.getStartTime(), ">")) {
  394. cuoWuXinXi.append(baoCunCuoWuXinXi(index, "医嘱时间不能小于入院时间"));
  395. }
  396. if (StringUtil.isBlank(item.getExecDept())) {
  397. cuoWuXinXi.append(baoCunCuoWuXinXi(index, "执行科室不能为空。"));
  398. }
  399. if ("3".equals(param.getReqType())) {
  400. if (StringUtil.isBlank(item.getReqComment())) {
  401. cuoWuXinXi.append(baoCunCuoWuXinXi(index, "病室摘要不能为空。"));
  402. }
  403. if (StringUtil.isBlank(item.getReqTzComment())) {
  404. cuoWuXinXi.append(baoCunCuoWuXinXi(index, "体征信息不能为空。"));
  405. }
  406. if (StringUtil.isBlank(item.getReqOtherResult())) {
  407. cuoWuXinXi.append(baoCunCuoWuXinXi(index, "相关辅检结果不能为空。"));
  408. }
  409. if (StringUtil.isBlank(item.getDiagCode())) {
  410. cuoWuXinXi.append(baoCunCuoWuXinXi(index, "临床诊断不能为空。"));
  411. }
  412. } else {
  413. if (StringUtil.isBlank(item.getInspectStuff())) {
  414. cuoWuXinXi.append(baoCunCuoWuXinXi(index, "标本不能为空。"));
  415. }
  416. }
  417. if (cuoWuXinXi.length() > 0) {
  418. cuoWuXinXi.append("<br>");
  419. }
  420. xm.add(item.getOrderCode().trim());
  421. content.add(String.format("%s:<span style='color:#409eff'>【%s】</span><br>" +
  422. "患者姓名:<span style='color:#409eff'>【%s】</span><br>" +
  423. "床位:<span style='color:#409eff'>【%s】</span>", "2".equals(param.getReqType()) ? "检查名" : "检验名",
  424. item.getOrderName(), huanZheXinXi.getName(), huanZheXinXi.getBedNo()));
  425. index++;
  426. }
  427. // 先判断是不是停用了
  428. String tingYong = publicServer.xiangMuXianZhi(xm, true);
  429. if (StringUtil.notBlank(tingYong)) {
  430. throw new BizException(ExceptionEnum.LOGICAL_HTML_ERROR, tingYong);
  431. }
  432. if (StringUtil.notBlank(cuoWuXinXi.toString())) {
  433. throw new BizException(ExceptionEnum.LOGICAL_HTML_ERROR, String.valueOf(cuoWuXinXi));
  434. }
  435. // 生成 医嘱号和申请号
  436. for (YshYjReq item : param.getList()) {
  437. item.setActOrderNo(publicServer.getActOrderNo());
  438. item.setReqNo(publicServer.getReqPageNo());
  439. }
  440. String userCode = TokenUtil.getTokenUserId();
  441. getThis().insertData(param, huanZheXinXi, userCode);
  442. try {
  443. publicServer.faSongXiaoXi(huanZheXinXi, content, "2".equals(param.getReqType()) ? "新增检查" : "新增检验", TokenUtil.getTokenUserId());
  444. } catch (Exception e) {
  445. e.printStackTrace();
  446. }
  447. log.info("数据:{}", JSON.toJSONString(param.getList()));
  448. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  449. }
  450. @Transactional(rollbackFor = Exception.class)
  451. public void insertData(TianJiaJianChaJianYan param, XinZhenYiZhu huanZheXinXi, String userCode) {
  452. Date reqDate = new Date();
  453. dao.chaRuShenQing(param.getList(), param.getInpatientNo(), param.getName(), param.getAge() + "岁", param.getAdmissTimes(),
  454. param.getBedNo(), userCode, huanZheXinXi.getDeptCode(), huanZheXinXi.getDeptCode(), param.getReqType(),
  455. "3".equals(param.getReqType()) ? "jc_zd_item" : "jy_zd_item", reqDate);
  456. dao.chaRuShenQingYiZhu(param.getList(), param.getInpatientNo(), param.getAdmissTimes(), userCode, huanZheXinXi.getDeptCode(), huanZheXinXi.getDeptCode(),
  457. PublicServer.getInfantFlag(param.getInpatientNo()), reqDate);
  458. }
  459. public String baoCunCuoWuXinXi(int index, String xinXi) {
  460. return String.format("第【%d】个%s<br>", index, xinXi);
  461. }
  462. /*-------------------------------------------------------------- 下面是检验的逻辑 -----------------------------------------------------------------------------------------------------*/
  463. public ResultVo<List<YshYjReq>> huoQuJianYan(ChaXunJianChaHeJianYan param) {
  464. QueryWrapper<?> qw = new QueryWrapper<>();
  465. qw.eq("inpatient_no", param.getPatNo());
  466. qw.eq("admiss_times", param.getTimes());
  467. qw.eq("req_type", "2");
  468. if (StringUtil.notBlank(param.getStartTime())) {
  469. qw.ge("start_time", param.getStartTime())
  470. .le("start_time", param.getEndTime());
  471. }
  472. if (StringUtil.notBlank(param.getOrderName())) {
  473. qw.like("order_name", param.getOrderName());
  474. }
  475. qw.orderByDesc("act_order_no");
  476. List<YshYjReq> list = dao.huoQuJianYanV2(qw);
  477. return ResultVoUtil.success(list);
  478. }
  479. public ResultVo<IPage<JcZdClass>> huoQuJianYanMing(long total, long currentPage, Integer leiXing) {
  480. IPage<JcZdClass> page = new Page<>(currentPage, 20, total == 0);
  481. if (leiXing == 1) {
  482. page = dao.jianYanFenLei(page);
  483. return ResultVoUtil.success(page);
  484. }
  485. return ResultVoUtil.success();
  486. }
  487. public ResultVo<List<GetDropdownBox>> biaoBenShuJu(String name) {
  488. return ResultVoUtil.success(dao.biaoBenLeiXing(StringUtil.isContainChinese(name)));
  489. }
  490. @DS("his")
  491. public ResultVo<List<JianYanFeiYongXiangQing>> viewInspectionItemDetails(String orderCode) {
  492. return ResultVoUtil.success(dao.viewInspectionItemDetails(orderCode));
  493. }
  494. public ResultVo<String> shanChuJianChaJianYan(Integer reqNo, String patNo, Integer times) {
  495. if (StringUtil.isBlank(patNo)) {
  496. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "住院号不能为空。");
  497. }
  498. YshYjReq yj = dao.huoQuJianYanJianCha(reqNo, patNo, times);
  499. if (yj == null) {
  500. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有查询到该数据的具体信息,已经被删除了。");
  501. }
  502. int feeCount = dao.selectedFeeCount(yj);
  503. if (feeCount > 0) {
  504. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "费用已上账无法删除。");
  505. }
  506. int feePatientFee = dao.selecePatientFee(yj);
  507. if (feePatientFee > 0) {
  508. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医技已确费无法删除。");
  509. }
  510. dao.shanChuJianYanJianCha(reqNo, patNo, times);
  511. dao.shanChuYiZhu(yj.getActOrderNo());
  512. dao.cancellationOfConfirmedFees(yj, TokenUtil.getTokenUserId());
  513. log.info("删除医技申请==》操作人:{},医技数据:{}", TokenUtil.getTokenUserId(), JSON.toJSONString(yj));
  514. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  515. }
  516. public ResultVo<Map<String, Object>> queryCheckTextResults(String patNo, String reqNo) {
  517. String jcId = dao.getJcIdByPatNo(patNo);
  518. if (StringUtil.isBlank(jcId)) {
  519. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有获取到患者的检查id");
  520. }
  521. YjJcRecord yjJcRecord = dao.getJcRecord(reqNo, jcId);
  522. if (yjJcRecord == null) {
  523. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有查询到检查结果。");
  524. }
  525. Map<String, String> textJc = dao.selectTextJc(yjJcRecord.getReportNo());
  526. if (textJc != null) {
  527. yjJcRecord.setDiagnosticOpinion(textJc.get("text_zd"));
  528. yjJcRecord.setCheckWhatYouSee(textJc.get("text_jc"));
  529. }
  530. Map<String, Object> map = new HashMap<>(Capacity.TWO);
  531. map.put("record", yjJcRecord);
  532. return ResultVoUtil.success(map);
  533. }
  534. /**
  535. * 检验检查 树状图
  536. *
  537. * @return 返回树
  538. */
  539. @DS("his")
  540. public ResultVo<Map<String, List<JyJcItem>>> getJyJcZdTree() {
  541. Map<String, List<JyJcItem>> map = new HashMap<>(Capacity.TWO);
  542. // 把 检验 项目大类做map的key
  543. Map<String, JyJcItem> jyMap = dao.queryInspectionClassification().stream().collect(
  544. Collectors.toMap(JyJcItem::getCode, a -> a, (k1, k2) -> k1)
  545. );
  546. // 获取检验的详细项目
  547. List<JyJcItem> jyDetailedItems = dao.getJyDetailedItems();
  548. grouping(jyMap, jyDetailedItems);
  549. // 把 检查 项目大类做map的key
  550. Map<String, JyJcItem> jcMap = dao.queryCheckClassification().stream().collect(
  551. Collectors.toMap(JyJcItem::getCode, a -> a, (k1, k2) -> k1)
  552. );
  553. // 获取检查的详细项目
  554. List<JyJcItem> jcDetailedItems = dao.selectJcDetailItems();
  555. grouping(jcMap, jcDetailedItems);
  556. // 检查项目还需要根据部位细分
  557. List<JyJcItem> jcTree = new ArrayList<>();
  558. for (Map.Entry<String, JyJcItem> item : jcMap.entrySet()) {
  559. // 没有节点就不要添加
  560. if (item.getValue().getChildren() != null) {
  561. JyJcItem temp = new JyJcItem();
  562. temp.setName(item.getValue().getName());
  563. temp.setChildren(new ArrayList<>());
  564. // 通过部位进行详细的区分
  565. Map<String, List<JyJcItem>> tempMap = item.getValue().getChildren().stream().collect(
  566. Collectors.groupingBy(JyJcItem::getBw)
  567. );
  568. for (Map.Entry<String, List<JyJcItem>> entry : tempMap.entrySet()) {
  569. // 如果部位是空的就直接添加到父节点
  570. if (StringUtil.isBlank(entry.getKey())) {
  571. temp.setChildren(entry.getValue());
  572. } else {
  573. // 添加到指定的部位
  574. JyJcItem temp1 = new JyJcItem();
  575. temp1.setName(entry.getKey());
  576. temp1.setChildren(entry.getValue());
  577. temp.getChildren().add(temp1);
  578. }
  579. }
  580. jcTree.add(temp);
  581. }
  582. }
  583. map.put("jy", new ArrayList<>(jyMap.values()));
  584. map.put("jc", jcTree);
  585. return ResultVoUtil.success(map);
  586. }
  587. private void grouping(Map<String, JyJcItem> jyMap, List<JyJcItem> jyDetailedItems) {
  588. for (JyJcItem item : jyDetailedItems) {
  589. if (jyMap.containsKey(item.getClasses())) {
  590. JyJcItem tempMap = jyMap.get(item.getClasses());
  591. if (tempMap.getChildren() == null) {
  592. tempMap.setChildren(new ArrayList<>());
  593. }
  594. tempMap.getChildren().add(item);
  595. }
  596. }
  597. }
  598. @DS("his")
  599. public ResultVo<List<JyJcItem>> getJcItem(String code) {
  600. return ResultVoUtil.success(dao.getJcItem(StringUtil.isContainChinese(code)));
  601. }
  602. @DS("his")
  603. public ResultVo<List<JyJcItem>> getJyItem(String code) {
  604. return ResultVoUtil.success(dao.getJyItem(StringUtil.isContainChinese(code)));
  605. }
  606. }