|
@@ -0,0 +1,139 @@
|
|
|
+package org.diagbot;
|
|
|
+
|
|
|
+import oracle.jdbc.OracleResultSet;
|
|
|
+import oracle.sql.BLOB;
|
|
|
+import oracle.sql.OPAQUE;
|
|
|
+import oracle.xdb.XMLType;
|
|
|
+import org.diagbot.pub.jdbc.MysqlJdbc;
|
|
|
+
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.sql.*;
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by louhr on 2019/9/3.
|
|
|
+ */
|
|
|
+public class EyeHospitalData {
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ EyeHospitalData ehl = new EyeHospitalData();
|
|
|
+ Connection conn = ehl.createOracleJdbc();
|
|
|
+ ehl.queryHospitalInput(conn);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Map<String, Object>> queryHospitalInput(Connection conn) {
|
|
|
+ PreparedStatement pstmt = null;
|
|
|
+ ResultSet rs = null;
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+ String ipid = "";
|
|
|
+ try {
|
|
|
+
|
|
|
+ DateFormat df = new SimpleDateFormat("yyyyMMdd");
|
|
|
+
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.setTime(new Date());
|
|
|
+ String end_time = df.format(cal.getTime());
|
|
|
+
|
|
|
+ cal.add(Calendar.DATE, -7);
|
|
|
+ String start_time = df.format(cal.getTime());
|
|
|
+
|
|
|
+
|
|
|
+ int record_cnt = 1;
|
|
|
+
|
|
|
+ while (start_time.compareTo("20190801") > -1) {
|
|
|
+ System.out.println(start_time + "..." + end_time);
|
|
|
+
|
|
|
+ String sql = "select xml_cont, ipid, pid, dept_name, dept_code, create_time from inpcase.hospital_record " +
|
|
|
+ "where substr(create_time, 0, 8) > '" + start_time + "' and substr(create_time, 0, 8) <= '" + end_time + "'";
|
|
|
+ pstmt = conn.prepareStatement(sql);
|
|
|
+ //建立一个结果集,用来保存查询出来的结果
|
|
|
+ rs = pstmt.executeQuery();
|
|
|
+
|
|
|
+
|
|
|
+ while (rs.next()) {
|
|
|
+ if (record_cnt % 100 == 0) {
|
|
|
+ System.out.println("已查询" + record_cnt + "行数据!");
|
|
|
+ }
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ OracleResultSet ors = (OracleResultSet) rs;
|
|
|
+ OPAQUE op = ors.getOPAQUE(1);
|
|
|
+ ipid = ors.getString(2);
|
|
|
+ String pid = ors.getString(3);
|
|
|
+ String dept_name = ors.getString(4);
|
|
|
+ String dept_code = ors.getString(5);
|
|
|
+ String create_time = ors.getString(6);
|
|
|
+
|
|
|
+ XMLType xml = XMLType.createXML(op);
|
|
|
+ String xml_cont = xml.getStringVal();
|
|
|
+ xml_cont = xml_cont.substring(xml_cont.indexOf("<text>") + 6, xml_cont.indexOf("</text>"));
|
|
|
+
|
|
|
+ String sex = xml_cont.substring(xml_cont.indexOf("性 别:") + 5, xml_cont.indexOf("性 别:") + 8);
|
|
|
+ String age = xml_cont.substring(xml_cont.indexOf("年 龄:") + 5, xml_cont.indexOf("年 龄:") + 8);
|
|
|
+ String marry = xml_cont.substring(xml_cont.indexOf("婚 姻:") + 5, xml_cont.indexOf("婚 姻:") + 8);
|
|
|
+ String in_hospital = xml_cont.substring(xml_cont.indexOf("入院日期:") + 5, xml_cont.indexOf("入院日期:") + 22);
|
|
|
+ String content = xml_cont.substring(xml_cont.indexOf("主 诉:"), xml_cont.indexOf("医师签名:"));
|
|
|
+
|
|
|
+ map.put("ipid", ipid);
|
|
|
+ map.put("pid", pid);
|
|
|
+ map.put("dept_name", dept_name);
|
|
|
+ map.put("dept_code", dept_code);
|
|
|
+ map.put("create_time", create_time);
|
|
|
+ map.put("sex", sex);
|
|
|
+ map.put("age", age);
|
|
|
+ map.put("marry", marry);
|
|
|
+ map.put("in_hospital", in_hospital);
|
|
|
+ map.put("content", content);
|
|
|
+
|
|
|
+ System.out.println(sex);
|
|
|
+ System.out.println(age);
|
|
|
+ System.out.println(marry);
|
|
|
+ System.out.println(in_hospital);
|
|
|
+ System.out.println(content);
|
|
|
+
|
|
|
+ list.add(map);
|
|
|
+
|
|
|
+ record_cnt++;
|
|
|
+ }
|
|
|
+
|
|
|
+ end_time = start_time;
|
|
|
+ cal.add(Calendar.DATE, -7);
|
|
|
+ start_time = df.format(cal.getTime());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println(ipid);
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ rs.close();
|
|
|
+ pstmt.close();
|
|
|
+ }catch (SQLException sqle) {
|
|
|
+ sqle.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void insertMysql(List<Map<String, Object>> list) {
|
|
|
+ MysqlJdbc nlpJdbc = new MysqlJdbc("root", "", "jdbc:mysql://127.0.0.1:3306/eye_hospital?useUnicode=true&characterEncoding=UTF-8");
|
|
|
+ nlpJdbc.insert(list, "hospital_record", new String[]{"ipid", "pid", "dept_name", "dept_code", "create_time", "sex", "age", "marry", "in_hospital", "content"});
|
|
|
+ }
|
|
|
+
|
|
|
+ private Connection createOracleJdbc() {
|
|
|
+ Connection conn = null;
|
|
|
+ try {
|
|
|
+ Class.forName("oracle.jdbc.driver.OracleDriver");
|
|
|
+ conn = DriverManager.getConnection("jdbc:oracle:thin:@//172.17.1.143:1521/orc1",
|
|
|
+ "louhr", "louhr");
|
|
|
+ return conn;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return conn;
|
|
|
+ }
|
|
|
+}
|