CommonFacade.java 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  1. package com.diagbot.facade;
  2. import com.diagbot.biz.push.entity.Item;
  3. import com.diagbot.biz.push.entity.Lis;
  4. import com.diagbot.client.CRFServiceClient;
  5. import com.diagbot.client.StandConvertServiceClient;
  6. import com.diagbot.dto.*;
  7. import com.diagbot.enums.ConceptTypeEnum;
  8. import com.diagbot.enums.LexiconEnum;
  9. import com.diagbot.enums.RedisEnum;
  10. import com.diagbot.enums.StandConvertEnum;
  11. import com.diagbot.exception.CommonErrorCode;
  12. import com.diagbot.exception.CommonException;
  13. import com.diagbot.model.ai.AIAnalyze;
  14. import com.diagbot.model.entity.Operation;
  15. import com.diagbot.model.entity.*;
  16. import com.diagbot.model.label.*;
  17. import com.diagbot.rule.CommonRule;
  18. import com.diagbot.util.*;
  19. import com.diagbot.vo.*;
  20. import com.diagbot.vo.neoPushEntity.Diag;
  21. import com.diagbot.vo.neoPushEntity.Drug;
  22. import com.diagbot.vo.neoPushEntity.*;
  23. import com.google.common.collect.Lists;
  24. import org.apache.commons.beanutils.BeanUtils;
  25. import org.apache.commons.lang3.StringUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.beans.factory.annotation.Value;
  28. import org.springframework.stereotype.Component;
  29. import java.lang.reflect.Method;
  30. import java.math.BigDecimal;
  31. import java.util.*;
  32. import java.util.stream.Collectors;
  33. /**
  34. * @Description: 通过业务facade
  35. * @author: zhoutg
  36. * @time: 2018/8/6 9:11
  37. */
  38. @Component
  39. public class CommonFacade {
  40. @Autowired
  41. CRFServiceClient crfServiceClient;
  42. @Autowired
  43. MappingConfigFacade mappingConfigFacade;
  44. @Autowired
  45. TranOperationConfigFacade tranOperationConfigFacade;
  46. @Autowired
  47. CommonRule commonRule;
  48. @Autowired
  49. RedisUtil redisUtil;
  50. @Autowired
  51. NLPFacade nlpFacade;
  52. @Autowired
  53. StandConvertServiceClient standConvertServiceClient;
  54. @Value("${StandConvert.rate}")
  55. String standConvertRate;
  56. /**
  57. * 组装好label
  58. *
  59. * @param searchData
  60. * @param participleFlag
  61. * @return
  62. */
  63. public WordCrfDTO crf_process(SearchData searchData, Boolean participleFlag) {
  64. AIAnalyze aiAnalyze = new AIAnalyze(crfServiceClient);
  65. // 合并既往史:既往史+传染病史+手术外伤史+过敏史+接种史
  66. String unionPasts = searchData.getPasts();
  67. if (StringUtil.isNotBlank(searchData.getInfectious())) { // 传染病史
  68. unionPasts = unionPasts + "。" + searchData.getInfectious();
  69. }
  70. if (StringUtil.isNotBlank(searchData.getSurgical())) { // 手术外伤史
  71. unionPasts = unionPasts + "。" + searchData.getSurgical();
  72. }
  73. if (StringUtil.isNotBlank(searchData.getAllergy())) { // 过敏史
  74. unionPasts = unionPasts + "。" + searchData.getAllergy();
  75. }
  76. if (StringUtil.isNotBlank(searchData.getVaccination())) { // 接种史
  77. unionPasts = unionPasts + "。" + searchData.getVaccination();
  78. }
  79. searchData.setPasts(unionPasts);
  80. WordCrfDTO wordCrfDTO = new WordCrfDTO();
  81. wordCrfDTO.setHospitalId(searchData.getHospitalId());
  82. // 年龄容错处理
  83. if (searchData.getAgeNum() != null) {
  84. wordCrfDTO.setAgeNum(searchData.getAgeNum());
  85. } else {
  86. wordCrfDTO.setAgeNum(CoreUtil.convertAge(searchData.getAge()));
  87. }
  88. wordCrfDTO.setAge(searchData.getAge());
  89. wordCrfDTO.setSex(searchData.getSex());
  90. wordCrfDTO.setDept(searchData.getDept());
  91. if (searchData.getDiseaseName() != null && StringUtils.isNotBlank(searchData.getDiseaseName().getName())) {
  92. wordCrfDTO.setDiseaseName(searchData.getDiseaseName());
  93. }
  94. if (searchData.getOperationName() != null && StringUtils.isNotBlank(searchData.getOperationName().getName())) {
  95. wordCrfDTO.setOperationName(searchData.getOperationName());
  96. }
  97. if (ListUtil.isNotEmpty(searchData.getLis())) {
  98. wordCrfDTO.setLis(searchData.getLis());
  99. }
  100. if (ListUtil.isNotEmpty(searchData.getPacs())) {
  101. wordCrfDTO.setPacs(searchData.getPacs());
  102. }
  103. if (ListUtil.isNotEmpty(searchData.getDrug())) {
  104. wordCrfDTO.setDrug(searchData.getDrug());
  105. }
  106. if (ListUtil.isNotEmpty(searchData.getTransfusion())) {
  107. wordCrfDTO.setTransfusion(searchData.getTransfusion());
  108. }
  109. if (ListUtil.isNotEmpty(searchData.getOperation())) {
  110. wordCrfDTO.setOperation(searchData.getOperation());
  111. }
  112. if (ListUtil.isNotEmpty(searchData.getLisOrder())) {
  113. wordCrfDTO.setLisOrder(searchData.getLisOrder());
  114. }
  115. if (ListUtil.isNotEmpty(searchData.getPacsOrder())) {
  116. wordCrfDTO.setPacsOrder(searchData.getPacsOrder());
  117. }
  118. if (ListUtil.isNotEmpty(searchData.getDrugOrder())) {
  119. wordCrfDTO.setDrugOrder(searchData.getDrugOrder());
  120. }
  121. if (ListUtil.isNotEmpty(searchData.getOperationOrder())) {
  122. wordCrfDTO.setOperationOrder(searchData.getOperationOrder());
  123. }
  124. if (ListUtil.isNotEmpty(searchData.getDiagOrder())) {
  125. wordCrfDTO.setDiagOrder(searchData.getDiagOrder());
  126. }
  127. if (ListUtil.isNotEmpty(searchData.getDiag())) {
  128. wordCrfDTO.setDiag(searchData.getDiag());
  129. }
  130. if (ListUtil.isNotEmpty(searchData.getTransfusionOrder())) {
  131. wordCrfDTO.setTransfusionOrder(searchData.getTransfusionOrder());
  132. }
  133. if (StringUtil.isNotBlank(searchData.getSymptom())) {
  134. wordCrfDTO.setSymptom(searchData.getSymptom());
  135. }
  136. if (StringUtil.isNotBlank(searchData.getChief())) {
  137. wordCrfDTO.setChief(searchData.getChief());
  138. }
  139. if (StringUtil.isNotBlank(unionPasts)) {
  140. wordCrfDTO.setPasts(unionPasts);
  141. }
  142. if (StringUtil.isNotBlank(searchData.getMenstrual())) {
  143. wordCrfDTO.setMenstrual(searchData.getMenstrual());
  144. }
  145. if (StringUtil.isNotBlank(searchData.getFamily())) {
  146. wordCrfDTO.setFamily(searchData.getFamily());
  147. }
  148. if (StringUtil.isNotBlank(searchData.getMarital())) {
  149. wordCrfDTO.setMarital(searchData.getMarital());
  150. }
  151. if (StringUtil.isNotBlank(searchData.getMarriage())) {
  152. wordCrfDTO.setMarriage(searchData.getMarriage());
  153. }
  154. if (StringUtil.isNotBlank(searchData.getPersonal())) {
  155. wordCrfDTO.setPersonal(searchData.getPersonal());
  156. }
  157. if (StringUtil.isNotBlank(searchData.getVital())) {
  158. wordCrfDTO.setVital(searchData.getVital());
  159. }
  160. if (ListUtil.isNotEmpty(searchData.getOtherAdvice())) {
  161. wordCrfDTO.setOtherAdvice(searchData.getOtherAdvice());
  162. }
  163. if (ListUtil.isNotEmpty(searchData.getScale())) {
  164. wordCrfDTO.setScale(searchData.getScale());
  165. }
  166. // 模型处理数据
  167. aiAnalyze.aiProcess(searchData, wordCrfDTO);
  168. // 统一处理化验、辅检、诊断,放入结构化
  169. processLisPacsDiag(wordCrfDTO);
  170. // 现病史的体征内容放入体征标签
  171. processPresentVital(wordCrfDTO);
  172. // 加入分词
  173. if (participleFlag) {
  174. participle(wordCrfDTO);
  175. }
  176. return wordCrfDTO;
  177. }
  178. /**
  179. * 分词
  180. *
  181. * @param wordCrfDTO
  182. */
  183. public void participle(WordCrfDTO wordCrfDTO) {
  184. // 主诉症状分词
  185. participleByType(wordCrfDTO.getChiefLabel().getClinicals(), String.valueOf(LexiconEnum.Symptom.getKey()));
  186. // 现病史症状分词
  187. participleByType(wordCrfDTO.getPresentLabel().getClinicals(), String.valueOf(LexiconEnum.Symptom.getKey()));
  188. }
  189. /**
  190. * 根据类型分词,通用方法
  191. *
  192. * @param tList
  193. * @param type
  194. * @param <T>
  195. */
  196. public <T> void participleByType(List<T> tList, String type) {
  197. List<T> participleList = Lists.newArrayList();
  198. if (ListUtil.isNotEmpty(tList)) {
  199. for (T t : tList) {
  200. String val = ReflectUtil.getProperty(t, "name");
  201. List<String> list = nlpFacade.getByType(val, type);
  202. if (ListUtil.isNotEmpty(list)) {
  203. for (String s : list) {
  204. if (!s.equals(val)) { // 去除自身
  205. try {
  206. T tNew = (T) tList.get(0).getClass().newInstance(); // 泛型不能直接创建对象
  207. BeanUtil.copyProperties(t, tNew);
  208. ReflectUtil.setProperty(tNew, "name", s);
  209. ReflectUtil.setProperty(tNew, "standName", s);
  210. participleList.add(tNew);
  211. } catch (Exception e) {
  212. e.printStackTrace();
  213. }
  214. }
  215. }
  216. }
  217. }
  218. if (ListUtil.isNotEmpty(participleList)) {
  219. tList.addAll(participleList);
  220. }
  221. }
  222. }
  223. /**
  224. * 同义词转换
  225. *
  226. * @param wordCrfDTO
  227. */
  228. public void wordStandConvert(WordCrfDTO wordCrfDTO) {
  229. StandConvert standConvert = dataTypeGet(wordCrfDTO);
  230. Map<String, Map<String, String>> standConvertMap = standConvertCrf(standConvert);
  231. dataTypeSet(wordCrfDTO, standConvertMap);
  232. }
  233. /**
  234. * 获取所有需要转标准词的词
  235. *
  236. * @param wordCrfDTO
  237. * @return
  238. */
  239. public StandConvert dataTypeGet(WordCrfDTO wordCrfDTO) {
  240. StandConvert standConvert = new StandConvert();
  241. // 【所有症状】(主诉、现病史)
  242. List<String> clinicalList = new ArrayList<>();
  243. ChiefLabel chiefLabel = wordCrfDTO.getChiefLabel();
  244. CoreUtil.addList(clinicalList, CoreUtil.getPropertyList(chiefLabel.getClinicals()));
  245. PresentLabel presentLabel = wordCrfDTO.getPresentLabel();
  246. CoreUtil.addList(clinicalList, CoreUtil.getPropertyList(presentLabel.getClinicals()));
  247. standConvert.setClinicalList(clinicalList);
  248. // 【所有疾病】
  249. DiagLabel diagLabel = wordCrfDTO.getDiagLabel();
  250. PastLabel pastLabel = wordCrfDTO.getPastLabel();
  251. List<String> diagList = new ArrayList<>();
  252. // 1、主诉诊断
  253. CoreUtil.addList(diagList, CoreUtil.getPropertyList(chiefLabel.getDiags()));
  254. // 2、现病史诊断
  255. CoreUtil.addList(diagList, CoreUtil.getPropertyList(presentLabel.getDiags()));
  256. // 3、文本诊断
  257. CoreUtil.addList(diagList, CoreUtil.getPropertyList(diagLabel.getDiags()));
  258. // 4、既往史诊断
  259. CoreUtil.addList(diagList, CoreUtil.getPropertyList(pastLabel.getDiags()));
  260. // 5、开单项诊断
  261. CoreUtil.addList(diagList, CoreUtil.filterUniqueList(wordCrfDTO.getDiagOrder()));
  262. // 6、结构化诊断
  263. CoreUtil.addList(diagList, CoreUtil.filterUniqueList(wordCrfDTO.getDiag()));
  264. // 7、选中诊断
  265. if (wordCrfDTO.getDiseaseName() != null && StringUtils.isBlank(wordCrfDTO.getDiseaseName().getUniqueName())) {
  266. diagList.add(wordCrfDTO.getDiseaseName().getName());
  267. }
  268. standConvert.setDiaglList(diagList);
  269. // // 【所有化验】
  270. // List<String> allLis = new ArrayList<>();
  271. // // 1、普通化验——取明细
  272. // CoreUtil.addList(allLis, CoreUtil.filterUniqueList(wordCrfDTO.getLis(), "detailName"));
  273. // // 2、开单化验——取套餐
  274. // CoreUtil.addList(allLis, CoreUtil.filterUniqueList(wordCrfDTO.getLisOrder()));
  275. // standConvert.setLisList(allLis);
  276. //
  277. // // 【所有辅助项目】
  278. // List<String> allPacs = new ArrayList<>();
  279. // // 1、模型解析辅检项目
  280. // CoreUtil.addList(allPacs, CoreUtil.filterUniqueList(wordCrfDTO.getPacsLabel().getItem()));
  281. // // 2、结构化辅检项目
  282. // CoreUtil.addList(allPacs, CoreUtil.filterUniqueList(wordCrfDTO.getPacs()));
  283. // // 3、开单辅检项目
  284. // CoreUtil.addList(allPacs, CoreUtil.filterUniqueList(wordCrfDTO.getPacsOrder()));
  285. // standConvert.setPacsList(allPacs);
  286. // 【所有药品】
  287. List<String> drugList = new ArrayList<>();
  288. // 1、主诉药品
  289. CoreUtil.addList(drugList, CoreUtil.getPropertyList(chiefLabel.getMedicines()));
  290. // 2、现病史药品
  291. CoreUtil.addList(drugList, CoreUtil.getPropertyList(presentLabel.getMedicines()));
  292. // 3、既往史(药物过敏)
  293. CoreUtil.addList(drugList, CoreUtil.getPropertyList(pastLabel.getAllergyMedicines()));
  294. // 4、既往史(药物)
  295. CoreUtil.addList(drugList, CoreUtil.getPropertyList(pastLabel.getMedicines()));
  296. // 5、开单药品
  297. CoreUtil.addList(drugList, CoreUtil.filterUniqueList(wordCrfDTO.getDrugOrder()));
  298. // 6、结构化药品
  299. CoreUtil.addList(drugList, CoreUtil.filterUniqueList(wordCrfDTO.getDrug()));
  300. standConvert.setDrugList(drugList);
  301. // // 【所有手术】
  302. // List<String> operationList = new ArrayList<>();
  303. // // 1、主诉手术
  304. // CoreUtil.addList(operationList, CoreUtil.getPropertyList(chiefLabel.getOperations()));
  305. // // 2、现病史手术
  306. // CoreUtil.addList(operationList, CoreUtil.getPropertyList(presentLabel.getOperations()));
  307. // // 3、既往史手术
  308. // CoreUtil.addList(operationList, CoreUtil.getPropertyList(pastLabel.getOperations()));
  309. // // 4、开单手术
  310. // CoreUtil.addList(operationList, CoreUtil.filterUniqueList(wordCrfDTO.getOperationOrder()));
  311. // // 5、结构化手术
  312. // CoreUtil.addList(operationList, CoreUtil.filterUniqueList(wordCrfDTO.getOperation()));
  313. // // 6、选中手术
  314. // if (wordCrfDTO.getOperationName() != null && StringUtils.isBlank(wordCrfDTO.getOperationName().getUniqueName())) {
  315. // operationList.add(wordCrfDTO.getOperationName().getName());
  316. // }
  317. // standConvert.setOperationList(operationList);
  318. // 【所有体征】(临床表现、体征结果)
  319. List<String> vitalList = new ArrayList<>();
  320. VitalLabel vitalLabel = wordCrfDTO.getVitalLabel();
  321. CoreUtil.addList(vitalList, CoreUtil.getPropertyList(vitalLabel.getVitals()));
  322. CoreUtil.addList(vitalList, CoreUtil.getPropertyList(vitalLabel.getClinicals()));
  323. standConvert.setVitalList(vitalList);
  324. // 【输血】
  325. List<String> transfusionList = new ArrayList<>();
  326. CoreUtil.addList(transfusionList, CoreUtil.filterUniqueList(wordCrfDTO.getTransfusionOrder()));
  327. standConvert.setTransfusionList(transfusionList);
  328. return standConvert;
  329. }
  330. /**
  331. * 标准词set到label中
  332. *
  333. * @param wordCrfDTO
  334. * @param map
  335. */
  336. public void dataTypeSet(WordCrfDTO wordCrfDTO, Map<String, Map<String, String>> map) {
  337. ChiefLabel chiefLabel = wordCrfDTO.getChiefLabel();
  338. PresentLabel presentLabel = wordCrfDTO.getPresentLabel();
  339. PastLabel pastLabel = wordCrfDTO.getPastLabel();
  340. DiagLabel diagLabel = wordCrfDTO.getDiagLabel();
  341. List<Lis> lis = wordCrfDTO.getLis();
  342. List<Item> pacsList = wordCrfDTO.getPacsLabel().getItem();
  343. VitalLabel vitalLabel = wordCrfDTO.getVitalLabel();
  344. // 【症状回填】
  345. // CoreUtil.setPropertyList(chiefLabel.getClinicals(), map.get(StandConvertEnum.symptom.toString()));
  346. // CoreUtil.setPropertyList(presentLabel.getClinicals(), map.get(StandConvertEnum.symptom.toString()));
  347. // 【诊断回填】
  348. // 1、主诉诊断
  349. CoreUtil.setPropertyList(chiefLabel.getDiags(), map.get(StandConvertEnum.disease.toString()));
  350. // 2、现病史诊断
  351. CoreUtil.setPropertyList(presentLabel.getDiags(), map.get(StandConvertEnum.disease.toString()));
  352. // 3、文本诊断
  353. CoreUtil.setPropertyList(diagLabel.getDiags(), map.get(StandConvertEnum.disease.toString()));
  354. // 4、既往史诊断
  355. CoreUtil.setPropertyList(pastLabel.getDiags(), map.get(StandConvertEnum.disease.toString()));
  356. // 5、开单项诊断
  357. CoreUtil.setPropertyList(wordCrfDTO.getDiagOrder(), "name", "uniqueName", map.get(StandConvertEnum.disease.toString()));
  358. // 6、结构化诊断
  359. CoreUtil.setPropertyList(wordCrfDTO.getDiag(), "name", "uniqueName", map.get(StandConvertEnum.disease.toString()));
  360. // 7、选中诊断
  361. CoreUtil.setPropertyList(wordCrfDTO.getDiseaseName(), "name", "uniqueName", map.get(StandConvertEnum.disease.toString()));
  362. // 【药品回填】
  363. // 1、主诉药品
  364. CoreUtil.setPropertyList(chiefLabel.getMedicines(), map.get(StandConvertEnum.drug.toString()));
  365. // 2、现病史药品
  366. CoreUtil.setPropertyList(presentLabel.getMedicines(), map.get(StandConvertEnum.drug.toString()));
  367. // 3、既往史(药物过敏)
  368. CoreUtil.setPropertyList(pastLabel.getAllergyMedicines(), map.get(StandConvertEnum.drug.toString()));
  369. // 4、既往史(药物)
  370. CoreUtil.setPropertyList(pastLabel.getMedicines(), map.get(StandConvertEnum.drug.toString()));
  371. // 5、开单药品
  372. CoreUtil.setPropertyList(wordCrfDTO.getDrugOrder(), "name", "uniqueName", map.get(StandConvertEnum.drug.toString()));
  373. // 6、结构化药品
  374. CoreUtil.setPropertyList(wordCrfDTO.getDrug(), "name", "uniqueName", map.get(StandConvertEnum.drug.toString()));
  375. // // 【化验回填】
  376. // // 1、普通化验
  377. // CoreUtil.setPropertyList(lis, "detailName", "uniqueName", map.get(StandConvertEnum.lis.toString()));
  378. // // 2、开单化验——取套餐
  379. // CoreUtil.setPropertyList(wordCrfDTO.getLisOrder(), "name", "uniqueName", map.get(StandConvertEnum.lis.toString()));
  380. //
  381. // // 【辅助项目回填】
  382. // // 1、模型解析辅检项目
  383. // CoreUtil.setPropertyList(pacsList, "name", "uniqueName", map.get(StandConvertEnum.pacs.toString()));
  384. // // 2、结构化辅检项目
  385. // CoreUtil.setPropertyList(wordCrfDTO.getPacs(), "name", "uniqueName", map.get(StandConvertEnum.pacs.toString()));
  386. // // 3、开单辅检项目
  387. // CoreUtil.setPropertyList(wordCrfDTO.getPacsOrder(), "name", "uniqueName", map.get(StandConvertEnum.pacs.toString()));
  388. // CoreUtil.setUninameFromDetail(wordCrfDTO.getLis(), "detailName");
  389. // CoreUtil.setUninameFromDetail(wordCrfDTO.getLisOrder(), "name");
  390. lisGetAndSet(wordCrfDTO);
  391. pacsGetAndSet(wordCrfDTO);
  392. // 【体征回填】
  393. // CoreUtil.setPropertyList(vitalLabel.getVitals(), map.get(StandConvertEnum.vital.toString()));
  394. // CoreUtil.setPropertyList(vitalLabel.getClinicals(), map.get(StandConvertEnum.vital.toString()));
  395. // 【手术回填】
  396. // 1、主诉手术
  397. // CoreUtil.setPropertyList(chiefLabel.getOperations(), map.get(StandConvertEnum.operation.toString()));
  398. // // 2、现病史手术
  399. // CoreUtil.setPropertyList(presentLabel.getOperations(), map.get(StandConvertEnum.operation.toString()));
  400. // // 3、既往史手术
  401. // CoreUtil.setPropertyList(pastLabel.getOperations(), map.get(StandConvertEnum.operation.toString()));
  402. // // 4、开单手术
  403. // CoreUtil.setPropertyList(wordCrfDTO.getOperationOrder(), "name", "uniqueName", map.get(StandConvertEnum.operation.toString()));
  404. // // 5、结构化手术
  405. // CoreUtil.setPropertyList(wordCrfDTO.getOperation(), "name", "uniqueName", map.get(StandConvertEnum.operation.toString()));
  406. // // 6、选中手术
  407. // CoreUtil.setPropertyList(wordCrfDTO.getOperationName(), "name", "uniqueName", map.get(StandConvertEnum.operation.toString()));
  408. operateGetAndSet(wordCrfDTO);
  409. //【输血回填】
  410. CoreUtil.setPropertyList(wordCrfDTO.getTransfusionOrder(), "name", "uniqueName", map.get(StandConvertEnum.transfusion.toString()));
  411. }
  412. /**
  413. * 标准词转换
  414. * 类型,疾病: disease,症状: symptom,手术和操作:operation,药品: drug,实验室检查:lis,辅助检查:pacs, 辅助检查:vital"
  415. *
  416. * @param standConvert
  417. * @return Map<String , Map < String , String>> -->Map<类型, Map<原始词, 标准词>>
  418. */
  419. public Map<String, Map<String, String>> standConvertCrf(StandConvert standConvert) {
  420. Map<String, Map<String, String>> map = new LinkedHashMap<>();
  421. List<StandConvertCrfVO> standConvertCrfVOList = new ArrayList<>();
  422. List<String> clinicalConList = getConvertList(standConvert.getClinicalList(), StandConvertEnum.symptom.toString(), standConvertCrfVOList);
  423. // List<String> operationConList = getConvertList(standConvert.getOperationList(), StandConvertEnum.operation.toString(), standConvertCrfVOList);
  424. List<String> drugConList = getConvertList(standConvert.getDrugList(), StandConvertEnum.drug.toString(), standConvertCrfVOList);
  425. List<String> vitallConList = getConvertList(standConvert.getVitalList(), StandConvertEnum.vital.toString(), standConvertCrfVOList);
  426. List<String> diseaseConList = getConvertList(standConvert.getDiaglList(), StandConvertEnum.disease.toString(), standConvertCrfVOList);
  427. // List<String> pacsConList = getConvertList(standConvert.getPacsList(), StandConvertEnum.pacs.toString(), standConvertCrfVOList);
  428. // List<String> lisConList = getConvertList(standConvert.getLisList(), StandConvertEnum.lis.toString(), standConvertCrfVOList);
  429. List<String> transfusionConList = getConvertList(standConvert.getTransfusionList(), StandConvertEnum.transfusion.toString(), standConvertCrfVOList);
  430. StandConvertCrfBatchDTO standConvertCrfBatchDTO = new StandConvertCrfBatchDTO();
  431. if (!(ListUtil.isEmpty(clinicalConList)
  432. // && ListUtil.isEmpty(operationConList)
  433. && ListUtil.isEmpty(drugConList)
  434. && ListUtil.isEmpty(vitallConList)
  435. && ListUtil.isEmpty(diseaseConList)
  436. // && ListUtil.isEmpty(pacsConList)
  437. // && ListUtil.isEmpty(lisConList)
  438. && ListUtil.isEmpty(transfusionConList))) {
  439. try {
  440. standConvertCrfBatchDTO = standConvertServiceClient.similarityBatch(standConvertCrfVOList);
  441. } catch (Exception e) {
  442. throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "标准词转换【服务器】挂了!" + e.getMessage());
  443. }
  444. }
  445. Map<String, Map<String, StandConvertCrfDTO>> crfMap = standConvertCrfBatchDTO.getData();
  446. getConvertMap(crfMap, StandConvertEnum.symptom.toString(), clinicalConList, standConvert.getClinicalList(), map);
  447. // getConvertMap(crfMap, StandConvertEnum.operation.toString(), operationConList, standConvert.getOperationList(), map);
  448. getConvertMap(crfMap, StandConvertEnum.drug.toString(), drugConList, standConvert.getDrugList(), map);
  449. getConvertMap(crfMap, StandConvertEnum.vital.toString(), vitallConList, standConvert.getVitalList(), map);
  450. getConvertMap(crfMap, StandConvertEnum.disease.toString(), diseaseConList, standConvert.getDiaglList(), map);
  451. // getConvertMap(crfMap, StandConvertEnum.pacs.toString(), pacsConList, standConvert.getPacsList(), map);
  452. // getConvertMap(crfMap, StandConvertEnum.lis.toString(), lisConList, standConvert.getLisList(), map);
  453. getConvertMap(crfMap, StandConvertEnum.transfusion.toString(), transfusionConList, standConvert.getTransfusionList(), map);
  454. return map;
  455. }
  456. /**
  457. * 获取标准词转换map结果,并更新redis
  458. *
  459. * @param crfDTO
  460. * @param type
  461. * @param convertList
  462. * @param map
  463. */
  464. public void getConvertMapDisease(Map<String, Map<String, StandConvertCrfDTO>> crfDTO, String type, List<String> convertList,
  465. List<String> originList, Map<String, Map<String, String>> map) {
  466. Map<String, String> typeMap = new LinkedHashMap<>();
  467. if (ListUtil.isNotEmpty(convertList)) {
  468. Map<String, StandConvertCrfDTO> crfMap = crfDTO.get(type);
  469. for (String s : convertList) {
  470. boolean convertFlag = false;
  471. String lastS = s;
  472. if (StringUtil.isBlank(s)) {
  473. continue;
  474. }
  475. if (crfMap != null) {
  476. StandConvertCrfDTO standConvertCrfDTO = crfMap.get(s);
  477. if (standConvertCrfDTO != null) {
  478. List<Map<String, String>> list = standConvertCrfDTO.getStandard_words();
  479. if (ListUtil.isEmpty(list)) {
  480. redisUtil.updateValue(type + "Conv:" + s, "");
  481. } else {
  482. String rateStr = standConvertCrfDTO.getStandard_words().get(0).get("rate");
  483. if (StringUtil.isBlank(rateStr)) {
  484. redisUtil.updateValue(type + "Conv:" + s, "");
  485. } else {
  486. BigDecimal rate = new BigDecimal(rateStr);
  487. int flag = rate.compareTo(new BigDecimal(standConvertRate));
  488. if (flag < 0) {
  489. redisUtil.updateValue(type + "Conv:" + s, "");
  490. } else {
  491. redisUtil.updateValue(type + "Conv:" + s, standConvertCrfDTO.getStandard_words().get(0).get("standard_word"));
  492. lastS = standConvertCrfDTO.getStandard_words().get(0).get("standard_word");
  493. convertFlag = true;
  494. }
  495. }
  496. }
  497. } else {
  498. redisUtil.updateValue(type + "Conv:" + s, "");
  499. }
  500. } else {
  501. redisUtil.updateValue(type + "Conv:" + s, "");
  502. }
  503. if (convertFlag) {
  504. typeMap.put(s, lastS);
  505. } else {
  506. typeMap.put(s, "");
  507. }
  508. }
  509. }
  510. // 将所有的词放入typeMap中
  511. for (String s : originList) {
  512. if (!typeMap.containsKey(s)) {
  513. String value = redisUtil.get(type + "Conv:" + s);
  514. typeMap.put(s, value);
  515. }
  516. }
  517. map.put(type, typeMap);
  518. }
  519. /**
  520. * 入参数据处理
  521. *
  522. * @param wordList
  523. * @param type
  524. * @param standConvertCrfVOList
  525. */
  526. public List<String> getConvertList(List<String> wordList, String type, List<StandConvertCrfVO> standConvertCrfVOList) {
  527. List<String> convertList = new ArrayList<>();
  528. if (ListUtil.isEmpty(wordList)) {
  529. return null;
  530. }
  531. if (ListUtil.isNotEmpty(wordList)) {
  532. for (String s : wordList) {
  533. String value = redisUtil.get(type + "Conv:" + s);
  534. if (value == null) {
  535. StandConvertCrfVO standConvertCrfVO = new StandConvertCrfVO();
  536. standConvertCrfVO.setWord_type(type);
  537. standConvertCrfVO.setWord(s);
  538. standConvertCrfVOList.add(standConvertCrfVO);
  539. if (!convertList.contains(s)) {
  540. convertList.add(s);
  541. }
  542. }
  543. }
  544. }
  545. return convertList;
  546. }
  547. /**
  548. * 获取标准词转换map结果,并更新redis
  549. *
  550. * @param crfDTO
  551. * @param type
  552. * @param convertList
  553. * @param map
  554. */
  555. public void getConvertMap(Map<String, Map<String, StandConvertCrfDTO>> crfDTO, String type, List<String> convertList,
  556. List<String> originList, Map<String, Map<String, String>> map) {
  557. Map<String, String> typeMap = new LinkedHashMap<>();
  558. if (ListUtil.isNotEmpty(convertList)) {
  559. Map<String, StandConvertCrfDTO> crfMap = crfDTO.get(type);
  560. for (String s : convertList) {
  561. String lastS = s;
  562. if (StringUtil.isBlank(s)) {
  563. continue;
  564. }
  565. if (crfMap != null) {
  566. StandConvertCrfDTO standConvertCrfDTO = crfMap.get(s);
  567. if (standConvertCrfDTO != null) {
  568. List<Map<String, String>> list = standConvertCrfDTO.getStandard_words();
  569. if (ListUtil.isEmpty(list)) {
  570. redisUtil.updateValue(type + "Conv:" + s, s);
  571. } else {
  572. String rateStr = standConvertCrfDTO.getStandard_words().get(0).get("rate");
  573. if (StringUtil.isBlank(rateStr)) {
  574. redisUtil.updateValue(type + "Conv:" + s, s);
  575. } else {
  576. BigDecimal rate = new BigDecimal(rateStr);
  577. int flag = rate.compareTo(new BigDecimal(standConvertRate));
  578. if (flag < 0) {
  579. redisUtil.updateValue(type + "Conv:" + s, s);
  580. } else {
  581. redisUtil.updateValue(type + "Conv:" + s, standConvertCrfDTO.getStandard_words().get(0).get("standard_word"));
  582. lastS = standConvertCrfDTO.getStandard_words().get(0).get("standard_word");
  583. }
  584. }
  585. }
  586. } else {
  587. redisUtil.updateValue(type + "Conv:" + s, s);
  588. }
  589. } else {
  590. redisUtil.updateValue(type + "Conv:" + s, s);
  591. }
  592. typeMap.put(s, lastS);
  593. }
  594. }
  595. // 将所有的词放入typeMap中
  596. for (String s : originList) {
  597. if (!typeMap.containsKey(s)) {
  598. String value = redisUtil.get(type + "Conv:" + s);
  599. typeMap.put(s, value);
  600. }
  601. }
  602. map.put(type, typeMap);
  603. }
  604. /**
  605. * 手术映射(关闭同义词转换)
  606. *
  607. * @param wordCrfDTO
  608. */
  609. public void operateGetAndSet(WordCrfDTO wordCrfDTO) {
  610. // 【所有手术】
  611. List<String> operationList = new ArrayList<>();
  612. // 1、主诉手术
  613. CoreUtil.addList(operationList, CoreUtil.getPropertyList(wordCrfDTO.getChiefLabel().getOperations()));
  614. // 2、现病史手术
  615. CoreUtil.addList(operationList, CoreUtil.getPropertyList(wordCrfDTO.getPresentLabel().getOperations()));
  616. // 3、既往史手术
  617. CoreUtil.addList(operationList, CoreUtil.getPropertyList(wordCrfDTO.getPastLabel().getOperations()));
  618. // 4、开单手术
  619. CoreUtil.addList(operationList, CoreUtil.filterUniqueList(wordCrfDTO.getOperationOrder()));
  620. // 5、结构化手术
  621. CoreUtil.addList(operationList, CoreUtil.filterUniqueList(wordCrfDTO.getOperation()));
  622. // 6、选中手术
  623. if (wordCrfDTO.getOperationName() != null && StringUtils.isBlank(wordCrfDTO.getOperationName().getUniqueName())) {
  624. operationList.add(wordCrfDTO.getOperationName().getName());
  625. }
  626. operationList = operationList
  627. .stream()
  628. .distinct()
  629. .collect(Collectors.toList());
  630. // Map<String, Map<String, Long>> configMap = new LinkedHashMap<>();
  631. if (ListUtil.isNotEmpty(operationList)) {
  632. // configMap = tranOperationConfigFacade.getConfigMap(wordCrfDTO.getHospitalId(), operationList, null);
  633. Map<String, Map<String, Map<String, List<String>>>> operstionMap = mappingConfigFacade.groupByHisNameWithName(operationList, ConceptTypeEnum.Operation.getKey(), wordCrfDTO.getHospitalId());
  634. // 1、主诉手术
  635. // setListProperty(wordCrfDTO.getChiefLabel(), "operations", "standName", configMap);
  636. setListProperty(wordCrfDTO.getChiefLabel(), "operations", ConceptTypeEnum.Operation.getKey(), "StandName", operstionMap);
  637. // 2、现病史手术
  638. // setListProperty(wordCrfDTO.getPresentLabel(), "operations", "standName", configMap);
  639. setListProperty(wordCrfDTO.getPresentLabel(), "operations", ConceptTypeEnum.Operation.getKey(), "StandName", operstionMap);
  640. // 3、既往史手术
  641. // setListProperty(wordCrfDTO.getPastLabel(), "operations", "standName", configMap);
  642. setListProperty(wordCrfDTO.getPastLabel(), "operations", ConceptTypeEnum.Operation.getKey(), "StandName", operstionMap);
  643. // 4、结构化手术
  644. // setListProperty(wordCrfDTO, "operation", "uniqueName", configMap);
  645. setListProperty(wordCrfDTO, "operation", ConceptTypeEnum.Operation.getKey(), "UniqueName", operstionMap);
  646. // 5、手术
  647. // setListProperty(wordCrfDTO, "operationOrder", "uniqueName", configMap);
  648. setListProperty(wordCrfDTO, "operationOrder", ConceptTypeEnum.Operation.getKey(), "UniqueName", operstionMap);
  649. // 6、选中手术
  650. if (wordCrfDTO.getOperationName() != null &&
  651. StringUtil.isNotBlank(wordCrfDTO.getOperationName().getName()) &&
  652. StringUtil.isBlank(wordCrfDTO.getOperationName().getUniqueName())) {
  653. wordCrfDTO.getOperationName().setUniqueName(wordCrfDTO.getOperationName().getName());
  654. }
  655. }
  656. }
  657. /**
  658. * 辅检映射(关闭同义词转换)
  659. *
  660. * @param wordCrfDTO
  661. */
  662. public void pacsGetAndSet(WordCrfDTO wordCrfDTO) {
  663. // 【所有辅检】
  664. List<String> pacsList = new ArrayList<>();
  665. // 1、结构化
  666. CoreUtil.addList(pacsList, CoreUtil.filterUniqueList(wordCrfDTO.getPacs()));
  667. // // 2、开单
  668. CoreUtil.addList(pacsList, CoreUtil.filterUniqueList(wordCrfDTO.getPacsOrder()));
  669. PacsLabel pacsLabel = wordCrfDTO.getPacsLabel();
  670. if (pacsLabel != null) {
  671. pacsList = pacsLabel.getItem().stream()
  672. .map(x -> x.getName())
  673. .collect(Collectors.toList());
  674. }
  675. if (ListUtil.isNotEmpty(pacsList)) {
  676. Map<String, Map<String, Map<String, List<String>>>> pacsMap = mappingConfigFacade.groupByHisNameWithName(pacsList, ConceptTypeEnum.Pacs.getKey(), wordCrfDTO.getHospitalId());
  677. setListProperty(wordCrfDTO, "pacs", ConceptTypeEnum.Pacs.getKey(), "UniqueName", pacsMap);
  678. setListProperty(wordCrfDTO, "pacsOrder", ConceptTypeEnum.Pacs.getKey(), "UniqueName", pacsMap);
  679. setListProperty(pacsLabel, "item", ConceptTypeEnum.Pacs.getKey(), "UniqueName", pacsMap);
  680. }
  681. }
  682. /**
  683. * 化验映射(关闭同义词转换)
  684. *
  685. * @param wordCrfDTO
  686. */
  687. public void lisGetAndSet(WordCrfDTO wordCrfDTO) {
  688. //化验公表转换
  689. List<String> lisHisNameList = Lists.newArrayList();
  690. // 【所有化验】
  691. List<Lis> lisList = wordCrfDTO.getLis();
  692. if (ListUtil.isNotEmpty(lisList)) {
  693. lisHisNameList.addAll(lisList
  694. .stream()
  695. .filter(i -> StringUtil.isNotBlank(i.getName()) || StringUtil.isNotBlank(i.getUniqueName()))
  696. .map(i -> i.getName())
  697. .collect(Collectors.toList()));
  698. }
  699. lisHisNameList = lisHisNameList
  700. .stream()
  701. .distinct()
  702. .collect(Collectors.toList());
  703. if (ListUtil.isNotEmpty(lisHisNameList)) {
  704. Map<String, Map<String, Map<String, List<String>>>> lisConfigMap = mappingConfigFacade.groupByHisNameWithName(lisHisNameList, ConceptTypeEnum.LisPack.getKey(), wordCrfDTO.getHospitalId());
  705. setListProperty(wordCrfDTO, "lis", ConceptTypeEnum.LisPack.getKey(), "UniqueName", lisConfigMap);
  706. }
  707. }
  708. /**
  709. * 替换映射内容
  710. *
  711. * @param obj 对象
  712. * @param listProperty 获取List属性名
  713. * @param objProperty 对象属性名
  714. * @param configMap 映射Map
  715. */
  716. public <T> void setListProperty(Object obj, String listProperty, String objProperty, Map<String, Map<String, Long>> configMap) {
  717. Object tList = CoreUtil.getFieldValue(obj, listProperty);
  718. List<T> newList = convertStandName((List) tList, configMap, objProperty);
  719. ReflectUtil.setProperty(obj, listProperty, newList);
  720. }
  721. public <T> void setListProperty(Object obj, String listProperty, Integer type, String propertyName, Map<String, Map<String, Map<String, List<String>>>> configMap) {
  722. Object tList = CoreUtil.getFieldValue(obj, listProperty);
  723. List<T> newList = convertStandName((List) tList, type, propertyName, configMap);
  724. ReflectUtil.setProperty(obj, listProperty, newList);
  725. }
  726. /**
  727. * 标准名称转换
  728. *
  729. * @param list
  730. * @param configMap
  731. * @param fieldName
  732. * @param <T>
  733. * @return
  734. */
  735. public <T> List<T> convertStandName(List<T> list, Map<String, Map<String, Long>> configMap, String fieldName) {
  736. List<T> retList = new ArrayList<>();
  737. try {
  738. if (ListUtil.isEmpty(list)) {
  739. return retList;
  740. }
  741. for (T item : list) {
  742. String name = ReflectUtil.getProperty(item, "name");
  743. if (StringUtil.isBlank(name)) {
  744. retList.add(item);
  745. continue;
  746. }
  747. if (fieldName.equals("uniqueName")) {
  748. String uniqueName = ReflectUtil.getProperty(item, "uniqueName");
  749. if (StringUtil.isNotBlank(uniqueName)) {
  750. retList.add(item);
  751. continue;
  752. }
  753. }
  754. if (configMap.containsKey(name)) {
  755. List<String> standNames = new ArrayList<>(configMap.get(name).keySet());
  756. for (String stdName : standNames) {
  757. T o = (T) item.getClass().newInstance();
  758. BeanUtil.copyProperties(item, o);
  759. BeanUtils.copyProperty(o, fieldName, stdName);
  760. retList.add(o);
  761. }
  762. } else {
  763. if (fieldName.equals("uniqueName")) {
  764. BeanUtils.copyProperty(item, fieldName, name);
  765. }
  766. retList.add(item);
  767. }
  768. }
  769. } catch (Exception e) {
  770. e.printStackTrace();
  771. }
  772. return retList;
  773. }
  774. /**
  775. * 标准名称转换
  776. *
  777. * @param list
  778. * @param configMap
  779. * @param type
  780. * @param <T>
  781. * @return
  782. */
  783. public <T> List<T> convertStandName(List<T> list, Integer type, String propertyName, Map<String, Map<String, Map<String, List<String>>>> configMap) {
  784. List<T> retList = new ArrayList<>();
  785. if (ListUtil.isEmpty(list)) {
  786. return list;
  787. }
  788. try {
  789. for (T item : list) {
  790. String name = ReflectUtil.getProperty(item, "name");
  791. if (StringUtil.isBlank(name)) {
  792. retList.add(item);
  793. continue;
  794. }
  795. // String uniqueName = item.getClass().getMethod("getUniqueName").invoke(item).toString();
  796. String uniqueName = ReflectUtil.getProperty(item, "uniqueName");
  797. if (StringUtil.isNotBlank(uniqueName) && !"StandName".equals(propertyName)) {
  798. retList.add(item);
  799. continue;
  800. }
  801. String hisDetailName = "";
  802. if (type.equals(ConceptTypeEnum.LisPack.getKey())) {
  803. hisDetailName = ReflectUtil.getProperty(item, "detailName");
  804. if (StringUtil.isBlank(hisDetailName)) {
  805. hisDetailName = "";
  806. }
  807. }
  808. if (configMap != null && configMap.containsKey(name)) {
  809. Map<String, Map<String, List<String>>> subMap = configMap.get(name);
  810. if (subMap.containsKey(hisDetailName)) {
  811. if (type.equals(ConceptTypeEnum.Drug.getKey())) {
  812. for (Map.Entry<String, List<String>> thirdEntry : subMap.get(hisDetailName).entrySet()) {
  813. if (ListUtil.isNotEmpty(thirdEntry.getValue())) {
  814. for (String form : thirdEntry.getValue()) {
  815. T o = (T) item.getClass().newInstance();
  816. BeanUtil.copyProperties(item, o);
  817. Method setUniqueName = o.getClass().getMethod("set" + propertyName, String.class);
  818. setUniqueName.invoke(o, thirdEntry.getKey());
  819. Method setForm = o.getClass().getMethod("setForm", String.class);
  820. setForm.invoke(o, form);
  821. retList.add(o);
  822. }
  823. } else {
  824. T o = (T) item.getClass().newInstance();
  825. BeanUtil.copyProperties(item, o);
  826. Method setUniqueName = o.getClass().getMethod("set" + propertyName, String.class);
  827. setUniqueName.invoke(o, thirdEntry.getKey());
  828. retList.add(o);
  829. }
  830. }
  831. } else {
  832. List<String> standNames = new ArrayList<>(subMap.get(hisDetailName).keySet());
  833. for (String stdName : standNames) {
  834. T o = (T) item.getClass().newInstance();
  835. BeanUtil.copyProperties(item, o);
  836. Method setUniqueName = o.getClass().getMethod("set" + propertyName, String.class);
  837. setUniqueName.invoke(o, stdName);
  838. retList.add(o);
  839. }
  840. }
  841. } else {
  842. retList.add(item);
  843. }
  844. } else {
  845. if (propertyName.equals("UniqueName")) {
  846. if (StringUtil.isNotBlank(hisDetailName)) {
  847. BeanUtils.copyProperty(item, "uniqueName", hisDetailName);
  848. } else {
  849. BeanUtils.copyProperty(item, "uniqueName", name);
  850. }
  851. }
  852. retList.add(item);
  853. }
  854. }
  855. } catch (Exception e) {
  856. e.printStackTrace();
  857. }
  858. return retList;
  859. }
  860. /**
  861. * 生成给图谱的入参(推送)
  862. */
  863. public NeoPushVO generatePushInput(WordCrfDTO wordCrfDTO) {
  864. NeoPushVO pushVO = new NeoPushVO();
  865. pushVO.setHospitalId(wordCrfDTO.getHospitalId());
  866. ChiefLabel chiefLabel = wordCrfDTO.getChiefLabel();
  867. PresentLabel presentLabel = wordCrfDTO.getPresentLabel();
  868. List<Item> diags = wordCrfDTO.getDiag();
  869. Item diseaseName = wordCrfDTO.getDiseaseName();
  870. PastLabel pastLabel = wordCrfDTO.getPastLabel();
  871. List<Lis> lis = wordCrfDTO.getLis();
  872. // List<Pacs> pacs = wordCrfDTO.getPacs();
  873. // 辅检
  874. PacsLabel pacsLabel = wordCrfDTO.getPacsLabel();
  875. // List<PacsNew> pacsNewList = wordCrfDTO.getPacsLabel().getPacsNewList();
  876. pushVO.setAge(wordCrfDTO.getAge());
  877. pushVO.setSex(wordCrfDTO.getSex());
  878. pushVO.setAgeNum(wordCrfDTO.getAgeNum());
  879. pushVO.setDiaeaseName(diseaseName);
  880. List<Item> depts = wordCrfDTO.getDept();
  881. if (ListUtil.isNotEmpty(depts)) {
  882. List<String> collect = depts.stream().map(x -> x.getUniqueName()).collect(Collectors.toList());
  883. pushVO.setDept(collect);
  884. }
  885. List<String> chiefSymptom = Lists.newArrayList();
  886. List<String> presentSymptom = Lists.newArrayList();
  887. if (chiefLabel != null) {
  888. ChiefPushVo chiefPushVo = new ChiefPushVo();
  889. if (ListUtil.isNotEmpty(chiefLabel.getClinicals())) {
  890. chiefSymptom = chiefLabel.getClinicals().stream().filter(x -> x.getNegative() == null).map(z -> z.getStandName()).collect(Collectors.toList());
  891. List<Symptom> cjiefClinicals = chiefLabel.getClinicals().stream().filter(x -> x.getNegative() == null).map(z ->
  892. {
  893. String name_sy = z.getBodyPart() == null ? z.getStandName() : z.getBodyPart().getName() + z.getStandName();
  894. Symptom symptom = new Symptom();
  895. symptom.setName(name_sy);
  896. return symptom;
  897. }).collect(Collectors.toList());
  898. if (ListUtil.isNotEmpty(cjiefClinicals)) {
  899. chiefPushVo.setSymptoms(cjiefClinicals);
  900. }
  901. }
  902. if (ListUtil.isNotEmpty(chiefLabel.getDiags())) {
  903. List<Diag> chief_diags = chiefLabel.getDiags().stream()
  904. .filter(x -> x.getNegative() == null && StringUtils.isNotBlank(x.getStandName()))
  905. .map(x ->
  906. {
  907. Diag diag = new Diag();
  908. diag.setName(x.getStandName());
  909. return diag;
  910. }).collect(Collectors.toList());
  911. chiefPushVo.setDiags(chief_diags);
  912. }
  913. if (ListUtil.isNotEmpty(chiefLabel.getPds())) {
  914. chiefPushVo.setPds(chiefLabel.getPds());
  915. }
  916. pushVO.setChiefPushVo(chiefPushVo);
  917. }
  918. if (presentLabel != null) {
  919. PresentPushVo presentPushVo = new PresentPushVo();
  920. if (ListUtil.isNotEmpty(presentLabel.getClinicals())) {
  921. presentSymptom = presentLabel.getClinicals().stream().filter(x -> x.getNegative() == null).map(z -> z.getStandName()).collect(Collectors.toList());
  922. List<Symptom> presentClinicals = presentLabel.getClinicals().stream()
  923. .filter(x -> x.getNegative() == null).map(z ->
  924. {
  925. String name_sy = z.getBodyPart() == null ? z.getStandName() : z.getBodyPart().getName() + z.getStandName();
  926. Symptom symptom = new Symptom();
  927. symptom.setName(name_sy);
  928. return symptom;
  929. }).collect(Collectors.toList());
  930. presentPushVo.setSymptoms(presentClinicals);
  931. }
  932. if (ListUtil.isNotEmpty(presentLabel.getDiags())) {
  933. List<Diag> presentdiags = presentLabel.getDiags().stream()
  934. .filter(x -> x.getNegative() == null && StringUtils.isNotBlank(x.getStandName()) && x.getPossible() != null).map
  935. (x -> x.getStandName()).distinct().map(z ->
  936. {
  937. Diag diag = new Diag();
  938. diag.setName(z);
  939. return diag;
  940. }).collect(Collectors.toList());
  941. presentPushVo.setDiags(presentdiags);
  942. }
  943. if (ListUtil.isNotEmpty(presentLabel.getMedicines())) {
  944. List<Drug> presentdrugs = presentLabel.getMedicines().stream().filter(x -> x.getNegative() == null).map(z ->
  945. {
  946. Drug drug = new Drug();
  947. drug.setName(z.getStandName());
  948. return drug;
  949. }).collect(Collectors.toList());
  950. presentPushVo.setDrugs(presentdrugs);
  951. }
  952. pushVO.setPresentPushVo(presentPushVo);
  953. }
  954. presentSymptom.removeAll(chiefSymptom);
  955. chiefSymptom.addAll(presentSymptom);
  956. pushVO.setSymptoms(chiefSymptom);
  957. if (ListUtil.isNotEmpty(lis)) {
  958. LisPushVo lisPushVo = new LisPushVo();
  959. lisPushVo.setLises(lis);
  960. pushVO.setLisPushVo(lisPushVo);
  961. }
  962. // 辅检
  963. if (pacsLabel != null) {
  964. PacsPushVo pacsPushVo = new PacsPushVo();
  965. pacsPushVo.setPacs(pacsLabel.getRes());
  966. pushVO.setPacsPushVo(pacsPushVo);
  967. }
  968. if (ListUtil.isNotEmpty(diags)) {
  969. DiagVo diagVo = new DiagVo();
  970. List<Diag> diseases = diags.stream().map(x -> {
  971. Diag diag = new Diag();
  972. diag.setName(x.getUniqueName());
  973. return diag;
  974. }).collect(Collectors.toList());
  975. diagVo.setDiags(diseases);
  976. pushVO.setDiagVo(diagVo);
  977. }
  978. return pushVO;
  979. }
  980. /**
  981. * 将现病史中提取的体征内容放入体征标签中
  982. *
  983. * @param wordCrfDTO
  984. */
  985. public void processPresentVital(WordCrfDTO wordCrfDTO) {
  986. PresentLabel presentLabel = wordCrfDTO.getPresentLabel();
  987. VitalLabel vitalLabel = wordCrfDTO.getVitalLabel();
  988. if (ListUtil.isNotEmpty(presentLabel.getVitals())) {
  989. vitalLabel.getVitals().addAll(BeanUtil.listCopyTo(presentLabel.getVitals(), Vital.class));
  990. }
  991. if (ListUtil.isNotEmpty(presentLabel.getClinicals())) {
  992. vitalLabel.getClinicals().addAll(BeanUtil.listCopyTo(presentLabel.getClinicals(), Clinical.class));
  993. }
  994. }
  995. /**
  996. * 统一处理化验、辅检、诊断,放入结构化
  997. *
  998. * @param wordCrfDTO
  999. */
  1000. public void processLisPacsDiag(WordCrfDTO wordCrfDTO) {
  1001. DiagLabel diagLabel = wordCrfDTO.getDiagLabel();
  1002. List<com.diagbot.model.entity.Diag> diags = diagLabel.getDiags();
  1003. if (ListUtil.isNotEmpty(diags)) {
  1004. wordCrfDTO.getDiag().addAll(diags.stream().filter(x -> x.getStandName() != null).map(x -> {
  1005. Item i = new Item();
  1006. i.setName(x.getName());
  1007. i.setUniqueName(x.getStandName());
  1008. return i;
  1009. }).collect(Collectors.toList()));
  1010. }
  1011. /**************************化验结构化处理开始*****************************/
  1012. List<Lis> lisList = new ArrayList<>();
  1013. // 处理主诉化验
  1014. getLisStruct(wordCrfDTO.getChiefLabel().getLises(), lisList);
  1015. // 处理现病史化验
  1016. getLisStruct(wordCrfDTO.getPresentLabel().getLises(), lisList);
  1017. // 统一放置化验结构
  1018. if (ListUtil.isNotEmpty(lisList)) {
  1019. wordCrfDTO.getLis().addAll(lisList);
  1020. }
  1021. /*************************化验结构化处理结束******************************/
  1022. /**************************辅检结构化处理开始*****************************/
  1023. // 处理辅检信息
  1024. PacsLabel pacsLabel = wordCrfDTO.getPacsLabel();
  1025. // 处理主诉辅检
  1026. getPacsStruct(pacsLabel, wordCrfDTO.getChiefLabel().getPacsLabel());
  1027. // 处理现病史辅检
  1028. getPacsStruct(pacsLabel, wordCrfDTO.getPresentLabel().getPacsLabel());
  1029. //结构化pacs
  1030. List<com.diagbot.biz.push.entity.Pacs> pacs = wordCrfDTO.getPacs();
  1031. if (ListUtil.isNotEmpty(pacs)) {
  1032. pacs.forEach(p -> {
  1033. Item item = new Item();
  1034. item.setName(p.getName() == null ? "" : p.getName());
  1035. item.setUniqueName(p.getUniqueName() == null ? "" : p.getUniqueName());
  1036. pacsLabel.getItem().add(item);
  1037. });
  1038. }
  1039. // 辅检结果去重
  1040. if (ListUtil.isNotEmpty(pacsLabel.getRes())) {
  1041. dealMsgWithItem(pacsLabel.getRes());
  1042. }
  1043. // 辅检名称去重
  1044. if (ListUtil.isNotEmpty(pacsLabel.getItem())) {
  1045. dealMsgWithItem(pacsLabel.getItem());
  1046. }
  1047. /*************************辅检结构化处理结束******************************/
  1048. }
  1049. public void getPacsStruct(PacsLabel res, PacsLabel dealPacsLabel) {
  1050. List<Item> pacsResList = res.getRes();
  1051. if (dealPacsLabel != null) {
  1052. // 添加辅检项目名称
  1053. if (ListUtil.isNotEmpty(dealPacsLabel.getItem())) {
  1054. res.getItem().addAll(dealPacsLabel.getItem());
  1055. }
  1056. // 添加辅检的诊断
  1057. if (ListUtil.isNotEmpty(dealPacsLabel.getDisease())) {
  1058. res.getDisease().addAll(dealPacsLabel.getDisease());
  1059. }
  1060. // 添加辅检的描述
  1061. if (ListUtil.isNotEmpty(dealPacsLabel.getPacsResults())) {
  1062. res.getPacsResults().addAll(dealPacsLabel.getPacsResults());
  1063. }
  1064. }
  1065. if (ListUtil.isNotEmpty(res.getDisease())) {
  1066. for (Pacs pacs : res.getDisease()) {
  1067. Item item = new Item();
  1068. item.setName(pacs.getName() == null ? "" : pacs.getName());
  1069. item.setUniqueName(pacs.getStandName() == null ? "" : pacs.getStandName());
  1070. pacsResList.add(item);
  1071. }
  1072. }
  1073. // 添加辅检的描述
  1074. if (ListUtil.isNotEmpty(res.getPacsResults())) {
  1075. for (Pacs pacs : res.getPacsResults()) {
  1076. Item item = new Item();
  1077. item.setName(pacs.getName());
  1078. item.setUniqueName(pacs.getStandName());
  1079. pacsResList.add(item);
  1080. // 部位 + 描述循环放入
  1081. for (BodyPart bodyPart : pacs.getBodyPartList()) {
  1082. Item itemPart = new Item();
  1083. itemPart.setName(bodyPart.getName() + pacs.getName());
  1084. itemPart.setUniqueName(bodyPart.getStandName() + pacs.getStandName());
  1085. pacsResList.add(itemPart);
  1086. }
  1087. // 描述 + 修饰、 修饰 + 描述 循环放入
  1088. for (Modification modification : pacs.getModification()) {
  1089. Item itemModification = new Item();
  1090. itemModification.setName(pacs.getName() + modification.getName());
  1091. itemModification.setUniqueName(pacs.getStandName() + modification.getStandName());
  1092. pacsResList.add(itemModification);
  1093. Item itemModificationRe = new Item();
  1094. itemModificationRe.setName(modification.getName() + pacs.getName());
  1095. itemModificationRe.setUniqueName(modification.getStandName() + pacs.getStandName());
  1096. pacsResList.add(itemModificationRe);
  1097. }
  1098. }
  1099. }
  1100. }
  1101. /**
  1102. * 获取化验的结构
  1103. *
  1104. * @param lises
  1105. * @param lisList
  1106. */
  1107. public void getLisStruct(List<com.diagbot.model.entity.Lis> lises, List<Lis> lisList) {
  1108. if (ListUtil.isNotEmpty(lises)) {
  1109. lises.stream().forEach(x -> {
  1110. String bigName = x.getBigItem().getName();//大项名
  1111. String detailName = x.getName();//小项名
  1112. String value = x.getPd().getValue();
  1113. String unit = x.getPd().getUnit();
  1114. String standName = x.getStandName();
  1115. lisList.add(getLis(bigName, detailName, value, unit, standName));
  1116. });
  1117. }
  1118. }
  1119. private Lis getLis(String bigName, String detailName, String value, String unit, String uniqueName) {
  1120. Lis lis = new Lis();
  1121. lis.setUnits(unit);
  1122. if (StringUtils.isBlank(unit)) {
  1123. if (CoreUtil.isNumbers(value)) {
  1124. lis.setValue(Double.parseDouble(value));
  1125. } else {
  1126. lis.setOtherValue(value);
  1127. }
  1128. } else {
  1129. lis.setValue(Double.parseDouble(value));
  1130. }
  1131. lis.setDetailName(detailName);
  1132. lis.setName(bigName);
  1133. lis.setUniqueName(uniqueName);
  1134. return lis;
  1135. }
  1136. /**
  1137. * 提示信息去重
  1138. *
  1139. * @param billMsgList
  1140. */
  1141. public void dealMsg(List<BillMsg> billMsgList) {
  1142. if (ListUtil.isNotEmpty(billMsgList)) {
  1143. List<String> msgList = new ArrayList<>();
  1144. Iterator<BillMsg> it = billMsgList.iterator();
  1145. while (it.hasNext()) {
  1146. String msg = it.next().getMsg();
  1147. if (msgList.contains(msg)) {
  1148. it.remove();
  1149. } else {
  1150. msgList.add(msg);
  1151. }
  1152. }
  1153. }
  1154. }
  1155. /**
  1156. * 提示信息去重
  1157. *
  1158. * @param itemList
  1159. */
  1160. public void dealMsgWithItem(List<Item> itemList) {
  1161. if (ListUtil.isNotEmpty(itemList)) {
  1162. List<String> msgList = new ArrayList<>();
  1163. Iterator<Item> it = itemList.iterator();
  1164. while (it.hasNext()) {
  1165. String msg = it.next().getName();
  1166. if (msgList.contains(msg)) {
  1167. it.remove();
  1168. } else {
  1169. msgList.add(msg);
  1170. }
  1171. }
  1172. }
  1173. }
  1174. /**
  1175. * 获取开单项数据,如没有redis数据,则返回null
  1176. *
  1177. * @param ruleVO
  1178. * @return
  1179. */
  1180. public RuleExtDTO getRuleData(RuleVO ruleVO) {
  1181. RuleExtDTO ruleExtDTO = null;
  1182. // 获取规则数据
  1183. RuleDTO ruleDTO = redisUtil.get(RedisEnum.allRule.getName() + ruleVO.getLibType() + "_" + ruleVO.getLibName() + "_" + ruleVO.getSuffix());
  1184. if (ruleDTO == null) {
  1185. // 辅检特殊处理,如果为空,再获取【辅助检查项目】【辅助检查子项目】中另外一个
  1186. if (ruleVO.getLibType().equals(LexiconEnum.PacsName.getKey())) {
  1187. ruleDTO = redisUtil.get("allRule:" + LexiconEnum.PacsSubName.getKey() + "_" + ruleVO.getLibName() + "_" + ruleVO.getSuffix());
  1188. } else if (ruleVO.getLibType().equals(LexiconEnum.PacsSubName.getKey())) {
  1189. ruleDTO = redisUtil.get("allRule:" + LexiconEnum.PacsName.getKey() + "_" + ruleVO.getLibName() + "_" + ruleVO.getSuffix());
  1190. }
  1191. }
  1192. if (ruleDTO != null) {
  1193. ruleExtDTO = new RuleExtDTO();
  1194. BeanUtil.copyProperties(ruleVO, ruleExtDTO);
  1195. BeanUtil.copyProperties(ruleDTO, ruleExtDTO);
  1196. return ruleExtDTO;
  1197. }
  1198. return ruleExtDTO;
  1199. }
  1200. /**
  1201. * 获取【手术数据源】
  1202. *
  1203. * @param wordCrfDTO
  1204. */
  1205. public List<Operation> getOperationSource(WordCrfDTO wordCrfDTO) {
  1206. List<Operation> operationSource = new ArrayList<>();
  1207. List<Item> operation = wordCrfDTO.getOperation();
  1208. List<Operation> operationsItem = new ArrayList<>();
  1209. for (Item item : operation) {
  1210. Operation operaData = new Operation();
  1211. operaData.setName(item.getName());
  1212. operaData.setStandName(item.getUniqueName());
  1213. operationsItem.add(operaData);
  1214. }
  1215. CoreUtil.addList(operationSource, wordCrfDTO.getChiefLabel().getOperations()); // 主诉手术
  1216. CoreUtil.addList(operationSource, wordCrfDTO.getPresentLabel().getOperations()); // 现病史手术
  1217. CoreUtil.addList(operationSource, wordCrfDTO.getPastLabel().getOperations()); // 既往史手术
  1218. CoreUtil.addList(operationSource, operationsItem); // 结构化手术
  1219. return operationSource;
  1220. }
  1221. /**
  1222. * 获取【药品过敏数据源】
  1223. *
  1224. * @param wordCrfDTO
  1225. */
  1226. public List<Item> getDrugAllergySource(WordCrfDTO wordCrfDTO) {
  1227. List<Item> drugAllergyAll = new ArrayList<>();
  1228. CoreUtil.addAllConvert(drugAllergyAll, wordCrfDTO.getPastLabel().getAllergyMedicines()); // 既往史过敏药品
  1229. return drugAllergyAll;
  1230. }
  1231. /**
  1232. * 获取【临床表现数据源】
  1233. *
  1234. * @param wordCrfDTO
  1235. */
  1236. public List<Clinical> getClinicalSource(WordCrfDTO wordCrfDTO) {
  1237. List<Clinical> clinicSource = new ArrayList<>();
  1238. CoreUtil.addList(clinicSource, wordCrfDTO.getChiefLabel().getClinicals()); // 主诉临床表现
  1239. CoreUtil.addList(clinicSource, wordCrfDTO.getPresentLabel().getClinicals()); // 现病史临床表现
  1240. return clinicSource;
  1241. }
  1242. /**
  1243. * 获取【诊断数据源】(只留阳性诊断)
  1244. *
  1245. * @param wordCrfDTO
  1246. */
  1247. public List<Item> getDiseaseSource(WordCrfDTO wordCrfDTO) {
  1248. List<Item> diags = new ArrayList<>();
  1249. CoreUtil.addList(diags, wordCrfDTO.getDiag()); // 结构化诊断
  1250. CoreUtil.addAllConvert(diags, wordCrfDTO.getChiefLabel().getDiags());// 主诉诊断
  1251. CoreUtil.addAllConvert(diags, wordCrfDTO.getPresentLabel().getDiags()); // 现病史诊断
  1252. CoreUtil.addAllConvert(diags, wordCrfDTO.getPastLabel().getDiags()); // 既往史诊断
  1253. return diags;
  1254. }
  1255. /**
  1256. * 获取【药品数据源】
  1257. *
  1258. * @param wordCrfDTO
  1259. */
  1260. public List<Item> getDrugSource(WordCrfDTO wordCrfDTO) {
  1261. List<Item> drugAll = new ArrayList<>();
  1262. CoreUtil.addList(drugAll, wordCrfDTO.getDrug());
  1263. CoreUtil.addAllConvert(drugAll, wordCrfDTO.getChiefLabel().getMedicines()); // 主诉药品
  1264. CoreUtil.addAllConvert(drugAll, wordCrfDTO.getPresentLabel().getMedicines());// 现病史药品
  1265. CoreUtil.addAllConvert(drugAll, wordCrfDTO.getPastLabel().getMedicines()); // 既往史药品
  1266. return drugAll;
  1267. }
  1268. }