|
@@ -0,0 +1,386 @@
|
|
|
|
+package com.lantone.qc.kernel;
|
|
|
|
+
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
|
+import com.lantone.qc.kernel.structure.ai.model.Lemma;
|
|
|
|
+import com.lantone.qc.pub.util.StringUtil;
|
|
|
|
+import com.lantone.qc.trans.comsis.OrdinaryAssistant;
|
|
|
|
+import com.lantone.qc.trans.util.http.db.DBUtil;
|
|
|
|
+
|
|
|
|
+import java.io.BufferedReader;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.io.InputStreamReader;
|
|
|
|
+import java.sql.*;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
+
|
|
|
|
+public class tzAdmissionNote {
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ String path = "C:/Users/dev_1/Desktop/dcsj/test.txt";
|
|
|
|
+ String str = readFile(path);
|
|
|
|
+// List<Map<String, String>> xmlMaps = WritXmlSelect();
|
|
|
|
+// System.out.println(xmlMaps);
|
|
|
|
+// AcquirePatientName(xmlMaps);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 读取文件内容
|
|
|
|
+ public static String readFile(String path) {//路径
|
|
|
|
+ File file = new File(path);
|
|
|
|
+ StringBuffer result = new StringBuffer();
|
|
|
|
+ List<String> caseList = new ArrayList<>();
|
|
|
|
+ Map<String, String> structureMap = new HashMap<>();
|
|
|
|
+ try {
|
|
|
|
+ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));//构造一个BufferedReader类来读取文件
|
|
|
|
+ String line = null;
|
|
|
|
+ while ((line = br.readLine()) != null) {//使用readLine方法,一次读一行
|
|
|
|
+ boolean flag = cutCase(line, caseList, result);
|
|
|
|
+ if (flag) {
|
|
|
|
+ result = new StringBuffer();
|
|
|
|
+ result.append(line);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (caseList.size() > 0) {
|
|
|
|
+ analysisList(caseList, structureMap);
|
|
|
|
+ }
|
|
|
|
+ br.close();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return result.toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //切出每一个个病历
|
|
|
|
+ private static void analysisList(List<String> caseList, Map<String, String> structureMap) {
|
|
|
|
+ for (String content : caseList) {
|
|
|
|
+ String[] split = content.split("\t");
|
|
|
|
+ if (split.length > 4) {
|
|
|
|
+ structureMap.put("病案号", split[0]);
|
|
|
|
+ if (split[1].equals("F")) {
|
|
|
|
+ structureMap.put("性别", "女");
|
|
|
|
+ } else {
|
|
|
|
+ structureMap.put("性别", "男");
|
|
|
|
+ }
|
|
|
|
+ structureMap.put("年龄", split[2] + split[3]);
|
|
|
|
+ //主诉,现病史等的处理
|
|
|
|
+ analysis(split[4], structureMap);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void analysis(String content, Map<String, String> structureMap) {
|
|
|
|
+ List<String> titles = Lists.newArrayList("主诉", "现病史", "既往史", "个人史", "月经史", "婚育史", "家族史", "体格检查",
|
|
|
|
+ "精神检查", "诊断", "处理", "处理结果", "注意事项", "西药", "检查", "外阴", "阴道", "宫颈", "子宫", "双附件");
|
|
|
|
+ if (StringUtil.isNotBlank(content)) {
|
|
|
|
+ List<String> sortTitles = sortTitles(titles, content);
|
|
|
|
+ cutByTitles(content, sortTitles, 0, structureMap, true);
|
|
|
|
+ structureMap = OrdinaryAssistant.mapKeyContrast(structureMap, consultationResults_pageDataTitles);
|
|
|
|
+ storage(structureMap);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static List<String> consultationResults_pageDataTitles = Lists.newArrayList(
|
|
|
|
+ "处理结果=处理"
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private static void storage(Map<String, String> structureMap) {
|
|
|
|
+ Connection conn = null;
|
|
|
|
+ Statement stmt = null;
|
|
|
|
+ PreparedStatement ps = null;
|
|
|
|
+ ResultSet rs = null;
|
|
|
|
+ String sql = "insert into str_admission_note(name,price,bookCount,author) values(?,?,?,?)";
|
|
|
|
+ try {
|
|
|
|
+ conn = DBUtil.getConnection();
|
|
|
|
+ ps = conn.prepareStatement(sql);
|
|
|
|
+
|
|
|
|
+// ps.setString(1, );
|
|
|
|
+// ps.setDouble(2, );
|
|
|
|
+// ps.setInt(3, );
|
|
|
|
+// ps.setString(4, );
|
|
|
|
+ int row = ps.executeUpdate();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if (rs != null) {
|
|
|
|
+ rs.close();
|
|
|
|
+ rs = null;
|
|
|
|
+ }
|
|
|
|
+ if (stmt != null) {
|
|
|
|
+ stmt.close();
|
|
|
|
+ stmt = null;
|
|
|
|
+ }
|
|
|
|
+ if (conn != null) {
|
|
|
|
+ conn.close();
|
|
|
|
+ conn = null;
|
|
|
|
+ }
|
|
|
|
+ } catch (SQLException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 将title根据在文本中的位置排序
|
|
|
|
+ *
|
|
|
|
+ * @param titles
|
|
|
|
+ * @param content
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static List<String> sortTitles(List<String> titles, String content) {
|
|
|
|
+ Map<Integer, String> titleIndex = new TreeMap<>();
|
|
|
|
+ int index, index_1, index_2;
|
|
|
|
+ for (String title : titles) {
|
|
|
|
+ index_1 = content.indexOf(title + ":");
|
|
|
|
+ index_2 = content.indexOf(title + ":");
|
|
|
|
+ index = Math.max(index_1, index_2);
|
|
|
|
+ if (index != -1) {
|
|
|
|
+ titleIndex.put(index, title);
|
|
|
|
+ StringBuffer sb = new StringBuffer(title.length());
|
|
|
|
+ for (int i = 0; i < title.length(); i++) {
|
|
|
|
+ sb.append('*');
|
|
|
|
+ }
|
|
|
|
+ content = content.substring(0, index) + sb.toString() + content.substring(index + title.length() + 1);
|
|
|
|
+ // content = content.substring(0, index) + content.substring(index + title.length() + 1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ titles = Lists.newArrayList(titleIndex.values());
|
|
|
|
+ return titles;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据文书各标题截取相应文本,存入structmap中
|
|
|
|
+ *
|
|
|
|
+ * @param line 原始文本
|
|
|
|
+ * @param titles 文书各标题
|
|
|
|
+ * @param depth 递归深度,也就是titles取值时的下标值
|
|
|
|
+ * @param structureMap 存储结构化数据
|
|
|
|
+ */
|
|
|
|
+ public static void cutByTitles(String line, List<String> titles, int depth, Map<String, String> structureMap, Boolean flag) {
|
|
|
|
+ if (depth > titles.size() || titles.size() == 0) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ String beforeTitle = null, title = null, newTitle = null, value = null;
|
|
|
|
+ beforeTitle = titles.get(Math.max(depth - 1, 0));
|
|
|
|
+ if (line.indexOf(beforeTitle) != 0 && flag) {
|
|
|
|
+ structureMap.put("现病史", line.substring(0, line.indexOf(beforeTitle)));
|
|
|
|
+ }
|
|
|
|
+ title = titles.get(Math.min(depth, titles.size() - 1));
|
|
|
|
+ if (depth == titles.size()) {
|
|
|
|
+ /*if (line.contains("\n")) {
|
|
|
|
+ line = line.split("\n")[0];
|
|
|
|
+ }
|
|
|
|
+ */
|
|
|
|
+ value = line.replace("\n", "");
|
|
|
|
+ structureMap.put(beforeTitle, value.trim());
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (line.contains(title + ":") || line.contains(title + ":")) {
|
|
|
|
+ if (line.contains(title + ":")) {
|
|
|
|
+ newTitle = title + ":";
|
|
|
|
+ } else {
|
|
|
|
+ newTitle = title + ":";
|
|
|
|
+ }
|
|
|
|
+ if (depth > 0) {
|
|
|
|
+ value = line.substring(0, line.indexOf(newTitle));
|
|
|
|
+ structureMap.put(beforeTitle.replace(" ", ""), value.trim().replace("\n", ""));
|
|
|
|
+ }
|
|
|
|
+ line = line.substring(line.indexOf(newTitle) + newTitle.length());
|
|
|
|
+ depth++;
|
|
|
|
+ } else {
|
|
|
|
+ titles.remove(depth);
|
|
|
|
+ }
|
|
|
|
+ cutByTitles(line, titles, depth, structureMap, false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //切出每一个个病历
|
|
|
|
+ private static boolean cutCase(String line, List<String> caseList, StringBuffer result) {
|
|
|
|
+ line = line.replace("浙江省台州市立医院", "")
|
|
|
|
+ .replace("台州学院医学院附属市立医院", "")
|
|
|
|
+ .replace("-------------------------------------------------------------------------------------------", "");
|
|
|
|
+ if (line.contains("\t")) {
|
|
|
|
+ String content = line.substring(0, line.indexOf("\t"));
|
|
|
|
+ String regex = "^\\d{7,}$";
|
|
|
|
+ if (content.matches(regex)) {
|
|
|
|
+ caseList.add(result.toString());
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ result.append(line);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //取患者姓名
|
|
|
|
+ private static void AcquirePatientName(List<Map<String, String>> xmlMaps) {
|
|
|
|
+ for (Map<String, String> structMap : xmlMaps) {
|
|
|
|
+ String recId = structMap.get("Id");
|
|
|
|
+ String xmlText = structMap.get("xml文书");
|
|
|
|
+ if (StringUtil.isNotBlank(xmlText)) {
|
|
|
|
+ //患者姓名
|
|
|
|
+ String patientName = null;
|
|
|
|
+ if (xmlText.contains("</NewCtrl>")) {
|
|
|
|
+ String[] newCtrls = xmlText.split("<NewCtrl");
|
|
|
|
+ for (int i = 1; i < newCtrls.length; i++) {
|
|
|
|
+ if (newCtrls[i].contains("患者姓名")) {
|
|
|
|
+ int conTextStartInt = newCtrls[i].indexOf("<Content_Text>") + 14;
|
|
|
|
+ int conTextEndInt = newCtrls[i].indexOf("</Content_Text>");
|
|
|
|
+ //取得患者姓名
|
|
|
|
+ patientName = newCtrls[i].substring(conTextStartInt, conTextEndInt);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if (xmlText.contains("</EMR-TERM>")) {
|
|
|
|
+ String[] emrTerms = xmlText.split("<EMR-TERM");
|
|
|
|
+ for (int i = 1; i < emrTerms.length; i++) {
|
|
|
|
+ if (!emrTerms[i].contains("任意医生")) {
|
|
|
|
+ int conTextStartInt = emrTerms[i].indexOf("creator=\"") + 9;
|
|
|
|
+ int conTextEndInt = emrTerms[i].indexOf("createDate") - 2;
|
|
|
|
+ //取得患者姓名
|
|
|
|
+ patientName = emrTerms[i].substring(conTextStartInt, conTextEndInt);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //名字脱敏
|
|
|
|
+ if (StringUtil.isNotBlank(patientName)) {
|
|
|
|
+ xmlText = ReplacePatientName(xmlText, patientName);
|
|
|
|
+ //手机号匹配
|
|
|
|
+ Pattern p = Pattern.compile("1[345678]\\d{9}");
|
|
|
|
+ Matcher m = p.matcher(xmlText);
|
|
|
|
+ if (m.find()) {
|
|
|
|
+ String group = m.group();
|
|
|
|
+ char[] groupChars = group.toCharArray();
|
|
|
|
+ String groupPhone = String.valueOf(groupChars[0]) + String.valueOf(groupChars[1]) + String.valueOf(groupChars[2]) + "********";
|
|
|
|
+ xmlText = xmlText.replace(group, groupPhone);
|
|
|
|
+ }
|
|
|
|
+ //座机号匹配
|
|
|
|
+ Pattern p2 = Pattern.compile("0\\d{2,3}-[1-9]\\d{6,7}");
|
|
|
|
+ Matcher m2 = p2.matcher(xmlText);
|
|
|
|
+ if (m2.find()) {
|
|
|
|
+ String group = m2.group();
|
|
|
|
+ String subStr = xmlText.substring(xmlText.indexOf(group) - 100, xmlText.indexOf(group));
|
|
|
|
+ if (subStr.contains("家庭电话")) {
|
|
|
|
+ char[] groupChars = group.toCharArray();
|
|
|
|
+ String groupPhone = null;
|
|
|
|
+ if (groupChars.length == 12) {
|
|
|
|
+ groupPhone = String.valueOf(groupChars[5]) + String.valueOf(groupChars[6]) + String.valueOf(groupChars[7]) + "****";
|
|
|
|
+ } else if (groupChars.length == 13) {
|
|
|
|
+ groupPhone = String.valueOf(groupChars[5]) + String.valueOf(groupChars[6]) + String.valueOf(groupChars[7]) + "*****";
|
|
|
|
+ }
|
|
|
|
+ xmlText = xmlText.replace(group, groupPhone);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //身份证匹配
|
|
|
|
+ Pattern p1 = Pattern.compile("\\d{17}[\\d|x]|\\d{15}");
|
|
|
|
+ Matcher m1 = p1.matcher(xmlText);
|
|
|
|
+ if (m1.find()) {
|
|
|
|
+ String idNumber = m1.group();
|
|
|
|
+ String subStr = xmlText.substring(xmlText.indexOf(idNumber) - 5, xmlText.indexOf(idNumber));
|
|
|
|
+ if (!subStr.contains("Id=")) {
|
|
|
|
+ char[] idNumberChars = idNumber.toCharArray();
|
|
|
|
+ String idNumberSen = String.valueOf(idNumberChars[0]) + String.valueOf(idNumberChars[1]) + String.valueOf(idNumberChars[2]) + String.valueOf(idNumberChars[3]) + "**************";
|
|
|
|
+ xmlText = xmlText.replace(idNumber, idNumberSen);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ System.out.println(recId);
|
|
|
|
+ System.out.println(xmlText);
|
|
|
|
+ ReplaceSensitivity(recId, xmlText);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static void ReplaceSensitivity(String recId, String xmlText) {
|
|
|
|
+ Connection conn = null;
|
|
|
|
+ Statement stmt = null;
|
|
|
|
+ ResultSet rs = null;
|
|
|
|
+ try {
|
|
|
|
+ conn = DBUtil.getConnection();
|
|
|
|
+ stmt = conn.createStatement();
|
|
|
|
+ stmt.executeUpdate("UPDATE med_medical_record_content mmrc SET mmrc.xml_text='" + xmlText + "'" + "WHERE mmrc.rec_id='" + recId + "'");
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if (rs != null) {
|
|
|
|
+ rs.close();
|
|
|
|
+ rs = null;
|
|
|
|
+ }
|
|
|
|
+ if (stmt != null) {
|
|
|
|
+ stmt.close();
|
|
|
|
+ stmt = null;
|
|
|
|
+ }
|
|
|
|
+ if (conn != null) {
|
|
|
|
+ conn.close();
|
|
|
|
+ conn = null;
|
|
|
|
+ }
|
|
|
|
+ } catch (SQLException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //查询xml文件内容
|
|
|
|
+ public static List<Map<String, String>> WritXmlSelect() {
|
|
|
|
+ Connection conn = null;
|
|
|
|
+ Statement stmt = null;
|
|
|
|
+ ResultSet rs = null;
|
|
|
|
+ List<Map<String, String>> resultList = new ArrayList<>();
|
|
|
|
+ try {
|
|
|
|
+ conn = DBUtil.getConnection();
|
|
|
|
+ stmt = conn.createStatement();
|
|
|
|
+ rs = stmt.executeQuery(
|
|
|
|
+ "SELECT mmrc.rec_id,mmrc.xml_text FROM `med_medical_record_content` mmrc\n" +
|
|
|
|
+ "LEFT JOIN med_medical_record mmr ON mmr.mode_id not in(\n" +
|
|
|
|
+ "'16','20','21','52','53','54','36','56') WHERE mmrc.rec_id = mmr.rec_id");
|
|
|
|
+ while (rs.next()) {
|
|
|
|
+ Map<String, String> map = new LinkedHashMap<>();
|
|
|
|
+ map.put("Id", rs.getString(1));
|
|
|
|
+ map.put("xml文书", rs.getString(2));
|
|
|
|
+ resultList.add(map);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if (rs != null) {
|
|
|
|
+ rs.close();
|
|
|
|
+ rs = null;
|
|
|
|
+ }
|
|
|
|
+ if (stmt != null) {
|
|
|
|
+ stmt.close();
|
|
|
|
+ stmt = null;
|
|
|
|
+ }
|
|
|
|
+ if (conn != null) {
|
|
|
|
+ conn.close();
|
|
|
|
+ conn = null;
|
|
|
|
+ }
|
|
|
|
+ } catch (SQLException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return resultList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //名字脱敏
|
|
|
|
+ private static String ReplacePatientName(String xmlText, String patientName) {
|
|
|
|
+ char[] patientNameChars = patientName.toCharArray();
|
|
|
|
+ String sensitivityName = null;
|
|
|
|
+ if (patientNameChars.length == 2) {
|
|
|
|
+ sensitivityName = patientNameChars[0] + "*";
|
|
|
|
+ } else if (patientNameChars.length == 3) {
|
|
|
|
+ sensitivityName = patientNameChars[0] + "**";
|
|
|
|
+ } else if (patientNameChars.length == 4) {
|
|
|
|
+ sensitivityName = patientNameChars[0] + "***";
|
|
|
|
+ }
|
|
|
|
+ if (StringUtil.isNotBlank(sensitivityName)) {
|
|
|
|
+ xmlText = xmlText.replace(patientName, sensitivityName);
|
|
|
|
+ }
|
|
|
|
+ return xmlText;
|
|
|
|
+ }
|
|
|
|
+}
|