MedRetrievalFacade.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. package com.diagbot.facade;
  2. import com.diagbot.dto.*;
  3. import com.diagbot.enums.LexiconEnum;
  4. import com.diagbot.exception.CommonErrorCode;
  5. import com.diagbot.exception.CommonException;
  6. import com.diagbot.util.BeanUtil;
  7. import com.diagbot.util.EntityUtil;
  8. import com.diagbot.util.ListUtil;
  9. import com.diagbot.util.StringUtil;
  10. import com.diagbot.vo.MedRetrievalVO;
  11. import com.diagbot.vo.RetrievalVO;
  12. import com.diagbot.vo.StaticKnowledgeIndexVO;
  13. import com.google.common.collect.Lists;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Component;
  16. import java.util.ArrayList;
  17. import java.util.Arrays;
  18. import java.util.HashMap;
  19. import java.util.List;
  20. import java.util.Map;
  21. /**
  22. * @Description:
  23. * @Author:zhaops
  24. * @time: 2021/2/22 10:35
  25. */
  26. @Component
  27. public class MedRetrievalFacade {
  28. @Autowired
  29. private KlConceptFacade klConceptFacade;
  30. @Autowired
  31. private DictionaryFacade dictionaryFacade;
  32. @Autowired
  33. private KlDictionaryInfoFacade klDictionaryInfoFacade;
  34. /**
  35. * 检索
  36. *
  37. * @param retrievalVO
  38. * @return
  39. */
  40. public RetrievalDTO index(RetrievalVO retrievalVO) {
  41. if (retrievalVO.getSize() == null) {
  42. retrievalVO.setSize(100);
  43. }
  44. if (retrievalVO.getDefaultList().equals(0)
  45. && StringUtil.isBlank(retrievalVO.getInputStr())) {
  46. throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "请输入检索内容");
  47. }
  48. RetrievalDTO retrievalDTO = new RetrievalDTO();
  49. MedRetrievalVO medRetrievalVO = new MedRetrievalVO();
  50. BeanUtil.copyProperties(retrievalVO, medRetrievalVO);
  51. medRetrievalVO.setTypeIds(new ArrayList<>());
  52. List<IndexDTO> indexList = Lists.newLinkedList();
  53. /**
  54. * 类型:1-化验大项、2-化验小项、3-辅检、4-诊断、5-药品、6-手术和操作、7-科室、8-输血、9-症状、10-量表、11-护理、12-中医诊断、13-中医证候、14-麻醉、15-药品剂型、16-给药途径、17-物理治疗
  55. */
  56. switch (retrievalVO.getType()) {
  57. case 1:
  58. medRetrievalVO.setTypeId(LexiconEnum.LisName.getKey());
  59. medRetrievalVO.getTypeIds().add(LexiconEnum.LisName.getKey());
  60. List<RetrievalConceptDTO> nameList = new ArrayList<>();
  61. indexList = klConceptFacade.index(medRetrievalVO);
  62. if (ListUtil.isNotEmpty(indexList)) {
  63. nameList = BeanUtil.listCopyTo(indexList, RetrievalConceptDTO.class);
  64. retrievalDTO.setNameList(nameList);
  65. }
  66. break;
  67. case 2:
  68. medRetrievalVO.setTypeId(LexiconEnum.LisSubName.getKey());
  69. medRetrievalVO.getTypeIds().add(LexiconEnum.LisSubName.getKey());
  70. indexList = klConceptFacade.index(medRetrievalVO);
  71. if (ListUtil.isNotEmpty(indexList)) {
  72. List<LisDetailDTO> lisDetails = Lists.newLinkedList();
  73. indexList.forEach(item -> {
  74. LisDetailDTO lisDetail = new LisDetailDTO();
  75. BeanUtil.copyProperties(item, lisDetail);
  76. lisDetail.setName(item.getPackName());
  77. lisDetail.setUniqueName(item.getName());
  78. //默认套餐名称
  79. if (StringUtil.isBlank(lisDetail.getName())) {
  80. lisDetail.setName(lisDetail.getUniqueName());
  81. }
  82. lisDetails.add(lisDetail);
  83. });
  84. retrievalDTO.setLisDetailNames(lisDetails);
  85. }
  86. break;
  87. case 3:
  88. medRetrievalVO.setTypeId(LexiconEnum.PacsName.getKey());
  89. medRetrievalVO.getTypeIds().addAll(Arrays.asList(LexiconEnum.PacsName.getKey(),
  90. LexiconEnum.PacsSubName.getKey()));
  91. indexList = klConceptFacade.index(medRetrievalVO);
  92. if (ListUtil.isNotEmpty(indexList)) {
  93. List<RetrievalConceptDTO> pacsNames = new ArrayList<>();
  94. pacsNames = BeanUtil.listCopyTo(indexList, RetrievalConceptDTO.class);
  95. retrievalDTO.setNameList(pacsNames);
  96. }
  97. break;
  98. case 4:
  99. medRetrievalVO.setTypeId(LexiconEnum.Disease.getKey());
  100. medRetrievalVO.getTypeIds().add(LexiconEnum.Disease.getKey());
  101. indexList = klConceptFacade.index(medRetrievalVO);
  102. if (ListUtil.isNotEmpty(indexList)) {
  103. retrievalDTO.setNameList(BeanUtil.listCopyTo(indexList, RetrievalConceptDTO.class));
  104. }
  105. break;
  106. case 5:
  107. medRetrievalVO.setTypeId(LexiconEnum.Medicine.getKey());
  108. medRetrievalVO.getTypeIds().add(LexiconEnum.Medicine.getKey());
  109. indexList = klConceptFacade.index(medRetrievalVO);
  110. if (ListUtil.isNotEmpty(indexList)) {
  111. retrievalDTO.setNameList(BeanUtil.listCopyTo(indexList, RetrievalConceptDTO.class));
  112. }
  113. break;
  114. case 6:
  115. medRetrievalVO.setTypeId(LexiconEnum.Operation.getKey());
  116. medRetrievalVO.getTypeIds().add(LexiconEnum.Operation.getKey());
  117. indexList = klConceptFacade.index(medRetrievalVO);
  118. if (ListUtil.isNotEmpty(indexList)) {
  119. retrievalDTO.setNameList(BeanUtil.listCopyTo(indexList, RetrievalConceptDTO.class));
  120. }
  121. break;
  122. case 7:
  123. medRetrievalVO.setTypeId(LexiconEnum.Dept.getKey());
  124. medRetrievalVO.getTypeIds().add(LexiconEnum.Dept.getKey());
  125. indexList = klConceptFacade.index(medRetrievalVO);
  126. if (ListUtil.isNotEmpty(indexList)) {
  127. List<RetrievalConceptDTO> deptNames = new ArrayList<>();
  128. deptNames = BeanUtil.listCopyTo(indexList, RetrievalConceptDTO.class);
  129. retrievalDTO.setNameList(deptNames);
  130. }
  131. break;
  132. case 8:
  133. medRetrievalVO.setTypeId(LexiconEnum.Transfusion.getKey());
  134. medRetrievalVO.getTypeIds().add(LexiconEnum.Transfusion.getKey());
  135. indexList = klConceptFacade.index(medRetrievalVO);
  136. if (ListUtil.isNotEmpty(indexList)) {
  137. List<RetrievalConceptDTO> transfusionNames = new ArrayList<>();
  138. transfusionNames = BeanUtil.listCopyTo(indexList, RetrievalConceptDTO.class);
  139. retrievalDTO.setNameList(transfusionNames);
  140. }
  141. break;
  142. case 9:
  143. medRetrievalVO.setTypeId(LexiconEnum.Symptom.getKey());
  144. medRetrievalVO.getTypeIds().add(LexiconEnum.Symptom.getKey());
  145. indexList = klConceptFacade.index(medRetrievalVO);
  146. if (ListUtil.isNotEmpty(indexList)) {
  147. List<RetrievalConceptDTO> symptomNames = new ArrayList<>();
  148. symptomNames = BeanUtil.listCopyTo(indexList, RetrievalConceptDTO.class);
  149. retrievalDTO.setNameList(symptomNames);
  150. }
  151. break;
  152. case 10:
  153. medRetrievalVO.setTypeId(LexiconEnum.Scale.getKey());
  154. medRetrievalVO.getTypeIds().add(LexiconEnum.Scale.getKey());
  155. indexList = klConceptFacade.index(medRetrievalVO);
  156. if (ListUtil.isNotEmpty(indexList)) {
  157. retrievalDTO.setNameList(BeanUtil.listCopyTo(indexList, RetrievalConceptDTO.class));
  158. }
  159. break;
  160. case 11:
  161. medRetrievalVO.setTypeId(LexiconEnum.Nurse.getKey());
  162. medRetrievalVO.getTypeIds().add(LexiconEnum.Nurse.getKey());
  163. indexList = klConceptFacade.index(medRetrievalVO);
  164. if (ListUtil.isNotEmpty(indexList)) {
  165. retrievalDTO.setNameList(BeanUtil.listCopyTo(indexList, RetrievalConceptDTO.class));
  166. }
  167. break;
  168. case 12:
  169. medRetrievalVO.setTypeId(LexiconEnum.Tcmdisease.getKey());
  170. medRetrievalVO.getTypeIds().add(LexiconEnum.Tcmdisease.getKey());
  171. indexList = klConceptFacade.index(medRetrievalVO);
  172. if (ListUtil.isNotEmpty(indexList)) {
  173. retrievalDTO.setNameList(BeanUtil.listCopyTo(indexList, RetrievalConceptDTO.class));
  174. }
  175. break;
  176. case 13:
  177. medRetrievalVO.setTypeId(LexiconEnum.Tcmsyndrome.getKey());
  178. medRetrievalVO.getTypeIds().add(LexiconEnum.Tcmsyndrome.getKey());
  179. indexList = klConceptFacade.index(medRetrievalVO);
  180. if (ListUtil.isNotEmpty(indexList)) {
  181. retrievalDTO.setNameList(BeanUtil.listCopyTo(indexList, RetrievalConceptDTO.class));
  182. }
  183. break;
  184. case 14:
  185. medRetrievalVO.setTypeId(LexiconEnum.Anesthesia.getKey());
  186. medRetrievalVO.getTypeIds().add(LexiconEnum.Anesthesia.getKey());
  187. indexList = klConceptFacade.index(medRetrievalVO);
  188. if (ListUtil.isNotEmpty(indexList)) {
  189. retrievalDTO.setNameList(BeanUtil.listCopyTo(indexList, RetrievalConceptDTO.class));
  190. }
  191. break;
  192. case 15:
  193. medRetrievalVO.setTypeId(LexiconEnum.Form.getKey());
  194. medRetrievalVO.getTypeIds().add(LexiconEnum.Form.getKey());
  195. indexList = klConceptFacade.index(medRetrievalVO);
  196. if (ListUtil.isNotEmpty(indexList)) {
  197. retrievalDTO.setNameList(BeanUtil.listCopyTo(indexList, RetrievalConceptDTO.class));
  198. }
  199. break;
  200. case 16:
  201. medRetrievalVO.setTypeId(LexiconEnum.AdministrationRoute.getKey());
  202. medRetrievalVO.getTypeIds().add(LexiconEnum.AdministrationRoute.getKey());
  203. indexList = klConceptFacade.index(medRetrievalVO);
  204. if (ListUtil.isNotEmpty(indexList)) {
  205. retrievalDTO.setNameList(BeanUtil.listCopyTo(indexList, RetrievalConceptDTO.class));
  206. }
  207. break;
  208. case 17:
  209. medRetrievalVO.setTypeId(LexiconEnum.Physicotherapy.getKey());
  210. medRetrievalVO.getTypeIds().add(LexiconEnum.Physicotherapy.getKey());
  211. indexList = klConceptFacade.index(medRetrievalVO);
  212. if (ListUtil.isNotEmpty(indexList)) {
  213. retrievalDTO.setNameList(BeanUtil.listCopyTo(indexList, RetrievalConceptDTO.class));
  214. }
  215. break;
  216. }
  217. return retrievalDTO;
  218. }
  219. /**
  220. * 医学知识(静态信息)检索
  221. *
  222. * @param staticKnowledgeIndexVO
  223. * @return
  224. */
  225. public List<StaticKnowledgeIndexDTO> staticKnowledgeIndex(StaticKnowledgeIndexVO staticKnowledgeIndexVO) {
  226. staticKnowledgeIndexVO.setTypeIds(new ArrayList<>());
  227. if (staticKnowledgeIndexVO.getSize() == null) {
  228. staticKnowledgeIndexVO.setSize(100);
  229. }
  230. List<Integer> types = staticKnowledgeIndexVO.getTypes();
  231. List<DictionaryInfoDTO> dicType = klDictionaryInfoFacade.getListByGroupType(10);
  232. Map<String, String> dicTypeMap = EntityUtil.makeMapWithKeyValue(dicType, "name", "val");
  233. List<DictionaryInfoDTO> dicTypeName = klDictionaryInfoFacade.getListByGroupType(13);
  234. List<DictionaryInfoDTO> dicType_back = dictionaryFacade.getListByGroupType(10);
  235. Map<String, String> dicTypeMap_back = EntityUtil.makeMapWithKeyValue(dicType_back, "name", "val");
  236. List<DictionaryInfoDTO> dicTypeName_back = dictionaryFacade.getListByGroupType(13);
  237. //检索类型(多选):0-全部、1-诊断、2-药品、3-检验、5-检查、6-手术和操作、8-量表、9-护理
  238. if (ListUtil.isEmpty(types)
  239. || (ListUtil.isNotEmpty(types) && types.contains(0))) {
  240. staticKnowledgeIndexVO.getTypeIds().addAll(Arrays.asList(LexiconEnum.Disease.getKey(),
  241. LexiconEnum.Medicine.getKey(),
  242. LexiconEnum.LisName.getKey(),
  243. LexiconEnum.LisSubName.getKey(),
  244. LexiconEnum.PacsName.getKey(),
  245. LexiconEnum.PacsSubName.getKey(),
  246. LexiconEnum.Operation.getKey(),
  247. LexiconEnum.Scale.getKey(),
  248. LexiconEnum.Nurse.getKey(),
  249. LexiconEnum.Law.getKey()));
  250. } else {
  251. if (types.contains(1)) {
  252. staticKnowledgeIndexVO.getTypeIds().add(LexiconEnum.Disease.getKey());
  253. }
  254. if (types.contains(2)) {
  255. staticKnowledgeIndexVO.getTypeIds().add(LexiconEnum.Medicine.getKey());
  256. }
  257. if (types.contains(3)) {
  258. staticKnowledgeIndexVO.getTypeIds().add(LexiconEnum.LisName.getKey());
  259. staticKnowledgeIndexVO.getTypeIds().add(LexiconEnum.LisSubName.getKey());
  260. }
  261. if (types.contains(5)) {
  262. staticKnowledgeIndexVO.getTypeIds().add(LexiconEnum.PacsName.getKey());
  263. staticKnowledgeIndexVO.getTypeIds().add(LexiconEnum.PacsSubName.getKey());
  264. }
  265. if (types.contains(6)) {
  266. staticKnowledgeIndexVO.getTypeIds().add(LexiconEnum.Operation.getKey());
  267. }
  268. if (types.contains(8)) {
  269. staticKnowledgeIndexVO.getTypeIds().add(LexiconEnum.Scale.getKey());
  270. }
  271. if (types.contains(9)) {
  272. staticKnowledgeIndexVO.getTypeIds().add(LexiconEnum.Nurse.getKey());
  273. }
  274. if (types.contains(10)) {
  275. staticKnowledgeIndexVO.getTypeIds().add(LexiconEnum.Law.getKey());
  276. }
  277. }
  278. List<StaticKnowledgeIndexDTO> retList = klConceptFacade.staticIndex(staticKnowledgeIndexVO);
  279. retList.forEach(i -> {
  280. //前端展示
  281. if (staticKnowledgeIndexVO.getHasInfo().equals(1)) {
  282. i.setTypeName(convertTypeName(i.getTypeName(), 2, dicTypeName));
  283. if (dicTypeMap.containsKey(i.getTypeName())) {
  284. i.setType(Integer.valueOf(dicTypeMap.get(i.getTypeName())));
  285. }
  286. } else {
  287. i.setTypeName(convertTypeName(i.getTypeName(), 2, dicTypeName_back));
  288. if (dicTypeMap_back.containsKey(i.getTypeName())) {
  289. i.setType(Integer.valueOf(dicTypeMap_back.get(i.getTypeName())));
  290. }
  291. }
  292. });
  293. return retList;
  294. }
  295. /**
  296. * 经典病历检索
  297. *
  298. * @param staticKnowledgeIndexVO
  299. * @return
  300. */
  301. public List<ClassicCaseIndexDTO> classicCaseIndex(StaticKnowledgeIndexVO staticKnowledgeIndexVO) {
  302. staticKnowledgeIndexVO.setTypeIds(new ArrayList<>());
  303. if (staticKnowledgeIndexVO.getSize() == null) {
  304. staticKnowledgeIndexVO.setSize(100);
  305. }
  306. List<Integer> types = staticKnowledgeIndexVO.getTypes();
  307. List<DictionaryInfoDTO> dicType = klDictionaryInfoFacade.getListByGroupType(10);
  308. Map<String, String> dicTypeMap = EntityUtil.makeMapWithKeyValue(dicType, "name", "val");
  309. List<DictionaryInfoDTO> dicTypeName = klDictionaryInfoFacade.getListByGroupType(13);
  310. List<DictionaryInfoDTO> dicType_back = dictionaryFacade.getListByGroupType(10);
  311. Map<String, String> dicTypeMap_back = EntityUtil.makeMapWithKeyValue(dicType_back, "name", "val");
  312. List<DictionaryInfoDTO> dicTypeName_back = dictionaryFacade.getListByGroupType(13);
  313. //类型检索
  314. staticKnowledgeIndexVO.getTypeIds().add(LexiconEnum.ClassicCase.getKey());
  315. List<ClassicCaseIndexDTO> retList = klConceptFacade.caseIndex(staticKnowledgeIndexVO);
  316. retList.forEach(i -> {
  317. //前端展示
  318. if (staticKnowledgeIndexVO.getHasInfo().equals(1)) {
  319. i.setTypeName(convertTypeName(i.getTypeName(), 2, dicTypeName));
  320. if (dicTypeMap.containsKey(i.getTypeName())) {
  321. i.setType(Integer.valueOf(dicTypeMap.get(i.getTypeName())));
  322. }
  323. } else {
  324. i.setTypeName(convertTypeName(i.getTypeName(), 2, dicTypeName_back));
  325. if (dicTypeMap_back.containsKey(i.getTypeName())) {
  326. i.setType(Integer.valueOf(dicTypeMap_back.get(i.getTypeName())));
  327. }
  328. }
  329. });
  330. return retList;
  331. }
  332. /**
  333. * 页面显示词性和标准词性转换
  334. *
  335. * @param typeName
  336. * @param flag 1-页面词性转标准词性,2- 标准词性转页面词性
  337. * @param dicList
  338. * @return
  339. */
  340. public String convertTypeName(String typeName, Integer flag, List<DictionaryInfoDTO> dicList) {
  341. if (ListUtil.isNotEmpty(dicList)) {
  342. Map<String, String> nameValMap = new HashMap<>();
  343. if (flag.equals(1)) {
  344. nameValMap = EntityUtil.makeMapWithKeyValue(dicList, "name", "val");
  345. } else if (flag.equals(2)) {
  346. nameValMap = EntityUtil.makeMapWithKeyValue(dicList, "val", "name");
  347. }
  348. if (nameValMap.containsKey(typeName)) {
  349. return nameValMap.get(typeName);
  350. }
  351. }
  352. return typeName;
  353. }
  354. }