PublicServer.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. package thyyxxk.webserver.service;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.dynamic.datasource.annotation.DS;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import lombok.AllArgsConstructor;
  7. import lombok.Data;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.apache.commons.collections4.ListUtils;
  10. import org.apache.ibatis.session.ExecutorType;
  11. import org.apache.ibatis.session.SqlSession;
  12. import org.apache.ibatis.session.SqlSessionFactory;
  13. import org.jetbrains.annotations.NotNull;
  14. import org.springframework.scheduling.annotation.Async;
  15. import org.springframework.stereotype.Service;
  16. import org.springframework.transaction.annotation.Isolation;
  17. import org.springframework.transaction.annotation.Propagation;
  18. import org.springframework.transaction.annotation.Transactional;
  19. import thyyxxk.webserver.config.exception.BizException;
  20. import thyyxxk.webserver.config.exception.ExceptionEnum;
  21. import thyyxxk.webserver.constants.Capacity;
  22. import thyyxxk.webserver.constants.Message;
  23. import thyyxxk.webserver.constants.RestrictedDrugLevels;
  24. import thyyxxk.webserver.constants.Ysjb;
  25. import thyyxxk.webserver.dao.his.PublicDao;
  26. import thyyxxk.webserver.dao.his.inpatient.TransferInOfExpensesDao;
  27. import thyyxxk.webserver.dao.his.settings.SettingsDao;
  28. import thyyxxk.webserver.entity.ResultVo;
  29. import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
  30. import thyyxxk.webserver.entity.datamodify.ZyDetailCharge;
  31. import thyyxxk.webserver.entity.dictionary.CodeName;
  32. import thyyxxk.webserver.entity.inpatient.ZyActpatient;
  33. import thyyxxk.webserver.entity.login.UserInfo;
  34. import thyyxxk.webserver.entity.login.UserInfoSelect;
  35. import thyyxxk.webserver.entity.medicalinsurance.inpatient.ZyPatientInfo;
  36. import thyyxxk.webserver.entity.publicapi.ItemDrug;
  37. import thyyxxk.webserver.entity.publicapi.ZkList;
  38. import thyyxxk.webserver.entity.settings.notification.SendMessageParam;
  39. import thyyxxk.webserver.entity.socketmessage.ApiMessageBody;
  40. import thyyxxk.webserver.entity.socketmessage.SendUserList;
  41. import thyyxxk.webserver.entity.socketmessage.SocketMessage;
  42. import thyyxxk.webserver.entity.zhuyuanyisheng.PatientAllergenInfo;
  43. import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.XinZhenYiZhu;
  44. import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.YaoPinXiangMu;
  45. import thyyxxk.webserver.service.externalhttp.WebSocketService;
  46. import thyyxxk.webserver.service.redislike.RedisLikeService;
  47. import thyyxxk.webserver.utils.*;
  48. import java.lang.reflect.InvocationTargetException;
  49. import java.math.BigDecimal;
  50. import java.util.*;
  51. import java.util.stream.Collectors;
  52. /**
  53. * <p>
  54. * 描述: 公共接口
  55. * </p>
  56. *
  57. * @author xc
  58. * @date 2021-09-17 10:54
  59. */
  60. @Service
  61. @Slf4j
  62. public class PublicServer {
  63. private final PublicDao dao;
  64. private final TransferInOfExpensesDao transferInOfExpensesDao;
  65. private final RedisLikeService redisLikeService;
  66. private final SettingsDao settingsDao;
  67. private final WebSocketService socketService;
  68. private final SqlSessionFactory sqlSessionFactory;
  69. public PublicServer(PublicDao dao, TransferInOfExpensesDao transferInOfExpensesDao, RedisLikeService redisLikeService, SettingsDao settingsDao, WebSocketService socketService, SqlSessionFactory sqlSessionFactory) {
  70. this.dao = dao;
  71. this.transferInOfExpensesDao = transferInOfExpensesDao;
  72. this.redisLikeService = redisLikeService;
  73. this.settingsDao = settingsDao;
  74. this.socketService = socketService;
  75. this.sqlSessionFactory = sqlSessionFactory;
  76. }
  77. /**
  78. * 手术日期格式
  79. *
  80. * @param opStartDate 手术开始时间
  81. * @param opEndDate 手术结束时间
  82. * @param anstStartDate 麻醉开始时间
  83. * @param anstEndDate 麻醉结束时间
  84. */
  85. public static void surgeryTimeLimit(String opName, Date opStartDate, Date opEndDate, Date anstStartDate, Date anstEndDate) {
  86. if (anstStartDate != null) {
  87. if (DateUtil.shiJianDaXiao(opStartDate, anstStartDate, "<")) {
  88. throw new BizException(ExceptionEnum.LOGICAL_ERROR, opName + ":麻醉开始时间要大于手术开始时间.");
  89. }
  90. long opDate = opEndDate.getTime() - opStartDate.getTime();
  91. long anstDate = anstEndDate.getTime() - anstStartDate.getTime();
  92. if (opDate >= anstDate) {
  93. throw new BizException(ExceptionEnum.LOGICAL_ERROR, opName + ":手术麻醉时间一定要比手术时间长.");
  94. }
  95. }
  96. }
  97. /**
  98. * 获取用户的角色信息
  99. *
  100. * @return 返回角色
  101. */
  102. public ResultVo<List<Integer>> getRoleCode() {
  103. return ResultVoUtil.success(redisLikeService.getUserInfoByToken().getRoles());
  104. }
  105. /**
  106. * @param jueSeBianMa 不需要限制的角色id
  107. * @return Boolean
  108. */
  109. public Boolean noNeedRule(int... jueSeBianMa) {
  110. return getaBoolean(jueSeBianMa, getRoleCode().getData());
  111. }
  112. /**
  113. * @param jueSeBianMa 不需要限制的角色id
  114. * @return Boolean
  115. */
  116. public Boolean noNeedRule(List<Integer> role, int... jueSeBianMa) {
  117. return getaBoolean(jueSeBianMa, role);
  118. }
  119. /**
  120. * @param jueSeBianMa 不需要限制的角色id
  121. * @return Boolean 如果有就返回true
  122. */
  123. public Boolean needRule(int... jueSeBianMa) {
  124. return !getaBoolean(jueSeBianMa, getRoleCode().getData());
  125. }
  126. /**
  127. * @param jueSeBianMa 不需要限制的角色id
  128. * @return Boolean
  129. */
  130. public Boolean needRule(List<Integer> role, int... jueSeBianMa) {
  131. return !getaBoolean(jueSeBianMa, role);
  132. }
  133. public Boolean getaBoolean(int[] jueSeBianMa, List<Integer> roleCode) {
  134. if (roleCode.contains(1)) {
  135. return false;
  136. }
  137. if (ListUtil.isBlank(roleCode)) {
  138. return true;
  139. }
  140. for (Integer i : jueSeBianMa) {
  141. if (roleCode.contains(i)) {
  142. return false;
  143. }
  144. }
  145. return true;
  146. }
  147. /**
  148. * 获取新的医嘱号
  149. *
  150. * @return 返回医嘱号
  151. */
  152. @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  153. public BigDecimal getActOrderNo() {
  154. BigDecimal oldId = dao.getActOrderNo();
  155. BigDecimal newId = oldId.add(BigDecimal.ONE);
  156. int num = dao.updateActOrderNo(newId, oldId);
  157. // 插入生成医嘱的日志
  158. orderRecord(newId, TokenUtil.getInstance().getTokenUserId());
  159. if (num == 0) {
  160. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "生成医嘱号错误,请重试!");
  161. }
  162. return newId;
  163. }
  164. /**
  165. * 获取模板的编码
  166. *
  167. * @return 返回编码信息
  168. */
  169. @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  170. public String getPatternCode() {
  171. Integer oldId = dao.getPatternCode();
  172. Integer newId = oldId + 1;
  173. int num = dao.updatePatternCode(newId, oldId);
  174. if (num == 0) {
  175. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "生成模板编码错误,请重试!");
  176. }
  177. return newId.toString();
  178. }
  179. /**
  180. * 获取医嘱模板下面的 子级 排序号
  181. *
  182. * @return 返回序号
  183. */
  184. @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  185. public BigDecimal getPatternOrderCode() {
  186. BigDecimal oldId = dao.getPatternOrderCode();
  187. BigDecimal newId = oldId.add(BigDecimal.ONE);
  188. int num = dao.updatePatternOrderCode(newId, oldId);
  189. if (num == 0) {
  190. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "生成子医嘱模板编码错误,请重试!");
  191. }
  192. return newId;
  193. }
  194. /**
  195. * @return 返回说明模板的编码
  196. */
  197. @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  198. public Integer getYjTemplateNo() {
  199. Integer oldId = dao.tempNo();
  200. Integer newId = oldId + 1;
  201. int num = dao.updateTempNo(newId, oldId);
  202. if (num == 0) {
  203. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "生成说明模板的编码错误,请重试!");
  204. }
  205. return newId;
  206. }
  207. /**
  208. * @return 返回申请号
  209. */
  210. @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  211. public Integer getReqPageNo() {
  212. Integer oldId = dao.getReqNo();
  213. Integer newId = oldId + 1;
  214. int num = dao.updateReqNo(newId, oldId);
  215. if (num == 0) {
  216. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "生成申请号错误,请重试!");
  217. }
  218. return newId;
  219. }
  220. /**
  221. * 获取药品单号
  222. *
  223. * @return 药品单号
  224. */
  225. @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  226. public Integer getTheDrugListNo() {
  227. Integer oldId = dao.caoYaoDanHao();
  228. Integer newId = oldId + 1;
  229. int num = dao.genXingCaoYaoDanHao(newId, oldId);
  230. if (num == 0) {
  231. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "生成申请号错误,请重试!");
  232. }
  233. return Integer.valueOf(DateUtil.formatDatetime(new Date(), "yyMMdd") + newId);
  234. }
  235. /**
  236. * 获取传染病序号
  237. *
  238. * @return 序号
  239. */
  240. @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  241. public Integer getCrbNo() {
  242. Integer oldId = dao.oldCrbNo();
  243. Integer newId = oldId + 1;
  244. int num = dao.updateCrbNo(newId, oldId);
  245. if (num == 0) {
  246. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "生成申请号错误,请重试!");
  247. }
  248. return newId;
  249. }
  250. /**
  251. * @param inpatientNo 住院号
  252. * @return 返回婴儿标志
  253. */
  254. public static int getInfantFlag(String inpatientNo) {
  255. if (StringUtil.isBlank(inpatientNo)) {
  256. return 0;
  257. }
  258. if (inpatientNo.contains("$")) {
  259. return 1;
  260. }
  261. return 0;
  262. }
  263. /**
  264. * 返回
  265. *
  266. * @param inpatientNo 住院号
  267. * @return 返回新住院号
  268. */
  269. public String getInpatientNo(String inpatientNo) {
  270. if (StringUtil.isBlank(inpatientNo)) {
  271. return "";
  272. }
  273. if (inpatientNo.contains("$")) {
  274. inpatientNo = inpatientNo.split("\\$")[0];
  275. }
  276. return inpatientNo;
  277. }
  278. /**
  279. * 获取最大流水号
  280. *
  281. * @param inpatientNo 住院号
  282. * @param admissTimes 住院次数
  283. * @return 返回 流水
  284. */
  285. public Integer getMaxDetailSn(String inpatientNo, Integer admissTimes) {
  286. return transferInOfExpensesDao.getMaxDetailSn(inpatientNo, admissTimes);
  287. }
  288. /**
  289. * 获取科室的子科室和本科
  290. *
  291. * @param deptCode 科室代码
  292. * @return 返回科室
  293. */
  294. public List<String> getKeShiLieBiaoList(String deptCode) {
  295. if (noNeedRule()) {
  296. List<String> list = dao.getKeShiLieBiao(deptCode);
  297. list.add(deptCode);
  298. return list;
  299. }
  300. return new ArrayList<>();
  301. }
  302. public Set<String> getChildDeptByUserCode() {
  303. return getChildDeptByUserCode(true);
  304. }
  305. public Set<String> getChildDeptByUserCode(String userCode) {
  306. return getChildDeptByUserCode(true, userCode);
  307. }
  308. public Set<String> getChildDeptByUserCode(boolean needPartTimeDept, String userCode) {
  309. UserInfo userInfo = redisLikeService.getUserInfoByCode(userCode);
  310. return getDept(needPartTimeDept, userInfo);
  311. }
  312. /**
  313. * 获取医生的子科室 和 兼职科室 以及兼职下面的子科室
  314. *
  315. * @return 返回科室
  316. */
  317. public Set<String> getChildDeptByUserCode(boolean needPartTimeDept) {
  318. UserInfo userInfo = redisLikeService.getUserInfoByToken();
  319. return getDept(needPartTimeDept, userInfo);
  320. }
  321. @NotNull
  322. private Set<String> getDept(boolean needPartTimeDept, UserInfo userInfo) {
  323. return redisLikeService.getDept(needPartTimeDept, userInfo);
  324. }
  325. /**
  326. * 获取科室 列表 下面的子科室
  327. *
  328. * @param deptCodeList 科室列表
  329. * @return 返回科室
  330. */
  331. public List<String> getKeShiLieBiaoList(List<String> deptCodeList) {
  332. if (ListUtil.isBlank(deptCodeList)) {
  333. return new ArrayList<>();
  334. }
  335. return dao.getKeShiLieBiaoList(deptCodeList);
  336. }
  337. /**
  338. * 获取人员信息
  339. *
  340. * @param code 人员代码
  341. * @return 返回人员
  342. */
  343. public ResultVo<List<GetDropdownBox>> getRenYuan(String code, String deptCode) {
  344. return ResultVoUtil.success(dao.getRenYuan(StringUtil.isContainChinese(code), deptCode));
  345. }
  346. /**
  347. * 获取员工信息
  348. *
  349. * @param code 编码
  350. * @return 返回
  351. */
  352. public UserInfo huoQuYuanGongXinXi(String code) {
  353. if (StringUtil.isBlank(code)) {
  354. return new UserInfo();
  355. }
  356. return dao.huoQuYuanGongBianMa(code);
  357. }
  358. public ResultVo<List<UserInfoSelect>> getPersonnelAll() {
  359. return ResultVoUtil.success(dao.getPersonnelAll());
  360. }
  361. /**
  362. * 搜索项目信息
  363. *
  364. * @param pyCode 拼音码
  365. * @return 返回项目信息
  366. */
  367. public ResultVo<List<GetDropdownBox>> getChargeCode(String pyCode) {
  368. log.info("获取编码:{}", pyCode);
  369. return ResultVoUtil.success(dao.getChargeCode(StringUtil.isContainChinese(pyCode)));
  370. }
  371. /**
  372. * 获取科室信息
  373. *
  374. * @return 返回科室
  375. */
  376. public ResultVo<List<GetDropdownBox>> getDept() {
  377. return ResultVoUtil.success(dao.getDept());
  378. }
  379. public ResultVo<List<GetDropdownBox>> queryDept(String code) {
  380. return ResultVoUtil.success(dao.queryDept(StringUtil.isContainChinese(code)));
  381. }
  382. /**
  383. * 获取这个人的账页号
  384. *
  385. * @param inpatientNo 住院号
  386. * @param admissTimes 住院次数
  387. * @return 返回有用的账页号
  388. */
  389. public Integer getLedgerSn(String inpatientNo, Integer admissTimes) {
  390. if (StringUtil.isBlank(inpatientNo) || admissTimes == null) {
  391. return 0;
  392. }
  393. inpatientNo = getInpatientNo(inpatientNo);
  394. return dao.getLedgerSn(inpatientNo, admissTimes);
  395. }
  396. /**
  397. * 更新患者的退费对应的正流水号
  398. *
  399. * @param inpatientNo 住院号
  400. * @param admissTimes 住院次数
  401. * @param ledger 账页号
  402. */
  403. public void genXingYuanLiuShuiBiaoZhi(String inpatientNo, Integer admissTimes, Integer ledger) {
  404. dao.chongZhiZhenLiuShui(inpatientNo, admissTimes, ledger);
  405. // 这里是重置 正流水号
  406. List<Integer> huoQuTuiFeiYuanLiuShui = dao.huoQuTuiFeiYuanLiuShui(inpatientNo, admissTimes, ledger);
  407. if (ListUtil.notBlank(huoQuTuiFeiYuanLiuShui)) {
  408. List<List<Integer>> fenGeFuLiuShui = ListUtils.partition(huoQuTuiFeiYuanLiuShui, 50);
  409. for (List<Integer> integers : fenGeFuLiuShui) {
  410. dao.genXingFuShuDuiYingZhenLiuShui(inpatientNo, admissTimes, ledger, integers);
  411. }
  412. }
  413. // 这里是判断正数的是否没有了,如果正数的没有了 那么负数的就要更新为空
  414. List<Integer> xuYaoQingKongDeFuLiuShui = new ArrayList<>();
  415. List<Integer> zhenShuLiuShuiMap = dao.zhenShuLiuShui(inpatientNo, admissTimes, ledger);
  416. List<Integer> fuShuLiuShui = dao.fuShuLiuShui(inpatientNo, admissTimes, ledger);
  417. for (Integer integer : fuShuLiuShui) {
  418. if (!zhenShuLiuShuiMap.contains(integer) && !xuYaoQingKongDeFuLiuShui.contains(integer)) {
  419. xuYaoQingKongDeFuLiuShui.add(integer);
  420. }
  421. }
  422. if (ListUtil.notBlank(xuYaoQingKongDeFuLiuShui)) {
  423. List<List<Integer>> list = ListUtils.partition(xuYaoQingKongDeFuLiuShui, 50);
  424. for (List<Integer> integers : list) {
  425. dao.chongZhiFuShuYuanLiuShui(inpatientNo, admissTimes, ledger, integers);
  426. }
  427. }
  428. // 这里判断是否重复退费,退多了
  429. Map<Integer, ZyDetailCharge> chongFuYuanLiuShuiMap = dao.chongFuTuiFeiLiuShui(inpatientNo, admissTimes, ledger).stream().collect(Collectors.toMap(ZyDetailCharge::getOriDetailSn, a -> a, (k1, k2) -> k1));
  430. if (!chongFuYuanLiuShuiMap.isEmpty()) {
  431. List<ZyDetailCharge> chongFuTuiFeiZhenShu = dao.getZhenShuLiuShui(inpatientNo, admissTimes, ledger, chongFuYuanLiuShuiMap.keySet());
  432. List<Integer> xuYaoChongZhiLiuShui = new ArrayList<>();
  433. if (ListUtil.notBlank(chongFuTuiFeiZhenShu)) {
  434. for (ZyDetailCharge zyDetailCharge : chongFuTuiFeiZhenShu) {
  435. ZyDetailCharge zy = chongFuYuanLiuShuiMap.get(zyDetailCharge.getDetailSn());
  436. if (BigUtils.bigXiaoYu(zyDetailCharge.getChargeFee(), zy.getChargeFee().negate())) {
  437. xuYaoChongZhiLiuShui.add(zyDetailCharge.getDetailSn());
  438. }
  439. }
  440. }
  441. // 这里更新
  442. if (ListUtil.notBlank(xuYaoChongZhiLiuShui)) {
  443. dao.chongFuTuiFeiChongZhi(inpatientNo, admissTimes, ledger, xuYaoChongZhiLiuShui);
  444. }
  445. }
  446. // 这个是判断 trans_flag_yb = 2 费用相加 不为 0 的 就重置一下
  447. if (!BigUtils.dengYu(dao.zhenFuXingDiFeiYong(inpatientNo, admissTimes, ledger), 0)) {
  448. dao.chongXingZhengFuXiangDi(inpatientNo, admissTimes, ledger);
  449. }
  450. }
  451. public List<String> huoQuBingFangDeKeShi(String deptCode) {
  452. if (getRoleCode().getData().contains(1) || getRoleCode().getData().contains(8) || StringUtil.isBlank(deptCode)) {
  453. return new ArrayList<>();
  454. }
  455. List<String> keShiDaiMa = dao.bingFangSuoSuKeShi(deptCode);
  456. if (ListUtil.isBlank(keShiDaiMa)) {
  457. keShiDaiMa.add(deptCode);
  458. }
  459. return keShiDaiMa;
  460. }
  461. /**
  462. * 这里的住院号是没有 处理过得
  463. *
  464. * @param inpatientNo 住院号
  465. * @return 返回病人基本信息
  466. */
  467. public ZyActpatient huoQuHuanZheXinXi(String inpatientNo) {
  468. if (StringUtil.isBlank(inpatientNo)) {
  469. throw new BizException(ExceptionEnum.NULL_POINTER, "住院号为空。");
  470. }
  471. ZyActpatient zyActpatient = dao.getHuanZheJiBenXinXi(inpatientNo);
  472. if (zyActpatient == null) {
  473. throw new BizException(ExceptionEnum.NULL_POINTER, "没有查询到患者的基本信息。");
  474. }
  475. zyActpatient.setInfantFlag(getInfantFlag(zyActpatient.getInpatientNo()));
  476. zyActpatient.setInpatientNo(getInpatientNo(zyActpatient.getInpatientNo()));
  477. return zyActpatient;
  478. }
  479. /**
  480. * 获取麻醉方式
  481. *
  482. * @return 返回数据
  483. */
  484. public ResultVo<List<GetDropdownBox>> maZuiFangShi() {
  485. return ResultVoUtil.success(dao.maZuiFangShi());
  486. }
  487. public Integer huoQuJianYanJianChaXuHao() {
  488. dao.jianYanJianChaSuo();
  489. Integer xuHao = dao.jianYanJianChaXuHao() + 1;
  490. dao.genXingJianYanJianChaXuHao(xuHao);
  491. return xuHao;
  492. }
  493. public Integer huoQuShouShuHao() {
  494. dao.suoZhuShouShu();
  495. Integer index = dao.shouShuXuHao() + 1;
  496. dao.genXingShouShuXuHao(index);
  497. return index;
  498. }
  499. public void huanZheJieSuan(String patNo, Integer times) {
  500. if (StringUtil.isBlank(patNo) || times == null) {
  501. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "住院号不能为空。");
  502. }
  503. patNo = getInpatientNo(patNo);
  504. Integer settleType = dao.jieSuanXinXi(patNo, times);
  505. if (settleType == null) {
  506. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "没有查询到患者结算信息。");
  507. }
  508. if (settleType == 1) {
  509. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "患者已经结算无法进行操作了。");
  510. }
  511. }
  512. /**
  513. * 药品限制
  514. *
  515. * @param listCode 药品的编码以及规格 做成code
  516. * @return 返回提示
  517. */
  518. public String yaoPinXianZhi(List<String> listCode, boolean delFlag) {
  519. StringBuilder sb = new StringBuilder();
  520. QueryWrapper<?> qw = new QueryWrapper<>();
  521. qw.in("rtrim(code) + rtrim(serial)", listCode);
  522. Map<String, YaoPinXiangMu> map = dao.huoQuYaoPinPiPeiXinXi(qw).stream().collect(Collectors.toMap(YaoPinXiangMu::getZdCode, a -> a, (k1, k2) -> k1));
  523. return yaoPingXiangMuXianZhi(map, sb, "药品", delFlag);
  524. }
  525. public String xiangMuXianZhi(List<String> listCode, boolean delFlag) {
  526. Map<String, YaoPinXiangMu> map = dao.huoQuXiangMuXinXi(listCode).stream().collect(Collectors.toMap(YaoPinXiangMu::getZdCode, a -> a, (k1, k2) -> k1));
  527. StringBuilder sb = new StringBuilder();
  528. return yaoPingXiangMuXianZhi(map, sb, "项目", delFlag);
  529. }
  530. @NotNull
  531. public String yaoPingXiangMuXianZhi(Map<String, YaoPinXiangMu> map, StringBuilder sb, String name, boolean delFlag) {
  532. for (YaoPinXiangMu item : map.values()) {
  533. if (delFlag && item.getDelFlag() == 1) {
  534. sb.append(cuoWuXinXi(item.getZdCode(), "00".equals(item.getSerial().trim()) ? "医嘱名:" + item.getName() + " 项目名:" + item.getZdName() : "" + item.getName(), name + "已被停用"));
  535. }
  536. if (StringUtil.isBlank(item.getNationalCode()) && !delFlag) {
  537. sb.append(cuoWuXinXi(item.getZdCode(), "00".equals(item.getSerial().trim()) ? "医嘱名:" + item.getName() + " 项目名:" + item.getZdName() : "" + item.getName(), name + "没有匹配医保编码"));
  538. }
  539. }
  540. return sb.toString();
  541. }
  542. public String cuoWuXinXi(String code, String name, String xinXi) {
  543. return "编码:<span style='color:teal'>【" + code + "】</span><br>" + "名称:<span style='color:#a5673f'>【" + name + "】 </span><br>" + "<span style='color:red'>" + xinXi + "</span><br>";
  544. }
  545. public void sendDoctorNotification(XinZhenYiZhu huanZheXinXi, String content, String title, String sender, List<String> userCodeList) {
  546. sendDoctorNotification(huanZheXinXi, Collections.singletonList(content), title, sender, userCodeList);
  547. }
  548. /**
  549. * @param huanZheXinXi 患者信息
  550. * @param content 内容
  551. * @param title 标题
  552. * @param userCode 发送人id
  553. */
  554. public void faSongXiaoXi(XinZhenYiZhu huanZheXinXi, List<String> content, String title, String userCode) {
  555. List<String> huShiBianMa = dao.huoQuHuanZheBingFangDeHuShi(huanZheXinXi.getDeptCode());
  556. sendDoctorNotification(huanZheXinXi, content, title, userCode, huShiBianMa);
  557. }
  558. /**
  559. * @param huanZheXinXi 患者信息
  560. * @param content 内容
  561. * @param title 标题
  562. * @param sender 发送人 TokenUtil.getInstance().getTokenUserId() 不能使用这个因为用的 异步的方法 会导致 tokenUtil.getTokenUserId() 为 99999
  563. * @param userCodeList 接收方
  564. */
  565. @Async
  566. public void sendDoctorNotification(XinZhenYiZhu huanZheXinXi, List<String> content, String title, String sender, List<String> userCodeList) {
  567. int count = content.size();
  568. // 发送通知类
  569. List<SocketMessage> socketMessage1 = new ArrayList<>();
  570. List<SocketMessage> socketMessage2 = new ArrayList<>();
  571. for (String s : content) {
  572. SocketMessage faSongNeiRong = new SocketMessage();
  573. faSongNeiRong.setSender(sender);
  574. faSongNeiRong.setContent(s);
  575. // 雪花算法
  576. faSongNeiRong.setId(SnowFlakeId.instance().nextId());
  577. faSongNeiRong.setPatId(huanZheXinXi.getInpatientNo() + "_" + huanZheXinXi.getAdmissTimes());
  578. faSongNeiRong.setTitle(title);
  579. socketMessage1.add(faSongNeiRong);
  580. for (String huShi : userCodeList) {
  581. SocketMessage jieShouFang = new SocketMessage();
  582. jieShouFang.setMsgId(faSongNeiRong.getId());
  583. jieShouFang.setSender(faSongNeiRong.getSender());
  584. jieShouFang.setReceiver(huShi);
  585. socketMessage2.add(jieShouFang);
  586. }
  587. }
  588. List<List<SocketMessage>> fenGeFaSongFang = ListUtils.partition(socketMessage1, 20);
  589. List<List<SocketMessage>> fenGeJieShouFang = ListUtils.partition(socketMessage2, 20);
  590. SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
  591. PublicDao mapper = sqlSession.getMapper(PublicDao.class);
  592. for (List<SocketMessage> item : fenGeFaSongFang) {
  593. mapper.chaRuTongZhiXinXi(item);
  594. }
  595. for (List<SocketMessage> item : fenGeJieShouFang) {
  596. mapper.chaRuJieShouShuJu(item);
  597. }
  598. try {
  599. sqlSession.commit();
  600. } finally {
  601. sqlSession.close();
  602. }
  603. JSONObject json = new JSONObject();
  604. UserInfo userInfo = redisLikeService.getUserInfoByCode(sender);
  605. json.put("avatar", userInfo.getAvatar());
  606. json.put("deptName", userInfo.getDeptName());
  607. json.put("name", userInfo.getName());
  608. json.put("msg", "患者:【" + huanZheXinXi.getName() + "】" + "新增数据:" + count + "条");
  609. json.put("title", title);
  610. json.put("count", count);
  611. String msgContent = SocketMsg.socketVo(Message.AVATAR_NOTIFICATION, json);
  612. socketService.sendUserListMessage(new SendUserList(userCodeList, msgContent));
  613. }
  614. public ResultVo<String> makePyCode(String tableName, String idColumn, String nameColumn, String pyColumn) {
  615. List<CodeName> list = dao.originalList(tableName, idColumn, nameColumn, pyColumn);
  616. if (null == list || list.isEmpty()) {
  617. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有需要更改的数据。");
  618. }
  619. for (CodeName item : list) {
  620. String pycode = PingYinUtils.pyShouZiMuDaXie(item.getName());
  621. dao.updatePycode(tableName, idColumn, item.getCode(), pyColumn, pycode);
  622. log.info("修复:{},{},{}", item.getCode(), item.getName(), pycode);
  623. }
  624. return ResultVoUtil.success("修复拼音码成功,共修复 " + list.size() + " 条。");
  625. }
  626. @DS("his")
  627. public ResultVo<List<GetDropdownBox>> getAllergens(String name) {
  628. return ResultVoUtil.success(dao.getAllergens(StringUtil.isContainChinese(name)));
  629. }
  630. public ResultVo<List<PatientAllergenInfo>> getPatientAllergens(String patNo) {
  631. return ResultVoUtil.success(dao.getPatientAllergens(patNo));
  632. }
  633. public ResultVo<Boolean> whetherThePatientHasAllergens(String PatNo) {
  634. return ResultVoUtil.success(dao.whetherThePatientHasAllergens(PatNo) > 0);
  635. }
  636. public ResultVo<Integer> newPatientAllergens(String patNo, String allergenCode, int allergenType) {
  637. if (StringUtil.isBlank(patNo)) {
  638. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有患者住院号");
  639. }
  640. PatientAllergenInfo info = new PatientAllergenInfo();
  641. info.setAllergenCode(allergenCode);
  642. info.setPatNo(patNo);
  643. info.setType(allergenType);
  644. dao.newPatientAllergens(info);
  645. return ResultVoUtil.success(info.getId());
  646. }
  647. public ResultVo<String> removePatientAllergens(Integer id) {
  648. dao.removePatientAllergens(id);
  649. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_EL_MESSAGE);
  650. }
  651. /**
  652. * @param name 名称
  653. * @return 获取药品信息
  654. */
  655. public ResultVo<List<GetDropdownBox>> getDrugInfo(String name) {
  656. return ResultVoUtil.success(dao.getDrugInfo(StringUtil.isContainChinese(name)));
  657. }
  658. public ResultVo<List<GetDropdownBox>> getBldCat(String name) {
  659. return ResultVoUtil.success(dao.getBldCat(StringUtil.isContainChinese(name)));
  660. }
  661. /**
  662. * 获取转科列表
  663. *
  664. * @return
  665. */
  666. public ResultVo<List<ZkList>> getTheTransferList() {
  667. List<ZkList> list = dao.getTheTransferList();
  668. for (ZkList zkList : list) {
  669. zkList.setValue(JSON.toJSONString(zkList));
  670. }
  671. return ResultVoUtil.success(list);
  672. }
  673. @Data
  674. @AllArgsConstructor
  675. public static class IntCodeName {
  676. private Integer code;
  677. private String name;
  678. }
  679. public ResultVo<Map<String, Object>> getPeopleToFillInInformation() throws InvocationTargetException, IllegalAccessException {
  680. Map<String, Object> map = new HashMap<>(Capacity.EIGHT);
  681. map.put("restrictedDrugLevels", EnumToJson.toJson(RestrictedDrugLevels.values()));
  682. map.put("ysjbData", EnumToJson.toJson(Ysjb.values()));
  683. map.put("deptData", getDept().getData());
  684. map.put("empPosition", dao.getEmpPosition());
  685. map.put("empInmark", dao.getEmpInmark());
  686. map.put("zdIfcadre", dao.getZdIfcadre());
  687. map.put("zdEmpTitle", dao.getZdEmpTitle());
  688. map.put("mzyZdChargeType", dao.getMzyZdChargeType());
  689. List<IntCodeName> list = new ArrayList<IntCodeName>() {{
  690. add(new IntCodeName(1, "非限制"));
  691. add(new IntCodeName(2, "限制"));
  692. }};
  693. map.put("doctorYpZl", list);
  694. return ResultVoUtil.success(map);
  695. }
  696. public ResultVo<Boolean> idVerification(String idCard) {
  697. return ResultVoUtil.success(IdCardUtil.isValidatedIdCard(idCard));
  698. }
  699. public Integer getPersonnelCode() {
  700. dao.lockThePersonnelCodeTable();
  701. Integer code = dao.getPersonnelCode();
  702. dao.updateStaffCodeTable(code);
  703. return code;
  704. }
  705. public ResultVo<String> sendMessage(SendMessageParam param) {
  706. settingsDao.insertNewMessage(SnowFlakeId.instance().nextId(), param.getMessage());
  707. JSONObject obj = new JSONObject();
  708. obj.put("message", param.getMessage());
  709. if (null != param.getRefreshDelay()) {
  710. int delay = param.getRefreshDelay() * 1000;
  711. obj.put("refreshDelay", delay);
  712. }
  713. String msgContent = SocketMsg.socketVo(Message.SYSTEM_NOTIFICATION, obj);
  714. ApiMessageBody messageBody = new ApiMessageBody(msgContent);
  715. socketService.sendMessageToAll(messageBody);
  716. log.info("发送全体消息 => 操作员:{},消息体:{}", TokenUtil.getInstance().getTokenUserId(), obj);
  717. return ResultVoUtil.success();
  718. }
  719. public void sendSystemAnnouncement() {
  720. Map<String, String> map = redisLikeService.getMessage();
  721. JSONObject obj = new JSONObject();
  722. obj.put("data", map);
  723. String msgContent = SocketMsg.socketVo(Message.SYSTEM_ANNOUNCEMENT, obj);
  724. ApiMessageBody messageBody = new ApiMessageBody(msgContent);
  725. socketService.sendMessageToAll(messageBody);
  726. }
  727. /**
  728. * @description: 查询有住院的科室
  729. * @author: lihong
  730. * @date: 2022/12/26 16:58
  731. * @return: thyyxxk.webserver.entity.ResultVo<java.util.List < thyyxxk.webserver.entity.datamodify.GetDropdownBox>>
  732. **/
  733. public ResultVo<List<GetDropdownBox>> getZhuYuanDept() {
  734. return ResultVoUtil.success(dao.getZhuYuanDept());
  735. }
  736. @Async
  737. public void orderRecord(BigDecimal orderCode, String userCode) {
  738. if (orderCode == null) {
  739. return;
  740. }
  741. if (dao.selectRecordByOrderNo(orderCode) > 0) {
  742. return;
  743. }
  744. dao.insertOrderNoRecord(orderCode, userCode);
  745. }
  746. public ResultVo<UserInfo> getUserInfoByCode(String code) {
  747. return ResultVoUtil.success(redisLikeService.getUserInfoByCode(code));
  748. }
  749. public ZyPatientInfo getPatInfo(String patNo, Integer times) {
  750. ZyPatientInfo p = dao.queryPatientInfo(patNo, times, "zy_actpatient");
  751. if (p == null) {
  752. p = dao.queryPatientInfo(patNo, times, "zy_inactpatient");
  753. }
  754. return p;
  755. }
  756. public ResultVo<JSONObject> getUserConfigByCode(String code) {
  757. String config = dao.getUserConfigByCode(code);
  758. return ResultVoUtil.success(StringUtil.isBlank(config) ? new JSONObject() : JSONObject.parseObject(config));
  759. }
  760. public ResultVo<String> setUserConfigByCode(JSONObject config) {
  761. dao.setUserConfigByCode(TokenUtil.getInstance().getTokenUserId(), JSON.toJSONString(config));
  762. return ResultVoUtil.success();
  763. }
  764. public ResultVo<String> refreshUserInfo(String code) {
  765. redisLikeService.updateUserInfo(code);
  766. return ResultVoUtil.success();
  767. }
  768. public ResultVo<List<ItemDrug>> getItemDrug(String code) {
  769. return ResultVoUtil.success(dao.getItemDrug(StringUtil.isContainChinese(code)));
  770. }
  771. public Set<String> getUserDeptList(String code) {
  772. Set<String> deptList;
  773. UserInfo userInfo = redisLikeService.getUserInfoByCode(code);
  774. if (userInfo.getDeptCode().startsWith("8")) {
  775. deptList = dao.chaXunZhiZXinKeShi(userInfo.getDeptCode());
  776. deptList.add(userInfo.getDeptCode());
  777. } else {
  778. deptList = getDept(true, userInfo);
  779. }
  780. return deptList;
  781. }
  782. public Set<String> getUserDeptList() {
  783. return getUserDeptList(TokenUtil.getInstance().getTokenUserId());
  784. }
  785. public static <T> String listToSqlIn(Collection<T> collection) {
  786. if (collection == null || collection.isEmpty()) {
  787. return "('')";
  788. }
  789. Set<T> uniqueSet = new HashSet<>(collection);
  790. StringBuilder sb = new StringBuilder("(");
  791. for (T item : uniqueSet) {
  792. if (item instanceof String) {
  793. sb.append("'").append(item).append("',");
  794. } else {
  795. sb.append(item).append(",");
  796. }
  797. }
  798. sb.deleteCharAt(sb.length() - 1);
  799. sb.append(")");
  800. return sb.toString();
  801. }
  802. }