ViewController.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. package com.zskk.control;
  2. import java.io.BufferedOutputStream;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. import java.text.ParseException;
  10. import java.text.SimpleDateFormat;
  11. import java.util.Date;
  12. import java.util.HashMap;
  13. import java.util.List;
  14. import java.util.Map;
  15. import com.alibaba.fastjson.JSON;
  16. import com.alibaba.fastjson.JSONArray;
  17. import com.alibaba.fastjson.JSONObject;
  18. import com.aliyun.oss.OSS;
  19. import com.aliyun.oss.OSSClientBuilder;
  20. import com.jfinal.core.Controller;
  21. import com.jfinal.kit.PropKit;
  22. import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
  23. import com.jfinal.plugin.activerecord.Db;
  24. import com.jfinal.plugin.activerecord.Record;
  25. import com.jfinal.plugin.activerecord.dialect.OracleDialect;
  26. import com.jfinal.plugin.activerecord.dialect.SqlServerDialect;
  27. import com.jfinal.plugin.druid.DruidPlugin;
  28. import com.zskk.service.DataService;
  29. import com.zskk.service.ServiceFactory;
  30. import com.zskk.service.ThreadPoolService;
  31. import okhttp3.FormBody;
  32. import okhttp3.MediaType;
  33. import okhttp3.OkHttpClient;
  34. import okhttp3.Request;
  35. import okhttp3.RequestBody;
  36. import okhttp3.Response;
  37. public class ViewController extends Controller {
  38. private static final MediaType JSON_CODE = MediaType.get("application/json; charset=utf-8");
  39. private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
  40. /**
  41. * 在被连接数据库执行sql语句
  42. */
  43. public void executeSql() {
  44. try {
  45. List<Record> d = Db.use("connected").find(this.getPara("sqlstr"));
  46. this.renderJson(d);
  47. } catch (Exception e) {
  48. // TODO: handle exception
  49. this.renderText(e.toString());
  50. }
  51. }
  52. /**
  53. * 在被连接数据库执行sql语句
  54. */
  55. public void executeSqlprint() {
  56. try {
  57. List<Record> d = Db.use("print").find(this.getPara("sqlstr"));
  58. this.renderJson(d);
  59. } catch (Exception e) {
  60. // TODO: handle exception
  61. this.renderText(e.toString());
  62. }
  63. }
  64. /**
  65. * 在被连接数据库执行sql语句
  66. */
  67. public void executeSqlUpdate() {
  68. try {
  69. Integer d = Db.use("connected").update(this.getPara("sqlstr"));
  70. this.renderText(d.toString());
  71. } catch (Exception e) {
  72. // TODO: handle exception
  73. this.renderText(e.toString());
  74. }
  75. }
  76. public void testConn() {
  77. try {
  78. DruidPlugin druidPluginConnected = createConnectedDruidPlugin();
  79. druidPluginConnected.start();
  80. // 配置ActiveRecord插件
  81. ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("connected", druidPluginConnected);
  82. arpConnected.setDialect(new OracleDialect());
  83. arpConnected.start();
  84. } catch (Exception e) {
  85. // TODO: handle exception
  86. this.renderText(e.toString());
  87. }
  88. }
  89. //调阅记录
  90. public void dyjl2pacs() {
  91. try {
  92. DataService dService = ServiceFactory.getService(DataService.class);
  93. JSONArray jsonArray = dService.getBindList(this.getPara("sdate"),this.getPara("edate"));
  94. for (Object object : jsonArray) {
  95. try {
  96. JSONObject jsonObject = JSON.parseObject(object.toString());
  97. String source = "";
  98. String[] sources = jsonObject.getString("source").split(",");
  99. for (int i = 0; i < sources.length; i++) {
  100. switch (sources[i]) {
  101. case "1":
  102. String sp1 = i==0?"":",";
  103. source = source + sp1+ "数字影像云公众号";
  104. break;
  105. case "2":
  106. String sp2 = i==0?"":",";
  107. source = source +sp2+ "集成链接";
  108. break;
  109. case "3":
  110. String sp3 = i==0?"":",";
  111. source = source +sp3+ "推送短信";
  112. break;
  113. default:
  114. break;
  115. }
  116. }
  117. Record recordei = Db.use("connected").findFirst("select * from examinfo where studyuid=?", jsonObject.getString("studyuid"));
  118. Record recordrc = Db.use("connected").findFirst("select * from reportcheck where studyuid=?", jsonObject.getString("studyuid"));
  119. Record recordri = Db.use("connected").findFirst("select * from reportinfo where studyuid=?", jsonObject.getString("studyuid"));
  120. if (recordei==null && recordrc==null && recordri==null) {
  121. continue;
  122. }
  123. if (recordei!=null) {
  124. Db.use("connected").update("update examinfo set ViewFlag='1',ViewTime=?,ViewName=? where studyuid=?",jsonObject.getString("createdAt"),source,jsonObject.getString("studyuid"));
  125. }
  126. if (recordrc!=null) {
  127. Db.use("connected").update("update reportcheck set ViewFlag='1',ViewTime=?,ViewName=? where studyuid=?",jsonObject.getString("createdAt"),source,jsonObject.getString("studyuid"));
  128. }
  129. if (recordri!=null) {
  130. Db.use("connected").update("update reportinfo set ViewFlag='1',ViewTime=?,ViewName=? where studyuid=?",jsonObject.getString("createdAt"),source,jsonObject.getString("studyuid"));
  131. }
  132. } catch (Exception e) {
  133. // TODO: handle exception
  134. continue;
  135. }
  136. }
  137. renderJson(jsonArray);
  138. } catch (Exception e) {
  139. // TODO: handle exception
  140. renderText(e.toString());
  141. }
  142. }
  143. public void sdtb() {
  144. try {
  145. List<Record> records = Db.use("connected").find("select * from V_EXAM_INFO where 最后更新时间 > ?",parseStringToDate1());
  146. renderJson(records);
  147. } catch (Exception e) {
  148. // TODO: handle exception
  149. renderText(e.toString());
  150. }
  151. }
  152. //胶片匹配
  153. public void jppp() {
  154. DataService dService = ServiceFactory.getService(DataService.class);
  155. List<Record> records = Db.use("print").find("select * from IMAGEVIEW where ADDTIME >? order by ADDTIME asc",this.getPara("time"));
  156. for (Record record : records) {
  157. try {
  158. if (record == null) {
  159. continue;
  160. }
  161. Map<String, String> annex_params = new HashMap<>();
  162. annex_params.put("institution_id", PropKit.get("institution_id"));
  163. annex_params.put("type", "2");
  164. annex_params.put("code", record.getStr("CHECKID"));
  165. //附件类型1.mp4 2.pdf 3.jpeg 4.png
  166. annex_params.put("annex_class_code", "4");
  167. annex_params.put("exam_datetime", parseStringToDate2(record.getStr("ADDTIME")));
  168. dService.saveAnnex(annex_params, record.getStr("IMGURL"));
  169. } catch (Exception e) {
  170. // TODO: handle exception
  171. continue;
  172. }
  173. }
  174. renderText(records.toString());
  175. }
  176. //报告匹配
  177. public void bgpp() {
  178. DataService dService = ServiceFactory.getService(DataService.class);
  179. List<Record> records = Db.use("connected").find("select * from reportcheck where checktime >? order by checktime asc",this.getPara("time"));
  180. for (Record record : records) {
  181. try {
  182. if (record == null) {
  183. continue;
  184. }
  185. if (record.getStr("impression").isBlank() || record.getStr("description").isBlank()) {
  186. continue;
  187. }
  188. Map<String, String> params = new HashMap<>();
  189. // 1:exam_id 2:patient_num 3:accession_num 4:study_uid
  190. params.put("type", "4");
  191. params.put("institution_id", PropKit.get("institution_id"));
  192. params.put("code", record.getStr("studyuid"));
  193. // 报告医生姓名
  194. params.put("report_doctor_name", record.getStr("reportdoctor"));
  195. // 报告时间
  196. params.put("report_datetime", record.getStr("reportdate"));
  197. // 审核医生姓名
  198. params.put("review_doctor_name",
  199. record.getStr("reviewdoctor") == null ? "" : record.getStr("reviewdoctor"));
  200. // 审核时间
  201. params.put("review_datetime", record.getStr("checktime"));
  202. // 确认医生姓名
  203. params.put("confirm_doctor_name",
  204. record.getStr("reviewdoctor") == null ? "" : record.getStr("reviewdoctor"));
  205. // 确认时间
  206. params.put("confirm_datetime", record.getStr("checktime"));
  207. // 意见建议
  208. params.put("impression", record.getStr("impression"));
  209. // 影像所见
  210. params.put("description", record.getStr("description"));
  211. // exams表
  212. // 申请科室
  213. params.put("application_department", record.getStr("department") == null ? "" : record.getStr("department"));
  214. // 申请医生
  215. params.put("application_doctor", record.getStr("clinicaldoctor") == null ? "" : record.getStr("clinicaldoctor"));
  216. // 临床诊断
  217. params.put("clin_diag", record.getStr("diagnosis") == null ? "" : record.getStr("diagnosis"));
  218. // 症状
  219. params.put("clin_symp", record.getStr("symptom") == null ? "" : record.getStr("symptom"));
  220. // patient_infos表
  221. // 患者姓名
  222. params.put("name", record.getStr("patientname"));
  223. // 患者手机号
  224. params.put("phone", record.getStr("phone") == null ? "" : record.getStr("phone"));
  225. // 患者身份证号
  226. params.put("card_num", record.getStr("idcard") == null ? "" : record.getStr("idcard"));
  227. // 检查结果1阴2阳
  228. params.put("report_result", "0");
  229. // 门诊号住院号
  230. params.put("hopitalized_no", "");
  231. params.put("exam_project", record.getStr("JianchaMingcheng") == null ? "" : record.getStr("JianchaMingcheng"));
  232. params.put("exam_method", record.getStr("JianchaFangfa") == null ? "" : record.getStr("JianchaFangfa"));
  233. ThreadPoolService tService = ServiceFactory.getService(ThreadPoolService.class);
  234. tService.execute(() -> {
  235. dService.saveReport(params);
  236. });
  237. Map<String, String> annex_params = new HashMap<>();
  238. annex_params.put("institution_id", PropKit.get("institution_id"));
  239. annex_params.put("type", "4");
  240. annex_params.put("code", record.getStr("studyuid"));
  241. //附件类型1.mp4 2.pdf 3.jpeg
  242. annex_params.put("annex_class_code", "3");
  243. dService.saveAnnex(annex_params, record.getStr("reportpath"));
  244. } catch (Exception e) {
  245. // TODO: handle exception
  246. continue;
  247. }
  248. }
  249. renderText(records.toString());
  250. }
  251. //打印数量匹配
  252. public void dypp() {
  253. DataService dService = ServiceFactory.getService(DataService.class);
  254. List<Record> records = Db.use("print").find("select * from IMAGEVIEW where PRINTED=? and PRINTTIME >?","true",this.getPara("time"));
  255. for (Record record : records) {
  256. try {
  257. if (record == null) {
  258. continue;
  259. }
  260. //2ct 3ct 4mr
  261. if (record.getStr("IAET").equals("4")) {
  262. continue;
  263. }
  264. Map<String, String> annex_params = new HashMap<>();
  265. annex_params.put("institution_id", PropKit.get("institution_id"));
  266. annex_params.put("type", "2");
  267. annex_params.put("code", record.getStr("CHECKID"));
  268. annex_params.put("print_time", record.getStr("PRINTTIME"));
  269. dService.savePrint(annex_params);
  270. } catch (Exception e) {
  271. // TODO: handle exception
  272. continue;
  273. }
  274. }
  275. renderText(records.toString());
  276. }
  277. /**
  278. * 日期字符串格式转换
  279. * @param dateStr
  280. * @return
  281. */
  282. private String parseStringToDate3(String dateStr) {
  283. if (dateStr == null) {
  284. return "";
  285. }
  286. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  287. Date date = null;
  288. String timeString = null;
  289. try {
  290. date = sdf.parse(dateStr);
  291. SimpleDateFormat sdf2= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  292. timeString = sdf2.format(date);
  293. } catch (ParseException e) {
  294. // TODO Auto-generated catch block
  295. e.printStackTrace();
  296. }
  297. return timeString;
  298. }
  299. /**
  300. * 日期字符串格式转换
  301. *
  302. * @param dateStr
  303. * @return
  304. */
  305. private String parseStringToDate1() {
  306. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  307. Date date = new Date();
  308. String timeString = null;
  309. Long i = date.getTime();
  310. Long j = i - 600000;
  311. Date newdate = new Date(j);
  312. timeString = sdf.format(newdate);
  313. return timeString;
  314. }
  315. /**
  316. * 日期字符串格式转换
  317. * @param dateStr
  318. * @return
  319. */
  320. private String parseStringToDate2(String dateStr) {
  321. if (dateStr == null) {
  322. return "";
  323. }
  324. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  325. Date date = null;
  326. String timeString = null;
  327. try {
  328. date = sdf.parse(dateStr);
  329. SimpleDateFormat sdf2= new SimpleDateFormat("yyyyMMdd");
  330. timeString = sdf2.format(date);
  331. } catch (ParseException e) {
  332. // TODO Auto-generated catch block
  333. e.printStackTrace();
  334. }
  335. return timeString;
  336. }
  337. public static String getFileWithUrl(String url, String filename) {
  338. Request request = new Request.Builder().url(url).build();
  339. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  340. if (!response.isSuccessful())
  341. throw new IOException("Unexpected code " + response);
  342. InputStream inputStream = response.body().source().inputStream();
  343. // 本地文件夹目录(下载位置)
  344. String folder = PropKit.get("oss_localPath");
  345. // 下载文件保存位置
  346. String savepath = folder + "/" + filename;
  347. BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(savepath)));
  348. byte[] data = new byte[1024];
  349. int len;
  350. int available = inputStream.available();
  351. while ((len = inputStream.read(data)) != -1) {
  352. bufferedOutputStream.write(data, 0, len);
  353. }
  354. bufferedOutputStream.flush();
  355. bufferedOutputStream.close();
  356. inputStream.close();
  357. return savepath;
  358. } catch (IOException e) {
  359. // TODO Auto-generated catch block
  360. e.printStackTrace();
  361. return e.toString();
  362. }
  363. }
  364. public void testdld() {
  365. try {
  366. String filePath = "http://200.200.200.163:8090/X-0-202208261038400267000310351.PNG";
  367. String fileNameStr[] = filePath.split("/");
  368. String fileName = fileNameStr[fileNameStr.length - 1];
  369. String fileStorePath = getFileWithUrl(filePath, fileName);
  370. renderText(fileStorePath);
  371. } catch (Exception e) {
  372. // TODO: handle exception
  373. renderText(e.toString());
  374. }
  375. }
  376. public static DruidPlugin createConnectedDruidPlugin() {
  377. return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());
  378. }
  379. /**
  380. * post请求
  381. * @param url-请求地址
  382. * @param map-参数集合
  383. * @return
  384. */
  385. private static String doPost(String url, Map<String, String> map) {
  386. FormBody.Builder builder = new FormBody.Builder();
  387. for (String key : map.keySet()) {
  388. builder.add(key, map.get(key));
  389. }
  390. RequestBody formBody = builder.build();
  391. Request request = new Request.Builder().url(url).post(formBody).build();
  392. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  393. if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  394. String content = response.body().string();
  395. return content;
  396. } catch (IOException e) {
  397. // TODO Auto-generated catch block
  398. e.printStackTrace();
  399. return null;
  400. }
  401. }
  402. /**
  403. * 日期字符串格式转换
  404. * @param dateStr
  405. * @return
  406. */
  407. private Date parseStringToDate(String dateStr) {
  408. if (dateStr == null) {
  409. return new Date();
  410. }
  411. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  412. Date date = null;
  413. try {
  414. date = sdf.parse(dateStr);
  415. } catch (ParseException e) {
  416. // TODO Auto-generated catch block
  417. e.printStackTrace();
  418. }
  419. return date;
  420. }
  421. private String parseStringToDate() {
  422. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
  423. Date date = new Date();
  424. String timeString = sdf.format(date);
  425. return timeString;
  426. }
  427. }