Jelajahi Sumber

诊断依据导入

zhoutg 4 tahun lalu
induk
melakukan
c924e8d5d6

+ 15 - 0
doc/008.20210629诊断依据基础表扩展/med_2021.sql

@@ -0,0 +1,15 @@
+USE `med_2021`;
+
+drop TABLE if EXISTS kl_diagnose_base_relation;
+CREATE TABLE `kl_diagnose_base_relation` (
+  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
+  `is_deleted` char(1) NOT NULL DEFAULT 'N' COMMENT '是否删除,N:未删除,Y:删除',
+  `gmt_create` datetime NOT NULL DEFAULT '1970-01-01 12:00:00' COMMENT '记录创建时间',
+  `gmt_modified` datetime NOT NULL DEFAULT '1970-01-01 12:00:00' COMMENT '记录修改时间,如果时间是1970年则表示纪录未修改',
+  `creator` varchar(20) NOT NULL DEFAULT '0' COMMENT '创建人,0表示无创建人值',
+  `modifier` varchar(20) NOT NULL DEFAULT '0' COMMENT '修改人,如果为0则表示纪录未修改',
+  `diagnose_base_id` bigint(20) NOT NULL COMMENT 'diagnose_base_id',
+	`concept_id` bigint(20) NOT NULL COMMENT 'concept_id',
+  `order_no` int(11) NOT NULL DEFAULT '0' COMMENT '排序号',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='基础规则关联表';

+ 2 - 2
src/main/java/com/diagbot/config/CacheDeleteInit.java

@@ -48,8 +48,8 @@ public class CacheDeleteInit implements CommandLineRunner {
         cacheFacade.loadDeptPush();
         log.info("CDSS-CORE服务启动加载科室和推送映射成功!");
 
-        cacheFacade.loadAllRuleCache();
-        log.info("CDSS-CORE服务启动加载医学知识库中的所有规则缓存成功!");
+        // cacheFacade.loadAllRuleCache();
+        // log.info("CDSS-CORE服务启动加载医学知识库中的所有规则缓存成功!");
 
         cacheFacade.loadAllBaseDiagnoseCache();
         log.info("CDSS-CORE服务启动加载诊断依据缓存成功!");

+ 2 - 6
src/main/java/com/diagbot/dto/BaseDiagnoseDTO.java

@@ -11,10 +11,6 @@ import lombok.Setter;
 @Getter
 @Setter
 public class BaseDiagnoseDTO {
-    /**
-     * 联合唯一键
-     */
-    private String baseKey;
 
     /**
      * id逗号隔开
@@ -32,9 +28,9 @@ public class BaseDiagnoseDTO {
     private Integer baseLibType;
 
     /**
-     * 提示概念id
+     * 多个概念id
      */
-    private Long conceptId;
+    private String baseConceptids;
 
     /**
      * 基础规则类型(1:等于术语本身;2:存在比较;3:不等于术语本身;)

+ 2 - 1
src/main/java/com/diagbot/facade/KlDiagnoseFacade.java

@@ -243,7 +243,8 @@ public class KlDiagnoseFacade extends KlDiagnoseServiceImpl {
                             if (null != detailVO) {
                                 KlDiagnoseBase klDiagnoseBase = new KlDiagnoseBase();
                                 klDiagnoseBase.setGmtModified(now);
-                                klDiagnoseBase.setConceptId(detailVO.getBasConceptId());
+                                // TODO
+                                // klDiagnoseBase.setConceptId(detailVO.getBasConceptId());
                                 klDiagnoseBase.setType(detailVO.getBasType());
                                 klDiagnoseBase.setDescription(detailVO.getBasDescription());
                                 klDiagnoseBase.setMaxOperator(detailVO.getMaxOperator());

+ 5 - 4
src/main/java/com/diagbot/facade/KlDiagnoseImportFacade.java

@@ -244,10 +244,11 @@ public class KlDiagnoseImportFacade {
                 continue;
             }
             if (!type.contains("正则") && !diagtypes.contains(type)) {
-                KlConcept klConcept = concept_map.get(rule + "_" + String.valueOf(LexiconExtEnum.getEnum(type).getKey()));
-                if (klConcept != null) {
-                    idv.setConceptId(klConcept.getId());
-                }
+                // TODO
+                // KlConcept klConcept = concept_map.get(rule + "_" + String.valueOf(LexiconExtEnum.getEnum(type).getKey()));
+                // if (klConcept != null) {
+                //     idv.setConceptId(klConcept.getId());
+                // }
             }
         }
         return importDiagnoseVOS;

+ 6 - 7
src/main/java/com/diagbot/rule/CommonRule.java

@@ -81,7 +81,7 @@ public class CommonRule {
                 Negative val = (Negative) CoreUtil.getFieldValue(d, "negative");
                 if (val == null) {
                     String c = (String) CoreUtil.getFieldValue(d, "standName");
-                    if (StringUtils.isNotBlank(c) && CoreUtil.compareName(ruleBaseDTO, c)) {
+                    if (StringUtils.isNotBlank(c) && CoreUtil.compareNameMulti(ruleBaseDTO, c)) {
                         CoreUtil.addSplitString(baseIdList, ids);
                     }
                 }
@@ -93,14 +93,14 @@ public class CommonRule {
      * 比较是否包含
      *
      * @param input
-     * @param ruleBaseDTO
+     * @param name
      * @return
      */
-    public <T> Boolean containsItem(List<T> input, RuleBaseDTO ruleBaseDTO) {
-        if (ListUtil.isNotEmpty(input) && ruleBaseDTO != null) {
+    public <T> Boolean containsItem(List<T> input, String name) {
+        if (ListUtil.isNotEmpty(input) && StringUtil.isNotBlank(name)) {
             for (T t : input) {
                 String c = (String) CoreUtil.getFieldValue(t, "uniqueName"); // 标准名称
-                if (c.contains(ruleBaseDTO.getBaseLibName())) {
+                if (c.contains(name)) {
                     return true;
                 }
             }
@@ -175,8 +175,7 @@ public class CommonRule {
         if (ListUtil.isNotEmpty(input)) {
             for (T t : input) {
                 String c = (String) CoreUtil.getFieldValue(t, "uniqueName"); // 标准名称
-                String c_name = (String) CoreUtil.getFieldValue(t, "name"); // 界面名称
-                if (CoreUtil.compareName(ruleBaseDTO, c)) {
+                if (CoreUtil.compareNameMulti(ruleBaseDTO, c)) {
                     CoreUtil.addSplitString(baseIdList, ids);
                 }
             }

+ 43 - 39
src/main/java/com/diagbot/rule/GroupRule.java

@@ -75,49 +75,53 @@ public class GroupRule {
         String symptom = wordCrfDTO.getSymptom(); // 现病史内容
         String menstrual = wordCrfDTO.getMenstrual(); // 月经史
         boolean flag = false;
-        switch (ruleBaseDTO.getBaseLibName()) {
-            case "妊娠":
-                Map map = gravidityRule(wordCrfDTO);
-                if (CoreUtil.getMapFlag(map) == true) {
-                    flag = true;
-                }
-                break;
-            case "流产":
-                flag = commonRule.containsItem(wordCrfDTO.getDiag(), ruleBaseDTO);
-                break;
-            case "月经期":
-                String regex = "月经第(([零一二三四五六七八九十]{0,3})||([0-9]{0,2}))天";
-                String regex2 = "(?<!上一次)经期";
-                if (RegexUtil.getRegexRes(symptom, regex) || RegexUtil.getRegexRes(menstrual, regex)
-                        || RegexUtil.getRegexRes(symptom, regex2) || RegexUtil.getRegexRes(menstrual, regex2)) {
-                    flag = true;
-                }
-                break;
-            case "幼儿":
-                if (age != null) {
-                    if (age < 6.0D && 1.0D <= age) {
+        List<String> nameList = CoreUtil.getSplit(ruleBaseDTO.getBaseLibName());
+        for (String name : nameList) {
+            switch (name) {
+                case "妊娠":
+                    Map map = gravidityRule(wordCrfDTO);
+                    if (CoreUtil.getMapFlag(map) == true) {
                         flag = true;
                     }
-                }
-                break;
-            case "儿童":
-                if (age != null) {
-                    if (age < 18.0D && age >= 6.0D) {
+                    break;
+                case "流产":
+                    flag = commonRule.containsItem(wordCrfDTO.getDiag(), name);
+                    break;
+                case "月经期":
+                    String regex = "月经第(([零一二三四五六七八九十]{0,3})||([0-9]{0,2}))天";
+                    String regex2 = "(?<!上一次)经期";
+                    if (RegexUtil.getRegexRes(symptom, regex) || RegexUtil.getRegexRes(menstrual, regex)
+                            || RegexUtil.getRegexRes(symptom, regex2) || RegexUtil.getRegexRes(menstrual, regex2)) {
                         flag = true;
                     }
-                }
-                break;
-            case "成人":
-                if (age >= 18) {
-                    flag = true;
-                }
-                break;
-            case "新生儿":
-                if (age <= 1) {
-                    flag = true;
-                }
-                break;
-            default: break;
+                    break;
+                case "幼儿":
+                    if (age != null) {
+                        if (age < 6.0D && 1.0D <= age) {
+                            flag = true;
+                        }
+                    }
+                    break;
+                case "儿童":
+                    if (age != null) {
+                        if (age < 18.0D && age >= 6.0D) {
+                            flag = true;
+                        }
+                    }
+                    break;
+                case "成人":
+                    if (age >= 18) {
+                        flag = true;
+                    }
+                    break;
+                case "新生儿":
+                    if (age <= 1) {
+                        flag = true;
+                    }
+                    break;
+                default:
+                    break;
+            }
         }
         res.put("flag", flag);
         res.put("msg", ruleBaseDTO.getBaseLibName());

+ 1 - 1
src/main/java/com/diagbot/rule/VitalRule.java

@@ -48,7 +48,7 @@ public class VitalRule {
      * @param ids
      */
     public void push(VitalLabel vitalLabel, RuleBaseDTO ruleBaseDTO, List<Long> baseIdList, String ids) {
-        Map<String, Object> map = CoreUtil.compareVital(ruleBaseDTO, vitalLabel);
+        Map<String, Object> map = CoreUtil.compareVitalMulti(ruleBaseDTO, vitalLabel);
         if (CoreUtil.getMapFlag(map)) {
             CoreUtil.addSplitString(baseIdList, ids);
         }

+ 112 - 0
src/main/java/com/diagbot/util/CoreUtil.java

@@ -4,6 +4,7 @@ import com.diagbot.biz.push.entity.Item;
 import com.diagbot.biz.push.entity.Lis;
 import com.diagbot.dto.PushBaseDTO;
 import com.diagbot.dto.RuleBaseDTO;
+import com.diagbot.enums.CommonEnum;
 import com.diagbot.enums.LexiconEnum;
 import com.diagbot.model.entity.BodyPart;
 import com.diagbot.model.entity.Clinical;
@@ -430,6 +431,72 @@ public class CoreUtil {
         return map;
     }
 
+    /**
+     * 比较查体是否匹配
+     *
+     * @param ruleBaseDTO
+     * @param vitalLabel
+     * @return
+     */
+    public static Map<String, Object> compareVitalMulti(RuleBaseDTO ruleBaseDTO, VitalLabel vitalLabel) {
+        Map<String, Object> map = new LinkedHashMap<>();
+        List<String> msgList = new ArrayList<>();
+        map.put("msgList", msgList);
+        List<Vital> vitalList = vitalLabel.getVitals(); // 体征数据
+        List<Clinical> clinicals = vitalLabel.getClinicals(); // 体征临床表现
+        boolean flag = false;
+        if (ruleBaseDTO == null) {
+            map.put("flag", flag);
+            return map;
+        }
+        // if (StringUtil.isBlank(ruleBaseDTO.getBaseMaxValue()) && StringUtil.isBlank(ruleBaseDTO.getBaseMinValue())) {
+        // 如果是体格检查结果,就用临床表现比较;如果是体格检查项目,用体征数值比较
+        if (ruleBaseDTO.getBaseLibType().equals(LexiconEnum.VitalResult.getKey())) {
+            // 体征名称比较(例如:喉头水肿)
+            String libNameMulti = ruleBaseDTO.getBaseLibName();
+            if (libNameMulti.contains(CommonEnum.splitSymbol.getName())) {
+                for (Clinical clinical : clinicals) {
+                    List<String> nameList = Lists.newArrayList(libNameMulti.split(CommonEnum.splitSymbol.getName()));
+                    if (nameList.contains(clinical.getStandName())) {
+                        msgList.add(clinical.getName());
+                        flag = true;
+                    }
+                }
+            } else {
+                for (Clinical clinical : clinicals) {
+                    if (ruleBaseDTO.getBaseLibName().equals(clinical.getStandName())) {
+                        msgList.add(clinical.getName());
+                        flag = true;
+                    }
+                }
+            }
+        } else {
+            // 体征数值比较(例如:体温,血压)
+            for (Vital vital : vitalList) {
+                List<Usual> usualList = vital.getUsualList();
+                if (ruleBaseDTO.getBaseLibName().equals(vital.getStandName()) && vital.getPd() != null
+                        && StringUtil.isNotBlank(vital.getPd().getValue())) {
+                    flag = compareNum(ruleBaseDTO, Double.parseDouble(vital.getPd().getValue()));
+                    if (flag) {
+                        msgList.add(vital.getName() + subZeroAndDot(String.valueOf(vital.getPd().getValue())));
+                    }
+                } else if (ListUtil.isNotEmpty(usualList)) { // 血压比较
+                    for (Usual usual : usualList) {
+                        if (ruleBaseDTO.getBaseLibName().equals(usual.getStandName())) {
+                            flag = compareNum(ruleBaseDTO, Double.parseDouble(usual.getValue()));
+                            if (flag) {
+                                msgList.add(vital.getName() + subZeroAndDot(String.valueOf(vital.getPd().getValue())));
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        map.put("flag", flag);
+        return map;
+    }
+
     /**
      * 比较数值大小(double)
      *
@@ -710,6 +777,27 @@ public class CoreUtil {
         return false;
     }
 
+    /**
+     * 比较名称是否匹配(多个名称用分隔符隔开)
+     *
+     * @param ruleBaseDTO
+     * @param input
+     * @return
+     */
+    public static Boolean compareNameMulti(RuleBaseDTO ruleBaseDTO, String input) {
+        if (StringUtil.isBlank(input) || ruleBaseDTO == null || StringUtil.isBlank(ruleBaseDTO.getBaseLibName())) {
+            return false;
+        }
+        // 多个名称用分隔符隔开,只需要满足一个即可
+        List<String> nameList = CoreUtil.getSplit(ruleBaseDTO.getBaseLibName());
+        for (String name : nameList) {
+            if (input.equals(name)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     /**
      * 获取所有阳性【T】,转成Item结构,放入列表
      *
@@ -1067,6 +1155,30 @@ public class CoreUtil {
         return res;
     }
 
+
+    /**
+     * 根据分隔符转成list
+     * @param name
+     * @return
+     */
+    public static List<String> getSplit(String name) {
+        return getSplit(name, CommonEnum.splitSymbol.getName());
+    }
+
+    /**
+     * 根据分隔符转成list
+     *
+     * @param name
+     * @param splitSymbol
+     * @return
+     */
+    public static List<String> getSplit(String name, String splitSymbol) {
+        if (StringUtil.isBlank(name)) {
+            return Lists.newArrayList();
+        }
+        return Lists.newArrayList(name.split(splitSymbol));
+    }
+
     public static void main(String[] args) {
         List<PushBaseDTO> pushBaseDTOList = ListUtil.newArrayList();
         PushBaseDTO pushBaseDTO = new PushBaseDTO();

+ 2 - 1
src/main/java/com/diagbot/vo/ImportDiagnoseVO.java

@@ -5,6 +5,7 @@ import cn.afterturn.easypoi.handler.inter.IExcelDataModel;
 import lombok.Data;
 
 import java.io.Serializable;
+import java.util.List;
 
 /**
  * <p>
@@ -41,7 +42,7 @@ public class ImportDiagnoseVO implements Serializable, IExcelDataModel {
     // private String minUnit;
 
     // 规则标准词id
-    private Long conceptId;
+    private List<Long> conceptId;
     //行号
     private Integer rowNum;
     //确诊公式(带拟诊)

+ 3 - 1
src/main/java/com/diagbot/vo/KlDiagnoseDetailVO.java

@@ -3,6 +3,8 @@ package com.diagbot.vo;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.util.List;
+
 /**
  * @author wangfeng
  * @Description:
@@ -15,7 +17,7 @@ public class KlDiagnoseDetailVO {
      * 描述
      */
     private String basDescription;
-    private Long basConceptId;
+    private List<Long> basConceptId;
     private String basLibName;
     private Integer basLibType;
     private String basLename;

+ 72 - 47
src/main/resources/mapper/KlDiagnoseBaseMapper.xml

@@ -26,55 +26,80 @@
     </resultMap>
 
     <select id="getAllBaseDiagnose" resultType="com.diagbot.dto.BaseDiagnoseDTO">
-        SELECT DISTINCT
-            CONCAT_WS(
-                "_",
-                t1.concept_id,
-                t1.type,
-                t1.max_operator,
-                t1.max_value,
-                t1.max_unit,
-                t1.min_operator,
-                t1.min_value,
-                t1.min_unit,
-                t1.eq_operator,
-                t1.eq_value,
-                t1.eq_unit
-            ) AS baseKey,
-            GROUP_CONCAT(t1.id) AS ids,
-            IFNULL(t2.lib_name, "") AS baseLibName,
-            IFNULL(t2.lib_type, 0) AS baseLibType,
-            t1.concept_id,
-            t1.type AS baseType,
-            t1.max_operator AS baseMaxOperator,
-            t1.max_value AS baseMaxValue,
-            t1.max_unit AS baseMaxUnit,
-            t1.min_operator AS baseMinOperator,
-            t1.min_value AS baseMinValue,
-            t1.min_unit AS baseMinUnit,
-            t1.eq_operator AS baseEqOperator,
-            t1.eq_value AS baseEqValue,
-            t1.eq_unit AS baseEqUnit
+        SELECT
+            t.type baseType,
+            t.max_operator baseMaxOperator,
+            t.max_value baseMaxValue,
+            t.max_unit baseMaxUnit,
+            t.min_operator baseMinOperator,
+            t.min_value baseMinValue,
+            t.min_unit baseMinUnit,
+            t.eq_operator baseEqOperator,
+            t.eq_value baseEqValue,
+            t.eq_unit baseEqUnit,
+            t.conceptids baseConceptids,
+            t.lib_name baseLibName,
+          t.lib_type baseLibType,
+            GROUP_CONCAT(t.id) ids
         FROM
-            kl_diagnose_base t1
-        LEFT JOIN kl_concept t2 ON t1.concept_id = t2.id
-        AND t2.is_deleted = "N"
-        AND t2.`status` = 1
-        WHERE
-            t1.is_deleted = "N"
-        AND t1.`status` = 1
+            (
+                SELECT
+                    t1.id,
+                    t1.type,
+                    t1.max_operator,
+                    t1.max_value,
+                    t1.max_unit,
+                    t1.min_operator,
+                    t1.min_value,
+                    t1.min_unit,
+                    t1.eq_operator,
+                    t1.eq_value,
+                    t1.eq_unit,
+                    IFNULL(t2.conceptids, 0) conceptids,
+                    IFNULL(t2.lib_name, '') lib_name,
+                    IFNULL(t2.lib_type, 0) lib_type
+                FROM
+                    kl_diagnose_base t1
+                LEFT JOIN (
+                    SELECT
+                        diagnose_base_id,
+                        lib_type,
+                        GROUP_CONCAT(
+                            concept_id
+                            ORDER BY
+                                concept_id
+                        ) conceptids,
+                        GROUP_CONCAT(
+                            lib_name
+                            ORDER BY
+                                concept_id SEPARATOR '##'
+                        ) lib_name
+                    FROM
+                        `kl_diagnose_base_relation` m,
+                        kl_concept c
+                    WHERE
+                        m.is_deleted = 'N'
+                    AND c.is_deleted = 'N'
+                    AND c. STATUS = 1
+                    AND m.concept_id = c.id
+                    GROUP BY m.diagnose_base_id, c.lib_type
+                ) t2 ON t1.id = t2.diagnose_base_id
+                WHERE
+                    t1.is_deleted = 'N'
+            ) t
         GROUP BY
-            t1.concept_id,
-            t1.type,
-            t1.max_operator,
-            t1.max_value,
-            t1.max_unit,
-            t1.min_operator,
-            t1.min_value,
-            t1.min_unit,
-            t1.eq_operator,
-            t1.eq_value,
-            t1.eq_unit;
+            t.type,
+            t.max_operator,
+            t.max_value,
+            t.max_unit,
+            t.min_operator,
+            t.min_value,
+            t.min_unit,
+            t.eq_operator,
+            t.eq_value,
+            t.eq_unit,
+            t.conceptids,
+            t.lib_name
     </select>
 
 </mapper>

+ 1 - 1
src/test/java/com/diagbot/CodeGeneration.java

@@ -56,7 +56,7 @@ public class CodeGeneration {
         StrategyConfig strategy = new StrategyConfig();
         // strategy.setTablePrefix(new String[] { "demo_" });// 此处可以修改为您的表前缀
         strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
-        strategy.setInclude(new String[] { "kl_diagnose_detail"}); // 需要生成的表
+        strategy.setInclude(new String[] { "kl_diagnose_base_relation"}); // 需要生成的表
 
         strategy.setSuperServiceClass(null);
         strategy.setSuperServiceImplClass(null);