Bläddra i källkod

字段标准化修改准备工作-台州入北仑

huj 4 år sedan
förälder
incheckning
84d6cf5418

+ 63 - 21
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/LeaveHospitalAI.java

@@ -2,12 +2,17 @@ package com.lantone.qc.kernel.structure.ai;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.google.common.collect.Lists;
 import com.lantone.qc.kernel.client.CRFServiceClient;
+import com.lantone.qc.kernel.structure.ai.process.EntityProcessDiag;
+import com.lantone.qc.kernel.structure.ai.process.EntityProcessDrug;
 import com.lantone.qc.kernel.structure.ai.process.EntityProcessLeaveHospital;
 import com.lantone.qc.kernel.util.CatalogueUtil;
 import com.lantone.qc.pub.Content;
 import com.lantone.qc.pub.model.InputInfo;
 import com.lantone.qc.pub.model.doc.LeaveHospitalDoc;
+import com.lantone.qc.pub.model.entity.Diag;
+import com.lantone.qc.pub.model.entity.Drug;
 import com.lantone.qc.pub.model.label.DiagLabel;
 import com.lantone.qc.pub.model.label.LeaveHospitalLabel;
 import com.lantone.qc.pub.util.StringUtil;
@@ -27,7 +32,7 @@ public class LeaveHospitalAI extends ModelAI {
     /**
      *
      */
-    public static List<String> medicalTextType = Arrays.asList("DischargeQA_cx", "Diagnoses_cx");
+    public static List<String> medicalTextType = Arrays.asList("DischargeQA_cx", "Diagnoses_cx", "CourseRecordSRR");
     public static String entityRelationObject = "entity_relation_object";
     public static String outputs = "outputs";
     public static String content = "content";
@@ -42,33 +47,38 @@ public class LeaveHospitalAI extends ModelAI {
             }
 
             Map<String, String> leaveHospitalStructureMap = leaveHospitalDoc.getStructureMap();
-            if (leaveHospitalStructureMap != null) {
-                //                //入院情况
-                //                if (leaveHospitalStructureMap.get(Content.inStatus) != null) {
-                //                    putContent(crfContent, medicalTextType.get(1), leaveHospitalStructureMap.get(Content.inStatus), Content.inStatus);
-                //                }
-                //出院诊断
-                if (StringUtil.isNotBlank(leaveHospitalStructureMap.get(Content.dischargeDiag))) {
-                    String dischargeDiag = leaveHospitalStructureMap.get(Content.dischargeDiag);
+            //入院情况
+            //if (leaveHospitalStructureMap.get(Content.inStatus) != null) {
+            //    putContent(crfContent, medicalTextType.get(1), leaveHospitalStructureMap.get(Content.inStatus), Content.inStatus);
+            //}
+            //出院诊断
+            if (StringUtil.isNotBlank(leaveHospitalStructureMap.get(Content.dischargeDiag))) {
+                String dischargeDiag = leaveHospitalStructureMap.get(Content.dischargeDiag);
                     /*if (CatalogueUtil.numberExist(dischargeDiag)) {
                         dischargeDiag = CatalogueUtil.removeBetweenWordSpace(dischargeDiag);
                     }*/
-                    putContent(crfContent, medicalTextType.get(1), dischargeDiag, Content.dischargeDiag);
-                }
+                putContent(crfContent, medicalTextType.get(1), dischargeDiag, Content.dischargeDiag);
             }
             if (leaveHospitalDoc.getLeaveHospitalDoctorAdviceLabel() != null
                     && StringUtils.isNotEmpty(leaveHospitalDoc.getLeaveHospitalDoctorAdviceLabel().getAiText())) {
                 putContent(crfContent, medicalTextType.get(0), leaveHospitalDoc.getLeaveHospitalDoctorAdviceLabel().getAiText(), Content.leaveHospitalDoctorAdvice);
             }
+            //药品
+            String drugContent = CatalogueUtil.structureMapJoin(leaveHospitalStructureMap, Lists.newArrayList("诊治经过", "出院带药"));
+            putContent(crfContent, medicalTextType.get(2), drugContent, "药品");
+
             JSONObject midData = loadAI(inputInfo.isUseCrfCache(), inputInfo.getMedicalRecordInfoDoc().getStructureMap().get("behospitalCode"), crfContent, crfServiceClient);//crf返回数据
             if (midData.containsKey(Content.discharge)) {
                 putDischargeCrfData(midData.getJSONObject(Content.discharge), inputInfo);//出院小结
             }
             if (midData.containsKey(Content.dischargeDiag)) {
-                putDischargeCrfData(midData.getJSONObject(Content.dischargeDiag), inputInfo);//出院诊断
+                putDiagCrfData(midData.getJSONObject(Content.dischargeDiag), inputInfo);//出院诊断
             }
             if (midData.containsKey(Content.leaveHospitalDoctorAdvice)) {
-//                putLeaveHospitalDoctorAdviceCrfData(midData.getJSONObject(Content.leaveHospitalDoctorAdvice), inputInfo);//出院医嘱
+                //putLeaveHospitalDoctorAdviceCrfData(midData.getJSONObject(Content.leaveHospitalDoctorAdvice), inputInfo);//出院医嘱
+            }
+            if (midData.containsKey("药品")) {
+                putDrugCrfData(midData.getJSONObject("药品"), inputInfo);
             }
         }
     }
@@ -85,18 +95,50 @@ public class LeaveHospitalAI extends ModelAI {
         if (aiOut == null) {
             return;
         }
-        //使用现病史结构来处理病历特点
         EntityProcessLeaveHospital entityProcessLeaveHospital = new EntityProcessLeaveHospital();
         LeaveHospitalLabel leaveHospitalLabel = entityProcessLeaveHospital.extractEntity(aiOut);
-        if (inputInfo.getLeaveHospitalDoc().getLeaveDiagLabel() == null) {
-            DiagLabel diagLabel = new DiagLabel();
-            diagLabel.setDiags(leaveHospitalLabel.getDiags());
-            inputInfo.getLeaveHospitalDoc().setLeaveDiagLabel(diagLabel);
+        inputInfo.getLeaveHospitalDoc().setLeaveHospitalLabel(leaveHospitalLabel);
+    }
+
+    /**
+     * 存放抓取的疾病
+     *
+     * @param jsonObject
+     * @param inputInfo
+     */
+    public void putDiagCrfData(JSONObject jsonObject, InputInfo inputInfo) {
+        JSONObject aiOut = loadEntity(jsonObject, entityRelationObject, outputs, content);
+        if (aiOut == null) {
+            return;
+        }
+        EntityProcessDiag entityProcessDiag = new EntityProcessDiag();
+        List<Diag> diags = entityProcessDiag.extractEntity(aiOut);
+        DiagLabel diagLabel = new DiagLabel();
+        diagLabel.setDiags(diags);
+        inputInfo.getLeaveHospitalDoc().setLeaveDiagLabel(diagLabel);
+    }
+
+    /**
+     * 存放抓取的药品
+     *
+     * @param jsonObject
+     * @param inputInfo
+     */
+    public void putDrugCrfData(JSONObject jsonObject, InputInfo inputInfo) {
+        JSONObject aiOut = loadEntity(jsonObject, entityRelationObject, outputs, content);
+        if (aiOut == null) {
+            return;
+        }
+        EntityProcessDrug entityProcessDrug = new EntityProcessDrug();
+        List<Drug> drugs = entityProcessDrug.extractEntity(aiOut);
+        LeaveHospitalDoc leaveHospitalDoc = inputInfo.getLeaveHospitalDoc();
+        if (leaveHospitalDoc.getLeaveHospitalLabel() == null) {
+            LeaveHospitalLabel label = new LeaveHospitalLabel();
+            label.setDrugs(drugs);
+            leaveHospitalDoc.setLeaveHospitalLabel(label);
         } else {
-            inputInfo.getLeaveHospitalDoc().getLeaveDiagLabel().setDiags(leaveHospitalLabel.getDiags());
+            leaveHospitalDoc.getLeaveHospitalLabel().setDrugs(drugs);
         }
-        //临床表现
-        inputInfo.getLeaveHospitalDoc().setLeaveHospitalLabel(leaveHospitalLabel);
     }
 
     /**

+ 62 - 27
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/OperationAI.java

@@ -2,18 +2,25 @@ package com.lantone.qc.kernel.structure.ai;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.google.common.collect.Lists;
 import com.lantone.qc.kernel.client.CRFServiceClient;
+import com.lantone.qc.kernel.structure.ai.process.EntityProcessDrug;
 import com.lantone.qc.kernel.structure.ai.process.EntityProcessOperationDiscussion;
 import com.lantone.qc.kernel.util.CatalogueUtil;
 import com.lantone.qc.pub.Content;
 import com.lantone.qc.pub.model.InputInfo;
 import com.lantone.qc.pub.model.doc.operation.OperationDiscussionDoc;
 import com.lantone.qc.pub.model.doc.operation.OperationDoc;
+import com.lantone.qc.pub.model.doc.operation.OperationRecordDoc;
+import com.lantone.qc.pub.model.entity.Drug;
 import com.lantone.qc.pub.model.label.OperationDiscussionLabel;
+import com.lantone.qc.pub.model.label.OperationRecordLabel;
 import com.lantone.qc.pub.util.StringUtil;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @ClassName : OperationAI
@@ -25,29 +32,59 @@ public class OperationAI extends ModelAI {
     /**
      *
      */
-    public static List<String> medicalTextType = Arrays.asList("CourseAfterOperation_cx");
+    public static List<String> medicalTextType = Arrays.asList("CourseAfterOperation_cx", "CourseRecordSRR");
     public static String entityRelationObject = "entity_relation_object";
     public static String outputs = "outputs";
     public static String content = "content";
+    public static List<String> discussionKey = Lists.newArrayList("术前诊断", "术中诊断", "手术名称", "麻醉方式"
+            , "手术经过", "目前情况", "术后注意事项");
 
     public void medrec(InputInfo inputInfo, CRFServiceClient crfServiceClient) {
         JSONArray crfContent = new JSONArray();
         List<OperationDoc> operationDocs = inputInfo.getOperationDocs();
         for (int i = 0; i < operationDocs.size(); i++) {
-            if (operationDocs.get(i).getOperationDiscussionDoc() == null) {
-                continue;
+            if (operationDocs.get(i).getOperationRecordDoc() != null) {
+                OperationRecordDoc operationRecordDoc = operationDocs.get(i).getOperationRecordDoc();
+                Map<String, String> structureMap = operationRecordDoc.getStructureMap();
+                //存放抓取的药品
+                String content = CatalogueUtil.structureMapJoin(structureMap, Lists.newArrayList("手术经过"));
+                putContent(crfContent, medicalTextType.get(1), content, "手术记录" + i + "药物");
+            }
+            if (operationDocs.get(i).getOperationDiscussionDoc() != null) {
+                OperationDiscussionDoc operationDiscussionDoc = operationDocs.get(i).getOperationDiscussionDoc();
+                Map<String, String> structureMap = operationDiscussionDoc.getStructureMap();
+                String discussionText = CatalogueUtil.structureMapJoin(structureMap, discussionKey);
+                putContent(crfContent, medicalTextType.get(0), discussionText, Content.operation_Discussion + i);
+                //存放抓取的药品
+                String content = CatalogueUtil.structureMapJoin(structureMap, Lists.newArrayList("治疗计划和措施"));
+                putContent(crfContent, medicalTextType.get(1), content, Content.operation_Discussion + i + "药物");
             }
-            OperationDiscussionDoc operationDiscussionDoc = operationDocs.get(i).getOperationDiscussionDoc();
-            putContent(crfContent, medicalTextType.get(0), operationDiscussionDoc.getText(), Content.operation_Discussion + i);
         }
 
         JSONObject midData = loadAI(inputInfo.isUseCrfCache(), inputInfo.getMedicalRecordInfoDoc().getStructureMap().get("behospitalCode"), crfContent, crfServiceClient);//crf返回数据
 
         for (int i = 0; i < operationDocs.size(); i++) {
-            if (midData.get(Content.operation_Discussion + i) == null) {
-                continue;
+            if (midData.get("手术记录" + i + "药物") != null) {
+                OperationRecordDoc operationRecordDoc = operationDocs.get(i).getOperationRecordDoc();
+                //手术记录药品
+                OperationRecordLabel operationRecordLabel = new OperationRecordLabel();
+                operationRecordLabel.setDrugs(putDrugCrfData(midData.getJSONObject("手术记录" + i + "药物")));
+            }
+            if (midData.get(Content.operation_Discussion + i) != null) {
+                OperationDiscussionDoc discussionDoc = operationDocs.get(i).getOperationDiscussionDoc();
+                OperationDiscussionLabel discussionLabel = putOperationDiscussionCrfData(midData.getJSONObject(Content.operation_Discussion + i));
+                if (discussionLabel != null) {
+                    discussionDoc.setOperationDiscussionLabel(discussionLabel);
+                }
+                //术后首程药品
+                if (midData.get(Content.operation_Discussion + i + "药物") != null) {
+                    discussionLabel = operationDocs.get(i).getOperationDiscussionDoc().getOperationDiscussionLabel();
+                    if (discussionLabel == null) {
+                        discussionLabel = new OperationDiscussionLabel();
+                    }
+                    discussionLabel.setDrugs(putDrugCrfData(midData.getJSONObject(Content.operation_Discussion + i + "药物")));
+                }
             }
-            putOperationDiscussionCrfData(midData.getJSONObject(Content.operation_Discussion + i), inputInfo);
         }
     }
 
@@ -55,32 +92,30 @@ public class OperationAI extends ModelAI {
      * 处理手术记录
      *
      * @param jsonObject
-     * @param inputInfo
      */
-    public void putOperationDiscussionCrfData(JSONObject jsonObject, InputInfo inputInfo) {
+    public OperationDiscussionLabel putOperationDiscussionCrfData(JSONObject jsonObject) {
         JSONObject aiOut = loadEntity(jsonObject, entityRelationObject, outputs, content);
         if (aiOut == null) {
-            return;
+            return null;
         }
         String originalText = jsonObject.getString("originalText");
-        //使用现病史结构来处理病历特点
         EntityProcessOperationDiscussion entityProcessOperationDiscussion = new EntityProcessOperationDiscussion();
-        OperationDiscussionLabel operationDiscussionLabel = entityProcessOperationDiscussion.extractEntity(aiOut);
-        List<OperationDoc> operationDocs = inputInfo.getOperationDocs();
-        for (OperationDoc operationDoc : operationDocs) {
-            OperationDiscussionDoc operationDiscussionDoc = null;
-            String text = null;
-            if(operationDoc.getOperationDiscussionDoc() != null){
-                operationDiscussionDoc = operationDoc.getOperationDiscussionDoc();
-                if(StringUtil.isNotBlank(operationDiscussionDoc.getText())){
-                    text = operationDiscussionDoc.getText();
-                }
-            }
-            if (StringUtil.isNotBlank(text) && StringUtil.isNotBlank(originalText) && text.equals(originalText)) {
-                operationDiscussionDoc.setOperationDiscussionLabel(operationDiscussionLabel);
-                break;
-            }
+        return entityProcessOperationDiscussion.extractEntity(aiOut);
+    }
+
+    /**
+     * 存放抓取的药品
+     *
+     * @param jsonObject
+     */
+    public List<Drug> putDrugCrfData(JSONObject jsonObject) {
+        JSONObject aiOut = loadEntity(jsonObject, entityRelationObject, outputs, content);
+        if (aiOut == null) {
+            return new ArrayList<>();
         }
+        EntityProcessDrug entityProcessDrug = new EntityProcessDrug();
+        List<Drug> drugs = entityProcessDrug.extractEntity(aiOut);
+        return drugs;
     }
 
     protected void putContent(JSONArray crfContent, String medicalTextType, String text, String sign) {

+ 50 - 32
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/ThreeLevelWardAI.java

@@ -96,19 +96,19 @@ public class ThreeLevelWardAI extends ModelAI {
 
         //主治医师首次查房记录模型输出
         if (midData.get(Content.attend) != null) {
-            putWardRoundCrfData(midData.getJSONObject(Content.attend), inputInfo, 0);//查房记录
+            attendingDocs.get(0).setThreeLevelWardLabel(putWardRoundCrfData(midData.getJSONObject(Content.attend)));
         }
         //主任医师首次查房记录模型输出
         if (midData.get(Content.director) != null) {
-            putWardRoundCrfData(midData.getJSONObject(Content.director), inputInfo, 0);//查房记录
+            directorDocs.get(0).setThreeLevelWardLabel(putWardRoundCrfData(midData.getJSONObject(Content.director)));
         }
         //主任医师最后一次查房记录模型输出
         if (midData.get(Content.director + "最后一次") != null) {
-            putWardRoundCrfData(midData.getJSONObject(Content.director + "最后一次"), inputInfo, 0);//最后一次查房记录
+            directorDocs.get(directorDocs.size() - 1).setThreeLevelWardLabel(putWardRoundCrfData(midData.getJSONObject(Content.director + "最后一次")));
         }
         //最后一次查房记录模型输出
         if (midData.get("末次查房") != null) {
-            putWardRoundCrfData(midData.getJSONObject("末次查房"), inputInfo, 0);//最后一次查房记录
+            allDoctorWradDocs.get(allDoctorWradDocs.size() - 1).setThreeLevelWardLabel(Lists.newArrayList(putWardRoundCrfData(midData.getJSONObject("末次查房"))));
         }
         //疑难患者副高及以上查房记录模型输出
         if (inputInfo.getDifficultCaseDiscussDocs().size() > 0 && ListUtil.isNotEmpty(directorDifficultRecord)) {
@@ -129,6 +129,14 @@ public class ThreeLevelWardAI extends ModelAI {
             }
         }
 
+        //2020/08/20新增所有查房记录抽取:实验室检查、辅助检查、药品等
+        for (int i = 0; i < allDoctorWradDocs.size(); i++) {
+            if (midData.get("第" + i + "次查房") == null) {
+                continue;
+            }
+            putWardRoundCrfData(midData.getJSONObject("第" + i + "次查房"), inputInfo, 0);//查房记录
+        }
+
     }
 
     protected void putContent(JSONArray crfContent, String medicalTextType, String text, String sign, String wardDate) {
@@ -145,7 +153,7 @@ public class ThreeLevelWardAI extends ModelAI {
     }
 
     /**
-     * 处理查房记录
+     * 处理全部查房记录
      *
      * @param jsonObject
      * @param inputInfo
@@ -157,43 +165,53 @@ public class ThreeLevelWardAI extends ModelAI {
         }
         String wardDate = jsonObject.getString("wardDate");
         String detailTitle = jsonObject.getString("detail_title");
-        //使用现病史结构来处理病历特点
         EntityProcessThreeLevelWard entityProcessThreeLevelWard = new EntityProcessThreeLevelWard();
         ThreeLevelWardLabel threeLevelWardLabel = entityProcessThreeLevelWard.extractEntity(aiOut);
         threeLevelWardLabel.setTitle(detailTitle);
         threeLevelWardLabel.setSerious(serious);
         ThreeLevelWardDoc threeLevelWardDoc = inputInfo.getThreeLevelWardDocs().get(0);
-        if (serious == 0) {//处理主治/主任查房记录
-            switch (detailTitle) {
-                case Content.attend:
-                    threeLevelWardDoc.getAttendingDoctorWardDocs().get(0).setThreeLevelWardLabel(threeLevelWardLabel);
-                    break;
-                case Content.director:
-                    threeLevelWardDoc.getDirectorDoctorWardDocs().get(0).setThreeLevelWardLabel(threeLevelWardLabel);
-                    break;
-                case Content.director + "最后一次":
-                    List<DirectorDoctorWardDoc> director = threeLevelWardDoc.getDirectorDoctorWardDocs();
-                    director.get(director.size() - 1).setThreeLevelWardLabel(threeLevelWardLabel);
-                    break;
-                case "末次查房":
-                    List<ThreeLevelWardDoc> allDoctorWradDocs = threeLevelWardDoc.getAllDoctorWradDocs();
-                    List<ThreeLevelWardLabel> lastWardLebelList = new ArrayList<>();
-                    lastWardLebelList.add(threeLevelWardLabel);
-                    allDoctorWradDocs.get(allDoctorWradDocs.size() - 1).setThreeLevelWardLabel(lastWardLebelList);
-                    break;
+        //2020/08/20新增所有查房记录抽取:实验室检查、辅助检查、药品等
+        Pattern p = Pattern.compile("\\d+");
+        Matcher matcher = p.matcher(detailTitle);
+        if (matcher.find()) {
+            String num = matcher.group(0);
+            int n = Integer.parseInt(num);
+            ThreeLevelWardDoc doc = threeLevelWardDoc.getAllDoctorWradDocs().get(n);
+            if (doc.getThreeLevelWardLabel().size() > 0) {
+                doc.getThreeLevelWardLabel().add(threeLevelWardLabel);
+            } else {
+                threeLevelWardDoc.getAllDoctorWradDocs().get(n).setThreeLevelWardLabel(Lists.newArrayList(threeLevelWardLabel));
             }
-        } else {
-            List<ThreeLevelWardDoc> allDoctorWradDocs = threeLevelWardDoc.getAllDoctorWradDocs();
-            for (ThreeLevelWardDoc wardDoc : allDoctorWradDocs) {
-                String date = wardDoc.getStructureMap().get("查房日期");
-                if (StringUtil.isNotBlank(date) && StringUtil.isNotBlank(wardDate) && date.equals(wardDate)) {
-                    wardDoc.getThreeLevelWardLabel().add(threeLevelWardLabel);
-                    break;
-                }
+        }
+        List<ThreeLevelWardDoc> allDoctorWradDocs = threeLevelWardDoc.getAllDoctorWradDocs();
+        for (ThreeLevelWardDoc wardDoc : allDoctorWradDocs) {
+            String date = wardDoc.getStructureMap().get("查房日期");
+            if (StringUtil.isNotBlank(date) && StringUtil.isNotBlank(wardDate) && date.equals(wardDate)) {
+                wardDoc.getThreeLevelWardLabel().add(threeLevelWardLabel);
+                break;
             }
         }
     }
 
+    /**
+     * 处理主治主任首次、末次查房
+     *
+     * @param jsonObject
+     * @return
+     */
+    public ThreeLevelWardLabel putWardRoundCrfData(JSONObject jsonObject) {
+        JSONObject aiOut = loadEntity(jsonObject, entityRelationObject, outputs, content);
+        if (aiOut == null) {
+            return new ThreeLevelWardLabel();
+        }
+        String detailTitle = jsonObject.getString("detail_title");
+        EntityProcessThreeLevelWard entityProcessThreeLevelWard = new EntityProcessThreeLevelWard();
+        ThreeLevelWardLabel threeLevelWardLabel = entityProcessThreeLevelWard.extractEntity(aiOut);
+        threeLevelWardLabel.setTitle(detailTitle);
+        return entityProcessThreeLevelWard.extractEntity(aiOut);
+
+    }
+
     /**
      * 存放每条疑难病例讨论记录后第一条查房记录
      *