首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从JAVA程序使用dcm4chee连接到dcm4che

从JAVA程序使用dcm4chee连接到dcm4che
EN

Stack Overflow用户
提问于 2018-03-01 11:11:51
回答 3查看 2.8K关注 0票数 6

更新

我在dcm4che的源代码中进行了更深入的研究,发现如果

  • 连接是“未安装”。
  • 或者协议的类型没有设置或不匹配。

我不知道“已安装”连接意味着什么,但可以手动设置此标志,因此我将其设置为指向true的本地和远程连接(甚至用getInstalled()检查它们是否“安装”--是的--以前该属性是null)。

至于协议,它们没有被指定,所以对于这两个连接,我将它们设置为DICOM

结果:我仍然得到同样的例外。

我想使用dcm4chee (5.12.0)工具包在dcm4che (2.18.3)和我的JAVA应用程序之间建立一个DICOM关联。

问题是,似乎没有任何关于如何在JAVA应用程序中使用dcm4che的文档,所以我所能做的就是阅读dcm4che的源代码,并试图弄清楚它的类和方法是用来做什么的,但是我被困住了。如果有人已经有一个工作的例子,这将是非常有帮助的。

到目前为止,我已经:

代码语言:javascript
复制
import org.dcm4che3.net.ApplicationEntity;
import org.dcm4che3.net.Association;
import org.dcm4che3.net.Connection;
import org.dcm4che3.net.Device;
import org.dcm4che3.net.pdu.AAssociateRQ;
import org.dcm4che3.net.pdu.PresentationContext;

...

ApplicationEntity locAE = new ApplicationEntity();
locAE.setAETitle("THIS_JAVA_APP");

Connection localConn = new Connection();
localConn.setCommonName("loc_conn");
localConn.setHostname("localhost");
localConn.setPort(11112);
localConn.setProtocol(Connection.Protocol.DICOM);
localConn.setInstalled(true);
locAE.addConnection(localConn);

ApplicationEntity remAE = new ApplicationEntity();
remAE.setAETitle("DCM4CHEE");

Connection remoteConn = new Connection();
remoteConn.setCommonName("rem_conn");
remoteConn.setHostname("localhost");
remoteConn.setPort(11112);
remoteConn.setProtocol(Connection.Protocol.DICOM);
remoteConn.setInstalled(true);
remAE.addConnection(remoteConn);

AAssociateRQ assocReq = new AAssociateRQ();
assocReq.setCalledAET(remAE.getAETitle());
assocReq.setCallingAET(locAE.getAETitle());
assocReq.setApplicationContext("1.2.840.10008.3.1.1.1");
assocReq.setImplClassUID("1.2.40.0.13.1.3");
assocReq.setImplVersionName("dcm4che-5.12.0");
assocReq.setMaxPDULength(16384);
assocReq.setMaxOpsInvoked(0);
assocReq.setMaxOpsPerformed(0);
assocReq.addPresentationContext(new PresentationContext(
    1, "1.2.840.10008.1.1", "1.2.840.10008.1.2"));

Device device = new Device("device");
device.addConnection(localConn);
device.addApplicationEntity(locAE);

Association assoc = locAE.connect(remAE, assocReq);

但我不知道我是否走上了正确的道路。

我所犯的错误:

代码语言:javascript
复制
org.dcm4che3.net.IncompatibleConnectionException: No compatible connection to DCM4CHEE available on THIS_JAVA_APP
at org.dcm4che3.net.ApplicationEntity.findCompatibelConnection(ApplicationEntity.java:646)
at org.dcm4che3.net.ApplicationEntity.connect(ApplicationEntity.java:651)
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-03-02 22:23:22

这是工作代码:(我不知道这是否是最小的解决方案,请随意试用.)

代码语言:javascript
复制
ApplicationEntity locAE = new ApplicationEntity();
locAE.setAETitle("THIS_JAVA_APP");
locAE.setInstalled(true);

Connection localConn = new Connection();
localConn.setCommonName("loc_conn");
localConn.setHostname("localhost");
localConn.setPort(11112);
localConn.setProtocol(Connection.Protocol.DICOM);
localConn.setInstalled(true);
locAE.addConnection(localConn);

ApplicationEntity remAE = new ApplicationEntity();
remAE.setAETitle("DCM4CHEE");
remAE.setInstalled(true);

Connection remoteConn = new Connection();
remoteConn.setCommonName("rem_conn");
remoteConn.setHostname("localhost");
remoteConn.setPort(11112);
remoteConn.setProtocol(Connection.Protocol.DICOM);
remoteConn.setInstalled(true);
remAE.addConnection(remoteConn);

AAssociateRQ assocReq = new AAssociateRQ();
assocReq.setCalledAET(remAE.getAETitle());
assocReq.setCallingAET(locAE.getAETitle());
assocReq.setApplicationContext("1.2.840.10008.3.1.1.1");
assocReq.setImplClassUID("1.2.40.0.13.1.3");
assocReq.setImplVersionName("dcm4che-5.12.0");
assocReq.setMaxPDULength(16384);
assocReq.setMaxOpsInvoked(0);
assocReq.setMaxOpsPerformed(0);
assocReq.addPresentationContext(new PresentationContext(
    1, "1.2.840.10008.1.1", "1.2.840.10008.1.2"));

Device device = new Device("device");
device.addConnection(localConn);
device.addApplicationEntity(locAE);

Executor exec = (Runnable command) -> {};
device.setExecutor(exec);

Association assoc = locAE.connect(localConn, remoteConn, assocReq);

以及相关的dcm4chee日志:

代码语言:javascript
复制
2018-03-02 23:21:42,832 INFO  THIS_JAVA_APP->DCM4CHEE (TCPServer-1) [org.dcm4cheri.net.FsmImpl] received AAssociateRQ
    appCtxName: 1.2.840.10008.3.1.1.1/DICOM Application Context Name
    implClass:  1.2.40.0.13.1.3
    implVersion:    dcm4che-5.12.0
    calledAET:  DCM4CHEE
    callingAET: THIS_JAVA_APP
    maxPDULen:  16378
    asyncOpsWindow: 
    pc-1:   as=1.2.840.10008.1.1/Verification SOP Class
        ts=1.2.840.10008.1.2/Implicit VR Little Endian
2018-03-02 23:21:42,843 INFO  THIS_JAVA_APP->DCM4CHEE (TCPServer-1) [org.dcm4cheri.net.FsmImpl] sending AAssociateAC
    appCtxName: 1.2.840.10008.3.1.1.1/DICOM Application Context Name
    implClass:  1.2.40.0.13.1.1.1
    implVersion:    dcm4che-1.4.34
    calledAET:  DCM4CHEE
    callingAET: THIS_JAVA_APP
    maxPDULen:  16352
    asyncOpsWindow: 
    pc-1:   0 - acceptance
        ts=1.2.840.10008.1.2/Implicit VR Little Endian

在您有了关联之后,请看另一篇文章用于如何执行一个C-查找。

票数 1
EN

Stack Overflow用户

发布于 2018-03-02 09:48:18

可能是,您在安装过程中缺少了一个Device实例?看起来,您需要一个Device,它同时附加了ApplicationEntityConnection

FindSCU.java源查看dcm4che源。

代码语言:javascript
复制
private final Device device = new Device("findscu");
private final ApplicationEntity ae = new ApplicationEntity("FINDSCU");
private final Connection conn = new Connection();

public FindSCU() throws IOException {
    device.addConnection(conn);
    device.addApplicationEntity(ae);
    ae.addConnection(conn);
}

我还认为,可能可以在没有任何参数的情况下实例化本地Connection对象,如这里的FindSCU示例所示。也许参数在某种程度上混淆了它,特别是考虑到您有指向localhost:11112的本地和远程连接。

但是,是的,我们必须承认,dcm4che3 API的文档是完全不够的。

票数 2
EN

Stack Overflow用户

发布于 2018-10-24 15:27:44

编辑

显然,我解决了这个问题。将遗嘱执行人改为

代码语言:javascript
复制
Executor exec = (Runnable command) -> {};
device.setExecutor(exec);

代码语言:javascript
复制
ExecutorService executorService = Executors.newSingleThreadExecutor();
ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
device.setExecutor(executorService);
device.setScheduledExecutor(scheduledExecutorService);

因此,我的应用程序正确地接收了来自服务器的关联响应。这可能会为其他人提供参考。

谢谢你分享你的代码。这对我真的很有帮助。

原始邮政

我无法使用与您建议的解决方案类似的代码来执行连接。我试图请求一个与dcm4che (都为5.14.1)的dcm4chee-弧光灯相关联,我有如下所示:

代码语言:javascript
复制
Device device = new Device(deviceName);
ApplicationEntity locAE = new ApplicationEntity(localAE);
Connection conn = new Connection();
Connection remote = new Connection();
AAssociateRQ rq = new AAssociateRQ();

device.addConnection(conn);
device.addApplicationEntity(locAE);
locAE.addConnection(conn);

ApplicationEntity remAE = new ApplicationEntity();
remAE.setAETitle(remoteAE);

remote.setCommonName("rem_conn");
remote.setHostname(remoteIP);
remote.setPort(remotePort);
remote.setProtocol(Connection.Protocol.DICOM);
remAE.addConnection(remote);

rq.setCalledAET(remAE.getAETitle());
rq.setCallingAET(locAE.getAETitle());
rq.setApplicationContext("1.2.840.10008.3.1.1.1");
rq.setImplClassUID("1.2.40.0.13.1.3");
rq.setImplVersionName("dcm4che-5.14.1");
rq.setMaxPDULength(16384);
rq.setMaxOpsInvoked(0);
rq.setMaxOpsPerformed(0);
rq.addPresentationContext(new PresentationContext(
        1, "1.2.840.10008.5.1.4.1.2.2.1", "1.2.840.10008.1.2"));

Executor exec = (Runnable command) -> {};
device.setExecutor(exec);

//Opens association and connects to remote server
Association as = locAE.connect(conn, remote, rq);

但是,当试图连接到远程AET时,它似乎没有接收到来自远程AET的AAssociation响应。我的Java应用程序挂在Sta5 (等待关联响应)中,而服务器挂在Sta6 (准备进行数据传输)中。

Java日志:

代码语言:javascript
复制
[main] INFO org.dcm4che3.net.Connection  - Initiate connection from 0.0.0.0/0.0.0.0:0 to localhost:11112
[main] INFO org.dcm4che3.net.Connection  - Established connection Socket[addr=localhost/127.0.0.1,port=11112,localport=50101]
[main] DEBUG org.dcm4che3.net.Association  - /127.0.0.1:50101>localhost/127.0.0.1:11112(1): enter state: Sta4 - Awaiting transport connection opening to complete
[main] INFO org.dcm4che3.net.Association  - DEVICEAE->DCMQRSCP(1) << A-ASSOCIATE-RQ
[main] DEBUG org.dcm4che3.net.Association  - A-ASSOCIATE-RQ[
  calledAET: DCMQRSCP
  callingAET: DEVICEAE
  applicationContext: 1.2.840.10008.3.1.1.1 - DICOM Application Context Name
  implClassUID: 1.2.40.0.13.1.3
  implVersionName: dcm4che-5.14.1
  maxPDULength: 16378
  maxOpsInvoked/maxOpsPerformed: 1/1
  PresentationContext[id: 1
  as: 1.2.840.10008.5.1.4.1.2.2.1 - Study Root Query/Retrieve Information Model - FIND
  ts: 1.2.840.10008.1.2 - Implicit VR Little Endian
 ]
]
[main] DEBUG org.dcm4che3.net.Association  - DEVICEAE->DCMQRSCP(1): enter state: Sta5 - Awaiting A-ASSOCIATE-AC or A-ASSOCIATE-RJ PDU

服务器日志:

代码语言:javascript
复制
19:11:29,397 INFO  - Accept connection Socket[addr=/127.0.0.1,port=50101,localport=11112]
19:11:29,397 DEBUG - /127.0.0.1:11112<-/127.0.0.1:50101(3): enter state: Sta2 - Transport connection open
19:11:29,416 INFO  - DCMQRSCP<-DEVICEAE(3) >> A-ASSOCIATE-RQ
19:11:29,416 DEBUG - A-ASSOCIATE-RQ[
 calledAET: DCMQRSCP
 callingAET: DEVICEAE
 applicationContext: 1.2.840.10008.3.1.1.1 - DICOM Application Context Name
 implClassUID: 1.2.40.0.13.1.3
 implVersionName: dcm4che-5.14.1
 maxPDULength: 16378
 maxOpsInvoked/maxOpsPerformed: 1/1
 PresentationContext[id: 1
 as: 1.2.840.10008.5.1.4.1.2.2.1 - Study Root Query/Retrieve Information Model - FIND
 ts: 1.2.840.10008.1.2 - Implicit VR Little Endian
  ]
 ]
19:11:29,419 DEBUG - DCMQRSCP<-DEVICEAE(3): enter state: Sta3 - Awaiting local A-ASSOCIATE response primitive
19:11:29,419 INFO  - DCMQRSCP<-DEVICEAE(3) << A-ASSOCIATE-AC
19:11:29,419 DEBUG - A-ASSOCIATE-AC[
 calledAET: DCMQRSCP
 callingAET: DEVICEAE
 applicationContext: 1.2.840.10008.3.1.1.1 - DICOM Application Context Name
 implClassUID: 1.2.40.0.13.1.3
 implVersionName: dcm4che-5.14.1
 maxPDULength: 16378
 maxOpsInvoked/maxOpsPerformed: 1/1
 PresentationContext[id: 1
 result: 0 - acceptance
 ts: 1.2.840.10008.1.2 - Implicit VR Little Endian
  ]
 ]
19:11:29,427 DEBUG - DCMQRSCP<-DEVICEAE(3): enter state: Sta6 - Association established and ready for data transfer

我觉得我错过了什么,但我找不到问题的根源。任何帮助都是非常感谢的,因为我仍然是dcm4che和DICOM协议的新手。

谢谢。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49048428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档