Create a C-Echo SCU

Description

This tutorial will show you how to create a very basic C-Echo SCU to perform Verification as Service Class User

you have to follow this steps:

First step: extends DefaultAssociationListener

In this step you have to extendsDefaultAssociationListener in order to be notify of Association's events (open, messages received, etc..)

public class InnerAssociationListener extends	DefaultAssociationListener {

	@Override
	public void associationOpened(Association aAssociation, AssociateSession aAssociateSession) throws Exception {
		CEchoRequestMessage lMessage = fFactory.newCEchoRequest(SOPClass.Verification.getUID());
		byte lPres = aAssociateSession.getSuitablePresentationContextID(SOPClass.Verification.getUID());

		for (int i = 0; i < 1; i++) {
			SendThread lT = new SendThread(aAssociation, lPres, lMessage);
			lT.start();
		}

	}

	@Override
	public void messageReceived(Association aAssociation, byte aPresentationContextID, DimseMessage aMessage) throws Exception {
		if (aMessage.isCEchoResponse()) {
			logger.debug("isCEchoResponse");
			logger.info("Response: " + ((CEchoResponseMessage)aMessage).statusToString() );
			aAssociation.sendReleaseRequest();
		}
	}

}

private class SendThread extends Thread {

	private Association fAssoc;

	private DimseMessage fMessage;

	private byte fPres;

	public SendThread(Association aAssoc, byte aPres, DimseMessage aMessage) {
		fAssoc = aAssoc;
		fPres = aPres;
		fMessage = aMessage;
	}

	@Override
	public void run() {
		super.run();
		try {
			fAssoc.sendMessage(fPres, fMessage);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}

	}

}

For more details on Association negotiation, you can check dicom norms (part 8).

Second step: create the AssociateRequest

protected AssociateRequest createRequest() throws Exception  {
	AssociateRequest lRequest = new AssociateRequest();
	lRequest.setMaximumPDUSize(60000);
	lRequest.setMaximumNumberOperationsInvoked(4);
	lRequest.setMaximumNumberOperationsPerformed(4);
	lRequest.addPresentationContext(SOPClass.Verification, TransferSyntax.Default);		
	return lRequest;
}

Third step: Open the association

protected AssociateRequest createRequest() throws Exception  {
	AssociateRequest lRequest = new AssociateRequest();
	lRequest.setMaximumPDUSize(60000);
	lRequest.setMaximumNumberOperationsInvoked(4);
	lRequest.setMaximumNumberOperationsPerformed(4);
	lRequest.addPresentationContext(SOPClass.Verification, TransferSyntax.Default);		
	return lRequest;
}

When the association will be opened, the InnerAssociationListener will send the C-Echo-Request message

Back