package com.zskk.control; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.NodeList; import com.jfinal.core.Controller; import com.jfinal.kit.PropKit; import com.jfinal.plugin.activerecord.ActiveRecordPlugin; import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Record; import com.jfinal.plugin.activerecord.dialect.OracleDialect; import com.jfinal.plugin.activerecord.dialect.SqlServerDialect; import com.jfinal.plugin.druid.DruidPlugin; import com.zskk.service.DataService; import com.zskk.service.ServiceFactory; import com.zskk.service.ThreadPoolService; import com.zskk.tools.ExecUtil; import com.zskk.tools.XmlHelper; import okhttp3.FormBody; import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; public class ViewController extends Controller { private static final MediaType JSON_CODE = MediaType.get("application/json; charset=utf-8"); private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient(); /** * 在被连接数据库执行sql语句 */ public void executeSql() { try { List d = Db.use("connected").find(this.getPara("sqlstr")); this.renderJson(d); } catch (Exception e) { // TODO: handle exception this.renderText(e.toString()); } } public void testConn() { try { DruidPlugin druidPluginConnected = createConnectedDruidPlugin(); druidPluginConnected.start(); // 配置ActiveRecord插件 ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("connected", druidPluginConnected); arpConnected.setDialect(new OracleDialect()); arpConnected.start(); } catch (Exception e) { // TODO: handle exception this.renderText(e.toString()); } } public void sdDown() { DataService dService = ServiceFactory.getService(DataService.class); List array2 = new ArrayList(); List array = Db.use("connected").find("SELECT * FROM studyinfo where ACCESSIONNUMBER=?", this.getPara("accno")); for (Record object : array) { try { String[] strings = object.getStr("YYK_PATHNAME").split("\\\\"); dService.downloadFileToFolder("smb://pacs:pacs@" + strings[2], "/" + strings[3] + "/" + strings[4], strings[5], "/home/zskk/SMB_FILE", null); } catch (Exception e) { // TODO: handle exception renderText(e.toString()); array2.add(object); } } renderJson(array2); } public void ttt4() { try { DataService dataService = new DataService(); dataService.downloadFileToFolder("smb://"+ "pacs:"+"pacs@"+"172.27.64.61", "/datacenter/20240115", "0532FB45.img", "/home/zskk/SMB_FILE",null); } catch (Exception e) { // TODO: handle exception this.renderText(e.toString()); } } public void sdcfind() { String execCmd = ExecUtil.execCmd("/zskk_system/other/cfind.sh " + this.getPara("time") + " STUDYUID_" + "temppp" + ".xml"); if (execCmd.contains("Connection refused")) { return; } File fin_floder = new File("/home/zskk/CFIND_XML/STUDYUID_" + "temppp" + "1.xml"); // 创建从文件读取数据的FileInputStream流 FileInputStream fin; try { fin = new FileInputStream(fin_floder); InputStreamReader isr = null; isr = new InputStreamReader(fin); BufferedReader raf = null; raf = new BufferedReader(isr); String xmlContent = null; xmlContent = raf.readLine(); xmlContent = xmlContent.replace("", ""); xmlContent = "" + xmlContent + ""; xmlContent = xmlContent.replace("�", ""); XmlHelper xmlHelper = XmlHelper.of(xmlContent); // NativeDicomModel节点列表 NodeList nativeDicomModelList = xmlHelper.getNodeList("/zskk/NativeDicomModel"); for (int i = 0; i < nativeDicomModelList.getLength(); i++) { String qString = ""; String studyuidString = ""; String modalitiesString = ""; // DicomAttribute节点列表 NodeList dicomAttributeList = xmlHelper.getNodeList(nativeDicomModelList.item(i), "DicomAttribute"); for (int j = 0; j < dicomAttributeList.getLength(); j++) { // DicomAttribute节点属性列表 NamedNodeMap attributeMap = dicomAttributeList.item(j).getAttributes(); if (attributeMap != null && attributeMap.getLength() > 0) { for (int k = 0; k < attributeMap.getLength(); k++) { if (attributeMap.item(k).getNodeName().equals("tag")) { // 获取studyuid if (attributeMap.item(k).getNodeValue().equals("0020000D")) { studyuidString = xmlHelper.getString(dicomAttributeList.item(j), "Value"); continue; } // 获取检查类型00080060or00080061 if (attributeMap.item(k).getNodeValue().equals("00080060")) { modalitiesString = xmlHelper.getString(dicomAttributeList.item(j), "Value"); } } } } } Record studyidfind = Db.use("local").findFirst("select * from study where studyuid = ?", studyuidString); if (studyidfind == null) { Record studyinfo = new Record().set("studyuid", studyuidString).set("modalities", modalitiesString) .set("status", 1).set("createAt", parseStringToDateTime()).set("updateAt", parseStringToDateTime()); Db.use("local").save("study", studyinfo); }else { studyidfind.set("status", 2); Db.use("local").update("study", studyidfind); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void sdreview() { try { DataService dService = ServiceFactory.getService(DataService.class); // "SELECT * FROM (select * from reportinfo where REVIEWDATE>to_date(?,'YYYY-MM-DD HH24:MI:SS')and rownum < 60)ORDER BY REVIEWDATE DESC", // List records = Db.use("connected").find("select * from reportinfo where REVIEWDATE between to_date(?,'YYYY-MM-DD HH24:MI:SS') and to_date(?,'YYYY-MM-DD HH24:MI:SS')", this.getPara("from"),this.getPara("to")); List records = Db.use("connected").find("select * from reportinfo where REVIEWDATE between ? and ?", this.getPara("from"),this.getPara("to")); if (records == null) { return; } for (Record record : records) { try { if (record.getStr("IMPRESSION") == null && record.getStr("DESCRIPTION") == null && record.getStr("REVIEWDOCTOR") == null) { continue; } Map params = new HashMap<>(); //1:exam_id 2:patient_num 3:accession_num 4:study_uid params.put("type", "3"); params.put("institution_id", PropKit.get("institution_id")); params.put("code", record.getStr("ACCESSIONNUMBER")); //报告医生姓名 params.put("report_doctor_name", record.getStr("REPORTDOCTOR")); //报告时间 params.put("report_datetime", record.getStr("REPORTDATE")); //审核医生姓名 params.put("review_doctor_name", record.getStr("REVIEWDOCTOR")==null?"":record.getStr("REVIEWDOCTOR")); //审核时间 params.put("review_datetime", record.getStr("REVIEWDATE")); //确认医生姓名 params.put("confirm_doctor_name", record.getStr("REVIEWDOCTOR")==null?"":record.getStr("REVIEWDOCTOR")); //确认时间 params.put("confirm_datetime", record.getStr("REVIEWDATE")); //意见建议 params.put("impression", record.getStr("IMPRESSION")); //影像所见 params.put("description", record.getStr("DESCRIPTION")); //exams表 //申请科室 params.put("application_department", record.getStr("DEPARTMENT")==null?"":record.getStr("DEPARTMENT")); //申请医生 params.put("application_doctor", record.getStr("CLINICALDOCTOR")==null?"":record.getStr("CLINICALDOCTOR")); //临床诊断 params.put("clin_diag", record.getStr("DIAGNOSIS")==null?"":record.getStr("DIAGNOSIS")); //症状 params.put("clin_symp", record.getStr("SYMPTOM")==null?"":record.getStr("SYMPTOM")); //patient_infos表 //患者姓名 params.put("name", record.getStr("PATIENTNAME")); //患者手机号 params.put("phone", record.getStr("PHONE")==null?"":record.getStr("PHONE")); //患者身份证号 params.put("card_num", record.getStr("IDCARD")==null?"":record.getStr("IDCARD")); //检查结果1阴2阳 params.put("report_result", record.getStr("RESULT").contains("是")?"2":"1"); //门诊号住院号 params.put("hopitalized_no", record.getStr("INPATIENTNUM")==null?"":record.getStr("INPATIENTNUM")); //门诊号 params.put("out_patient", record.getStr("OUTPATIENTNUM")==null?"":record.getStr("OUTPATIENTNUM")); //病人ID // params.put("his_patient_id", record.getStr("PATIENTID")==null?"":record.getStr("PATIENTID")); //检查方法 params.put("exam_project", record.getStr("PROJECT")==null?"":record.getStr("PROJECT")); ThreadPoolService tService = ServiceFactory.getService(ThreadPoolService.class); tService.execute(() -> { dService.saveReport(params); }); } catch (Exception e) { // TODO: handle exception continue; } } this.renderJson(records); } catch (Exception e) { // TODO: handle exception this.renderText(e.toString()); } } public static DruidPlugin createConnectedDruidPlugin() { return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim()); } /** * post请求 * @param url-请求地址 * @param map-参数集合 * @return */ private static String doPost(String url, Map map) { FormBody.Builder builder = new FormBody.Builder(); for (String key : map.keySet()) { builder.add(key, map.get(key)); } RequestBody formBody = builder.build(); Request request = new Request.Builder().url(url).post(formBody).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; } } private String parseStringToDate() { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); Date date = new Date(); long dInteger = date.getTime() - 86400000; String daString = sdf.format(new Date(dInteger)); return daString; } private String parseStringToDate2() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); long dInteger = date.getTime() - 300000; String daString = sdf.format(new Date(dInteger)); return daString; } /** * 日期字符串格式转换 * * @param dateStr * @return */ private String parseStringToDate1(String dString) { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); Date date = new Date(); long dInteger = date.getTime(); String daString = sdf.format(new Date(dInteger)); return daString; } /** * 日期字符串格式转换年月日时分秒 * * @param dateStr * @return */ private String parseStringToDateTime() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); String daString = sdf.format(date); return daString; } /** * 获取当前时间 * @param dateStr * @return */ private String getNowDate() { SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); //4小时 Date lastDate = new Date(date.getTime()-172800000); String timeString = null; timeString = sdf.format(lastDate); return timeString; } }