|
@@ -1,20 +1,24 @@
|
|
|
package com.lantone.structure.facade;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONException;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.lantone.common.util.FastJsonUtils;
|
|
|
import com.lantone.structure.ai.AIAnalyze;
|
|
|
import com.lantone.structure.client.CRFServiceClient;
|
|
|
import com.lantone.structure.client.SimilarityServiceClient;
|
|
|
import com.lantone.structure.dto.AnalysisDTO;
|
|
|
import com.lantone.structure.model.InputInfo;
|
|
|
-import com.lantone.structure.model.doc.BeHospitalizedDoc;
|
|
|
-import com.lantone.structure.model.label.PresentLabel;
|
|
|
+import com.lantone.structure.model.doc.*;
|
|
|
import com.lantone.structure.vo.AnalysisVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @Description:
|
|
@@ -31,19 +35,39 @@ public class StructureFacade {
|
|
|
|
|
|
|
|
|
public AnalysisDTO analysis(AnalysisVO analysisVO) {
|
|
|
- if (!analysisVO.getType().equals("现病史")) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- AnalysisDTO analysisDTO = new AnalysisDTO();
|
|
|
InputInfo inputInfo = new InputInfo();
|
|
|
-
|
|
|
- BeHospitalizedDoc beHospitalizedDoc = new BeHospitalizedDoc();
|
|
|
-
|
|
|
- PresentLabel presentLabel = new PresentLabel();
|
|
|
- presentLabel.setText(analysisVO.getText());
|
|
|
- beHospitalizedDoc.setPresentLabel(presentLabel);
|
|
|
-
|
|
|
- inputInfo.setBeHospitalizedDoc(beHospitalizedDoc);
|
|
|
+ switch (analysisVO.getType()) {
|
|
|
+ case "剖宫产手术":
|
|
|
+ List<CaesareanSectionDoc> caesareanSectionDocList = new ArrayList<>();
|
|
|
+ CaesareanSectionDoc caesareanSectionDoc = new CaesareanSectionDoc();
|
|
|
+ caesareanSectionDoc.setText(analysisVO.getText());
|
|
|
+ caesareanSectionDocList.add(caesareanSectionDoc);
|
|
|
+ inputInfo.setCaesareanSectionDocs(caesareanSectionDocList);
|
|
|
+ break;
|
|
|
+ case "输血记录":
|
|
|
+ List<ClinicalBloodDoc> clinicalBloodDocList = new ArrayList<>();
|
|
|
+ ClinicalBloodDoc clinicalBloodDoc = new ClinicalBloodDoc();
|
|
|
+ clinicalBloodDoc.setText(analysisVO.getText());
|
|
|
+ clinicalBloodDocList.add(clinicalBloodDoc);
|
|
|
+ inputInfo.setClinicalBloodDocs(clinicalBloodDocList);
|
|
|
+ break;
|
|
|
+ case "抢救记录":
|
|
|
+ List<RescueDoc> rescueDocList = new ArrayList<>();
|
|
|
+ RescueDoc rescueDoc = new RescueDoc();
|
|
|
+ rescueDoc.setText(analysisVO.getText());
|
|
|
+ rescueDocList.add(rescueDoc);
|
|
|
+ inputInfo.setRescueDocs(rescueDocList);
|
|
|
+ break;
|
|
|
+ case "阶段小结":
|
|
|
+ List<StagesSummaryDoc> stagesSummaryDocList = new ArrayList<>();
|
|
|
+ StagesSummaryDoc stagesSummaryDoc = new StagesSummaryDoc();
|
|
|
+ stagesSummaryDoc.setText(analysisVO.getText());
|
|
|
+ stagesSummaryDocList.add(stagesSummaryDoc);
|
|
|
+ inputInfo.setStagesSummaryDocs(stagesSummaryDocList);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
AIAnalyze aiAnalyze = new AIAnalyze(crfServiceClient, similarityServiceClient);
|
|
|
try {
|
|
@@ -52,15 +76,170 @@ public class StructureFacade {
|
|
|
log.error("AI模型执行错误:" + e.getMessage(), e);
|
|
|
}
|
|
|
|
|
|
+ //存储映射
|
|
|
+ AnalysisDTO analysisDTO = saveMap(inputInfo, analysisVO);
|
|
|
+ return analysisDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ public AnalysisDTO saveMap(InputInfo inputInfo, AnalysisVO analysisVO) {
|
|
|
Map<String, Object> map = Maps.newHashMap();
|
|
|
- Map<String, Object> jsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(inputInfo.getBeHospitalizedDoc().getPresentLabel()));
|
|
|
- jsonMap.remove("text");
|
|
|
- jsonMap.remove("aiText");
|
|
|
- jsonMap.remove("crfLabel");
|
|
|
- jsonMap.remove("crfOutput");
|
|
|
- map.put("现病史", jsonMap);
|
|
|
+ Map<String, String> retMap = new HashMap<>();
|
|
|
+ AnalysisDTO analysisDTO = new AnalysisDTO();
|
|
|
+ Map<String, String> keyContrastMap = Maps.newHashMap();
|
|
|
+ if (analysisVO.getType().equals("剖宫产手术")) {
|
|
|
+ Map<String, Object> jsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(inputInfo.getCaesareanSectionDocs().get(0).getCaesareanSectionLabel()));
|
|
|
+ //添加keyContrastMap数据
|
|
|
+ AddKeyValue(keyContrastMap, sectionKeyContrasts);
|
|
|
+ mapKeyContrastCommon(jsonMap, keyContrastMap, retMap);
|
|
|
+ } else if (analysisVO.getType().equals("输血记录")) {
|
|
|
+ Map<String, Object> jsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(inputInfo.getClinicalBloodDocs().get(0).getClinicalBloodLabel()));
|
|
|
+ mapKeyContrastCommon(jsonMap, keyContrastMap, retMap);
|
|
|
+ } else if (analysisVO.getType().equals("抢救记录")) {
|
|
|
+ Map<String, Object> jsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(inputInfo.getRescueDocs().get(0).getRescueLabel()));
|
|
|
+ mapKeyContrastCommon(jsonMap, keyContrastMap, retMap);
|
|
|
+ } else if (analysisVO.getType().equals("阶段小结")) {
|
|
|
+ Map<String, Object> jsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(inputInfo.getStagesSummaryDocs().get(0).getStagesSummaryLabel()));
|
|
|
+ mapKeyContrastCommon(jsonMap, keyContrastMap, retMap);
|
|
|
+ }
|
|
|
+ map.put(analysisVO.getType(), retMap);
|
|
|
analysisDTO.setResult(map);
|
|
|
+
|
|
|
return analysisDTO;
|
|
|
}
|
|
|
|
|
|
+ public void AddKeyValue(Map<String, String> keyContrastMap, List<String> keyContrasts) {
|
|
|
+ for (String keyContrast : keyContrasts) {
|
|
|
+ String[] split = keyContrast.split("=");
|
|
|
+ keyContrastMap.put(split[0], split[1]);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> sectionKeyContrasts = Lists.newArrayList(
|
|
|
+ "bloodPressure=血压情况",
|
|
|
+ "caputSuccedaneum=产瘤",
|
|
|
+ "drugs=手术用药名称",
|
|
|
+ "puerperaCondition=手术时产妇情况",
|
|
|
+ "amnioticFluid=羊水",
|
|
|
+ "diagnosis=诊断名称",
|
|
|
+ "anesthesiaMethod=麻醉方法",
|
|
|
+ "transfusion=输血成分",
|
|
|
+ "newborn=新生儿",
|
|
|
+ "fluidInfusion=补液",
|
|
|
+ "uCAgents=宫缩剂名称",
|
|
|
+ "uterineWallSutures=子宫壁缝合情况",
|
|
|
+ "childbirthConditions=胎盘娩出情况",
|
|
|
+ "uterusConditions=子宫情况",
|
|
|
+ "childbirthWay=胎儿娩出方式",
|
|
|
+ "cordAroundNeck=脐带绕颈",
|
|
|
+ "apgarScores=Apgar评分",
|
|
|
+ "placenta=胎盘",
|
|
|
+ "uterineCavityDispose=宫腔探查处理情况",
|
|
|
+ "cordAroundBody=脐带绕身",
|
|
|
+ "umbilicalCord=脐带",
|
|
|
+ "uterineCavityAbnormity=宫腔探查异常情况描述",
|
|
|
+ "hemorrhage=术中出血",
|
|
|
+ "amnioticFluidCharacter=羊水性状",
|
|
|
+ "quantity=量",
|
|
|
+ "volume=体积",
|
|
|
+ "weight=重量",
|
|
|
+ "extent=长度",
|
|
|
+ "negative=否定",
|
|
|
+ "cylinderNumber=圈数",
|
|
|
+ "usageWardRound=宫缩剂用法",
|
|
|
+ "consumption=宫缩剂用量",
|
|
|
+ "score=分数",
|
|
|
+ "caputSuccedaneumPart=产瘤部位"
|
|
|
+ );
|
|
|
+
|
|
|
+ private List<String> bloodKeyContrasts = Lists.newArrayList(
|
|
|
+ "当前诊断=死亡诊断",
|
|
|
+ "死亡日期=死亡时间",
|
|
|
+ "初步诊断=入院诊断",
|
|
|
+ "诊治经过=诊疗经过",
|
|
|
+ "本人姓名=姓名",
|
|
|
+ "现病史- 发病情况=发病情况",
|
|
|
+ "病历日期=记录时间",
|
|
|
+ "医生=记录医师"
|
|
|
+ );
|
|
|
+
|
|
|
+ private List<String> rescueContrasts = Lists.newArrayList(
|
|
|
+
|
|
|
+ );
|
|
|
+
|
|
|
+ private List<String> stagesContrasts = Lists.newArrayList(
|
|
|
+
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ public void mapKeyContrastCommon(Map sourceMap, Map<String, String> keyContrastMap, Map<String, String> retMap) {
|
|
|
+ Map<String, Object> sourceMap_ = copyMap(sourceMap);
|
|
|
+ for (Map.Entry<String, Object> dateEntry : sourceMap_.entrySet()) {
|
|
|
+ try {
|
|
|
+ Object object = JSON.parse(FastJsonUtils.getBeanToJson(dateEntry.getValue()));
|
|
|
+ if (object instanceof JSONObject) {
|
|
|
+ Map<String, Object> firstJsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(dateEntry.getValue()));
|
|
|
+ if (firstJsonMap.size() == 1) {
|
|
|
+ String key = keyContrastMap.get(dateEntry.getKey());
|
|
|
+ retMap.put(key, (String) firstJsonMap.get("name"));
|
|
|
+ } else {
|
|
|
+ for (Map.Entry<String, Object> firstDateEntry : firstJsonMap.entrySet()) {
|
|
|
+ Map<String, Object> jsonToMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(firstDateEntry.getValue()));
|
|
|
+ if (jsonToMap.size() == 1) {
|
|
|
+ String childKey = keyContrastMap.get(firstDateEntry.getKey());
|
|
|
+ if (retMap.containsKey(keyContrastMap.get(firstDateEntry.getKey()))) {
|
|
|
+ retMap.put(keyContrastMap.get(dateEntry.getKey()) + childKey, (String) jsonToMap.get("name"));
|
|
|
+ } else {
|
|
|
+ retMap.put(childKey, (String) jsonToMap.get("name"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (object instanceof JSONArray) {
|
|
|
+ List<Map<String, Object>> jsonToListMap = FastJsonUtils.getJsonToListMap(FastJsonUtils.getBeanToJson(dateEntry.getValue()));
|
|
|
+ int count = 1;
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ for (Map<String, Object> mapList : jsonToListMap) {
|
|
|
+ for (Map.Entry<String, Object> firstDateEntry : mapList.entrySet()) {
|
|
|
+ if (firstDateEntry.getKey().equals("name")) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ Map<String, Object> jsonToMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(firstDateEntry.getValue()));
|
|
|
+ if (jsonToMap.size() == 1) {
|
|
|
+ String childKey = keyContrastMap.get(firstDateEntry.getKey());
|
|
|
+ if (retMap.containsKey(keyContrastMap.get(firstDateEntry.getKey()))) {
|
|
|
+ retMap.put(keyContrastMap.get(dateEntry.getKey()) + childKey, (String) jsonToMap.get("name"));
|
|
|
+ } else {
|
|
|
+ retMap.put(childKey, (String) jsonToMap.get("name"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sb.append((count++) + "." + mapList.get("name"));
|
|
|
+ }
|
|
|
+ retMap.put(keyContrastMap.get(dateEntry.getKey()), sb.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (JSONException e) {
|
|
|
+ log.error(keyContrastMap.get(dateEntry.getKey()) + "json为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 复制一个map
|
|
|
+ *
|
|
|
+ * @param map
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static Map<String, Object> copyMap(Map<String, Object> map) {
|
|
|
+ if (map == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Map<String, Object> retMap = Maps.newHashMap();
|
|
|
+ map.keySet().forEach(key -> {
|
|
|
+ retMap.put(key, map.get(key));
|
|
|
+ });
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
}
|