123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484 |
- package com.zskk.service;
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Base64;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.bouncycastle.crypto.CryptoException;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.aliyun.oss.OSS;
- import com.aliyun.oss.OSSClientBuilder;
- import com.aliyun.oss.model.PutObjectResult;
- import com.jfinal.kit.PropKit;
- import com.jfinal.plugin.activerecord.Record;
- import com.zskk.tools.SM4Utils;
- import okhttp3.FormBody;
- import okhttp3.OkHttpClient;
- import okhttp3.Request;
- import okhttp3.RequestBody;
- import okhttp3.Response;
- import com.zskk.tools.SM4Utils;
- public class DataService {
- private static String GET_EXAM_URL = "http://192.168.0.34:9600/zskkapi/butt/getExam";
- private static String SAVE_REPORT_URL = "http://192.168.0.34:9600/zskkapi/butt/saveReport";
- private static String GET_CONFIRM_EXAM_URL = "https://risserver3.pacsonline.cn/butt/getConfirmExam";
- private static String UPDATE_PATIENT_URL = "https://risserver3.pacsonline.cn/butt/saveExam";
- private static String RETURN_BIND_URL = "https://risserver3.pacsonline.cn/butt/getBindInfo";
- private static String SAVE_ANNEX_URL = "https://risserver3.pacsonline.cn/butt/saveAnnex";
-
- private static String SAVE_PRINT_URL = "https://risserver3.pacsonline.cn/butt/savePrint";
- private static String SAVE_EXAMINFO_URL = "http://10.200.199.136:9605/api/postExamInfo";
-
- private static String SAVE_EXAMREPORT_URL = "http://10.200.199.136:9605/api/postExamReport";
-
- private static String SAVE_LABREPORT_URL = "http://10.200.199.136:9605/api/postLabReport";
- // private static String SAVE_EXAMINFO_URL = "http://111.53.165.106:9605/api/postExamInfo";
- private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
-
- /**
- * 互认-检查信息
- *
- * @param instutionId
- * @param number
- */
- public String postExamInfo(Record record) {
- Map<String, String> params = new HashMap<>();
- params.put("request_time", "1");
- params.put("request_no", "2");
-
- JSONObject jsonObject = new JSONObject();
- JSONObject jsonObjectA = new JSONObject();
- jsonObjectA.put("AA", checkStr(record.getStr("AA")));
- jsonObjectA.put("AB", checkStr(record.getStr("AB")));
- jsonObjectA.put("AC", checkStr(record.getStr("AC")));
- jsonObjectA.put("AD", checkStr(record.getStr("AD")));
- jsonObjectA.put("AE", checkStr(record.getStr("AE")));
- jsonObjectA.put("AF", checkStr(record.getStr("AF")));
- jsonObjectA.put("AG", checkStr(record.getStr("AG")));
-
- JSONObject jsonObjectB = new JSONObject();
- jsonObjectB.put("BA", checkStr(record.getStr("BA")));
- jsonObjectB.put("BB", checkStr(record.getStr("BB")));
- jsonObjectB.put("BC", checkStr(record.getStr("BC")));
- jsonObjectB.put("BD", checkStr(record.getStr("BD")));
- jsonObjectB.put("BE", checkStr(record.getStr("BE")));
- jsonObjectB.put("BF", checkStr(record.getStr("BF")));
- jsonObjectB.put("BG", checkStr(record.getStr("BG")));
- jsonObjectB.put("BH", checkStr(record.getStr("BH")));
- jsonObjectB.put("BI", checkStr(record.getStr("BI")));
- jsonObjectB.put("BJ", checkStr(record.getStr("BJ")));
- jsonObjectB.put("BK", "12140300MB0351839N");
- jsonObjectB.put("BL", "阳泉煤业(集团)有限责任公司总医院");
- jsonObjectB.put("BM", checkStr(record.getStr("BM")));
- jsonObjectB.put("BN", checkStr(record.getStr("BN")));
- JSONObject jsonObjectC = new JSONObject();
- jsonObjectC.put("CA", checkStr(record.getStr("CA")));
- jsonObjectC.put("CB", checkStr(record.getStr("CB")));
- jsonObjectC.put("CC", checkStr(record.getStr("CC")));
- jsonObjectC.put("CD", checkStr(record.getStr("CD")));
- jsonObjectC.put("CE", checkStr(record.getStr("CE")));
- jsonObjectC.put("CF", checkStr(record.getStr("CF")));
- jsonObjectC.put("CG", checkStr(record.getStr("CG")));
- jsonObjectC.put("CH", checkStr(record.getStr("CH")));
- jsonObjectC.put("CI", checkStr(record.getStr("CI")));
- jsonObjectC.put("CJ", checkStr(record.getStr("CJ")));
- jsonObjectC.put("CK", checkStr(record.getStr("CK")));
- jsonObjectC.put("CL", checkStr(record.getStr("CL")));
- jsonObjectC.put("CM", checkStr(record.getStr("CM")));
- jsonObjectC.put("CN", checkStr(record.getStr("CN")));
- jsonObjectC.put("CO", checkStr(record.getStr("CO")));
- jsonObject.put("A", jsonObjectA);
- jsonObject.put("B", jsonObjectB);
- jsonObject.put("C", jsonObjectC);
- try {
- String encodedString = Base64.getEncoder().encodeToString(jsonObject.toJSONString().getBytes());
- params.put("data", SM4Utils.sm4Encrypt("zLxapoeqWYpoeqWY",encodedString));
- } catch (CryptoException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- String content = postWithParameters(SAVE_EXAMINFO_URL, params);
- return content;
- }
-
- /**
- * 互认-检查报告信息
- *
- * @param instutionId
- * @param number
- */
- public String postExamReport(Record record) {
- Map<String, String> params = new HashMap<>();
- params.put("request_time", "1");
- params.put("request_no", "3");
-
- JSONObject jsonObject = new JSONObject();
- JSONObject jsonObjectB = new JSONObject();
-
- jsonObjectB.put("BD", checkStr(record.getStr("检查号")));
- jsonObjectB.put("BJ", "121403004061412685");
- jsonObjectB.put("BK", "阳泉市第一人民医院");
- JSONObject jsonObjectC = new JSONObject();
- jsonObjectC.put("CA", checkStr(record.getStr("报告单编号")));
- jsonObjectC.put("CB", checkStr(record.getStr("检查类型")));
- jsonObjectC.put("CC", checkStr(record.getStr("检查部位")));
- jsonObjectC.put("CD", checkStr(record.getStr("检查所见")));
- jsonObjectC.put("CE", checkStr(record.getStr("影像诊断")));
- jsonObjectC.put("CF", checkStr(record.getStr("检查结果类别")));
- jsonObjectC.put("CG", checkStr(record.getStr("报告科室名称")));
- jsonObjectC.put("CH", checkStr(record.getStr("报告医生姓名")));
- jsonObjectC.put("CI", checkStr(record.getStr("审核医生姓名")));
- jsonObjectC.put("CJ", checkStr(record.getStr("报告时间")));
- jsonObjectC.put("CK", checkStr(record.getStr("审核时间")));
- jsonObjectC.put("CL", checkStr(record.getStr("检查时间")));
- jsonObjectC.put("CM", checkStr(record.getStr("危急值")));
- jsonObjectC.put("CN", checkStr(record.getStr("报告医生编码")));
- jsonObjectC.put("CO", checkStr(record.getStr("审核医生编码")));
- jsonObjectC.put("CP", checkStr(record.getStr("患者编号")));
- jsonObjectC.put("CQ", checkStr(record.getStr("报告单")));
- jsonObjectC.put("CR", checkStr(record.getStr("检查状态")));
- jsonObject.put("B", jsonObjectB);
- jsonObject.put("C", jsonObjectC);
- try {
- String encodedString = Base64.getEncoder().encodeToString(jsonObject.toJSONString().getBytes());
- params.put("data", SM4Utils.sm4Encrypt("zLxapoeqWYpoeqWY",encodedString));
- } catch (CryptoException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- String content = postWithParameters(SAVE_EXAMREPORT_URL, params);
- return content;
- }
-
- /**
- * 互认-检验报告信息
- *
- * @param instutionId
- * @param number
- */
- public String postLabReport(Record record, List<Record> items) {
- Map<String, String> params = new HashMap<>();
- params.put("request_time", "1");
- params.put("request_no", "4");
-
- JSONObject jsonObject = new JSONObject();
-
- JSONObject jsonObjectA = new JSONObject();
- jsonObjectA.put("AA", checkStr(record.getStr("姓名")));
- jsonObjectA.put("AB", checkStr(record.getStr("证件类型编码")));
- jsonObjectA.put("AC", checkStr(record.getStr("证件号码")));
- jsonObjectA.put("AD", checkStr(record.getStr("性别编码")));
- jsonObjectA.put("AE", checkStr(record.getStr("出生日期")));
- jsonObjectA.put("AF", checkStr(record.getStr("联系电话")));
- jsonObjectA.put("AG", checkStr(record.getStr("电子健康卡号")));
- JSONObject jsonObjectB = new JSONObject();
- jsonObjectB.put("BA", checkStr(record.getStr("就诊类型编码")));
- jsonObjectB.put("BB", checkStr(record.getStr("就诊卡号")));
- jsonObjectB.put("BC", checkStr(record.getStr("患者编号")));
- jsonObjectB.put("BD", checkStr(record.getStr("就诊时间")));
- jsonObjectB.put("BE", checkStr(record.getStr("就诊科室名称")));
- jsonObjectB.put("BF", checkStr(record.getStr("申请医师名称")));
- jsonObjectB.put("BG", checkStr(record.getStr("申请医生编码")));
- jsonObjectB.put("BH", checkStr(record.getStr("主诉")));
- jsonObjectB.put("BI", checkStr(record.getStr("年龄")));
- jsonObjectB.put("BJ", "121403004061412685");
- jsonObjectB.put("BK", "阳泉市第一人民医院");
- jsonObjectB.put("BL", checkStr(record.getStr("临床诊断名称")));
- jsonObjectB.put("BM", checkStr(record.getStr("临床诊断代码")));
- JSONObject jsonObjectC = new JSONObject();
- jsonObjectC.put("CA", checkStr(record.getStr("报告单编号")));
- jsonObjectC.put("CB", checkStr(record.getStr("标本类型")));
- jsonObjectC.put("CC", checkStr(record.getStr("检验项目名称")));
- jsonObjectC.put("CD", checkStr(record.getStr("检测项目类型")));
- jsonObjectC.put("CE", checkStr(record.getStr("报告医生姓名")));
- jsonObjectC.put("CF", checkStr(record.getStr("报告医生编码")));
- jsonObjectC.put("CG", checkStr(record.getStr("审核医师姓名")));
- jsonObjectC.put("CH", checkStr(record.getStr("审核医师编码")));
- jsonObjectC.put("CI", checkStr(record.getStr("报告科室名称")));
- jsonObjectC.put("CJ", checkStr(record.getStr("报告评语")));
- jsonObjectC.put("CK", checkStr(record.getStr("报告时间")));
- jsonObjectC.put("CL", checkStr(record.getStr("互认项目编码")));
- jsonObjectC.put("CM", checkStr(record.getStr("互认项目名称")));
- jsonObjectC.put("CN", checkStr(record.getStr("报告单")));
-
- JSONArray jsonArrayD = new JSONArray();
- for (Record itemrecord : items) {
- JSONObject jsonObjectE = new JSONObject();
- jsonObjectE.put("EA", checkStr(itemrecord.getStr("检验细项名称中文")));
- jsonObjectE.put("EB", checkStr(itemrecord.getStr("检验细项缩写")));
- jsonObjectE.put("EC", checkStr(itemrecord.getStr("检验细项序号")));
- jsonObjectE.put("ED", checkStr(itemrecord.getStr("检验细项测量值")));
- jsonObjectE.put("EE", checkStr(itemrecord.getStr("检验细项结果计量单位")));
- jsonObjectE.put("EF", checkStr(itemrecord.getStr("检验细项结果")));
- jsonObjectE.put("EG", checkStr(itemrecord.getStr("药敏结果")));
- jsonObjectE.put("EH", checkStr(itemrecord.getStr("参考范围")));
- jsonObjectE.put("EI", checkStr(itemrecord.getStr("检测方法")));
- jsonObjectE.put("EJ", checkStr(itemrecord.getStr("KB")));
- jsonObjectE.put("EK", checkStr(itemrecord.getStr("MIC")));
- jsonObjectE.put("EL", checkStr(itemrecord.getStr("敏感度")));
- jsonObjectE.put("EM", checkStr(itemrecord.getStr("互认项目编码")));
- jsonObjectE.put("EN", checkStr(itemrecord.getStr("互认项目名称")));
- jsonArrayD.add(jsonObjectE);
- }
- jsonObject.put("A", jsonObjectA);
- jsonObject.put("B", jsonObjectB);
- jsonObject.put("C", jsonObjectC);
- jsonObject.put("D", jsonArrayD);
- try {
- String encodedString = Base64.getEncoder().encodeToString(jsonObject.toJSONString().getBytes());
- params.put("data", SM4Utils.sm4Encrypt("zLxapoeqWYpoeqWY",encodedString));
- } catch (CryptoException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- String content = postWithParameters(SAVE_LABREPORT_URL, params);
- return content;
- }
-
- /**
- * 校验字符串
- */
- public String checkStr(String string) {
- return string==null?"":string;
- }
- public JSONArray getExamList(Integer number) {
- Map<String, String> map = new HashMap<String, String>();
- map.put("institution_id", PropKit.get("institution_id"));
- 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;
- }
- public JSONArray getBindList(String start, String finish) {
- Map<String, String> map = new HashMap<String, String>();
- map.put("institution_id", PropKit.get("institution_id"));
- map.put("start", start);
- map.put("finish", finish);
- String content = getWithUrl(RETURN_BIND_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 String saveReport(Map<String, String> map) {
- String content = postWithParameters(SAVE_REPORT_URL, map);
- return content;
- }
- /**
- * 更新患者信息
- *
- * @param instutionId
- * @param number
- */
- public void updatePatientInfo(Map<String, String> map) {
- postWithParameters(UPDATE_PATIENT_URL, map);
- }
- /**
- * 保存附件
- *
- * @param instutionId
- * @param number
- * @throws FileNotFoundException
- */
- public void saveAnnex(Map<String, String> map, String filePath) {
- OSS OSS_CLIENT = new OSSClientBuilder().build(PropKit.get("oss_endpoint"), PropKit.get("oss_accessKey"), PropKit.get("oss_secretKey"));
- String fileNameStr[] = filePath.split("/");
- String fileName = fileNameStr[fileNameStr.length - 1];
- String fileStorePath = getFileWithUrl(filePath, fileName);
- File file = new File(fileStorePath);
- String key = PropKit.get("institution_id") + "/" + fileName;
- InputStream inputStream = null;
- try {
- inputStream = new FileInputStream(fileStorePath);
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- Boolean eBoolean = OSS_CLIENT.doesObjectExist(PropKit.get("oss_bucketName"), key);
- if (!eBoolean) {
- OSS_CLIENT.putObject(PropKit.get("oss_bucketName"), key, inputStream);
- Boolean bBoolean = OSS_CLIENT.doesObjectExist(PropKit.get("oss_bucketName"), key);
- if (!bBoolean) {
- OSS_CLIENT.putObject(PropKit.get("oss_bucketName"), key, inputStream);
- }
- }
- map.put("url", "https://zskk-image.oss-cn-beijing.aliyuncs.com/" + key);
- map.put("name", key);
- postWithParameters(SAVE_ANNEX_URL, map);
- try {
- inputStream.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- file.delete();
- }
-
- /**
- * 获取未出报告的检查列表
- *
- * @param instutionId
- * @param number
- */
- public void savePrint(Map<String, String> map) {
-
- String content = postWithParameters(SAVE_PRINT_URL, map);
-
- }
-
- 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).addHeader("Authorization", "Bearer Zjc3YmIyODBhNjY4ZWZlMzc5MjdiMzFiNWE3MGExODM=").build();
- try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
- if (!response.isSuccessful())
- throw new IOException("Unexpected code " + response);
- String content = response.body().string();
- return content;
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- }
- }
- public static String getWithUrl(String url, Map<String, String> map) {
- for (Map.Entry<String, String> entry : map.entrySet()) {
- String s = url.contains("?") ? "&" : "?";
- url = url + s + entry.getKey() + "=" + entry.getValue();
- }
- Request request = new Request.Builder().url(url).build();
- String content = "";
- try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
- if (!response.isSuccessful())
- throw new IOException("Unexpected code " + response);
- content = response.body().string();
- return content;
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- }
- }
- public static String getFileWithUrl(String url, String filename) {
- Request request = new Request.Builder().url(url).build();
- try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
- if (!response.isSuccessful())
- throw new IOException("Unexpected code " + response);
- InputStream inputStream = response.body().source().inputStream();
- // 本地文件夹目录(下载位置)
- String folder = PropKit.get("oss_localPath");
- // 下载文件保存位置
- String savepath = folder + "/" + filename;
- BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(savepath)));
- byte[] data = new byte[1024];
- int len;
- int available = inputStream.available();
- while ((len = inputStream.read(data)) != -1) {
- bufferedOutputStream.write(data, 0, len);
- }
- bufferedOutputStream.flush();
- bufferedOutputStream.close();
- inputStream.close();
- return savepath;
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return "";
- }
- }
- public static void main(String[] args) {
- // Map<String, String> map = new HashMap<String, String>();
- // map.put("institution_id", "06300006");
- // map.put("start", "2022-02-01");
- // map.put("finish", "2022-03-01");
- // String content = postExamReport(null);
- // System.out.println(content);
-
-
- }
- }
|