DataService.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. package com.zskk.service;
  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.Base64;
  12. import java.util.Date;
  13. import java.util.HashMap;
  14. import java.util.List;
  15. import java.util.Map;
  16. import org.bouncycastle.crypto.CryptoException;
  17. import com.alibaba.fastjson.JSON;
  18. import com.alibaba.fastjson.JSONArray;
  19. import com.alibaba.fastjson.JSONObject;
  20. import com.aliyun.oss.OSS;
  21. import com.aliyun.oss.OSSClientBuilder;
  22. import com.aliyun.oss.model.PutObjectResult;
  23. import com.jfinal.kit.PropKit;
  24. import com.jfinal.plugin.activerecord.Record;
  25. import com.zskk.tools.SM4Utils;
  26. import okhttp3.FormBody;
  27. import okhttp3.OkHttpClient;
  28. import okhttp3.Request;
  29. import okhttp3.RequestBody;
  30. import okhttp3.Response;
  31. import com.zskk.tools.SM4Utils;
  32. public class DataService {
  33. private static String GET_EXAM_URL = "http://192.168.0.34:9600/zskkapi/butt/getExam";
  34. private static String SAVE_REPORT_URL = "http://192.168.0.34:9600/zskkapi/butt/saveReport";
  35. private static String GET_CONFIRM_EXAM_URL = "https://risserver3.pacsonline.cn/butt/getConfirmExam";
  36. private static String UPDATE_PATIENT_URL = "https://risserver3.pacsonline.cn/butt/saveExam";
  37. private static String RETURN_BIND_URL = "https://risserver3.pacsonline.cn/butt/getBindInfo";
  38. private static String SAVE_ANNEX_URL = "https://risserver3.pacsonline.cn/butt/saveAnnex";
  39. private static String SAVE_PRINT_URL = "https://risserver3.pacsonline.cn/butt/savePrint";
  40. private static String SAVE_EXAMINFO_URL = "http://10.200.199.136:9605/api/postExamInfo";
  41. private static String SAVE_EXAMREPORT_URL = "http://10.200.199.136:9605/api/postExamReport";
  42. private static String SAVE_LABREPORT_URL = "http://10.200.199.136:9605/api/postLabReport";
  43. // private static String SAVE_EXAMINFO_URL = "http://111.53.165.106:9605/api/postExamInfo";
  44. private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
  45. /**
  46. * 互认-检查信息
  47. *
  48. * @param instutionId
  49. * @param number
  50. */
  51. public String postExamInfo(Record record) {
  52. Map<String, String> params = new HashMap<>();
  53. params.put("request_time", "1");
  54. params.put("request_no", "2");
  55. JSONObject jsonObject = new JSONObject();
  56. JSONObject jsonObjectA = new JSONObject();
  57. jsonObjectA.put("AA", checkStr(record.getStr("AA")));
  58. jsonObjectA.put("AB", checkStr(record.getStr("AB")));
  59. jsonObjectA.put("AC", checkStr(record.getStr("AC")));
  60. jsonObjectA.put("AD", checkStr(record.getStr("AD")));
  61. jsonObjectA.put("AE", checkStr(record.getStr("AE")));
  62. jsonObjectA.put("AF", checkStr(record.getStr("AF")));
  63. jsonObjectA.put("AG", checkStr(record.getStr("AG")));
  64. JSONObject jsonObjectB = new JSONObject();
  65. jsonObjectB.put("BA", checkStr(record.getStr("BA")));
  66. jsonObjectB.put("BB", checkStr(record.getStr("BB")));
  67. jsonObjectB.put("BC", checkStr(record.getStr("BC")));
  68. jsonObjectB.put("BD", checkStr(record.getStr("BD")));
  69. jsonObjectB.put("BE", checkStr(record.getStr("BE")));
  70. jsonObjectB.put("BF", checkStr(record.getStr("BF")));
  71. jsonObjectB.put("BG", checkStr(record.getStr("BG")));
  72. jsonObjectB.put("BH", checkStr(record.getStr("BH")));
  73. jsonObjectB.put("BI", checkStr(record.getStr("BI")));
  74. jsonObjectB.put("BJ", checkStr(record.getStr("BJ")));
  75. jsonObjectB.put("BK", "12140300MB0351839N");
  76. jsonObjectB.put("BL", "阳泉煤业(集团)有限责任公司总医院");
  77. jsonObjectB.put("BM", checkStr(record.getStr("BM")));
  78. jsonObjectB.put("BN", checkStr(record.getStr("BN")));
  79. JSONObject jsonObjectC = new JSONObject();
  80. jsonObjectC.put("CA", checkStr(record.getStr("CA")));
  81. jsonObjectC.put("CB", checkStr(record.getStr("CB")));
  82. jsonObjectC.put("CC", checkStr(record.getStr("CC")));
  83. jsonObjectC.put("CD", checkStr(record.getStr("CD")));
  84. jsonObjectC.put("CE", checkStr(record.getStr("CE")));
  85. jsonObjectC.put("CF", checkStr(record.getStr("CF")));
  86. jsonObjectC.put("CG", checkStr(record.getStr("CG")));
  87. jsonObjectC.put("CH", checkStr(record.getStr("CH")));
  88. jsonObjectC.put("CI", checkStr(record.getStr("CI")));
  89. jsonObjectC.put("CJ", checkStr(record.getStr("CJ")));
  90. jsonObjectC.put("CK", checkStr(record.getStr("CK")));
  91. jsonObjectC.put("CL", checkStr(record.getStr("CL")));
  92. jsonObjectC.put("CM", checkStr(record.getStr("CM")));
  93. jsonObjectC.put("CN", checkStr(record.getStr("CN")));
  94. jsonObjectC.put("CO", checkStr(record.getStr("CO")));
  95. jsonObject.put("A", jsonObjectA);
  96. jsonObject.put("B", jsonObjectB);
  97. jsonObject.put("C", jsonObjectC);
  98. try {
  99. String encodedString = Base64.getEncoder().encodeToString(jsonObject.toJSONString().getBytes());
  100. params.put("data", SM4Utils.sm4Encrypt("zLxapoeqWYpoeqWY",encodedString));
  101. } catch (CryptoException e) {
  102. // TODO Auto-generated catch block
  103. e.printStackTrace();
  104. }
  105. String content = postWithParameters(SAVE_EXAMINFO_URL, params);
  106. return content;
  107. }
  108. /**
  109. * 互认-检查报告信息
  110. *
  111. * @param instutionId
  112. * @param number
  113. */
  114. public String postExamReport(Record record) {
  115. Map<String, String> params = new HashMap<>();
  116. params.put("request_time", "1");
  117. params.put("request_no", "3");
  118. JSONObject jsonObject = new JSONObject();
  119. JSONObject jsonObjectB = new JSONObject();
  120. jsonObjectB.put("BD", checkStr(record.getStr("检查号")));
  121. jsonObjectB.put("BJ", "121403004061412685");
  122. jsonObjectB.put("BK", "阳泉市第一人民医院");
  123. JSONObject jsonObjectC = new JSONObject();
  124. jsonObjectC.put("CA", checkStr(record.getStr("报告单编号")));
  125. jsonObjectC.put("CB", checkStr(record.getStr("检查类型")));
  126. jsonObjectC.put("CC", checkStr(record.getStr("检查部位")));
  127. jsonObjectC.put("CD", checkStr(record.getStr("检查所见")));
  128. jsonObjectC.put("CE", checkStr(record.getStr("影像诊断")));
  129. jsonObjectC.put("CF", checkStr(record.getStr("检查结果类别")));
  130. jsonObjectC.put("CG", checkStr(record.getStr("报告科室名称")));
  131. jsonObjectC.put("CH", checkStr(record.getStr("报告医生姓名")));
  132. jsonObjectC.put("CI", checkStr(record.getStr("审核医生姓名")));
  133. jsonObjectC.put("CJ", checkStr(record.getStr("报告时间")));
  134. jsonObjectC.put("CK", checkStr(record.getStr("审核时间")));
  135. jsonObjectC.put("CL", checkStr(record.getStr("检查时间")));
  136. jsonObjectC.put("CM", checkStr(record.getStr("危急值")));
  137. jsonObjectC.put("CN", checkStr(record.getStr("报告医生编码")));
  138. jsonObjectC.put("CO", checkStr(record.getStr("审核医生编码")));
  139. jsonObjectC.put("CP", checkStr(record.getStr("患者编号")));
  140. jsonObjectC.put("CQ", checkStr(record.getStr("报告单")));
  141. jsonObjectC.put("CR", checkStr(record.getStr("检查状态")));
  142. jsonObject.put("B", jsonObjectB);
  143. jsonObject.put("C", jsonObjectC);
  144. try {
  145. String encodedString = Base64.getEncoder().encodeToString(jsonObject.toJSONString().getBytes());
  146. params.put("data", SM4Utils.sm4Encrypt("zLxapoeqWYpoeqWY",encodedString));
  147. } catch (CryptoException e) {
  148. // TODO Auto-generated catch block
  149. e.printStackTrace();
  150. }
  151. String content = postWithParameters(SAVE_EXAMREPORT_URL, params);
  152. return content;
  153. }
  154. /**
  155. * 互认-检验报告信息
  156. *
  157. * @param instutionId
  158. * @param number
  159. */
  160. public String postLabReport(Record record, List<Record> items) {
  161. Map<String, String> params = new HashMap<>();
  162. params.put("request_time", "1");
  163. params.put("request_no", "4");
  164. JSONObject jsonObject = new JSONObject();
  165. JSONObject jsonObjectA = new JSONObject();
  166. jsonObjectA.put("AA", checkStr(record.getStr("姓名")));
  167. jsonObjectA.put("AB", checkStr(record.getStr("证件类型编码")));
  168. jsonObjectA.put("AC", checkStr(record.getStr("证件号码")));
  169. jsonObjectA.put("AD", checkStr(record.getStr("性别编码")));
  170. jsonObjectA.put("AE", checkStr(record.getStr("出生日期")));
  171. jsonObjectA.put("AF", checkStr(record.getStr("联系电话")));
  172. jsonObjectA.put("AG", checkStr(record.getStr("电子健康卡号")));
  173. JSONObject jsonObjectB = new JSONObject();
  174. jsonObjectB.put("BA", checkStr(record.getStr("就诊类型编码")));
  175. jsonObjectB.put("BB", checkStr(record.getStr("就诊卡号")));
  176. jsonObjectB.put("BC", checkStr(record.getStr("患者编号")));
  177. jsonObjectB.put("BD", checkStr(record.getStr("就诊时间")));
  178. jsonObjectB.put("BE", checkStr(record.getStr("就诊科室名称")));
  179. jsonObjectB.put("BF", checkStr(record.getStr("申请医师名称")));
  180. jsonObjectB.put("BG", checkStr(record.getStr("申请医生编码")));
  181. jsonObjectB.put("BH", checkStr(record.getStr("主诉")));
  182. jsonObjectB.put("BI", checkStr(record.getStr("年龄")));
  183. jsonObjectB.put("BJ", "121403004061412685");
  184. jsonObjectB.put("BK", "阳泉市第一人民医院");
  185. jsonObjectB.put("BL", checkStr(record.getStr("临床诊断名称")));
  186. jsonObjectB.put("BM", checkStr(record.getStr("临床诊断代码")));
  187. JSONObject jsonObjectC = new JSONObject();
  188. jsonObjectC.put("CA", checkStr(record.getStr("报告单编号")));
  189. jsonObjectC.put("CB", checkStr(record.getStr("标本类型")));
  190. jsonObjectC.put("CC", checkStr(record.getStr("检验项目名称")));
  191. jsonObjectC.put("CD", checkStr(record.getStr("检测项目类型")));
  192. jsonObjectC.put("CE", checkStr(record.getStr("报告医生姓名")));
  193. jsonObjectC.put("CF", checkStr(record.getStr("报告医生编码")));
  194. jsonObjectC.put("CG", checkStr(record.getStr("审核医师姓名")));
  195. jsonObjectC.put("CH", checkStr(record.getStr("审核医师编码")));
  196. jsonObjectC.put("CI", checkStr(record.getStr("报告科室名称")));
  197. jsonObjectC.put("CJ", checkStr(record.getStr("报告评语")));
  198. jsonObjectC.put("CK", checkStr(record.getStr("报告时间")));
  199. jsonObjectC.put("CL", checkStr(record.getStr("互认项目编码")));
  200. jsonObjectC.put("CM", checkStr(record.getStr("互认项目名称")));
  201. jsonObjectC.put("CN", checkStr(record.getStr("报告单")));
  202. JSONArray jsonArrayD = new JSONArray();
  203. for (Record itemrecord : items) {
  204. JSONObject jsonObjectE = new JSONObject();
  205. jsonObjectE.put("EA", checkStr(itemrecord.getStr("检验细项名称中文")));
  206. jsonObjectE.put("EB", checkStr(itemrecord.getStr("检验细项缩写")));
  207. jsonObjectE.put("EC", checkStr(itemrecord.getStr("检验细项序号")));
  208. jsonObjectE.put("ED", checkStr(itemrecord.getStr("检验细项测量值")));
  209. jsonObjectE.put("EE", checkStr(itemrecord.getStr("检验细项结果计量单位")));
  210. jsonObjectE.put("EF", checkStr(itemrecord.getStr("检验细项结果")));
  211. jsonObjectE.put("EG", checkStr(itemrecord.getStr("药敏结果")));
  212. jsonObjectE.put("EH", checkStr(itemrecord.getStr("参考范围")));
  213. jsonObjectE.put("EI", checkStr(itemrecord.getStr("检测方法")));
  214. jsonObjectE.put("EJ", checkStr(itemrecord.getStr("KB")));
  215. jsonObjectE.put("EK", checkStr(itemrecord.getStr("MIC")));
  216. jsonObjectE.put("EL", checkStr(itemrecord.getStr("敏感度")));
  217. jsonObjectE.put("EM", checkStr(itemrecord.getStr("互认项目编码")));
  218. jsonObjectE.put("EN", checkStr(itemrecord.getStr("互认项目名称")));
  219. jsonArrayD.add(jsonObjectE);
  220. }
  221. jsonObject.put("A", jsonObjectA);
  222. jsonObject.put("B", jsonObjectB);
  223. jsonObject.put("C", jsonObjectC);
  224. jsonObject.put("D", jsonArrayD);
  225. try {
  226. String encodedString = Base64.getEncoder().encodeToString(jsonObject.toJSONString().getBytes());
  227. params.put("data", SM4Utils.sm4Encrypt("zLxapoeqWYpoeqWY",encodedString));
  228. } catch (CryptoException e) {
  229. // TODO Auto-generated catch block
  230. e.printStackTrace();
  231. }
  232. String content = postWithParameters(SAVE_LABREPORT_URL, params);
  233. return content;
  234. }
  235. /**
  236. * 校验字符串
  237. */
  238. public String checkStr(String string) {
  239. return string==null?"":string;
  240. }
  241. public JSONArray getExamList(Integer number) {
  242. Map<String, String> map = new HashMap<String, String>();
  243. map.put("institution_id", PropKit.get("institution_id"));
  244. map.put("num", number.toString());
  245. String content = postWithParameters(GET_EXAM_URL, map);
  246. JSONObject jsonObject = JSON.parseObject(content);
  247. if (!jsonObject.getString("msg").equals("success")) {
  248. return null;
  249. }
  250. JSONArray jsonArray = JSON.parseArray(jsonObject.getString("data"));
  251. return jsonArray;
  252. }
  253. public JSONArray getBindList(String start, String finish) {
  254. Map<String, String> map = new HashMap<String, String>();
  255. map.put("institution_id", PropKit.get("institution_id"));
  256. map.put("start", start);
  257. map.put("finish", finish);
  258. String content = getWithUrl(RETURN_BIND_URL, map);
  259. JSONObject jsonObject = JSON.parseObject(content);
  260. if (!jsonObject.getString("msg").equals("success")) {
  261. return null;
  262. }
  263. JSONArray jsonArray = JSON.parseArray(jsonObject.getString("data"));
  264. return jsonArray;
  265. }
  266. /**
  267. * 写入报告
  268. *
  269. * @param instutionId
  270. * @param number
  271. */
  272. public String saveReport(Map<String, String> map) {
  273. String content = postWithParameters(SAVE_REPORT_URL, map);
  274. return content;
  275. }
  276. /**
  277. * 更新患者信息  
  278. *
  279. * @param instutionId
  280. * @param number
  281. */
  282. public void updatePatientInfo(Map<String, String> map) {
  283. postWithParameters(UPDATE_PATIENT_URL, map);
  284. }
  285. /**
  286. * 保存附件
  287. *
  288. * @param instutionId
  289. * @param number
  290. * @throws FileNotFoundException
  291. */
  292. public void saveAnnex(Map<String, String> map, String filePath) {
  293. OSS OSS_CLIENT = new OSSClientBuilder().build(PropKit.get("oss_endpoint"), PropKit.get("oss_accessKey"), PropKit.get("oss_secretKey"));
  294. String fileNameStr[] = filePath.split("/");
  295. String fileName = fileNameStr[fileNameStr.length - 1];
  296. String fileStorePath = getFileWithUrl(filePath, fileName);
  297. File file = new File(fileStorePath);
  298. String key = PropKit.get("institution_id") + "/" + fileName;
  299. InputStream inputStream = null;
  300. try {
  301. inputStream = new FileInputStream(fileStorePath);
  302. } catch (FileNotFoundException e) {
  303. // TODO Auto-generated catch block
  304. e.printStackTrace();
  305. }
  306. Boolean eBoolean = OSS_CLIENT.doesObjectExist(PropKit.get("oss_bucketName"), key);
  307. if (!eBoolean) {
  308. OSS_CLIENT.putObject(PropKit.get("oss_bucketName"), key, inputStream);
  309. Boolean bBoolean = OSS_CLIENT.doesObjectExist(PropKit.get("oss_bucketName"), key);
  310. if (!bBoolean) {
  311. OSS_CLIENT.putObject(PropKit.get("oss_bucketName"), key, inputStream);
  312. }
  313. }
  314. map.put("url", "https://zskk-image.oss-cn-beijing.aliyuncs.com/" + key);
  315. map.put("name", key);
  316. postWithParameters(SAVE_ANNEX_URL, map);
  317. try {
  318. inputStream.close();
  319. } catch (IOException e) {
  320. // TODO Auto-generated catch block
  321. e.printStackTrace();
  322. }
  323. file.delete();
  324. }
  325. /**
  326. * 获取未出报告的检查列表
  327. *
  328. * @param instutionId
  329. * @param number
  330. */
  331. public void savePrint(Map<String, String> map) {
  332. String content = postWithParameters(SAVE_PRINT_URL, map);
  333. }
  334. public static String postWithParameters(String url, Map<String, String> map) {
  335. FormBody.Builder formbody = new FormBody.Builder();
  336. for (Map.Entry<String, String> entry : map.entrySet()) {
  337. formbody.add(entry.getKey(), entry.getValue());
  338. }
  339. RequestBody requestBody = formbody.build();
  340. Request request = new Request.Builder().url(url).post(requestBody).addHeader("Authorization", "Bearer Zjc3YmIyODBhNjY4ZWZlMzc5MjdiMzFiNWE3MGExODM=").build();
  341. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  342. if (!response.isSuccessful())
  343. throw new IOException("Unexpected code " + response);
  344. String content = response.body().string();
  345. return content;
  346. } catch (IOException e) {
  347. // TODO Auto-generated catch block
  348. e.printStackTrace();
  349. return null;
  350. }
  351. }
  352. public static String getWithUrl(String url, Map<String, String> map) {
  353. for (Map.Entry<String, String> entry : map.entrySet()) {
  354. String s = url.contains("?") ? "&" : "?";
  355. url = url + s + entry.getKey() + "=" + entry.getValue();
  356. }
  357. Request request = new Request.Builder().url(url).build();
  358. String content = "";
  359. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  360. if (!response.isSuccessful())
  361. throw new IOException("Unexpected code " + response);
  362. content = response.body().string();
  363. return content;
  364. } catch (IOException e) {
  365. // TODO Auto-generated catch block
  366. e.printStackTrace();
  367. return null;
  368. }
  369. }
  370. public static String getFileWithUrl(String url, String filename) {
  371. Request request = new Request.Builder().url(url).build();
  372. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  373. if (!response.isSuccessful())
  374. throw new IOException("Unexpected code " + response);
  375. InputStream inputStream = response.body().source().inputStream();
  376. // 本地文件夹目录(下载位置)
  377. String folder = PropKit.get("oss_localPath");
  378. // 下载文件保存位置
  379. String savepath = folder + "/" + filename;
  380. BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(savepath)));
  381. byte[] data = new byte[1024];
  382. int len;
  383. int available = inputStream.available();
  384. while ((len = inputStream.read(data)) != -1) {
  385. bufferedOutputStream.write(data, 0, len);
  386. }
  387. bufferedOutputStream.flush();
  388. bufferedOutputStream.close();
  389. inputStream.close();
  390. return savepath;
  391. } catch (IOException e) {
  392. // TODO Auto-generated catch block
  393. e.printStackTrace();
  394. return "";
  395. }
  396. }
  397. public static void main(String[] args) {
  398. // Map<String, String> map = new HashMap<String, String>();
  399. // map.put("institution_id", "06300006");
  400. // map.put("start", "2022-02-01");
  401. // map.put("finish", "2022-03-01");
  402. // String content = postExamReport(null);
  403. // System.out.println(content);
  404. }
  405. }