CommonFacade.java 60 KB

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