|
@@ -0,0 +1,227 @@
|
|
|
+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.BeHospitalizedDoc;
|
|
|
+import com.lantone.structure.util.MapUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.time.DateUtils;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:入院记录
|
|
|
+ * @author: cy
|
|
|
+ * @time: 2021/3/05 16:12
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public class BeHospitalizedTran extends TargetTran {
|
|
|
+ @Override
|
|
|
+ public Map<String, String> convert(String text) {
|
|
|
+ BeHospitalizedDoc beHospitalizedDoc = new BeHospitalizedDoc();
|
|
|
+ beHospitalizedDoc.setText(text);
|
|
|
+ inputInfo.setBeHospitalizedDoc(beHospitalizedDoc);
|
|
|
+ Map<String, String> structureMap = cutWord(text);
|
|
|
+ Map<String, String> retMap = new HashMap<String, String>();
|
|
|
+ // beHospitalContrast(inputInfo.getBeHospitalizedDoc(), structureMap);
|
|
|
+ mapKeyContrastCommon(structureMap,stagesContrasts,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.containsKey("既往史") || sourceMap.containsKey("肺脏")){
|
|
|
+ sourceMap.remove("记录时间");
|
|
|
+ sourceMap.remove("既往史");
|
|
|
+ sourceMap.remove("肺脏");
|
|
|
+ }
|
|
|
+ return sourceMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<String> stagesContrasts = Lists.newArrayList(
|
|
|
+ "姓 名=患者姓名",
|
|
|
+ "性 别=性别代码",
|
|
|
+ "民 族=民族",
|
|
|
+ "婚 姻=婚姻状况代码",
|
|
|
+ "职 业=职业类别代码",
|
|
|
+ "入院时间=入院日期时间",
|
|
|
+ "病史陈述者=病史陈述者姓名",
|
|
|
+ "与患者关系=陈述者与患者的关系代码",
|
|
|
+ "主 诉=主诉",
|
|
|
+ "主 诉=主诉",
|
|
|
+ "一般情况=体格检查--一般状况检查结果",
|
|
|
+ "皮肤黏膜=体格检查--皮肤和黏膜检查结果",
|
|
|
+ "浅表淋巴结=体格检查--全身浅表淋巴结检查结果",
|
|
|
+ "头部及其器官=体格检查--头部及其器官检查结果",
|
|
|
+ "颈部=体格检查--颈部检查结果",
|
|
|
+ "胸部=体格检查--胸部检查结果",
|
|
|
+ "腹部=体格检查--腹部检查结果",
|
|
|
+ "肛门、直肠=体格检查--肛门指诊检查结果描述",
|
|
|
+ "外生殖器=体格检查--外生殖器检查结果",
|
|
|
+ "神经系统=体格检查--神经系统检查结果",
|
|
|
+ "表格<辅助检查表>内容=辅助检查结果",
|
|
|
+ "其他=体格检查-其他检查结果"
|
|
|
+ );
|
|
|
+
|
|
|
+ public void beHospitalContrast ( BeHospitalizedDoc beHospitalizedDoc,Map<String, String> retMap) {
|
|
|
+ String text = beHospitalizedDoc.getText();
|
|
|
+
|
|
|
+ //主持人姓名去职称
|
|
|
+ List<String>titleStr = Lists.newArrayList("﹙副﹚主任医师","(副)主任医师","副主任医师", "主治医师","主任医师",
|
|
|
+ "住院医师","医师", "护士");
|
|
|
+ for (String timeName : titleStr) {
|
|
|
+ String dirName = retMap.get("讨论主持人");
|
|
|
+ if (StringUtil.isNotEmpty(dirName)) {
|
|
|
+ if (dirName.contains(timeName)) {
|
|
|
+ retMap.put("讨论主持人", dirName.split(timeName)[0]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(StringUtil.isNotEmpty(retMap.get("主持人总结"))){
|
|
|
+ String dirSum = retMap.get("主持人总结");
|
|
|
+ if(dirSum.contains("主持人(签名)")){
|
|
|
+ String substring = dirSum.substring(0, dirSum.lastIndexOf("主持人(签名)"));
|
|
|
+ if(StringUtil.isNotEmpty(substring)){
|
|
|
+ retMap.put("主持人总结",substring);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtil.isNotEmpty(retMap.get("参加人员"))){
|
|
|
+ String fir = text.substring(text.indexOf("参加人员:")+5, text.lastIndexOf("汇报病史"));
|
|
|
+ String[] split = fir.split("\n");
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ for (int i = 0; i < split.length-1; i++) {
|
|
|
+ sb.append(split[i]).append(" ");
|
|
|
+ }
|
|
|
+ retMap.put("参加人员",sb.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ String trueRet = "";
|
|
|
+ if(text.contains("主持人(签名)") && text.contains("记录者(签名)")){
|
|
|
+ trueRet = text.substring( text.indexOf("主持人(签名)")+7, text.indexOf("记录者(签名)")).trim();
|
|
|
+ }
|
|
|
+ if(StringUtil.isNotEmpty(trueRet)){
|
|
|
+ retMap.put("主任医师签名",trueRet);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(text.contains(" 记录者(签名)")){
|
|
|
+ String record = text.substring(text.indexOf("记录者(签名)")+7);
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+
|
|
|
+ String[] split = record.split(" ");
|
|
|
+ sb.append(split[0].trim()).append(split[1].trim()).append(split[2].trim());
|
|
|
+ if(StringUtil.isNotEmpty(sb.toString())){
|
|
|
+ retMap.put("主治医师签名",sb.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 抽取文本中的最后时间
|
|
|
+ *
|
|
|
+ * @param top
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String lastTime(String top) {
|
|
|
+ int length = top.trim().length();
|
|
|
+ String substring = top.trim().substring(length - 22, length);
|
|
|
+ String stringDate = "";
|
|
|
+ if( substring.contains("年")){
|
|
|
+ String[] time = substring.split("年");
|
|
|
+ String timeYear = time[0].trim();
|
|
|
+ timeYear = extractDate(timeYear);
|
|
|
+ if( substring.contains("月")){
|
|
|
+ String[] timeLater = time[1].split("月");
|
|
|
+ String timeMouth = timeLater[0].trim();
|
|
|
+ if(substring.contains("日")){
|
|
|
+ String[] timeLast = timeLater[1].split("日");
|
|
|
+ String timeDate = timeLast[0].trim();
|
|
|
+ if(StringUtil.isNotEmpty(timeYear) && StringUtil.isNotEmpty(timeMouth) && StringUtil.isNotEmpty(timeDate)){
|
|
|
+ stringDate = timeYear + "年" + timeMouth + "月" + timeDate + "日" ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Date date = null;
|
|
|
+ try {
|
|
|
+ date = DateUtils.parseDate(stringDate, StringUtil.dateFormats);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(),e);
|
|
|
+ }
|
|
|
+ if(date!= null){
|
|
|
+ return stringDate;
|
|
|
+ }else{
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String parseString(String text){
|
|
|
+ if(text.contains("/")){
|
|
|
+ text = text.substring(text.lastIndexOf("/")+1);
|
|
|
+ text= parseString(text);
|
|
|
+ }
|
|
|
+ return text;
|
|
|
+ }
|
|
|
+}
|