概述

dcm4che是一个开源临床影像与对象管理系统,针对医疗企业的开源程序和实用软件的集合,基于java语言开发,支持JDK1.6以上的开发。

DICOM网络传输采用的是C/S模式,storescu(客户端)/storescp(服务端)主要是处理dicom文件的传输存储,
本文主要记录使用dcm4che实现storescp中C-STORE服务类型的学习心得。

步骤

  1. pom中引入dcm4che的依赖jar包
  2. 设置(org.dcm4che3.net.Connection)连接的IP和端口
  3. 设置(org.dcm4che3.net.ApplicationEntity)AETitle的名称,服务类型和过滤器
  4. 启动service

引入依赖

        <dependency><groupId>org.dcm4che</groupId><artifactId>dcm4che-core</artifactId><version>5.23.3</version></dependency><dependency><groupId>org.dcm4che.tool</groupId><artifactId>dcm4che-tool-storescu</artifactId><version>5.23.3</version></dependency><dependency><groupId>org.dcm4che</groupId><artifactId>dcm4che-net</artifactId><version>5.23.3</version></dependency><dependency><groupId>org.dcm4che</groupId><artifactId>dcm4che-imageio</artifactId><version>5.23.3</version></dependency><dependency><groupId>org.dcm4che</groupId><artifactId>dcm4che-imageio-opencv</artifactId><version>5.23.3</version></dependency>

实现C-STORE

import org.dcm4che3.data.Attributes;
import org.dcm4che3.data.Tag;
import org.dcm4che3.data.VR;
import org.dcm4che3.io.DicomOutputStream;
import org.dcm4che3.net.*;
import org.dcm4che3.net.pdu.PresentationContext;
import org.dcm4che3.net.service.BasicCEchoSCP;
import org.dcm4che3.net.service.BasicCStoreSCP;
import org.dcm4che3.net.service.DicomServiceException;
import org.dcm4che3.net.service.DicomServiceRegistry;
import org.dcm4che3.util.SafeClose;import java.io.File;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;public class DcmCStoreSCP {private final Device device = new Device("storescp");private final ApplicationEntity ae = new ApplicationEntity("*");private final Connection conn = new Connection();private String saveDir = "D:/dicomFile/cacheData/"; //接收到dicom文件的存储目录ExecutorService executorService  = Executors.newCachedThreadPool();private final BasicCStoreSCP cstoreSCP = new BasicCStoreSCP("*") {private static final String PART_EXT = ".part";@Overrideprotected void store(Association as, PresentationContext pc,Attributes rq, PDVInputStream data, Attributes rsp)throws IOException {try {rsp.setInt(Tag.Status, VR.US, 0);if (saveDir == null)return;String cuid = rq.getString(Tag.AffectedSOPClassUID);String iuid = rq.getString(Tag.AffectedSOPInstanceUID);String tsuid = pc.getTransferSyntax();File file = new File(saveDir, iuid + PART_EXT);try {storeTo(as, as.createFileMetaInformation(iuid, cuid, tsuid),data, file);renameTo(as, file, new File(saveDir, iuid));} catch (Exception e) {file.delete();throw new DicomServiceException(Status.ProcessingFailure, e);}} finally {}}};public DcmCStoreSCP() {device.setDimseRQHandler(createServiceRegistry());device.addConnection(conn);device.addApplicationEntity(ae);ae.setAssociationAcceptor(true);ae.addConnection(conn);}public void setPort(int nPort) {if(conn == null) {return;}conn.setPort(nPort);}public void setIP(String strIP) {if(conn == null) {return;}conn.setHostname(strIP);}public void setAETitle(String strAETitle) throws IOException {ae.setAETitle(strAETitle);ae.addTransferCapability(new TransferCapability(null, "*", TransferCapability.Role.SCP, "*"));}public void statrService() throws IOException, GeneralSecurityException {device.setExecutor(executorService);ScheduledExecutorService scheduledExecutorService =Executors.newSingleThreadScheduledExecutor();device.setScheduledExecutor(scheduledExecutorService);device.bindConnections();}private DicomServiceRegistry createServiceRegistry() {DicomServiceRegistry serviceRegistry = new DicomServiceRegistry();serviceRegistry.addDicomService(new BasicCEchoSCP());serviceRegistry.addDicomService(cstoreSCP);return serviceRegistry;}private void storeTo(Association as, Attributes fmi,PDVInputStream data, File file) throws IOException  {file.getParentFile().mkdirs();DicomOutputStream out = new DicomOutputStream(file);try {out.writeFileMetaInformation(fmi);data.copyTo(out);} finally {SafeClose.close(out);}}private void renameTo(Association as, File from, File dest)throws IOException {if (!dest.getParentFile().mkdirs())dest.delete();if (!from.renameTo(dest))throw new IOException("Failed to rename " + from + " to " + dest);}
}

设置IP/端口,AETITLE,初始化服务

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;import java.io.IOException;
import java.security.GeneralSecurityException;@Component
public class DcmInit implements ApplicationRunner {@Overridepublic void run(ApplicationArguments args) throws Exception {DcmCStoreSCP scp=new DcmCStoreSCP();scp.setIP("127.0.0.1");scp.setPort(102);try {scp.setAETitle("aetest");scp.statrService();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (GeneralSecurityException e) {// TODO Auto-generated catch blocke.printStackTrace();}}
}

运行测试

可以借助dcm4che提供的SCU方式进行测试。

cmd命令,切换到dcm4che的bin目录下,

执行storescu --help可以查看相关帮助命令

执行如下命令发送文件

storescu -c aetest@127.0.0.1:102 D:/IMAGE/DICOMDIR

执行完可看到对应的目录下已经接收到发送的文件(这里我发送了其它dicom图)

以上为我初步研究学习使用DCM4CHE实现一个C-STORE --storescp的过程记录。

DCM4CHE实现DICOM的C-STORE --STORESCP相关推荐

  1. dcm4che解析DICOM文件生成JPEG图像

    dcm4che概述 dcm4che是为专注于医疗健康企业开发的基于DICOM标准的开源应用和工具的集合.目前最新的版本是dcm4che3.3.8.本片文章主要讲的是使用dcm4che3.3.8解析DI ...

  2. 使用 dcm4che 操作 Dicom 文件

    一.使用dcm4che3的准备工作 1.1.dcm4che git地址:GitHub - dcm4che/dcm4che: DICOM Implementation in JAVA 1.2. 执行 m ...

  3. 【转】000.DICOM:DICOM标准学习路线图(初稿)!!!!!!!!!!!!

    转自:https://zssure.blog.csdn.net/article/details/49231303 题记: DICOM医学图像处理专栏撰写已有两个年头,积累了近百篇文章. 起初 只是用于 ...

  4. DICOM:DICOM标准学习路线图(初稿)

    题记: DICOM医学图像处理专栏撰写已有两个年头,积累了近百篇文章. 起初 只是用于记录自己科研.工作中遇到的疑难问题,专注于图像处理(主要是医学图像,这也正是专栏名称最初的由来):后来逐渐延伸到了 ...

  5. DICOM医学图像处理:二零一四▪DICOM专栏一览

    题记 二零一四刚过,新年伊始就发生了"外滩踩踏"恶性事件,告诫我们要珍爱生命,为自己更为家人-- 回顾去年,有些许收获.有些许感慨-- 曾经听过一个段子说两个在公司工作多年的老员工 ...

  6. [医疗信息化][DICOM教程]DICOM标准简介

    [医疗信息化][DICOM教程]DICOM标准简介 使用OsiriX的DICOM标准简介 内容 介绍 什么是DICOM 医院系统内的图像传输 了解DICOM服务 OsiriX提供的DICOM服务 其他 ...

  7. Python处理医学影像学中的DICOM

    DICOMDICOM(Digital Imaging and Communications in Medicine)即医学数字成像和通信,是医学图像和相关信息的国际标准(ISO 12052).它定义了 ...

  8. Python 处理医学影像学中的DICOM

    DICOMDICOM(Digital Imaging and Communications in Medicine)即医学数字成像和通信,是医学图像和相关信息的国际标准(ISO 12052).它定义了 ...

  9. 搭建 dicom 开发环境

    搭建 dicom 开发环境 搭建 dcm4chee-arc-light (可选) 准备vagrant 准备docker dcm4che/dcm4chee-arc-light dicom 开发环境 编译 ...

最新文章

  1. linux查找文件命令find
  2. python2 python3编码_Python2和Python3编码问题-从底层出发
  3. 浅谈机房内的汇流铜排
  4. 二叉树的层序遍历算法 + 打印二叉树所有最左边的元素(算法)
  5. boost::spirit模块实现在正确引用的情况下打印任何字符序列的测试程序
  6. 模拟退火算法求解TSP问题
  7. java swing rectangle_Java SwingUtilities.convertRectangle方法代碼示例
  8. Kubernetes持久化方案(PV、PVC、StorageClass)
  9. 问一个 TCP 连接可以发多少个 HTTP 请求?
  10. ARP协议报文格式及ARP表
  11. 学生管理数据库,及相关查询
  12. 一年时间,拿到了人生中的第一个20万
  13. RSD处理高分5号高光谱(GF5 AHSI)数据(四)——从地物光谱搜索高光谱数据集
  14. mysql: load data与select into outfile
  15. 我确实不知道如何使用计算机翻译,新视野大学英语4课后翻译
  16. Android 选择图片、上传图片之ImagePicker
  17. 123457123456#0#-----com.threeapp.MakerHanBao01----儿童汉堡制作游戏
  18. linux删除文件最后一行换行符,linux - 使用sed删除最后一个换行符 - 堆栈内存溢出...
  19. python3多行输入字符串_python中怎么输入多行字符串
  20. 用友软件显示系统加密服务器,用友云主机指向加密服务器

热门文章

  1. 【漫画】互联网人叹气图鉴
  2. cmd中启动MySQL输入net start mysql 显示‘net‘不是内部或外部命令,也不是可运行的程序或批处理的文件。
  3. 李筱懿:视频号如何运营才能出爆款?
  4. 【LeetCode】723. Candy Crush 解题报告 (C++)
  5. Rapidly-Exploring Random Trees(RRT)
  6. 会议室大屏幕用投影还是拼接屏好?
  7. vue-quill-editor编辑器文本不居中问题处理
  8. c语言中f1是什么意思啊,F1知识科普,这些字母代表什么你知道吗?
  9. 复旦大学和吉大计算机考研选哪个,复旦综合实力强,但这个学科比不上吉大,考生该怎么报考...
  10. fluent-bit代替filebeat实战(smartgate、nginx)