|
@@ -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;
|
|
|
+ }
|
|
|
}
|