Browse Source

调整为cmove模式

刘韬 2 years ago
parent
commit
d9ac497170

+ 6 - 6
DataFusion/src/com/zskk/config/ZskkConfig.java

@@ -91,13 +91,13 @@ public class ZskkConfig extends JFinalConfig {
 		cfData.addTask("*/2 * * * *", new CFindTask());
 		me.add(cfData);
 		
-//		Cron4jPlugin cpData = new Cron4jPlugin();
-//		cpData.addTask("*/8 * * * *", new DataTask());
-//		me.add(cpData);
+		Cron4jPlugin cpData = new Cron4jPlugin();
+		cpData.addTask("*/8 * * * *", new DataTask());
+		me.add(cpData);
 		
-//		Cron4jPlugin inData = new Cron4jPlugin();
-//		inData.addTask("*/4 * * * *", new UpdateTask());
-//		me.add(inData);
+		Cron4jPlugin inData = new Cron4jPlugin();
+		inData.addTask("*/3 * * * *", new UpdateTask());
+		me.add(inData);
 		
 //		Cron4jPlugin cgData = new Cron4jPlugin();
 //		cgData.addTask("*/1 * * * *", new CGetTask());

+ 16 - 5
DataFusion/src/com/zskk/task/DataTask.java

@@ -8,6 +8,7 @@ import java.util.Map;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.jfinal.kit.PropKit;
 import com.jfinal.plugin.activerecord.Db;
 import com.jfinal.plugin.activerecord.Record;
 import com.jfinal.plugin.cron4j.ITask;
@@ -24,7 +25,7 @@ public class DataTask implements ITask {
         JSONArray jsonArray = dService.getExamList(80);	
         for (Object object : jsonArray) {
 			JSONObject jsonObject = JSON.parseObject(object.toString());
-			Record record = Db.use("connected").findFirst("select * from reportinfo where accessionNumber=?", jsonObject.getString("accession_num"));
+			Record record = Db.use("connected").findFirst("select * from reportinfo where studyuid=?", jsonObject.getString("studyuid"));
 			if (record == null) {
 				continue;
 			}
@@ -32,7 +33,11 @@ public class DataTask implements ITask {
 				continue;
 			}
 			Map<String, String> params = new HashMap<>();
-			params.put("exam_id", jsonObject.getString("id"));
+			params.put("type", "1");
+			
+			params.put("institution_id", PropKit.get("institution_id"));
+
+			params.put("code", jsonObject.getString("id"));
 			//报告医生姓名
 			params.put("report_doctor_name", record.getStr("reportdoctor"));
 			//报告时间
@@ -57,7 +62,7 @@ public class DataTask implements ITask {
 			//临床诊断
 			params.put("clin_diag", record.getStr("diagnosis"));
 			//症状
-			params.put("clin_symp", "");
+			params.put("clin_symp", record.getStr("symptom")==null?record.getStr("symptom"):"");
 			//patient_infos表
 			//患者姓名
 			params.put("name", record.getStr("patientname"));
@@ -66,9 +71,15 @@ public class DataTask implements ITask {
 			//患者身份证号
 			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("report_result", record.getStr("result").contains("false")?"1":"2");
 			//门诊号住院号
-//			params.put("hopitalized_no", record.getStr("hospitalNumber")==null?"":record.getStr("hospitalNumber"));
+			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("patient")==null?"":record.getStr("patient"));
+			//检查方法
+			params.put("exam_project", record.getStr("project"));
 			ThreadPoolService tService = ServiceFactory.getService(ThreadPoolService.class);
 			tService.execute(() -> {
 				dService.saveReport(params);

+ 82 - 9
DataFusion/src/com/zskk/task/UpdateTask.java

@@ -1,24 +1,82 @@
 package com.zskk.task;
 
+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.Date;
 import java.util.List;
+
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.NodeList;
+
 import com.jfinal.plugin.activerecord.Db;
 import com.jfinal.plugin.activerecord.Record;
 import com.jfinal.plugin.cron4j.ITask;
+import com.zskk.tools.XmlHelper;
 
 public class UpdateTask implements ITask {
 
 	@Override
 	public void run() {
 		// TODO Auto-generated method stub
-		List<Record> records = Db.use("connected").find("select StudyInstanceUID,PatientStudyDate from reportinfo_image where PatientStudyDate>? group by PatientStudyDate,StudyInstanceUID order by PatientStudyDate desc", parseStringToDate());
-		for (Record record : records) {
-			Record studyidfind = Db.use("local").findFirst("select * from study where studyuid = ?",record.getStr("StudyInstanceUID"));
-			if (studyidfind == null) {
-				Record studyinfo = new Record().set("studyuid", record.getStr("StudyInstanceUID")).set("status", 1).set("createAt", record.getStr("PatientStudyDate"));
-				Db.use("local").save("study", studyinfo);
+		String dateString = parseStringToDate();
+		String fileString = dateString.replace("0", "o");
+		File fin_floder = new File("/home/zskk/CFIND_XML/STUDYUID_" + fileString + "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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
+			xmlContent = "<zskk>" + xmlContent + "</zskk>";
+			xmlContent = xmlContent.replace("&#0", "");
+			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("00080061")) {
+									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());
+					Db.use("local").save("study", studyinfo);
+				}
 			}
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
 		}
 	}
 
@@ -29,18 +87,33 @@ public class UpdateTask implements ITask {
 	}
 	
 	/**
-	 * 日期字符串格式转换
+	 * 日期字符串格式转换年月日
 	 * 
 	 * @param dateStr
 	 * @return
 	 */
 	private String parseStringToDate() {
-		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
 		Date date = new Date();
-		long dInteger = date.getTime() - 600000;
+		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;
+
+	}
+	
 
 }

+ 19 - 0
DataFusion/src/com/zskk/tools/Charsets.java

@@ -0,0 +1,19 @@
+    package com.zskk.tools;
+
+    import java.nio.charset.Charset;
+
+    /**
+     * 字符集工具类
+     * Author: L.cm
+     * Date: 2016年3月29日 下午3:44:52
+     */
+    public class Charsets {
+
+        // 字符集GBK
+        public static final Charset GBK = Charset.forName("GBK");
+        // 字符集ISO-8859-1
+        public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
+        // 字符集utf-8
+        public static final Charset UTF_8 = Charset.forName("UTF-8");
+
+    }

+ 76 - 0
DataFusion/src/com/zskk/tools/IOUtils.java

@@ -0,0 +1,76 @@
+    package com.zskk.tools;
+
+    import java.io.*;
+    import java.nio.charset.Charset;
+
+    /**
+     * IOUtils
+     * @author L.cm
+     */
+    public abstract class IOUtils {
+        private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
+
+        /**
+         * closeQuietly
+         * @param closeable 自动关闭
+         */
+        public static void closeQuietly(Closeable closeable) {
+            try {
+                if (closeable != null) {
+                    closeable.close();
+                }
+            } catch (IOException ioe) {
+                // ignore
+            }
+        }
+
+        /**
+         * InputStream to String utf-8
+         *
+         * @param input  the <code>InputStream</code> to read from
+         * @return the requested String
+         * @throws NullPointerException if the input is null
+         * @throws IOException if an I/O error occurs
+         */
+        public static String toString(InputStream input) throws IOException {
+            return toString(input, Charsets.UTF_8);
+        }
+
+        /**
+         * InputStream to String
+         *
+         * @param input  the <code>InputStream</code> to read from
+         * @param charset  the <code>Charset</code>
+         * @return the requested String
+         * @throws NullPointerException if the input is null
+         * @throws IOException if an I/O error occurs
+         */
+        public static String toString(InputStream input, Charset charset) throws IOException {
+            InputStreamReader in = new InputStreamReader(input, charset);
+            StringBuffer out = new StringBuffer();
+            char[] c = new char[DEFAULT_BUFFER_SIZE];
+            for (int n; (n = in.read(c)) != -1;) {
+                out.append(new String(c, 0, n));
+            }
+            IOUtils.closeQuietly(in);
+            IOUtils.closeQuietly(input);
+            return out.toString();
+        }
+
+        /**
+         * InputStream to File
+         * @param input  the <code>InputStream</code> to read from
+         * @param file the File to write
+         * @throws IOException id异常
+         */
+        public static void toFile(InputStream input, File file) throws IOException {
+            OutputStream os = new FileOutputStream(file);
+            int bytesRead = 0;
+            byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
+            while ((bytesRead = input.read(buffer, 0, DEFAULT_BUFFER_SIZE)) != -1) {
+                os.write(buffer, 0, bytesRead);
+            }
+            IOUtils.closeQuietly(os);
+            IOUtils.closeQuietly(input);
+        }
+    }

+ 241 - 0
DataFusion/src/com/zskk/tools/XmlHelper.java

@@ -0,0 +1,241 @@
+    package com.zskk.tools;
+
+    import org.w3c.dom.Document;
+    import org.w3c.dom.Element;
+    import org.w3c.dom.Node;
+    import org.w3c.dom.NodeList;
+    import org.xml.sax.InputSource;
+    import org.xml.sax.SAXException;
+
+    import javax.xml.namespace.QName;
+    import javax.xml.parsers.DocumentBuilder;
+    import javax.xml.parsers.DocumentBuilderFactory;
+    import javax.xml.parsers.ParserConfigurationException;
+    import javax.xml.xpath.XPath;
+    import javax.xml.xpath.XPathConstants;
+    import javax.xml.xpath.XPathExpressionException;
+    import javax.xml.xpath.XPathFactory;
+    import java.io.IOException;
+    import java.io.InputStream;
+    import java.io.StringReader;
+    import java.util.HashMap;
+    import java.util.Map;
+
+    /**
+     * xpath解析xml
+     * <pre>
+     *     文档地址:
+     *     http://www.w3school.com.cn/xpath/index.asp
+     * </pre>
+     */
+    public class XmlHelper {
+        private final XPath path;
+        private final Document doc;
+
+        private XmlHelper(InputSource inputSource) throws ParserConfigurationException, SAXException, IOException {
+            DocumentBuilderFactory dbf = getDocumentBuilderFactory();
+            DocumentBuilder db = dbf.newDocumentBuilder();
+            doc = db.parse(inputSource);
+            path = getXPathFactory().newXPath();
+        }
+
+        private static XmlHelper create(InputSource inputSource) {
+            try {
+                return new XmlHelper(inputSource);
+            } catch (ParserConfigurationException e) {
+                throw new RuntimeException(e);
+            } catch (SAXException e) {
+                throw new RuntimeException(e);
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        public static XmlHelper of(InputStream is) {
+            InputSource inputSource = new InputSource(is);
+            return create(inputSource);
+        }
+
+        public static XmlHelper of(String xmlStr) {
+            StringReader sr = new StringReader(xmlStr.trim());
+            InputSource inputSource = new InputSource(sr);
+            XmlHelper xmlHelper = create(inputSource);
+            IOUtils.closeQuietly(sr);
+            return xmlHelper;
+        }
+
+        private Object evalXPath(String expression, Object item, QName returnType) {
+            item = null == item ? doc : item;
+            try {
+                return path.evaluate(expression, item, returnType);
+            } catch (XPathExpressionException e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        /**
+         * 获取String
+         * @param expression 路径
+         * @return String
+         */
+        public String getString(String expression) {
+            return (String) evalXPath(expression, null, XPathConstants.STRING);
+        }
+
+        /**
+         * 获取Boolean
+         * @param expression 路径
+         * @return String
+         */
+        public Boolean getBoolean(String expression) {
+            return (Boolean) evalXPath(expression, null, XPathConstants.BOOLEAN);
+        }
+
+        /**
+         * 获取Number
+         * @param expression 路径
+         * @return {Number}
+         */
+        public Number getNumber(String expression) {
+            return (Number) evalXPath(expression, null, XPathConstants.NUMBER);
+        }
+
+        /**
+         * 获取某个节点
+         * @param expression 路径
+         * @return {Node}
+         */
+        public Node getNode(String expression) {
+            return (Node) evalXPath(expression, null, XPathConstants.NODE);
+        }
+
+        /**
+         * 获取子节点
+         * @param expression 路径
+         * @return NodeList
+         */
+        public NodeList getNodeList(String expression) {
+            return (NodeList) evalXPath(expression, null, XPathConstants.NODESET);
+        }
+
+
+        /**
+         * 获取String
+         * @param node 节点
+         * @param expression 相对于node的路径
+         * @return String
+         */
+        public String getString(Object node, String expression) {
+            return (String) evalXPath(expression, node, XPathConstants.STRING);
+        }
+
+        /**
+         * 获取
+         * @param node 节点
+         * @param expression 相对于node的路径
+         * @return String
+         */
+        public Boolean getBoolean(Object node, String expression) {
+            return (Boolean) evalXPath(expression, node, XPathConstants.BOOLEAN);
+        }
+
+        /**
+         * 获取
+         * @param node 节点
+         * @param expression 相对于node的路径
+         * @return {Number}
+         */
+        public Number getNumber(Object node, String expression) {
+            return (Number) evalXPath(expression, node, XPathConstants.NUMBER);
+        }
+
+        /**
+         * 获取某个节点
+         * @param node 节点
+         * @param expression 路径
+         * @return {Node}
+         */
+        public Node getNode(Object node, String expression) {
+            return (Node) evalXPath(expression, node, XPathConstants.NODE);
+        }
+
+        /**
+         * 获取子节点
+         * @param node 节点
+         * @param expression 相对于node的路径
+         * @return NodeList
+         */
+        public NodeList getNodeList(Object node, String expression) {
+            return (NodeList) evalXPath(expression, node, XPathConstants.NODESET);
+        }
+
+        /**
+         * 针对没有嵌套节点的简单处理
+         * @return map集合
+         */
+        public Map<String, String> toMap() {
+            Element root = doc.getDocumentElement();
+            Map<String, String> params = new HashMap<String, String>();
+
+            // 将节点封装成map形式
+            NodeList list = root.getChildNodes();
+            for (int i = 0; i < list.getLength(); i++) {
+                Node node = list.item(i);
+                if (node instanceof Element) {
+                    params.put(node.getNodeName(), node.getTextContent());
+                }
+            }
+            return params;
+        }
+        
+        private static boolean preventedXXE = false;
+
+        private static DocumentBuilderFactory getDocumentBuilderFactory() throws ParserConfigurationException{
+        		DocumentBuilderFactory dbf = XmlHelper.XmlHelperHolder.documentBuilderFactory;
+        		if (!preventedXXE) {
+        			preventXXE(dbf);
+        			preventedXXE = true;
+        		}
+            return dbf;
+        }
+        
+        // https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=23_5
+        private static void preventXXE(DocumentBuilderFactory dbf) throws ParserConfigurationException {
+        		// This is the PRIMARY defense. If DTDs (doctypes) are disallowed, almost all XML entity attacks are prevented
+            // Xerces 2 only - http://xerces.apache.org/xerces2-j/features.html#disallow-doctype-decl
+            dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
+
+            // If you can't completely disable DTDs, then at least do the following:
+            // Xerces 1 - http://xerces.apache.org/xerces-j/features.html#external-general-entities
+            // Xerces 2 - http://xerces.apache.org/xerces2-j/features.html#external-general-entities
+
+            // JDK7+ - http://xml.org/sax/features/external-general-entities 
+            dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
+
+            // Xerces 1 - http://xerces.apache.org/xerces-j/features.html#external-parameter-entities
+            // Xerces 2 - http://xerces.apache.org/xerces2-j/features.html#external-parameter-entities
+
+            // JDK7+ - http://xml.org/sax/features/external-parameter-entities 
+            dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
+
+            // Disable external DTDs as well
+            dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
+
+            // and these as well, per Timothy Morgan's 2014 paper: "XML Schema, DTD, and Entity Attacks"
+            dbf.setXIncludeAware(false);
+            dbf.setExpandEntityReferences(false);
+        }
+
+        private static XPathFactory getXPathFactory() {
+            return  XmlHelper.XmlHelperHolder.xPathFactory;
+        }
+
+        /**
+         * 内部类单例
+         */
+        private static class XmlHelperHolder {
+            private static DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+            private static XPathFactory xPathFactory = XPathFactory.newInstance();
+        }
+
+    }