ソースを参照

添加现病史信息抽取

kongwz 5 年 前
コミット
b4d3f39f24

+ 57 - 111
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/BeHospitalizedAI.java

@@ -9,10 +9,9 @@ import com.lantone.qc.kernel.structure.ai.process.*;
 import com.lantone.qc.pub.Content;
 import com.lantone.qc.pub.model.InputInfo;
 import com.lantone.qc.pub.model.doc.BeHospitalizedDoc;
-import com.lantone.qc.pub.model.entity.Annotation;
-import com.lantone.qc.pub.model.entity.Clinical;
-import com.lantone.qc.pub.model.entity.Diag;
+import com.lantone.qc.pub.model.entity.*;
 import com.lantone.qc.pub.model.label.ChiefLabel;
+import com.lantone.qc.pub.model.label.PresentLabel;
 import com.lantone.qc.pub.model.vo.CRFVo;
 import com.lantone.qc.pub.util.StringUtil;
 import org.apache.commons.lang3.StringUtils;
@@ -81,12 +80,11 @@ public class BeHospitalizedAI {
         //获取CRF模型返回数据
         JSONArray data = getAnnotation(crfServiceClient, crfVo).getData();
         JSONObject midData = getOutputs(data);
-        putChiefCrfData(midData.getJSONObject(Content.chief), inputInfo);
         //处理主诉
-//        putAllCrfData(midData.getJSONObject(Content.chief),crfOut);
-//        putAllCrfData(midData.getJSONObject(Content.present), crfOut);
-//        putAllCrfData(midData.getJSONObject(Content.special_exam), crfOut);
-//
+        putChiefCrfData(midData.getJSONObject(Content.chief), inputInfo);
+        //处理现病史
+        putPresentCrfData(midData.getJSONObject(Content.present), inputInfo);
+
 //        //存放CRF模型既往史、家族史返回数据
 //        putAllCrfData(midData.getJSONObject(Content.past), crfOut);
 //        putAllCrfData(midData.getJSONObject(Content.family), crfOut);
@@ -112,7 +110,17 @@ public class BeHospitalizedAI {
         chiefLabel.setClinicals(loadClinicals(aiOut));
         chiefLabel.setDiags(loadDiags(aiOut));
     }
-
+    public void putPresentCrfData(JSONObject jsonObject, InputInfo inputInfo){
+        if (jsonObject == null) {
+            return;
+        }
+        JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
+        //放置入inputinfo
+        PresentLabel presentLabel = inputInfo.getBeHospitalizedDoc().getPresentLabel();
+        presentLabel.setClinicals(loadClinicals(aiOut));
+        presentLabel.setGenerals(loadGeneralDes(aiOut));
+        presentLabel.setPacses(loadpacses(aiOut));
+    }
     /**
      * 关系抽取临床表现信息
      * @param aiOut
@@ -136,111 +144,49 @@ public class BeHospitalizedAI {
         List<Diag> diags = entityProcessDiag.extractEntity(aiOut);
         return diags;
     }
-
-    public void putAllCrfData_new(JSONObject jsonObject,Map<String,CrfOut> crfOut){
-        if (jsonObject == null) {
-            return;
-        }
-        JSONObject outputs = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
-        Map<String, Map<String, String>> chiefMap = annsiys_tr(outputs);
-        System.out.println();
-
+    /**
+     * 关系抽取化验信息
+     * @param aiOut
+     * @return
+     */
+    public List<Lis> loadLises(JSONObject aiOut) {
+        //化验信息
+        EntityProcessLis entityProcessLis = new EntityProcessLis();
+        List<Lis> lises = entityProcessLis.extractEntity(aiOut);
+        return lises;
     }
-    public void packageData(Map<String, Map<String, String>> chiefMap){
-        if(chiefMap.size()>0){
-            for (Map.Entry<String, Map<String, String>> data:chiefMap.entrySet()) {
-                String key = data.getKey();
-                Map<String, String> value = data.getValue();
-                if(value.size()>0){
-
-                }
-            }
-        }
+    /**
+     * 关系抽取辅检信息
+     * @param aiOut
+     * @return
+     */
+    public List<Pacs> loadpacses(JSONObject aiOut) {
+        //辅检信息
+        EntityProcessPacs entityProcessLis = new EntityProcessPacs();
+        List<Pacs> pacses = entityProcessLis.extractEntity(aiOut);
+        return pacses;
     }
-    public void putAllCrfData(JSONObject jsonObject,Map<String,List<CrfOut>> crfOut){
-        if (jsonObject == null) {
-            return;
-        }
-        JSONObject outputs = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
-        Map<String, Map<String, String>> stringMapMap = annsiys_tr(outputs);
-        List<CrfOut> medOut = new ArrayList<>();
-        CrfOut outputInfo = new CrfOut();
-//        add2Output(new EntityProcessClinic(), outputs, outputInfo);//临床表现
-//        add2Output(new EntityProcessGenerals(), outputs, outputInfo);//一般情况描述
-//        add2Output(new EntityProcessVital(), outputs, outputInfo);//体征
-//        add2Output(new EntityProcessLis(), outputs, outputInfo);//化验
-//        add2Output(new EntityProcessPacs(), outputs, outputInfo);//辅检
-//        add2Output(new EntityProcessDiag(), outputs, outputInfo);//诊断
-//        add2Output(new EntityProcessPast(), outputs, outputInfo);
-
-        medOut.add(outputInfo);
-        crfOut.put(jsonObject.getString("detail_title"),medOut);
+    /**
+     * 关系抽取体格检查
+     * @param aiOut
+     * @return
+     */
+    public List<Vital> loadvital(JSONObject aiOut) {
+        //一般情况描述信息
+        EntityProcessVital entityProcessVital = new EntityProcessVital();
+        List<Vital> vitals = entityProcessVital.extractEntity(aiOut);
+        return vitals;
     }
-    public Map<String,Map<String,String>> annsiys_tr(JSONObject outputs){
-        Map<String,Map<String,String>> result_map = new HashMap<>();
-        Map<Integer,List<Integer>> id_map = new HashMap<>();
-        JSONObject annotation = outputs.getJSONObject("annotation");
-        JSONArray entitys = annotation.getJSONArray("T");
-        JSONArray relations = annotation.getJSONArray("R");
-        if(relations.size()>0){
-            for(int i = 0;i<relations.size();i++){
-                if (StringUtils.isEmpty(relations.get(i).toString())) {
-                    continue;
-                }
-                JSONObject jsonObject = relations.getJSONObject(i);
-                if(!jsonObject.isEmpty()){
-                    Integer from_id = jsonObject.getInteger("from");
-                    Integer to_id = jsonObject.getInteger("to");
-                    if(id_map.containsKey(from_id)){
-                        List<Integer> integers = id_map.get(from_id);
-                        integers.add(to_id);
-                        id_map.put(from_id,integers);
-                    }else {
-                        List<Integer> ids = new ArrayList<>();
-                        ids.add(to_id);
-                        id_map.put(from_id,ids);
-                    }
-                }
-            }
-        }
-        if(id_map.size()>0 && entitys.size()>0){
-            for(int i = 0;i<entitys.size();i++){
-                if (StringUtils.isEmpty(entitys.get(i).toString())) {
-                    continue;
-                }
-                JSONObject jsonObject = entitys.getJSONObject(i);
-                if(!jsonObject.isEmpty()){
-                    String name = jsonObject.getString("name");
-                    Integer id = jsonObject.getInteger("id");
-                    String value = jsonObject.getString("value");
-                    if(id_map.keySet().contains(id)){
-                        Map<String,String> rMap = new HashMap<>();
-                        rMap.put("type",name);
-                        List<Integer> ids = id_map.get(id);
-                        if(ids.size()>0){
-                            for (Integer id_n:ids) {
-                                if(entitys.size()>0){
-                                    for(int h = 0;h<entitys.size();h++){
-                                        if (StringUtils.isEmpty(entitys.get(h).toString())) {
-                                            continue;
-                                        }
-                                        JSONObject jsonObject_h = entitys.getJSONObject(h);
-                                        if(!jsonObject_h.isEmpty()){
-                                            Integer id1 = jsonObject_h.getInteger("id");
-                                            if(id_n.equals(id1)){
-                                                rMap.put(jsonObject_h.getString("name"),jsonObject_h.getString("value"));
-                                                result_map.put(value,rMap);
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        return result_map;
+    /**
+     * 关系抽取一般情况描述信息
+     * @param aiOut
+     * @return
+     */
+    public List<GeneralDesc> loadGeneralDes(JSONObject aiOut) {
+        //一般情况描述信息
+        EntityProcessGenerals entityProcessGeneral = new EntityProcessGenerals();
+        List<GeneralDesc> generals = entityProcessGeneral.extractEntity(aiOut);
+        return generals;
     }
 
     public void putContent(JSONArray crfContent, String medicalTextType, String text,String sign){

+ 2 - 4
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/process/EntityProcessGenerals.java

@@ -13,9 +13,7 @@ import java.util.List;
 import java.util.Map;
 
 public class EntityProcessGenerals extends EntityProcess{
-
-    @Override
-    public void extractEntity(JSONObject outputs, CrfOut outputInfo) {
+    public List<GeneralDesc> extractEntity(JSONObject outputs) {
         List<GeneralDesc> generals = new ArrayList<>();
         GeneralDesc general;
         List<Map<String, String>> generalEntityList = processJson(outputs, EntityEnum.GENERAL.toString());
@@ -39,6 +37,6 @@ public class EntityProcessGenerals extends EntityProcess{
             }
             generals.add(general);
         }
-        outputInfo.setGenerals(generals);
+        return generals;
     }
 }

+ 2 - 5
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/process/EntityProcessLis.java

@@ -1,20 +1,17 @@
 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.Lis;
 import com.lantone.qc.pub.model.entity.LisValue;
 import com.lantone.qc.pub.model.entity.PD;
 import org.apache.commons.lang3.StringUtils;
-
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
 public class EntityProcessLis extends EntityProcess {
-    @Override
-    public void extractEntity(JSONObject outputs, CrfOut outputInfo) {
+    public List<Lis> extractEntity(JSONObject outputs) {
         List<Lis> lises = new ArrayList<>();
         Lis lis = null;
         List<Map<String, String>> lisEntityList = processJson(outputs, EntityEnum.LABORATORY.toString());
@@ -47,6 +44,6 @@ public class EntityProcessLis extends EntityProcess {
             }
             lises.add(lis);
         }
-        outputInfo.setLises(lises);
+        return lises;
     }
 }

+ 2 - 3
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/process/EntityProcessPacs.java

@@ -13,8 +13,7 @@ import java.util.List;
 import java.util.Map;
 
 public class EntityProcessPacs extends EntityProcess {
-    @Override
-    public void extractEntity(JSONObject outputs, CrfOut outputInfo) {
+    public List<Pacs> extractEntity(JSONObject outputs) {
         List<Pacs> pacses = new ArrayList<>();
         Pacs pacs = null;
         List<Map<String, String>> pacsEntityList = processJson(outputs, EntityEnum.AUXILIARY_EXAMINATION.toString());
@@ -43,6 +42,6 @@ public class EntityProcessPacs extends EntityProcess {
             }
             pacses.add(pacs);
         }
-        outputInfo.setPacses(pacses);
+        return pacses;
     }
 }

+ 2 - 4
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/process/EntityProcessVital.java

@@ -1,7 +1,6 @@
 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.*;
 import org.apache.commons.lang3.StringUtils;
@@ -11,8 +10,7 @@ import java.util.List;
 import java.util.Map;
 
 public class EntityProcessVital extends EntityProcess {
-    @Override
-    public void extractEntity(JSONObject outputs, CrfOut outputInfo) {
+    public List<Vital> extractEntity(JSONObject outputs) {
         List<Vital> vitals = new ArrayList<>();
         Vital vital =null;
         List<Map<String, String>> vitalEntityList = processJson(outputs, EntityEnum.SIGN.toString());
@@ -54,6 +52,6 @@ public class EntityProcessVital extends EntityProcess {
             }
             vitals.add(vital);
         }
-        outputInfo.setVitals(vitals);
+        return vitals;
     }
 }

+ 2 - 1
public/src/main/java/com/lantone/qc/pub/model/label/PresentLabel.java

@@ -23,5 +23,6 @@ public class PresentLabel extends GeneralLabel {
     private List<Lis> lises;
     //治疗
     private List<Treat> treats;
-    private List<General> generals;
+    //一般情况
+    private List<GeneralDesc> generals;
 }