Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete sample based on DicomHero6 #5

Open
geolyth opened this issue Nov 7, 2023 · 9 comments
Open

Complete sample based on DicomHero6 #5

geolyth opened this issue Nov 7, 2023 · 9 comments

Comments

@geolyth
Copy link

geolyth commented Nov 7, 2023

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

@binarno
Copy link
Owner

binarno commented Nov 7, 2023

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.

@geolyth
Copy link
Author

geolyth commented Nov 7, 2023

@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.

@binarno
Copy link
Owner

binarno commented Nov 7, 2023

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?

@geolyth
Copy link
Author

geolyth commented Nov 8, 2023

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.

@binarno
Copy link
Owner

binarno commented Nov 8, 2023

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.

@geolyth
Copy link
Author

geolyth commented Nov 8, 2023

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
Copy link
Author

geolyth commented Nov 22, 2023

@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

@binarno
Copy link
Owner

binarno commented Nov 22, 2023

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.

@geolyth
Copy link
Author

geolyth commented Nov 22, 2023

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());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants