刘韬 5 年之前
父节点
当前提交
3684053d21

+ 97 - 0
ZSKK_DicomServer/pom.xml

@@ -0,0 +1,97 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>com.zskk</groupId>
+	<artifactId>ZSKK_DicomServer</artifactId>
+	<packaging>war</packaging>
+	<version>0.0.1-SNAPSHOT</version>
+	<name>ZSKK_DicomServer</name>
+	<url>http://maven.apache.org</url>
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+		<jdk.version>12</jdk.version>
+	</properties>
+	<dependencies>
+		<dependency>
+			<groupId>org.junit.jupiter</groupId>
+			<artifactId>junit-jupiter-api</artifactId>
+			<version>5.5.1</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.jfinal</groupId>
+			<artifactId>jfinal</artifactId>
+			<version>4.3</version>
+		</dependency>
+		<dependency>
+			<groupId>com.alibaba</groupId>
+			<artifactId>druid</artifactId>
+			<version>1.1.19</version>
+		</dependency>
+		<dependency>
+			<groupId>log4j</groupId>
+			<artifactId>log4j</artifactId>
+			<version>1.2.17</version>
+		</dependency>
+		<dependency>
+			<groupId>mysql</groupId>
+			<artifactId>mysql-connector-java</artifactId>
+			<version>8.0.17</version>
+		</dependency>
+		<dependency>
+			<groupId>javax.servlet</groupId>
+			<artifactId>javax.servlet-api</artifactId>
+			<version>4.0.1</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.jfinal</groupId>
+			<artifactId>jetty-server</artifactId>
+			<version>2019.3</version>
+			<scope>provided</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>org.dcm4che</groupId>
+			<artifactId>dcm4che-core</artifactId>
+			<version>5.18.0</version>
+		</dependency>
+		<dependency>
+			<groupId>org.dcm4che</groupId>
+			<artifactId>dcm4che-net</artifactId>
+			<version>5.18.0</version>
+		</dependency>
+	</dependencies>
+	<build>
+		<finalName>zskk_dicomserver_v3.0Beta1</finalName>
+		<plugins>
+			<plugin>
+				<artifactId>maven-war-plugin</artifactId>
+				<version>3.2.3</version>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.8.1</version>
+				<configuration>
+					<source>${jdk.version}</source>
+					<target>${jdk.version}</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+	<repositories>
+		<repository>
+			<id>Dcm4Che</id>
+			<name>Dcm4Che</name>
+			<url>http://www.dcm4che.org/maven2/</url>
+			<releases>
+				<enabled>true</enabled>
+			</releases>
+			<snapshots>
+				<enabled>false</enabled>
+			</snapshots>
+		</repository>
+	</repositories>
+</project>

+ 82 - 0
ZSKK_DicomServer/src/main/java/com/zskk/common/ZskkConfig.java

@@ -0,0 +1,82 @@
+/**
+ * Copyright (c) 2017-2019, lt 北京中世康恺科技有限公司 (www.pacsonline.cn).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ */
+
+package com.zskk.common;
+
+import com.jfinal.config.Constants;
+import com.jfinal.config.Handlers;
+import com.jfinal.config.Interceptors;
+import com.jfinal.config.JFinalConfig;
+import com.jfinal.config.Plugins;
+import com.jfinal.config.Routes;
+import com.jfinal.core.JFinal;
+import com.jfinal.kit.PropKit;
+import com.jfinal.template.Engine;
+import com.zskk.controller.DicomController;
+import com.zskk.service.ServiceFactory;
+
+public class ZskkConfig extends JFinalConfig {
+	// 本地开发模式
+	private boolean isLocalDev = false;
+
+	/**
+	 * 如果生产环境配置文件存在,则优先加载该配置,否则加载开发环境配置文件
+	 * 
+	 * @param pro 生产环境配置文件
+	 * @param dev 开发环境配置文件
+	 */
+	public void loadProp(String pro, String dev) {
+		try {
+			PropKit.use(pro);
+		} catch (Exception e) {
+			PropKit.use(dev);
+			isLocalDev = true;
+		}
+	}
+
+	public void configConstant(Constants me) {
+		loadProp("config.properties", "a_little_config.txt");
+		me.setDevMode(PropKit.getBoolean("devMode", false));
+	}
+
+	public void configRoute(Routes me) {
+		me.add("/msg", DicomController.class);
+	}
+
+	public void configPlugin(Plugins me) {
+		//预留数据库功能
+	}
+
+	public void configInterceptor(Interceptors me) {
+	
+	}
+
+	public void configHandler(Handlers me) {
+
+	}
+
+	/*/
+	 * 运行即启动
+	 */
+	@Override
+	public void onStart() {
+		// TODO Auto-generated method stub
+		super.onStart();
+		ServiceFactory.init();
+	}
+
+	/*/
+	 * 本地调试运行此处,线上发布注释main方法,并在maven配置文件注释jetty依赖
+	 */
+	public static void main(String[] args) {
+		JFinal.start("src/main/webapp", 10001, "/", 5);
+	}
+
+	@Override
+	public void configEngine(Engine engine) {
+
+	}
+}

+ 28 - 0
ZSKK_DicomServer/src/main/java/com/zskk/controller/DicomController.java

@@ -0,0 +1,28 @@
+package com.zskk.controller;
+
+import com.jfinal.core.Controller;
+import com.zskk.service.DicomEchoService;
+import com.zskk.service.ServiceFactory;
+
+public class DicomController extends Controller {
+	
+	/**
+	 * calledAeTitle-calledAeTitle,host-ip,port-端口号
+	 */
+	public void cEcho() {
+        String calledAeTitle = getPara("calledAeTitle");
+        String host = getPara("host");
+        Integer port = getParaToInt("port");
+
+		DicomEchoService dService = ServiceFactory.getService(DicomEchoService.class);
+		try {
+			dService.doEcho(calledAeTitle, host, port);
+			renderText("DICOM Echo succeed!");
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			renderText("DICOM Echo faild...");
+		}
+	}
+	
+}

+ 78 - 0
ZSKK_DicomServer/src/main/java/com/zskk/service/DicomEchoService.java

@@ -0,0 +1,78 @@
+package com.zskk.service;
+
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import org.dcm4che3.data.UID;
+import org.dcm4che3.net.ApplicationEntity;
+import org.dcm4che3.net.Association;
+import org.dcm4che3.net.Connection;
+import org.dcm4che3.net.Device;
+import org.dcm4che3.net.IncompatibleConnectionException;
+import org.dcm4che3.net.pdu.AAssociateRQ;
+import org.dcm4che3.net.pdu.PresentationContext;
+
+public class DicomEchoService {
+
+	private Device device;
+    private ApplicationEntity ae;
+    private Connection conn;
+
+    public void setExecutor(Executor executor) {
+        device.setExecutor(executor);
+    }
+
+    public void setScheduledExecutor(ScheduledExecutorService executor) {
+        device.setScheduledExecutor(executor);
+    }
+
+    public void echo(String calledAET, String hostName, int port)
+            throws IOException, InterruptedException, GeneralSecurityException, IncompatibleConnectionException {
+        Association as = ae.connect(mkConnection(hostName, port), mkAARQ(calledAET));
+        as.cecho();
+        as.release();
+    }
+
+    private AAssociateRQ mkAARQ(String calledAET) {
+        AAssociateRQ aarq = new AAssociateRQ();
+        aarq.setCallingAET(ae.getAETitle()); // optional: will be set in ae.connect() if not explicitly set.
+        aarq.setCalledAET(calledAET);
+        aarq.addPresentationContext(new PresentationContext(1,
+                UID.VerificationSOPClass, UID.ImplicitVRLittleEndian));
+        return aarq;
+    }
+
+    private Connection mkConnection(String hostName, int port) {
+        return new Connection(null, hostName, port);
+    }
+
+    /**
+     * 
+     * @param calledAeTitle
+     * @param host
+     * @param port
+     * @throws Exception
+     */
+    public void doEcho(String calledAeTitle, String host, Integer port) throws Exception {
+        ExecutorService executor = Executors.newSingleThreadExecutor();
+        ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
+        try {
+        	device = new Device("c-echo-scu");
+            ae = new ApplicationEntity("c-echo-scu");
+            conn = new Connection();
+            device.addApplicationEntity(ae);
+            device.addConnection(conn);
+            ae.addConnection(conn);
+            this.setExecutor(executor);
+            this.setScheduledExecutor(scheduledExecutor);
+            this.echo(calledAeTitle, host, port);
+        } finally {
+            executor.shutdown();
+            scheduledExecutor.shutdown();
+        }
+    }
+
+}

+ 29 - 0
ZSKK_DicomServer/src/main/java/com/zskk/service/ServiceFactory.java

@@ -0,0 +1,29 @@
+package com.zskk.service;
+
+import java.util.HashMap;
+import java.util.Map;
+import com.jfinal.aop.Duang;
+
+/**
+ * Service的工厂方法
+ * 使用工厂方法的主要目的是 为了AOP
+ * @author yht
+ *
+ */
+public class ServiceFactory {
+	private static final Map<Class<?>, Object> CLASS_MAP = new HashMap<Class<?>, Object>();
+	
+	/**
+	 * 初始化 创建Service
+	 */
+	public static void init(){
+		CLASS_MAP.put(ThreadPoolService.class, 	        Duang.duang(ThreadPoolService.class));
+		CLASS_MAP.put(DicomEchoService.class, 	        Duang.duang(DicomEchoService.class));
+
+	}
+	
+	@SuppressWarnings("unchecked")
+	public static <T> T getService(Class<T> c){
+		return (T)CLASS_MAP.get(c);
+	}
+}

+ 60 - 0
ZSKK_DicomServer/src/main/java/com/zskk/service/ThreadPoolService.java

@@ -0,0 +1,60 @@
+package com.zskk.service;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 线程池服务
+ * @author yht
+ *
+ */
+public class ThreadPoolService {
+	private static ExecutorService POOLS = null;
+	private static ScheduledExecutorService TIMER_POOLS = null;
+	public ThreadPoolService(){
+		POOLS		= Executors.newCachedThreadPool();
+		TIMER_POOLS = Executors.newScheduledThreadPool(1);
+	}
+
+	/**
+	 * 执行
+	 * @param run
+	 */
+	public void execute(Runnable run){
+		POOLS.execute(()->{
+			try{
+				run.run();
+			}catch(Exception e){
+//				LogUtil.sysError(e.getMessage(), e);
+			}
+		});
+	}
+	
+	/**
+	 * 提交任务
+	 * @param callable
+	 * @return
+	 */
+	public <T> Future<T>  submit(Callable<T> callable){
+		return POOLS.submit(callable);
+	}
+	
+	/**
+	 * 循环任务
+	 * @param call
+	 * @param delay
+	 */
+	public void schedule(Runnable call, long delay){
+		TIMER_POOLS.scheduleAtFixedRate(()->{
+			try{
+				call.run();
+			}catch(Exception e){
+//				LogUtil.sysError(e.getMessage(), e);
+			}
+		}, 0, delay, TimeUnit.MINUTES);
+	}
+}

+ 5 - 0
ZSKK_DicomServer/src/main/resources/config.properties

@@ -0,0 +1,5 @@
+#Database
+jdbcUrl  = jdbc:mysql://www.pacsonline.cn:3306/pacsonline?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
+user     = pacs
+password = ZSKK@2017~!@#
+devMode  = true

+ 12 - 0
ZSKK_DicomServer/src/main/resources/log4j.properties

@@ -0,0 +1,12 @@
+# log4j.rootLogger=WARN, stdout, file
+log4j.rootLogger=WARN, stdout, file
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%n%-d{yyyy-MM-dd HH:mm:ss}%n[%p]-[Thread: %t]-[%C.%M()]: %m%n
+
+# Output to the File
+log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.file.DatePattern='_'yyyy-MM-dd'.log'
+log4j.appender.file.File=./log/zskk_dicom_server_system.log
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%n%-d{yyyy-MM-dd HH:mm:ss}%n[%p]-[Thread: %t]-[%C.%M()]: %m%n

+ 19 - 0
ZSKK_DicomServer/src/main/webapp/WEB-INF/web.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
+  <display-name>PacsOnline_Wechat_Patient</display-name>
+  <filter>
+    <filter-name>zskk</filter-name>
+    <filter-class>com.jfinal.core.JFinalFilter</filter-class>
+    <init-param>
+      <param-name>configClass</param-name>
+      <param-value>com.zskk.common.ZskkConfig</param-value>
+    </init-param>
+  </filter>
+
+  <filter-mapping>
+    <filter-name>zskk</filter-name>
+    <url-pattern>/*</url-pattern>
+  </filter-mapping>
+</web-app>
+
+

+ 5 - 0
ZSKK_DicomServer/src/main/webapp/index.jsp

@@ -0,0 +1,5 @@
+<html>
+<body>
+<h2>Hello World!</h2>
+</body>
+</html>