浏览代码

Merge remote-tracking branch 'origin/master'

gaodm 4 年之前
父节点
当前提交
823422edd0

+ 1 - 1
src/main/java/com/diagbot/model/ai/BeHospitalizedAI.java

@@ -90,7 +90,7 @@ public class BeHospitalizedAI extends ModelAI {
                 presentLabel.setText(presentText);
                 presentLabel.setAiText(presentText);
                 wordCrfDTO.setPresentLabel(presentLabel);
-                putContent(crfContent, medicalTextType.get(7), presentText, Content.present);
+                putContent(crfContent, medicalTextType.get(5), presentText, Content.present);
             }
             /* 既往史 */
             if (StringUtils.isNotBlank(inputInfo.getPasts())) {

+ 5 - 2
src/main/java/com/diagbot/model/ai/model/EntityEnum.java

@@ -6,9 +6,9 @@ package com.diagbot.model.ai.model;
  * @Date: 2019/12/17 9:58
  */
 public enum EntityEnum {
-    CLINICAL_FEATURE("临床表现"), DIEASE("疾病名称"), BODY("身体部位"), SIGN("体征"), INDEX_VALUE("指标值"),
+    CLINICAL_FEATURE("临床表现"), DIEASE("疾病名称"), BODY("身体部位"), SIGN("体征"), INDEX_VALUE("指标值"),LABORATORY_BIG("实验室检查-套餐-细项-实验室检查"),
     LABORATORY("实验室检查"), LABORATORY_VALUE("实验室检查值"), AUXILIARY_EXAMINATION("辅助检查"), AUXILIARY_DESCRIPT("辅助检查描述"),
-    NEGATIVE("否定"), POSSIBLE("可能的"), TIME("时间"), CAUSE("诱因"), MODIFICATION("修饰"),
+    NEGATIVE("否定"), POSSIBLE("可能的"), LABORATORY_ITEM("实验室检查大项"), TIME("时间"), CAUSE("诱因"), MODIFICATION("修饰"),
     PROPERTY("性质"), DEGREE("程度"), AGGRAVATE("加重情况"), RELIEF("缓解情况"), BEHOSPITALIZEDWAY("入院途径"),
     TREND("趋势"), FREQUENCY("频率"), QUANTITY("数量"), SIZE("尺寸"), CURE("治疗"), TREAT_MENT("治疗或治疗目的"), DRUG("药物名称"),
     DOSE("药品剂量"), OPERATION("手术名称"), GENERAL("一般情况"), GENERAL_DESCRIPT("一般情况描述"),
@@ -67,6 +67,9 @@ public enum EntityEnum {
             case "实验室检查值":
                 entityEnum = EntityEnum.LABORATORY_VALUE;
                 break;
+            case "实验室检查大项":
+                entityEnum = EntityEnum.LABORATORY_ITEM;
+                break;
             case "辅助检查":
                 entityEnum = EntityEnum.AUXILIARY_EXAMINATION;
                 break;

+ 95 - 1
src/main/java/com/diagbot/model/ai/process/EntityProcessLis.java

@@ -1,21 +1,42 @@
 package com.diagbot.model.ai.process;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.diagbot.model.ai.model.EntityEnum;
 import com.diagbot.model.entity.Lis;
 import com.diagbot.model.entity.LisValue;
 import com.diagbot.model.entity.PD;
+import com.diagbot.util.ListUtil;
 import org.apache.commons.lang3.StringUtils;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 public class EntityProcessLis extends EntityProcess {
     public List<Lis> extractEntity(JSONObject outputs) {
         List<Lis> lises = new ArrayList<>();
         Lis lis = null;
         List<Map<String, String>> lisEntityList = processJson(outputs, EntityEnum.LABORATORY.toString());
+        lisEntityList = lisEntityList.stream().filter(x -> x.containsKey(EntityEnum.LABORATORY_VALUE.toString())).collect(Collectors.toList());
+        Map<String, List<String>> detail_name = processLisoutputs(outputs);
+        if(ListUtil.isNotEmpty(lisEntityList)){
+            for (Map<String, String> c:lisEntityList) {
+                String detailName = c.get(EntityEnum.LABORATORY.toString());
+                String value = c.get(EntityEnum.LABORATORY_VALUE.toString());
+                for(Map.Entry<String, List<String>> f:detail_name.entrySet()){
+                    String name = f.getKey();
+                    List<String> details = f.getValue();
+                    if(details.contains(detailName)){
+                        c.put(EntityEnum.LABORATORY_ITEM.toString(),name);
+                        break;
+                    }
+                }
+            }
+        }
+        lisEntityList = lisEntityList.stream().filter(x -> x.containsKey(EntityEnum.LABORATORY_ITEM.toString())).collect(Collectors.toList());
         for (Map<String, String> lisEntityMap : lisEntityList) {
             if (StringUtils.isEmpty(lisEntityMap.get(EntityEnum.LABORATORY.toString()))) {
                 continue;
@@ -24,6 +45,11 @@ public class EntityProcessLis extends EntityProcess {
             for (String key : lisEntityMap.keySet()) {
                 String entity = StringUtils.isEmpty(lisEntityMap.get(key)) ? "" : lisEntityMap.get(key);
                 switch (EntityEnum.parseOfValue(key)) {
+                    case LABORATORY_ITEM:
+                        LisValue big = new LisValue();
+                        big.setName(entity);
+                        lis.setBigItem(big);
+                        break;
                     case LABORATORY:
                         lis.setName(entity);
                         break;
@@ -35,7 +61,7 @@ public class EntityProcessLis extends EntityProcess {
                         String value = entity;
                         String[] val_unit = new String[2];
                         if (value.trim().length() > 0) {
-                            val_unit = extract_digit(value);
+                            val_unit = extract_digit_new(value);
                         }
                         pd.setValue(val_unit[0]);
                         pd.setUnit(val_unit[1]);
@@ -47,4 +73,72 @@ public class EntityProcessLis extends EntityProcess {
         }
         return lises;
     }
+
+    private Map<String,List<String>> processLisoutputs(JSONObject outputs){
+        JSONObject annotation = outputs.getJSONObject("annotation");
+        JSONArray entitys = annotation.getJSONArray("T");
+        JSONArray relations = annotation.getJSONArray("R");
+        //把name为实验室检查的id和value拿出来
+        Map<Integer,String> id_value = new HashMap<>();
+
+        for (int i = 0; i < entitys.size(); i++) {
+            if (StringUtils.isEmpty(entitys.get(i).toString())) {
+                continue;
+            }
+            JSONObject entity = entitys.getJSONObject(i);
+            String name = entity.getString("name");
+            int id = entity.getIntValue("id");
+            String value = entity.getString("value");
+            if(EntityEnum.LABORATORY.toString().equals(name)){
+                id_value.put(id,value);
+            }
+        }
+        //遍历关系,把name为LABORATORY_BIG的from和to拿出来
+        Map<Integer,List<Integer>> from_to = new HashMap<>();
+        for (int i = 0; i < relations.size(); i++) {
+            if (StringUtils.isEmpty(relations.get(i).toString())) {
+                continue;
+            }
+            JSONObject relationsJSONObject = relations.getJSONObject(i);
+            if(EntityEnum.LABORATORY_BIG.toString().equals(relationsJSONObject.getString("name"))){
+                int from = relationsJSONObject.getIntValue("from");
+                int to = relationsJSONObject.getIntValue("to");
+                if(from_to.containsKey(from)){
+                    List<Integer> toList = from_to.get(from);
+                    toList.add(to);
+                    from_to.put(from,toList);
+                }else {
+                    List<Integer> toList = new ArrayList<>();
+                    toList.add(to);
+                    from_to.put(from,toList);
+                }
+            }
+        }
+        //组装化验的大小项
+        Map<String,List<String>> detail_name = new HashMap<>();
+        if(from_to.size()>0 && id_value.size()>0){
+            for(Map.Entry<Integer,List<Integer>> ft:from_to.entrySet()){
+                Integer big = ft.getKey();
+                List<Integer> details = ft.getValue();
+                for (Integer id:details) {
+                    if(id_value.containsKey(big)&& id_value.containsKey(id)){
+//                    detail_name.put(id_value.get(ft.getValue()),id_value.get(ft.getKey()));
+                        if(detail_name.containsKey(id_value.get(big))){
+                            List<String> detailList = detail_name.get(id_value.get(big));
+                            if(!detailList.contains(id_value.get(id))){
+                                detailList.add(id_value.get(id));
+                            }
+                            detail_name.put(id_value.get(big),detailList);
+                        }else {
+                            List<String> detailList = new ArrayList<>();
+                            detailList.add(id_value.get(id));
+                            detail_name.put(id_value.get(big),detailList);
+                        }
+                    }
+                }
+
+            }
+        }
+        return detail_name;
+    }
 }

+ 1 - 0
src/main/java/com/diagbot/model/entity/Lis.java

@@ -13,6 +13,7 @@ import lombok.Setter;
 @Getter
 @Setter
 public class Lis extends General {
+    private LisValue bigItem;//化验大项
     private LisValue lisValue;
     private PD pd;