ViewController.java 14 KB

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