YiZhuLuRuServer.java 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  1. package thyyxxk.webserver.service.zhuyuanyisheng;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.core.metadata.IPage;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.apache.commons.collections4.ListUtils;
  9. import org.springframework.stereotype.Service;
  10. import org.springframework.transaction.annotation.Transactional;
  11. import thyyxxk.webserver.config.exception.BizException;
  12. import thyyxxk.webserver.config.exception.ExceptionEnum;
  13. import thyyxxk.webserver.constants.Capacity;
  14. import thyyxxk.webserver.constants.sidicts.ChargeStatus;
  15. import thyyxxk.webserver.dao.his.zhuyuanyisheng.YiZhuLuRuDao;
  16. import thyyxxk.webserver.entity.ResultVo;
  17. import thyyxxk.webserver.entity.RoleCode;
  18. import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
  19. import thyyxxk.webserver.entity.datamodify.YzActOrder;
  20. import thyyxxk.webserver.entity.inpatient.patient.Patient;
  21. import thyyxxk.webserver.entity.login.UserInfo;
  22. import thyyxxk.webserver.entity.zhuyuanyisheng.DoctorSOrderFee;
  23. import thyyxxk.webserver.entity.zhuyuanyisheng.ZyOrderZk;
  24. import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.*;
  25. import thyyxxk.webserver.service.PublicServer;
  26. import thyyxxk.webserver.service.redislike.RedisLikeService;
  27. import thyyxxk.webserver.utils.*;
  28. import java.math.BigDecimal;
  29. import java.util.*;
  30. import java.util.stream.Collectors;
  31. import java.util.stream.Stream;
  32. /**
  33. * <p>
  34. * 描述: 医嘱录入
  35. * </p>
  36. *
  37. * @author xc
  38. * @date 2022-01-04 16:59
  39. */
  40. @Service
  41. @Slf4j
  42. public class YiZhuLuRuServer {
  43. private final YiZhuLuRuDao dao;
  44. private final PublicServer publicServer;
  45. private final RedisLikeService redisLikeService;
  46. /**
  47. * 转科的医嘱编码
  48. */
  49. private final String ZK_CODE = "06286";
  50. private final String ONCE = "ONCE";
  51. private final String ITEM = "00";
  52. private final String SMALL_PACKAGE = "01";
  53. private final String BIG_PACKAGE = "99";
  54. public YiZhuLuRuServer(YiZhuLuRuDao dao, PublicServer publicServer, RedisLikeService redisLikeService) {
  55. this.dao = dao;
  56. this.publicServer = publicServer;
  57. this.redisLikeService = redisLikeService;
  58. }
  59. public ResultVo<String> getOrderNo() {
  60. return ResultVoUtil.success(BigDecimal.valueOf(publicServer.getActOrderNo()).stripTrailingZeros().toPlainString());
  61. }
  62. public ResultVo<List<Patient>> getMyPatient() {
  63. return ResultVoUtil.success(dao.getMyPatient(TokenUtil.getTokenUserId()));
  64. }
  65. /**
  66. * 获取医嘱的名称 这里为什么不用 医嘱的code和医嘱号呢,是因为药品编码和项目编码有些一样而医嘱号,又每次只能查询一个
  67. *
  68. * @param inpatientNo 住院号
  69. * @param admissTimes 住院次数
  70. * @param orderName 前端搜索的医嘱名称
  71. * @return 返回医嘱名称去重了
  72. */
  73. public ResultVo<List<GetDropdownBox>> huoQuYiZhuMingCheng(String inpatientNo, Integer admissTimes, String orderName) {
  74. return ResultVoUtil.success(dao.huoQuYiZhuMingZi(inpatientNo, admissTimes, StringUtil.isContainChinese(orderName)));
  75. }
  76. /**
  77. * 获取患者个人的频率
  78. *
  79. * @param patNo 住院号
  80. * @param times 住院次数
  81. * @return 返回自己的医嘱频率
  82. */
  83. public ResultVo<List<GetDropdownBox>> huoQuGeRenPinLv(String patNo, Integer times) {
  84. return ResultVoUtil.success(dao.huoQuGeRenPinLv(patNo, times));
  85. }
  86. /**
  87. * 获取医嘱的数据
  88. * 可以根据,医嘱时间区间,执行频率,医嘱名
  89. *
  90. * @param param 查询条件
  91. * @return 返回分页数据,同时做了树状图,这样会有一个问题,那就是开了套餐的数据查询不出来
  92. */
  93. public ResultVo<List<XinZhenYzActOrder>> huoQuYiZhuShuJu(YiZhuFeiYongChaXunTiaoJian param) {
  94. QueryWrapper<?> qw = new QueryWrapper<>();
  95. qw.eq("a.inpatient_no", param.getPatNo()).eq("a.admiss_times", param.getTimes());
  96. // qw.orderByDesc("a.act_order_no");
  97. qw.orderByAsc("a.order_time");
  98. List<XinZhenYzActOrder> yiZhuList = dao.huoQuYiZhuShuJu(qw);
  99. // 还有那些没有被匹配的子级医嘱
  100. Map<BigDecimal, XinZhenYzActOrder> wuFuJiYiZhu = yiZhuList.stream().collect(Collectors.toMap(XinZhenYzActOrder::getActOrderNo, a -> a, (k1, k2) -> k1));
  101. if (ListUtil.isBlank(yiZhuList)) {
  102. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
  103. }
  104. // 做成树状图
  105. Map<BigDecimal, XinZhenYzActOrder> map = new HashMap<>();
  106. List<XinZhenYzActOrder> tree = new ArrayList<>();
  107. for (XinZhenYzActOrder item : yiZhuList) {
  108. if (item.getParentNo() == null) {
  109. tree.add(item);
  110. wuFuJiYiZhu.remove(item.getActOrderNo());
  111. }
  112. map.put(item.getActOrderNo(), item);
  113. EntityStringTrim.beanAttributeValueTrim(item);
  114. if ("00".equals(item.getSerial())) {
  115. item.setGroupNoName("医技科室");
  116. item.setSerialName("项目");
  117. } else {
  118. if ("01".equals(item.getSerial())) {
  119. item.setSerialName("小包装");
  120. } else if ("99".equals(item.getSerial())) {
  121. item.setSerialName("大包装");
  122. }
  123. }
  124. }
  125. for (XinZhenYzActOrder item : yiZhuList) {
  126. XinZhenYzActOrder actOrder = map.get(item.getParentNo());
  127. if (actOrder != null) {
  128. wuFuJiYiZhu.remove(item.getActOrderNo());
  129. if (actOrder.getChildren() == null) {
  130. actOrder.setChildren(new ArrayList<>());
  131. actOrder.setOrderGroup("┌");
  132. }
  133. item.setOrderGroup("丨");
  134. actOrder.getChildren().add(item);
  135. }
  136. }
  137. if (!wuFuJiYiZhu.isEmpty()) {
  138. tree.addAll(wuFuJiYiZhu.values());
  139. }
  140. // 删除前后空格
  141. EntityStringTrim.beanAttributeValueTrimList(tree);
  142. List<XinZhenYzActOrder> list = new ArrayList<>();
  143. for (XinZhenYzActOrder zy : tree) {
  144. list.add(zy);
  145. if (ListUtil.notBlank(zy.getChildren())) {
  146. zy.getChildren().get(zy.getChildren().size() - 1).setOrderGroup("└");
  147. list.addAll(zy.getChildren());
  148. zy.setChildren(null);
  149. }
  150. }
  151. return ResultVoUtil.success(list);
  152. }
  153. /**
  154. * 获取搜索的项目信息,如药品和项目
  155. *
  156. * @param code 拼音首字母,中文,编码来进行搜索
  157. * @return 返回项目信息
  158. */
  159. public ResultVo<List<YiZhuMingChen>> huoQuXiangMu(String code) {
  160. code = StringUtil.isContainChinese(code);
  161. // 药品
  162. List<YiZhuMingChen> list = dao.yiZhuYaoPing(code, publicServer.getGroupNo());
  163. // 项目
  164. list.addAll(dao.yiZhuXiangMu(code));
  165. // 模板
  166. list.addAll(dao.composeOrders(code, TokenUtil.getTokenUserId()));
  167. EntityStringTrim.beanAttributeValueTrimList(list);
  168. return ResultVoUtil.success(list);
  169. }
  170. /**
  171. * 获取父医嘱
  172. *
  173. * @param patNo 住院号
  174. * @param times 次数
  175. * @return
  176. */
  177. public ResultVo<List<XinZhenYzActOrder>> getParentOrders(String patNo, String times) {
  178. return ResultVoUtil.success(dao.getParentOrders(patNo, times));
  179. }
  180. /**
  181. * 确认医嘱
  182. *
  183. * @param param
  184. * @return
  185. */
  186. public ResultVo<Map<String, Object>> confirmOrders(XinZhenYiZhu param) {
  187. QueryWrapper<?> qw = new QueryWrapper<>();
  188. qw.eq("a.inpatient_no", param.getInpatientNo()).eq("a.admiss_times", param.getAdmissTimes());
  189. qw.eq("a.status_flag", "1");
  190. qw.eq("a.enter_oper", TokenUtil.getTokenUserId());
  191. List<XinZhenYzActOrder> yiZhuList = dao.huoQuYiZhuShuJu(qw);
  192. if (ListUtil.isBlank(yiZhuList)) {
  193. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有需要确认的医嘱.");
  194. }
  195. Set<String> yaoPingCode = new HashSet<>();
  196. // 项目的 code
  197. Set<String> xiangMuCode = new HashSet<>();
  198. for (XinZhenYzActOrder item : yiZhuList) {
  199. if (ITEM.equals(item.getSerial())) {
  200. xiangMuCode.add(item.getOrderCode());
  201. } else {
  202. yaoPingCode.add(item.getOrderCode().trim() + item.getSerial().trim());
  203. }
  204. }
  205. String userCode = TokenUtil.getTokenUserId();
  206. // 获取医生开药品的权限
  207. Integer doctorLevel = dao.huoQuYiShenDengJi(userCode);
  208. XinZhenYiZhu huanZheXinXi = dao.huoQuHuanZheXinXi(param.getInpatientNo(), param.getAdmissTimes());
  209. Map<String, XinZhenYzActOrder> drug = getDrugInformation(yaoPingCode, huanZheXinXi.getSmallDept());
  210. Map<String, List<XinZhenYzActOrder>> project = getProjectInformation(xiangMuCode);
  211. // 是否可以确认
  212. boolean isThereAnyErrorMessage = false;
  213. Map<String, Object> map = new HashMap<>();
  214. List<BigDecimal> confirmOrderInformation = new ArrayList<>();
  215. for (XinZhenYzActOrder item : yiZhuList) {
  216. confirmOrderInformation.add(item.getActOrderNo());
  217. Map<String, Object> errorMessageMap = checkData(item, drug, project, huanZheXinXi, doctorLevel);
  218. if (!errorMessageMap.isEmpty()) {
  219. if (!isThereAnyErrorMessage && errorMessageMap.containsKey("error")) {
  220. isThereAnyErrorMessage = true;
  221. }
  222. map.put(item.getId(), errorMessageMap);
  223. errorMessageMap.put("data", item);
  224. }
  225. }
  226. if (isThereAnyErrorMessage) {
  227. return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请修改错误的医嘱", map);
  228. }
  229. dao.confirmOrders(confirmOrderInformation, TokenUtil.getTokenUserId(), param.getInpatientNo(), param.getAdmissTimes());
  230. log.info("确认的医嘱:{}", JSON.toJSONString(yiZhuList));
  231. return ResultVoUtil.success();
  232. }
  233. /**
  234. * 录入单条医嘱
  235. *
  236. * @param param 参数
  237. * @return 错误信息和提示
  238. */
  239. public ResultVo<Map<String, Object>> enterOrders(XinZhenYiZhu param) {
  240. XinZhenYzActOrder oldOrderNo = dao.getActOrderNoOne(param.getActOrderNo());
  241. if (oldOrderNo != null) {
  242. if (!"1".equals(oldOrderNo.getStatusFlag().trim())) {
  243. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该医嘱不是录入状态无法保存.");
  244. }
  245. if (!oldOrderNo.getInpatientNo().trim().equals(param.getInpatientNo())) {
  246. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "两次医嘱的.");
  247. }
  248. }
  249. String userCode = TokenUtil.getTokenUserId();
  250. // 获取医生开药品的权限
  251. Integer doctorLevel = dao.huoQuYiShenDengJi(userCode);
  252. XinZhenYiZhu huanZheXinXi = dao.huoQuHuanZheXinXi(param.getInpatientNo(), param.getAdmissTimes());
  253. XinZhenYzActOrder data = param.getData();
  254. // 设置 药房
  255. data.setGroupNo(publicServer.getGroupNo());
  256. // 药品的 code
  257. Set<String> yaoPingCode = new HashSet<>();
  258. // 项目的 code
  259. Set<String> xiangMuCode = new HashSet<>();
  260. if (ITEM.equals(data.getSerial())) {
  261. xiangMuCode.add(data.getOrderCode());
  262. } else {
  263. yaoPingCode.add(data.getOrderCode().trim() + data.getSerial().trim());
  264. }
  265. Map<String, XinZhenYzActOrder> drug = getDrugInformation(yaoPingCode, huanZheXinXi.getSmallDept());
  266. Map<String, List<XinZhenYzActOrder>> project = getProjectInformation(xiangMuCode);
  267. Map<String, Object> errorMessageMap = checkData(data, drug, project, huanZheXinXi, doctorLevel);
  268. if (data.getParentNo() != null) {
  269. XinZhenYzActOrder parentOrder = dao.getActOrderNoOne(data.getParentNo().stripTrailingZeros().toPlainString());
  270. if (parentOrder != null) {
  271. data.setFrequCode(parentOrder.getFrequCode());
  272. }
  273. }
  274. // 删除抗菌药物信息
  275. dao.deleteAntimicrobialInformation(param.getActOrderNo());
  276. // 先删除转科在插入
  277. dao.deleteTransferOrder(param.getActOrderNo());
  278. if (errorMessageMap.isEmpty()) {
  279. if (ZK_CODE.equals(data.getOrderCode())) {
  280. ZyOrderZk transferData = new ZyOrderZk();
  281. transferData
  282. .setActOrderNo(param.getActOrderNo())
  283. .setNewDept(data.getZkDeptCode())
  284. .setNewWard(data.getZkWardCode())
  285. .setOldWard(huanZheXinXi.getDeptCode())
  286. .setOldDept(huanZheXinXi.getSmallDept());
  287. dao.insertDoctorSOrder(transferData);
  288. }
  289. // 判断是不是抗菌药物
  290. XinZhenYzActOrder kssItem = drug.get(data.getOrderCode().trim() + data.getSerial().trim());
  291. if (kssItem != null && kssItem.getKjywFlag() != null && kssItem.getKjywFlag() == 1) {
  292. YzActRecordKss kss = new YzActRecordKss();
  293. kss.setActOrderNo(data.getActOrderNo());
  294. kss.setChargeCode(data.getOrderCode());
  295. kss.setYyfs(data.getYyfs());
  296. kss.setSsqk(data.getSsqk());
  297. kss.setYysj(data.getYysj());
  298. dao.insertAntimicrobialInformation(param.getActOrderNo(),
  299. kss, userCode, param.getInpatientNo(), param.getAdmissTimes());
  300. }
  301. }
  302. dao.deleteOrderNo(param.getActOrderNo(), param.getInpatientNo(), param.getAdmissTimes());
  303. dao.insertEntryOrder(huanZheXinXi, param.getData(), userCode);
  304. if (!errorMessageMap.isEmpty()) {
  305. Map<String, Object> map = new HashMap<>();
  306. errorMessageMap.put("data", data);
  307. map.put(param.getActOrderNo(), errorMessageMap);
  308. if (errorMessageMap.containsKey("error")) {
  309. return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请修改有错误的医嘱。", map);
  310. }
  311. }
  312. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "添加成功.");
  313. }
  314. /**
  315. * 插入医嘱模板中的数据到患者的医嘱表
  316. *
  317. * @param param 参数
  318. * @return
  319. */
  320. public ResultVo<String> insertTemplateOrder(XinZhenYiZhu param) {
  321. if (StringUtil.isBlank(param.getInpatientNo())) {
  322. return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请先选择患者.");
  323. }
  324. Map<String, XinZhenYzActOrder> fatherAndSonDoctorSAdvice = new HashMap<>(param.getList().size());
  325. param.getList().forEach(item -> {
  326. fatherAndSonDoctorSAdvice.put(item.getId(), item);
  327. item.setActOrderNo(BigDecimal.valueOf(publicServer.getActOrderNo()));
  328. });
  329. XinZhenYiZhu huanZheXinXi = dao.huoQuHuanZheXinXi(param.getInpatientNo(), param.getAdmissTimes());
  330. String userCode = TokenUtil.getTokenUserId();
  331. param.getList().forEach(item -> {
  332. String key = item.getParentNo() != null ? item.getParentNo().stripTrailingZeros().toPlainString() : "";
  333. if (StringUtil.notBlank(key)) {
  334. if (fatherAndSonDoctorSAdvice.containsKey(key)) {
  335. item.setParentNo(fatherAndSonDoctorSAdvice.get(key).getActOrderNo());
  336. }
  337. }
  338. dao.insertEntryOrder(huanZheXinXi, item, userCode);
  339. });
  340. return ResultVoUtil.success();
  341. }
  342. /**
  343. * 删除单条医嘱
  344. *
  345. * @param orderNo 医嘱号
  346. * @return 提示
  347. */
  348. public ResultVo<String> toDeleteAnOrder(String orderNo) {
  349. XinZhenYzActOrder oldData = dao.getActOrderNoOne(orderNo);
  350. String message = judgeWhetherItCanBeDeleted(oldData);
  351. if (StringUtil.notBlank(message)) {
  352. return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, message);
  353. }
  354. dao.toDeleteAnOrder(orderNo, oldData.getInpatientNo());
  355. dao.deleteGroup(orderNo);
  356. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  357. }
  358. /**
  359. * 删除多条录入的医嘱
  360. *
  361. * @param param 参数
  362. * @return 返回提示
  363. */
  364. public ResultVo<Map<BigDecimal, String>> deleteMultipleOrders(XinZhenYiZhu param) {
  365. QueryWrapper<?> qw = new QueryWrapper<>();
  366. qw.eq("inpatient_no", param.getInpatientNo());
  367. qw.eq("admiss_times", param.getAdmissTimes());
  368. List<BigDecimal> list = new ArrayList<>();
  369. param.getList().forEach(item -> {
  370. list.add(item.getActOrderNo());
  371. });
  372. qw.in("act_order_no", list);
  373. List<XinZhenYzActOrder> deleteOrderList = dao.getOrdersToDelete(qw);
  374. if (ListUtil.isBlank(deleteOrderList)) {
  375. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到原医嘱可能已经被删除了");
  376. }
  377. Map<BigDecimal, String> map = new HashMap<>();
  378. deleteOrderList.forEach(item -> {
  379. String error = judgeWhetherItCanBeDeleted(item);
  380. if (StringUtil.notBlank(error)) {
  381. map.put(item.getActOrderNo(), error);
  382. }
  383. });
  384. log.info("数据:{}", deleteOrderList);
  385. if (map.isEmpty()) {
  386. dao.deleteParentChildRelationship(param.getInpatientNo(), param.getAdmissTimes(), list);
  387. dao.deleteMultipleOrders(qw);
  388. return ResultVoUtil.fail(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  389. }
  390. return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "删除失败", map);
  391. }
  392. private String judgeWhetherItCanBeDeleted(XinZhenYzActOrder oldData) {
  393. StringBuilder str = new StringBuilder();
  394. if (oldData == null) {
  395. return "没有找到原医嘱可能已经被删除了";
  396. }
  397. if (!oldData.getStatusFlag().equals("1")) {
  398. str.append("该医嘱不是录入状态,无法删除");
  399. }
  400. if (!oldData.getEnterOper().equals(TokenUtil.getTokenUserId())) {
  401. str.append("该医嘱录入人不是您,无法删除.");
  402. }
  403. return str.toString();
  404. }
  405. /**
  406. * 获取某一个费用的详细信息
  407. *
  408. * @param code 编码
  409. * @param serial 00-项目 01-小包装的药品 99-大包装
  410. * @return 返回该费用的一些详细信息,以及一些提示信息。
  411. */
  412. public ResultVo<Map<String, Object>> huoQuFeiYongXinXi(String code, String serial, String deptCode) {
  413. Map<String, Object> map = new HashMap<>();
  414. // 一些提示
  415. List<String> prompt = new ArrayList<>();
  416. // 加载项目信息
  417. if (ITEM.equals(serial.trim())) {
  418. List<XinZhenYzActOrder> xiangMu = dao.huoQuXiangMu(code);
  419. for (XinZhenYzActOrder item : xiangMu) {
  420. if (item.getDelFlag() == 1) {
  421. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("该医嘱下的【%s】,已经被停用了,请联系物价科。", item.getOrderName()));
  422. } else if (StringUtil.isBlank(item.getNationalCode())) {
  423. prompt.add(String.format("该医嘱下面的【%s】,没有医保编码,请注意。", item.getOrderName()));
  424. } else {
  425. prompt.add(String.format("该医嘱下【%s】,医保码为:【%s】。", item.getOrderName(), item.getNationalCode()));
  426. }
  427. }
  428. if (ListUtil.isBlank(xiangMu)) {
  429. Integer paiChiYiZhu = dao.shiFouPaiChiYiZhu(code);
  430. switch (paiChiYiZhu) {
  431. case 1:
  432. prompt.add("全排斥医嘱");
  433. break;
  434. case 2:
  435. prompt.add("单组排斥医嘱");
  436. break;
  437. case 3:
  438. prompt.add("多组斥医嘱");
  439. break;
  440. default:
  441. break;
  442. }
  443. }
  444. } else {
  445. YaoPinXinXi yp = dao.huoQuYaoPin(code.trim() + serial.trim(), publicServer.getGroupNo());
  446. if (StringUtil.notBlank(deptCode)) {
  447. if (dao.restrictedUseInTheDepartment(code.trim(), deptCode) > 0) {
  448. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "该药品禁止在患者所在的科室使用。");
  449. }
  450. }
  451. if (yp == null) {
  452. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "该医嘱下的药品,可能已经被停用了,请联系药剂科。");
  453. }
  454. if (yp.getVisibleFlagZy() == 1) {
  455. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "该药品禁止住院使用。");
  456. }
  457. Integer yiShenDengJi = dao.huoQuYiShenDengJi(TokenUtil.getTokenUserId());
  458. int yiShen = yiShenDengJi == null ? 0 : yiShenDengJi;
  459. if (yp.getYpLevel() > yiShen) {
  460. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "您没有开此药品的权限。");
  461. }
  462. List<YaoPingJiLiang> yaoPingJiLiang = new ArrayList<>();
  463. if (StringUtil.notBlank(yp.getWeighUnit())) {
  464. yaoPingJiLiang.add(new YaoPingJiLiang(yp.getWeighUnit(), yp.getWeighUnitName(), yp.getWeight()));
  465. }
  466. if (StringUtil.notBlank(yp.getVolUnit())) {
  467. yaoPingJiLiang.add(new YaoPingJiLiang(yp.getVolUnit(), yp.getVolUnitName(), yp.getVolum()));
  468. }
  469. if (StringUtil.notBlank(yp.getPackUnit())) {
  470. yaoPingJiLiang.add(new YaoPingJiLiang(yp.getPackUnit(), yp.getPackUnitName(), yp.getPackSize()));
  471. }
  472. if (yp.getKjywFlag() == 1) {
  473. prompt.add("抗菌药物,需填写抗菌药物医嘱附注");
  474. }
  475. if (yp.getSelfFlagYb() == 1) {
  476. prompt.add("该药品医保自费药品,如符合条件请填写记账,不是请填写自费");
  477. }
  478. if (StringUtil.isBlank(yp.getNationalCode())) {
  479. prompt.add("该药品医保没有匹配医保码");
  480. } else {
  481. prompt.add(String.format("药品医保码为:【%s】", yp.getNationalCode()));
  482. }
  483. if (yp.getStockAmount() != null && BigUtils.bigXiaoYu(yp.getStockAmount(), 10)) {
  484. prompt.add(String.format("该药品剩余数量为:【%s】", yp.getStockAmount().stripTrailingZeros().toPlainString()));
  485. }
  486. if (yp.getPsFlag() == 1) {
  487. prompt.add("此药品为皮试药品");
  488. map.put("piShi", dao.piShiGeiYaoFangShi());
  489. }
  490. map.put("yaoPingJiLiang", yaoPingJiLiang);
  491. map.put("data", yp);
  492. }
  493. map.put("prompt", prompt);
  494. return ResultVoUtil.success(map);
  495. }
  496. /**
  497. * 获取频率
  498. *
  499. * @param code 五笔,拼音,中文,编码
  500. * @return 返回对应的数据
  501. */
  502. public ResultVo<List<GetDropdownBox>> huoQuZhuYuanPinLv(String code) {
  503. return ResultVoUtil.success(dao.huoQuZhuYuanPinLv(StringUtil.isContainChinese(code)));
  504. }
  505. /**
  506. * 获取给药方式
  507. *
  508. * @param code 五笔,拼音,中文,编码
  509. * @return 返回对应的数据
  510. */
  511. public ResultVo<List<GetDropdownBox>> huoQuGeiYaoFangShi(String code) {
  512. return ResultVoUtil.success(dao.huoQuGeiYaoFangShi(StringUtil.isContainChinese(code)));
  513. }
  514. /**
  515. * 获取执行科室
  516. *
  517. * @param code 五笔,拼音,中文,编码
  518. * @return 返回对应的数据
  519. */
  520. public ResultVo<List<GetDropdownBox>> huoQuZhiXinKeShi(String code) {
  521. return ResultVoUtil.success(dao.huoQuZhiXinKeShi(StringUtil.isContainChinese(code)));
  522. }
  523. public ResultVo<Map<String, Object>> singleDataCheck(XinZhenYiZhu param) {
  524. // 获取医生开药品的权限
  525. Integer 医生级别 = dao.huoQuYiShenDengJi(TokenUtil.getTokenUserId());
  526. Set<String> yaoPingCode = new HashSet<>();
  527. Set<String> xiangMuCode = new HashSet<>();
  528. for (XinZhenYzActOrder item : param.getList()) {
  529. if (ITEM.equals(item.getSerial().trim())) {
  530. xiangMuCode.add(item.getOrderCode().trim());
  531. } else {
  532. yaoPingCode.add(item.getOrderCode().trim() + item.getSerial().trim());
  533. }
  534. }
  535. XinZhenYiZhu huanZheXinXi = dao.huoQuHuanZheXinXi(param.getInpatientNo(), param.getAdmissTimes());
  536. Map<String, Object> errorMessage = checkData(param.getList().get(0), getDrugInformation(yaoPingCode, huanZheXinXi == null ? null : huanZheXinXi.getSmallDept()), getProjectInformation(xiangMuCode), huanZheXinXi, 医生级别);
  537. errorMessage.put("data", param.getList().get(0));
  538. return ResultVoUtil.success(errorMessage);
  539. }
  540. /**
  541. * 保存医嘱
  542. *
  543. * @param param 医嘱数据
  544. * @return 返回错误提示或者别的
  545. */
  546. public ResultVo<Map<String, Object>> saveTheDoctorSOrder(XinZhenYiZhu param) {
  547. log.info("上传数据:{}", JSON.toJSONStringWithDateFormat(param, DateUtil.DEFAULT_PATTERN));
  548. // 获取医生开药品的权限
  549. Integer doctorLevel = dao.huoQuYiShenDengJi(TokenUtil.getTokenUserId());
  550. // 药品的 code
  551. Set<String> yaoPingCode = new HashSet<>();
  552. // 项目的 code
  553. Set<String> xiangMuCode = new HashSet<>();
  554. // id 做 map
  555. Map<String, XinZhenYzActOrder> doctorSOrderMap = new HashMap<>(param.getList().size());
  556. for (XinZhenYzActOrder item : param.getList()) {
  557. if (ITEM.equals(item.getSerial().trim())) {
  558. xiangMuCode.add(item.getOrderCode().trim());
  559. } else {
  560. yaoPingCode.add(item.getOrderCode().trim() + item.getSerial().trim());
  561. }
  562. doctorSOrderMap.put(item.getId(), item);
  563. }
  564. // 医嘱 map {医嘱号: { 具体数据 }}
  565. // 获取患者信息
  566. XinZhenYiZhu huanZheXinXi = dao.huoQuHuanZheXinXi(param.getInpatientNo(), param.getAdmissTimes());
  567. if (huanZheXinXi == null) {
  568. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "没有查询到患者的在院信息。");
  569. }
  570. // 设置婴儿标志
  571. huanZheXinXi.setInfantFlag(PublicServer.getInfantFlag(huanZheXinXi.getInpatientNo()));
  572. boolean isThereAnyErrorMessage = false;
  573. Map<String, Object> map = new HashMap<>();
  574. Map<String, XinZhenYzActOrder> drug = getDrugInformation(yaoPingCode, huanZheXinXi.getSmallDept());
  575. Map<String, List<XinZhenYzActOrder>> project = getProjectInformation(xiangMuCode);
  576. int index = 0;
  577. for (XinZhenYzActOrder item : param.getList()) {
  578. Map<String, Object> errorMessageMap = checkData(item, drug, project, huanZheXinXi, doctorLevel);
  579. if (!errorMessageMap.isEmpty()) {
  580. if (!isThereAnyErrorMessage && errorMessageMap.containsKey("error")) {
  581. isThereAnyErrorMessage = true;
  582. }
  583. map.put(item.getId(), errorMessageMap);
  584. }
  585. errorMessageMap.put("data", item);
  586. errorMessageMap.put("index", index++);
  587. }
  588. if (isThereAnyErrorMessage) {
  589. return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请修改错误的医嘱", map);
  590. }
  591. /* 在这里上传医嘱,一点错误信息都没了的话 */
  592. // 这个是 抗菌药物的信息
  593. List<YzActRecordKss> kssList = new ArrayList<>();
  594. // 这个是 转科医嘱的
  595. ZyOrderZk transferData = null;
  596. for (XinZhenYzActOrder item : param.getList()) {
  597. // 生成医嘱号
  598. item.setActOrderNo(BigDecimal.valueOf(publicServer.getActOrderNo()));
  599. if (item.getParentNo() != null && doctorSOrderMap.containsKey(item.getParentNo().stripTrailingZeros().toPlainString())) {
  600. item.setParentNo(doctorSOrderMap.get(item.getParentNo().stripTrailingZeros().toPlainString()).getActOrderNo());
  601. }
  602. if (item.getKjywFlag() != null && item.getKjywFlag() == 1) {
  603. YzActRecordKss kss = new YzActRecordKss();
  604. kss.setActOrderNo(item.getActOrderNo());
  605. kss.setChargeCode(item.getOrderCode());
  606. kss.setYyfs(item.getYyfs());
  607. kss.setSsqk(item.getSsqk());
  608. kss.setYysj(item.getYysj());
  609. kssList.add(kss);
  610. }
  611. if (ZK_CODE.equals(item.getOrderCode())) {
  612. transferData = new ZyOrderZk();
  613. transferData.setActOrderNo(item.getActOrderNo().stripTrailingZeros().toPlainString()).setNewDept(item.getZkDeptCode()).setNewWard(item.getZkWardCode());
  614. }
  615. }
  616. // 执行人
  617. String inputCode = TokenUtil.getTokenUserId();
  618. // 判断患者是否结算了
  619. publicServer.huanZheJieSuan(param.getInpatientNo(), param.getAdmissTimes());
  620. if (ListUtil.notBlank(kssList)) {
  621. dao.shanChuYuanKuangJunYaoWu(kssList);
  622. dao.chaRuKuangJunYaoWuXinXi(huanZheXinXi.getInpatientNo(), huanZheXinXi.getAdmissTimes(), inputCode, kssList);
  623. }
  624. if (transferData != null) {
  625. transferData.setOldWard(huanZheXinXi.getDeptCode()).setOldDept(huanZheXinXi.getSmallDept());
  626. dao.insertDoctorSOrder(transferData);
  627. }
  628. String groupNo = publicServer.getGroupNo();
  629. sendAMessageToTheNurse(param, inputCode, huanZheXinXi, groupNo);
  630. // dao.chaRuYiZhu(huanZheXinXi.getInpatientNo(), huanZheXinXi.getAdmissTimes(), inputCode, huanZheXinXi.getInfantFlag(), huanZheXinXi.getDeptCode(), huanZheXinXi.getDeptCode(), huanZheXinXi.getReferPhysician(), param.getList());
  631. return ResultVoUtil.success(map);
  632. }
  633. public ResultVo<String> doesTheTemplateExist(String name) {
  634. if (dao.duplicateTemplateName(name, TokenUtil.getTokenUserId()) == 0) {
  635. return ResultVoUtil.success();
  636. }
  637. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "模板名称重复");
  638. }
  639. public ResultVo<String> saveTemplate(YzOrderPattern param) {
  640. // 如果名字重复了,那么就修改原来的模板
  641. YzOrderPattern yzOrderPattern = dao.yuanLaiDeMuBanBianMa(param.getPatternName(), TokenUtil.getTokenUserId());
  642. UserInfo userInfo = redisLikeService.getUserInfoByCode(TokenUtil.getTokenUserId());
  643. List<Integer> role = userInfo.getRoles();
  644. if ("1".equals(param.getInputType()) && publicServer.noNeedRule(role, 38)) {
  645. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有权限创建科室模板。");
  646. } else if ("2".equals(param.getInputType()) && publicServer.noNeedRule(role, 38, 11)) {
  647. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有权限创建科室模板。");
  648. }
  649. if (null == yzOrderPattern) {
  650. yzOrderPattern = new YzOrderPattern();
  651. }
  652. String patternCode = yzOrderPattern.getPatternCode();
  653. // 有原来的模板名称而且 还要是自己创建的才能删除,否则就只能创建新的模板了
  654. if (StringUtil.notBlank(patternCode) && userInfo.getCode().equals(yzOrderPattern.getInputId())) {
  655. // 更新的时候先删除模板 原来的模板
  656. dao.shanChuLaoMuBan(patternCode);
  657. param.setPatternCode(patternCode);
  658. } else {
  659. // 设置新的模板号
  660. param.setPatternCode(publicServer.getPatternCode());
  661. }
  662. String py = PingYinUtils.pyShouZiMuDaXie(param.getPatternName());
  663. String wb = PingYinUtils.getWBCode(param.getPatternName());
  664. param.setPyCode(py.length() > 9 ? py.substring(0, 9) : py);
  665. param.setDCode(wb.length() > 9 ? wb.substring(0, 9) : wb);
  666. param.setInputId(TokenUtil.getTokenUserId());
  667. param.setDeptCode(userInfo.getDeptCode());
  668. dao.chaRuMuBan(param);
  669. Map<String, XinZhenYzActOrder> map = param.getList().stream().collect(Collectors.toMap(XinZhenYzActOrder::getId, a -> a, (k1, k2) -> k1));
  670. for (XinZhenYzActOrder item : param.getList()) {
  671. // 设置模板号
  672. item.setActOrderNo(BigDecimal.valueOf(publicServer.getPatternOrderCode()));
  673. if (item.getParentNo() != null && map.containsKey(item.getParentNo().stripTrailingZeros().toPlainString())) {
  674. item.setParentNo(map.get(item.getParentNo().stripTrailingZeros().toPlainString()).getActOrderNo());
  675. }
  676. }
  677. dao.chaRuMuBanShuJu(param.getList(), param.getPatternCode());
  678. return ResultVoUtil.success();
  679. }
  680. private void calculateDrugAmount(XinZhenYzActOrder item, XinZhenYzActOrder feiYongXinXi, List<String> 错误信息) {
  681. if (feiYongXinXi == null) {
  682. return;
  683. }
  684. if (StringUtil.notBlank(feiYongXinXi.getDrugWeightUnit()) && item.getDoseUnit().trim().equals(feiYongXinXi.getDrugWeightUnit().trim())) {
  685. item.setDrugOcc(DecimalUtil.divide(item.getDose(), feiYongXinXi.getDrugWeight(), 2));
  686. } else if (StringUtil.notBlank(feiYongXinXi.getDrugVolUnit()) && item.getDoseUnit().trim().equals(feiYongXinXi.getDrugVolUnit())) {
  687. item.setDrugOcc(DecimalUtil.divide(item.getDose(), feiYongXinXi.getDrugVolume(), 2));
  688. } else if (StringUtil.notBlank(feiYongXinXi.getPackUnit()) && item.getDoseUnit().trim().equals(feiYongXinXi.getPackUnit())) {
  689. if (new BigDecimal(item.getDose().intValue()).compareTo(item.getDose()) != 0) {
  690. 错误信息.add("已经是最小单位了请不要带小数点");
  691. }
  692. item.setDrugOcc(DecimalUtil.divide(item.getDose(), feiYongXinXi.getPackSize(), 2));
  693. }
  694. }
  695. private Map<String, Object> checkData(XinZhenYzActOrder item, Map<String, XinZhenYzActOrder> drug, Map<String, List<XinZhenYzActOrder>> project, XinZhenYiZhu huanZheXinXi, Integer 医生级别) {
  696. Boolean 严格校验 = huanZheXinXi != null;
  697. List<String> 错误信息 = new ArrayList<>();
  698. List<String> 警告信息 = new ArrayList<>();
  699. if (ITEM.equals(item.getSerial())) {
  700. List<XinZhenYzActOrder> 项目明细 = project.get(item.getOrderCode());
  701. // 如果这个项目下面没有费用明细,那么这就是一条口头医,口头医嘱每次只能开一个
  702. if (ListUtil.isBlank(项目明细)) {
  703. item.setDrugQuan(BigDecimal.valueOf(1));
  704. item.setDrugOcc(BigDecimal.valueOf(1));
  705. } else {
  706. for (XinZhenYzActOrder 明细 : 项目明细) {
  707. if (明细.getDelFlag() == 1) {
  708. 错误信息.add(String.format("项目:【%s】,已经被物价停用了", 明细.getOrderName()));
  709. }
  710. if (StringUtil.isBlank(明细.getNationalCode())) {
  711. 警告信息.add(String.format("项目:【%s】,没有匹配医保码", 明细.getOrderName()));
  712. }
  713. }
  714. }
  715. } else {
  716. XinZhenYzActOrder feiYongXinXi = drug.get(item.getOrderCode().trim() + item.getSerial().trim());
  717. if (feiYongXinXi != null) {
  718. if (feiYongXinXi.getDelFlag() == 1) {
  719. 错误信息.add("药品已经被停用了,请联系药剂科");
  720. }
  721. if (feiYongXinXi.getYpLevel() > 医生级别) {
  722. 错误信息.add("您没有开此药品的权限");
  723. }
  724. if (StringUtil.isBlank(feiYongXinXi.getNationalCode())) {
  725. 警告信息.add("该药品没有医保编码");
  726. }
  727. if (feiYongXinXi.getStockAmount() != null && BigUtils.bigXiaoYu(feiYongXinXi.getStockAmount(), 10)) {
  728. 警告信息.add(String.format("该药品剩余数量为:【%s】", feiYongXinXi.getStockAmount().stripTrailingZeros().toPlainString()));
  729. }
  730. if (严格校验) {
  731. if (feiYongXinXi.getDeptRestrictions() > 0) {
  732. 错误信息.add("该药品禁止在患者所在的科室使用。");
  733. }
  734. if (feiYongXinXi.getVisibleFlagZy() == 1) {
  735. 错误信息.add("该药品禁止住院患者使用。");
  736. }
  737. item.setKjywFlag(feiYongXinXi.getKjywFlag());
  738. if (feiYongXinXi.getKjywFlag() == 1) {
  739. if (item.getYyfs() == null) {
  740. 错误信息.add("请填写抗菌药物医嘱附注信息录入");
  741. } else if (item.getYyfs() == 1 || item.getYyfs() == 2) {
  742. if (item.getSsqk() == null || item.getYyfs() == null) {
  743. 错误信息.add("当用药方式为 1 或 2 时,手术切口和用药时间不能为空");
  744. }
  745. }
  746. }
  747. }
  748. // 计算费用金额
  749. calculateDrugAmount(item, feiYongXinXi, 错误信息);
  750. }
  751. }
  752. if (StringUtil.isBlank(item.getOrderCode())) {
  753. 错误信息.add("项目编码不能为空");
  754. }
  755. if (StringUtil.isBlank(item.getOrderName())) {
  756. 错误信息.add("项目名称不能为空");
  757. }
  758. if (StringUtil.isBlank(item.getExecUnit())) {
  759. 错误信息.add("执行科室不能为空");
  760. } else if (item.getExecUnit().startsWith("8")) {
  761. 错误信息.add("执行科室不能选择为病区");
  762. }
  763. if (ZK_CODE.equals(item.getOrderCode())) {
  764. if (StringUtil.isBlank(item.getZkWardCode())) {
  765. 错误信息.add("转科病房不能为空");
  766. }
  767. if (StringUtil.isBlank(item.getZkDeptCode())) {
  768. 错误信息.add("转科科室不能为空");
  769. }
  770. }
  771. if (StringUtil.isBlank(item.getFrequCode())) {
  772. 错误信息.add("频次不能为空");
  773. }
  774. // 药品的校验
  775. if (!ITEM.equals(item.getSerial().trim())) {
  776. if (StringUtil.isBlank(item.getDrugSpecification())) {
  777. 错误信息.add("药品规格不能为空");
  778. }
  779. if (StringUtil.isBlank(item.getSupplyCode())) {
  780. 错误信息.add("给药方式不能为空");
  781. }
  782. if (item.getDose() == null || BigUtils.dengYu(item.getDose(), 0)) {
  783. 错误信息.add("一次计量不能为空");
  784. }
  785. if (StringUtil.isBlank(item.getDoseUnit())) {
  786. 错误信息.add("计量单位不能为空");
  787. }
  788. if (StringUtil.isBlank(item.getSerial())) {
  789. 错误信息.add("包装大小不能为空");
  790. }
  791. }
  792. if (严格校验) {
  793. // 获取患者的入院时间
  794. if (item.getOrderTime() == null) {
  795. 错误信息.add("医嘱时间不能为空");
  796. } else if (item.getStartTime() == null) {
  797. 错误信息.add("开始时间不能为空");
  798. } else if (huanZheXinXi.getAdmissDate() == null) {
  799. 错误信息.add("没有查询到患者的入院时间");
  800. } else if (DateUtil.shiJianDaXiao(item.getStartTime(), huanZheXinXi.getAdmissDate(), "<")) {
  801. 错误信息.add("开始时间不能在患者入院之前,患者入院时间" + DateUtil.formatDatetime(huanZheXinXi.getAdmissDate()));
  802. } else if (DateUtil.shiJianDaXiao(item.getStartTime(), item.getOrderTime(), "<")) {
  803. 错误信息.add("开始时间不能在开医嘱之前");
  804. }
  805. if (item.getEndTime() != null) {
  806. if (ONCE.equals(item.getFrequCode().trim())) {
  807. item.setEndTime(null);
  808. } else {
  809. if (DateUtil.shiJianDaXiao(item.getEndTime(), item.getStartTime(), "<")) {
  810. 错误信息.add("结束时间不能在开始时间之前");
  811. }
  812. }
  813. }
  814. }
  815. Map<String, Object> map = new HashMap<>(Capacity.TWO);
  816. if (ListUtil.notBlank(错误信息)) {
  817. map.put("error", 错误信息);
  818. }
  819. if (ListUtil.notBlank(警告信息)) {
  820. map.put("warning", 警告信息);
  821. }
  822. return map;
  823. }
  824. /***
  825. * 获取项目信息
  826. * @param xiangMuCode 项目编码
  827. * @return 返回数据
  828. */
  829. private Map<String, List<XinZhenYzActOrder>> getProjectInformation(Set<String> xiangMuCode) {
  830. if (!xiangMuCode.isEmpty()) {
  831. return dao.huoQuXiangMuXinXi(xiangMuCode).stream().collect(Collectors.groupingBy(item -> item.getOrderCode().trim()));
  832. }
  833. return new HashMap<>(0);
  834. }
  835. /**
  836. * 获取药品信息
  837. *
  838. * @param yaoPingCode 药品编码
  839. * @return 返回数据
  840. */
  841. private Map<String, XinZhenYzActOrder> getDrugInformation(Set<String> yaoPingCode, String dept) {
  842. if (!yaoPingCode.isEmpty()) {
  843. return dao.huoQuYaoPinXinXi(yaoPingCode, publicServer.getGroupNo(), dept).stream().collect(Collectors.toMap(item -> item.getOrderCode().trim() + item.getSerial().trim(), a -> a, (k1, k2) -> k1));
  844. }
  845. return new HashMap<>(0);
  846. }
  847. private void sendAMessageToTheNurse(XinZhenYiZhu param, String inputCode, XinZhenYiZhu huanZheXinXi, String groupNo) {
  848. List<String> content = new ArrayList<>();
  849. for (XinZhenYzActOrder item : param.getList()) {
  850. if (StringUtil.isBlank(item.getDrugFlag())) {
  851. item.setDrugFlag("o");
  852. }
  853. if ("00".equals(item.getSerial().trim())) {
  854. item.setGroupNo("00");
  855. } else if ("01".equals(item.getSerial().trim()) || "99".equals(item.getSerial().trim())) {
  856. item.setGroupNo(groupNo);
  857. }
  858. if (item.getEndTime() != null) {
  859. item.setModifier(inputCode);
  860. }
  861. content.add(String.format("医嘱名:<span style='color:#409eff'>【%s】</span><br>" + "医嘱时间:<span style='color:#409eff'>【%tF %<tT】</span><br>" + "患者姓名:<span style='color:#409eff'>【%s】</span><br>" + "床位:<span style='color:#409eff'>【%s】</span><br>" + "频次:<span style='color:#409eff'>【%s】</span>", item.getOrderName(), item.getOrderTime(), huanZheXinXi.getName(), huanZheXinXi.getBedNo(), item.getFrequCode()));
  862. }
  863. publicServer.faSongXiaoXi(huanZheXinXi, content, "新增医嘱", inputCode);
  864. }
  865. /**
  866. * 获取医嘱录入的模板1
  867. *
  868. * @param code 模板编码
  869. * @param deptCode 科室编码
  870. * @param muBanLeiXing 项目类型
  871. * @param currentPage 当前页
  872. * @param total 总数
  873. * @return 返回模板
  874. */
  875. public ResultVo<IPage<YzOrderPattern>> huoQuYiZhuMuBan(String code, String deptCode, Integer muBanLeiXing, long currentPage, long total) {
  876. IPage<YzOrderPattern> page = new Page<>();
  877. if (total == 0) {
  878. page.setTotal(dao.huoQuMuBanTotal(StringUtil.isContainChinese(code), TokenUtil.getTokenUserId(), deptCode, muBanLeiXing));
  879. }
  880. page.setRecords(dao.huoQuMuBan(StringUtil.isContainChinese(code), TokenUtil.getTokenUserId(), deptCode, muBanLeiXing, currentPage));
  881. return ResultVoUtil.success(page);
  882. }
  883. /**
  884. * 获取 我的医嘱模板的最大医嘱码
  885. *
  886. * @return 最大排序码
  887. */
  888. public ResultVo<Integer> getDoctorSOrderTemplateMaxSortNo() {
  889. Integer sortCode = dao.getMyTemplateMaxSortNo(TokenUtil.getTokenUserId());
  890. return ResultVoUtil.success(sortCode == null ? 0 : sortCode);
  891. }
  892. private String getActOrderNo() {
  893. Random random = new Random();
  894. String a = String.valueOf(random.nextInt(5) + 1);
  895. String b = String.valueOf(random.nextInt(99999));
  896. return a + b;
  897. }
  898. /**
  899. * 获取模板数据
  900. *
  901. * @param code 模板的编码
  902. * @return 返回数据
  903. */
  904. public ResultVo<List<YzActOrder>> huoQuMuBanShuJu(String code) {
  905. List<YzActOrder> muBanShuJu = dao.huoQuMuBanShuJu(code);
  906. Map<BigDecimal, YzActOrder> map = new HashMap<>(muBanShuJu.size());
  907. List<YzActOrder> tree = new ArrayList<>();
  908. for (YzActOrder item : muBanShuJu) {
  909. item.setId(getActOrderNo());
  910. if (item.getParentNo() == null) {
  911. tree.add(item);
  912. }
  913. map.put(item.getActOrderNo(), item);
  914. }
  915. for (YzActOrder item : muBanShuJu) {
  916. YzActOrder yzActOrder = map.get(item.getParentNo());
  917. if (yzActOrder != null) {
  918. item.setParentNo(new BigDecimal(yzActOrder.getId()));
  919. item.setIsChildren(true);
  920. if (yzActOrder.getChildren() == null) {
  921. yzActOrder.setChildren(new ArrayList<>());
  922. }
  923. yzActOrder.getChildren().add(item);
  924. // 没有副医嘱的就返回到最上层
  925. } else if (!tree.contains(item)) {
  926. item.setParentNo(null);
  927. tree.add(item);
  928. }
  929. }
  930. return ResultVoUtil.success(tree);
  931. }
  932. /**
  933. * 删除医嘱模板
  934. *
  935. * @param patternCode 模板的编码
  936. * @return 提示
  937. */
  938. public ResultVo<String> deleteADoctorSOrderTemplate(String patternCode) {
  939. if (StringUtil.isBlank(patternCode)) {
  940. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "模板编号为空。");
  941. }
  942. YzOrderPattern yzOrderPattern = dao.huoQuMuBanXinXi(patternCode);
  943. EntityStringTrim.beanAttributeValueTrim(yzOrderPattern);
  944. if (yzOrderPattern == null) {
  945. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到对应的模板信息。");
  946. }
  947. String userId = TokenUtil.getTokenUserId();
  948. List<Integer> role = publicServer.getRoleCode().getData();
  949. if (publicServer.needRule(role, RoleCode.PHYSICIAN_S_ORDER_TEMPLATEEDIT)) {
  950. return startDeletingTemplates(patternCode);
  951. }
  952. if (userId.equals(yzOrderPattern.getInputId())) {
  953. return startDeletingTemplates(patternCode);
  954. }
  955. // 主任可以删除本科室的任意模板
  956. if (publicServer.needRule(role, RoleCode.DIRECTOR) && dao.userDeptCode(userId).equals(yzOrderPattern.getDeptCode())) {
  957. return startDeletingTemplates(patternCode);
  958. }
  959. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有权限删除这个模板。");
  960. }
  961. /**
  962. * 删除父模板以及下面的子模板 数据
  963. *
  964. * @param patternCode 模板编码
  965. */
  966. private ResultVo<String> startDeletingTemplates(String patternCode) {
  967. dao.shanChuMuBan(patternCode);
  968. log.info("删除医嘱模板==> 操作人:{},模板编码:{}", TokenUtil.getTokenUserId(), patternCode);
  969. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "删除成功。");
  970. }
  971. /**
  972. * 收藏医嘱模板或者取消收藏
  973. * 如果以及收藏了就删除,没有就收藏
  974. *
  975. * @param patternCode 模板号
  976. * @return 提示
  977. */
  978. public ResultVo<String> collectDoctorSOrderTemplate(String patternCode) {
  979. String userId = TokenUtil.getTokenUserId();
  980. String saveTheDoctorSOrderNumber = dao.whetherToSaveTheDoctorSOrderTemplate(patternCode, userId);
  981. if (StringUtil.notBlank(saveTheDoctorSOrderNumber)) {
  982. dao.shanChuMuBan(saveTheDoctorSOrderNumber);
  983. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "已取消删除。");
  984. } else {
  985. YzOrderPattern yzOrderPattern = dao.huoQuMuBanXinXi(patternCode);
  986. EntityStringTrim.beanAttributeValueTrim(yzOrderPattern);
  987. dao.chaRuShouCang(publicServer.getPatternCode(), yzOrderPattern.getPatternName() + "(收藏)", yzOrderPattern.getPyCode(), yzOrderPattern.getDCode(), dao.userDeptCode(userId), userId, yzOrderPattern.getPatternCode());
  988. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "收藏成功。");
  989. }
  990. }
  991. /**
  992. * 删除或修改模板
  993. *
  994. * @param patternCode 模板点吗
  995. * @param patternName 模板名称
  996. * @param sortNo 排序号
  997. * @param flag 标志 1-修改 2- 删除 3-收藏和取消收藏
  998. * @return 返回给前端提示
  999. */
  1000. public ResultVo<String> muBanCaoZuo(String patternCode, String patternName, String deptCode, Integer sortNo, Integer flag) {
  1001. if (StringUtil.isBlank(patternCode)) {
  1002. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "模板编码为空。");
  1003. }
  1004. YzOrderPattern yzOrderPattern = dao.huoQuMuBanXinXi(patternCode);
  1005. if (yzOrderPattern == null) {
  1006. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到对应的模板信息。");
  1007. }
  1008. EntityStringTrim.beanAttributeValueTrim(yzOrderPattern);
  1009. String inputId = TokenUtil.getTokenUserId();
  1010. List<Integer> role = publicServer.getRoleCode().getData();
  1011. // 管理员 和 医务部的无视 规则
  1012. if (!role.contains(1) && !role.contains(38) && flag != 3) {
  1013. // 只有模板在不等于 自己的时候触发
  1014. if (!inputId.equals(yzOrderPattern.getInputId())) {
  1015. if ("2".equals(yzOrderPattern.getInputType()) && !role.contains(11)) {
  1016. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该模板为科室模板您没有权限修改或删除,请联系科主任进行修改。");
  1017. } else if ("1".equals(yzOrderPattern.getInputType())) {
  1018. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该模板为全院模板,无法删除或修改。");
  1019. }
  1020. }
  1021. }
  1022. if (flag == 1) {
  1023. if (StringUtil.isBlank(patternName)) {
  1024. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "模板名称不能为空。");
  1025. }
  1026. if (patternName.trim().equals(yzOrderPattern.getPatternName().trim()) && sortNo.equals(yzOrderPattern.getSortNo())) {
  1027. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "数据没有变化,请勿点击。");
  1028. }
  1029. dao.genXingMuBan(patternName.trim(), PingYinUtils.pyShouZiMuDaXie(patternName), PingYinUtils.getWBCode(patternName), yzOrderPattern.getPatternCode(), sortNo);
  1030. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "修改成功。");
  1031. } else if (flag == 2) {
  1032. // 删除父模板以及下面的子模板 数据
  1033. dao.shanChuMuBan(yzOrderPattern.getPatternCode());
  1034. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "删除成功。");
  1035. } else if (flag == 3) {
  1036. // 收藏模板
  1037. String collectCode = dao.chongFuShouCang(inputId, patternCode);
  1038. if (collectCode == null) {
  1039. dao.chaRuShouCang(publicServer.getPatternCode(), yzOrderPattern.getPatternName() + "(收藏)", yzOrderPattern.getPyCode(), yzOrderPattern.getDCode(), deptCode, inputId, yzOrderPattern.getPatternCode());
  1040. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "收藏成功。");
  1041. } else {
  1042. dao.shanChuMuBan(yzOrderPattern.getPatternCode());
  1043. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "已取消收藏。");
  1044. }
  1045. }
  1046. return ResultVoUtil.success();
  1047. }
  1048. /**
  1049. * 医嘱操作
  1050. *
  1051. * @param actOrderNo 医嘱号
  1052. * @param flag 标志 1-设为紧急 2-撤销 3-停止
  1053. * @return 返回提示
  1054. */
  1055. @Transactional(rollbackFor = Exception.class)
  1056. public ResultVo<String> yiZhuChaoZuo(BigDecimal actOrderNo, Integer flag, String content) {
  1057. YzActOrder yz = dao.chaXunYiZhuXinXin(actOrderNo);
  1058. if (yz == null) {
  1059. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有查询到该医嘱可能已经被撤销了");
  1060. }
  1061. switch (flag) {
  1062. case 1:
  1063. return sheZhiJinJi(yz);
  1064. case 2:
  1065. return ceXiaoYiZhu(yz, content);
  1066. case 3:
  1067. return tingZhiShiJian(yz, content);
  1068. default:
  1069. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "你想干什么?");
  1070. }
  1071. }
  1072. public ResultVo<String> sheZhiJinJi(YzActOrder yz) {
  1073. String emergencyFlag = null;
  1074. if (yz.getEmergencyFlag() == null || !"1".equals(yz.getEmergencyFlag().trim())) {
  1075. emergencyFlag = "1";
  1076. }
  1077. dao.sheZhiJinJi(yz.getActOrderNo(), emergencyFlag);
  1078. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  1079. }
  1080. private ResultVo<String> ceXiaoYiZhu(YzActOrder param, String content) {
  1081. if (StringUtil.isBlank(content)) {
  1082. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请填写撤销原因。");
  1083. }
  1084. YzActOrder yz = dao.chaXunYiZhuXinXin(param.getActOrderNo());
  1085. if (yz == null) {
  1086. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到对应医嘱的信息。");
  1087. }
  1088. String userCode = TokenUtil.getTokenUserId();
  1089. if (publicServer.noNeedRule(38)) {
  1090. if (!yz.getPhysician().trim().equals(userCode)) {
  1091. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "不是本人开的医嘱无权撤销。");
  1092. }
  1093. if (DateUtil.shiJianDaXiao(new Date(), DateUtil.addDateMinut(yz.getStartTime(), 24), ">")) {
  1094. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "已经超过24个小时了,无法撤销。");
  1095. }
  1096. }
  1097. if (!"2".equals(yz.getStatusFlag().trim())) {
  1098. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该医嘱无法被撤销。");
  1099. }
  1100. // 获取该医嘱下面的项目有没有被执行了,如果被执行了的话就不能撤销了。
  1101. publicServer.huoQuGaiYiZhuXiaXiangMu(yz.getActOrderNo());
  1102. // 插入撤销的原因
  1103. dao.chaRuCheXiaoYuanYin(yz.getActOrderNo(), yz.getInpatientNo(), yz.getAdmissTimes(), content, yz.getOrderCode());
  1104. // 删除费用 删除药品的药单 删除医嘱表 删除医技
  1105. dao.cheXiaoYiZhu(yz.getActOrderNo());
  1106. // 把原来的医嘱插入到 yz_erase_order 这个表
  1107. dao.chaRuShanChuBiao(yz.getActOrderNo());
  1108. // 更新原来的状态
  1109. dao.genXingShanChuBiaoZhi(userCode, yz.getActOrderNo());
  1110. log.info("删除医嘱==》数据:{},操作人:{}", JSON.toJSONString(yz), userCode);
  1111. publicServer.faSongXiaoXi(dao.huoQuHuanZheXinXi(yz.getInpatientNo(), yz.getAdmissTimes()), Stream.of(String.format("医嘱名:【%s】,<br>" + "医嘱号:【%s】,<br>" + "撤销原因【%s】", yz.getOrderName(), yz.getActOrderNo().toString(), content)).collect(Collectors.toList()), "撤销医嘱", TokenUtil.getTokenUserId());
  1112. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "医嘱撤销成功。");
  1113. }
  1114. private ResultVo<String> tingZhiShiJian(YzActOrder yz, String content) {
  1115. String userCode = TokenUtil.getTokenUserId();
  1116. if (StringUtil.isBlank(content)) {
  1117. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请选择停止时间。");
  1118. }
  1119. String LOGICAL_ERROR = tingZhiYiZhuJiaoYan(yz, content);
  1120. if (LOGICAL_ERROR != null) {
  1121. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, LOGICAL_ERROR);
  1122. }
  1123. dao.sheZhiTingZhiShiJian(userCode, yz.getActOrderNo(), content);
  1124. log.info("停止医嘱==》医嘱号:{},停止时间:{},操作人:{}", yz.getActOrderNo(), content, userCode);
  1125. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  1126. }
  1127. private String tingZhiYiZhuJiaoYan(YzActOrder yz, String content) {
  1128. if (!DateUtil.dateStrIsValid(content, DateUtil.DEFAULT_PATTERN)) {
  1129. return "请输入正确的时间格式。";
  1130. }
  1131. if (yz.getEndTime() != null) {
  1132. return "该医嘱已经被停止了,无法修改。";
  1133. }
  1134. if (DateUtil.shiJianDaXiao(content, DateUtil.formatDatetime(yz.getStartTime()), "<=")) {
  1135. return "停止时间不能在开始时间前面。";
  1136. }
  1137. if (ONCE.equals(yz.getFrequCode().trim())) {
  1138. return "临时医嘱,无法设置停止时间。";
  1139. }
  1140. if (DateUtil.shiJianDaXiao(yz.getOrderTime(), yz.getEndTime(), ">=")) {
  1141. return "停止时间不能在,医嘱时间之前。";
  1142. }
  1143. return null;
  1144. }
  1145. @Transactional(rollbackFor = Exception.class)
  1146. public ResultVo<String> piLiangXiuGaiTingZhiShiJian(YiZhuTingZhiShiJian param) {
  1147. if (ListUtil.isBlank(param.getActOrderNoList())) {
  1148. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请先选择数据");
  1149. }
  1150. if (param.getActOrderNoList().size() > 20) {
  1151. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "批量操作每次不得大于20条");
  1152. }
  1153. List<YzActOrder> yiZhuXinXi = dao.yiZhuXinXiJiHe(param.getActOrderNoList());
  1154. if (yiZhuXinXi == null) {
  1155. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有查询到对应的医嘱信息,您选择的数据可以已经被全部停止或撤销。");
  1156. }
  1157. StringBuilder cuoWuXinXi = new StringBuilder();
  1158. for (YzActOrder yzActOrder : yiZhuXinXi) {
  1159. String jiaoYan = tingZhiYiZhuJiaoYan(yzActOrder, param.getEndTime());
  1160. if (jiaoYan != null) {
  1161. cuoWuXinXi.append("医嘱号:").append(yzActOrder.getActOrderNo()).append("<br>").append("医嘱名:").append(yzActOrder.getOrderName()).append("<br>").append(jiaoYan).append("<br><br>");
  1162. }
  1163. }
  1164. if (cuoWuXinXi.length() > 0) {
  1165. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_HTML_ERROR, cuoWuXinXi.toString());
  1166. }
  1167. dao.piLiangSheZhiTingZhiShiJian(param.getActOrderNoList(), TokenUtil.getTokenUserId(), param.getEndTime());
  1168. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
  1169. }
  1170. /**
  1171. * 获取医嘱下面产生的费用
  1172. *
  1173. * @param patNo 住院号
  1174. * @param times 住院次数
  1175. * @return 返回
  1176. */
  1177. public ResultVo<Map<String, Object>> expensesForGettingADoctorSOrder(String patNo, Integer times) {
  1178. List<DoctorSOrderFee> feeDate = dao.expensesForGettingADoctorSOrder(patNo, times);
  1179. // 这些编码的医嘱都是有问题的
  1180. List<String> problem = Arrays.asList("5", "6", "7", "9");
  1181. Map<String, String> problemDoctorSOrder = new HashMap<>();
  1182. Map<String, FeeSum> totalCost = new HashMap<>();
  1183. Map<String, List<DoctorSOrderFee>> map = new HashMap<>(feeDate.size());
  1184. for (DoctorSOrderFee fee : feeDate) {
  1185. // 如果这个没有就代表没有产生费用
  1186. if (fee.getOrderNoStr() == null) {
  1187. continue;
  1188. }
  1189. String chargeStatusName = ChargeStatus.getValue(fee.getChargeStatus());
  1190. String amount = fee.getChargeAmount().abs().stripTrailingZeros().toPlainString();
  1191. String money = fee.getChargeFee().stripTrailingZeros().toPlainString();
  1192. // 计算费用总和
  1193. if (totalCost.containsKey(fee.getOrderNoStr())) {
  1194. FeeSum sum = totalCost.get(fee.getOrderNoStr());
  1195. sum.setSum(DecimalUtil.add(money, sum.getSum()));
  1196. sum.setAmount(DecimalUtil.add(amount, sum.getAmount()));
  1197. totalCost.replace(fee.getOrderNoStr(), sum);
  1198. } else {
  1199. FeeSum sum = new FeeSum();
  1200. sum.setAmount(amount);
  1201. sum.setSum(money);
  1202. totalCost.put(fee.getOrderNoStr(), sum);
  1203. }
  1204. if (problem.contains(fee.getChargeStatus())) {
  1205. problemDoctorSOrder.put(fee.getOrderNoStr(), chargeStatusName);
  1206. }
  1207. fee.setChargeStatusName(chargeStatusName);
  1208. if (map.containsKey(fee.getOrderNoStr())) {
  1209. map.get(fee.getOrderNoStr()).add(fee);
  1210. } else {
  1211. List<DoctorSOrderFee> list = new ArrayList<>();
  1212. list.add(fee);
  1213. map.put(fee.getOrderNoStr(), list);
  1214. }
  1215. }
  1216. Map<String, Object> feeData = new HashMap<>(3);
  1217. feeData.put("data", map);
  1218. feeData.put("problem", problemDoctorSOrder);
  1219. feeData.put("totalCost", totalCost);
  1220. return ResultVoUtil.success(feeData);
  1221. }
  1222. /**
  1223. * 退药医嘱
  1224. *
  1225. * @param param 医嘱数组
  1226. * @return 返回提示
  1227. */
  1228. public ResultVo<String> drugWithdrawal(List<String> param) {
  1229. if (ListUtil.isBlank(param)) {
  1230. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有可以退的药品。");
  1231. }
  1232. List<List<String>> list = ListUtils.partition(param, 40);
  1233. List<YzActOrder> yzActOrders = new ArrayList<>();
  1234. for (List<String> strings : list) {
  1235. yzActOrders.addAll(dao.getOriginalOrderData(strings));
  1236. }
  1237. List<List<YzActOrder>> returnedDoctorSOrder = ListUtils.partition(yzActOrders, 20);
  1238. String userCode = TokenUtil.getTokenUserId();
  1239. Map<String, String> fatherAndSonDoctorSAdvice = new HashMap<>();
  1240. for (YzActOrder item : yzActOrders) {
  1241. BigDecimal orderNo = BigDecimal.valueOf(publicServer.getActOrderNo());
  1242. BigDecimal oldOrderNo = item.getActOrderNo();
  1243. fatherAndSonDoctorSAdvice.put(oldOrderNo.stripTrailingZeros().toPlainString(), orderNo.stripTrailingZeros().toPlainString());
  1244. if (item.getParentNo() != null && fatherAndSonDoctorSAdvice.containsKey(item.getParentNo().stripTrailingZeros().toPlainString())) {
  1245. item.setParentNo(new BigDecimal(fatherAndSonDoctorSAdvice.get(item.getParentNo().stripTrailingZeros().toPlainString())));
  1246. }
  1247. item.setActOrderNo(orderNo);
  1248. }
  1249. for (List<YzActOrder> orders : returnedDoctorSOrder) {
  1250. dao.insertAReturnOrder(userCode, orders);
  1251. }
  1252. return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "退药成功。");
  1253. }
  1254. }