CommonFacade.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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.dto.BillMsg;
  6. import com.diagbot.dto.WordCrfDTO;
  7. import com.diagbot.enums.StandConvertEnum;
  8. import com.diagbot.model.ai.AIAnalyze;
  9. import com.diagbot.model.entity.BodyPart;
  10. import com.diagbot.model.entity.Modification;
  11. import com.diagbot.model.entity.Pacs;
  12. import com.diagbot.model.label.ChiefLabel;
  13. import com.diagbot.model.label.DiagLabel;
  14. import com.diagbot.model.label.PacsLabel;
  15. import com.diagbot.model.label.PastLabel;
  16. import com.diagbot.model.label.PresentLabel;
  17. import com.diagbot.model.label.VitalLabel;
  18. import com.diagbot.util.CoreUtil;
  19. import com.diagbot.util.ListUtil;
  20. import com.diagbot.util.StringUtil;
  21. import com.diagbot.vo.NeoPushVO;
  22. import com.diagbot.vo.SearchData;
  23. import com.diagbot.vo.StandConvert;
  24. import com.diagbot.vo.neoPushEntity.*;
  25. import org.apache.commons.lang3.StringUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Component;
  28. import java.util.ArrayList;
  29. import java.util.Iterator;
  30. import java.util.List;
  31. import java.util.Map;
  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. LisConfigFacade lisConfigFacade;
  44. @Autowired
  45. PacsConfigFacade pacsConfigFacade;
  46. //组装好的label
  47. public WordCrfDTO crf_process(SearchData searchData) {
  48. AIAnalyze aiAnalyze = new AIAnalyze(crfServiceClient);
  49. WordCrfDTO wordCrfDTO = new WordCrfDTO();
  50. wordCrfDTO.setHospitalId(searchData.getHospitalId());
  51. // 年龄容错处理
  52. if (searchData.getAgeNum() != null) {
  53. wordCrfDTO.setAgeNum(searchData.getAgeNum());
  54. } else {
  55. wordCrfDTO.setAgeNum(CoreUtil.convertAge(searchData.getAge()));
  56. }
  57. wordCrfDTO.setAge(searchData.getAge());
  58. wordCrfDTO.setSex(searchData.getSex());
  59. wordCrfDTO.setDept(searchData.getDept());
  60. if (searchData.getDiseaseName() != null && StringUtils.isNotBlank(searchData.getDiseaseName().getName())) {
  61. wordCrfDTO.setDiseaseName(searchData.getDiseaseName());
  62. }
  63. if (searchData.getOperationName() != null && StringUtils.isNotBlank(searchData.getOperationName().getName())) {
  64. wordCrfDTO.setOperationName(searchData.getOperationName());
  65. }
  66. if (ListUtil.isNotEmpty(searchData.getLis())) {
  67. wordCrfDTO.setLis(searchData.getLis());
  68. }
  69. if (ListUtil.isNotEmpty(searchData.getPacs())) {
  70. wordCrfDTO.setPacs(searchData.getPacs());
  71. }
  72. if (ListUtil.isNotEmpty(searchData.getDrug())) {
  73. wordCrfDTO.setDrug(searchData.getDrug());
  74. }
  75. if (ListUtil.isNotEmpty(searchData.getOperation())) {
  76. wordCrfDTO.setOperation(searchData.getOperation());
  77. }
  78. if (ListUtil.isNotEmpty(searchData.getLisOrder())) {
  79. wordCrfDTO.setLisOrder(searchData.getLisOrder());
  80. }
  81. if (ListUtil.isNotEmpty(searchData.getPacsOrder())) {
  82. wordCrfDTO.setPacsOrder(searchData.getPacsOrder());
  83. }
  84. if (ListUtil.isNotEmpty(searchData.getDrugOrder())) {
  85. wordCrfDTO.setDrugOrder(searchData.getDrugOrder());
  86. }
  87. if (ListUtil.isNotEmpty(searchData.getOperationOrder())) {
  88. wordCrfDTO.setOperationOrder(searchData.getOperationOrder());
  89. }
  90. if (ListUtil.isNotEmpty(searchData.getDiagOrder())) {
  91. wordCrfDTO.setDiagOrder(searchData.getDiagOrder());
  92. }
  93. if (ListUtil.isNotEmpty(searchData.getDiag())) {
  94. wordCrfDTO.setDiag(searchData.getDiag());
  95. }
  96. if (ListUtil.isNotEmpty(searchData.getTransfusionOrder())) {
  97. wordCrfDTO.setTransfusionOrder(searchData.getTransfusionOrder());
  98. }
  99. if (StringUtil.isNotBlank(searchData.getSymptom())) {
  100. wordCrfDTO.setSymptom(searchData.getSymptom());
  101. }
  102. if (StringUtil.isNotBlank(searchData.getChief())) {
  103. wordCrfDTO.setChief(searchData.getChief());
  104. }
  105. if (StringUtil.isNotBlank(searchData.getPasts())) {
  106. wordCrfDTO.setPasts(searchData.getPasts());
  107. }
  108. if (StringUtil.isNotBlank(searchData.getMenstrual())) {
  109. wordCrfDTO.setMenstrual(searchData.getMenstrual());
  110. }
  111. //模型处理数据
  112. aiAnalyze.aiProcess(searchData, wordCrfDTO);
  113. // 统一处理化验、辅检、诊断,放入结构化
  114. processLisPacsDiag(wordCrfDTO);
  115. // 现病史中体征内容放入体征标签
  116. processPresentVital(wordCrfDTO);
  117. return wordCrfDTO;
  118. }
  119. //返回给图谱的词,这些词需要转换成标准词
  120. public StandConvert dataTypeGet(WordCrfDTO wordCrfDTO) {
  121. StandConvert standConvert = new StandConvert();
  122. // 【所有症状】(主诉、现病史)
  123. List<String> clinicalList = new ArrayList<>();
  124. ChiefLabel chiefLabel = wordCrfDTO.getChiefLabel();
  125. CoreUtil.addList(clinicalList, CoreUtil.getPropertyList(chiefLabel.getClinicals()));
  126. PresentLabel presentLabel = wordCrfDTO.getPresentLabel();
  127. CoreUtil.addList(clinicalList, CoreUtil.getPropertyList(presentLabel.getClinicals()));
  128. standConvert.setClinicalList(clinicalList);
  129. // 【所有疾病】
  130. DiagLabel diagLabel = wordCrfDTO.getDiagLabel();
  131. PastLabel pastLabel = wordCrfDTO.getPastLabel();
  132. List<String> diagList = new ArrayList<>();
  133. // 1、主诉诊断
  134. CoreUtil.addList(diagList, CoreUtil.getPropertyList(chiefLabel.getDiags()));
  135. // 2、现病史诊断
  136. CoreUtil.addList(diagList, CoreUtil.getPropertyList(presentLabel.getDiags()));
  137. // 3、文本诊断
  138. CoreUtil.addList(diagList, CoreUtil.getPropertyList(diagLabel.getDiags()));
  139. // 4、既往史诊断
  140. CoreUtil.addList(diagList, CoreUtil.getPropertyList(pastLabel.getDiags()));
  141. // 5、开单项诊断
  142. CoreUtil.addList(diagList, CoreUtil.filterUniqueList(wordCrfDTO.getDiagOrder()));
  143. // 6、结构化诊断
  144. CoreUtil.addList(diagList, CoreUtil.filterUniqueList(wordCrfDTO.getDiag()));
  145. // 7、选中诊断
  146. if (wordCrfDTO.getDiseaseName() != null && StringUtils.isBlank(wordCrfDTO.getDiseaseName().getUniqueName())) {
  147. diagList.add(wordCrfDTO.getDiseaseName().getName());
  148. }
  149. standConvert.setDiaglList(diagList);
  150. // 【所有化验】
  151. List<String> allLis = new ArrayList<>();
  152. // 1、普通化验——取明细
  153. CoreUtil.addList(allLis, CoreUtil.filterUniqueList(wordCrfDTO.getLis(), "detailName"));
  154. // 2、开单化验——取套餐
  155. CoreUtil.addList(allLis, CoreUtil.filterUniqueList(wordCrfDTO.getLisOrder()));
  156. standConvert.setLisList(allLis);
  157. // 【所有辅助项目】
  158. List<String> allPacs = new ArrayList<>();
  159. // 1、模型解析辅检项目
  160. CoreUtil.addList(allPacs, CoreUtil.filterUniqueList(wordCrfDTO.getPacsLabel().getItem()));
  161. // 2、结构化辅检项目
  162. CoreUtil.addList(allPacs, CoreUtil.filterUniqueList(wordCrfDTO.getPacs()));
  163. // 3、开单辅检项目
  164. CoreUtil.addList(allPacs, CoreUtil.filterUniqueList(wordCrfDTO.getPacsOrder()));
  165. standConvert.setPacsList(allPacs);
  166. // 【所有药品】
  167. List<String> drugList = new ArrayList<>();
  168. // 1、主诉药品
  169. CoreUtil.addList(drugList, CoreUtil.getPropertyList(chiefLabel.getMedicines()));
  170. // 2、现病史药品
  171. CoreUtil.addList(drugList, CoreUtil.getPropertyList(presentLabel.getMedicines()));
  172. // 3、既往史(药物过敏)
  173. CoreUtil.addList(drugList, CoreUtil.getPropertyList(pastLabel.getAllergyMedicines()));
  174. // 4、既往史(药物)
  175. CoreUtil.addList(drugList, CoreUtil.getPropertyList(pastLabel.getMedicines()));
  176. // 5、开单药品
  177. CoreUtil.addList(drugList, CoreUtil.filterUniqueList(wordCrfDTO.getDrugOrder()));
  178. // 6、结构化药品
  179. CoreUtil.addList(drugList, CoreUtil.filterUniqueList(wordCrfDTO.getDrug()));
  180. standConvert.setDrugList(drugList);
  181. // 【所有手术】
  182. List<String> operationList = new ArrayList<>();
  183. // 1、现病史手术
  184. CoreUtil.addList(operationList, CoreUtil.getPropertyList(presentLabel.getOperations()));
  185. // 2、既往史手术
  186. CoreUtil.addList(operationList, CoreUtil.getPropertyList(pastLabel.getOperations()));
  187. // 3、开单手术
  188. CoreUtil.addList(operationList, CoreUtil.filterUniqueList(wordCrfDTO.getOperationOrder()));
  189. // 4、结构化手术
  190. CoreUtil.addList(operationList, CoreUtil.filterUniqueList(wordCrfDTO.getOperation()));
  191. // 5、选中手术
  192. if (wordCrfDTO.getOperationName() != null && StringUtils.isBlank(wordCrfDTO.getOperationName().getUniqueName())) {
  193. operationList.add(wordCrfDTO.getOperationName().getName());
  194. }
  195. standConvert.setOperationList(operationList);
  196. // 【所有体征】(临床表现、体征结果)
  197. List<String> vitalList = new ArrayList<>();
  198. VitalLabel vitalLabel = wordCrfDTO.getVitalLabel();
  199. CoreUtil.addList(vitalList, CoreUtil.getPropertyList(vitalLabel.getVitals()));
  200. CoreUtil.addList(vitalList, CoreUtil.getPropertyList(vitalLabel.getClinicals()));
  201. standConvert.setVitalList(vitalList);
  202. // 【输血】
  203. List<String> transfusionList = new ArrayList<>();
  204. CoreUtil.addList(transfusionList, CoreUtil.filterUniqueList(wordCrfDTO.getTransfusionOrder()));
  205. standConvert.setTransfusionList(transfusionList);
  206. return standConvert;
  207. }
  208. //把图谱返回的标准词set到label中
  209. public void dataTypeSet(WordCrfDTO wordCrfDTO, Map<String, Map<String, String>> map) {
  210. ChiefLabel chiefLabel = wordCrfDTO.getChiefLabel();
  211. PresentLabel presentLabel = wordCrfDTO.getPresentLabel();
  212. PastLabel pastLabel = wordCrfDTO.getPastLabel();
  213. DiagLabel diagLabel = wordCrfDTO.getDiagLabel();
  214. List<Lis> lis = wordCrfDTO.getLis();
  215. List<Item> pacsList = wordCrfDTO.getPacsLabel().getItem();
  216. VitalLabel vitalLabel = wordCrfDTO.getVitalLabel();
  217. // 【症状回填】
  218. CoreUtil.setPropertyList(chiefLabel.getClinicals(), map.get(StandConvertEnum.symptom.toString()));
  219. CoreUtil.setPropertyList(presentLabel.getClinicals(), map.get(StandConvertEnum.symptom.toString()));
  220. // 【诊断回填】
  221. // 1、主诉诊断
  222. CoreUtil.setPropertyList(chiefLabel.getDiags(), map.get(StandConvertEnum.disease.toString()));
  223. // 2、现病史诊断
  224. CoreUtil.setPropertyList(presentLabel.getDiags(), map.get(StandConvertEnum.disease.toString()));
  225. // 3、文本诊断
  226. CoreUtil.setPropertyList(diagLabel.getDiags(), map.get(StandConvertEnum.disease.toString()));
  227. // 4、既往史诊断
  228. CoreUtil.setPropertyList(pastLabel.getDiags(), map.get(StandConvertEnum.disease.toString()));
  229. // 5、开单项诊断
  230. CoreUtil.setPropertyList(wordCrfDTO.getDiagOrder(), "name", "uniqueName", map.get(StandConvertEnum.disease.toString()));
  231. // 6、结构化诊断
  232. CoreUtil.setPropertyList(wordCrfDTO.getDiag(), "name", "uniqueName", map.get(StandConvertEnum.disease.toString()));
  233. // 7、选中诊断
  234. CoreUtil.setPropertyList(wordCrfDTO.getDiseaseName(), "name", "uniqueName", map.get(StandConvertEnum.disease.toString()));
  235. // 【药品回填】
  236. // 1、主诉药品
  237. CoreUtil.setPropertyList(chiefLabel.getMedicines(), map.get(StandConvertEnum.drug.toString()));
  238. // 2、现病史药品
  239. CoreUtil.setPropertyList(presentLabel.getMedicines(), map.get(StandConvertEnum.drug.toString()));
  240. // 3、既往史(药物过敏)
  241. CoreUtil.setPropertyList(pastLabel.getAllergyMedicines(), map.get(StandConvertEnum.drug.toString()));
  242. // 4、既往史(药物)
  243. CoreUtil.setPropertyList(pastLabel.getMedicines(), map.get(StandConvertEnum.drug.toString()));
  244. // 5、开单药品
  245. CoreUtil.setPropertyList(wordCrfDTO.getDrugOrder(), "name", "uniqueName", map.get(StandConvertEnum.drug.toString()));
  246. // 6、结构化药品
  247. CoreUtil.setPropertyList(wordCrfDTO.getDrug(), "name", "uniqueName", map.get(StandConvertEnum.drug.toString()));
  248. // 【化验回填】
  249. // 1、普通化验
  250. CoreUtil.setPropertyList(lis, "detailName", "uniqueName", map.get(StandConvertEnum.lis.toString()));
  251. // 2、开单化验——取套餐
  252. CoreUtil.setPropertyList(wordCrfDTO.getLisOrder(), "name", "uniqueName", map.get(StandConvertEnum.lis.toString()));
  253. // 【辅助项目回填】
  254. // 1、模型解析辅检项目
  255. CoreUtil.setPropertyList(pacsList, "name", "uniqueName", map.get(StandConvertEnum.pacs.toString()));
  256. // 2、结构化辅检项目
  257. CoreUtil.setPropertyList(wordCrfDTO.getPacs(), "name", "uniqueName", map.get(StandConvertEnum.pacs.toString()));
  258. // 3、开单辅检项目
  259. CoreUtil.setPropertyList(wordCrfDTO.getPacsOrder(), "name", "uniqueName", map.get(StandConvertEnum.pacs.toString()));
  260. // 【体征回填】
  261. CoreUtil.setPropertyList(vitalLabel.getVitals(), map.get(StandConvertEnum.vital.toString()));
  262. CoreUtil.setPropertyList(vitalLabel.getClinicals(), map.get(StandConvertEnum.vital.toString()));
  263. // 【手术回填】
  264. // 1、现病史手术
  265. CoreUtil.setPropertyList(presentLabel.getOperations(), map.get(StandConvertEnum.operation.toString()));
  266. // 2、既往史手术
  267. CoreUtil.setPropertyList(pastLabel.getOperations(), map.get(StandConvertEnum.operation.toString()));
  268. // 3、开单手术
  269. CoreUtil.setPropertyList(wordCrfDTO.getOperationOrder(), "name", "uniqueName", map.get(StandConvertEnum.operation.toString()));
  270. // 4、结构化手术
  271. CoreUtil.setPropertyList(wordCrfDTO.getOperation(), "name", "uniqueName", map.get(StandConvertEnum.operation.toString()));
  272. // 5、选中手术
  273. CoreUtil.setPropertyList(wordCrfDTO.getOperationName(), "name", "uniqueName", map.get(StandConvertEnum.operation.toString()));
  274. //【输血回填】
  275. CoreUtil.setPropertyList(wordCrfDTO.getTransfusionOrder(), "name", "uniqueName", map.get(StandConvertEnum.transfusion.toString()));
  276. }
  277. /**
  278. * 生成给图谱的入参(推送)
  279. */
  280. public NeoPushVO generatePushInput(WordCrfDTO wordCrfDTO) {
  281. NeoPushVO pushVO = new NeoPushVO();
  282. ChiefLabel chiefLabel = wordCrfDTO.getChiefLabel();
  283. PresentLabel presentLabel = wordCrfDTO.getPresentLabel();
  284. List<Item> diags = wordCrfDTO.getDiag();
  285. Item diseaseName = wordCrfDTO.getDiseaseName();
  286. PastLabel pastLabel = wordCrfDTO.getPastLabel();
  287. List<Lis> lis = wordCrfDTO.getLis();
  288. // List<Pacs> pacs = wordCrfDTO.getPacs();
  289. // TODO 辅检
  290. PacsLabel pacsLabel = wordCrfDTO.getPacsLabel();
  291. // List<PacsNew> pacsNewList = wordCrfDTO.getPacsLabel().getPacsNewList();
  292. pushVO.setAge(wordCrfDTO.getAge());
  293. pushVO.setSex(wordCrfDTO.getSex());
  294. pushVO.setAgeNum(wordCrfDTO.getAgeNum());
  295. pushVO.setDiaeaseName(diseaseName);
  296. List<Item> depts = wordCrfDTO.getDept();
  297. if (ListUtil.isNotEmpty(depts)) {
  298. List<String> collect = depts.stream().map(x -> x.getUniqueName()).collect(Collectors.toList());
  299. pushVO.setDept(collect);
  300. }
  301. if (chiefLabel != null) {
  302. ChiefPushVo chiefPushVo = new ChiefPushVo();
  303. if (ListUtil.isNotEmpty(chiefLabel.getClinicals())) {
  304. List<Symptom> cjiefClinicals = chiefLabel.getClinicals().stream().filter(x -> x.getNegative() == null).map(z ->
  305. {
  306. String name_sy = z.getBodyPart() == null? z.getStandName() : z.getBodyPart().getName()+z.getStandName();
  307. Symptom symptom = new Symptom();
  308. symptom.setName(name_sy);
  309. return symptom;
  310. }).collect(Collectors.toList());
  311. if (ListUtil.isNotEmpty(cjiefClinicals)) {
  312. chiefPushVo.setSymptoms(cjiefClinicals);
  313. }
  314. }
  315. if (ListUtil.isNotEmpty(chiefLabel.getDiags())) {
  316. List<Diag> chief_diags = chiefLabel.getDiags().stream()
  317. .filter(x -> x.getNegative() == null && StringUtils.isNotBlank(x.getStandName()))
  318. .map(x ->
  319. {
  320. Diag diag = new Diag();
  321. diag.setName(x.getStandName());
  322. return diag;
  323. }).collect(Collectors.toList());
  324. chiefPushVo.setDiags(chief_diags);
  325. }
  326. if (ListUtil.isNotEmpty(chiefLabel.getPds())) {
  327. chiefPushVo.setPds(chiefLabel.getPds());
  328. }
  329. pushVO.setChiefPushVo(chiefPushVo);
  330. }
  331. if (presentLabel != null) {
  332. PresentPushVo presentPushVo = new PresentPushVo();
  333. if (ListUtil.isNotEmpty(presentLabel.getClinicals())) {
  334. List<Symptom> presentClinicals = presentLabel.getClinicals().stream()
  335. .filter(x -> x.getNegative() == null).map(z ->
  336. {
  337. String name_sy = z.getBodyPart() == null? z.getStandName() : z.getBodyPart().getName()+z.getStandName();
  338. Symptom symptom = new Symptom();
  339. symptom.setName(name_sy);
  340. return symptom;
  341. }).collect(Collectors.toList());
  342. presentPushVo.setSymptoms(presentClinicals);
  343. }
  344. if (ListUtil.isNotEmpty(presentLabel.getDiags())) {
  345. List<Diag> presentdiags = presentLabel.getDiags().stream()
  346. .filter(x -> x.getNegative() == null && StringUtils.isNotBlank(x.getStandName())).map
  347. (x -> x.getStandName()).distinct().map(z ->
  348. {
  349. Diag diag = new Diag();
  350. diag.setName(z);
  351. return diag;
  352. }).collect(Collectors.toList());
  353. presentPushVo.setDiags(presentdiags);
  354. }
  355. if (ListUtil.isNotEmpty(presentLabel.getMedicines())) {
  356. List<Drug> presentdrugs = presentLabel.getMedicines().stream().filter(x -> x.getNegative() == null).map(z ->
  357. {
  358. Drug drug = new Drug();
  359. drug.setName(z.getStandName());
  360. return drug;
  361. }).collect(Collectors.toList());
  362. presentPushVo.setDrugs(presentdrugs);
  363. }
  364. pushVO.setPresentPushVo(presentPushVo);
  365. }
  366. if (ListUtil.isNotEmpty(lis)) {
  367. LisPushVo lisPushVo = new LisPushVo();
  368. lisPushVo.setLises(lis);
  369. pushVO.setLisPushVo(lisPushVo);
  370. }
  371. // TODO 辅检
  372. if (pacsLabel != null) {
  373. PacsPushVo pacsPushVo = new PacsPushVo();
  374. pacsPushVo.setPacs(pacsLabel.getRes());
  375. pushVO.setPacsPushVo(pacsPushVo);
  376. }
  377. if (ListUtil.isNotEmpty(diags)) {
  378. DiagVo diagVo = new DiagVo();
  379. List<Diag> diseases = diags.stream().map(x -> {
  380. Diag diag = new Diag();
  381. diag.setName(x.getUniqueName());
  382. return diag;
  383. }).collect(Collectors.toList());
  384. diagVo.setDiags(diseases);
  385. pushVO.setDiagVo(diagVo);
  386. }
  387. return pushVO;
  388. }
  389. /**
  390. * 将现病史中提取的体征内容放入体征标签中
  391. *
  392. * @param wordCrfDTO
  393. */
  394. public void processPresentVital(WordCrfDTO wordCrfDTO) {
  395. PresentLabel presentLabel = wordCrfDTO.getPresentLabel();
  396. VitalLabel vitalLabel = wordCrfDTO.getVitalLabel();
  397. if (ListUtil.isNotEmpty(presentLabel.getVitals())) {
  398. vitalLabel.getVitals().addAll(presentLabel.getVitals());
  399. }
  400. if (ListUtil.isNotEmpty(presentLabel.getClinicals())) {
  401. vitalLabel.getClinicals().addAll(presentLabel.getClinicals());
  402. }
  403. }
  404. /**
  405. * 统一处理化验、辅检、诊断,放入结构化
  406. *
  407. * @param wordCrfDTO
  408. */
  409. public void processLisPacsDiag(WordCrfDTO wordCrfDTO) {
  410. DiagLabel diagLabel = wordCrfDTO.getDiagLabel();
  411. List<com.diagbot.model.entity.Diag> diags = diagLabel.getDiags();
  412. if (ListUtil.isNotEmpty(diags)) {
  413. wordCrfDTO.getDiag().addAll(diags.stream().filter(x -> x.getStandName() != null).map(x -> {
  414. Item i = new Item();
  415. i.setName(x.getName());
  416. i.setUniqueName(x.getStandName());
  417. return i;
  418. }).collect(Collectors.toList()));
  419. }
  420. List<Lis> lisList = new ArrayList<>();
  421. /**************************化验结构化处理开始*****************************/
  422. // 处理主诉化验
  423. getLisStruct(wordCrfDTO.getChiefLabel().getLises(), lisList, wordCrfDTO.getHospitalId());
  424. // 处理现病史化验
  425. getLisStruct(wordCrfDTO.getPresentLabel().getLises(), lisList, wordCrfDTO.getHospitalId());
  426. // 统一放置化验结构
  427. if (ListUtil.isNotEmpty(lisList)) {
  428. wordCrfDTO.getLis().addAll(lisList);
  429. }
  430. /*************************化验结构化处理结束******************************/
  431. /**************************辅检结构化处理开始*****************************/
  432. // 处理辅检信息
  433. PacsLabel pacsLabel = wordCrfDTO.getPacsLabel();
  434. // 处理主诉辅检
  435. getPacsStruct(pacsLabel, wordCrfDTO.getChiefLabel().getPacsLabel());
  436. // 处理现病史辅检
  437. getPacsStruct(pacsLabel, wordCrfDTO.getPresentLabel().getPacsLabel());
  438. // 辅检结果去重
  439. if (ListUtil.isNotEmpty(pacsLabel.getRes())) {
  440. dealMsgWithItem(pacsLabel.getRes());
  441. }
  442. // 辅检名称去重
  443. if (ListUtil.isNotEmpty(pacsLabel.getItem())) {
  444. dealMsgWithItem(pacsLabel.getItem());
  445. }
  446. /*************************辅检结构化处理结束******************************/
  447. //处理辅检
  448. // List<com.diagbot.biz.push.entity.Pacs> pacs = new ArrayList<>();
  449. // List<PacsNew> packagePacs = new ArrayList<>();
  450. // List<PacsNew> pacsNewList = wordCrfDTO.getPresentLabel().getPacsNewList();
  451. // if(ListUtil.isNotEmpty(pacsNewList)){
  452. // List<String> pacsNames = pacsNewList.stream().map(x -> x.getName()).collect(Collectors.toList());
  453. // Map<String, Map<String, Long>> configMap = pacsConfigFacade.getConfigMap(wordCrfDTO.getHospitalId(), pacsNames, null);
  454. // if(configMap.size() > 0){
  455. // pacsNewList.stream().forEach(pacsNew ->{
  456. // String name = pacsNew.getName();
  457. // List<Pacs> disease = pacsNew.getDisease();
  458. // List<Pacs> pacsResults = pacsNew.getPacsResults();
  459. // if(configMap.containsKey(name)){
  460. // Map<String, Long> uinqueNameMap = configMap.get(name);
  461. // List<PacsNew> collect = uinqueNameMap.keySet().stream().map(x -> {
  462. // PacsNew pan = new PacsNew();
  463. // pan.setName(name);
  464. // pan.setUniqueName(x);
  465. // pan.setPacsResults(pacsResults);
  466. // pan.setDisease(disease);
  467. // return pan;
  468. // }).collect(Collectors.toList());
  469. // packagePacs.addAll(collect);
  470. // collect.forEach(x ->{
  471. // com.diagbot.biz.push.entity.Pacs p = new com.diagbot.biz.push.entity.Pacs();
  472. // p.setName(x.getName());
  473. // p.setUniqueName(x.getUniqueName());
  474. // pacs.add(p);
  475. // });
  476. // }else {
  477. // PacsNew pan = new PacsNew();
  478. // pan.setName(name);
  479. // pan.setPacsResults(pacsResults);
  480. // pan.setDisease(disease);
  481. // packagePacs.add(pan);
  482. // com.diagbot.biz.push.entity.Pacs p = new com.diagbot.biz.push.entity.Pacs();
  483. // p.setName(name);
  484. // pacs.add(p);
  485. // }
  486. // });
  487. // }else {
  488. // packagePacs.addAll(pacsNewList);
  489. // pacsNewList.forEach(x ->{
  490. // com.diagbot.biz.push.entity.Pacs p = new com.diagbot.biz.push.entity.Pacs();
  491. // p.setName(x.getName());
  492. // pacs.add(p);
  493. // });
  494. // }
  495. // }
  496. // if(ListUtil.isNotEmpty(pacs)){
  497. // wordCrfDTO.getPacs().addAll(pacs);
  498. // }
  499. // pacsLabel.getPacsNewList().addAll(packagePacs);
  500. }
  501. public void getPacsStruct(PacsLabel res, PacsLabel dealPacsLabel) {
  502. List<Item> pacsResList = res.getRes();
  503. if (dealPacsLabel != null) {
  504. // 添加辅检项目名称
  505. if (ListUtil.isNotEmpty(dealPacsLabel.getItem())) {
  506. res.getItem().addAll(dealPacsLabel.getItem());
  507. }
  508. // 添加辅检的诊断
  509. if (ListUtil.isNotEmpty(dealPacsLabel.getDisease())) {
  510. res.getDisease().addAll(dealPacsLabel.getDisease());
  511. }
  512. // 添加辅检的描述
  513. if (ListUtil.isNotEmpty(dealPacsLabel.getPacsResults())) {
  514. res.getPacsResults().addAll(dealPacsLabel.getPacsResults());
  515. }
  516. }
  517. if (ListUtil.isNotEmpty(res.getDisease())) {
  518. for (Pacs pacs : res.getDisease()) {
  519. Item item = new Item();
  520. item.setName(pacs.getName());
  521. item.setUniqueName(pacs.getStandName());
  522. pacsResList.add(item);
  523. }
  524. }
  525. // 添加辅检的描述
  526. if (ListUtil.isNotEmpty(res.getPacsResults())) {
  527. for (Pacs pacs : res.getPacsResults()) {
  528. Item item = new Item();
  529. item.setName(pacs.getName());
  530. item.setUniqueName(pacs.getStandName());
  531. pacsResList.add(item);
  532. // 部位 + 描述循环放入
  533. for (BodyPart bodyPart : pacs.getBodyPartList()) {
  534. Item itemPart = new Item();
  535. itemPart.setName(bodyPart.getName() + pacs.getName());
  536. itemPart.setUniqueName(bodyPart.getStandName() + pacs.getStandName());
  537. pacsResList.add(itemPart);
  538. }
  539. // 描述 + 修饰、 修饰 + 描述 循环放入
  540. for (Modification modification : pacs.getModification()) {
  541. Item itemModification = new Item();
  542. itemModification.setName(pacs.getName() + modification.getName());
  543. itemModification.setUniqueName(pacs.getStandName() + modification.getStandName());
  544. pacsResList.add(itemModification);
  545. Item itemModificationRe = new Item();
  546. itemModificationRe.setName(modification.getName() + pacs.getName());
  547. itemModificationRe.setUniqueName(modification.getStandName() + pacs.getStandName());
  548. pacsResList.add(itemModificationRe);
  549. }
  550. }
  551. }
  552. }
  553. /**
  554. * 获取化验的结构
  555. *
  556. * @param lises
  557. * @param lisList
  558. * @param hospitalId
  559. */
  560. public void getLisStruct(List<com.diagbot.model.entity.Lis> lises, List<Lis> lisList, Long hospitalId) {
  561. if (ListUtil.isNotEmpty(lises)) {
  562. List<String> lisNames = lises.stream().map(x -> x.getBigItem().getName()).distinct().collect(Collectors.toList());
  563. Map<String, Map<String, Map<String, Long>>> configMap = lisConfigFacade.getConfigMap(hospitalId, lisNames, null);
  564. if (configMap.size() > 0) {
  565. lises.stream().forEach(x -> {
  566. String bigName = x.getBigItem().getName();//大项名
  567. String detailName = x.getName();//小项名
  568. String value = x.getPd().getValue();
  569. String unit = x.getPd().getUnit();
  570. if (configMap.containsKey(bigName)) {
  571. Map<String, Map<String, Long>> uniqueDetailMap = configMap.get(bigName);
  572. if (uniqueDetailMap.containsKey(detailName)) {
  573. List<String> uniques = uniqueDetailMap.get(detailName).keySet().stream().collect(Collectors.toList());//所有的公表项
  574. if (ListUtil.isNotEmpty(uniques)) {
  575. List<Lis> lisStream = uniques.stream().map(z -> {
  576. return getLis(bigName, detailName, value, unit, z);
  577. }).collect(Collectors.toList());
  578. lisList.addAll(lisStream);
  579. }
  580. } else {
  581. Lis lis = getLis(bigName, detailName, value, unit, null);
  582. lisList.add(lis);
  583. }
  584. } else {
  585. Lis lis = getLis(bigName, detailName, value, unit, null);
  586. lisList.add(lis);
  587. }
  588. });
  589. } else {
  590. lises.stream().forEach(x -> {
  591. Lis lis = getLis(x.getBigItem().getName(), x.getName(), x.getPd().getValue(), x.getPd().getUnit(), null);
  592. lisList.add(lis);
  593. });
  594. }
  595. }
  596. }
  597. private Lis getLis(String bigName, String detailName, String value, String unit, String uniqueName) {
  598. Lis lis = new Lis();
  599. lis.setUnits(unit);
  600. if (StringUtils.isBlank(unit)) {
  601. if (CoreUtil.isNumbers(value)) {
  602. lis.setValue(Double.parseDouble(value));
  603. } else {
  604. lis.setOtherValue(value);
  605. }
  606. } else {
  607. lis.setValue(Double.parseDouble(value));
  608. }
  609. lis.setDetailName(detailName);
  610. lis.setName(bigName);
  611. lis.setUniqueName(uniqueName);
  612. return lis;
  613. }
  614. /**
  615. * 提示信息去重
  616. *
  617. * @param billMsgList
  618. */
  619. public void dealMsg(List<BillMsg> billMsgList) {
  620. if (ListUtil.isNotEmpty(billMsgList)) {
  621. List<String> msgList = new ArrayList<>();
  622. Iterator<BillMsg> it = billMsgList.iterator();
  623. while (it.hasNext()) {
  624. String msg = it.next().getMsg();
  625. if (msgList.contains(msg)) {
  626. it.remove();
  627. } else {
  628. msgList.add(msg);
  629. }
  630. }
  631. }
  632. }
  633. /**
  634. * 提示信息去重
  635. *
  636. * @param itemList
  637. */
  638. public void dealMsgWithItem(List<Item> itemList) {
  639. if (ListUtil.isNotEmpty(itemList)) {
  640. List<String> msgList = new ArrayList<>();
  641. Iterator<Item> it = itemList.iterator();
  642. while (it.hasNext()) {
  643. String msg = it.next().getName();
  644. if (msgList.contains(msg)) {
  645. it.remove();
  646. } else {
  647. msgList.add(msg);
  648. }
  649. }
  650. }
  651. }
  652. }