Переглянути джерело

Merge branch 'master' of http://192.168.2.236:10080/louhr/qc

louhr 5 роки тому
батько
коміт
4b05e566e4

+ 9 - 0
kernel/src/main/java/com/lantone/qc/kernel/analysis/QCAnalysis.java

@@ -1,5 +1,6 @@
 package com.lantone.qc.kernel.analysis;
 
+import com.google.common.collect.Maps;
 import com.lantone.qc.kernel.client.CRFServiceClient;
 import com.lantone.qc.kernel.client.SimilarityServiceClient;
 import com.lantone.qc.kernel.structure.ai.AIAnalyze;
@@ -49,6 +50,14 @@ public class QCAnalysis {
             CatalogueUtil.qcCatalogueMap.get(entry.getKey()).execute(inputInfo, outputInfo);
         }
         outputInfo.setPageData(inputInfo.getPageData());
+        Map<String, Map<String, String>> result = outputInfo.getResult();
+        Map<String, Map<String, String>> resultNew = Maps.newHashMap();
+        result.keySet().forEach(key->{
+            if (result.get(key).get("status").equals("-1")) {
+                resultNew.put(key,result.get(key));
+            }
+        });
+        outputInfo.setResult(resultNew);
         return outputInfo;
     }
 }

+ 20 - 0
kernel/src/main/java/com/lantone/qc/kernel/catalogue/QCCatalogue.java

@@ -4,6 +4,7 @@ import com.google.common.collect.Maps;
 import com.lantone.qc.kernel.util.CatalogueUtil;
 import com.lantone.qc.pub.model.InputInfo;
 import com.lantone.qc.pub.model.OutputInfo;
+import com.lantone.qc.pub.util.StringUtil;
 import lombok.extern.slf4j.Slf4j;
 
 import java.text.ParseException;
@@ -31,6 +32,7 @@ public class QCCatalogue {
         if (outputInfo.getResult().get(className) != null) {
             return;
         }
+        precondExecute(inputInfo, outputInfo);
         try {
             start(inputInfo, outputInfo);
         } catch (Exception e) {
@@ -55,4 +57,22 @@ public class QCCatalogue {
         info = "";
     }
 
+    //前置条件运行
+    private void precondExecute(InputInfo inputInfo, OutputInfo outputInfo) {
+        Map<String, String> catalogueMap = inputInfo.getInputCatalogueMap().get(className);
+        if (catalogueMap == null) {
+            return;
+        }
+        String precond = catalogueMap.get("precond");
+        if (StringUtil.isBlank(precond)) {
+            return;
+        }
+        for (String i : precond.split(",")) {
+            QCCatalogue qCCatalogue = CatalogueUtil.qcCatalogueMap.get(i);
+            if (qCCatalogue != null) {
+                qCCatalogue.execute(inputInfo, outputInfo);
+            }
+        }
+    }
+
 }

+ 40 - 0
kernel/src/main/java/com/lantone/qc/kernel/catalogue/threelevelward/THR0429.java

@@ -0,0 +1,40 @@
+package com.lantone.qc.kernel.catalogue.threelevelward;
+
+import com.lantone.qc.kernel.catalogue.QCCatalogue;
+import com.lantone.qc.pub.model.InputInfo;
+import com.lantone.qc.pub.model.OutputInfo;
+import com.lantone.qc.pub.model.doc.ThreeLevelWardDoc;
+import com.lantone.qc.pub.model.label.ThreeLevelWardLabel;
+import com.lantone.qc.pub.util.StringUtil;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * @ClassName : THR0429
+ * @Description : 疑难患者上级医师(副高及以上)查房记录无病情分析及评估
+ * @Author : 胡敬
+ * @Date: 2020-03-25 14:20
+ */
+@Component
+public class THR0429 extends QCCatalogue {
+    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
+        status = "0";
+        if (inputInfo.getThreeLevelWardDocs().size() > 0) {
+            List<ThreeLevelWardDoc> threeLevelWardDocs = inputInfo.getThreeLevelWardDocs();
+            for (ThreeLevelWardDoc threeLevelWardDoc : threeLevelWardDocs) {
+                if (threeLevelWardDoc.getThreeLevelWardLabel().getSerious() != 2) {
+                    continue;
+                }
+                ThreeLevelWardLabel threeLevelWardLabel = threeLevelWardDoc.getThreeLevelWardLabel();
+                if (threeLevelWardLabel.getDiags().size() == 0
+                        || StringUtil.isNotBlank(threeLevelWardLabel.getDiagBasisText()) && threeLevelWardLabel.getDiagBasisText().length() < 30
+                        || threeLevelWardLabel.getDiffDiag().size() == 0 && StringUtil.isBlank(threeLevelWardLabel.getDiffDiagText())
+                        || threeLevelWardLabel.getTreatmentPlans().size() == 0) {
+                    status = "-1";
+                    return;
+                }
+            }
+        }
+    }
+}

+ 40 - 0
kernel/src/main/java/com/lantone/qc/kernel/catalogue/threelevelward/THR0430.java

@@ -0,0 +1,40 @@
+package com.lantone.qc.kernel.catalogue.threelevelward;
+
+import com.lantone.qc.kernel.catalogue.QCCatalogue;
+import com.lantone.qc.pub.model.InputInfo;
+import com.lantone.qc.pub.model.OutputInfo;
+import com.lantone.qc.pub.model.doc.ThreeLevelWardDoc;
+import com.lantone.qc.pub.model.label.ThreeLevelWardLabel;
+import com.lantone.qc.pub.util.StringUtil;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * @ClassName : THR0430
+ * @Description : 抢救患者上级医师(副高及以上)查房记录无病情分析及评估
+ * @Author : 胡敬
+ * @Date: 2020-03-25 14:20
+ */
+@Component
+public class THR0430 extends QCCatalogue {
+    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
+        status = "0";
+        if (inputInfo.getThreeLevelWardDocs().size() > 0) {
+            List<ThreeLevelWardDoc> threeLevelWardDocs = inputInfo.getThreeLevelWardDocs();
+            for (ThreeLevelWardDoc threeLevelWardDoc : threeLevelWardDocs) {
+                if (threeLevelWardDoc.getThreeLevelWardLabel().getSerious() != 3) {
+                    continue;
+                }
+                ThreeLevelWardLabel threeLevelWardLabel = threeLevelWardDoc.getThreeLevelWardLabel();
+                if (threeLevelWardLabel.getDiags().size() == 0
+                        || StringUtil.isNotBlank(threeLevelWardLabel.getDiagBasisText()) && threeLevelWardLabel.getDiagBasisText().length() < 30
+                        || threeLevelWardLabel.getDiffDiag().size() == 0 && StringUtil.isBlank(threeLevelWardLabel.getDiffDiagText())
+                        || threeLevelWardLabel.getTreatmentPlans().size() == 0) {
+                    status = "-1";
+                    return;
+                }
+            }
+        }
+    }
+}

+ 36 - 0
kernel/src/main/java/com/lantone/qc/kernel/catalogue/threelevelward/THR0432.java

@@ -0,0 +1,36 @@
+package com.lantone.qc.kernel.catalogue.threelevelward;
+
+import com.lantone.qc.kernel.catalogue.QCCatalogue;
+import com.lantone.qc.pub.model.InputInfo;
+import com.lantone.qc.pub.model.OutputInfo;
+import com.lantone.qc.pub.model.doc.ThreeLevelWardDoc;
+import com.lantone.qc.pub.model.label.ThreeLevelWardLabel;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * @ClassName : THR0432
+ * @Description : 疑难患者上级医师(副高及以上)查房记录无诊疗意见
+ * @Author : 胡敬
+ * @Date: 2020-03-25 14:16
+ */
+@Component
+public class THR0432 extends QCCatalogue {
+    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
+        status = "0";
+        if (inputInfo.getThreeLevelWardDocs().size() > 0) {
+            List<ThreeLevelWardDoc> threeLevelWardDocs = inputInfo.getThreeLevelWardDocs();
+            for (ThreeLevelWardDoc threeLevelWardDoc : threeLevelWardDocs) {
+                if (threeLevelWardDoc.getThreeLevelWardLabel().getSerious() != 2) {
+                    continue;
+                }
+                ThreeLevelWardLabel threeLevelWardLabel = threeLevelWardDoc.getThreeLevelWardLabel();
+                if (threeLevelWardLabel.getTreatmentPlans().size() == 0) {
+                    status = "-1";
+                    return;
+                }
+            }
+        }
+    }
+}

+ 36 - 0
kernel/src/main/java/com/lantone/qc/kernel/catalogue/threelevelward/THR0433.java

@@ -0,0 +1,36 @@
+package com.lantone.qc.kernel.catalogue.threelevelward;
+
+import com.lantone.qc.kernel.catalogue.QCCatalogue;
+import com.lantone.qc.pub.model.InputInfo;
+import com.lantone.qc.pub.model.OutputInfo;
+import com.lantone.qc.pub.model.doc.ThreeLevelWardDoc;
+import com.lantone.qc.pub.model.label.ThreeLevelWardLabel;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * @ClassName : THR0433
+ * @Description : 抢救患者上级医师(副高及以上)查房记录无诊疗意见
+ * @Author : 胡敬
+ * @Date: 2020-03-25 14:16
+ */
+@Component
+public class THR0433 extends QCCatalogue {
+    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
+        status = "0";
+        if (inputInfo.getThreeLevelWardDocs().size() > 0) {
+            List<ThreeLevelWardDoc> threeLevelWardDocs = inputInfo.getThreeLevelWardDocs();
+            for (ThreeLevelWardDoc threeLevelWardDoc : threeLevelWardDocs) {
+                if (threeLevelWardDoc.getThreeLevelWardLabel().getSerious() != 3) {
+                    continue;
+                }
+                ThreeLevelWardLabel threeLevelWardLabel = threeLevelWardDoc.getThreeLevelWardLabel();
+                if (threeLevelWardLabel.getTreatmentPlans().size() == 0) {
+                    status = "-1";
+                    return;
+                }
+            }
+        }
+    }
+}

+ 108 - 0
kernel/src/main/java/com/lantone/qc/kernel/catalogue/threelevelward/THR0435.java

@@ -0,0 +1,108 @@
+package com.lantone.qc.kernel.catalogue.threelevelward;
+
+import com.lantone.qc.kernel.catalogue.QCCatalogue;
+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.OutputInfo;
+import com.lantone.qc.pub.model.doc.DifficultCaseDiscussDoc;
+import com.lantone.qc.pub.model.doc.ThreeLevelWardDoc;
+import com.lantone.qc.pub.util.StringUtil;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * @ClassName : THR0435
+ * @Description : 疑难患者无上级医师(副高及以上)查房记录
+ * @Author : 胡敬
+ * @Date: 2020-03-25 10:21
+ */
+@Component
+public class THR0435 extends QCCatalogue {
+    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
+        status = "0";
+        if (inputInfo.getDifficultCaseDiscussDocs().size() == 0 || inputInfo.getThreeLevelWardDocs().size() == 0) {
+            return;
+        }
+        List<DifficultCaseDiscussDoc> difficultCaseDiscussDocs = inputInfo.getDifficultCaseDiscussDocs(); //疑难病例讨论记录
+        Map<Date, Map<String, String>> dateRecord = new TreeMap<>(new Comparator<Date>() {
+            @Override
+            public int compare(Date o1, Date o2) {
+                // 降序排列
+                return o1.compareTo(o2);
+            }
+        });//按时间key排序,存放疑难病例讨论记录、查房记录
+        String recordTime = "", title = "";
+        for (DifficultCaseDiscussDoc difficultCaseDiscussDoc : difficultCaseDiscussDocs) {
+            Map<String, String> difficultCaseDiscussStructureMap = difficultCaseDiscussDoc.getStructureMap();
+            recordTime = difficultCaseDiscussStructureMap.get("讨论时间");
+            Date recordDate = StringUtil.parseDateTime(recordTime);
+            if (recordDate == null) {
+                continue;
+            }
+            dateRecord.put(recordDate, difficultCaseDiscussStructureMap);
+        }
+        dateRecord = extractDifficult(dateRecord);//24小时内记录只取第一条
+        List<ThreeLevelWardDoc> threeLevelWardDocs = inputInfo.getThreeLevelWardDocs();//查房记录
+        for (ThreeLevelWardDoc threeLevelWardDoc : threeLevelWardDocs) {
+            Map<String, String> rescueStructureMap = threeLevelWardDoc.getStructureMap();
+            recordTime = rescueStructureMap.get("查房日期");
+            title = CatalogueUtil.subTitle(rescueStructureMap.get("查房标题"));
+            Date recordDate = StringUtil.parseDateTime(recordTime);
+            if (recordDate == null || StringUtil.isBlank(title) || !title.contains(Content.director)) {//只存副高以上查房记录
+                continue;
+            }
+            dateRecord.put(recordDate, rescueStructureMap);
+        }
+
+        List<Map<String, String>> dateRecordList = new ArrayList<>(dateRecord.values());
+        //如果最后一条是疑难病例讨论记录,则之后肯定没有查房记录
+        if (dateRecordList.get(dateRecordList.size() - 1).containsKey("抢救时间")) {
+            status = "-1";
+            return;
+        }
+        for (int i = 0; i < dateRecordList.size(); i++) {
+            if (i != dateRecordList.size() - 1) {
+                //当前为疑难病例讨论记录
+                if (!dateRecordList.get(i).containsKey("讨论时间")) {
+                    continue;
+                }
+                //疑难病例讨论记录下一条不是查房记录则报错
+                if (!dateRecordList.get(i + 1).containsKey("查房日期")) {
+                    status = "-1";
+                    return;
+                }
+            }
+        }
+    }
+
+    /**
+     * 抽取24小时内第一条记录
+     *
+     * @param dateRecord
+     */
+    private Map<Date, Map<String, String>> extractDifficult(Map<Date, Map<String, String>> dateRecord) {
+        Map<Date, Map<String, String>> record = new TreeMap<>(new Comparator<Date>() {
+            @Override
+            public int compare(Date o1, Date o2) {
+                // 降序排列
+                return o1.compareTo(o2);
+            }
+        });
+        Date lastDate = null;
+        for (Map.Entry<Date, Map<String, String>> dateRecordEntry : dateRecord.entrySet()) {
+            Date difficultCaseDiscussDate = dateRecordEntry.getKey();
+            if (lastDate == null || CatalogueUtil.compareTime(lastDate, difficultCaseDiscussDate, (long) (24 * 60))) {
+                lastDate = difficultCaseDiscussDate;
+                record.put(difficultCaseDiscussDate, dateRecordEntry.getValue());
+            }
+        }
+        return record;
+    }
+}

+ 108 - 0
kernel/src/main/java/com/lantone/qc/kernel/catalogue/threelevelward/THR0436.java

@@ -0,0 +1,108 @@
+package com.lantone.qc.kernel.catalogue.threelevelward;
+
+import com.lantone.qc.kernel.catalogue.QCCatalogue;
+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.OutputInfo;
+import com.lantone.qc.pub.model.doc.RescueDoc;
+import com.lantone.qc.pub.model.doc.ThreeLevelWardDoc;
+import com.lantone.qc.pub.util.StringUtil;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * @ClassName : THR0436
+ * @Description : 抢救患者无上级医师(副高及以上)查房记录
+ * @Author : 胡敬
+ * @Date: 2020-03-24 19:35
+ */
+@Component
+public class THR0436 extends QCCatalogue {
+    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
+        status = "0";
+        if (inputInfo.getRescueDocs().size() == 0 || inputInfo.getThreeLevelWardDocs().size() == 0) {
+            return;
+        }
+        List<RescueDoc> rescueDocs = inputInfo.getRescueDocs(); //抢救记录
+        Map<Date, Map<String, String>> dateRecord = new TreeMap<>(new Comparator<Date>() {
+            @Override
+            public int compare(Date o1, Date o2) {
+                // 降序排列
+                return o1.compareTo(o2);
+            }
+        });//按时间key排序,存放抢救记录、查房记录
+        String recordTime = "", title = "";
+        for (RescueDoc rescueDoc : rescueDocs) {
+            Map<String, String> rescueStructureMap = rescueDoc.getStructureMap();
+            recordTime = rescueStructureMap.get("抢救时间");
+            Date recordDate = StringUtil.parseDateTime(recordTime);
+            if (recordDate == null) {
+                continue;
+            }
+            dateRecord.put(recordDate, rescueStructureMap);
+        }
+        dateRecord = extractRescue(dateRecord);//24小时内记录只取第一条
+        List<ThreeLevelWardDoc> threeLevelWardDocs = inputInfo.getThreeLevelWardDocs();//查房记录
+        for (ThreeLevelWardDoc threeLevelWardDoc : threeLevelWardDocs) {
+            Map<String, String> rescueStructureMap = threeLevelWardDoc.getStructureMap();
+            recordTime = rescueStructureMap.get("查房日期");
+            title = CatalogueUtil.subTitle(rescueStructureMap.get("查房标题"));
+            Date recordDate = StringUtil.parseDateTime(recordTime);
+            if (recordDate == null || StringUtil.isBlank(title) || !title.contains(Content.director)) {//只存副高以上查房记录
+                continue;
+            }
+            dateRecord.put(recordDate, rescueStructureMap);
+        }
+
+        List<Map<String, String>> dateRecordList = new ArrayList<>(dateRecord.values());
+        //如果最后一条是抢救记录,则之后肯定没有查房记录
+        if (dateRecordList.get(dateRecordList.size() - 1).containsKey("抢救时间")) {
+            status = "-1";
+            return;
+        }
+        for (int i = 0; i < dateRecordList.size(); i++) {
+            if (i != dateRecordList.size() - 1) {
+                //当前为抢救记录
+                if (!dateRecordList.get(i).containsKey("抢救时间")) {
+                    continue;
+                }
+                //抢救记录下一条不是查房记录则报错
+                if (!dateRecordList.get(i + 1).containsKey("查房日期")) {
+                    status = "-1";
+                    return;
+                }
+            }
+        }
+    }
+
+    /**
+     * 抽取24小时内第一条记录
+     *
+     * @param dateRecord
+     */
+    private Map<Date, Map<String, String>> extractRescue(Map<Date, Map<String, String>> dateRecord) {
+        Map<Date, Map<String, String>> record = new TreeMap<>(new Comparator<Date>() {
+            @Override
+            public int compare(Date o1, Date o2) {
+                // 降序排列
+                return o1.compareTo(o2);
+            }
+        });
+        Date lastDate = null;
+        for (Map.Entry<Date, Map<String, String>> dateRecordEntry : dateRecord.entrySet()) {
+            Date rescueDate = dateRecordEntry.getKey();
+            if (lastDate == null || CatalogueUtil.compareTime(lastDate, rescueDate, (long) (24 * 60))) {
+                lastDate = rescueDate;
+                record.put(rescueDate, dateRecordEntry.getValue());
+            }
+        }
+        return record;
+    }
+}

+ 202 - 3
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/ThreeLevelWardAI.java

@@ -7,12 +7,20 @@ import com.lantone.qc.kernel.structure.ai.process.EntityProcessThreeLevelWard;
 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.DifficultCaseDiscussDoc;
+import com.lantone.qc.pub.model.doc.RescueDoc;
 import com.lantone.qc.pub.model.doc.ThreeLevelWardDoc;
 import com.lantone.qc.pub.model.label.ThreeLevelWardLabel;
+import com.lantone.qc.pub.util.ListUtil;
+import com.lantone.qc.pub.util.StringUtil;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeMap;
 
 /**
  * @ClassName : ThreeLevelWardAI
@@ -32,6 +40,9 @@ public class ThreeLevelWardAI extends ModelAI {
     public void medrec(InputInfo inputInfo, CRFServiceClient crfServiceClient) {
         JSONArray crfContent = new JSONArray();
         List<ThreeLevelWardDoc> threeLevelWardDocs = inputInfo.getThreeLevelWardDocs();
+        if (threeLevelWardDocs.size() == 0) {
+            return;
+        }
         //主治/主任首次查房记录
         Map<String, Map<String, String>> firstWardRecord = CatalogueUtil.extractWardRecord(threeLevelWardDocs);
         //主治医师首次查房记录
@@ -43,16 +54,52 @@ public class ThreeLevelWardAI extends ModelAI {
             putContent(crfContent, medicalTextType.get(0), firstWardRecord.get(Content.director).get("病情记录"), Content.director);
         }
 
+        List<Map<String, String>> directorDifficultRecord = new ArrayList<>();
+        //疑难患者副高及以上查房记录
+        if (inputInfo.getDifficultCaseDiscussDocs().size() > 0) {
+            directorDifficultRecord = putDirectorDifficultRecord(inputInfo, threeLevelWardDocs);
+            for (int i = 0; i < directorDifficultRecord.size(); i++) {
+                putContent(crfContent, medicalTextType.get(0), directorDifficultRecord.get(i).get("病情记录"), Content.difficultPatients + i);
+            }
+        }
+        List<Map<String, String>> directorRescueRecord = new ArrayList<>();
+        //抢救患者副高及以上查房记录
+        if (inputInfo.getRescueDocs().size() > 0) {
+            directorRescueRecord = putDirectorRescueRecord(inputInfo, threeLevelWardDocs);
+            for (int i = 0; i < directorRescueRecord.size(); i++) {
+                putContent(crfContent, medicalTextType.get(0), directorRescueRecord.get(i).get("病情记录"), Content.rescuingPatients + i);
+            }
+        }
+
         JSONObject midData = loadAI(crfContent, crfServiceClient);//crf返回数据
 
         //主治医师首次查房记录模型输出
         if (midData.get(Content.indications) != null) {
-            putWardRoundCrfData(midData.getJSONObject(Content.indications), inputInfo, Content.indications);//查房记录
+            putWardRoundCrfData(midData.getJSONObject(Content.indications), inputInfo, Content.indications, 0);//查房记录
         }
         //主任医师首次查房记录模型输出
         if (midData.get(Content.director) != null) {
-            putWardRoundCrfData(midData.getJSONObject(Content.director), inputInfo, Content.indications);//查房记录
+            putWardRoundCrfData(midData.getJSONObject(Content.director), inputInfo, Content.director, 0);//查房记录
+        }
+        //疑难患者副高及以上查房记录模型输出
+        if (inputInfo.getDifficultCaseDiscussDocs().size() > 0 && ListUtil.isNotEmpty(directorDifficultRecord)) {
+            for (int i = 0; i < directorDifficultRecord.size(); i++) {
+                if (midData.get(Content.difficultPatients + i) == null) {
+                    continue;
+                }
+                putWardRoundCrfData(midData.getJSONObject(Content.difficultPatients + i), inputInfo, Content.director, 2);//查房记录
+            }
         }
+        //抢救患者副高及以上查房记录模型输出
+        if (inputInfo.getRescueDocs().size() > 0 && ListUtil.isNotEmpty(directorDifficultRecord)) {
+            for (int i = 0; i < directorDifficultRecord.size(); i++) {
+                if (midData.get(Content.rescuingPatients + i) == null) {
+                    continue;
+                }
+                putWardRoundCrfData(midData.getJSONObject(Content.difficultPatients + i), inputInfo, Content.director, 3);//查房记录
+            }
+        }
+
     }
 
     /**
@@ -61,15 +108,167 @@ public class ThreeLevelWardAI extends ModelAI {
      * @param jsonObject
      * @param inputInfo
      */
-    public void putWardRoundCrfData(JSONObject jsonObject, InputInfo inputInfo, String detailTitle) {
+    public void putWardRoundCrfData(JSONObject jsonObject, InputInfo inputInfo, String detailTitle, int serious) {
         JSONObject aiOut = loadEntity(jsonObject, entityRelationObject, outputs, content);
         //使用现病史结构来处理病历特点
         EntityProcessThreeLevelWard entityProcessThreeLevelWard = new EntityProcessThreeLevelWard();
         ThreeLevelWardLabel threeLevelWardLabel = entityProcessThreeLevelWard.extractEntity(aiOut);
         threeLevelWardLabel.setTitle(detailTitle);
+        threeLevelWardLabel.setSerious(serious);
         ThreeLevelWardDoc threeLevelWardDoc = new ThreeLevelWardDoc();
         threeLevelWardDoc.setThreeLevelWardLabel(threeLevelWardLabel);
         //临床表现
         inputInfo.getThreeLevelWardDocs().add(threeLevelWardDoc);
     }
+
+    /**
+     * 存放每条疑难病例讨论记录后第一条查房记录
+     *
+     * @param inputInfo
+     * @param threeLevelWardDocs
+     * @return
+     */
+    private List<Map<String, String>> putDirectorDifficultRecord(InputInfo inputInfo, List<ThreeLevelWardDoc> threeLevelWardDocs) {
+        List<Map<String, String>> record = new ArrayList<>();
+        List<DifficultCaseDiscussDoc> difficultCaseDiscussDocs = inputInfo.getDifficultCaseDiscussDocs(); //疑难病例讨论记录
+        Map<Date, Map<String, String>> dateRecord = new TreeMap<>(new Comparator<Date>() {
+            @Override
+            public int compare(Date o1, Date o2) {
+                // 降序排列
+                return o1.compareTo(o2);
+            }
+        });//按时间key排序,存放抢救记录、查房记录
+        String recordTime = "", title = "";
+        for (DifficultCaseDiscussDoc difficultCaseDiscussDoc : difficultCaseDiscussDocs) {
+            Map<String, String> difficultCaseDiscussStructureMap = difficultCaseDiscussDoc.getStructureMap();
+            recordTime = difficultCaseDiscussStructureMap.get("讨论时间");
+            Date recordDate = StringUtil.parseDateTime(recordTime);
+            if (recordDate == null) {
+                continue;
+            }
+            dateRecord.put(recordDate, difficultCaseDiscussStructureMap);
+        }
+        dateRecord = extractUnique(dateRecord);
+        for (ThreeLevelWardDoc threeLevelWardDoc : threeLevelWardDocs) {
+            Map<String, String> rescueStructureMap = threeLevelWardDoc.getStructureMap();
+            recordTime = rescueStructureMap.get("查房日期");
+            title = CatalogueUtil.subTitle(rescueStructureMap.get("查房标题"));
+            Date recordDate = StringUtil.parseDateTime(recordTime);
+            if (recordDate == null || StringUtil.isBlank(title) || !title.contains(Content.director)) {//只存副高以上查房记录) {
+                continue;
+            }
+            dateRecord.put(recordDate, rescueStructureMap);
+        }
+        List<Map<String, String>> dateRecordList = new ArrayList<>(dateRecord.values());
+        //如果最后一条是疑难病例讨论记录,则之后肯定没有查房记录
+        if (dateRecordList.get(dateRecordList.size() - 1).containsKey("讨论时间")) {
+            record = new ArrayList<>();
+            return record;
+        }
+        for (int i = 0; i < dateRecordList.size(); i++) {
+            if (i != dateRecordList.size() - 1) {
+                //当前为疑难病例讨论记录
+                if (!dateRecordList.get(i).containsKey("抢救时间")) {
+                    continue;
+                }
+                //疑难病例讨论记录下一条不是查房记录则清空list
+                if (!dateRecordList.get(i + 1).containsKey("查房日期")) {
+                    record = new ArrayList<>();
+                    break;
+                } else {
+                    //疑难病例讨论记录下一条是查房记录,添加进list(这条疑难病例讨论记录后全部查房记录的第一条)
+                    record.add(dateRecordList.get(i + 1));
+                }
+            }
+        }
+        return record;
+    }
+
+    /**
+     * 存放每条抢救记录后第一条
+     *
+     * @param inputInfo
+     * @param threeLevelWardDocs
+     * @return
+     */
+    private List<Map<String, String>> putDirectorRescueRecord(InputInfo inputInfo, List<ThreeLevelWardDoc> threeLevelWardDocs) {
+        List<Map<String, String>> record = new ArrayList<>();
+        List<RescueDoc> rescueDocs = inputInfo.getRescueDocs(); //抢救记录
+        Map<Date, Map<String, String>> dateRecord = new TreeMap<>(new Comparator<Date>() {
+
+            @Override
+            public int compare(Date o1, Date o2) {
+                // 降序排列
+                return o1.compareTo(o2);
+            }
+        });//按时间key排序,存放抢救记录、查房记录
+        String recordTime = "", title = "";
+        for (RescueDoc rescueDoc : rescueDocs) {
+            Map<String, String> rescueStructureMap = rescueDoc.getStructureMap();
+            recordTime = rescueStructureMap.get("抢救时间");
+            Date recordDate = StringUtil.parseDateTime(recordTime);
+            if (recordDate == null) {
+                continue;
+            }
+            dateRecord.put(recordDate, rescueStructureMap);
+        }
+        dateRecord = extractUnique(dateRecord);
+        for (ThreeLevelWardDoc threeLevelWardDoc : threeLevelWardDocs) {
+            Map<String, String> rescueStructureMap = threeLevelWardDoc.getStructureMap();
+            recordTime = rescueStructureMap.get("查房日期");
+            title = CatalogueUtil.subTitle(rescueStructureMap.get("查房标题"));
+            Date recordDate = StringUtil.parseDateTime(recordTime);
+            if (recordDate == null || StringUtil.isBlank(title) || !title.contains(Content.director)) {//只存副高以上查房记录) {
+                continue;
+            }
+            dateRecord.put(recordDate, rescueStructureMap);
+        }
+        List<Map<String, String>> dateRecordList = new ArrayList<>(dateRecord.values());
+        //如果最后一条是抢救记录,则之后肯定没有查房记录
+        if (dateRecordList.get(dateRecordList.size() - 1).containsKey("抢救时间")) {
+            record = new ArrayList<>();
+            return record;
+        }
+        for (int i = 0; i < dateRecordList.size(); i++) {
+            if (i != dateRecordList.size() - 1) {
+                //当前为抢救记录
+                if (!dateRecordList.get(i).containsKey("抢救时间")) {
+                    continue;
+                }
+                //抢救记录下一条不是查房记录则清空list
+                if (!dateRecordList.get(i + 1).containsKey("查房日期")) {
+                    record = new ArrayList<>();
+                    break;
+                } else {
+                    //抢救记录下一条是查房记录,添加进list(抢救记录后全部查房记录的第一条)
+                    record.add(dateRecordList.get(i + 1));
+                }
+            }
+        }
+        return record;
+    }
+
+    /**
+     * 抽取24小时内第一条记录
+     *
+     * @param dateRecord
+     */
+    private Map<Date, Map<String, String>> extractUnique(Map<Date, Map<String, String>> dateRecord) {
+        Map<Date, Map<String, String>> record = new TreeMap<>(new Comparator<Date>() {
+            @Override
+            public int compare(Date o1, Date o2) {
+                // 降序排列
+                return o1.compareTo(o2);
+            }
+        });
+        Date lastDate = null;
+        for (Map.Entry<Date, Map<String, String>> dateRecordEntry : dateRecord.entrySet()) {
+            Date date = dateRecordEntry.getKey();
+            if (lastDate == null || CatalogueUtil.compareTime(lastDate, date, (long) (24 * 60))) {
+                lastDate = date;
+                record.put(date, dateRecordEntry.getValue());
+            }
+        }
+        return record;
+    }
 }

+ 1 - 1
kernel/src/main/java/com/lantone/qc/kernel/util/CatalogueUtil.java

@@ -267,7 +267,7 @@ public class CatalogueUtil {
      * @return
      */
     public static String subTitle(String srcText) {
-        if (srcText.contains("代")) {
+        if (StringUtil.isNotBlank(srcText) && srcText.contains("代")) {
             srcText = srcText.substring(srcText.indexOf("代") + 1);
         }
         return srcText;

+ 4 - 0
public/src/main/java/com/lantone/qc/pub/Content.java

@@ -199,6 +199,10 @@ public class Content {
     public static final String indications="主治";
     public static final String director="主任";
 
+    public static final String criticallyIllPatients="危重患者";
+    public static final String difficultPatients="疑难患者";
+    public static final String rescuingPatients="抢救患者";
+
     public static final String operative_information="手术信息";
     public static final String operative_code="手术编码";
     public static final String operative_date="手术日期";

+ 1 - 0
public/src/main/java/com/lantone/qc/pub/model/label/ThreeLevelWardLabel.java

@@ -19,6 +19,7 @@ import java.util.List;
 @Getter
 @Setter
 public class ThreeLevelWardLabel {
+    int serious = 0;    //不严重患者:0,危重患者:1,疑难患者:2,抢救患者:3
     String title;   //医师职称
     List<Clinical> clinicals = new ArrayList<>();   //病史(临床表现)
     List<Sign> signs = new ArrayList<>();   //查体

+ 25 - 16
trans/src/main/java/com/lantone/qc/trans/changx/ChangxBeHospitalizedDocTrans.java

@@ -1,5 +1,6 @@
 package com.lantone.qc.trans.changx;
 
+import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.lantone.qc.pub.model.doc.BeHospitalizedDoc;
 import com.lantone.qc.pub.model.keys.ModelStandardKeys;
@@ -34,25 +35,33 @@ public class ChangxBeHospitalizedDocTrans extends ModelDocTrans {
         int index3 = content.indexOf("辅助检查");
         content = content.substring(0, index3) + "\n" + content.substring(index3);
 
-        Map<String, String> structureMap =
-                Preproc.extract_doc_pub(
-                        false,
-                        ListUtil.isEmpty(medrecVo.getLabel()) ? ModelStandardKeys.beHospitalized : medrecVo.getLabel(),
-                        content
-                );
-
-        Map<String, Object> pageData = Maps.newHashMap();
-        structureMap.keySet().forEach(i -> {
-            pageData.put(i, structureMap.get(i));
+        List<String> targetTitles = Lists.newArrayList();
+        List<String> sourceTitles = ListUtil.isEmpty(medrecVo.getLabel()) ? ModelStandardKeys.beHospitalized : medrecVo.getLabel();
+        sourceTitles.forEach(sourceTitle -> {
+            String targetTitle = "";
+            for (int index = 0; index < sourceTitle.length(); index++) {
+                if (index == sourceTitle.length() - 1) {
+                    targetTitle += sourceTitle.substring(index, index + 1);
+                } else {
+                    targetTitle += sourceTitle.substring(index, index + 1) + "[\\s]*";
+                }
+            }
+            targetTitles.add(targetTitle);
         });
 
-        structureMap.put("体格检查", structureMap.get("体格检查(一)"));
-        structureMap.put("专科体格检查", structureMap.get("体格检查(二)"));
-        structureMap.remove("体格检查(一)");
-        structureMap.remove("体格检查(二)");
+        Map<String, String> sourceMap = Preproc.extract_doc_pub(false, targetTitles, content);
+        Map<String, String> targetMap = Maps.newHashMap();
+        for (String key : sourceMap.keySet()) {
+            targetMap.put(key.replaceAll("\\s", ""), sourceMap.get(key));
+        }
+
+        targetMap.put("体格检查", targetMap.get("体格检查(一)"));
+        targetMap.put("专科体格检查", targetMap.get("体格检查(二)"));
+        targetMap.remove("体格检查(一)");
+        targetMap.remove("体格检查(二)");
 
-        BeHospitalizedDoc beHospitalizedDoc = ModelDocGenerate.beHospitalizedDocGen(structureMap);
-        beHospitalizedDoc.setPageData(pageData);
+        BeHospitalizedDoc beHospitalizedDoc = ModelDocGenerate.beHospitalizedDocGen(targetMap);
+        beHospitalizedDoc.setPageData((Map) sourceMap);
 
         return beHospitalizedDoc;
     }