BillProcess.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. package com.diagbot.process;
  2. import com.diagbot.dto.*;
  3. import com.diagbot.enums.NeoEnum;
  4. import com.diagbot.facade.NeoFacade;
  5. import com.diagbot.model.entity.*;
  6. import com.diagbot.model.label.ChiefLabel;
  7. import com.diagbot.model.label.DiagLabel;
  8. import com.diagbot.model.label.PastLabel;
  9. import com.diagbot.model.label.PresentLabel;
  10. import com.diagbot.rule.*;
  11. import com.diagbot.util.BeanUtil;
  12. import com.diagbot.util.ListUtil;
  13. import org.apache.commons.lang3.StringUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Component;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import java.util.Map;
  19. /**
  20. * @Description: 开单总入口
  21. * @author: zhoutg
  22. * @time: 2018/8/6 9:11
  23. */
  24. @Component
  25. public class BillProcess {
  26. @Autowired
  27. NeoFacade neoFacade;
  28. public void process(List<BillNeoDTO> billNeoDTOList, WordCrfDTO wordCrfDTO, IndicationDTO res) {
  29. // 合并图谱数据到同一个对象中
  30. List<BillNeoMaxDTO> billNeoMaxDTOList = new ArrayList<>();
  31. for (BillNeoDTO billNeoDTO : billNeoDTOList) {
  32. BillNeoMaxDTO billNeoMaxDTO = new BillNeoMaxDTO();
  33. if (billNeoDTO.getDrugBillNeoDTO() != null) {
  34. BeanUtil.copyProperties(billNeoDTO.getDrugBillNeoDTO(), billNeoMaxDTO);
  35. } else if (billNeoDTO.getLisBillNeoDTO() != null) {
  36. BeanUtil.copyProperties(billNeoDTO.getLisBillNeoDTO(), billNeoMaxDTO);
  37. } else if (billNeoDTO.getPacsBillNeoDTO() != null) {
  38. BeanUtil.copyProperties(billNeoDTO.getPacsBillNeoDTO(), billNeoMaxDTO);
  39. }
  40. billNeoMaxDTO.setOrderName(billNeoDTO.getName()); // 开单名称
  41. billNeoMaxDTO.setOrderStandName(billNeoDTO.getStandname()); // 开单标准名称
  42. // TODO 测试数据开始
  43. if (billNeoDTO.getName().equals("普通胃镜检查")) {
  44. NodeNeoDTO sexNeo = new NodeNeoDTO();
  45. sexNeo.setName("男");
  46. billNeoMaxDTO.setGender(sexNeo);
  47. NodeNeoDTO nodeNeoDTO = new NodeNeoDTO();
  48. nodeNeoDTO.setName("红细胞压积");
  49. nodeNeoDTO.setVal("阳性");
  50. billNeoDTO.getPacsBillNeoDTO().getLis().add(nodeNeoDTO);
  51. NodeNeoDTO opereat = new NodeNeoDTO();
  52. opereat.setName("胸腔镜下左下肺叶切除术");
  53. billNeoDTO.getPacsBillNeoDTO().getOperations().add(opereat);
  54. NodeNeoDTO opereat2 = new NodeNeoDTO();
  55. opereat2.setName("区域淋巴结清扫术");
  56. billNeoDTO.getPacsBillNeoDTO().getOperations().add(opereat2);
  57. NodeNeoDTO drug = new NodeNeoDTO();
  58. drug.setName("青霉素类");
  59. billNeoDTO.getPacsBillNeoDTO().getAllergicmeds().add(drug);
  60. NodeNeoDTO drug3 = new NodeNeoDTO();
  61. drug3.setName("泰舒达类");
  62. billNeoDTO.getPacsBillNeoDTO().getOralmeds().add(drug3);
  63. // NodeNeoDTO vital = new NodeNeoDTO();
  64. // vital.setName("体温");
  65. // vital.setMax(new BigDecimal(39.1));
  66. // vital.setMin(new BigDecimal(37.1));
  67. // billNeoDTO.getVitals().add(vital);
  68. }
  69. // 测试数据结束
  70. System.out.println(billNeoMaxDTO);
  71. billNeoMaxDTOList.add(billNeoMaxDTO);
  72. }
  73. processRule(billNeoMaxDTOList, wordCrfDTO, res);
  74. }
  75. // 规则处理
  76. public void processRule(List<BillNeoMaxDTO> billNeoMaxDTOList, WordCrfDTO wordCrfDTO, IndicationDTO indicationDTO) {
  77. // 获取药品缓存
  78. Map<String, List<String>> drugMap = neoFacade.getDrugCache();
  79. DiagLabel diagLabel = wordCrfDTO.getDiagLabel();
  80. ChiefLabel chiefLabel = wordCrfDTO.getChiefLabel();
  81. PresentLabel presentLabel = wordCrfDTO.getPresentLabel();
  82. PastLabel pastLabel = wordCrfDTO.getPastLabel();
  83. // 体征
  84. List<Vital> vitals = wordCrfDTO.getVitalLabel().getVitals();
  85. // 诊断数据
  86. List<Diag> diags = diagLabel.getDiags();
  87. // 手术数据
  88. List<Operation> operations_present = presentLabel.getOperations();
  89. List<Operation> operations_past = pastLabel.getOperations();
  90. operations_present.addAll(operations_past);
  91. // 临床表现数据
  92. List<Clinical> clinicals = new ArrayList<>();
  93. if(chiefLabel != null && ListUtil.isNotEmpty(chiefLabel.getClinicals())){
  94. clinicals.addAll(chiefLabel.getClinicals());
  95. }
  96. // 现病史临床表现数据先不用
  97. if(presentLabel != null && ListUtil.isNotEmpty(presentLabel.getClinicals())){
  98. clinicals.addAll(presentLabel.getClinicals());
  99. }
  100. List<BillMsg> billMsgList = new ArrayList<>();
  101. for (BillNeoMaxDTO bill : billNeoMaxDTOList) {
  102. // 性别
  103. SexRule.compareSexWithBill(wordCrfDTO, bill, billMsgList, NeoEnum.gender.getName());
  104. // 年龄
  105. AgeRule.compareAgeWithBill(wordCrfDTO, bill, billMsgList, NeoEnum.ageNeoDTO.getName());
  106. // 诊断
  107. CommonRule.compareNameWithBill(bill.getDisease(), diags, bill, billMsgList, NeoEnum.disease.getName());
  108. // 化验
  109. LisRule.compareLisWithBill(wordCrfDTO.getLis(), bill, billMsgList, NeoEnum.lis.getName());
  110. //体征
  111. VitalRule.compareVitalWithBill(vitals, bill, billMsgList, NeoEnum.vitals.getName());
  112. // 辅检
  113. PacsRule.comparePacsWithBill(bill.getPacs(), wordCrfDTO.getPacs(), bill, billMsgList, NeoEnum.pacs.getName());
  114. // 临床表现
  115. CommonRule.compareNameWithBill(bill.getClinicfindings(), clinicals, bill, billMsgList, NeoEnum.clinicfindings.getName());
  116. // 手术(既往史、现病史)
  117. CommonRule.compareNameWithBill(bill.getOperations(), operations_present, bill, billMsgList, NeoEnum.operations.getName());
  118. // 禁忌过敏药品(既往史)
  119. DrugRule.compareDrugWithBill(bill.getAllergicmeds(), pastLabel.getAllergyMedicines(), bill, billMsgList, drugMap, NeoEnum.allergicmeds.getName());
  120. // 服用药品(现病史一般情况后的药品)
  121. DrugRule.compareDrugWithBill(bill.getOralmeds(), takeMedicine(presentLabel), bill, billMsgList, drugMap, NeoEnum.oralmeds.getName());
  122. }
  123. indicationDTO.setBillMsgList(billMsgList);
  124. }
  125. /**
  126. * 一般情况以后的药品
  127. * @param presentLabel
  128. */
  129. public List<Medicine> takeMedicine(PresentLabel presentLabel){
  130. List<Medicine> takems = new ArrayList<>();
  131. List<GeneralDesc> generals = presentLabel.getGenerals();
  132. List<Medicine> medicines = presentLabel.getMedicines();
  133. if (generals.size() > 0) {
  134. String presentText = presentLabel.getText();
  135. if (StringUtils.isNotBlank(presentText) && medicines != null && medicines.size() > 0) {
  136. String lastGeneral = generals.get(generals.size() - 1).getName();
  137. int lastGeneralIndex = presentText.lastIndexOf(lastGeneral);
  138. for (Medicine medicine : medicines) {
  139. /* 现病史中一般情况之后的药品名称,并且不包含不详 */
  140. int medicine_index = presentText.indexOf(medicine.getName());
  141. if (medicine_index > lastGeneralIndex && !medicine.getName().contains("不详")) {
  142. takems.add(medicine);
  143. }
  144. }
  145. }
  146. }
  147. return takems;
  148. }
  149. }