NeoFacade.java 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  1. package com.diagbot.facade;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.diagbot.biz.push.entity.Item;
  4. import com.diagbot.biz.push.entity.Lis;
  5. import com.diagbot.client.ChiefPresentSimilarityServiceClient;
  6. import com.diagbot.client.StandConvertServiceClient;
  7. import com.diagbot.dto.*;
  8. import com.diagbot.entity.DiseaseInfo;
  9. import com.diagbot.entity.DiseaseProperty;
  10. import com.diagbot.entity.node.LisRemind;
  11. import com.diagbot.entity.relationship.LisRemindMedicine;
  12. import com.diagbot.entity.relationship.LisRemindYiBaoDiseaseName;
  13. import com.diagbot.enums.RedisEnum;
  14. import com.diagbot.enums.StandConvertEnum;
  15. import com.diagbot.exception.CommonErrorCode;
  16. import com.diagbot.exception.CommonException;
  17. import com.diagbot.model.entity.PD;
  18. import com.diagbot.repository.*;
  19. import com.diagbot.util.ListUtil;
  20. import com.diagbot.util.NeoUtil;
  21. import com.diagbot.util.RedisUtil;
  22. import com.diagbot.util.StringUtil;
  23. import com.diagbot.vo.Drug;
  24. import com.diagbot.vo.*;
  25. import com.diagbot.vo.neoPushEntity.*;
  26. import com.google.common.collect.Lists;
  27. import com.google.common.collect.Maps;
  28. import org.springframework.beans.BeanUtils;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.beans.factory.annotation.Qualifier;
  31. import org.springframework.beans.factory.annotation.Value;
  32. import org.springframework.cache.annotation.Cacheable;
  33. import org.springframework.data.redis.core.RedisTemplate;
  34. import org.springframework.stereotype.Component;
  35. import java.math.BigDecimal;
  36. import java.text.DecimalFormat;
  37. import java.util.*;
  38. import java.util.function.Function;
  39. import java.util.stream.Collectors;
  40. import java.util.stream.Stream;
  41. /**
  42. * @Description: 图谱facade
  43. * @author: Mark
  44. * @time: 2018/8/6 9:11
  45. */
  46. @Component
  47. public class NeoFacade {
  48. @Autowired
  49. MedicineRepository medicineRepository;
  50. @Autowired
  51. PacsNameRepository pacsNameRepository;
  52. @Autowired
  53. PacsSubNameRepository pacsSubNameRepository;
  54. @Autowired
  55. LisNameRepository lisNameRepository;
  56. @Autowired
  57. LisSetRepository lisSetRepository;
  58. @Autowired
  59. LisRemindRepository lisRemindRepository;
  60. @Autowired
  61. YiBaoDiseaseRepository yiBaodiseaseRepository;
  62. @Autowired
  63. YiBaoOperationNameRepository yiBaoOperationRepository;
  64. @Autowired
  65. MedicineCodeRepository medicineCodeRepository;
  66. @Autowired
  67. MedRegNameRepository medRegNameRepository;
  68. @Autowired
  69. PacsCriticalRepository pacsCriticalRepository;
  70. @Autowired
  71. YiBaoDiseaseRepository yiBaoDiseaseRepository;
  72. @Autowired
  73. CombiOperationRepository combiOperationRepository;
  74. @Autowired
  75. BaseNodeRepository nodeRepository;
  76. @Autowired
  77. ChiefPresentSimilarityServiceClient chiefPresentSimilarityServiceClient;
  78. @Autowired
  79. NeoFacade self;
  80. @Autowired
  81. StandConvertServiceClient standConvertServiceClient;
  82. @Autowired
  83. RedisUtil redisUtil;
  84. @Autowired
  85. @Qualifier("redisTemplateForSimilar")
  86. RedisTemplate redisTemplate;
  87. @Value("${StandConvert.rate}")
  88. String standConvertRate;
  89. @Autowired
  90. SymptomNameRepository symptomNameRepository;
  91. @Autowired
  92. TransfusionRemindRepository transfusionRemindRepository;
  93. @Autowired
  94. TransfusionSuggestRepository transfusionSuggestRepository;
  95. @Autowired
  96. PacsRemindRepository pacsRemindRepository;
  97. @Autowired
  98. PacsResultRepository pacsResultRepository;
  99. /**
  100. * 返回药品缓存信息
  101. *
  102. * @return
  103. */
  104. // @Cacheable(value = "cache", key = "'drugCache'")
  105. public Map<String, List<String>> getDrugCache() {
  106. Map<String, List<String>> res = new HashMap<>();
  107. String med_type;
  108. String med_name;
  109. String comma = "::";
  110. List<String> medClass = nodeRepository.getMedHuaXueClass();
  111. medClass.addAll(nodeRepository.getMedYaoLiClass());
  112. medClass.addAll(nodeRepository.getMedZhiLiaoClass());
  113. medClass.addAll(nodeRepository.getMedJiePouClass());
  114. for (String medcls : medClass) {
  115. String[] spres = medcls.split(comma);
  116. med_type = spres[1];
  117. med_name = spres[0];
  118. if (res.get(med_type) == null) {
  119. res.put(med_type, new ArrayList<>());
  120. }
  121. if (res.get(med_type).indexOf(med_name) == -1) {
  122. res.get(med_type).add(med_name);
  123. }
  124. }
  125. Map redisMap = res.entrySet().stream().collect(
  126. Collectors.toMap(k -> RedisEnum.drugType.getName() + k.getKey(),
  127. v -> v.getValue(), (v1, v2) -> (v2)));
  128. if (redisMap != null && redisMap.size() > 0) {
  129. redisTemplate.opsForValue().multiSet(redisMap);
  130. }
  131. return res;
  132. }
  133. public void diseasePropertyCache() {
  134. List<DiseaseProperty> diseaseProperty = nodeRepository.getDiseaseProperty();
  135. if (ListUtil.isNotEmpty(diseaseProperty)) {
  136. Map map = diseaseProperty.stream().collect(Collectors.toMap(
  137. k -> RedisEnum.diseaseType.getName() + k.getName(),
  138. v -> {
  139. Map<String, String> desc = new HashMap<>();
  140. desc.put("name", v.getName());
  141. desc.put("sex", v.getSex());
  142. desc.put("age", v.getAge());
  143. desc.put("fbl", v.getFbl());
  144. return desc;
  145. },
  146. (v1, v2) -> (v2)
  147. ));
  148. redisTemplate.opsForValue().multiSet(map);
  149. }
  150. }
  151. /**
  152. * 返回图谱中所有症状缓存信息
  153. *
  154. * @return
  155. */
  156. @Cacheable(value = "cache", key = "'symptomCache'")
  157. public List<String> getSymptomCache() {
  158. List<String> symptomClass = nodeRepository.getSymptomClass();
  159. return symptomClass;
  160. }
  161. /**
  162. * 返回图谱中所有疾病和性别信息
  163. *
  164. * @return
  165. */
  166. @Cacheable(value = "cache", key = "'disSexCache'")
  167. public Map<String, String> getDisSexCache() {
  168. Map<String, String> disSexClass = Maps.newHashMap();
  169. List<String> disSex = nodeRepository.getDisSexClass();
  170. if (ListUtil.isNotEmpty(disSex)) {
  171. disSex.parallelStream().forEach(x -> {
  172. String[] splits = x.split("&");
  173. disSexClass.put(splits[0], splits[1]);
  174. });
  175. }
  176. return disSexClass;
  177. }
  178. /**
  179. * 返回图谱中所有疾病和年龄信息
  180. *
  181. * @return
  182. */
  183. @Cacheable(value = "cache", key = "'disAgeCache'")
  184. public Map<String, String> getDisAgeCache() {
  185. Map<String, String> disAgeClass = Maps.newHashMap();
  186. List<String> ageClass = nodeRepository.getDisAgeClass();
  187. if (ListUtil.isNotEmpty(ageClass)) {
  188. ageClass.parallelStream().forEach(x -> {
  189. String[] splits = x.split("&");
  190. disAgeClass.put(splits[0], splits[1]);
  191. });
  192. }
  193. return disAgeClass;
  194. }
  195. /**
  196. * 返回图谱中所有疾病和发病率信息
  197. *
  198. * @return
  199. */
  200. @Cacheable(value = "cache", key = "'disdistributionCache'")
  201. public Map<String, Double> getDisdistributionCache() {
  202. DecimalFormat df = new DecimalFormat("0.######");
  203. Map<String, Double> disdistribution = new HashMap<>();
  204. List<String> disdistributionClass = nodeRepository.getDisdistributionClass();
  205. if (ListUtil.isNotEmpty(disdistributionClass)) {
  206. disdistributionClass.parallelStream().forEach(x -> {
  207. String[] splits = x.split("&");
  208. disdistribution.put(splits[0], Double.parseDouble(splits[1]));
  209. });
  210. }
  211. return disdistribution;
  212. }
  213. /**
  214. * 图谱反推的数据
  215. *
  216. * @param pushVO
  217. * @return
  218. */
  219. public NeoPushDTO getReversePush(NeoPushVO pushVO) {
  220. NeoPushDTO neoPushDTO = new NeoPushDTO();
  221. // 如果有诊断名称,则通过诊断反推
  222. if (null != pushVO.getDiagVo() && pushVO.getDiagVo().getDiags().size() > 0) {
  223. neoPushDTO = getDiagInfo(pushVO);
  224. }
  225. return neoPushDTO;
  226. }
  227. /**
  228. * 图谱正推的数据
  229. *
  230. * @param pushVO
  231. * @return
  232. */
  233. public List<String> getPush(NeoPushVO pushVO) {
  234. Double age = pushVO.getAgeNum();
  235. Integer sex = pushVO.getSex();
  236. List<String> presentDiags = Lists.newArrayList();
  237. PresentPushVo presentPushVo = pushVO.getPresentPushVo();
  238. if(presentPushVo != null){
  239. List<Diag> diags = presentPushVo.getDiags();
  240. if(ListUtil.isNotEmpty(diags)){
  241. presentDiags = diags.stream().map(x -> x.getName()).collect(Collectors.toList());
  242. }
  243. }
  244. List<PD> pds = pushVO.getChiefPushVo().getPds();
  245. PD pd = null;
  246. if(ListUtil.isNotEmpty(pds)){
  247. pd = pds.get(0);
  248. }
  249. List<String> pushDis = new ArrayList<>();
  250. List<String> allDis = Lists.newArrayList();
  251. //如果化验有特异性就直接推送疾病
  252. List<Lis> lises = null;
  253. LisPushVo lisPushVo = pushVO.getLisPushVo();
  254. if (lisPushVo != null) {
  255. lises = lisPushVo.getLises();
  256. }
  257. pushDis = pushDisBySpecialLis(age, sex, pd, lises,presentDiags);
  258. if(ListUtil.isNotEmpty(pushDis)){
  259. return pushDis;
  260. }
  261. // 症状、体征推送出的疾病
  262. pushDisBySymptomOrVital(pushVO, allDis);
  263. //化验推出的疾病
  264. pushDisByLis(allDis, lises);
  265. //辅检推出的疾病
  266. pushDisByPacs(pushVO, allDis);
  267. filterAndSort(pushDis, allDis, sex, age, pd);
  268. pushDis = addDiagFromPresent(pushDis,presentDiags);
  269. return pushDis;
  270. }
  271. /**
  272. * 化验特异性推送疾病
  273. * @param age
  274. * @param sex
  275. * @param
  276. * @param lises
  277. * @return
  278. */
  279. private List<String> pushDisBySpecialLis(Double age, Integer sex, PD pd, List<Lis> lises,List<String> presentDiags) {
  280. List<String> neoPushDTOS = new ArrayList<>();
  281. if (ListUtil.isNotEmpty(lises)) {
  282. List<String> lis_dis = lises.parallelStream()
  283. .map(x -> nodeRepository.getDisByLis_Special(x.getName(), x.getUniqueName() + x.getResult()))
  284. .flatMap(List::stream).collect(Collectors.toList());
  285. if (ListUtil.isNotEmpty(lis_dis)) {
  286. filterAndSort(neoPushDTOS, lis_dis, sex, age,pd);
  287. neoPushDTOS = addDiagFromPresent(neoPushDTOS,presentDiags);
  288. }
  289. }
  290. return neoPushDTOS;
  291. }
  292. /**
  293. * 把现病史中的诊断添加到推送诊断中
  294. * @param lis_dis
  295. * @param presentDiags
  296. */
  297. private List<String> addDiagFromPresent(List<String> lis_dis,List<String> presentDiags){
  298. List<String> lis_dis_new = Lists.newArrayList();
  299. if(ListUtil.isNotEmpty(lis_dis) && ListUtil.isNotEmpty(presentDiags)){
  300. if(lis_dis.size()>=10){
  301. for(int i =0; i< lis_dis.size(); i++){
  302. if(i == 10 - presentDiags.size()){
  303. for (String dis: presentDiags) {
  304. if(!lis_dis_new.contains(dis)){
  305. lis_dis_new.add(dis);
  306. }
  307. }
  308. lis_dis_new.add(lis_dis.get(i));
  309. }else {
  310. lis_dis_new.add(lis_dis.get(i));
  311. }
  312. }
  313. }else {
  314. lis_dis_new.addAll(lis_dis);
  315. lis_dis_new.addAll(presentDiags);
  316. }
  317. lis_dis_new = lis_dis_new.stream().distinct().collect(Collectors.toList());
  318. }else {
  319. lis_dis_new =lis_dis;
  320. }
  321. return lis_dis_new;
  322. }
  323. /**
  324. * 辅检推送疾病
  325. * @param pushVO
  326. * @param allDis
  327. */
  328. private void pushDisByPacs(NeoPushVO pushVO, List<String> allDis) {
  329. PacsPushVo pacsPushVo = pushVO.getPacsPushVo();
  330. if (pacsPushVo != null) {
  331. List<Item> pacs = pacsPushVo.getPacs();
  332. if (ListUtil.isNotEmpty(pacs)) {
  333. List<String> pacsNames = pacs.stream().map(x -> x.getUniqueName()).collect(Collectors.toList());
  334. List<String> allDis_byPacsResult = getDisByPacsResult(pacsNames);
  335. allDis.addAll(allDis_byPacsResult);
  336. }
  337. }
  338. }
  339. /**
  340. * 化验推送疾病
  341. * @param allDis
  342. * @param lises
  343. */
  344. private void pushDisByLis(List<String> allDis, List<Lis> lises) {
  345. if (ListUtil.isNotEmpty(lises)) {
  346. List<String> lis_dis = lises.parallelStream()
  347. .map(x -> nodeRepository.getDisByLis(x.getName(), x.getUniqueName() + x.getResult()))
  348. .flatMap(List::stream).collect(Collectors.toList());
  349. allDis.addAll(lis_dis);
  350. }
  351. }
  352. /**
  353. * 症状和体征推送疾病
  354. * @param pushVO
  355. * @param allDis
  356. */
  357. private void pushDisBySymptomOrVital(NeoPushVO pushVO, List<String> allDis) {
  358. ChiefPushVo chiefPushVo = pushVO.getChiefPushVo();
  359. PresentPushVo presentPushVo = pushVO.getPresentPushVo();
  360. List<String> symptoms = new ArrayList<>();
  361. List<String> symptom_chief = new ArrayList<>();
  362. List<String> symptom_present = new ArrayList<>();
  363. if (chiefPushVo != null) {
  364. if (ListUtil.isNotEmpty(chiefPushVo.getSymptoms())) {
  365. symptom_chief = chiefPushVo.getSymptoms().stream().map(x -> x.getName()).collect(Collectors.toList());
  366. }
  367. }
  368. if (presentPushVo != null) {
  369. if (ListUtil.isNotEmpty(presentPushVo.getSymptoms())) {
  370. symptom_present = presentPushVo.getSymptoms().stream().map(x -> x.getName()).collect(Collectors.toList());
  371. }
  372. }
  373. symptoms = Stream.of(symptom_chief, symptom_present).flatMap(Collection::stream).distinct().collect(Collectors.toList());
  374. //症状、体征推疾病
  375. List<String> allDis_bySymptom = getDisBySymptom(symptoms);
  376. allDis.addAll(allDis_bySymptom);
  377. }
  378. private void filterAndSort(List<String> dises, List<String> allDis, int gender_code, double age, PD pd) {
  379. //推送出的所有疾病进行性别和年龄的过滤
  380. List<Map<String, String>> diseases = null;
  381. Map<String, Double> dis_fbl = new HashMap<>();
  382. if (ListUtil.isNotEmpty(allDis)) {
  383. // diseases = redisUtil.get(allDis);
  384. diseases = redisUtil.geth(allDis);
  385. allDis = diseases.stream().filter(x -> NeoUtil.matchBasic(x, gender_code, age) && NeoUtil.matchPds(x.get("name"),pd))
  386. // allDis = diseases.stream().filter(x -> NeoUtil.matchBasic(x, gender_code, age))
  387. .map(x -> x.get("name")).collect(Collectors.toList());
  388. diseases.forEach(x -> dis_fbl.put(x.get("name"), Double.parseDouble(x.get("fbl"))));
  389. }
  390. Map<Long, List<String>> numberDiseasesMap = disCountSort(allDis);
  391. //根据发病率排序
  392. // Map<String, Double> disdistributionCache = self.getDisdistributionCache();
  393. Map<Long, Map<String, Double>> disPack = new LinkedHashMap<>();
  394. numberDiseasesMap.forEach((x, y) -> {
  395. Map<String, Double> collect = y.stream()
  396. .collect(Collectors.toMap(v -> v, v -> dis_fbl.get(v), (e1, e2) -> e2));
  397. disPack.put(x, collect);
  398. });
  399. disPack.forEach((x, y) -> {
  400. Map<String, Double> collect = y.entrySet().stream()
  401. .sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
  402. .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, LinkedHashMap::new));
  403. disPack.put(x, collect);
  404. collect.forEach((k, n) -> {
  405. /*NeoPushDTO neoPushDTO = new NeoPushDTO();
  406. PushBaseDTO pushBaseDTO = new PushBaseDTO();
  407. pushBaseDTO.setName(k);
  408. neoPushDTO.setDisease(pushBaseDTO);
  409. neoPushDTOS.add(neoPushDTO);*/
  410. dises.add(k);
  411. });
  412. });
  413. }
  414. public List<String> getDisBySymptom(List<String> symptoms) {
  415. List<String> symptomCache = getSymptomCache();
  416. //取交集
  417. symptoms.retainAll(symptomCache);
  418. long start = System.currentTimeMillis();
  419. List<String> allDis_bySymptom = pushDisBySymptom(symptomNameRepository, symptoms);
  420. long end = System.currentTimeMillis();
  421. return allDis_bySymptom;
  422. }
  423. public List<String> getDisByPacsResult(List<String> pacsResult) {
  424. /*List<PacsResult> byNameIn = pacsResultRepository.findByNameIn(pacsResult);
  425. List<String> allDis = byNameIn.stream()
  426. .map(z -> z.getDisease().stream().filter(o -> NeoUtil.matchBasic(o,sex,age)).map(y -> y.getName()).collect(Collectors.toList())).flatMap(List::stream)
  427. .collect(Collectors.toList());*/
  428. List<String> allDis = pacsResultRepository.getDisByPacsResults(pacsResult);
  429. return allDis;
  430. }
  431. /**
  432. * 症状、体征、化验、辅检等其他推送疾病
  433. *
  434. * @param symptomNameRepository
  435. * @param symptoms
  436. * @return
  437. */
  438. public List<String> pushDisBySymptom(SymptomNameRepository symptomNameRepository, List<String> symptoms) {
  439. List<String> allDis = Lists.newArrayList();
  440. /*List<Symptom> byNameIn = symptomNameRepository.findByNameIn(symptoms);
  441. allDis = byNameIn.parallelStream()
  442. .map(z -> z.getDisease().stream().filter(o -> NeoUtil.matchBasic(o,sex,age)).map(y -> y.getName()).collect(Collectors.toList())).flatMap(List::stream)
  443. .collect(Collectors.toList());*/
  444. allDis = symptomNameRepository.getDisBySymptoms(symptoms);
  445. return allDis;
  446. }
  447. /**
  448. * 推送的疾病计数排序
  449. *
  450. * @param allDis
  451. * @return
  452. */
  453. public Map<Long, List<String>> disCountSort(List<String> allDis) {
  454. Map<String, Long> dis_count = allDis.stream().collect(
  455. Collectors.groupingBy(Function.identity(), Collectors.counting())
  456. );
  457. if (dis_count != null && dis_count.size() > 0) {
  458. dis_count = dis_count.entrySet().stream().sorted((o1, o2) -> o2.getValue().compareTo(o1.getValue()))
  459. .map(entry -> {
  460. Map<String, Long> result = new LinkedHashMap();
  461. result.put(entry.getKey(), entry.getValue());
  462. return result;
  463. }).reduce((map1, map2) -> {
  464. map2.entrySet().forEach(entry -> map1.put(entry.getKey(), entry.getValue()));
  465. return map1;
  466. }).get();
  467. }
  468. Map<Long, List<String>> number_diseases = new LinkedHashMap<>();
  469. dis_count.forEach((x, y) -> {
  470. if (number_diseases.containsKey(y)) {
  471. List<String> diseases = number_diseases.get(y);
  472. diseases.add(x);
  473. number_diseases.put(y, diseases);
  474. } else {
  475. List<String> diseases = Lists.newArrayList();
  476. diseases.add(x);
  477. number_diseases.put(y, diseases);
  478. }
  479. });
  480. return number_diseases;
  481. }
  482. /**
  483. * 反推信息
  484. * @param dis
  485. * @return
  486. */
  487. public NeoPushDTO reverseInfo(String dis){
  488. NeoPushDTO neoPushDTO = new NeoPushDTO();
  489. List<DiseaseInfo> diseaseInfo = nodeRepository.getDiseaseInfo(dis);
  490. if(ListUtil.isNotEmpty(diseaseInfo)){
  491. diseaseInfo.forEach(disIf ->{
  492. String tp = disIf.getTp();
  493. List<String> col = disIf.getCol();
  494. switch (tp){
  495. case "医保疾病名称相关症状":
  496. neoPushDTO.setSymptoms(col.stream().map(x ->NeoUtil.updatePushInfo(x)).collect(Collectors.toList()));
  497. break;
  498. case "医保疾病名称相关化验套餐名称":
  499. neoPushDTO.setLis(col.stream().map(x ->NeoUtil.updatePushInfo(x)).collect(Collectors.toList()));
  500. break;
  501. case "医保疾病名称相关辅助检查名称":
  502. neoPushDTO.setPacs(col.stream().map(x ->NeoUtil.updatePushInfo(x)).collect(Collectors.toList()));
  503. break;
  504. case "医保疾病名称相关体征":
  505. neoPushDTO.setVitals(col.stream().map(x ->NeoUtil.updatePushInfo(x)).collect(Collectors.toList()));
  506. break;
  507. default:
  508. break;
  509. }
  510. });
  511. }
  512. return neoPushDTO;
  513. }
  514. /**
  515. * 处理开单合理性图谱数据
  516. *
  517. * @param billNeoVO
  518. * @return
  519. */
  520. public List<BillNeoDTO> getBillNeo(BillNeoVO billNeoVO) {
  521. List<BillNeoDTO> billNeoDTOs = new ArrayList<>();
  522. try {
  523. billNeoDTOs.addAll(getDrugBill(billNeoVO.getDrugList()));
  524. billNeoDTOs.addAll(getPacsBill(billNeoVO.getPacsList()));
  525. billNeoDTOs.addAll(getLisDetailBill(billNeoVO.getLisDetailList()));
  526. billNeoDTOs.addAll(getLisBill(billNeoVO.getLisList()));
  527. billNeoDTOs.addAll(getOperationBill(billNeoVO.getOperationList()));
  528. billNeoDTOs.addAll(getCombiOpBill(billNeoVO.getCombiopList()));
  529. billNeoDTOs.addAll(getTransfusionBill(billNeoVO.getTransfusionList()));
  530. } catch (Exception ex) {
  531. ex.printStackTrace();
  532. }
  533. return billNeoDTOs;
  534. }
  535. /**
  536. * 处理高危项目图谱数据
  537. *
  538. * @param wordCrfDTO
  539. * @return
  540. */
  541. public List<HighRiskNeoDTO> getHighRiskNeo(WordCrfDTO wordCrfDTO) {
  542. List<HighRiskNeoDTO> highRiskNeoDTOS = new ArrayList<>();
  543. highRiskNeoDTOS.addAll(getHighRiskDrugList(wordCrfDTO.getDrugOrder()));
  544. highRiskNeoDTOS.addAll(getHighRiskOperationList(wordCrfDTO));
  545. return highRiskNeoDTOS;
  546. }
  547. /**
  548. * 获取危急值图谱数据
  549. */
  550. public List<CriticalNeoDTO> getCritialNeo(CriticalNeoVO criticalNeoVO) {
  551. List<CriticalNeoDTO> criticalNeoDTOs = new ArrayList<>();
  552. criticalNeoDTOs.addAll(getLisCritical(criticalNeoVO));
  553. criticalNeoDTOs.addAll(getPacsCritical(criticalNeoVO));
  554. return criticalNeoDTOs;
  555. }
  556. /**
  557. * 处理其它化验提醒
  558. */
  559. public List<OtherTipNeoDTO> getOtherRemind(List<Lis> lislist) {
  560. Map<String, List<LisRemind>> lrmap = new HashMap<>();
  561. List<OtherTipNeoDTO> otherTipNeoDTOS = new ArrayList<>();
  562. try {
  563. List<LisRemind> lisReminds = lisRemindRepository.findByNameContaining("");
  564. String lisname, result, unit;
  565. Double val;
  566. for (LisRemind lisRemind : lisReminds) {
  567. lisname = lisRemind.getLisname();
  568. if (null == lrmap.get(lisname)) {
  569. lrmap.put(lisname, new ArrayList<>());
  570. }
  571. lrmap.get(lisname).add(lisRemind);
  572. }
  573. for (Lis lis : lislist) {
  574. lisname = lis.getUniqueName();
  575. if (null != lrmap.get(lisname)) {
  576. List<LisRemind> lrlist = lrmap.get(lisname);
  577. result = lis.getOtherValue();
  578. if (StringUtil.isBlank(result)) {
  579. val = lis.getValue();
  580. unit = lis.getUnits();
  581. for (LisRemind lisRemind : lrlist) {
  582. if (lisRemind.getRange() == 0) { /*&& lisRemind.getUnit().equals(unit) &&*/
  583. if (null == lisRemind.getMinval() && val <= lisRemind.getMaxval()) {
  584. otherTipNeoDTOS = updateTipNeoDTO(otherTipNeoDTOS, lis, lisRemind);
  585. } else if (null == lisRemind.getMaxval() && val >= lisRemind.getMinval()) {
  586. otherTipNeoDTOS = updateTipNeoDTO(otherTipNeoDTOS, lis, lisRemind);
  587. } else if (null != lisRemind.getMinval() && null != lisRemind.getMaxval() &&
  588. val <= lisRemind.getMaxval() && val >= lisRemind.getMinval()) {
  589. otherTipNeoDTOS = updateTipNeoDTO(otherTipNeoDTOS, lis, lisRemind);
  590. }
  591. } else if (lisRemind.getRange() == 1) { /*&& lisRemind.getUnit().equals(unit) &&*/
  592. if (null != lisRemind.getMaxval() && val > lisRemind.getMaxval()) {
  593. otherTipNeoDTOS = updateTipNeoDTO(otherTipNeoDTOS, lis, lisRemind);
  594. } else if (null != lisRemind.getMinval() && val < lisRemind.getMinval()) {
  595. otherTipNeoDTOS = updateTipNeoDTO(otherTipNeoDTOS, lis, lisRemind);
  596. }
  597. }
  598. }
  599. } else {
  600. for (LisRemind lisRemind : lrlist) {
  601. if (result.equals(lisRemind.getResult())) {
  602. OtherTipNeoDTO otherTipNeoDTO = new OtherTipNeoDTO();
  603. BeanUtils.copyProperties(lis, otherTipNeoDTO);
  604. otherTipNeoDTO.setFactor(getReminds(lisRemind));
  605. otherTipNeoDTOS.add(otherTipNeoDTO);
  606. }
  607. }
  608. }
  609. }
  610. }
  611. } catch (Exception ex) {
  612. ex.printStackTrace();
  613. }
  614. return otherTipNeoDTOS;
  615. }
  616. public List<OtherTipNeoDTO> updateTipNeoDTO(List<OtherTipNeoDTO> otherTipNeoDTOS, Lis lis, LisRemind lisRemind) {
  617. OtherTipNeoDTO otherTipNeoDTO = new OtherTipNeoDTO();
  618. BeanUtils.copyProperties(lis, otherTipNeoDTO);
  619. otherTipNeoDTO.setFactor(getReminds(lisRemind));
  620. otherTipNeoDTOS.add(otherTipNeoDTO);
  621. return otherTipNeoDTOS;
  622. }
  623. public List<NodeNeoDTO> getReminds(LisRemind lisRemind) {
  624. List<NodeNeoDTO> nodeNeoDTOS = new ArrayList<>();
  625. NodeNeoDTO nodeNeoDTO;
  626. for (LisRemindYiBaoDiseaseName lisReminddisease : lisRemind.getLisReminddisease()) {
  627. if (NeoUtil.isExist(lisReminddisease)) {
  628. nodeNeoDTO = new NodeNeoDTO();
  629. nodeNeoDTO.setName(lisReminddisease.getYiBaoDiseaseName().getName());
  630. nodeNeoDTO.setTermtype(Constants.zhenduan);
  631. nodeNeoDTOS.add(nodeNeoDTO);
  632. }
  633. }
  634. for (LisRemindMedicine lisRemindmedicine : lisRemind.getLisRemindmedicines()) {
  635. if (NeoUtil.isExist(lisRemindmedicine)) {
  636. nodeNeoDTO = new NodeNeoDTO();
  637. nodeNeoDTO.setName(lisRemindmedicine.getMedicine().getName());
  638. nodeNeoDTO.setTermtype(Constants.yaoping);
  639. nodeNeoDTOS.add(nodeNeoDTO);
  640. }
  641. }
  642. return nodeNeoDTOS;
  643. }
  644. /**
  645. * 处理建议输血
  646. */
  647. public List<OtherTipTransfusionNeoDTO> getRecommendTransfs(WordCrfDTO wordCrfDTO) {
  648. TransfusionSuggestNode transfusionSuggestNode = new TransfusionSuggestNode();
  649. List<OtherTipTransfusionNeoDTO> otherTipTransfsNeoDTOS = transfusionSuggestNode.getTransfusionSuggest(wordCrfDTO, transfusionSuggestRepository);
  650. return otherTipTransfsNeoDTOS;
  651. }
  652. /**
  653. * 处理辅检提醒
  654. */
  655. public List<OtherTipPacsNeoDTO> getPacsReminds(WordCrfDTO wordCrfDTO) {
  656. PacsRemindNode pacsRemindNode = new PacsRemindNode();
  657. List<OtherTipPacsNeoDTO> otherTipPacsNeoDTOS = pacsRemindNode.getPacsReminds(wordCrfDTO, pacsRemindRepository);
  658. return otherTipPacsNeoDTOS;
  659. }
  660. /**
  661. * 处理处方开单合理性
  662. */
  663. public List<BillNeoDTO> getDrugBill(List<Map<String, String>> medsterm) {
  664. MedicineNode medicineNode = new MedicineNode();
  665. List<BillNeoDTO> billNeoDTOs = medicineNode.getMedicineBill(medsterm, medicineRepository, medRegNameRepository);
  666. return billNeoDTOs;
  667. }
  668. /**
  669. * 处理辅检开单合理性
  670. */
  671. public List<BillNeoDTO> getPacsBill(List<Map<String, String>> pacsterm) {
  672. PacsNameNode pacsNode = new PacsNameNode();
  673. List<BillNeoDTO> billNeoDTOs = pacsNode.getPacsBill(pacsterm, pacsNameRepository);
  674. PacsSubNameNode pacsSubNode = new PacsSubNameNode();
  675. billNeoDTOs.addAll(pacsSubNode.getSubPacsBill(pacsterm, pacsSubNameRepository));
  676. return billNeoDTOs;
  677. }
  678. /**
  679. * 处理化验套餐开单合理性
  680. */
  681. public List<BillNeoDTO> getLisBill(List<Map<String, String>> lissetterms) {
  682. LisSetNode lisSetNode = new LisSetNode();
  683. List<BillNeoDTO> billNeoDTOs = lisSetNode.getLisBill(lissetterms, lisSetRepository);
  684. return billNeoDTOs;
  685. }
  686. /**
  687. * 处理化验开单合理性
  688. */
  689. public List<BillNeoDTO> getLisDetailBill(List<Map<String, String>> listerm) {
  690. LisNameNode lisNode = new LisNameNode();
  691. List<BillNeoDTO> billNeoDTOs = lisNode.getLisDetailBill(listerm, lisNameRepository);
  692. return billNeoDTOs;
  693. }
  694. /**
  695. * 处理手术开单合理性
  696. */
  697. public List<BillNeoDTO> getOperationBill(List<Map<String, String>> opterms) {
  698. YiBaoOperationNameNode yiBaoOpNode = new YiBaoOperationNameNode();
  699. List<BillNeoDTO> billNeoDTOs = yiBaoOpNode.getOperationBill(opterms, yiBaoOperationRepository);
  700. return billNeoDTOs;
  701. }
  702. /**
  703. * 处理联合项目开单合理性
  704. */
  705. public List<BillNeoDTO> getCombiOpBill(List<Map<String, String>> combiterms) {
  706. CombiOperationNode combiNode = new CombiOperationNode();
  707. List<BillNeoDTO> billNeoDTOS = combiNode.getCombiOpBill(combiterms, combiOperationRepository);
  708. return billNeoDTOS;
  709. }
  710. /**
  711. * 处理输血开单合理性
  712. */
  713. public List<BillNeoDTO> getTransfusionBill(List<Map<String, String>> termlist) {
  714. TransfusionRemindNode transfusionRemindNode = new TransfusionRemindNode();
  715. List<BillNeoDTO> billNeoDTOS = transfusionRemindNode.getTransfusionBill(termlist, transfusionRemindRepository);
  716. return billNeoDTOS;
  717. }
  718. /**
  719. * 推送疾病信息
  720. *
  721. * @param neoPushVO
  722. * @return
  723. */
  724. public NeoPushDTO getDiagInfo(NeoPushVO neoPushVO) {
  725. NeoPushDTO pushDTO = new NeoPushDTO();
  726. // YiBaoDiseaseNode icdDiseaseNode = new YiBaoDiseaseNode();
  727. String term = neoPushVO.getDiagVo().getDiags().get(0).getName();
  728. /*List<YiBaoDiseaseName> yiBaoName = yiBaoDiseaseRepository.findByNameIs(term);
  729. YiBaoDiseaseName icdDisease = null;
  730. if (ListUtil.isNotEmpty(yiBaoName)) {
  731. icdDisease = yiBaoName.get(0);
  732. }
  733. if (icdDisease != null) {
  734. icdDisease = NeoUtil.extract_node(icdDisease);
  735. pushDTO = icdDiseaseNode.YiBaoDiseasetoDiseaseDTO(icdDisease, neoPushVO);
  736. }*/
  737. pushDTO = this.reverseInfo(term);
  738. return pushDTO;
  739. }
  740. /**
  741. * 获取化验危急值
  742. *
  743. * @param criticalNeoVO
  744. */
  745. public List<CriticalNeoDTO> getLisCritical(CriticalNeoVO criticalNeoVO) {
  746. LisNameNode lisNode = new LisNameNode();
  747. List<CriticalNeoDTO> criticalNeoDTOs = lisNode.getLisCritialList(criticalNeoVO, lisNameRepository);
  748. return criticalNeoDTOs;
  749. }
  750. /**
  751. * 获取辅检危急值
  752. *
  753. * @Param criticalNeoVO
  754. */
  755. public List<CriticalNeoDTO> getPacsCritical(CriticalNeoVO criticalNeoVO) {
  756. PacsCriticalNode pacsCriticalNode = new PacsCriticalNode();
  757. List<CriticalNeoDTO> criticalNeoDTOS = pacsCriticalNode.getPacsList(criticalNeoVO, pacsCriticalRepository);
  758. return criticalNeoDTOS;
  759. }
  760. /**
  761. * 处理高危药品数据
  762. *
  763. * @param drugs
  764. * @return
  765. */
  766. public List<HighRiskNeoDTO> getHighRiskDrugList(List<Drug> drugs) {
  767. MedRegNameNode medRegNameNode = new MedRegNameNode();
  768. List<HighRiskNeoDTO> highRiskNeoDTOS = medRegNameNode.getHighRiskDrug(drugs, medicineRepository, medicineCodeRepository);
  769. return highRiskNeoDTOS;
  770. }
  771. /**
  772. * 处理高危手术和操作数据
  773. *
  774. * @param wordCrfDTO
  775. * @return
  776. */
  777. public List<HighRiskNeoDTO> getHighRiskOperationList(WordCrfDTO wordCrfDTO) {
  778. YiBaoOperationNameNode yiBaoOperationNode = new YiBaoOperationNameNode();
  779. List<HighRiskNeoDTO> highRiskNeoDTOS = yiBaoOperationNode.getHighRiskOperation(wordCrfDTO, yiBaoOperationRepository);
  780. return highRiskNeoDTOS;
  781. }
  782. /**
  783. * 提取方法
  784. *
  785. * @param jsonArray
  786. * @param originName
  787. * @param map
  788. */
  789. public void putMap(JSONArray jsonArray, String originName, Map<String, String> map) {
  790. if (jsonArray.size() == 2) {
  791. double likeRate = jsonArray.getDoubleValue(1);
  792. // System.out.println(originName + " " + likeRate);
  793. if (likeRate > 0.9) {
  794. String standName = jsonArray.getString(0);
  795. map.put(originName, standName);
  796. } else {
  797. map.put(originName, originName);
  798. }
  799. }
  800. }
  801. /**
  802. * 标准词转换
  803. * 类型,疾病: disease,症状: symptom,手术和操作:operation,药品: drug,实验室检查:lis,辅助检查:pacs, 辅助检查:vital"
  804. *
  805. * @param standConvert
  806. * @return Map<String, Map < String, String>> -->Map<类型, Map<原始词, 标准词>>
  807. */
  808. public Map<String, Map<String, String>> standConvertCrf(StandConvert standConvert) {
  809. Map<String, Map<String, String>> map = new LinkedHashMap<>();
  810. List<StandConvertCrfVO> standConvertCrfVOList = new ArrayList<>();
  811. List<String> clinicalConList = getConvertList(standConvert.getClinicalList(), StandConvertEnum.symptom.toString(), standConvertCrfVOList);
  812. List<String> operationConList = getConvertList(standConvert.getOperationList(), StandConvertEnum.operation.toString(), standConvertCrfVOList);
  813. List<String> drugConList = getConvertList(standConvert.getDrugList(), StandConvertEnum.drug.toString(), standConvertCrfVOList);
  814. List<String> vitallConList = getConvertList(standConvert.getVitalList(), StandConvertEnum.vital.toString(), standConvertCrfVOList);
  815. List<String> diseaseConList = getConvertList(standConvert.getDiaglList(), StandConvertEnum.disease.toString(), standConvertCrfVOList);
  816. List<String> pacsConList = getConvertList(standConvert.getPacsList(), StandConvertEnum.pacs.toString(), standConvertCrfVOList);
  817. List<String> lisConList = getConvertList(standConvert.getLisList(), StandConvertEnum.lis.toString(), standConvertCrfVOList);
  818. List<String> transfusionConList = getConvertList(standConvert.getTransfusionList(), StandConvertEnum.transfusion.toString(), standConvertCrfVOList);
  819. StandConvertCrfBatchDTO standConvertCrfBatchDTO = new StandConvertCrfBatchDTO();
  820. if (!(ListUtil.isEmpty(clinicalConList) && ListUtil.isEmpty(operationConList) && ListUtil.isEmpty(drugConList)
  821. && ListUtil.isEmpty(vitallConList) && ListUtil.isEmpty(diseaseConList) && ListUtil.isEmpty(pacsConList)
  822. && ListUtil.isEmpty(lisConList) && ListUtil.isEmpty(transfusionConList))) {
  823. try {
  824. standConvertCrfBatchDTO = standConvertServiceClient.similarityBatch(standConvertCrfVOList);
  825. } catch (Exception e) {
  826. throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "标准词转换【服务器】挂了!" + e.getMessage());
  827. }
  828. }
  829. Map<String, Map<String, StandConvertCrfDTO>> crfMap = standConvertCrfBatchDTO.getData();
  830. getConvertMap(crfMap, StandConvertEnum.symptom.toString(), clinicalConList, standConvert.getClinicalList(), map);
  831. getConvertMap(crfMap, StandConvertEnum.operation.toString(), operationConList, standConvert.getOperationList(), map);
  832. getConvertMap(crfMap, StandConvertEnum.drug.toString(), drugConList, standConvert.getDrugList(), map);
  833. getConvertMap(crfMap, StandConvertEnum.vital.toString(), vitallConList, standConvert.getVitalList(), map);
  834. getConvertMap(crfMap, StandConvertEnum.disease.toString(), diseaseConList, standConvert.getDiaglList(), map);
  835. getConvertMap(crfMap, StandConvertEnum.pacs.toString(), pacsConList, standConvert.getPacsList(), map);
  836. getConvertMap(crfMap, StandConvertEnum.lis.toString(), lisConList, standConvert.getLisList(), map);
  837. getConvertMap(crfMap, StandConvertEnum.transfusion.toString(), transfusionConList, standConvert.getTransfusionList(), map);
  838. return map;
  839. }
  840. /**
  841. * 入参数据处理
  842. *
  843. * @param wordList
  844. * @param type
  845. * @param standConvertCrfVOList
  846. */
  847. public List<String> getConvertList(List<String> wordList, String type, List<StandConvertCrfVO> standConvertCrfVOList) {
  848. List<String> convertList = new ArrayList<>();
  849. if (ListUtil.isEmpty(wordList)) {
  850. return null;
  851. }
  852. if (ListUtil.isNotEmpty(wordList)) {
  853. for (String s : wordList) {
  854. String value = redisUtil.getWithString(type + "Conv:" + s);
  855. if (StringUtil.isBlank(value)) {
  856. StandConvertCrfVO standConvertCrfVO = new StandConvertCrfVO();
  857. standConvertCrfVO.setWord_type(type);
  858. standConvertCrfVO.setWord(s);
  859. standConvertCrfVOList.add(standConvertCrfVO);
  860. if (!convertList.contains(s)) {
  861. convertList.add(s);
  862. }
  863. }
  864. }
  865. }
  866. return convertList;
  867. }
  868. /**
  869. * 获取标准词转换map结果,并更新redis
  870. *
  871. * @param crfDTO
  872. * @param type
  873. * @param convertList
  874. * @param map
  875. */
  876. public void getConvertMap(Map<String, Map<String, StandConvertCrfDTO>> crfDTO, String type, List<String> convertList,
  877. List<String> originList, Map<String, Map<String, String>> map) {
  878. Map<String, String> typeMap = new LinkedHashMap<>();
  879. if (ListUtil.isNotEmpty(convertList)) {
  880. Map<String, StandConvertCrfDTO> crfMap = crfDTO.get(type);
  881. for (String s : convertList) {
  882. String lastS = s;
  883. if (StringUtil.isBlank(s)) {
  884. continue;
  885. }
  886. if (crfMap != null) {
  887. StandConvertCrfDTO standConvertCrfDTO = crfMap.get(s);
  888. if (standConvertCrfDTO != null) {
  889. List<Map<String, String>> list = standConvertCrfDTO.getStandard_words();
  890. if (ListUtil.isEmpty(list)) {
  891. redisUtil.updateValue(type + "Conv:" + s, s);
  892. } else {
  893. String rateStr = standConvertCrfDTO.getStandard_words().get(0).get("rate");
  894. if (StringUtil.isBlank(rateStr)) {
  895. redisUtil.updateValue(type + "Conv:" + s, s);
  896. } else {
  897. BigDecimal rate = new BigDecimal(rateStr);
  898. int flag = rate.compareTo(new BigDecimal(standConvertRate));
  899. if (flag < 0) {
  900. redisUtil.updateValue(type + "Conv:" + s, s);
  901. } else {
  902. redisUtil.updateValue(type + "Conv:" + s, standConvertCrfDTO.getStandard_words().get(0).get("standard_word"));
  903. lastS = standConvertCrfDTO.getStandard_words().get(0).get("standard_word");
  904. }
  905. }
  906. }
  907. } else {
  908. redisUtil.updateValue(type + "Conv:" + s, s);
  909. }
  910. }
  911. typeMap.put(s, lastS);
  912. }
  913. }
  914. // 将所有的词放入typeMap中
  915. for (String s : originList) {
  916. if (!typeMap.containsKey(s)) {
  917. typeMap.put(s, s);
  918. }
  919. }
  920. map.put(type, typeMap);
  921. }
  922. }