Explorar el Código

恩泽:阶段小结crf模型逻辑增加

wangsy hace 4 años
padre
commit
154f389d6d

+ 87 - 0
structure-center/src/main/java/com/lantone/structure/ai/StagesSummaryAI.java

@@ -0,0 +1,87 @@
+package com.lantone.structure.ai;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.google.common.collect.Lists;
+import com.lantone.common.util.CatalogueUtil;
+import com.lantone.common.util.StringUtil;
+import com.lantone.structure.ai.process.EntityProcessStagesSummary;
+import com.lantone.structure.client.CRFServiceClient;
+import com.lantone.structure.model.Content;
+import com.lantone.structure.model.InputInfo;
+import com.lantone.structure.model.doc.StagesSummaryDoc;
+import com.lantone.structure.model.label.StagesSummaryLabel;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @ClassName : StagesSummaryAI
+ * @Description : 阶段小结
+ * @Author : wsy
+ * @Date: 2021-01-25 17:16
+ */
+public class StagesSummaryAI extends ModelAI {
+
+    public static List<String> medicalTextType = Arrays.asList("Taizhou_summary");
+    public static String entityRelationObject = "entity_relation_object";
+    public static String outputs = "outputs";
+    public static String content = "content";
+    public static List<String> mapKey = Lists.newArrayList("病历内容","诊治经过");
+
+    public void medrec(InputInfo inputInfo, CRFServiceClient crfServiceClient) {
+        JSONArray crfContent = new JSONArray();
+        List<StagesSummaryDoc> resultsDocs = inputInfo.getStagesSummaryDocs();
+        for (int i = 0; i < resultsDocs.size(); i++) {
+            Map<String, String> structureMap = resultsDocs.get(i).getStructureMap();
+            String content = CatalogueUtil.structureMapJoin(structureMap, mapKey);
+            putContent(crfContent, medicalTextType.get(0), content, Content.stagesSummary);
+        }
+
+        JSONObject midData = loadAI(crfContent, crfServiceClient);//crf返回数据
+
+        for (int i = 0; i < resultsDocs.size(); i++) {
+            if (midData.get(Content.stagesSummary) == null) {
+                continue;
+            }
+            StagesSummaryDoc resultsDoc = resultsDocs.get(i);
+            StagesSummaryLabel stagesSummaryLabel = putStagesSummaryCrfData(midData.getJSONObject(Content.stagesSummary), inputInfo);
+            if (stagesSummaryLabel != null) {
+                resultsDoc.setStagesSummaryLabel(stagesSummaryLabel);
+            }
+        }
+    }
+
+
+    /**
+     * 处理阶段小结
+     *
+     * @param jsonObject
+     */
+    public StagesSummaryLabel putStagesSummaryCrfData(JSONObject jsonObject, InputInfo inputInfo) {
+        StagesSummaryLabel stagesSummaryLabel = new StagesSummaryLabel();
+        if (jsonObject == null) {
+            return stagesSummaryLabel;
+        }
+        JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(StagesSummaryAI.outputs);
+        if (aiOut == null) {
+            return stagesSummaryLabel;
+        }
+        EntityProcessStagesSummary entityProcessStagesSummary = new EntityProcessStagesSummary();
+        stagesSummaryLabel = entityProcessStagesSummary.extractEntity(aiOut);
+        return stagesSummaryLabel;
+    }
+
+    protected void putContent(JSONArray crfContent, String medicalTextType, String text, String sign) {
+        String move_text = CatalogueUtil.removeSpecialChar(text);
+        if (StringUtil.isEmpty(move_text)) {
+            return;
+        }
+        JSONObject detailContent = new JSONObject();
+        detailContent.put("medical_text_type", medicalTextType);
+        detailContent.put("content", move_text);
+        detailContent.put("detail_title", sign);
+        crfContent.add(detailContent);
+    }
+}

+ 72 - 0
structure-center/src/main/java/com/lantone/structure/ai/process/EntityProcessStagesSummary.java

@@ -0,0 +1,72 @@
+package com.lantone.structure.ai.process;
+
+
+import com.alibaba.fastjson.JSONObject;
+import com.lantone.structure.ai.model.EntityEnum;
+import com.lantone.structure.ai.model.Lemma;
+import com.lantone.structure.model.entity.AuxiliaryExamination;
+import com.lantone.structure.model.entity.Drug;
+import com.lantone.structure.model.entity.Laboratory;
+import com.lantone.structure.model.entity.Surgery;
+import com.lantone.structure.model.label.StagesSummaryLabel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 阶段小结处理
+ */
+public class EntityProcessStagesSummary extends EntityProcess {
+    private Logger logger = LoggerFactory.getLogger(EntityProcessStagesSummary.class);
+
+    public StagesSummaryLabel extractEntity(JSONObject aiOut) {
+        StagesSummaryLabel stagesSummaryLabel = new StagesSummaryLabel();
+        try {
+            //药品
+            List<Lemma> drugLemma = createEntityTree(aiOut, EntityEnum.DRUG_NAME.toString());
+            List<Drug> drugList = new ArrayList<>();
+            for (Lemma lemma : drugLemma) {
+                Drug drug = new Drug();
+                drug.setName(lemma.getText());
+                drugList.add(drug);
+            }
+            stagesSummaryLabel.setDrugs(drugList);
+
+            //手术名称
+            List<Lemma> surgeryLemma = createEntityTree(aiOut, EntityEnum.OPERATION.toString());
+            List<Surgery> surgeryList = new ArrayList<>();
+            for (Lemma lemma : surgeryLemma) {
+                Surgery surgery = new Surgery();
+                surgery.setName(lemma.getText());
+                surgeryList.add(surgery);
+            }
+            stagesSummaryLabel.setSurgerys(surgeryList);
+
+            //实验室检查
+            List<Lemma> examinationLemma = createEntityTree(aiOut, EntityEnum.LABORATORY.toString());
+            List<Laboratory> laboratoryList = new ArrayList<>();
+            for (Lemma lemma : examinationLemma) {
+                Laboratory examination = new Laboratory();
+                examination.setName(lemma.getText());
+                laboratoryList.add(examination);
+            }
+            stagesSummaryLabel.setLaboratory(laboratoryList);
+
+            //辅助检查
+            List<Lemma> auxiliaryExaminationLemma = createEntityTree(aiOut, EntityEnum.AUXILIARY_EXAMINATION.toString());
+            List<AuxiliaryExamination> auxiliaryExaminationList = new ArrayList<>();
+            for (Lemma lemma : auxiliaryExaminationLemma) {
+                AuxiliaryExamination auxiliaryExamination = new AuxiliaryExamination();
+                auxiliaryExamination.setName(lemma.getText());
+                auxiliaryExaminationList.add(auxiliaryExamination);
+            }
+            stagesSummaryLabel.setAuxiliaryExaminations(auxiliaryExaminationList);
+        } catch (Exception e) {
+            e.printStackTrace();
+            logger.error(e.getMessage(), e);
+        }
+        return stagesSummaryLabel;
+    }
+}

+ 2 - 0
structure-center/src/main/java/com/lantone/structure/model/doc/StagesSummaryDoc.java

@@ -1,5 +1,6 @@
 package com.lantone.structure.model.doc;
 
+import com.lantone.structure.model.label.StagesSummaryLabel;
 import lombok.Getter;
 import lombok.Setter;
 
@@ -11,4 +12,5 @@ import lombok.Setter;
 @Getter
 @Setter
 public class StagesSummaryDoc extends ModelDoc {
+    private StagesSummaryLabel stagesSummaryLabel;
 }

+ 15 - 0
structure-center/src/main/java/com/lantone/structure/model/entity/Surgery.java

@@ -0,0 +1,15 @@
+package com.lantone.structure.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @ClassName : Surgery
+ * @Description : 手术名称
+ * @Author : wsy
+ * @Date: 2021-01-25 19:15
+ */
+@Setter
+@Getter
+public class Surgery extends General {
+}

+ 26 - 0
structure-center/src/main/java/com/lantone/structure/model/label/StagesSummaryLabel.java

@@ -0,0 +1,26 @@
+package com.lantone.structure.model.label;
+
+import com.lantone.structure.model.entity.AuxiliaryExamination;
+import com.lantone.structure.model.entity.Drug;
+import com.lantone.structure.model.entity.Laboratory;
+import com.lantone.structure.model.entity.Surgery;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @ClassName : StagesSummaryLabel
+ * @Description :
+ * @Author : wsy
+ * @Date: 2021-01-25 9:51
+ */
+@Getter
+@Setter
+public class StagesSummaryLabel {
+    private List<Drug> drugs = new ArrayList<>(); //药物
+    private List<Surgery> surgerys = new ArrayList<>(); //手术名称
+    private List<Laboratory> laboratory = new ArrayList<>(); //实验室检查
+    private List<AuxiliaryExamination> auxiliaryExaminations = new ArrayList<>(); //辅助检查
+}