ViewController.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. package com.zskk.control;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.jfinal.core.Controller;
  5. import com.jfinal.kit.HashKit;
  6. import com.jfinal.kit.PropKit;
  7. import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
  8. import com.jfinal.plugin.activerecord.Db;
  9. import com.jfinal.plugin.activerecord.Record;
  10. import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
  11. import com.jfinal.plugin.activerecord.dialect.OracleDialect;
  12. import com.jfinal.plugin.activerecord.dialect.SqlServerDialect;
  13. import com.jfinal.plugin.druid.DruidPlugin;
  14. import com.jfinal.plugin.redis.RedisPlugin;
  15. import com.zskk.model.*;
  16. import okhttp3.FormBody;
  17. import okhttp3.OkHttpClient;
  18. import okhttp3.Request;
  19. import okhttp3.RequestBody;
  20. import okhttp3.Response;
  21. import org.apache.commons.codec.digest.DigestUtils;
  22. import java.io.BufferedReader;
  23. import java.io.IOException;
  24. import java.io.InputStreamReader;
  25. import java.io.PrintWriter;
  26. import java.io.UnsupportedEncodingException;
  27. import java.net.URLEncoder;
  28. import java.text.ParseException;
  29. import java.text.SimpleDateFormat;
  30. import java.util.*;
  31. public class ViewController extends Controller {
  32. private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
  33. // static{
  34. // PropKit.use("config.properties");
  35. // DruidPlugin plugin = new DruidPlugin(PropKit.get("jdbcUrl_zskk"), PropKit.get("user_zskk"), PropKit.get("password_zskk").trim());
  36. // ActiveRecordPlugin arp = new ActiveRecordPlugin(plugin);
  37. // _MappingKit.mapping(arp);
  38. // plugin.start();
  39. // arp.start();
  40. //
  41. // }
  42. /**
  43. * 在被连接数据库执行sql语句
  44. */
  45. public void executeSql() {
  46. try {
  47. List<Record> d = Db.use("connected").find("select top 5 * from reportinfo");
  48. this.renderJson(d);
  49. } catch (Exception e) {
  50. // TODO: handle exception
  51. this.renderText(e.toString());
  52. }
  53. }
  54. public void executeSql2() {
  55. try {
  56. String sqlString = this.getPara("str");
  57. List<Record> d = Db.use("connected").find(sqlString);
  58. this.renderJson(d);
  59. } catch (Exception e) {
  60. // TODO: handle exception
  61. this.renderText(e.toString());
  62. }
  63. }
  64. public void executeSql3() {
  65. try {
  66. DruidPlugin druidPluginConnected = createConnectedDruidPlugin();
  67. druidPluginConnected.start();
  68. // 配置ActiveRecord插件
  69. ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("connected", druidPluginConnected);
  70. arpConnected.setDialect(new SqlServerDialect());
  71. arpConnected.start();
  72. } catch (Exception e) {
  73. // TODO: handle exception
  74. this.renderText(e.toString());
  75. }
  76. }
  77. public static DruidPlugin createConnectedDruidPlugin() {
  78. return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());
  79. }
  80. public static DruidPlugin createZskkDruidPlugin() {
  81. return new DruidPlugin("jdbc:mysql://47.104.6.21:3306/pacsonline?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false", "pacs","ZSKK@2017~!@#");
  82. }
  83. public static void testTask() {
  84. try {
  85. String string = "here";
  86. String jString = "{\"birthdate\":\"1976-04-21 00:00:00\",\"modality\":\"MR\",\"patientid\":\"030419456\",\"patientsex\":\"女\",\"reportPaperNum\":740386,\"reportdate\":\"2020-01-08 16:13:06\",\"diagnosis\":\"上颌骨恶性肿瘤\",\"accessionNumber\":\"17822\",\"patientname\":\"王晓艳\",\"symptom\":\"上颌骨恶性肿瘤\",\"clinicaldoctor\":\"周宏\",\"phone\":\"13836302692\",\"DESCRIPTION\":\" 右侧上颌窦呈术后改变,上颌窦窦壁、部分鼻甲及右侧上腭部局部缺如。右侧上颌窦壁及鼻翼旁皮下软组织不均匀增厚,其内信号欠均,T1WI呈等、稍低信号,T2脂肪抑制呈不均匀稍高信号,增强扫描呈不均匀强化。右侧翼外肌内可见片状异常信号影,T1WI及T2脂肪抑制均呈低信号,增强扫描未见明显强化。双侧颈深部Ⅱ-Ⅳ区及咽旁可见多发结节影,T1WI呈低信号,T2脂肪抑制呈高信号,增强扫描呈不均匀中等强化,大者约为1.7*0.9*2.8cm。右侧筛窦及乳突内可见长T1长T2信号影,增强扫描未见强化。\\r\\n\\r\\n\",\"printreport\":false,\"idcard\":\"231003197604211648\",\"patientage\":\"43岁\",\"impression\":\" 1、右侧上颌窦呈术后改变,上颌窦窦壁、部分鼻甲及右侧上腭部局部缺如:右侧上颌窦壁及鼻翼旁皮下软组织不均匀增厚,右侧翼外肌双低信号,考虑术后改变伴周围软组织水肿,请以此为基准片定期复查。\\r\\n2、双侧颈深及左侧咽旁多发淋巴结增大,请追随。\\r\\n3、右侧副鼻窦炎、中耳炎。\\r\\n\",\"regPaperNum\":\"894136\",\"reviewdoctor\":\"杨波\",\"department\":\"放疗三科\",\"studyuid\":\"17822\",\"printfilm\":false,\"reportdoctor\":\"刘媛\"}";
  87. List<Exams> exams = Exams.dao.find("SELECT * FROM pacsonline.exams where id='116f84268cc9186a'");
  88. for (Exams exams2 : exams) {
  89. //Studies studies = Studies.dao.use("zskk").findById(exams2.getStudyId());
  90. // Record record = Db.use("connected").findFirst("select * from zskk where accessionNumber=?",exams2.getAccessionNum());
  91. // Record record = (Record)JSON.parse(jString);
  92. JSONObject record = JSON.parseObject(jString);
  93. if (record == null) {
  94. continue;
  95. }
  96. Report report = new Report().use("zskk");
  97. report.setId(creatId());
  98. report.setReportDatetime(parseStringToDate(record.getString("reportdate")));
  99. if (record.getString("impression") == null || record.getString("DESCRIPTION") == null || record.getString("impression").isBlank() || record.getString("DESCRIPTION").isBlank()) {
  100. continue;
  101. }
  102. report.setImpression(record.getString("impression"));
  103. report.setDescription(record.getString("DESCRIPTION"));
  104. report.setExamId(exams2.getId());
  105. report.setCreatedAt(new Date());
  106. report.setReportDoctorId(getDoctorIdByName(record.getString("reportdoctor")));
  107. report.setReviewDoctorId(getDoctorIdByName(record.getString("reviewdoctor")));
  108. report.setReviewDatetime(parseStringToDate(record.getString("reportdate")));
  109. report.setConfirmDoctorId(getDoctorIdByName(record.getString("reviewdoctor")));
  110. report.setConfirmDatetime(parseStringToDate(record.getString("reportdate")));
  111. // report.save();
  112. PatientInfos patientInfos = PatientInfos.dao.findById(exams2.getPatientId());
  113. patientInfos.setName(record.getString("patientname"));
  114. patientInfos.setPhone(record.getString("phone"));
  115. patientInfos.setCardNum(record.getString("idcard"));
  116. // patientInfos.update();
  117. exams2.setExamStatus(9);
  118. exams2.setClinDoctors(record.getString("clinicaldoctor"));
  119. exams2.setApplicationDepartment(record.getString("department"));
  120. exams2.setApplicationDoctor(record.getString("clinicaldoctor"));
  121. exams2.setClinDiag(record.getString("diagnosis"));
  122. // exams2.update();
  123. //传云医康 数据
  124. Map<String, String> data = new HashMap<String, String>();
  125. //获取data数据
  126. //医院id
  127. data.put("hospital_id","15700002");
  128. //影像所见
  129. data.put("description",record.getString("DESCRIPTION"));
  130. //意见建议
  131. data.put("impression",record.getString("impression"));
  132. //检查id
  133. data.put("exam_id",exams2.getId());
  134. //患者id
  135. data.put("patient_id",exams2.getPatientId());
  136. data.put("study_id",exams2.getStudyId());
  137. //患者姓名
  138. data.put("patient_name",record.getString("patientname"));
  139. //患者性别
  140. data.put("patient_sex",record.getString("patientsex").equals("女")?"F":"M");
  141. //身份证号
  142. data.put("card_num","");
  143. //手机号
  144. data.put("phone","");
  145. //患者生日
  146. data.put("birthday",returnSecondTimestamp(record.getString("birthdate")));
  147. //患者检查时年龄
  148. data.put("patient_age",patientInfos.getAge());
  149. //阴阳性 1阴性 2阳性
  150. data.put("report_result","");
  151. //报告时间 10位时间戳
  152. data.put("report_datetime",returnSecondTimestamp(record.getString("reportdate")));
  153. //报告医生id
  154. data.put("report_doctor_id",record.getString("reportdoctor"));
  155. //报告医生姓名
  156. data.put("report_doctor_name",record.getString("reportdoctor"));
  157. //审核时间
  158. data.put("review_datetime",returnSecondTimestamp(record.getString("reportdate")));
  159. //审核医生id
  160. data.put("review_doctor_id",record.getString("reviewdoctor"));
  161. //审核姓名
  162. data.put("review_doctor_name",record.getString("reviewdoctor"));
  163. //确认时间
  164. data.put("confirm_datetime", returnSecondTimestamp(record.getString("reportdate")));
  165. //确认医生id
  166. data.put("confirm_doctor_id", record.getString("reviewdoctor"));
  167. //确认医生姓名
  168. data.put("confirm_doctor_name",record.getString("reviewdoctor"));
  169. // System.out.println(data);
  170. //调用接口
  171. // String s = post(null, data);
  172. //// string = string+s;
  173. // String ssString = data.toString();
  174. //
  175. //// String ssString = "{\"birthday\":\"-937382400\",\"review_datetime\":\"1577608513\",\"review_doctor_name\":\"王宪\",\"confirm_doctor_id\":\"王宪\",\"description\":\"所示胸腰椎及骨盆未见骨质异常;rn双侧膈下见气体密度影;rn腹部肠管内积气伴局部扩张;rn腰大肌影清晰;腹壁软组织影未见异常;rn胆囊区、肾区、输尿管区、膀胱区未见阳性结石影;rn双肾轮廓显影欠清;隐约可见;未见明显形态改变;rn腹部未见异常软组织团块影,未见异常钙化影。rn\",\"study_id\":\"116f50c27d705e37\",\"hospital_id\":\"15700002\",\"confirm_datetime\":\"1577608513\",\"card_num\":\"\",\"patient_sex\":\"M\",\"phone\":\"\",\"report_doctor_id\":\"王宪\",\"patient_id\":\"116f50c27d46d081\",\"report_doctor_name\":\"王宪\",\"patient_name\":\"赵清标\",\"impression\":\"1、膈下游离气体,考虑气腹,请结合临床rn2、腹部肠管扩张、积气,请结合临床。rn\",\"review_doctor_id\":\"王宪\",\"report_datetime\":\"1577608513\",\"patient_age\":\"79岁\",\"report_result\":\"\",\"confirm_doctor_name\":\"王宪\",\"exam_id\":\"116f50c27d8a1bc5\"}";
  176. // Map maps = (Map)JSON.parse(ssString);
  177. // System.out.println(ssString);
  178. String ssString=JSON.toJSONString(data);
  179. System.out.println(ssString);
  180. ssString = ssString.replace("\\r\\n","");
  181. ssString = ssString.replace(" ","");
  182. ssString = ssString.replace("、",",");
  183. ssString = ssString.replace("*","乘");
  184. Map maps = (Map)JSON.parse(ssString);
  185. post(null, maps);
  186. }
  187. System.out.println(string);
  188. // this.renderText(string);
  189. } catch (Exception e) {
  190. // TODO: handle exception
  191. // this.renderText(e.toString());
  192. System.out.println(e.toString());
  193. }
  194. }
  195. public static String getSign(Map<String, String> param, String key) {
  196. return DigestUtils.md5Hex(Ksort(param) + key);
  197. }
  198. public static String getSecondTimestamp(Date date) {
  199. if (null == date) {
  200. return "参数为空";
  201. }
  202. String timestamp = String.valueOf(date.getTime());
  203. int length = timestamp.length();
  204. if (length > 3) {
  205. return String.valueOf(timestamp.substring(0, length - 3));
  206. } else {
  207. return "参数不足3位数";
  208. }
  209. }
  210. private static String creatId() {
  211. UUID id = UUID.randomUUID();
  212. String[] idd= id.toString().split("-");
  213. return idd[0]+idd[1]+idd[2];
  214. }
  215. private static String getDoctorIdByName(String name) {
  216. if (name == null || name.isBlank()) {
  217. return null;
  218. }
  219. name = name.replace(" ", "");
  220. Doctors doctors = Doctors.dao.findFirst("SELECT * FROM doctors where instr(?,realname) and institution_id=15700002 and realname <>''",name);
  221. if (doctors == null) {
  222. Doctors newDoctors = new Doctors().use("zskk");
  223. newDoctors.setId(creatId());
  224. newDoctors.setUsername("none");
  225. newDoctors.setRealname(name);
  226. newDoctors.setPassword("123456");
  227. newDoctors.setInstitutionId("15700002");
  228. newDoctors.setCreatedAt(new Date());
  229. newDoctors.setUpdatedAt(new Date());
  230. // newDoctors.save();
  231. return newDoctors.getId();
  232. }
  233. return doctors.getId();
  234. }
  235. private static Date parseStringToDate(String dateStr) {
  236. if (dateStr == null) {
  237. return new Date();
  238. }
  239. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  240. Date date = null;
  241. try {
  242. date = sdf.parse(dateStr);
  243. } catch (ParseException e) {
  244. // TODO Auto-generated catch block
  245. e.printStackTrace();
  246. }
  247. return date;
  248. }
  249. public static String sendPost(String url, Map<String, String> parameters) {
  250. String result = "";// 返回的结果
  251. BufferedReader in = null;// 读取响应输入流
  252. PrintWriter out = null;
  253. StringBuffer sb = new StringBuffer();// 处理请求参数
  254. String params = "";// 编码之后的参数
  255. try {
  256. // 编码请求参数
  257. if (parameters.size() == 1) {
  258. for (String name : parameters.keySet()) {
  259. sb.append(name).append("=").append(
  260. java.net.URLEncoder.encode(parameters.get(name),
  261. "UTF-8"));
  262. }
  263. params = sb.toString();
  264. } else {
  265. for (String name : parameters.keySet()) {
  266. sb.append(name).append("=").append(
  267. java.net.URLEncoder.encode(parameters.get(name),
  268. "UTF-8")).append("&");
  269. }
  270. String temp_params = sb.toString();
  271. params = temp_params.substring(0, temp_params.length() - 1);
  272. }
  273. // 创建URL对象
  274. java.net.URL connURL = new java.net.URL(url);
  275. // 打开URL连接
  276. java.net.HttpURLConnection httpConn = (java.net.HttpURLConnection) connURL
  277. .openConnection();
  278. // 设置通用属性
  279. httpConn.setRequestProperty("Accept", "*/*");
  280. httpConn.setRequestProperty("Connection", "Keep-Alive");
  281. httpConn.setRequestProperty("User-Agent",
  282. "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
  283. // 设置POST方式
  284. httpConn.setDoInput(true);
  285. httpConn.setDoOutput(true);
  286. // 获取HttpURLConnection对象对应的输出流
  287. out = new PrintWriter(httpConn.getOutputStream());
  288. // 发送请求参数
  289. out.write(params);
  290. // flush输出流的缓冲
  291. out.flush();
  292. // 定义BufferedReader输入流来读取URL的响应,设置编码方式
  293. in = new BufferedReader(new InputStreamReader(httpConn
  294. .getInputStream(), "UTF-8"));
  295. String line;
  296. // 读取返回的内容
  297. while ((line = in.readLine()) != null) {
  298. result += line;
  299. }
  300. System.out.println(result);
  301. return result;
  302. } catch (Exception e) {
  303. e.printStackTrace();
  304. } finally {
  305. try {
  306. if (out != null) {
  307. out.close();
  308. }
  309. if (in != null) {
  310. in.close();
  311. }
  312. } catch (IOException ex) {
  313. ex.printStackTrace();
  314. }
  315. }
  316. return result;
  317. }
  318. private static void post(String url, Map<String, String> map) throws IOException {
  319. RequestBody formBody = new FormBody.Builder()
  320. .add("timestamp", String.valueOf(getSecondTimestamp(new Date())))
  321. .add("signature", Ksort(map))
  322. .add("data", JSON.toJSONString(map))
  323. .build();
  324. System.out.println(String.valueOf(getSecondTimestamp(new Date())));
  325. System.out.println(Ksort(map));
  326. System.out.println(JSON.toJSONString(map));
  327. Request request = new Request.Builder()
  328. .url("http://39.106.136.96/pacs/zskk/writePatientReport")
  329. .post(formBody)
  330. .build();
  331. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  332. if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  333. System.out.println(response.body().string());
  334. // return response.body().string();
  335. //
  336. }
  337. }
  338. public static String Ksort(Map<String, String> map){
  339. String sb = "";
  340. String[] key = new String[map.size()];
  341. int index = 0;
  342. for (String k : map.keySet()) {
  343. key[index] = k;
  344. index++;
  345. }
  346. Arrays.sort(key);
  347. for (String s : key) {
  348. sb += s + "=" + map.get(s) + "&";
  349. }
  350. sb = sb.substring(0, sb.length() - 1);
  351. System.out.println("***"+sb);
  352. try {
  353. sb = URLEncoder.encode(sb, "UTF-8");
  354. } catch (UnsupportedEncodingException e) {
  355. e.printStackTrace();
  356. }// 使用常见的UTF-8编码
  357. sb = sb.replace("%3D", "=").replace("%26", "&");
  358. System.out.println("**"+sb);
  359. String resultString = HashKit.md5(sb+"YgpxjVeIx0yoK6Atz413IAj7hU9dygH4");
  360. return resultString;
  361. }
  362. public static String returnSecondTimestamp(String data) throws ParseException {
  363. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  364. return String.valueOf(sdf.parse(data).getTime()/1000);
  365. }
  366. public static void main(String[] args) {
  367. try {
  368. String ssString = returnSecondTimestamp("1955-03-17 00:00:00");
  369. System.out.println(ssString);
  370. } catch (ParseException e) {
  371. // TODO Auto-generated catch block
  372. e.printStackTrace();
  373. }
  374. // testTask();
  375. }
  376. }