HisWjwMatchService.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package thyyxxk.webserver.service.dictionary;
  2. import com.alibaba.fastjson.JSONObject;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Service;
  6. import thyyxxk.webserver.dao.his.dictionary.HisWjwMatchDao;
  7. import thyyxxk.webserver.entity.dictionary.HisWjwMatchEntity;
  8. import thyyxxk.webserver.utils.StringUtil;
  9. import thyyxxk.webserver.utils.TokenUtil;
  10. import java.util.*;
  11. @Slf4j
  12. @Service
  13. public class HisWjwMatchService {
  14. private final HisWjwMatchDao dao;
  15. @Autowired
  16. public HisWjwMatchService(HisWjwMatchDao dao) {
  17. this.dao = dao;
  18. }
  19. public Map<String, List<HisWjwMatchEntity>> selectMatchableDataByLabel(String label) {
  20. String histable, wjwtable;
  21. int type;
  22. switch (label) {
  23. case "department":
  24. histable = "zd_unit_code";
  25. wjwtable = "t_wjw_dept";
  26. type = 1;
  27. break;
  28. case "anaesthesia":
  29. histable = "zd_anaesthesia";
  30. wjwtable = "t_wjw_anaesthesia";
  31. type = 1;
  32. break;
  33. case "diagnose":
  34. histable = "zd_icd_code_new";
  35. wjwtable = "t_si_dl_dss_dns";
  36. type = 2;
  37. break;
  38. case "surgery":
  39. histable = "zd_icd9_cm3";
  40. wjwtable = "t_si_dl_oprtn";
  41. type = 3;
  42. break;
  43. case "surgery_chargeCode":
  44. default:
  45. histable = "zd_icd9_cm3";
  46. wjwtable = "zd_charge_item";
  47. type = 4;
  48. break;
  49. }
  50. List<HisWjwMatchEntity> hisList;
  51. List<HisWjwMatchEntity> wjwList;
  52. if (type == 1) {
  53. hisList = dao.selectHisData(histable);
  54. wjwList = dao.selectWjwData(wjwtable);
  55. } else if (type == 4) {
  56. hisList = dao.selectSurgeries();
  57. wjwList = dao.selectChargeCodes();
  58. for (HisWjwMatchEntity entity : hisList) {
  59. if (null != entity.getWjwCode()) {
  60. entity.setChargeCodeString(entity.getWjwCode());
  61. entity.setChargeCode(entity.getWjwCode().split("\\^"));
  62. entity.setWjwCode(null);
  63. }
  64. if (null != entity.getWjwName()) {
  65. entity.setChargeNameString(entity.getWjwName());
  66. entity.setChargeName(entity.getWjwName().split("\\^"));
  67. entity.setWjwName(null);
  68. }
  69. }
  70. } else {
  71. hisList = dao.selectNationTempData(histable);
  72. wjwList = new ArrayList<>();
  73. }
  74. Map<String, List<HisWjwMatchEntity>> result = new HashMap<>();
  75. result.put("hisList", hisList);
  76. result.put("wjwList", wjwList);
  77. return result;
  78. }
  79. public List<HisWjwMatchEntity> fetchSimilarities(String label, String name, String key) {
  80. String table,codeColumn,nameColumn;
  81. if (label.equals("diagnose")) {
  82. table = "t_si_dl_dss_dns";
  83. codeColumn = "diagnosis_code";
  84. nameColumn = "diagnosis_name";
  85. } else {
  86. table = "t_si_dl_oprtn";
  87. codeColumn = "surgical_operation_code";
  88. nameColumn = "operation_operation_name";
  89. }
  90. List<HisWjwMatchEntity> list = dao.selectMedInsData(table, codeColumn, nameColumn, key);
  91. list.forEach(item -> {
  92. item.setSimilarity(StringUtil.getSimilarDegree(name, item.getName()));
  93. });
  94. list.sort(Comparator.comparingDouble(HisWjwMatchEntity::getSimilarity).reversed());
  95. return list;
  96. }
  97. public String executeMatchAction(HisWjwMatchEntity entity) {
  98. log.info("【操作员:{}】匹配卫健委/国临字典:{}", TokenUtil.getTokenUserId(), JSONObject.toJSONString(entity));
  99. if (entity.getLabel().equals("surgery_chargeCode")) {
  100. if (null != entity.getChargeCode()) {
  101. StringBuilder codeBuilder = new StringBuilder();
  102. StringBuilder nameBuilder = new StringBuilder();
  103. for (String code : entity.getChargeCode()) {
  104. codeBuilder.append(code).append('^');
  105. }
  106. if (codeBuilder.length() > 1) {
  107. entity.setWjwCode(codeBuilder.substring(0, codeBuilder.length() - 1));
  108. }
  109. for (String name : entity.getChargeName()) {
  110. nameBuilder.append(name).append('^');
  111. }
  112. if (nameBuilder.length() > 1) {
  113. entity.setWjwName(nameBuilder.substring(0, nameBuilder.length() - 1));
  114. }
  115. }
  116. dao.updateDateAndOper(entity.getCode(), TokenUtil.getTokenUserId());
  117. }
  118. dao.executeMatchAction(entity);
  119. return StringUtil.isBlank(entity.getWjwCode()) ? "撤销匹配成功" : "匹配成功";
  120. }
  121. }