|
@@ -0,0 +1,190 @@
|
|
|
+package com.lantone.qc.kernel;
|
|
|
+
|
|
|
+import com.lantone.qc.pub.util.StringUtil;
|
|
|
+import com.lantone.qc.trans.util.http.db.DBUtil;
|
|
|
+
|
|
|
+import java.sql.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+public class WritAnalysisTest {
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ List<Map<String, String>> xmlMaps = WritXmlSelect();
|
|
|
+ System.out.println(xmlMaps);
|
|
|
+ AcquirePatientName(xmlMaps);
|
|
|
+ }
|
|
|
+
|
|
|
+ //取患者姓名
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+}
|