|
@@ -0,0 +1,327 @@
|
|
|
|
+package com.zskk.service;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.jfinal.plugin.cron4j.ITask;
|
|
|
|
+import com.zskk.model.Exams;
|
|
|
|
+import org.apache.http.client.config.RequestConfig;
|
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
|
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
|
|
|
+import org.apache.log4j.Logger;
|
|
|
|
+
|
|
|
|
+import java.io.BufferedReader;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStreamReader;
|
|
|
|
+import java.io.PrintWriter;
|
|
|
|
+import java.nio.charset.Charset;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+public class DataService implements ITask {
|
|
|
|
+ static Logger logger = Logger.getLogger(DataService.class);
|
|
|
|
+ private static String GET_EXAM_URL = "https://risserver3.pacsonline.cn/butt/getExam";
|
|
|
|
+
|
|
|
|
+ private static String SAVE_REPORT_URL = "https://risserver3.pacsonline.cn/butt/saveReport";
|
|
|
|
+
|
|
|
|
+ // private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
|
|
|
|
+
|
|
|
|
+ private static CloseableHttpClient httpClient;
|
|
|
|
+
|
|
|
|
+ static {
|
|
|
|
+ PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
|
|
|
+ cm.setMaxTotal(100);
|
|
|
|
+ cm.setDefaultMaxPerRoute(20);
|
|
|
|
+ cm.setDefaultMaxPerRoute(50);
|
|
|
|
+ httpClient = HttpClients.custom().setConnectionManager(cm).build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取未出报告的检查列表
|
|
|
|
+ * @param instutionId
|
|
|
|
+ * @param number
|
|
|
|
+ */
|
|
|
|
+ public static JSONArray getExamList(String instutionId, Integer number) {
|
|
|
|
+ Map <String,String> map = new HashMap<String,String>();
|
|
|
|
+ map.put("institution_id", instutionId);
|
|
|
|
+ map.put("num", number.toString());
|
|
|
|
+ String content = postWithParameters(GET_EXAM_URL, map);
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(content);
|
|
|
|
+ if (!jsonObject.getString("msg").equals("success")) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ JSONArray jsonArray = JSON.parseArray(jsonObject.getString("data"));
|
|
|
|
+ return jsonArray;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 写入报告
|
|
|
|
+ * @param instutionId
|
|
|
|
+ * @param number
|
|
|
|
+ */
|
|
|
|
+ public void saveReport(String instutionId, Integer number) {
|
|
|
|
+ Map <String,String> map = new HashMap<String,String>();
|
|
|
|
+ postWithParameters(SAVE_REPORT_URL, map);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 发送POST请求
|
|
|
|
+ *
|
|
|
|
+ * @param url 目的地址
|
|
|
|
+ * @param parameters 请求参数,Map类型。
|
|
|
|
+ * @return 远程响应结果
|
|
|
|
+ */
|
|
|
|
+ public static String postWithParameters(String url, Map<String, String> parameters) {
|
|
|
|
+ String result = "";// 返回的结果
|
|
|
|
+ BufferedReader in = null;// 读取响应输入流
|
|
|
|
+ PrintWriter out = null;
|
|
|
|
+ StringBuffer sb = new StringBuffer();// 处理请求参数
|
|
|
|
+ String params = "";// 编码之后的参数
|
|
|
|
+ try {
|
|
|
|
+ // 编码请求参数
|
|
|
|
+ if (parameters.size() == 1) {
|
|
|
|
+ for (String name : parameters.keySet()) {
|
|
|
|
+ sb.append(name).append("=").append(
|
|
|
|
+ java.net.URLEncoder.encode(parameters.get(name),
|
|
|
|
+ "UTF-8"));
|
|
|
|
+ }
|
|
|
|
+ params = sb.toString();
|
|
|
|
+ } else {
|
|
|
|
+ for (String name : parameters.keySet()) {
|
|
|
|
+ sb.append(name).append("=").append(
|
|
|
|
+ java.net.URLEncoder.encode(parameters.get(name),
|
|
|
|
+ "UTF-8")).append("&");
|
|
|
|
+ }
|
|
|
|
+ String temp_params = sb.toString();
|
|
|
|
+ //System.out.println(temp_params);
|
|
|
|
+ params = temp_params.substring(0, temp_params.length() - 1);
|
|
|
|
+ System.out.println(params);
|
|
|
|
+ }
|
|
|
|
+ //params = java.net.URLEncoder.encode(params, "UTF-8");
|
|
|
|
+ // 创建URL对象
|
|
|
|
+ java.net.URL connURL = new java.net.URL(url);
|
|
|
|
+ // 打开URL连接
|
|
|
|
+ java.net.HttpURLConnection httpConn = (java.net.HttpURLConnection) connURL
|
|
|
|
+ .openConnection();
|
|
|
|
+ // 设置通用属性
|
|
|
|
+ httpConn.setRequestProperty("Accept", "*/*");
|
|
|
|
+ httpConn.setRequestProperty("Connection", "Keep-Alive");
|
|
|
|
+ httpConn.setRequestProperty("User-Agent",
|
|
|
|
+ "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
|
|
|
|
+ // 设置POST方式
|
|
|
|
+ httpConn.setDoInput(true);
|
|
|
|
+ httpConn.setDoOutput(true);
|
|
|
|
+ // 获取HttpURLConnection对象对应的输出流
|
|
|
|
+ // out = new PrintWriter(httpConn.getOutputStream()); // 用PrintWriter进行包装
|
|
|
|
+ // out.println(params);
|
|
|
|
+ out = new PrintWriter(httpConn.getOutputStream());
|
|
|
|
+ // 发送请求参数
|
|
|
|
+ out.write(params);
|
|
|
|
+ // flush输出流的缓冲
|
|
|
|
+ out.flush();
|
|
|
|
+ // 定义BufferedReader输入流来读取URL的响应,设置编码方式
|
|
|
|
+
|
|
|
|
+ in = new BufferedReader(new InputStreamReader(httpConn
|
|
|
|
+ .getInputStream(), "UTF-8"));
|
|
|
|
+ String line;
|
|
|
|
+ // 读取返回的内容
|
|
|
|
+ while ((line = in.readLine()) != null) {
|
|
|
|
+ result += line;
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if (out != null) {
|
|
|
|
+ out.close();
|
|
|
|
+ }
|
|
|
|
+ if (in != null) {
|
|
|
|
+ in.close();
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static String post(String url, String jsonString) {
|
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
|
+ BufferedReader in = null;
|
|
|
|
+ String result = "";
|
|
|
|
+ try {
|
|
|
|
+ HttpPost httpPost = new HttpPost(url);
|
|
|
|
+ RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(30000).setConnectionRequestTimeout(30000).setSocketTimeout(30000).build();
|
|
|
|
+ httpPost.setConfig(requestConfig);
|
|
|
|
+ httpPost.setConfig(requestConfig);
|
|
|
|
+ httpPost.addHeader("Content-type", "application/json; charset=utf-8");
|
|
|
|
+ httpPost.setHeader("Accept", "application/json");
|
|
|
|
+ httpPost.setEntity(new StringEntity(jsonString, Charset.forName("UTF-8")));
|
|
|
|
+ response = httpClient.execute(httpPost);
|
|
|
|
+ in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
|
+ StringBuffer sb = new StringBuffer("");
|
|
|
|
+ String line = "";
|
|
|
|
+ String NL = System.getProperty("line.separator");
|
|
|
|
+ while ((line = in.readLine()) != null) {
|
|
|
|
+ sb.append(line + NL);
|
|
|
|
+ }
|
|
|
|
+ in.close();
|
|
|
|
+ result = sb.toString();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if (null != response) {
|
|
|
|
+ response.close();
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ JSONArray examList = getExamList("51000001", 2);
|
|
|
|
+ List<Exams> exams = JSONObject.parseArray(examList.toJSONString(), Exams.class);
|
|
|
|
+ for (Exams exams2 : exams) {
|
|
|
|
+ logger.info(exams2.getId());
|
|
|
|
+ System.out.println(exams2.getId());
|
|
|
|
+ String id = exams2.getId();
|
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
|
+ // params.put("institution_id",exams2.getId());
|
|
|
|
+ //exams表
|
|
|
|
+ params.put("exam_id", "cnb5070nvccjeoqu");
|
|
|
|
+ //报告医生姓名
|
|
|
|
+ params.put("report_doctor_name", "盛季平");
|
|
|
|
+// //报告时间
|
|
|
|
+ params.put("report_datetime", "2020-02-26 11:48:31");
|
|
|
|
+// //审核医生姓名
|
|
|
|
+ params.put("review_doctor_name", "盛季平");
|
|
|
|
+// //审核时间
|
|
|
|
+ params.put("review_datetime", "2020-02-26 11:48:31");
|
|
|
|
+// //确认医生姓名
|
|
|
|
+ params.put("confirm_doctor_name", "盛季平");
|
|
|
|
+// //确认时间
|
|
|
|
+ params.put("confirm_datetime", "2020-02-26 11:48:31");
|
|
|
|
+//// if (record.getStr("impression") == null && record.getStr("description") == null) {
|
|
|
|
+//// continue;
|
|
|
|
+//// }
|
|
|
|
+// //意见建议
|
|
|
|
+ params.put("impression", "考虑右胫骨远端陈旧骨折,并创伤性关节,请结合临床。");
|
|
|
|
+// //影像所见
|
|
|
|
+ params.put("description", " 右侧胫骨远端略膨大、变形,边缘毛糙、增生硬化;右踝关节间隙变窄,周围可见多个不规则结节状骨性密度影;右踝关节周围软组织肿胀。");
|
|
|
|
+// //exams表
|
|
|
|
+// //申请科室
|
|
|
|
+ params.put("application_department", "骨科三区病房");
|
|
|
|
+// //申请医生
|
|
|
|
+ params.put("application_doctor", "何炜");
|
|
|
|
+// //临床诊断
|
|
|
|
+ params.put("clin_diag", "null");
|
|
|
|
+// //patient_infos表
|
|
|
|
+// //患者姓名
|
|
|
|
+ params.put("name", "刘日昇");
|
|
|
|
+// //患者手机号
|
|
|
|
+ params.put("phone", "13650842393");
|
|
|
|
+// //患者身份证号
|
|
|
|
+ params.put("card_num", "440125197208070312");
|
|
|
|
+ params.put("report_result", "1");
|
|
|
|
+ String post = post(SAVE_REPORT_URL, JSON.toJSONString(params));
|
|
|
|
+ logger.error(post);
|
|
|
|
+ //System.out.println(post);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void stop() {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* public static String postWithParameters(String url, Map<String, String> map) {
|
|
|
|
+
|
|
|
|
+ FormBody.Builder formbody = new FormBody.Builder();
|
|
|
|
+
|
|
|
|
+ for (Map.Entry<String, String> entry : map.entrySet()) {
|
|
|
|
+ formbody.add(entry.getKey(), entry.getValue());
|
|
|
|
+ }
|
|
|
|
+ RequestBody requestBody = formbody.build();
|
|
|
|
+
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
+ .url(url)
|
|
|
|
+ .post(requestBody)
|
|
|
|
+ .build();
|
|
|
|
+
|
|
|
|
+ try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
|
|
|
|
+ if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
|
|
|
|
+ String content = response.body().string();
|
|
|
|
+ System.out.println(content);
|
|
|
|
+ return content;
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ // TODO Auto-generated catch block
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }*/
|
|
|
|
+
|
|
|
|
+ /*public static void main(String[] args) {
|
|
|
|
+
|
|
|
|
+ JSONArray examList = getExamList("51000001", 2);
|
|
|
|
+ List<Exams> exams = JSONObject.parseArray(examList.toJSONString(), Exams.class);
|
|
|
|
+ for (Exams exams2 : exams) {
|
|
|
|
+ logger.info(exams2.getId());
|
|
|
|
+ System.out.println(exams2.getId());
|
|
|
|
+ String id = exams2.getId();
|
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
|
+ // params.put("institution_id",exams2.getId());
|
|
|
|
+ //exams表
|
|
|
|
+ params.put("exam_id","cnb506yaldqwzkmm");
|
|
|
|
+ //报告医生姓名
|
|
|
|
+ params.put("report_doctor_name","11");
|
|
|
|
+// //报告时间
|
|
|
|
+ params.put("report_datetime","2018-05-08 15:13:19");
|
|
|
|
+// //审核医生姓名
|
|
|
|
+ params.put("review_doctor_name","2");
|
|
|
|
+// //审核时间
|
|
|
|
+ params.put("review_datetime","2018-05-08 15:13:19");
|
|
|
|
+// //确认医生姓名
|
|
|
|
+ params.put("confirm_doctor_name","3");
|
|
|
|
+// //确认时间
|
|
|
|
+ params.put("confirm_datetime","2018-05-08 15:13:19");
|
|
|
|
+//// if (record.getStr("impression") == null && record.getStr("description") == null) {
|
|
|
|
+//// continue;
|
|
|
|
+//// }
|
|
|
|
+// //意见建议
|
|
|
|
+ params.put("impression"," 44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444 44444444444 ,444444444444444444444444444444444444444444444444444444444444444444");
|
|
|
|
+// //影像所见
|
|
|
|
+ params.put("description"," 54444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444");
|
|
|
|
+// //exams表
|
|
|
|
+// //申请科室
|
|
|
|
+ params.put("application_department","6");
|
|
|
|
+// //申请医生
|
|
|
|
+ params.put("application_doctor","7");
|
|
|
|
+// //临床诊断
|
|
|
|
+ params.put("clin_diag","8");
|
|
|
|
+// //patient_infos表
|
|
|
|
+// //患者姓名
|
|
|
|
+ params.put("name","9");
|
|
|
|
+// //患者手机号
|
|
|
|
+ params.put("phone","10");
|
|
|
|
+// //患者身份证号
|
|
|
|
+ params.put("card_num","11");
|
|
|
|
+ params.put("report_result","1");
|
|
|
|
+ String post = post(SAVE_REPORT_URL, JSON.toJSONString(params));
|
|
|
|
+ logger.error(post);
|
|
|
|
+ //System.out.println(post);
|
|
|
|
+ }
|
|
|
|
+ }*/
|
|
|
|
+}
|