|
@@ -1,5 +1,8 @@
|
|
|
package com.lantone.qc.kernel;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.gson.JsonObject;
|
|
|
import com.lantone.qc.pub.jdbc.MysqlJdbc;
|
|
|
import com.lantone.qc.pub.util.FastJsonUtils;
|
|
|
import com.lantone.qc.pub.util.PropertiesUtil;
|
|
@@ -10,10 +13,7 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.InputStream;
|
|
|
-import java.sql.Connection;
|
|
|
-import java.sql.ResultSet;
|
|
|
-import java.sql.SQLException;
|
|
|
-import java.sql.Statement;
|
|
|
+import java.sql.*;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -32,20 +32,23 @@ public class TaizDataImportApiTest {
|
|
|
|
|
|
private Map<String,String> caseMap = new HashMap<>();
|
|
|
|
|
|
+ private List<String> deletePatient = new ArrayList<>();
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
TaizDataImportApiTest test = new TaizDataImportApiTest();
|
|
|
//模块映射
|
|
|
test.loadModelHospital();
|
|
|
//长兴患者信息
|
|
|
if (cid.equals("changx")) {
|
|
|
- test.insertPatient(test.loadOraclePatients("BR_INPATIENTINFO_CX20200327"));
|
|
|
+ test.insertPatient(test.loadOraclePatients("BR_INPATIENTINFO_CX"));
|
|
|
}
|
|
|
//台州患者信息
|
|
|
if (cid.equals("taizhou")) {
|
|
|
test.insertPatient(test.loadOraclePatients("BR_INPATIENTINFO_TZ20200330"));
|
|
|
}
|
|
|
- //病人流水号获取
|
|
|
+ //病人流水号获取 病历号--->id
|
|
|
Map<String, String> patientMap = test.loadPatients(hospitalId);
|
|
|
+ //model-->id
|
|
|
Map<String, String> modelMap = test.loadModel();
|
|
|
test.insertPatientText(patientMap, modelMap);
|
|
|
}
|
|
@@ -66,19 +69,42 @@ public class TaizDataImportApiTest {
|
|
|
|
|
|
for (Map.Entry<String, String> entry : patientMap.entrySet()) {
|
|
|
List<PatientText> patientTexts = new ArrayList<>();
|
|
|
+ //病人的病案首页内容
|
|
|
+ Map<String, String> homePageMap = DataTest.loadHomePage(entry.getKey());
|
|
|
+ if (homePageMap == null || homePageMap.isEmpty()) { //没病案首页直接不导入
|
|
|
+ deletePatient.add(entry.getKey()); //没病案首页的患者也要删除
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<String, Object> firstPageTextMap = new HashMap<>();
|
|
|
+ firstPageTextMap.put("case_number", entry.getKey());
|
|
|
+ firstPageTextMap.put("case_number_id", patientMap.get(entry.getKey()));
|
|
|
+ firstPageTextMap.put("hospital_id", hospitalId);
|
|
|
+ firstPageTextMap.put("mode_id", 6);
|
|
|
+ firstPageTextMap.put("origin_text", FastJsonUtils.getBeanToJson(homePageMap));
|
|
|
+ String pagetext = "";
|
|
|
+ for (Map.Entry<String, String> e : homePageMap.entrySet()) {
|
|
|
+ pagetext = pagetext + "【" + e.getKey() + "】:" + e.getValue().toString() + "\n";
|
|
|
+ }
|
|
|
+ firstPageTextMap.put("text", pagetext);
|
|
|
+
|
|
|
if ("changx".equals(cid)) {
|
|
|
patientTexts = loadChangxOraclePatientTexts(entry.getKey());
|
|
|
}
|
|
|
if ("taizhou".equals(cid)) {
|
|
|
patientTexts = loadTaizhouOraclePatientTexts(entry.getKey());
|
|
|
}
|
|
|
+ if (!wholePatientRecord(patientTexts, modelMap) || patientTexts.size() == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //数据完整后才放入病案首页
|
|
|
+ list.add(firstPageTextMap);
|
|
|
for (PatientText patientText : patientTexts) {
|
|
|
-System.out.println(patientText.getBrzyid() + " " + patientText.getBljlmc());
|
|
|
+//System.out.println(patientText.getBrzyid() + " " + patientText.getBljlmc());
|
|
|
Map<String, Object> patientTextMap = new HashMap<>();
|
|
|
patientTextMap.put("case_number", patientText.getBrzyid());
|
|
|
patientTextMap.put("case_number_id", patientMap.get(patientText.getBrzyid()));
|
|
|
patientTextMap.put("hospital_id", hospitalId);
|
|
|
-System.out.println("******" + patientText.getBljlmc() + "**" + caseMap.get(patientText.getBljlmc()));
|
|
|
+//System.out.println("******" + patientText.getBljlmc() + "**" + caseMap.get(patientText.getBljlmc()));
|
|
|
patientTextMap.put("mode_id", modelMap.get(caseMap.get(patientText.getBljlmc())));
|
|
|
|
|
|
if (patientTextMap.get("mode_id") == null) {
|
|
@@ -89,7 +115,7 @@ System.out.println("******" + patientText.getBljlmc() + "**" + caseMap.get(patie
|
|
|
String text = "";
|
|
|
Map<String, String> textMap = new HashMap<>();
|
|
|
if ("changx".equals(cid)) {
|
|
|
-
|
|
|
+ textMap = CxXmlUtil.beHospitalizedXmlToMap(patientText.getBljlnr(), caseMap.get(patientText.getBljlmc()));
|
|
|
}
|
|
|
if ("taizhou".equals(cid)) {
|
|
|
textMap = TzXmlUtil.getXmlToMapForTZ(patientText.getBljlnr());
|
|
@@ -102,6 +128,35 @@ System.out.println("******" + patientText.getBljlmc() + "**" + caseMap.get(patie
|
|
|
}
|
|
|
}
|
|
|
initMysqlJdbc().insert(list, "qc_model_mapping", new String[]{"case_number", "case_number_id", "origin_text", "mode_id", "text"});
|
|
|
+
|
|
|
+ deletePatientInfos(deletePatient);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证数据完整性
|
|
|
+ * @param patientTexts
|
|
|
+ * @param modelMap
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean wholePatientRecord(List<PatientText> patientTexts, Map<String, String> modelMap) {
|
|
|
+ Map<String, String> m = new HashMap<>();
|
|
|
+ for (PatientText patientText : patientTexts) {
|
|
|
+ String modelId = modelMap.get(caseMap.get(patientText.getBljlmc()));
|
|
|
+ if (StringUtils.isEmpty(modelId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (modelId.equals("1") && patientText.getBljlnr().indexOf("<") != 0) {
|
|
|
+ deletePatient.add(patientTexts.get(0).getBrzyid());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ m.put(modelId, modelId);
|
|
|
+ }
|
|
|
+ if (m.get("1") != null && m.get("2") != null && m.get("4") != null && m.get("5") != null) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ deletePatient.add(patientTexts.get(0).getBrzyid());
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
private List<Patient> loadOraclePatients(String tableName) {
|
|
@@ -164,7 +219,6 @@ System.out.println("******" + patientText.getBljlmc() + "**" + caseMap.get(patie
|
|
|
}
|
|
|
return patientTexts;
|
|
|
}
|
|
|
-
|
|
|
private List<PatientText> loadChangxOraclePatientTexts(String brzyid) {
|
|
|
MysqlJdbc mysqlJdbc = initOracleJdbc();
|
|
|
Connection conn = mysqlJdbc.connect();
|
|
@@ -174,8 +228,8 @@ System.out.println("******" + patientText.getBljlmc() + "**" + caseMap.get(patie
|
|
|
List<PatientText> patientTexts = new ArrayList<>();
|
|
|
try {
|
|
|
st = conn.createStatement();
|
|
|
- String sql = "select brzyid,bljlmc,bljlnr from MR_MEDICALRECORDS_CX20200327 a " +
|
|
|
- "left join MR_MRCONTENT_CX20200327 b on a.bljlid=b.bljlid " +
|
|
|
+ String sql = "select brzyid,bllbid,bljlnr from MR_MEDICALRECORDS_CX a " +
|
|
|
+ "left join MR_MRCONTENT_CX b on a.bljlid=b.bljlid " +
|
|
|
"where bljlnr is not null and brzyid = '" + brzyid + "' " +
|
|
|
"order by brzyid";
|
|
|
rs = st.executeQuery(sql);
|
|
@@ -304,6 +358,27 @@ System.out.println("******" + patientText.getBljlmc() + "**" + caseMap.get(patie
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void deletePatientInfos(List<String> caseNumbers) {
|
|
|
+ MysqlJdbc mysqlJdbc = initMysqlJdbc();
|
|
|
+ Connection conn = mysqlJdbc.connect();
|
|
|
+ Statement st = null;
|
|
|
+ ResultSet rs = null;
|
|
|
+ String r1, r2;
|
|
|
+ try {
|
|
|
+ st = conn.createStatement();
|
|
|
+ for (String caseNumber : caseNumbers) {
|
|
|
+ String sql = "delete from qc_cases_number where case_number = '" + caseNumber + "'";
|
|
|
+ st.execute(sql);
|
|
|
+ }
|
|
|
+ } catch (SQLException sqle) {
|
|
|
+ sqle.printStackTrace();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ mysqlJdbc.close(rs, st, conn);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private MysqlJdbc initMysqlJdbc() {
|
|
|
PropertiesUtil propertiesUtil = new PropertiesUtil("kernel.properties");
|
|
|
MysqlJdbc mysqlJdbc = new MysqlJdbc(propertiesUtil.getProperty("mysql.test.user"),
|