Bladeren bron

添加既往史信息抽取

kongwz 5 jaren geleden
bovenliggende
commit
142dcc4c40

+ 14 - 0
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/BeHospitalizedAI.java

@@ -11,6 +11,7 @@ import com.lantone.qc.pub.model.InputInfo;
 import com.lantone.qc.pub.model.doc.BeHospitalizedDoc;
 import com.lantone.qc.pub.model.entity.*;
 import com.lantone.qc.pub.model.label.ChiefLabel;
+import com.lantone.qc.pub.model.label.PastLabel;
 import com.lantone.qc.pub.model.label.PresentLabel;
 import com.lantone.qc.pub.model.vo.CRFVo;
 import com.lantone.qc.pub.util.StringUtil;
@@ -84,6 +85,9 @@ public class BeHospitalizedAI {
         putChiefCrfData(midData.getJSONObject(Content.chief), inputInfo);
         //处理现病史
         putPresentCrfData(midData.getJSONObject(Content.present), inputInfo);
+        //处理既往史
+        putPastCrfData(midData.getJSONObject(Content.past), inputInfo);
+
 
 //        //存放CRF模型既往史、家族史返回数据
 //        putAllCrfData(midData.getJSONObject(Content.past), crfOut);
@@ -121,6 +125,16 @@ public class BeHospitalizedAI {
         presentLabel.setGenerals(loadGeneralDes(aiOut));
         presentLabel.setPacses(loadpacses(aiOut));
     }
+    public void putPastCrfData(JSONObject jsonObject, InputInfo inputInfo){
+        if (jsonObject == null) {
+            return;
+        }
+        JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
+        //放置入inputinfo
+        EntityProcessPast entityProcessPast = new EntityProcessPast();
+        inputInfo.getBeHospitalizedDoc().setPastLabel(entityProcessPast.extractEntity(aiOut));
+
+    }
     /**
      * 关系抽取临床表现信息
      * @param aiOut

+ 0 - 203
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/process/EntityProcessMethod.java

@@ -1,203 +0,0 @@
-package com.lantone.qc.kernel.structure.ai.process;
-
-import com.alibaba.fastjson.JSONArray;
-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.pub.model.entity.*;
-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.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class EntityProcessMethod {
-    //获取诊断
-    public List<Diag> extractDiagEntity(JSONObject outputs) {
-        List<Diag> diagnose = new ArrayList<>();
-        Diag diag = null;
-        List<Map<String, String>> diagEntityList = processJson(outputs, EntityEnum.DIEASE.toString());
-        for (Map<String, String> diagEntityMap : diagEntityList) {
-            if (StringUtils.isEmpty(diagEntityMap.get(EntityEnum.DIEASE.toString()))) {
-                continue;
-            }
-            diag = new Diag();
-            for (String key : diagEntityMap.keySet()) {
-                String value = StringUtils.isEmpty(diagEntityMap.get(key)) ? "" : diagEntityMap.get(key);
-                switch (EntityEnum.parseOfValue(key)) {
-                    case DIEASE:
-                        diag.setName(value);
-                        break;
-                    case POSSIBLE:
-                        Possible possible = new Possible();
-                        possible.setName(value);
-                        diag.setPossible(possible);
-                        break;
-                }
-            }
-            diagnose.add(diag);
-        }
-        return diagnose;
-    }
-    //获取临床表现
-    public List<Clinical> extractClinicalEntity(JSONObject outputs) {
-        List<Clinical> clinicals =new ArrayList<>();
-        Clinical clinical;
-        List<Map<String, String>> symptomEntityList = processJson(outputs, EntityEnum.CLINICAL_FEATURE.toString());
-        for (Map<String, String> symptomEntityMap : symptomEntityList) {
-            if (StringUtils.isEmpty(symptomEntityMap.get(EntityEnum.CLINICAL_FEATURE.toString()))) {
-                continue;
-            }
-            clinical = new Clinical();
-            for (String key : symptomEntityMap.keySet()) {
-                String entity = StringUtils.isEmpty(symptomEntityMap.get(key)) ? "" : symptomEntityMap.get(key);
-                switch (EntityEnum.parseOfValue(key)){
-                    case CLINICAL_FEATURE:
-                        clinical.setName(symptomEntityMap.get(key));
-                        break;
-                    case NEGATIVE:
-                        Negative negative = new Negative();
-                        negative.setName(entity);
-                        clinical.setNegative(negative);
-                        break;
-                    case BODY:
-                        BodyPart bodyPart = new BodyPart();
-                        bodyPart.setName(entity);
-                        clinical.setBodyPart(bodyPart);
-                    case TREND:
-                        Trend trend = new Trend();
-                        trend.setName(entity);
-                        clinical.setTrend(trend);
-                    case CAUSE:
-                        Cause cause = new Cause();
-                        cause.setName(entity);
-                        clinical.setCause(cause);
-                    case TIME:
-                        List<PD> timestamp = new ArrayList<>();
-                        PD pd = new PD();
-                        String[] val_unit = new String[2];
-                        if(entity.trim().length()>0){
-                            val_unit = extract_digit(entity);
-                        }
-                        pd.setValue(val_unit[0]);
-                        pd.setUnit(val_unit[1]);
-                        timestamp.add(pd);
-                        clinical.setTimestamp(timestamp);
-                        break;
-                }
-            }
-            clinicals.add(clinical);
-        }
-        return clinicals;
-    }
-    /**
-     * 处理关系抽取输出的json
-     *
-     * @param outputs    关系抽取输出的json
-     * @param entityType 需要处理的实体类别
-     * @return
-     */
-    public List<Map<String, String>> processJson(JSONObject outputs, String entityType) {
-        List<Map<String, String>> connectEntityList = new ArrayList<>();
-        Map<String, String> connectEntity = null;
-        JSONObject annotation = outputs.getJSONObject("annotation");
-        JSONArray entitys = annotation.getJSONArray("T");
-        JSONArray relations = annotation.getJSONArray("R");
-        for (int i = 0; i < entitys.size(); i++) {
-            if (StringUtils.isEmpty(entitys.get(i).toString())) {
-                continue;
-            }
-            JSONObject entity = entitys.getJSONObject(i);
-            if (entityType.equals(entity.getString("name"))) {
-                int id = entity.getIntValue("id");
-                List<Integer> connectEntityIdList = getConnectEntityIdList(id, relations);
-                if (connectEntityIdList.size() == 0) {
-                    connectEntity = new HashMap<>();
-                    connectEntity.put(entity.getString("name"), entity.getString("value"));
-                    connectEntityList.add(connectEntity);
-                } else {
-                    connectEntity = getConnectEntity(connectEntityIdList, entitys);
-                    connectEntity.put(entity.getString("name"), entity.getString("value"));
-                    connectEntityList.add(connectEntity);
-                }
-            }
-        }
-        return connectEntityList;
-    }
-
-    /**
-     * 获取与传入实体有关系实体的id列表(List)
-     *
-     * @param entityId  传入实体的id
-     * @param relations 关系抽取出的关系对
-     * @return connectEntityIdList 有关系实体的id列表(List)
-     */
-    public List<Integer> getConnectEntityIdList(int entityId, JSONArray relations) {
-        List<Integer> connectEntityIdList = new ArrayList<>();
-        for (int i = 0; i < relations.size(); i++) {
-            if (StringUtils.isEmpty(relations.get(i).toString())) {
-                continue;
-            }
-            JSONObject relation = relations.getJSONObject(i);
-            if (relation.getIntValue("from") == entityId) {
-                connectEntityIdList.add(relation.getIntValue("to"));
-            }
-            if (relation.getIntValue("to") == entityId) {
-                connectEntityIdList.add(relation.getIntValue("from"));
-            }
-        }
-        return connectEntityIdList;
-    }
-
-    /**
-     * 获取实体id列表对应的所有实体类型及实体值
-     *
-     * @param connectEntityIdList 实体id列表
-     * @param entitys             关系抽取的实体列表
-     * @return entityRelationPair 实体id列表对应的所有实体类型及实体值
-     */
-    public Map<String, String> getConnectEntity(List<Integer> connectEntityIdList, JSONArray entitys) {
-        Map<String, String> entityRelationPair = new HashMap<>();
-        for (int connectEntityId : connectEntityIdList) {
-            for (int i = 0; i < entitys.size(); i++) {
-                if (StringUtils.isEmpty(entitys.get(i).toString())) {
-                    continue;
-                }
-                JSONObject entity = entitys.getJSONObject(i);
-                if (connectEntityId == entity.getIntValue("id")) {
-                    if (entityRelationPair.containsKey(entity.getString("name"))) {
-                        entityRelationPair.put(entity.getString("name"),
-                                entityRelationPair.get(entity.getString("name")) + "," + entity.getString("value"));
-                    } else {
-                        entityRelationPair.put(entity.getString("name"), entity.getString("value"));
-                    }
-                    break;
-                }
-            }
-        }
-        return entityRelationPair;
-    }
-
-
-    public String[] extract_digit(String value) {
-        String[] res = new String[2];
-        try {
-            String reg_time = "([\\d]+)([\\u4e00-\\u9fa5]+)";
-            Pattern pattern = Pattern.compile(reg_time);
-            Matcher matcher = pattern.matcher(value);
-            if (matcher.find(0)) {
-                res[0] = matcher.group(1);
-                res[1] = matcher.group(2);
-            } else {
-                res[0] = value;
-                res[1] = "";
-            }
-        } catch (Exception ex) {
-            ex.printStackTrace();
-        }
-        return res;
-    }
-}

+ 35 - 26
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/process/EntityProcessPast.java

@@ -3,9 +3,8 @@ 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.pub.model.entity.Negative;
-import com.lantone.qc.pub.model.entity.Operation;
-import com.lantone.qc.pub.model.entity.Past;
+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;
 
@@ -22,33 +21,43 @@ public class EntityProcessPast extends EntityProcess {
     public static String vaccination_history = "预防接种史";
     public static String infect_history = "传染病史";
 
-    public void extractEntity(JSONObject outputs, CrfOut outputInfo) {
+    public PastLabel extractEntity(JSONObject aiOut) {
+        PastLabel pastLabel = new PastLabel();
         List<Past> pasts = new ArrayList<>();
-        //疾病史
-        addPast(outputs, pasts);
-        //手术史
-        addPast(outputs, EntityEnum.OPERATION, Operation.class);
-        addPast(outputs, pasts, EntityEnum.OPERATION, 1, EntityProcessPast.surgery_history);
-        addPast(outputs, pasts, EntityEnum.OPERATION_KEYWORD, 1, EntityProcessPast.surgery_history);
 
-        //外伤史
-        addPast(outputs, pasts, EntityEnum.INJURY, 2, EntityProcessPast.injury_history);
 
-        //过敏史
-        addPast(outputs, pasts, EntityEnum.ALLERGY, 3, EntityProcessPast.allergy_history);
-        addPast(outputs, pasts, EntityEnum.FOOD_ALLERGY, 3, EntityProcessPast.allergy_history);
-        addPast(outputs, pasts, EntityEnum.DRUG_ALLERGY, 3, EntityProcessPast.allergy_history);
-        addPast(outputs, pasts, EntityEnum.ALLERGY_SYMPTOM, 3, EntityProcessPast.allergy_history);
+        try {
+            List<Diag> diags = addEntity(aiOut, EntityEnum.DIEASE, Diag.class);
+            //手术史
+            List<Operation> operations = addEntity(aiOut, EntityEnum.OPERATION, Operation.class);
+            //外伤史
+            List<Wound> wounds = addEntity(aiOut, EntityEnum.INJURY, Wound.class);
+            //过敏史
+            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);
 
-        //输血史
-        addPast(outputs, pasts, EntityEnum.BLOOD_TRANSFUSION, 4, EntityProcessPast.blood_history);
-
-        //预防接种史
-        addPast(outputs, pasts, EntityEnum.VACCINATION, 5, EntityProcessPast.vaccination_history);
-
-        //传染病史
-        addPast(outputs, pasts, EntityEnum.INFECTIOUS_KEYWORD, 7, EntityProcessPast.infect_history);
-        outputInfo.setPasts(pasts);
+            //输血史
+            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;
 
 
 

+ 19 - 0
public/src/main/java/com/lantone/qc/pub/model/label/PastLabel.java

@@ -1,10 +1,29 @@
 package com.lantone.qc.pub.model.label;
 
+import com.lantone.qc.pub.model.entity.*;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
 /**
  * @ClassName : PastLabel
  * @Description : 既往史
  * @Author : 楼辉荣
  * @Date: 2020-03-03 18:45
  */
+@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;//预防接种史
+
 }