|
@@ -0,0 +1,158 @@
|
|
|
+package com.lantone.structure.facade.tran;
|
|
|
+
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+import com.lantone.common.util.StringUtil;
|
|
|
+import com.lantone.structure.facade.tran.util.CommonAnalysisUtil;
|
|
|
+import com.lantone.structure.model.doc.operation.OperationDiscussionDoc;
|
|
|
+import com.lantone.structure.model.doc.operation.OperationDoc;
|
|
|
+import com.lantone.structure.util.MapUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:术后首次病程
|
|
|
+ * @author: cy
|
|
|
+ * @time: 2021/3/16 14:12
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public class OperationDiscussionTran extends TargetTran {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, String> convert(String text) {
|
|
|
+ List<OperationDoc> operationDocs = new ArrayList<>();
|
|
|
+ OperationDoc operationDoc = new OperationDoc();
|
|
|
+ OperationDiscussionDoc operationDiscussionDoc = new OperationDiscussionDoc();
|
|
|
+ operationDiscussionDoc.setText(text);
|
|
|
+ operationDoc.setOperationDiscussionDoc(operationDiscussionDoc);
|
|
|
+ operationDocs.add(operationDoc);
|
|
|
+ inputInfo.setOperationDocs(operationDocs);
|
|
|
+ Map<String, String> structureMap = new HashMap<String, String>();
|
|
|
+ Map<String, String> retMap = new HashMap<String, String>();
|
|
|
+ structureMap = cutWord(text);
|
|
|
+ oDContrast(inputInfo.getOperationDocs(), structureMap);
|
|
|
+ mapKeyContrastCommon(structureMap,stagesContrasts,retMap);
|
|
|
+ // preoperativeDiscussionDoc.setStructureMap(retMap);
|
|
|
+ // aiProcess();
|
|
|
+ // lastSovle(inputInfo.getOperationDocs(),retMap);
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, String> cutWord(String text) {
|
|
|
+ Map<String, String> sourceMap = Maps.newHashMap();
|
|
|
+ List<String> titles = CommonAnalysisUtil.sortTitles(
|
|
|
+ Lists.newArrayList("简要病情"),
|
|
|
+ text
|
|
|
+ );
|
|
|
+ CommonAnalysisUtil.cutByTitles(text, titles, 0, sourceMap);
|
|
|
+ if( sourceMap.containsKey("术前诊断")){
|
|
|
+ sourceMap.remove("术前诊断");
|
|
|
+ }
|
|
|
+ return sourceMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> stagesContrasts = Lists.newArrayList(
|
|
|
+ "手术指征=手术指征",
|
|
|
+ "手术指征=手术适应证"
|
|
|
+ );
|
|
|
+
|
|
|
+ public void oDContrast(List<OperationDoc> operationDocs,Map<String, String> retMap) {
|
|
|
+ String text = operationDocs.get(0).getOperationDiscussionDoc().getText();
|
|
|
+ if(text.contains("\n")){
|
|
|
+ String[] split = text.split("\n");
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ if(i<=1){
|
|
|
+ String date= extractDate(split[i]);
|
|
|
+ if(StringUtil.isNotEmpty(date)){
|
|
|
+ retMap.put("记录日期时间",date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(text.contains("患者诊断")){
|
|
|
+ String sureStr = text.substring(text.indexOf("患者诊断") + "患者诊断".length());
|
|
|
+ if(sureStr.contains("禁忌症")){
|
|
|
+ sureStr = sureStr.substring(0,sureStr.indexOf("禁忌症"));
|
|
|
+ }
|
|
|
+ if(sureStr.contains("手术指征")){
|
|
|
+ sureStr = sureStr.substring(0,sureStr.indexOf("手术指征"));
|
|
|
+ }
|
|
|
+ if(sureStr.contains("明确")){
|
|
|
+ sureStr = sureStr.substring(0,sureStr.indexOf("明确"));
|
|
|
+ }
|
|
|
+ retMap.put("术后诊断名称",sureStr);
|
|
|
+ }
|
|
|
+ if(text.contains("注意观察")){
|
|
|
+ String sureStr = text.substring(text.indexOf("注意观察") + "注意观察".length());
|
|
|
+ if(sureStr.contains("。")){
|
|
|
+ sureStr = sureStr.split("。")[0];
|
|
|
+ }
|
|
|
+ retMap.put("注意事项",sureStr);
|
|
|
+ }
|
|
|
+ String signName= parseString(text);
|
|
|
+ if(StringUtil.isNotEmpty(signName)){
|
|
|
+ retMap.put("医师签名",signName);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void mapKeyContrastCommon(Map sourceMap, List<String> keyContrasts, Map<String, String> retMap) {
|
|
|
+ Map<String, String> sourceMap_ = MapUtil.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));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 抽取文本中的第一个时间
|
|
|
+ *
|
|
|
+ * @param top
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String extractDate (String top){
|
|
|
+ Pattern pattern = Pattern.compile("[0-9]{4}[-][0-9]{1,2}[-][0-9]{1,2}");
|
|
|
+ Matcher matcher = pattern.matcher(top);
|
|
|
+ if (matcher.find()) {
|
|
|
+ return matcher.group(0);
|
|
|
+ } else {
|
|
|
+ Pattern p1 = Pattern.compile("[0-9]{4}年[0-9]+月[0-9]+日");
|
|
|
+ Matcher m1 = p1.matcher(top);
|
|
|
+ if (m1.find()) {
|
|
|
+ return m1.group(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 取/后
|
|
|
+ public static String parseString(String text){
|
|
|
+ if(text.contains("/")){
|
|
|
+ text = text.substring(text.lastIndexOf("/")+1);
|
|
|
+ text= parseString(text);
|
|
|
+ }
|
|
|
+ return text;
|
|
|
+ }
|
|
|
+}
|