DICOMHERO-Simple-Dicom-Viewer icon indicating copy to clipboard operation
DICOMHERO-Simple-Dicom-Viewer copied to clipboard

Complete sample based on DicomHero6

Open geolyth opened this issue 2 years ago • 9 comments
trafficstars

Is possible to have a complete working sample based on DicomHero6? I refactored this old code found here (if interested I could also open a PR for it) but when I try to use a connection to a PACS server I reveice a crash.

Thanks

geolyth avatar Nov 07 '23 13:11 geolyth

It would be useful to see the code that fails to connect to the PACS, then I could try to replicate the issue and fix it. You can send the snippet of code directly to [email protected] or attach it to this thread.

binarno avatar Nov 07 '23 14:11 binarno

@binarno I'm trying to use the code from DicomHero documentation.


TCPStream tcpStream = new TCPStream(new TCPActiveAddress("127.0.0.1", "1004"));
        // Allocate a stream reader and a writer that use the TCP stream.
        // If you need a more complex stream (e.g. a stream that uses your
        // own services to send and receive data) then use a Pipe
        StreamReader readSCU = new StreamReader(tcpStream.getStreamInput());
        StreamWriter writeSCU = new StreamWriter(tcpStream.getStreamOutput());

        // Add all the abstract syntaxes and the supported transfer
        // syntaxes for each abstract syntax (the pair abstract/transfer syntax is
        // called "presentation context")
        PresentationContext presentationContext = new PresentationContext("1.2.840.10008.5.1.4.1.1.4.1");
        presentationContext.addTransferSyntax("1.2.840.10008.1.2.1");
        PresentationContexts presentationContexts = new PresentationContexts();
        presentationContexts.addPresentationContext(presentationContext);

        // The AssociationSCU constructor will negotiate a connection through
        // the readSCU and writeSCU stream reader and writer
        AssociationSCU scu = new AssociationSCU("JPIServer", "SCP", 1, 1, presentationContexts, readSCU, writeSCU, 0);
        DimseService dimseService = new DimseService(scu);

        // Let's prepare a dataset to store on the SCP
        DataSet payload = new DataSet(dimseService.getTransferSyntax("1.2.840.10008.5.1.4.1.1.4.1"));
        //payload.setString(TagId(tagId_t::SOPInstanceUID_0008_0018), "1.1.1.1")
        //payload.setString(TagId(tagId_t::SOPClassUID_0008_0016), "1.2.840.10008.5.1.4.1.1.4.1")
        //payload.setString(TagId(tagId_t::PatientName_0010_0010),"Patient^Test")
        payload.setString(new TagId(0x08, 0x18), "1.1.1.1");
        payload.setString(new TagId(0x08, 0x16), "1.2.840.10008.5.1.4.1.1.4.1");
        payload.setString(new TagId(0x10, 0x10),"Patient^Test");

        CStoreCommand command = new CStoreCommand(
                "1.2.840.10008.5.1.4.1.1.4.1", //< one of the negotiated abstract syntaxes
                dimseService.getNextCommandID(),
                dimseCommandPriority_t.medium,
                payload.getString(new TagId(0x08, 0x16), 0),
                payload.getString(new TagId(0x08, 0x18), 0),
                "",
                0,
                payload
        );

        dimseService.sendCommandOrResponse(command);
        DimseResponse response = new DimseResponse(dimseService.getCStoreResponse(command));
        if (response.getStatus() == dimseStatus_t.success) {
            // SUCCESS!
            Log.i("APP_DI", "SUCCESS");
        } else {
            Log.i("APP_DI", "ERROR");
        }

I receive this stacktrace:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.binarno.dicomhero6demo/com.binarno.dicomhero6demo.MainActivity}: java.io.IOException: [long dicomhero::implementation::throwTcpException(long)]
                                                                                                     file: ../../../../dicomheroCore6/library/implementation/tcpSequenceStreamImpl.cpp  line: 150
                                                                                                     exception type: N9dicomhero20TCPConnectionRefusedE
                                                                                                     exception message: Connection refused
                                                                                                    
                                                                                                    
                                                                                                    [long dicomhero::implementation::throwTcpException(long)]
                                                                                                     file: ../../../../dicomheroCore6/library/implementation/tcpSequenceStreamImpl.cpp  line: 181
                                                                                                     exception type: N9dicomhero20TCPConnectionRefusedE
                                                                                                     exception message: Connection refused
                                                                                                    
                                                                                                    
                                                                                                    [void dicomhero::implementation::tcpSequenceStream::write(const std::uint8_t *, size_t)]
                                                                                                     file: ../../../../dicomheroCore6/library/implementation/tcpSequenceStreamImpl.cpp  line: 695
                                                                                                     exception type: N9dicomhero20TCPConnectionRefusedE
                                                                                                     exception message: Connection refused
                                                                                                    
                                                                                                    
                                                                                                    [virtual void dicomhero::implementation::baseSequenceStreamOutput::write(size_t, const std::uint8_t *, size_t)]
                                                                                                     file: ../../../../dicomheroCore6/library/implementation/baseSequenceStreamImpl.cpp  line: 110
                                                                                                     exception type: N9dicomhero20TCPConnectionRefusedE
                                                                                                     exception message: Connection refused
                                                                                                    
                                                                                                    
                                                                                                    [void dicomhero::implementation::streamWriter::flushDataBuffer()]
                                                                                                     file: ../../../../dicomheroCore6/library/implementation/streamWriterImpl.cpp  line: 92
                                                                                                     exception type: N9dicomhero20TCPConnectionRefusedE
                                                                                                     exception message: Connection refused
                                                                                                    
                                                                                                    
                                                                                                    [void dicomhero::implementation::acsePDU::encodePDU(std::shared_ptr<streamWriter>) const]
                                                                                                     file: ../../../../dicomheroCore6/library/implementation/acseImpl.cpp  line: 1060
                                                                                                     exception type: N9dicomhero20TCPConnectionRefusedE
                                                                                                     exception message: Connection refused
                                                                                                    
                                                                                                    
                                                                                                    [dicomhero::implementation::associationSCU::associationSCU(const std::shared_ptr<const presentationContexts> &, const std::string &, const std::string &, std::uint16_t, std::uint16_t, std::shared_ptr<streamReader>, std::shared_ptr<streamWriter>, std::uint32_t)]
                                                                                                     file: ../../../../dicomheroCore6/library/implementation/acseImpl.cpp  line: 2601
                                                                                                     exception type: N9dicomhero20TCPConnectionRefusedE
                                                                                                     exception message: Connection refused

I would like to open a connection to a PACS Server and then do a query to retrieve some data but I started to understand if code from documentation works and I found that error.

geolyth avatar Nov 07 '23 17:11 geolyth

The error indicates that the TCP connection has been refused: this happens before the ACSE & DIMSE negotiation. Have you tried to connect to 127.0.0.1 port 1004 via telnet to confirm that a process is actually listening on that port?

binarno avatar Nov 07 '23 18:11 binarno

Yes I already tried and the connection is listening on that port (I checked the PACS server informations). This is the reason I want to have a complete sample based on DicomHero6 on how to connect to a PACS server and retrieve informations from this.

geolyth avatar Nov 08 '23 09:11 geolyth

Is the PACS running on the same android device or emulator where the code is running? If not then consider than 127.0.0.1 is a local address and the android app will access its own local network interface, not the PACS' one (even if the PACS is running on the host machine running the emulator). Try to use the public IP address, if running the APP in the emulator use a bridged network interface.

binarno avatar Nov 08 '23 10:11 binarno

I have a PACS server on a laptop and I'm trying to run your app (using also the snippet above) to connect to it. I'll try as you suggested. Thanks

geolyth avatar Nov 08 '23 13:11 geolyth

@binarno Sorry to bother you, I tried but maybe I am following a wrong guide. Can you explain me in details how can I do the bridged network in the emulator? P.S. I am italian...

Thank you

geolyth avatar Nov 22 '23 11:11 geolyth

According to this page https://developer.android.com/studio/run/emulator-networking, connecting the Android emulator to 10.0.2.2 should connect to 127.0.0.1 on the host machine.

binarno avatar Nov 22 '23 14:11 binarno

Ok now the connection seems to work. I read the documentation but I am not able to find a complete sample of how to execute a simple query to retrieve data (for example a list of patients that starts with a letter).

This code seems to work fine now:

        TCPStream tcpStream = new TCPStream(new TCPActiveAddress("10.0.2.2", "1004"));
        StreamReader readSCU = new StreamReader(tcpStream.getStreamInput());
        StreamWriter writeSCU = new StreamWriter(tcpStream.getStreamOutput());

geolyth avatar Nov 22 '23 16:11 geolyth