zhoutg 4 years ago
parent
commit
db0acbe4de

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

@@ -151,6 +151,14 @@ public class BeHospitalizedAI extends ModelAI {
                 PacsLabel pacsLabel = new PacsLabel();
                 pacsLabel.setPacsNewList(collect);
                 wordCrfDTO.setPacsLabel(pacsLabel);
+
+                StringBuffer sb = new StringBuffer();
+                for (PacsNew pacsNew : collect) {
+                    sb.append(pacsNew.getUniqueName() + ":").append(pacsNew.getResult() + "。\n");
+                }
+                pacsLabel.setText(sb.toString());
+                pacsLabel.setAiText(sb.toString());
+                putContent(crfContent, medicalTextType.get(5), sb.toString(), Content.pacs);
             }
 
             /* *//* 辅助检查(暂用主诉现病史模型,之后会新训练单独模型再做修改) *//*
@@ -258,26 +266,9 @@ public class BeHospitalizedAI extends ModelAI {
             /*if (wordCrfDTO.getPacsLabel() != null) {
                 putPacsCrfData(midData.getJSONObject(Content.pacs), wordCrfDTO);
             }*/
-            /**
-             * 处理辅检pacsnew
-             */
-            if(wordCrfDTO.getPacsLabel() != null && ListUtil.isNotEmpty(wordCrfDTO.getPacsLabel().getPacsNewList())){
-                EntityProcessPacsNew entityProcessPacsNew = new EntityProcessPacsNew();
-                List<PacsNew> pacsNews = wordCrfDTO.getPacsLabel().getPacsNewList();
-                for (PacsNew pacsnew:pacsNews) {
-                    JSONArray crfPacsContent = new JSONArray();
-                    putContent(crfPacsContent, medicalTextType.get(5), pacsnew.getResult(), Content.pacs);
-                    JSONObject midPacsData = loadAI(crfPacsContent, crfServiceClient);
-                    JSONObject jsonObject = midPacsData.getJSONObject(Content.pacs);
-                    if(jsonObject == null){
-                        continue;
-                    }
-                    JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
-                    if (aiOut == null) {
-                        continue;
-                    }
-                    entityProcessPacsNew.extractEntity(aiOut, pacsnew);
-                }
+            // 处理辅检
+            if(StringUtil.isNotBlank(wordCrfDTO.getPacsLabel().getText())) {
+                putInitialPacsCrfData(midData.getJSONObject(Content.pacs), wordCrfDTO.getPacsLabel());
             }
         }
     }
@@ -631,4 +622,22 @@ public class BeHospitalizedAI extends ModelAI {
         }
         wordCrfDTO.setVitalLabel(vitalLabel);
     }
+
+    /*
+     * 初步诊断信息提取
+     *
+     * @param jsonObject
+     * @param inputInfo
+     */
+    public void putInitialPacsCrfData(JSONObject jsonObject, PacsLabel pacsLabel) {
+        if (jsonObject == null) {
+            return;
+        }
+        JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
+        if (aiOut == null) {
+            return;
+        }
+        EntityProcessPacsNew entityProcessPacsNew = new EntityProcessPacsNew();
+        entityProcessPacsNew.extractEntity(aiOut, pacsLabel);
+    }
 }

+ 40 - 23
src/main/java/com/diagbot/model/ai/process/EntityProcessPacsNew.java

@@ -6,9 +6,12 @@ import com.diagbot.model.ai.model.Lemma;
 import com.diagbot.model.entity.BodyPart;
 import com.diagbot.model.entity.Pacs;
 import com.diagbot.model.entity.PacsNew;
+import com.diagbot.model.label.PacsLabel;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author kwz
@@ -17,37 +20,51 @@ import java.util.List;
  */
 public class EntityProcessPacsNew extends EntityProcess {
 
-    public void extractEntity(JSONObject aiOut, PacsNew pacsNew) {
+    public void extractEntity(JSONObject aiOut, PacsLabel pacsLabel) {
         //辅检描述情况
-        List<Pacs> pacses = new ArrayList<>();
-        List<Lemma> pacsLemmas = createEntityTree(aiOut, EntityEnum.AUXILIARY_DESCRIPT.toString());
-        for (Lemma lemma : pacsLemmas) {
-            Pacs pacs = new Pacs();
-            pacs.setName(lemma.getText());
-            pacs.setStandName(lemma.getText());
+        List<Lemma> pacsAll = createEntityTree(aiOut, EntityEnum.AUXILIARY_EXAMINATION.toString());
+
+        Map<String, PacsNew> map = new HashMap<>();
+        for (Lemma lemma : pacsAll) {
+            PacsNew pacs = new PacsNew();
             if (lemma.isHaveChildren()) {
-                List<BodyPart> bodyPartList = new ArrayList<>();
+                List<Pacs> descList = new ArrayList<>();
+                List<Pacs> disList = new ArrayList<>();
                 for (Lemma relationLemma : lemma.getRelationLemmas()) {
-                    if (relationLemma.getProperty().equals(EntityEnum.BODY.toString())) {
-                        bodyPartList.add(addBodyPart(relationLemma));
+                    if (relationLemma.getProperty().equals(EntityEnum.AUXILIARY_DESCRIPT.toString())) {
+                        Pacs desc = new Pacs();
+                        desc.setName(relationLemma.getText());
+                        desc.setStandName(relationLemma.getText());
+                        // if (lemma.isHaveChildren()) {
+                        //     List<BodyPart> bodyPartList = new ArrayList<>();
+                        //     for (Lemma relationLemmaSon : lemma.getRelationLemmas()) {
+                        //         if (relationLemma.getProperty().equals(EntityEnum.BODY.toString())) {
+                        //             bodyPartList.add(addBodyPart(relationLemmaSon));
+                        //         }
+                        //     }
+                        //     desc.setBodyPartList(bodyPartList);
+                        // }
+                        descList.add(desc);
+                    } else if (relationLemma.getProperty().equals(EntityEnum.DIEASE.toString())) {
+                        // 辅检诊断信息
+                        Pacs dis = new Pacs();
+                        dis.setName(relationLemma.getText());
+                        dis.setStandName(relationLemma.getText());
+                        disList.add(dis);
                     }
                 }
-                pacs.setBodyPartList(bodyPartList);
+                pacs.setPacsResults(descList);
+                pacs.setDisease(disList);
             }
-            pacses.add(pacs);
+            map.put(lemma.getText(), pacs);
         }
-        pacsNew.setPacsResults(pacses);
-
-        // 辅检诊断信息
-        List<Pacs> pacsDisList = new ArrayList<>();
-        List<Lemma> disLemmas = createEntityTree(aiOut, EntityEnum.DIEASE.toString());
-        for (Lemma lemma : disLemmas) {
-            Pacs pacs = new Pacs();
-            pacs.setName(lemma.getText());
-            pacs.setStandName(lemma.getText());
-            pacsDisList.add(pacs);
+        List<PacsNew> pacsNewList = pacsLabel.getPacsNewList();
+        for (PacsNew p : pacsNewList) {
+            if (map.get(p.getName()) != null) {
+                p.setPacsResults(map.get(p.getName()).getPacsResults());
+                p.setDisease(map.get(p.getName()).getDisease());
+            }
         }
-        pacsNew.setDisease(pacsDisList);
     }
 
     /**