Jelajahi Sumber

移除公式编码中没有的数据

kongwz 4 tahun lalu
induk
melakukan
7b5345ee99

+ 15 - 1
src/main/java/com/diagbot/enums/DiagnoseLexiconTypeEnum.java

@@ -20,7 +20,21 @@ public enum DiagnoseLexiconTypeEnum implements KeyedNamed {
     zsxbszz(900, "G"),
     jwzz(901, "H"),
     Age(410,"I"),
-    Group(117, "J");
+    Group(117, "J"),
+    // 旧新诊断依据类型对应
+    SymptomTpye(1, "A:症状"),
+    VitalResultTpye(2, "B:体格检查结果"),
+//    VitalTpye(104, "C"),
+    LisSubNameTpye(3, "D:实验室检查子项目"),
+    PacsResultTpye(4, "E:辅助检查结果"),
+    DiseaseTpye(5, "F:疾病"),
+    DiseaseHisTpye(6, "F:疾病"),//病史
+    ZsxbszzTpyeCause(7, "G:主诉现病史正则"),//诱因
+    ZsxbszzTpyeBc(8, "G:主诉现病史正则"),//病程
+    jwzzTpye(9, "H:既往正则"),
+    QuezhenTpye(91, "确诊"),
+    NizhenTpye(92, "拟诊"),
+    JtTpye(93, "警惕");
 
     @Setter
     private int key;

+ 113 - 64
src/main/java/com/diagbot/facade/KlDiagnoseDetailFacade.java

@@ -4,28 +4,18 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.diagbot.dto.ExportDiagnoseDTO;
 import com.diagbot.dto.ExportDiagnoseNameDTO;
 import com.diagbot.entity.KlDiagnoseDetail;
+import com.diagbot.enums.DiagnoseLexiconTypeEnum;
 import com.diagbot.enums.IsDeleteEnum;
 import com.diagbot.service.impl.KlDiagnoseDetailServiceImpl;
-import com.diagbot.util.BeanUtil;
-import com.diagbot.util.EntityUtil;
-import com.diagbot.util.ExcelUtils;
-import com.diagbot.util.ReflectUtil;
-import com.diagbot.util.RegexUtil;
-import com.diagbot.util.StringUtil;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.compress.utils.Lists;
+import com.diagbot.util.*;
+import com.google.common.collect.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * <p>
@@ -47,6 +37,7 @@ public class KlDiagnoseDetailFacade extends KlDiagnoseDetailServiceImpl {
     public void exportDiagnose(HttpServletResponse response) {
         // 获取全部数据、分组
         List<KlDiagnoseDetail> klDiagnoseDetailList = klDiagnoseDetailFacade.list(new QueryWrapper<KlDiagnoseDetail>()
+                .eq("dis_name", "急性化脓性扁桃体炎")
                 .eq("is_deleted", IsDeleteEnum.N.getKey()));
         Map<String, List<KlDiagnoseDetail>> diagnoseDetailMap = EntityUtil.makeEntityListMap(klDiagnoseDetailList, "disName");
         // TODO 获取公式,分隔编码,替换编码,组装导出数据  Map<String, List<ExportDiagnoseDTO>>
@@ -83,36 +74,74 @@ public class KlDiagnoseDetailFacade extends KlDiagnoseDetailServiceImpl {
     }
 
 
-    public Map<String, List<ExportDiagnoseDTO>> processDiagnoseDetail(Map<String, List<KlDiagnoseDetail>> diagnoseDetailMap){
+    public Map<String, List<ExportDiagnoseDTO>> processDiagnoseDetail(Map<String, List<KlDiagnoseDetail>> diagnoseDetailMap) {
         Map<String, List<ExportDiagnoseDTO>> data = new LinkedHashMap<>();
-        for(Map.Entry<String, List<KlDiagnoseDetail>> kd : diagnoseDetailMap.entrySet()){
+
+        for (Map.Entry<String, List<KlDiagnoseDetail>> kd : diagnoseDetailMap.entrySet()) {
             String sheetName = kd.getKey();
             List<KlDiagnoseDetail> datats = kd.getValue();
-            removeKlDiagnoseDetail(datats);
-            List<ExportDiagnoseDTO> eds = Lists.newArrayList();
-            for (KlDiagnoseDetail kdl:datats) {
+            Map<Integer, List<String>> typeCodeNewListMap = new HashMap<>();// 1 --> [1.0,1.1]
+            Map<Integer, List<String>> exportDiagnoseDTOS = removeKlDiagnoseDetail(datats, typeCodeNewListMap);
+            List<ExportDiagnoseDTO> exportDiagnoseDTO= packageData(exportDiagnoseDTOS, datats, typeCodeNewListMap);
+            data.put(sheetName,exportDiagnoseDTO);
+        }
+        return data;
+    }
+
+    /**
+     *
+     * @param exportDiagnoseDTOS 各种类型的关联词
+     * @param datats 诊断依据
+     * @param typeCodeNewListMap 各种类型的codes
+     */
+    public List<ExportDiagnoseDTO> packageData(Map<Integer, List<String>> exportDiagnoseDTOS,List<KlDiagnoseDetail> datats,Map<Integer, List<String>> typeCodeNewListMap){
+        List<ExportDiagnoseDTO> eds = Lists.newArrayList();
+
+        Map<Integer, List<KlDiagnoseDetail>> typeDiagnoseDetails = EntityUtil.makeEntityListMap(datats, "type");
+        for (Map.Entry<Integer, List<String>> edd : exportDiagnoseDTOS.entrySet()) {
+            Integer type = edd.getKey();
+            List<KlDiagnoseDetail> klDiagnoseDetails = typeDiagnoseDetails.get(type);
+            List<String> relations = edd.getValue();
+            List<String> codes = typeCodeNewListMap.get(type);
+            String maxCode = codes.get(codes.size() - 1);
+            String[] maxCodeArray = maxCode.split("\\.");
+            Integer max = Integer.parseInt(maxCodeArray[1]);
+            for (String relation:relations) {
+                max += 1;
+                KlDiagnoseDetail klDiagnoseDetail = new KlDiagnoseDetail();
+                klDiagnoseDetail.setType(type);
+                klDiagnoseDetail.setCode(maxCodeArray[0]+"."+max);
+                klDiagnoseDetail.setStandard(relation);
+                klDiagnoseDetails.add(klDiagnoseDetail);
+            }
+        }
+        for (Map.Entry<Integer, List<KlDiagnoseDetail>> tdd : typeDiagnoseDetails.entrySet()) {
+            List<KlDiagnoseDetail> klDiagnoseDetails = tdd.getValue();
+            for (KlDiagnoseDetail kdl:klDiagnoseDetails) {
                 Integer type = kdl.getType();
                 String code = kdl.getCode();
                 ExportDiagnoseDTO exportDiagnoseDTO = new ExportDiagnoseDTO();
                 BeanUtil.copyProperties(kdl, exportDiagnoseDTO);
-                ReflectUtil.setProperty(exportDiagnoseDTO, "type", type.toString());
-                ReflectUtil.setProperty(exportDiagnoseDTO, "orderNo", code);
-                if(code.startsWith("3.") || code.startsWith("4.")){
-                    exportDiagnoseDTO.setRule(kdl.getRelation());
-                    exportDiagnoseDTO.setRelation("");
-                }else {
-                    exportDiagnoseDTO.setRule(kdl.getStandard());
-                }
-                if(type == 91 || type == 92 || type == 93){
+                String typeName = DiagnoseLexiconTypeEnum.getName(type);
+                if (type == 91 || type == 92 || type == 93) {
+                    ReflectUtil.setProperty(exportDiagnoseDTO, "type", typeName);
                     exportDiagnoseDTO.setRule(kdl.getFormula());
+                }else {
+                    ReflectUtil.setProperty(exportDiagnoseDTO, "type", typeName.split(":")[1]);
+                    ReflectUtil.setProperty(exportDiagnoseDTO, "orderNo", typeName.split(":")[0]+code.split("\\.")[1]);
+                    if (code.startsWith("3.") || code.startsWith("4.")) {
+                        exportDiagnoseDTO.setRule(kdl.getRelation());
+                        exportDiagnoseDTO.setRelation("");
+                    } else {
+                        exportDiagnoseDTO.setRule(kdl.getStandard());
+                    }
+                    exportDiagnoseDTO.setEq(kdl.getMidResult());
                 }
 
-                exportDiagnoseDTO.setEq(kdl.getMidResult());
                 eds.add(exportDiagnoseDTO);
             }
-            data.put(sheetName,eds);
         }
-        return data;
+        return eds;
     }
 
     /**
@@ -133,63 +162,83 @@ public class KlDiagnoseDetailFacade extends KlDiagnoseDetailServiceImpl {
 
     /**
      * 移除公式编码中没有的数据
+     *
      * @param klDiagnoseDetails
      */
-    public void removeKlDiagnoseDetail(List<KlDiagnoseDetail> klDiagnoseDetails){
-        Map<String, List<String>> allFormula = getAllFormula(klDiagnoseDetails);
+    public Map<Integer, List<String>> removeKlDiagnoseDetail(List<KlDiagnoseDetail> klDiagnoseDetails, Map<Integer, List<String>> typeCodeNewListMap) {
+
+        Map<Integer, List<String>> typeRelationNamesMap = new HashMap<>();// 1 --> [症状1,症状2]
+
+        //获取所有公式
+        List<String> allFormula = getAllFormula(klDiagnoseDetails);
+        //获取公式中的所有编码
         List<String> regexData = getCodes(allFormula);
+
+        //遍历病历
+        List<Integer> types = Stream.of(1, 2, 5, 6, 7, 8, 9).collect(Collectors.toList());
         Iterator<KlDiagnoseDetail> iterator = klDiagnoseDetails.iterator();
-        while (iterator.hasNext()){
+        while (iterator.hasNext()) {
             KlDiagnoseDetail next = iterator.next();
-            String code = next.getCode();
-            if(!regexData.contains(code) && StringUtil.isNotBlank(code)){
+            String code = next.getCode();//1.0
+            Integer type = next.getType();//1
+            String relation = next.getRelation();
+            if (!regexData.contains(code) && StringUtil.isNotBlank(code)) {
                 iterator.remove();
+            } else {
+                if (StringUtil.isNotBlank(relation) && types.contains(type)) {
+                    List<String> relationNames = Lists.newArrayList(relation.split("\\、"));
+                    if (typeRelationNamesMap.containsKey(type)) {
+                        List<String> contionNames = typeRelationNamesMap.get(type);
+                        contionNames.addAll(relationNames);
+                        typeRelationNamesMap.put(type, contionNames);
+                    } else {
+                        typeRelationNamesMap.put(type, relationNames);
+                    }
+                }
+                if (StringUtil.isNotBlank(code)) {
+                    if (typeCodeNewListMap.containsKey(type)) {
+                        List<String> codes = typeCodeNewListMap.get(type);
+                        codes.add(code);
+                        typeCodeNewListMap.put(type, codes);
+                    } else {
+                        List<String> codes = Lists.newArrayList();
+                        codes.add(code);
+                        typeCodeNewListMap.put(type, codes);
+                    }
+                }
             }
         }
+        return typeRelationNamesMap;
     }
 
 
     /**
      * 获取每个诊断依据的公式
+     *
      * @param klDiagnoseDetails
      * @return
      */
-    private Map<String,List<String>> getAllFormula(List<KlDiagnoseDetail> klDiagnoseDetails){
-        Map<String,List<String>> typeFormulaMap = new HashMap<>();
-        for (KlDiagnoseDetail klDiagnoseDetail : klDiagnoseDetails) {
-            Integer type = klDiagnoseDetail.getType();
-            String formula = klDiagnoseDetail.getFormula();
-            if((type == 91 || type == 92 || type == 93)&& StringUtil.isNotBlank(formula)){
-                if(typeFormulaMap.containsKey(type.toString())){
-                    List<String> formulas = typeFormulaMap.get(type.toString());
-                    formulas.add(formula);
-                    typeFormulaMap.put(type.toString(),formulas);
-                }else {
-                    List<String> formulas = Lists.newArrayList();
-                    formulas.add(formula);
-                    typeFormulaMap.put(type.toString(),formulas);
-                }
-            }
+    private List<String> getAllFormula(List<KlDiagnoseDetail> klDiagnoseDetails) {
+        List<String> formulas = Lists.newArrayList();
+        if (ListUtil.isNotEmpty(klDiagnoseDetails)) {
+            formulas = klDiagnoseDetails.stream().filter(x -> StringUtil.isBlank(x.getCode()) && StringUtil.isNotBlank(x.getFormula()))
+                    .map(x -> x.getFormula()).collect(Collectors.toList());
+
         }
-        return typeFormulaMap;
+        return formulas;
     }
 
     /**
      * 获取公式中的所有编码
-     * @param getAllFormula
+     *
+     * @param formulas
      * @return
      */
-    private List<String> getCodes(Map<String,List<String>> getAllFormula) {
-        StringBuffer sb = new StringBuffer();
+    private List<String> getCodes(List<String> formulas) {
         String pateern = "([1-9]\\d*\\.?\\d*)|(0\\.\\d*[1-9])";
-        if(MapUtils.isNotEmpty(getAllFormula)){
-            getAllFormula.forEach((x,y) ->{
-                String collect = y.stream().collect(Collectors.joining(","));
-                sb.append(collect).append("+");
-            });
-        }
+        String content = formulas.stream().collect(Collectors.joining(","));
         //获取公式中的编码
-        return RegexUtil.getRegexDatas(sb.toString(), pateern);
+        return RegexUtil.getRegexDatas(content, pateern);
     }
 
 }

+ 5 - 0
src/main/java/com/diagbot/util/RegexUtil.java

@@ -6,6 +6,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 
 /**
  * @author zhoutg
@@ -226,6 +227,10 @@ public class RegexUtil {
 
         System.out.println(getRegexDatas("拟诊+(3.3/3.4)任一","([1-9]\\d*\\.?\\d*)|(0\\.\\d*[1-9])"));
 
+        ArrayList<String> js = Lists.newArrayList("G.4", "G.1", "G.2", "G.3");
+        List<String> collect = js.stream().sorted().collect(Collectors.toList());
+        System.out.println(collect);
+
 
     }
 }