ViewController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. package com.zskk.control;
  2. import java.io.BufferedReader;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7. import java.text.SimpleDateFormat;
  8. import java.util.ArrayList;
  9. import java.util.Date;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.Map;
  13. import org.w3c.dom.NamedNodeMap;
  14. import org.w3c.dom.NodeList;
  15. import com.jfinal.core.Controller;
  16. import com.jfinal.kit.PropKit;
  17. import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
  18. import com.jfinal.plugin.activerecord.Db;
  19. import com.jfinal.plugin.activerecord.Record;
  20. import com.jfinal.plugin.activerecord.dialect.SqlServerDialect;
  21. import com.jfinal.plugin.druid.DruidPlugin;
  22. import com.zskk.service.DataService;
  23. import com.zskk.service.ServiceFactory;
  24. import com.zskk.service.ThreadPoolService;
  25. import com.zskk.tools.ExecUtil;
  26. import com.zskk.tools.XmlHelper;
  27. import okhttp3.FormBody;
  28. import okhttp3.MediaType;
  29. import okhttp3.OkHttpClient;
  30. import okhttp3.Request;
  31. import okhttp3.RequestBody;
  32. import okhttp3.Response;
  33. public class ViewController extends Controller {
  34. private static final MediaType JSON_CODE = MediaType.get("application/json; charset=utf-8");
  35. private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
  36. /**
  37. * 在被连接数据库执行sql语句
  38. */
  39. public void executeSql() {
  40. List<Record> d = Db.use("connected").find(this.getPara("sqlstr"));
  41. this.renderJson(d);
  42. }
  43. public void testConn() {
  44. try {
  45. DruidPlugin druidPluginConnected = createConnectedDruidPlugin();
  46. druidPluginConnected.start();
  47. // 配置ActiveRecord插件
  48. ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("connected", druidPluginConnected);
  49. arpConnected.setDialect(new SqlServerDialect());
  50. arpConnected.start();
  51. } catch (Exception e) {
  52. // TODO: handle exception
  53. this.renderText(e.toString());
  54. }
  55. }
  56. public void test() {
  57. try {
  58. //延迟10分钟获取影像,并且查找状态为待CMOVE和错误状态的检查
  59. // List<Record> studyidfinds = Db.use("local").find("select * from study where status =1 and createAt<? order by createAt asc limit 1",parseStringToDate2());
  60. List<Record> studyidfinds = Db.use("local").find("select * from study where status =1 asc limit 1");
  61. if (studyidfinds == null) {
  62. return;
  63. }
  64. for (Record studyidfind : studyidfinds) {
  65. // flag++;
  66. // if (flag <= 5) {
  67. //状态4:下载中
  68. studyidfind.set("status", 4);
  69. studyidfind.set("updateAt", parseStringToDateTime());
  70. Db.use("local").update("study", studyidfind);
  71. // ThreadPoolService tService = ServiceFactory.getService(ThreadPoolService.class);
  72. // tService.execute(() -> {
  73. String execCmd = ExecUtil.execCmd("/zskk_system/other/cmove.sh " + studyidfind.getStr("studyuid"));
  74. if (execCmd.contains("Connection refused")) {
  75. //状态2:错误
  76. studyidfind.set("status", 2);
  77. studyidfind.set("updateAt", parseStringToDateTime());
  78. Db.use("local").update("study", studyidfind);
  79. }else {
  80. //状态2:完成
  81. studyidfind.set("status", 3);
  82. studyidfind.set("updateAt", parseStringToDateTime());
  83. Db.use("local").update("study", studyidfind);
  84. }
  85. // });
  86. // }
  87. }
  88. //延迟10分钟获取影像,并且查找状态为待CMOVE和错误状态的检查
  89. // List<Record> studyidfindsde = Db.use("local").find("select * from study where status =1 or status =2 and createAt<? order by createAt desc limit 1",parseStringToDate2());
  90. List<Record> studyidfindsde = Db.use("local").find("select * from study where status =1 or status =2 limit 1");
  91. if (studyidfindsde == null) {
  92. return;
  93. }
  94. for (Record studyidfind : studyidfindsde) {
  95. //状态4:下载中
  96. studyidfind.set("status", 4);
  97. studyidfind.set("updateAt", parseStringToDateTime());
  98. Db.use("local").update("study", studyidfind);
  99. // ThreadPoolService tService = ServiceFactory.getService(ThreadPoolService.class);
  100. // tService.execute(() -> {
  101. String execCmd = ExecUtil.execCmd("/zskk_system/other/cmove.sh " + studyidfind.getStr("studyuid"));
  102. if (execCmd.contains("Connection refused")) {
  103. //状态2:错误
  104. studyidfind.set("status", 2);
  105. studyidfind.set("updateAt", parseStringToDateTime());
  106. Db.use("local").update("study", studyidfind);
  107. }else {
  108. //状态2:完成
  109. studyidfind.set("status", 3);
  110. studyidfind.set("updateAt", parseStringToDateTime());
  111. Db.use("local").update("study", studyidfind);
  112. }
  113. // });
  114. // }
  115. }
  116. renderJson(studyidfindsde);
  117. } catch (Exception e) {
  118. // TODO: handle exception
  119. renderText(e.toString());
  120. }
  121. }
  122. public void sdcfind() {
  123. String execCmd = ExecUtil.execCmd("/zskk_system/other/cfind.sh " + this.getPara("time") + " STUDYUID_" + "temppp" + ".xml");
  124. if (execCmd.contains("Connection refused")) {
  125. return;
  126. }
  127. File fin_floder = new File("/home/zskk/CFIND_XML/STUDYUID_" + "temppp" + "1.xml");
  128. // 创建从文件读取数据的FileInputStream流
  129. FileInputStream fin;
  130. try {
  131. fin = new FileInputStream(fin_floder);
  132. InputStreamReader isr = null;
  133. isr = new InputStreamReader(fin);
  134. BufferedReader raf = null;
  135. raf = new BufferedReader(isr);
  136. String xmlContent = null;
  137. xmlContent = raf.readLine();
  138. xmlContent = xmlContent.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
  139. xmlContent = "<zskk>" + xmlContent + "</zskk>";
  140. xmlContent = xmlContent.replace("&#0", "");
  141. XmlHelper xmlHelper = XmlHelper.of(xmlContent);
  142. // NativeDicomModel节点列表
  143. NodeList nativeDicomModelList = xmlHelper.getNodeList("/zskk/NativeDicomModel");
  144. for (int i = 0; i < nativeDicomModelList.getLength(); i++) {
  145. String qString = "";
  146. String studyuidString = "";
  147. String modalitiesString = "";
  148. // DicomAttribute节点列表
  149. NodeList dicomAttributeList = xmlHelper.getNodeList(nativeDicomModelList.item(i), "DicomAttribute");
  150. for (int j = 0; j < dicomAttributeList.getLength(); j++) {
  151. // DicomAttribute节点属性列表
  152. NamedNodeMap attributeMap = dicomAttributeList.item(j).getAttributes();
  153. if (attributeMap != null && attributeMap.getLength() > 0) {
  154. for (int k = 0; k < attributeMap.getLength(); k++) {
  155. if (attributeMap.item(k).getNodeName().equals("tag")) {
  156. // 获取studyuid
  157. if (attributeMap.item(k).getNodeValue().equals("0020000D")) {
  158. studyuidString = xmlHelper.getString(dicomAttributeList.item(j), "Value");
  159. continue;
  160. }
  161. // 获取检查类型00080060or00080061
  162. if (attributeMap.item(k).getNodeValue().equals("00080060")) {
  163. modalitiesString = xmlHelper.getString(dicomAttributeList.item(j), "Value");
  164. }
  165. }
  166. }
  167. }
  168. }
  169. Record studyidfind = Db.use("local").findFirst("select * from study where studyuid = ?",
  170. studyuidString);
  171. if (studyidfind == null) {
  172. Record studyinfo = new Record().set("studyuid", studyuidString).set("modalities", modalitiesString)
  173. .set("status", 1).set("createAt", parseStringToDateTime()).set("updateAt", parseStringToDateTime());
  174. Db.use("local").save("study", studyinfo);
  175. }else {
  176. studyidfind.set("status", 2);
  177. Db.use("local").update("study", studyidfind);
  178. }
  179. }
  180. } catch (IOException e) {
  181. // TODO Auto-generated catch block
  182. e.printStackTrace();
  183. }
  184. }
  185. public void sdreview() {
  186. try {
  187. DataService dService = ServiceFactory.getService(DataService.class);
  188. List<Record> records = Db.use("connected").find(
  189. "SELECT * FROM (select * from reportinfo where REVIEWDATE>to_date(?,'YYYY-MM-DD HH24:MI:SS') and REVIEWDATE<to_date(?,'YYYY-MM-DD HH24:MI:SS') and rownum < 500)ORDER BY REVIEWDATE DESC",this.getPara("from"),this.getPara("to"));
  190. if (records == null) {
  191. return;
  192. }
  193. for (Record record : records) {
  194. try {
  195. if (record.getStr("IMPRESSION") == null && record.getStr("DESCRPTION") == null
  196. && record.getStr("REVIEWDOCTOR") == null) {
  197. continue;
  198. }
  199. Map<String, String> params = new HashMap<>();
  200. params.put("type", "4");
  201. params.put("institution_id", PropKit.get("institution_id"));
  202. params.put("code", record.getStr("STUDYUID"));
  203. // 报告医生姓名
  204. params.put("report_doctor_name", record.getStr("REPORTDOCTOR"));
  205. // 报告时间
  206. params.put("report_datetime", record.getStr("REVIEWDATE"));
  207. // 审核医生姓名
  208. params.put("review_doctor_name",
  209. record.getStr("REVIEWDOCTOR") == null ? "" : record.getStr("REVIEWDOCTOR"));
  210. // 审核时间
  211. params.put("review_datetime", record.getStr("REVIEWDATE"));
  212. // 确认医生姓名
  213. params.put("confirm_doctor_name",
  214. record.getStr("REVIEWDOCTOR") == null ? "" : record.getStr("REVIEWDOCTOR"));
  215. // 确认时间
  216. params.put("confirm_datetime", record.getStr("REVIEWDATE"));
  217. // 意见建议
  218. params.put("impression", record.getStr("IMPRESSION"));
  219. // 影像所见
  220. params.put("description", record.getStr("DESCRPTION"));
  221. // exams表
  222. // 申请科室
  223. params.put("application_department", record.getStr("DEPARTMENT"));
  224. // 申请医生
  225. params.put("application_doctor", record.getStr("CLINICALDOCTOR"));
  226. // 临床诊断
  227. params.put("clin_diag", record.getStr("DIAGNOSE") == null ? "" : record.getStr("DIAGNOSE"));
  228. // 症状
  229. params.put("clin_symp", record.getStr("SYMPROM") == null ? "" : record.getStr("SYMPROM"));
  230. // patient_infos表
  231. // 患者姓名
  232. params.put("name", record.getStr("PATIENTNAME"));
  233. // 患者手机号
  234. params.put("phone", record.getStr("PHONE") == null ? "" : record.getStr("PHONE"));
  235. // 患者身份证号
  236. params.put("card_num", record.getStr("IDCARD") == null ? "" : record.getStr("IDCARD"));
  237. // 检查结果1阴2阳
  238. params.put("report_result", record.getStr("RESULT").contains("阳") ? "2" : "1");
  239. // 门诊号住院号
  240. params.put("hopitalized_no", record.getStr("INPATIENTNUM") == null ? "" : record.getStr("INPATIENTNUM"));
  241. // 门诊号
  242. params.put("out_patient", record.getStr("OUTPATIENTNUM") == null ? "" : record.getStr("OUTPATIENTNUM"));
  243. // 病人ID
  244. params.put("his_patient_id", record.getStr("PATIENTID") == null ? "" : record.getStr("PATIENTID"));
  245. // 检查方法
  246. params.put("exam_project", record.getStr("PROIECT"));
  247. ThreadPoolService tService = ServiceFactory.getService(ThreadPoolService.class);
  248. tService.execute(() -> {
  249. dService.saveReport(params);
  250. });
  251. } catch (Exception e) {
  252. // TODO: handle exception
  253. continue;
  254. }
  255. }
  256. this.renderJson(records);
  257. } catch (Exception e) {
  258. // TODO: handle exception
  259. this.renderText(e.toString());
  260. }
  261. }
  262. public static DruidPlugin createConnectedDruidPlugin() {
  263. return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());
  264. }
  265. /**
  266. * post请求
  267. * @param url-请求地址
  268. * @param map-参数集合
  269. * @return
  270. */
  271. private static String doPost(String url, Map<String, String> map) {
  272. FormBody.Builder builder = new FormBody.Builder();
  273. for (String key : map.keySet()) {
  274. builder.add(key, map.get(key));
  275. }
  276. RequestBody formBody = builder.build();
  277. Request request = new Request.Builder().url(url).post(formBody).build();
  278. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  279. if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  280. String content = response.body().string();
  281. return content;
  282. } catch (IOException e) {
  283. // TODO Auto-generated catch block
  284. e.printStackTrace();
  285. return null;
  286. }
  287. }
  288. private String parseStringToDate() {
  289. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
  290. Date date = new Date();
  291. long dInteger = date.getTime() - 86400000;
  292. String daString = sdf.format(new Date(dInteger));
  293. return daString;
  294. }
  295. private String parseStringToDate2() {
  296. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  297. Date date = new Date();
  298. long dInteger = date.getTime() - 300000;
  299. String daString = sdf.format(new Date(dInteger));
  300. return daString;
  301. }
  302. /**
  303. * 日期字符串格式转换
  304. *
  305. * @param dateStr
  306. * @return
  307. */
  308. private String parseStringToDate1(String dString) {
  309. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
  310. Date date = new Date();
  311. long dInteger = date.getTime();
  312. String daString = sdf.format(new Date(dInteger));
  313. return daString;
  314. }
  315. /**
  316. * 日期字符串格式转换年月日时分秒
  317. *
  318. * @param dateStr
  319. * @return
  320. */
  321. private String parseStringToDateTime() {
  322. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  323. Date date = new Date();
  324. String daString = sdf.format(date);
  325. return daString;
  326. }
  327. /**
  328. * 获取当前时间
  329. * @param dateStr
  330. * @return
  331. */
  332. private String getNowDate() {
  333. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  334. Date date = new Date();
  335. //4小时
  336. Date lastDate = new Date(date.getTime()-172800000);
  337. String timeString = null;
  338. timeString = sdf.format(lastDate);
  339. return timeString;
  340. }
  341. }