ConceptInfoFacade.java 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. package com.diagbot.facade;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.diagbot.client.CdssCoreClient;
  6. import com.diagbot.dto.ConceptDetailDTO;
  7. import com.diagbot.dto.ConceptInfoDTO;
  8. import com.diagbot.dto.DictionaryInfoDTO;
  9. import com.diagbot.dto.RespDTO;
  10. import com.diagbot.dto.StaticKnowledgeDTO;
  11. import com.diagbot.dto.StaticKnowledgeDetailDTO;
  12. import com.diagbot.dto.StaticKnowledgeIndexDTO;
  13. import com.diagbot.entity.ConceptDetail;
  14. import com.diagbot.entity.ConceptInfo;
  15. import com.diagbot.enums.StaticTypeEnum;
  16. import com.diagbot.enums.IsDeleteEnum;
  17. import com.diagbot.exception.CommonErrorCode;
  18. import com.diagbot.exception.CommonException;
  19. import com.diagbot.service.ConceptDetailService;
  20. import com.diagbot.service.impl.ConceptInfoServiceImpl;
  21. import com.diagbot.util.BeanUtil;
  22. import com.diagbot.util.DateUtil;
  23. import com.diagbot.util.EntityUtil;
  24. import com.diagbot.util.ListUtil;
  25. import com.diagbot.util.RespDTOUtil;
  26. import com.diagbot.util.StringUtil;
  27. import com.diagbot.util.SysUserUtils;
  28. import com.diagbot.vo.ChangeStatusVO;
  29. import com.diagbot.vo.ConceptDetailVO;
  30. import com.diagbot.vo.ConceptInfoPageVO;
  31. import com.diagbot.vo.ConceptInfoVO;
  32. import com.diagbot.vo.HasStaticKnowledgeVO;
  33. import com.diagbot.vo.IdVO;
  34. import com.diagbot.vo.StaticKnowledgeHISVO;
  35. import com.diagbot.vo.StaticKnowledgeIndexVO;
  36. import com.diagbot.vo.StaticKnowledgeVO;
  37. import com.google.common.collect.Lists;
  38. import org.springframework.beans.factory.annotation.Autowired;
  39. import org.springframework.beans.factory.annotation.Qualifier;
  40. import org.springframework.stereotype.Component;
  41. import java.util.ArrayList;
  42. import java.util.Arrays;
  43. import java.util.Date;
  44. import java.util.HashMap;
  45. import java.util.List;
  46. import java.util.Map;
  47. import java.util.stream.Collectors;
  48. /**
  49. * @Description:
  50. * @Author:zhaops
  51. * @time: 2020/8/19 14:17
  52. */
  53. @Component
  54. public class ConceptInfoFacade extends ConceptInfoServiceImpl {
  55. @Autowired
  56. private CdssCoreClient cdssCoreClient;
  57. @Autowired
  58. private DictionaryFacade dictionaryFacade;
  59. @Autowired
  60. private ConceptDetailFacade conceptDetailFacade;
  61. @Autowired
  62. @Qualifier("conceptDetailServiceImpl")
  63. private ConceptDetailService conceptDetailService;
  64. @Autowired
  65. private LisConfigFacade lisConfigFacade;
  66. @Autowired
  67. private PacsConfigFacade pacsConfigFacade;
  68. @Autowired
  69. private DrugConfigFacade drugConfigFacade;
  70. @Autowired
  71. private DiseaseConfigFacade diseaseConfigFacade;
  72. @Autowired
  73. private OperationConfigFacade operationConfigFacade;
  74. /**
  75. * 返回带静态知识的检索结果
  76. *
  77. * @param staticKnowledgeIndexVO
  78. * @return
  79. */
  80. public List<StaticKnowledgeIndexDTO> staticKnowledgeIndexWithInfo(StaticKnowledgeIndexVO staticKnowledgeIndexVO) {
  81. List<StaticKnowledgeIndexDTO> staticKnowledgeIndexDTOList = staticKnowledgeIndex(staticKnowledgeIndexVO);
  82. //过滤没有静态知识的检索结果
  83. staticKnowledgeIndexDTOList = staticKnowledgeIndexDTOList
  84. .stream()
  85. .filter(i -> i.getHasInfo().equals(1))
  86. .collect(Collectors.toList());
  87. if (staticKnowledgeIndexDTOList.size() > 100) {
  88. staticKnowledgeIndexDTOList = staticKnowledgeIndexDTOList.subList(0, 100);
  89. }
  90. return staticKnowledgeIndexDTOList;
  91. }
  92. /**
  93. * 返回不带静态知识的检索结果
  94. *
  95. * @param staticKnowledgeIndexVO
  96. * @return
  97. */
  98. public List<StaticKnowledgeIndexDTO> staticKnowledgeIndexWithoutInfo(StaticKnowledgeIndexVO staticKnowledgeIndexVO) {
  99. List<StaticKnowledgeIndexDTO> staticKnowledgeIndexDTOList = staticKnowledgeIndex(staticKnowledgeIndexVO);
  100. //过滤没有静态知识的检索结果
  101. staticKnowledgeIndexDTOList = staticKnowledgeIndexDTOList
  102. .stream()
  103. .filter(i -> i.getHasInfo().equals(0))
  104. .collect(Collectors.toList());
  105. if (staticKnowledgeIndexDTOList.size() > 100) {
  106. staticKnowledgeIndexDTOList = staticKnowledgeIndexDTOList.subList(0, 100);
  107. }
  108. return staticKnowledgeIndexDTOList;
  109. }
  110. /**
  111. * 医学知识(静态信息)检索
  112. *
  113. * @param staticKnowledgeIndexVO
  114. * @return
  115. */
  116. public List<StaticKnowledgeIndexDTO> staticKnowledgeIndex(StaticKnowledgeIndexVO staticKnowledgeIndexVO) {
  117. List<StaticKnowledgeIndexDTO> retList = Lists.newLinkedList();
  118. //静态知识检索顺序
  119. List<DictionaryInfoDTO> dicStaticIndexList = dictionaryFacade.getListByGroupType(7);
  120. //页面术语类型和图谱映射
  121. List<DictionaryInfoDTO> dicTypeMappingList = dictionaryFacade.getListByGroupType(8);
  122. List<StaticKnowledgeIndexDTO> staticKnowledgeIndexDTOList = Lists.newLinkedList();
  123. RespDTO<List<StaticKnowledgeIndexDTO>> respDTO = cdssCoreClient.staticKnowledgeIndex(staticKnowledgeIndexVO);
  124. RespDTOUtil.respNGDealCover(respDTO, "检索失败");
  125. staticKnowledgeIndexDTOList = respDTO.data;
  126. if (ListUtil.isNotEmpty(staticKnowledgeIndexDTOList)) {
  127. //typeName转换
  128. staticKnowledgeIndexDTOList.forEach(item -> {
  129. item.setTypeName(convertTypeName(item.getTypeName(), 2, dicTypeMappingList));
  130. });
  131. //是否有静态知识
  132. List<String> conNameList = staticKnowledgeIndexDTOList
  133. .stream()
  134. .map(i -> i.getName())
  135. .collect(Collectors.toList());
  136. QueryWrapper<ConceptInfo> conceptInfoQueryWrapper = new QueryWrapper<>();
  137. conceptInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
  138. conceptInfoQueryWrapper.in("name", conNameList);
  139. List<ConceptInfo> conceptInfoList = this.list(conceptInfoQueryWrapper);
  140. /*int n = 0;
  141. do {
  142. List<String> subConNameList = new ArrayList<>();
  143. if (n + 1000 < conNameList.size()) {
  144. subConNameList = conNameList.subList(n, n + 1000);
  145. } else {
  146. subConNameList = conNameList.subList(n, conNameList.size());
  147. }
  148. conceptInfoQueryWrapper = new QueryWrapper<>();
  149. conceptInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
  150. conceptInfoQueryWrapper.in("name", subConNameList);
  151. List<ConceptInfo> subConceptInfoList = this.list(conceptInfoQueryWrapper);
  152. if (ListUtil.isNotEmpty(subConceptInfoList)) {
  153. conceptInfoList.addAll(subConceptInfoList);
  154. }
  155. n += 1000;
  156. } while (conceptInfoList.size() < 100 && n < conNameList.size());*/
  157. //staticKnowledgeIndexDTOList = staticKnowledgeIndexDTOList.subList(0, n);
  158. if (ListUtil.isNotEmpty(conceptInfoList)) {
  159. //typeName转换
  160. conceptInfoList.forEach(item -> {
  161. item.setType(convertTypeName(item.getType(), 2, dicTypeMappingList));
  162. });
  163. Map<String, ConceptInfo> infoMap
  164. = EntityUtil.makeEntityMapByKeys(conceptInfoList, "_", "name", "type");
  165. for (StaticKnowledgeIndexDTO item : staticKnowledgeIndexDTOList) {
  166. if (infoMap.containsKey(item.getName() + "_" + item.getTypeName())) {
  167. item.setId(infoMap.get(item.getName() + "_" + item.getTypeName()).getId());
  168. }
  169. }
  170. List<Long> conceptIdList = conceptInfoList.stream()
  171. .map(i -> i.getId())
  172. .collect(Collectors.toList());
  173. if (ListUtil.isNotEmpty(conceptIdList)) {
  174. QueryWrapper<ConceptDetail> conceptDetailQueryWrapper = new QueryWrapper<>();
  175. //conceptDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
  176. conceptDetailQueryWrapper.in("concept_id", conceptIdList);
  177. List<ConceptDetail> conceptDetailList = conceptDetailFacade.list(conceptDetailQueryWrapper);
  178. Map<Long, List<ConceptDetail>> detailMap
  179. = EntityUtil.makeEntityListMap(conceptDetailList, "conceptId");
  180. for (StaticKnowledgeIndexDTO item : staticKnowledgeIndexDTOList) {
  181. if (item.getId() == null
  182. || !detailMap.containsKey(item.getId())) {
  183. item.setHasInfo(0);
  184. item.setHasStaticKnowledge(0);
  185. item.setHasClinicalPathway(0);
  186. item.setHasNotice((0));
  187. item.setHasTreatInfo(0);
  188. continue;
  189. }
  190. for (ConceptDetail detail : detailMap.get(item.getId())) {
  191. item.setHasInfo(1);
  192. if (detail.getIsDeleted().equals(IsDeleteEnum.Y.getKey())) {
  193. continue;
  194. }
  195. List<String> contentTypeList = Arrays.asList(detail.getContentType().split(","));
  196. if (contentTypeList.contains("1")) {
  197. item.setHasStaticKnowledge(1);
  198. }
  199. if (contentTypeList.contains("2")) {
  200. item.setHasNotice(1);
  201. }
  202. if (contentTypeList.contains("3")) {
  203. item.setHasClinicalPathway(1);
  204. }
  205. if (contentTypeList.contains("4")) {
  206. item.setHasTreatInfo(1);
  207. }
  208. }
  209. }
  210. }
  211. }
  212. //排序
  213. Map<String, List<StaticKnowledgeIndexDTO>> map
  214. = EntityUtil.makeEntityListMap(staticKnowledgeIndexDTOList, "typeName");
  215. for (DictionaryInfoDTO dic : dicStaticIndexList) {
  216. if (dic.getName().equals("检验")) {
  217. if (map.containsKey(ConceptTypeEnum.LisPack.getName())) {
  218. retList.addAll(map.get(ConceptTypeEnum.LisPack.getName()));
  219. }
  220. if (map.containsKey(ConceptTypeEnum.Lis.getName())) {
  221. retList.addAll(map.get(ConceptTypeEnum.Lis.getName()));
  222. }
  223. } else if (map.containsKey(dic.getName())) {
  224. retList.addAll(map.get(dic.getName()));
  225. }
  226. }
  227. }
  228. return retList;
  229. }
  230. /**
  231. * 页面获取静态知识
  232. *
  233. * @param staticKnowledgeVO
  234. * @return
  235. */
  236. public StaticKnowledgeDTO getStaticKnowledge(StaticKnowledgeVO staticKnowledgeVO) {
  237. StaticKnowledgeDTO staticKnowledgeDTO = new StaticKnowledgeDTO();
  238. String typeName = StaticTypeEnum.getName(staticKnowledgeVO.getType());
  239. List<DictionaryInfoDTO> dicList = dictionaryFacade.getListByGroupType(8);
  240. typeName = convertTypeName(typeName, 1, dicList);
  241. QueryWrapper<ConceptInfo> conceptInfoQueryWrapper = new QueryWrapper<>();
  242. conceptInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  243. .eq("name", staticKnowledgeVO.getName())
  244. .eq("type", typeName);
  245. ConceptInfo conceptInfo = this.getOne(conceptInfoQueryWrapper, false);
  246. if (conceptInfo == null) {
  247. throw new CommonException(CommonErrorCode.IS_EXISTS, "缺少静态信息");
  248. }
  249. BeanUtil.copyProperties(conceptInfo, staticKnowledgeDTO);
  250. Long conceptId = conceptInfo.getId();
  251. QueryWrapper<ConceptDetail> conceptDetailQueryWrapper = new QueryWrapper<>();
  252. conceptDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  253. .eq("concept_id", conceptId);
  254. if (ListUtil.isNotEmpty(staticKnowledgeVO.getContentTypes())) {
  255. String sql = "";
  256. for (Integer contentType : staticKnowledgeVO.getContentTypes()) {
  257. if (contentType.equals(0)) {
  258. sql = "";
  259. break;
  260. }
  261. if (StringUtil.isNotBlank(sql)) {
  262. sql += " or ";
  263. }
  264. sql += "find_in_set(" + contentType + ",content_type)";
  265. }
  266. if (StringUtil.isNotBlank(sql)) {
  267. sql = "(" + sql + ")";
  268. conceptDetailQueryWrapper.apply(sql);
  269. }
  270. }
  271. conceptDetailQueryWrapper.orderByAsc("order_no");
  272. List<ConceptDetail> conceptDetailList = conceptDetailFacade.list(conceptDetailQueryWrapper);
  273. List<StaticKnowledgeDetailDTO> detailList
  274. = BeanUtil.listCopyTo(conceptDetailList, StaticKnowledgeDetailDTO.class);
  275. List<StaticKnowledgeDetailDTO> introduceList = detailList
  276. .stream()
  277. .filter(i -> Arrays.asList(i.getContentType().split(",")).contains("1"))
  278. .collect(Collectors.toList());
  279. List<StaticKnowledgeDetailDTO> noticeList = detailList
  280. .stream()
  281. .filter(i -> Arrays.asList(i.getContentType().split(",")).contains("2"))
  282. .collect(Collectors.toList());
  283. List<StaticKnowledgeDetailDTO> clinicalPathwayList = detailList
  284. .stream()
  285. .filter(i -> Arrays.asList(i.getContentType().split(",")).contains("3"))
  286. .collect(Collectors.toList());
  287. List<StaticKnowledgeDetailDTO> treatInfoList = detailList
  288. .stream()
  289. .filter(i -> Arrays.asList(i.getContentType().split(",")).contains("4"))
  290. .collect(Collectors.toList());
  291. Map<String, List<StaticKnowledgeDetailDTO>> detailMap = new HashMap<>();
  292. if (ListUtil.isEmpty(staticKnowledgeVO.getContentTypes()) || staticKnowledgeVO.getContentTypes().contains(0)) {
  293. if (ListUtil.isNotEmpty(introduceList)) {
  294. detailMap.put("静态知识", introduceList);
  295. }
  296. if (ListUtil.isNotEmpty(noticeList)) {
  297. detailMap.put("注意事项", noticeList);
  298. }
  299. if (ListUtil.isNotEmpty(clinicalPathwayList)) {
  300. detailMap.put("临床路径", clinicalPathwayList);
  301. }
  302. if (ListUtil.isNotEmpty(treatInfoList)) {
  303. detailMap.put("治疗方案", treatInfoList);
  304. }
  305. } else {
  306. if (ListUtil.isNotEmpty(introduceList) && staticKnowledgeVO.getContentTypes().contains(1)) {
  307. detailMap.put("静态知识", introduceList);
  308. }
  309. if (ListUtil.isNotEmpty(noticeList) && staticKnowledgeVO.getContentTypes().contains(2)) {
  310. detailMap.put("注意事项", noticeList);
  311. }
  312. if (ListUtil.isNotEmpty(clinicalPathwayList) && staticKnowledgeVO.getContentTypes().contains(3)) {
  313. detailMap.put("临床路径", clinicalPathwayList);
  314. }
  315. if (ListUtil.isNotEmpty(treatInfoList) && staticKnowledgeVO.getContentTypes().contains(4)) {
  316. detailMap.put("治疗方案", treatInfoList);
  317. }
  318. }
  319. staticKnowledgeDTO.setDetails(detailMap);
  320. return staticKnowledgeDTO;
  321. }
  322. /**
  323. * 医院端获取静态知识(对接)
  324. *
  325. * @param staticKnowledgeHISVO
  326. * @return
  327. */
  328. public List<StaticKnowledgeDTO> getStaticKnowledgeForHIS(StaticKnowledgeHISVO staticKnowledgeHISVO) {
  329. List<StaticKnowledgeDTO> retList = Lists.newArrayList();
  330. String typeName = StaticTypeEnum.getName(staticKnowledgeHISVO.getType());
  331. List<DictionaryInfoDTO> dicList = dictionaryFacade.getListByGroupType(8);
  332. typeName = convertTypeName(typeName, 1, dicList);
  333. //术语映射
  334. List<String> uniqueNameList = getUniqueNames(staticKnowledgeHISVO);
  335. if (ListUtil.isEmpty(uniqueNameList)) {
  336. return retList;
  337. }
  338. QueryWrapper<ConceptInfo> conceptInfoQueryWrapper = new QueryWrapper<>();
  339. conceptInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  340. .in("name", uniqueNameList)
  341. .eq("type", typeName);
  342. List<ConceptInfo> conceptInfoList = this.list(conceptInfoQueryWrapper);
  343. if (ListUtil.isEmpty(conceptInfoList)) {
  344. return retList;
  345. }
  346. retList = BeanUtil.listCopyTo(conceptInfoList, StaticKnowledgeDTO.class);
  347. List<Long> conceptIdList = conceptInfoList.stream().map(i -> i.getId()).collect(Collectors.toList());
  348. QueryWrapper<ConceptDetail> conceptDetailQueryWrapper = new QueryWrapper<>();
  349. conceptDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  350. .in("concept_id", conceptIdList);
  351. if (ListUtil.isNotEmpty(staticKnowledgeHISVO.getContentTypes())) {
  352. String sql = "";
  353. for (Integer contentType : staticKnowledgeHISVO.getContentTypes()) {
  354. if (contentType.equals(0)) {
  355. sql = "";
  356. break;
  357. }
  358. if (StringUtil.isNotBlank(sql)) {
  359. sql += " or ";
  360. }
  361. sql += "find_in_set(" + contentType + ",content_type)";
  362. }
  363. if (StringUtil.isNotBlank(sql)) {
  364. sql = "(" + sql + ")";
  365. }
  366. conceptDetailQueryWrapper.apply(sql);
  367. }
  368. conceptDetailQueryWrapper.orderByAsc("concept_id", "order_no");
  369. List<ConceptDetail> conceptDetailList = conceptDetailFacade.list(conceptDetailQueryWrapper);
  370. List<StaticKnowledgeDetailDTO> detailList
  371. = BeanUtil.listCopyTo(conceptDetailList, StaticKnowledgeDetailDTO.class);
  372. Map<Long, List<StaticKnowledgeDetailDTO>> conceptMap
  373. = EntityUtil.makeEntityListMap(detailList, "conceptId");
  374. for (StaticKnowledgeDTO staticKnowledgeDTO : retList) {
  375. List<StaticKnowledgeDetailDTO> subDetailList = conceptMap.get(staticKnowledgeDTO.getId());
  376. if (ListUtil.isNotEmpty(subDetailList)) {
  377. List<StaticKnowledgeDetailDTO> introduceList = subDetailList
  378. .stream()
  379. .filter(i -> Arrays.asList(i.getContentType().split(",")).contains("1"))
  380. .collect(Collectors.toList());
  381. List<StaticKnowledgeDetailDTO> noticeList = subDetailList
  382. .stream()
  383. .filter(i -> Arrays.asList(i.getContentType().split(",")).contains("2"))
  384. .collect(Collectors.toList());
  385. List<StaticKnowledgeDetailDTO> clinicalPathwayList = subDetailList
  386. .stream()
  387. .filter(i -> Arrays.asList(i.getContentType().split(",")).contains("3"))
  388. .collect(Collectors.toList());
  389. List<StaticKnowledgeDetailDTO> treatInfoList = subDetailList
  390. .stream()
  391. .filter(i -> Arrays.asList(i.getContentType().split(",")).contains("4"))
  392. .collect(Collectors.toList());
  393. Map<String, List<StaticKnowledgeDetailDTO>> subDetailMap = new HashMap<>();
  394. if (ListUtil.isEmpty(staticKnowledgeHISVO.getContentTypes()) || staticKnowledgeHISVO.getContentTypes().contains(0)) {
  395. if (ListUtil.isNotEmpty(introduceList)) {
  396. subDetailMap.put("静态知识", introduceList);
  397. }
  398. if (ListUtil.isNotEmpty(noticeList)) {
  399. subDetailMap.put("注意事项", noticeList);
  400. }
  401. if (ListUtil.isNotEmpty(clinicalPathwayList)) {
  402. subDetailMap.put("临床路径", clinicalPathwayList);
  403. }
  404. if (ListUtil.isNotEmpty(treatInfoList)) {
  405. subDetailMap.put("治疗方案", treatInfoList);
  406. }
  407. } else {
  408. if (ListUtil.isNotEmpty(introduceList) && staticKnowledgeHISVO.getContentTypes().contains(1)) {
  409. subDetailMap.put("静态知识", introduceList);
  410. }
  411. if (ListUtil.isNotEmpty(noticeList) && staticKnowledgeHISVO.getContentTypes().contains(2)) {
  412. subDetailMap.put("注意事项", noticeList);
  413. }
  414. if (ListUtil.isNotEmpty(clinicalPathwayList) && staticKnowledgeHISVO.getContentTypes().contains(3)) {
  415. subDetailMap.put("临床路径", clinicalPathwayList);
  416. }
  417. if (ListUtil.isNotEmpty(treatInfoList) && staticKnowledgeHISVO.getContentTypes().contains(4)) {
  418. subDetailMap.put("治疗方案", treatInfoList);
  419. }
  420. }
  421. staticKnowledgeDTO.setDetails(subDetailMap);
  422. }
  423. }
  424. return retList;
  425. }
  426. /**
  427. * 页面术语类型和图谱标签名称相互转换
  428. *
  429. * @param typeName
  430. * @param flag 1-页面术语类型转图谱标签名称,2- 图谱标签名称转页面术语类型
  431. * @param dicList
  432. * @return
  433. */
  434. public String convertTypeName(String typeName, Integer flag, List<DictionaryInfoDTO> dicList) {
  435. if (ListUtil.isNotEmpty(dicList)) {
  436. Map<String, String> nameValMap = new HashMap<>();
  437. if (flag.equals(1)) {
  438. nameValMap = EntityUtil.makeMapWithKeyValue(dicList, "name", "val");
  439. } else if (flag.equals(2)) {
  440. nameValMap = EntityUtil.makeMapWithKeyValue(dicList, "val", "name");
  441. }
  442. if (nameValMap.containsKey(typeName)) {
  443. return nameValMap.get(typeName);
  444. }
  445. }
  446. return typeName;
  447. }
  448. /**
  449. * @param staticKnowledgeHISVO
  450. * @return
  451. */
  452. public List<String> getUniqueNames(StaticKnowledgeHISVO staticKnowledgeHISVO) {
  453. String hospitalId = SysUserUtils.getCurrentHospitalID();
  454. List<String> nameList = null;
  455. switch (staticKnowledgeHISVO.getType()) {
  456. case 1:
  457. Map<String, Map<String, Long>> disConfigMap
  458. = diseaseConfigFacade.getConfigMap(Long.valueOf(hospitalId),
  459. ListUtil.arrayToList(new String[] { staticKnowledgeHISVO.getHisName() }), null);
  460. if (disConfigMap != null) {
  461. nameList = new ArrayList<>(disConfigMap.get(staticKnowledgeHISVO.getHisName()).keySet());
  462. }
  463. break;
  464. case 2:
  465. Map<String, Map<String, Long>> drugConfigMap
  466. = drugConfigFacade.getConfigMapWithoutForm(Long.valueOf(hospitalId),
  467. ListUtil.arrayToList(new String[] { staticKnowledgeHISVO.getHisName() }), null);
  468. if (drugConfigMap != null) {
  469. nameList = new ArrayList<>(drugConfigMap.get(staticKnowledgeHISVO.getHisName()).keySet());
  470. }
  471. break;
  472. case 3:
  473. case 4:
  474. Map<String, Map<String, Map<String, Long>>> lisConfigMap
  475. = lisConfigFacade.getConfigMap(Long.valueOf(hospitalId),
  476. ListUtil.arrayToList(new String[] { staticKnowledgeHISVO.getHisName() }), null);
  477. if (lisConfigMap != null) {
  478. if (StringUtil.isBlank(staticKnowledgeHISVO.getHisDetailName())) {
  479. staticKnowledgeHISVO.setHisDetailName("");
  480. }
  481. if (lisConfigMap.containsKey(staticKnowledgeHISVO.getHisName())) {
  482. if (lisConfigMap.get(staticKnowledgeHISVO.getHisName()).containsKey(staticKnowledgeHISVO.getHisDetailName())) {
  483. nameList = new ArrayList<>(lisConfigMap.get(staticKnowledgeHISVO.getHisName())
  484. .get(staticKnowledgeHISVO.getHisDetailName()).keySet());
  485. }
  486. }
  487. }
  488. break;
  489. case 5:
  490. Map<String, Map<String, Long>> pacsConfigMap
  491. = pacsConfigFacade.getConfigMap(Long.valueOf(hospitalId),
  492. ListUtil.arrayToList(new String[] { staticKnowledgeHISVO.getHisName() }), null);
  493. if (pacsConfigMap != null) {
  494. nameList = new ArrayList<>(pacsConfigMap.get(staticKnowledgeHISVO.getHisName()).keySet());
  495. }
  496. break;
  497. case 6:
  498. Map<String, Map<String, Long>> operationConfigMap
  499. = operationConfigFacade.getConfigMap(Long.valueOf(hospitalId),
  500. ListUtil.arrayToList(new String[] { staticKnowledgeHISVO.getHisName() }), null);
  501. if (operationConfigMap != null) {
  502. nameList = new ArrayList<>(operationConfigMap.get(staticKnowledgeHISVO.getHisName()).keySet());
  503. }
  504. break;
  505. default:
  506. break;
  507. }
  508. nameList = nameList
  509. .stream()
  510. .distinct()
  511. .collect(Collectors.toList());
  512. return nameList;
  513. }
  514. /**
  515. * 列表
  516. *
  517. * @param conceptInfoPageVO
  518. * @return
  519. */
  520. public IPage<ConceptInfoDTO> getPage(ConceptInfoPageVO conceptInfoPageVO) {
  521. List<DictionaryInfoDTO> dicList = dictionaryFacade.getListByGroupType(8);
  522. if (StringUtil.isNotBlank(conceptInfoPageVO.getType())) {
  523. String typeName
  524. = convertTypeName(StaticTypeEnum.getName(Integer.valueOf(conceptInfoPageVO.getType())), 1, dicList);
  525. conceptInfoPageVO.setTypeName(typeName);
  526. }
  527. IPage<ConceptInfoDTO> page = super.getPage(conceptInfoPageVO);
  528. List<ConceptInfoDTO> records = page.getRecords();
  529. if (ListUtil.isNotEmpty(records)) {
  530. records.forEach(record -> {
  531. String typeName = convertTypeName(record.getType(), 2, dicList);
  532. record.setTypeName(typeName);
  533. record.setType(String.valueOf(StaticTypeEnum.getKey(typeName)));
  534. });
  535. }
  536. page.setRecords(records);
  537. return page;
  538. }
  539. /**
  540. * 保存记录(新增or修改)
  541. *
  542. * @param conceptInfoVO
  543. * @return
  544. */
  545. public Boolean saveOrUpdateRecord(ConceptInfoVO conceptInfoVO) {
  546. String userId = SysUserUtils.getCurrentPrincipleID();
  547. Date now = DateUtil.now();
  548. List<DictionaryInfoDTO> dicList = dictionaryFacade.getListByGroupType(8);
  549. //术语类型转换
  550. String typeName = convertTypeName(StaticTypeEnum.getName(Integer.valueOf(conceptInfoVO.getType())), 1, dicList);
  551. conceptInfoVO.setTypeName(typeName);
  552. ConceptInfo conceptInfo = new ConceptInfo();
  553. if (conceptInfoVO.getId() != null) {
  554. conceptInfo = this.getById(conceptInfoVO.getId());
  555. if (conceptInfo != null
  556. && !conceptInfo.getName().equals(conceptInfoVO.getName())) {
  557. throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "标准术语名称不允许修改");
  558. }
  559. } else {
  560. QueryWrapper<ConceptInfo> conceptInfoQueryWrapper = new QueryWrapper<>();
  561. conceptInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  562. .eq("name", conceptInfoVO.getName())
  563. .eq("type", typeName);
  564. conceptInfo = this.getOne(conceptInfoQueryWrapper, false);
  565. //术语不存在,保存术语信息
  566. if (conceptInfo == null) {
  567. conceptInfo = new ConceptInfo();
  568. conceptInfo.setCreator(userId);
  569. conceptInfo.setGmtCreate(now);
  570. }
  571. }
  572. conceptInfo.setName(conceptInfoVO.getName());
  573. conceptInfo.setClinicalPathwayName(conceptInfoVO.getClinicalPathwayName());
  574. conceptInfo.setNoticeName(conceptInfoVO.getNoticeName());
  575. conceptInfo.setType(typeName);
  576. conceptInfo.setModifier(userId);
  577. conceptInfo.setGmtModified(now);
  578. //是否包含静态信息,包含启用和禁用
  579. List<ConceptDetail> oldDetails = null;
  580. QueryWrapper<ConceptDetail> conceptDetailQueryWrapper = new QueryWrapper<>();
  581. if (conceptInfo.getId() != null) {
  582. conceptDetailQueryWrapper.eq("concept_id", conceptInfo.getId());
  583. oldDetails = conceptDetailFacade.list(conceptDetailQueryWrapper);
  584. }
  585. if (conceptInfoVO.getId() == null
  586. && ListUtil.isNotEmpty(oldDetails)) {
  587. throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "静态信息已添加,不允许重复添加");
  588. }
  589. if (ListUtil.isEmpty(oldDetails)
  590. && ListUtil.isNotEmpty(conceptInfoVO.getDetails())) {
  591. //TODO 更新图谱是否有静态信息
  592. HasStaticKnowledgeVO hasStaticKnowledgeVO = new HasStaticKnowledgeVO();
  593. hasStaticKnowledgeVO.setName(conceptInfoVO.getName());
  594. hasStaticKnowledgeVO.setType(typeName);
  595. hasStaticKnowledgeVO.setHasInfo(1);
  596. RespDTO<Boolean> respDTO = cdssCoreClient.updateHasInfoStatus(hasStaticKnowledgeVO);
  597. //更新失败
  598. if (RespDTOUtil.respIsNG(respDTO)) {
  599. }
  600. }
  601. //删除已有静态信息
  602. if (conceptInfo.getId() != null) {
  603. conceptDetailFacade.remove(conceptDetailQueryWrapper);
  604. }
  605. //更新术语信息
  606. this.saveOrUpdate(conceptInfo);
  607. //插入新的静态信息
  608. List<ConceptDetail> conceptDetailList = Lists.newLinkedList();
  609. if (ListUtil.isNotEmpty(conceptInfoVO.getDetails())) {
  610. for (ConceptDetailVO detailVO : conceptInfoVO.getDetails()) {
  611. ConceptDetail conceptDetail = new ConceptDetail();
  612. BeanUtil.copyProperties(detailVO, conceptDetail);
  613. conceptDetail.setConceptId(conceptInfo.getId());
  614. conceptDetail.setCreator(userId);
  615. conceptDetail.setGmtCreate(now);
  616. conceptDetail.setModifier(userId);
  617. conceptDetail.setGmtModified(now);
  618. conceptDetailList.add(conceptDetail);
  619. }
  620. conceptDetailService.saveBatch(conceptDetailList);
  621. }
  622. return true;
  623. }
  624. /**
  625. * 启用禁用
  626. *
  627. * @param changeStatusVO
  628. * @return
  629. */
  630. public Boolean changeStatus(ChangeStatusVO changeStatusVO) {
  631. String userId = SysUserUtils.getCurrentPrincipleID();
  632. Date now = DateUtil.now();
  633. UpdateWrapper<ConceptDetail> conceptDetailUpdateWrapper = new UpdateWrapper<>();
  634. conceptDetailUpdateWrapper.eq("concept_id", changeStatusVO.getId())
  635. .set("gmt_modified", now)
  636. .set("modifier", userId)
  637. .set("is_deleted", changeStatusVO.getIsDeleted());
  638. conceptDetailService.update(conceptDetailUpdateWrapper);
  639. return true;
  640. }
  641. /**
  642. * 是否已存在
  643. *
  644. * @param conceptInfoVO
  645. * @return
  646. */
  647. public Boolean isExist(ConceptInfoVO conceptInfoVO) {
  648. List<DictionaryInfoDTO> dicList = dictionaryFacade.getListByGroupType(8);
  649. //术语类型转换
  650. String typeName = convertTypeName(StaticTypeEnum.getName(Integer.valueOf(conceptInfoVO.getType())), 1, dicList);
  651. conceptInfoVO.setTypeName(typeName);
  652. QueryWrapper<ConceptInfo> conceptInfoQueryWrapper = new QueryWrapper<>();
  653. conceptInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  654. .eq("name", conceptInfoVO.getName())
  655. .eq("type", typeName);
  656. ConceptInfo conceptInfo = this.getOne(conceptInfoQueryWrapper, false);
  657. if (conceptInfo == null) {
  658. return false;
  659. }
  660. QueryWrapper<ConceptDetail> conceptDetailQueryWrapper = new QueryWrapper<>();
  661. conceptDetailQueryWrapper.eq("concept_id", conceptInfo.getId());
  662. List<ConceptDetail> conceptDetailList = conceptDetailService.list(conceptDetailQueryWrapper);
  663. if (ListUtil.isEmpty(conceptDetailList)) {
  664. return false;
  665. }
  666. return true;
  667. }
  668. /**
  669. * 根据术语id获取静态信息
  670. *
  671. * @param idVO
  672. * @return
  673. */
  674. public ConceptInfoDTO getRecordById(IdVO idVO) {
  675. List<DictionaryInfoDTO> dicList = dictionaryFacade.getListByGroupType(8);
  676. ConceptInfoDTO conceptInfoDTO = new ConceptInfoDTO();
  677. ConceptInfo conceptInfo = this.getById(idVO.getId());
  678. if (conceptInfo == null) {
  679. return null;
  680. }
  681. BeanUtil.copyProperties(conceptInfo, conceptInfoDTO);
  682. QueryWrapper<ConceptDetail> conceptDetailQueryWrapper = new QueryWrapper<>();
  683. conceptDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  684. .eq("concept_id", idVO.getId())
  685. .orderByAsc("order_no");
  686. List<ConceptDetail> conceptDetailList = conceptDetailFacade.list(conceptDetailQueryWrapper);
  687. if (ListUtil.isNotEmpty(conceptDetailList)) {
  688. List<ConceptDetailDTO> details = BeanUtil.listCopyTo(conceptDetailList, ConceptDetailDTO.class);
  689. conceptInfoDTO.setDetails(details);
  690. //启用状态、修改人、修改时间为明细的内容
  691. String typeName = convertTypeName(conceptInfoDTO.getType(), 2, dicList);
  692. conceptInfoDTO.setTypeName(typeName);
  693. conceptInfoDTO.setType(String.valueOf(StaticTypeEnum.getKey(typeName)));
  694. conceptInfoDTO.setModifier(conceptDetailList.get(0).getModifier());
  695. conceptInfoDTO.setGmtModified(conceptDetailList.get(0).getGmtModified());
  696. conceptInfoDTO.setIsDeleted(conceptDetailList.get(0).getIsDeleted());
  697. }
  698. return conceptInfoDTO;
  699. }
  700. /**
  701. * 获取静态知识map Map<name_type,List<ConceptDetail>>
  702. *
  703. * @param nameList
  704. * @return
  705. */
  706. public Map<String, List<ConceptDetail>> getDetailByConcept(List<String> nameList) {
  707. Map<String, List<ConceptDetail>> retMap = new HashMap<>();
  708. List<DictionaryInfoDTO> dicList = dictionaryFacade.getListByGroupType(8);
  709. QueryWrapper<ConceptInfo> conceptInfoQueryWrapper = new QueryWrapper<>();
  710. conceptInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
  711. if (ListUtil.isNotEmpty(nameList)) {
  712. conceptInfoQueryWrapper.in("name", nameList);
  713. }
  714. List<ConceptInfo> conceptInfoList = this.list(conceptInfoQueryWrapper);
  715. Map<Long, ConceptInfo> conceptMap = EntityUtil.makeEntityMap(conceptInfoList, "id");
  716. if (ListUtil.isNotEmpty(conceptInfoList)) {
  717. List<Long> conceptIds = conceptInfoList.stream()
  718. .map(i -> i.getId())
  719. .collect(Collectors.toList());
  720. QueryWrapper<ConceptDetail> conceptDetailQueryWrapper = new QueryWrapper<>();
  721. conceptDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
  722. .in("concept_id", conceptIds);
  723. List<ConceptDetail> conceptDetailList = conceptDetailFacade.list(conceptDetailQueryWrapper);
  724. Map<Long, List<ConceptDetail>> detailMap
  725. = EntityUtil.makeEntityListMap(conceptDetailList, "conceptId");
  726. for (Map.Entry<Long, ConceptInfo> entry : conceptMap.entrySet()) {
  727. if (detailMap.containsKey(entry.getKey())) {
  728. retMap.put(entry.getValue().getName() + "_" + convertTypeName(entry.getValue().getType(), 2, dicList), detailMap.get(entry.getKey()));
  729. }
  730. }
  731. }
  732. return retMap;
  733. }
  734. }