|
@@ -0,0 +1,128 @@
|
|
|
+package com.lantone.qc.kernel;
|
|
|
+
|
|
|
+import com.lantone.qc.pub.util.StringUtil;
|
|
|
+import com.lantone.qc.trans.util.http.db.DBUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
+import java.io.*;
|
|
|
+import java.sql.Connection;
|
|
|
+import java.sql.ResultSet;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.sql.Statement;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+public class tzWriterDiagnosisTest {
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ AcquirePatientName();
|
|
|
+ }
|
|
|
+
|
|
|
+ //取患者姓名
|
|
|
+ private static void AcquirePatientName() {
|
|
|
+ String path = "C:/Users/lantone/Desktop/诊断分类(65份以下)/1000.txt";
|
|
|
+ List<String> caseList = readFile(path);
|
|
|
+ for (String diag : caseList) {
|
|
|
+ System.out.println(diag + "\n");
|
|
|
+ ReplaceSen(diag);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void ReplaceSen(String diag) {
|
|
|
+ Connection conn = null;
|
|
|
+ Statement stmt = null;
|
|
|
+ ResultSet rs = null;
|
|
|
+ try {
|
|
|
+ conn = DBUtil.getConnection();
|
|
|
+ stmt = conn.createStatement();
|
|
|
+ rs = stmt.executeQuery("SELECT * FROM str_admission_note WHERE diagnosis='" + diag + "'");
|
|
|
+ List<String> diagnosisList = new ArrayList<>();
|
|
|
+ int aaaNum = 1;
|
|
|
+ while (rs.next()) {
|
|
|
+ diagnosisList = new ArrayList<>();
|
|
|
+ for (int i = 1; i < 23; i++) {
|
|
|
+ diagnosisList.add(rs.getString(i));
|
|
|
+ }
|
|
|
+ if (diagnosisList.size() > 0) {
|
|
|
+ str(diagnosisList, diag, aaaNum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void str(List<String> diagnosisList, String diag, int aaaNum) throws Exception {
|
|
|
+ String medRecordNum = diagnosisList.get(0);
|
|
|
+ //将写入转化为流的形式
|
|
|
+ String filePath = "C:/Users/lantone/Desktop/诊断分类(65份以下)/" + diag + "/" + medRecordNum + ".txt";
|
|
|
+ // 指定路径如果没有则创建并添加
|
|
|
+ File file = new File(filePath);
|
|
|
+ File fileParent = file.getParentFile();
|
|
|
+ if (!fileParent.exists()) {
|
|
|
+ //创建父目录文件
|
|
|
+ fileParent.mkdirs();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.createNewFile();
|
|
|
+ } else {
|
|
|
+ medRecordNum = medRecordNum + "_" + aaaNum++;
|
|
|
+ filePath = "C:/Users/lantone/Desktop/诊断分类(65份以下)/" + diag + "/" + medRecordNum + ".txt";
|
|
|
+ File fil2 = new File(filePath);
|
|
|
+ if (!fil2.exists()) {
|
|
|
+ fil2.createNewFile();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //一次写一行
|
|
|
+ BufferedWriter bw = new BufferedWriter(new FileWriter(filePath));
|
|
|
+ for (String listStr : diagnosisList) {
|
|
|
+ if(StringUtil.isNotBlank(listStr)){
|
|
|
+ bw.write(listStr);
|
|
|
+ bw.newLine(); //换行用
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //关闭流
|
|
|
+ bw.close();
|
|
|
+ System.out.println("写入成功");
|
|
|
+ } catch (IOException e) {
|
|
|
+ System.out.println("ERROR");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 读取文件内容
|
|
|
+ public static List<String> readFile(String path) {//路径
|
|
|
+ File file = new File(path);
|
|
|
+ List<String> caseList = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));//构造一个BufferedReader类来读取文件
|
|
|
+ String line = null;
|
|
|
+ while ((line = br.readLine()) != null) {//使用readLine方法,一次读一行
|
|
|
+ caseList.add(line);
|
|
|
+ }
|
|
|
+ br.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return caseList;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|