|
@@ -1,28 +1,18 @@
|
|
|
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.google.common.collect.ObjectArrays;
|
|
|
-import com.lantone.common.util.FastJsonUtils;
|
|
|
-import com.lantone.common.util.StringUtil;
|
|
|
-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.*;
|
|
|
+import com.lantone.structure.facade.tran.CesareanSectionTran;
|
|
|
+import com.lantone.structure.facade.tran.ClinicalBloodTran;
|
|
|
+import com.lantone.structure.facade.tran.RescueTran;
|
|
|
+import com.lantone.structure.facade.tran.StagesSummaryTran;
|
|
|
+import com.lantone.structure.facade.tran.TargetTran;
|
|
|
import com.lantone.structure.vo.AnalysisVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.util.*;
|
|
|
-
|
|
|
/**
|
|
|
* @Description:
|
|
|
* @author: rengb
|
|
@@ -38,347 +28,26 @@ public class StructureFacade {
|
|
|
|
|
|
|
|
|
public AnalysisDTO analysis(AnalysisVO analysisVO) {
|
|
|
- InputInfo inputInfo = new InputInfo();
|
|
|
+ AnalysisDTO analysisDTO = new AnalysisDTO();
|
|
|
+ TargetTran targetTran = null;
|
|
|
switch (analysisVO.getType()) {
|
|
|
case "剖宫产手术":
|
|
|
- List<CaesareanSectionDoc> caesareanSectionDocList = new ArrayList<>();
|
|
|
- CaesareanSectionDoc caesareanSectionDoc = new CaesareanSectionDoc();
|
|
|
- caesareanSectionDoc.setText(analysisVO.getText());
|
|
|
- caesareanSectionDocList.add(caesareanSectionDoc);
|
|
|
- inputInfo.setCaesareanSectionDocs(caesareanSectionDocList);
|
|
|
+ targetTran = new CesareanSectionTran();
|
|
|
break;
|
|
|
case "输血记录":
|
|
|
- List<ClinicalBloodDoc> clinicalBloodDocList = new ArrayList<>();
|
|
|
- ClinicalBloodDoc clinicalBloodDoc = new ClinicalBloodDoc();
|
|
|
- clinicalBloodDoc.setText(analysisVO.getText());
|
|
|
- clinicalBloodDocList.add(clinicalBloodDoc);
|
|
|
- inputInfo.setClinicalBloodDocs(clinicalBloodDocList);
|
|
|
+ targetTran = new ClinicalBloodTran();
|
|
|
break;
|
|
|
case "抢救记录":
|
|
|
- List<RescueDoc> rescueDocList = new ArrayList<>();
|
|
|
- RescueDoc rescueDoc = new RescueDoc();
|
|
|
- rescueDoc.setText(analysisVO.getText());
|
|
|
- rescueDocList.add(rescueDoc);
|
|
|
- inputInfo.setRescueDocs(rescueDocList);
|
|
|
+ targetTran = new RescueTran();
|
|
|
break;
|
|
|
case "阶段小结":
|
|
|
- List<StagesSummaryDoc> stagesSummaryDocList = new ArrayList<>();
|
|
|
- StagesSummaryDoc stagesSummaryDoc = new StagesSummaryDoc();
|
|
|
- stagesSummaryDoc.setText(analysisVO.getText());
|
|
|
- stagesSummaryDocList.add(stagesSummaryDoc);
|
|
|
- inputInfo.setStagesSummaryDocs(stagesSummaryDocList);
|
|
|
+ targetTran = new StagesSummaryTran();
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
- AIAnalyze aiAnalyze = new AIAnalyze(crfServiceClient, similarityServiceClient);
|
|
|
- try {
|
|
|
- aiAnalyze.aiProcess(inputInfo);
|
|
|
- } catch (Exception e) {
|
|
|
- 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, String> retMap = new HashMap<>();
|
|
|
- Map<String, String> structureMap = 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);
|
|
|
- replaceMapping(retMap,ezSectionMaps,structureMap);
|
|
|
- } else if (analysisVO.getType().equals("输血记录")) {
|
|
|
- Map<String, Object> jsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(inputInfo.getClinicalBloodDocs().get(0).getClinicalBloodLabel()));
|
|
|
- AddKeyValue(keyContrastMap, bloodKeyContrasts);
|
|
|
- bloodKeyContrastCommon(jsonMap, keyContrastMap, structureMap);
|
|
|
- } else if (analysisVO.getType().equals("抢救记录")) {
|
|
|
- Map<String, Object> jsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(inputInfo.getRescueDocs().get(0).getRescueLabel()));
|
|
|
- // AddKeyValue(keyContrastMap, rescueContrasts);
|
|
|
- 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(), structureMap);
|
|
|
- analysisDTO.setResult(map);
|
|
|
-
|
|
|
+ analysisDTO.setResult(targetTran.convert(analysisVO.getText()));
|
|
|
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(
|
|
|
- "reason=输血原因",
|
|
|
- "responseType=输血反应类型",
|
|
|
- "indication=输血指征",
|
|
|
- "type=输血类型",
|
|
|
- "startTime=输血开始时间",
|
|
|
- "endTime=输血结束时间",
|
|
|
- "当前诊断=死亡诊断",
|
|
|
- "死亡日期=死亡时间",
|
|
|
- "初步诊断=入院诊断",
|
|
|
- "诊治经过=诊疗经过",
|
|
|
- "现病史- 发病情况=发病情况",
|
|
|
- "本人姓名=姓名",
|
|
|
- "病历日期=记录时间",
|
|
|
- "医生=记录医师"
|
|
|
- );
|
|
|
-
|
|
|
- private List<String> rescueContrasts = Lists.newArrayList(
|
|
|
- "auxiliaryTest=检查/检验项目名称",
|
|
|
- "interventions=介入物名称",
|
|
|
- "operations=手术及操作名称",
|
|
|
- //无对应
|
|
|
- "drugs=抢救药品",
|
|
|
- "methods=操作方法",
|
|
|
- "diagnosis=疾病诊断名称",
|
|
|
- //无对应
|
|
|
- "conditions=抢救病情"
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- );
|
|
|
-
|
|
|
- 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为空");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void bloodKeyContrastCommon(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 {
|
|
|
- StringBuffer sbX = new StringBuffer();
|
|
|
- for (Map.Entry<String, Object> firstDateEntry : firstJsonMap.entrySet()) {
|
|
|
- String beanToJson = FastJsonUtils.getBeanToJson( firstDateEntry.getValue());
|
|
|
- if(beanToJson.contains("name")||beanToJson.contains("measurementUnit")){
|
|
|
- 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{
|
|
|
- for (Map.Entry<String, Object> typeObjectEntry : jsonToMap.entrySet()) {
|
|
|
- Object value = typeObjectEntry.getValue();
|
|
|
- if(value instanceof JSONObject){
|
|
|
- Map<String, Object> objToMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(value));
|
|
|
- sbX.append(objToMap.get("name"));
|
|
|
- }else{
|
|
|
- sbX.append( jsonToMap.get("name"));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }else{
|
|
|
- sbX.append(firstDateEntry.getValue());
|
|
|
- }
|
|
|
- retMap.put(keyContrastMap.get(dateEntry.getKey()),sbX.toString());
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- } else if (object instanceof JSONArray) {
|
|
|
- List<Map<String, Object>> jsonToListMap = FastJsonUtils.getJsonToListMap(FastJsonUtils.getBeanToJson(dateEntry.getValue()));
|
|
|
- int count = 1;
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
- if(jsonToListMap.size()==1){
|
|
|
- Object name = jsonToListMap.get(0).get("name");
|
|
|
- retMap.put(keyContrastMap.get(dateEntry.getKey()),String.valueOf(name));
|
|
|
- }else{
|
|
|
- for (Map<String, Object> mapList : jsonToListMap) {
|
|
|
- for (Map.Entry<String, Object> stringObjectEntry : mapList.entrySet()) {
|
|
|
- if(stringObjectEntry.getKey()=="negative"){
|
|
|
- Map<String, Object> negativeJsonMap = FastJsonUtils.getJsonToMap(FastJsonUtils.getBeanToJson(stringObjectEntry.getValue()));
|
|
|
- Object negativeObject = negativeJsonMap.get("name");
|
|
|
- sb.append((count++) + "." +(negativeObject==null? "":negativeObject));
|
|
|
- }else if(stringObjectEntry.getKey()=="name"){
|
|
|
- sb.append(stringObjectEntry.getValue());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- retMap.put(keyContrastMap.get(dateEntry.getKey()), sb.toString());
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- } catch (JSONException e) {
|
|
|
- log.error(keyContrastMap.get(dateEntry.getKey()) + "json为空");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void replaceMapping(Map sourceMap, List<String> keyContrasts, Map<String, String> retMap) {
|
|
|
- Map<String, String> sourceMap_ = copyMap(sourceMap);
|
|
|
- String[] arry = null;
|
|
|
- String sourceKey = null, targetKey;
|
|
|
- Set<String> removeKey = new HashSet<>();
|
|
|
- for (String keyContrast : keyContrasts) {
|
|
|
- arry = keyContrast.split("=");
|
|
|
- sourceKey = arry[0];
|
|
|
- if (arry.length == 1) {
|
|
|
- targetKey = arry[0];
|
|
|
- } else {
|
|
|
- targetKey = arry[1];
|
|
|
- }
|
|
|
- if (StringUtil.isNotBlank(sourceMap_.get(sourceKey))
|
|
|
- && (!retMap.containsKey(targetKey) || StringUtil.isBlank(retMap.get(targetKey)))) {
|
|
|
- retMap.put(targetKey, sourceMap_.get(sourceKey));
|
|
|
- }
|
|
|
- removeKey.add(sourceKey);
|
|
|
- }
|
|
|
- Set<String> keySet = retMap.keySet();
|
|
|
- for (String key : sourceMap_.keySet()) {
|
|
|
- if (!keySet.contains(key) && !removeKey.contains(key)) { // 如果之前已放过key就不用放了
|
|
|
- retMap.put(key, sourceMap_.get(key));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private List<String> ezSectionMaps = Lists.newArrayList(
|
|
|
- "诊断名称=手术指征",
|
|
|
- "量=羊水量(mL)",
|
|
|
- "长度=新生儿出生身长(cm)",
|
|
|
- "圈数=绕颈身(周)",
|
|
|
- "宫缩剂用法=宫缩剂使用方法",
|
|
|
- "手术用药名称=手术用药",
|
|
|
- "术中出血量=出血量(mL)",
|
|
|
- "补液量=输液量(mL)",
|
|
|
- "脐带长度=脐带长度(cm)",
|
|
|
- "分数=Apgar评分值"
|
|
|
- );
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 复制一个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;
|
|
|
- }
|
|
|
-
|
|
|
}
|