Bläddra i källkod

添加国临诊断与手术对医保的匹配

lighter 3 år sedan
förälder
incheckning
54046b5a45

+ 22 - 7
src/main/java/thyyxxk/webserver/controller/dictionary/HisWjwMatchController.java

@@ -25,9 +25,6 @@ public class HisWjwMatchController {
         if (StringUtil.isBlank(label)) {
             return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "label参数不能为空。");
         }
-        if (!label.equals("anaesthesia") && !label.equals("department")) {
-            return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "label参数不正确。");
-        }
         Map<String, List<HisWjwMatchEntity>> result = service.selectMatchableDataByLabel(label);
         if (null == result) {
             return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
@@ -35,6 +32,13 @@ public class HisWjwMatchController {
         return ResultVoUtil.success(result);
     }
 
+    @GetMapping("/fetchSimilarities")
+    public ResultVo<List<HisWjwMatchEntity>> fetchSimilarities(@RequestParam("label") String label,
+                                                               @RequestParam("name") String name,
+                                                               @RequestParam("key") String key) {
+        return ResultVoUtil.success(service.fetchSimilarities(label, name, key));
+    }
+
     @PostMapping("/executeMatchAction")
     public ResultVo<String> executeMatchAction(@RequestBody HisWjwMatchEntity entity) {
         if (StringUtil.isBlank(entity.getCode())) {
@@ -43,11 +47,22 @@ public class HisWjwMatchController {
         if (StringUtil.isBlank(entity.getLabel())) {
             return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "匹配数据类别不能为空!");
         }
-        if (entity.getLabel().equals("anaesthesia")) {
-            entity.setLabel("zd_anaesthesia");
-        } else {
-            entity.setLabel("zd_unit_code");
+        switch (entity.getLabel()) {
+            case "anaesthesia":
+                entity.setLabel("zd_anaesthesia");
+                break;
+            case "department":
+                entity.setLabel("zd_unit_code");
+                break;
+            case "diagnose":
+                entity.setLabel("zd_icd_code_new");
+                break;
+            case "surgery":
+            default:
+                entity.setLabel("zd_icd9_cm3");
+                break;
         }
+
         return ResultVoUtil.success(service.executeMatchAction(entity));
     }
 

+ 17 - 1
src/main/java/thyyxxk/webserver/dao/his/dictionary/HisWjwMatchDao.java

@@ -22,6 +22,22 @@ public interface HisWjwMatchDao {
     @Select("select code,name,py_code from ${table}")
     List<HisWjwMatchEntity> selectWjwData(@Param("table") String table);
 
-    @Update("update ${label} set wjw_code=#{wjwCode} where code=#{code}")
+    @Select("select rtrim(code) as code, rtrim(name) as name from ${table} where yb_code is null")
+    List<HisWjwMatchEntity> selectNationTempData(@Param("table") String table);
+
+    @Select("select ${codeColumn} as code, ${nameColumn} as name, py_code from ${table} where " +
+            "${codeColumn} like #{key} ")
+    List<HisWjwMatchEntity> selectMedInsData(@Param("table") String table,
+                                             @Param("codeColumn") String codeColumn,
+                                             @Param("nameColumn") String nameColumn,
+                                             @Param("key") String key);
+
+    @Update("<script>" +
+            "update ${label} set ${targetCodeColumn}=#{wjwCode} " +
+            "<if test=\"targetNameColumn != null and targetNameColumn != '' \">" +
+            ", ${targetNameColumn}=#{wjwName} " +
+            "</if>" +
+            "where code=#{code} " +
+            "</script>")
     void executeMatchAction(HisWjwMatchEntity entity);
 }

+ 4 - 0
src/main/java/thyyxxk/webserver/entity/dictionary/HisWjwMatchEntity.java

@@ -7,6 +7,10 @@ public class HisWjwMatchEntity {
     private String code;
     private String name;
     private String wjwCode;
+    private String wjwName;
     private String pyCode;
+    private Double similarity;
     private String label;
+    private String targetCodeColumn;
+    private String targetNameColumn;
 }

+ 52 - 11
src/main/java/thyyxxk/webserver/service/dictionary/HisWjwMatchService.java

@@ -8,9 +8,7 @@ import thyyxxk.webserver.dao.his.dictionary.HisWjwMatchDao;
 import thyyxxk.webserver.entity.dictionary.HisWjwMatchEntity;
 import thyyxxk.webserver.utils.StringUtil;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 @Slf4j
 @Service
@@ -24,23 +22,66 @@ public class HisWjwMatchService {
 
     public Map<String, List<HisWjwMatchEntity>> selectMatchableDataByLabel(String label) {
         String histable, wjwtable;
-        if (label.equals("anaesthesia")) {
-            histable = "zd_anaesthesia";
-            wjwtable = "t_wjw_anaesthesia";
+        int type;
+        switch (label) {
+            case "department":
+                histable = "zd_unit_code";
+                wjwtable = "t_wjw_dept";
+                type = 1;
+                break;
+            case "anaesthesia":
+                histable = "zd_anaesthesia";
+                wjwtable = "t_wjw_anaesthesia";
+                type = 1;
+                break;
+            case "diagnose":
+                histable = "zd_icd_code_new";
+                wjwtable = "t_si_dl_dss_dns";
+                type = 2;
+                break;
+            case "surgery":
+            default:
+                histable = "zd_icd9_cm3";
+                wjwtable = "t_si_dl_oprtn";
+                type = 3;
+                break;
+        }
+        List<HisWjwMatchEntity> hisList;
+        List<HisWjwMatchEntity> wjwList;
+        if (type == 1) {
+            hisList = dao.selectHisData(histable);
+            wjwList = dao.selectWjwData(wjwtable);
         } else {
-            histable = "zd_unit_code";
-            wjwtable = "t_wjw_dept";
+            hisList = dao.selectNationTempData(histable);
+            wjwList = new ArrayList<>();
         }
-        List<HisWjwMatchEntity> hisList = dao.selectHisData(histable);
-        List<HisWjwMatchEntity> wjwList = dao.selectWjwData(wjwtable);
         Map<String, List<HisWjwMatchEntity>> result = new HashMap<>();
         result.put("hisList", hisList);
         result.put("wjwList", wjwList);
         return result;
     }
 
+    public List<HisWjwMatchEntity> fetchSimilarities(String label, String name, String key) {
+        String table,codeColumn,nameColumn;
+        if (label.equals("diagnose")) {
+            table = "t_si_dl_dss_dns";
+            codeColumn = "diagnosis_code";
+            nameColumn = "diagnosis_name";
+        } else {
+            table = "t_si_dl_oprtn";
+            codeColumn = "surgical_operation_code";
+            nameColumn = "operation_operation_name";
+        }
+        List<HisWjwMatchEntity> list = dao.selectMedInsData(table, codeColumn, nameColumn, key);
+        list.forEach(item -> {
+            item.setSimilarity(StringUtil.getSimilarDegree(name, item.getName()));
+        });
+        list.sort(Comparator.comparingDouble(HisWjwMatchEntity::getSimilarity).reversed());
+        return list;
+    }
+
     public String executeMatchAction(HisWjwMatchEntity entity) {
-        log.info("匹配卫健委字典:{}", JSONObject.toJSONString(entity));
+        log.info("匹配卫健委/国临字典:{}", JSONObject.toJSONString(entity));
         dao.executeMatchAction(entity);
         return StringUtil.isBlank(entity.getWjwCode()) ? "撤销匹配成功" : "匹配成功";
     }

+ 39 - 0
src/main/java/thyyxxk/webserver/utils/StringUtil.java

@@ -4,7 +4,9 @@ package thyyxxk.webserver.utils;
 import lombok.extern.slf4j.Slf4j;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -127,5 +129,42 @@ public class StringUtil {
         }
     }
 
+    /**
+     * 字符串相似度算法
+     * */
+    public static double getSimilarDegree(String source, String target) {
+        Map<Character, int[]> vector = new HashMap<>();
+        int[] charCountArray;
+        for (char sourceChar : source.toCharArray()) {
+            if (vector.containsKey(sourceChar)) {
+                vector.get(sourceChar)[0]++;
+            } else {
+                charCountArray = new int[2];
+                charCountArray[0] = 1;
+                vector.put(sourceChar, charCountArray);
+            }
+        }
+        for (char targetChar : target.toCharArray()) {
+            if (vector.containsKey(targetChar)) {
+                vector.get(targetChar)[1] ++;
+            } else {
+                charCountArray = new int[2];
+                charCountArray[1] = 1;
+                vector.put(targetChar, charCountArray);
+            }
+        }
+        double v1Modulo = 0d;
+        double v2Modulo = 0d;
+        double vProduct = 0d;
+        for (Map.Entry<Character, int[]> entry : vector.entrySet()) {
+            int[] tempArray = entry.getValue();
+            v1Modulo += tempArray[0] * tempArray[0];
+            v2Modulo += tempArray[1] * tempArray[1];
+            vProduct += tempArray[0] * tempArray[1];
+        }
+        v1Modulo = Math.sqrt(v1Modulo);
+        v2Modulo = Math.sqrt(v2Modulo);
+        return vProduct / (v1Modulo * v2Modulo);
+    }
 }