Explorar o código

既往史关系抽取重新调整

louhr %!s(int64=5) %!d(string=hai) anos
pai
achega
14ce7c166e

+ 27 - 0
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/process/EntityProcess.java

@@ -189,6 +189,33 @@ public class EntityProcess {
         return null;
     }
 
+    /**
+     * 查找时间表述
+     * @param detailLemma
+     * @return
+     */
+    protected PD findPD(Lemma detailLemma) {
+        for (Lemma lemma : detailLemma.getRelationLemmas()) {
+            if (lemma.getProperty().equals(EntityEnum.TIME.toString())) {
+                PD pd = new PD();
+                pd.setName(lemma.getText());
+                pd.setValue(lemma.getText());
+                return pd;
+            }
+        }
+        return null;
+    }
+
+    protected <T> T findT(Lemma detailLemma, T t, String entityType) throws Exception {
+        for (Lemma lemma : detailLemma.getRelationLemmas()) {
+            if (lemma.getProperty().equals(entityType)) {
+                BeanUtils.copyProperty(t, "name", lemma.getText());
+                return t;
+            }
+        }
+        return null;
+    }
+
     /**
      * 查找时间
      * @param detailLemma

+ 131 - 80
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/process/EntityProcessPast.java

@@ -3,107 +3,158 @@ package com.lantone.qc.kernel.structure.ai.process;
 import com.alibaba.fastjson.JSONObject;
 import com.lantone.qc.kernel.structure.ai.model.CrfOut;
 import com.lantone.qc.kernel.structure.ai.model.EntityEnum;
+import com.lantone.qc.kernel.structure.ai.model.Lemma;
 import com.lantone.qc.pub.model.entity.*;
 import com.lantone.qc.pub.model.label.PastLabel;
 import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+/**
+ * @ClassName : EntityProcessPast
+ * @Description : 既往史
+ * @Author : 楼辉荣
+ * @Date: 2020-03-10 10:20
+ */
 public class EntityProcessPast extends EntityProcess {
-    public static String allergy_history = "过敏史";
-    public static String disease_history = "疾病史";
-    public static String surgery_history = "手术史";
-    public static String injury_history = "外伤史";
-    public static String blood_history = "输血史";
-    public static String vaccination_history = "预防接种史";
-    public static String infect_history = "传染病史";
+    private Logger logger = LoggerFactory.getLogger(EntityProcessPast.class);
 
     public PastLabel extractEntity(JSONObject aiOut) {
         PastLabel pastLabel = new PastLabel();
-
         try {
-            List<Diag> diags = addEntity(aiOut, EntityEnum.DIEASE, Diag.class);
+            //读取疾病信息
+            List<Lemma> diagLemmas = createEntityTree(aiOut, EntityEnum.DIEASE.toString());
+            for (Lemma lemma : diagLemmas) {
+                Diag diag = new Diag();
+                diag.setName(lemma.getText());
+                if (lemma.isHaveChildren()) {
+                    //阴性
+                    diag.setNegative(findNegative(lemma));
+                    //可能的
+                    for (Lemma relationLemma : lemma.getRelationLemmas()) {
+                        if (relationLemma.getProperty().equals(EntityEnum.POSSIBLE.toString())) {
+                            Possible possible = new Possible();
+                            possible.setName(relationLemma.getText());
+                            diag.setPossible(possible);
+                        }
+                    }
+                }
+                pastLabel.addDiag(diag);
+            }
             //手术史
-            List<Operation> operations = addEntity(aiOut, EntityEnum.OPERATION, Operation.class);
+            List<Lemma> operationLemmas = createEntityTree(aiOut, EntityEnum.OPERATION.toString());
+            for (Lemma lemma : operationLemmas) {
+                Operation operation = new Operation();
+                operation.setName(lemma.getText());
+                if (lemma.isHaveChildren()) {
+                    //阴性
+                    operation.setNegative(findNegative(lemma));
+                    //时间
+                    operation.setPd(findPD(lemma));
+                    //手术结果
+                    for (Lemma relationLemma : lemma.getRelationLemmas()) {
+                        if (relationLemma.getProperty().equals(EntityEnum.OPERATION_RESULT.toString())) {
+                            OperationResult operationResult = new OperationResult();
+                            operationResult.setName(relationLemma.getText());
+                            operation.setOperationResult(operationResult);
+                        }
+                    }
+                    //手术原因
+                    for (Lemma relationLemma : lemma.getRelationLemmas()) {
+                        if (relationLemma.getProperty().equals(EntityEnum.DIEASE.toString())) {
+                            Diag diag = new Diag();
+                            diag.setName(relationLemma.getText());
+                            operation.setDiag(diag);
+                        }
+                    }
+                }
+                pastLabel.addOperation(operation);
+            }
             //外伤史
-            List<Wound> wounds = addEntity(aiOut, EntityEnum.INJURY, Wound.class);
+            List<Lemma> woundLemmas = createEntityTree(aiOut, EntityEnum.INJURY.toString());
+            for (Lemma lemma : woundLemmas) {
+                Wound wound = new Wound();
+                wound.setName(lemma.getText());
+                if (lemma.isHaveChildren()) {
+                    wound.setNegative(findNegative(lemma));//阴性
+                    wound.setPd(findPD(lemma));//时间
+                    wound.setBodyPart(findT(lemma, new BodyPart(), EntityEnum.BODY.toString()));//部位
+                    wound.setDegree(findT(lemma, new Degree(), EntityEnum.TREND.toString()));//程度
+                    wound.setTreat(findT(lemma, new Treat(), EntityEnum.CURE.toString()));//治疗
+                    wound.setOperation(findT(lemma, new Operation(), EntityEnum.OPERATION.toString()));//手术
+                }
+                pastLabel.addWound(wound);
+            }
             //过敏史
-            List<Allergy> allergies = addEntity(aiOut, EntityEnum.ALLERGY, Allergy.class);
-            List<AllergyFood> allergyFoods = addEntity(aiOut, EntityEnum.FOOD_ALLERGY, AllergyFood.class);
-            List<AllergyMedicine> allergyMedicines = addEntity(aiOut, EntityEnum.DRUG_ALLERGY, AllergyMedicine.class);
-            List<AllergyDesc> allergyDescs = addEntity(aiOut, EntityEnum.ALLERGY_SYMPTOM, AllergyDesc.class);
-
+            List<Lemma> allergyLemmas = createEntityTree(aiOut, EntityEnum.ALLERGY.toString());
+            for (Lemma lemma : allergyLemmas) {
+                Allergy allergy = new Allergy();
+                allergy.setName(lemma.getText());
+                allergy.setNegative(findNegative(lemma));
+                pastLabel.addAllergy(allergy);
+            }
+            //食物过敏史
+            List<Lemma> allergyFoodLemmas = createEntityTree(aiOut, EntityEnum.FOOD_ALLERGY.toString());
+            for (Lemma lemma : allergyFoodLemmas) {
+                AllergyFood allergyFood = new AllergyFood();
+                allergyFood.setName(lemma.getText());
+                if (lemma.isHaveChildren()) {
+                    allergyFood.setNegative(findNegative(lemma));
+                    allergyFood.setPd(findPD(lemma));//时间
+                    allergyFood.setDegree(findT(lemma, new Degree(), EntityEnum.TREND.toString()));//程度
+                }
+                pastLabel.addAllergyFood(allergyFood);
+            }
+            //药物过敏史
+            List<Lemma> allergyMedicineLemmas = createEntityTree(aiOut, EntityEnum.DRUG_ALLERGY.toString());
+            for (Lemma lemma : allergyMedicineLemmas) {
+                AllergyMedicine allergyMedicine = new AllergyMedicine();
+                allergyMedicine.setName(lemma.getText());
+                if (lemma.isHaveChildren()) {
+                    allergyMedicine.setNegative(findNegative(lemma));
+                    allergyMedicine.setPd(findPD(lemma));//时间
+                    allergyMedicine.setDegree(findT(lemma, new Degree(), EntityEnum.TREND.toString()));//程度
+                }
+                pastLabel.addAllergyMedicine(allergyMedicine);
+            }
             //输血史
-            List<BloodTransfusion> bloodTransfusions = addEntity(aiOut, EntityEnum.BLOOD_TRANSFUSION, BloodTransfusion.class);
-             //预防接种史
-            List<Vaccinate> vaccinates = addEntity(aiOut, EntityEnum.VACCINATION, Vaccinate.class);
-            //传染病史
-            List<DiagInfectious> diagInfectious = addEntity(aiOut, EntityEnum.INFECTIOUS_KEYWORD, DiagInfectious.class);
-            pastLabel.setDiags(diags);
-            pastLabel.setAllergies(allergies);
-            pastLabel.setAllergyFoods(allergyFoods);
-            pastLabel.setAllergyMedicines(allergyMedicines);
-            pastLabel.setAllergyDescs(allergyDescs);
-            pastLabel.setBloodTransfusions(bloodTransfusions);
-            pastLabel.setDiagInfectiouses(diagInfectious);
-            pastLabel.setOperations(operations);
-            pastLabel.setVaccinates(vaccinates);
-            pastLabel.setWounds(wounds);
-        }catch (Exception e){
-            e.printStackTrace();
-        }
-        return pastLabel;
-
-
-
-    }
-    private void addPast(JSONObject outputs, List<Past> pasts) {
-        Past past = null;
-        List<Map<String, String>> pastEntityList = processJson(outputs, EntityEnum.DIEASE.toString());
-        for (Map<String, String> pastEntityMap : pastEntityList) {
-            if (StringUtils.isEmpty(pastEntityMap.get(EntityEnum.DIEASE.toString()))) {
-                continue;
+            List<Lemma> bloodTransfusionLemmas = createEntityTree(aiOut, EntityEnum.BLOOD_TRANSFUSION.toString());
+            for (Lemma lemma : bloodTransfusionLemmas) {
+                BloodTransfusion bloodTransfusion = new BloodTransfusion();
+                bloodTransfusion.setName(lemma.getText());
+                if (lemma.isHaveChildren()) {
+                    bloodTransfusion.setNegative(findNegative(lemma));
+                }
+                pastLabel.addBloodTransfusion(bloodTransfusion);
+            }
+            //预防接种史
+            List<Lemma> vaccinateLemmas = createEntityTree(aiOut, EntityEnum.VACCINATION.toString());
+            for (Lemma lemma : vaccinateLemmas) {
+                Vaccinate vaccinate = new Vaccinate();
+                vaccinate.setName(lemma.getText());
+                if (lemma.isHaveChildren()) {
+                    vaccinate.setNegative(findNegative(lemma));
+                }
+                pastLabel.addVaccinate(vaccinate);
             }
-            past = new Past();
-            String cureValue = "";
-            for (String key : pastEntityMap.keySet()) {
-                switch (EntityEnum.parseOfValue(key)) {
-                    case DIEASE:
-                        past.setType(6);
-                        past.setTitle(EntityProcessPast.disease_history);
-                        past.setValue(pastEntityMap.get(key));
-                        break;
-                    case CURE:
-                        past.setTreat(pastEntityMap.get(key));
-                        break;
-                    case CURE_AIM:
-                        cureValue += "," + pastEntityMap.get(key);
-                        break;
-                    case TREND:
-                        cureValue += "," + pastEntityMap.get(key);
-                        break;
-                    case TIME:
-                        cureValue += "," + pastEntityMap.get(key);
-                        break;
-                    case FREQUENCY:
-                        cureValue += "," + pastEntityMap.get(key);
-                        break;
-                    case MODIFICATION:
-                        cureValue += "," + pastEntityMap.get(key);
-                        break;
-                    case NEGATIVE:
-                        Negative negative = new Negative();
-                        negative.setName(StringUtils.isEmpty(pastEntityMap.get(key)) ? "" : pastEntityMap.get(key));
-                        past.setNegative(negative);
-                        break;
-                    //TODO   PD
+            //传染病史
+            List<Lemma> diagInfectiousLemmas = createEntityTree(aiOut, EntityEnum.INFECTIOUS_KEYWORD.toString());
+            for (Lemma lemma : diagInfectiousLemmas) {
+                DiagInfectious diagInfectious = new DiagInfectious();
+                diagInfectious.setName(lemma.getText());
+                if (lemma.isHaveChildren()) {
+                    diagInfectious.setNegative(findNegative(lemma));
                 }
+                pastLabel.addDiagInfectious(diagInfectious);
             }
-            past.setDescribe(cureValue.startsWith(",") ? cureValue.substring(1, cureValue.length()) : cureValue);
-            pasts.add(past);
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
         }
+        return pastLabel;
     }
 }

+ 6 - 0
public/src/main/java/com/lantone/qc/pub/model/entity/Allergy.java

@@ -1,10 +1,16 @@
 package com.lantone.qc.pub.model.entity;
 
+import lombok.Getter;
+import lombok.Setter;
+
 /**
  * @ClassName : Allergy
  * @Description : 过敏
  * @Author : 楼辉荣
  * @Date: 2020-03-05 19:05
  */
+@Getter
+@Setter
 public class Allergy extends General {
+    private Negative negative; //阴性
 }

+ 1 - 0
public/src/main/java/com/lantone/qc/pub/model/entity/AllergyFood.java

@@ -12,6 +12,7 @@ import lombok.Setter;
 @Setter
 @Getter
 public class AllergyFood extends General {
+    private Negative negative;//阴性
     private PD pd;  //时间
     private Degree degree; //程度
 }

+ 1 - 0
public/src/main/java/com/lantone/qc/pub/model/entity/AllergyMedicine.java

@@ -12,6 +12,7 @@ import lombok.Setter;
 @Setter
 @Getter
 public class AllergyMedicine extends General {
+    private Negative negative;  //阴性
     private PD pd;  //时间
     private Degree degree; //程度
 }

+ 6 - 0
public/src/main/java/com/lantone/qc/pub/model/entity/BloodTransfusion.java

@@ -1,10 +1,16 @@
 package com.lantone.qc.pub.model.entity;
 
+import lombok.Getter;
+import lombok.Setter;
+
 /**
  * @ClassName : BloodTransfusion
  * @Description : 输血史
  * @Author : 楼辉荣
  * @Date: 2020-03-05 19:08
  */
+@Setter
+@Getter
 public class BloodTransfusion extends General {
+    private Negative negative;  //否定
 }

+ 1 - 0
public/src/main/java/com/lantone/qc/pub/model/entity/Operation.java

@@ -12,6 +12,7 @@ import lombok.Setter;
 @Getter
 @Setter
 public class Operation extends General {
+    private Negative negative;  //阴性
     private PD pd;  //手术时间
     private OperationResult operationResult;    //手术结果
     private Diag diag;  //手术原因

+ 6 - 0
public/src/main/java/com/lantone/qc/pub/model/entity/Vaccinate.java

@@ -1,10 +1,16 @@
 package com.lantone.qc.pub.model.entity;
 
+import lombok.Getter;
+import lombok.Setter;
+
 /**
  * @ClassName : Vaccinate
  * @Description : 预防接种史
  * @Author : 楼辉荣
  * @Date: 2020-03-05 19:11
  */
+@Getter
+@Setter
 public class Vaccinate extends General {
+    private Negative negative;
 }

+ 1 - 0
public/src/main/java/com/lantone/qc/pub/model/entity/Wound.java

@@ -12,6 +12,7 @@ import lombok.Setter;
 @Getter
 @Setter
 public class Wound extends General {
+    private Negative negative;  //阴性
     private PD pd;  //时间
     private BodyPart bodyPart;  //部位
     private Degree degree;  // 程度

+ 41 - 10
public/src/main/java/com/lantone/qc/pub/model/label/PastLabel.java

@@ -4,6 +4,7 @@ import com.lantone.qc.pub.model.entity.*;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -15,15 +16,45 @@ import java.util.List;
 @Setter
 @Getter
 public class PastLabel extends GeneralLabel{
-    private List<Diag> diags;//疾病史
-    private List<Wound> wounds;//外伤史
-    private List<DiagInfectious> diagInfectiouses;//传染病史
-    private List<Allergy> allergies;//过敏史
-    private List<AllergyFood> allergyFoods;//食物过敏史
-    private List<AllergyMedicine> allergyMedicines;//药物过敏史
-    private List<AllergyDesc> allergyDescs;
-    private List<BloodTransfusion> bloodTransfusions;//输血史
-    private List<Operation> operations;//手术史
-    private List<Vaccinate> vaccinates;//预防接种史
+    private List<Diag> diags = new ArrayList<>();//疾病史
+    private List<Wound> wounds = new ArrayList<>();//外伤史
+    private List<DiagInfectious> diagInfectiouses = new ArrayList<>();//传染病史
+    private List<Allergy> allergies = new ArrayList<>();//过敏史
+    private List<AllergyFood> allergyFoods = new ArrayList<>();//食物过敏史
+    private List<AllergyMedicine> allergyMedicines = new ArrayList<>();//药物过敏史
+    private List<AllergyDesc> allergyDescs = new ArrayList<>();
+    private List<BloodTransfusion> bloodTransfusions = new ArrayList<>();//输血史
+    private List<Operation> operations = new ArrayList<>();//手术史
+    private List<Vaccinate> vaccinates = new ArrayList<>();//预防接种史
 
+    public void addDiag(Diag diag) {
+        this.diags.add(diag);
+    }
+    public void addWound(Wound wound) {
+        this.wounds.add(wound);
+    }
+    public void addDiagInfectious(DiagInfectious diagInfectious) {
+        this.diagInfectiouses.add(diagInfectious);
+    }
+    public void addAllergy(Allergy allergy) {
+        this.allergies.add(allergy);
+    }
+    public void addAllergyFood(AllergyFood allergyFood) {
+        this.allergyFoods.add(allergyFood);
+    }
+    public void addAllergyMedicine(AllergyMedicine allergyMedicine) {
+        this.allergyMedicines.add(allergyMedicine);
+    }
+    public void addAllergyDesc(AllergyDesc allergyDesc) {
+        this.allergyDescs.add(allergyDesc);
+    }
+    public void addBloodTransfusion(BloodTransfusion bloodTransfusion) {
+        this.bloodTransfusions.add(bloodTransfusion);
+    }
+    public void addOperation(Operation operation) {
+        this.operations.add(operation);
+    }
+    public void addVaccinate(Vaccinate vaccinate) {
+        this.vaccinates.add(vaccinate);
+    }
 }