/*******************************************************************************
 *  Copyright 2017-2018 Centre for Development of Advanced Computing(C-DAC), Pune
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *   http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package cdac.medinfo.sdk.dcm30_04.services.print.testcases.customizedscp;
import java.io.IOException;


import cdac.medinfo.sdk.dcm30_04.baselibs.PrinterConfigurationSequence;
import cdac.medinfo.sdk.dcm30_04.baselibs.PrinterConfigurationSequenceItem;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.PrinterConfigurationModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.PrinterModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.SOPCommonModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.print.PrinterConfigurationIOD;
import cdac.medinfo.sdk.dcm30_04.dicommodel.print.PrinterIOD;
import cdac.medinfo.sdk.dcm30_04.enums.EnumCommandField;
import cdac.medinfo.sdk.dcm30_04.enums.EnumDecimateCropResult;
import cdac.medinfo.sdk.dcm30_04.enums.EnumLoggingLevel;
import cdac.medinfo.sdk.dcm30_04.enums.EnumMagnificationType;
import cdac.medinfo.sdk.dcm30_04.enums.EnumPDUType;
import cdac.medinfo.sdk.dcm30_04.enums.EnumPrinterStatus;
import cdac.medinfo.sdk.dcm30_04.enums.EnumPrinterStatusInfo;
import cdac.medinfo.sdk.dcm30_04.enums.EnumQueueStatus;
import cdac.medinfo.sdk.dcm30_04.enums.EnumRequestedResolutionID;
import cdac.medinfo.sdk.dcm30_04.enums.EnumSOPClassUIDs;
import cdac.medinfo.sdk.dcm30_04.services.association.AReleaseRQorRP;
import cdac.medinfo.sdk.dcm30_04.services.association.AssociateRQ;
import cdac.medinfo.sdk.dcm30_04.services.association.AssociationNegotiator;
import cdac.medinfo.sdk.dcm30_04.services.association.DefaultAssociation;
import cdac.medinfo.sdk.dcm30_04.services.association.IDIMSEAssociation;
import cdac.medinfo.sdk.dcm30_04.services.dicomnetcommons.EnumDataSink;
import cdac.medinfo.sdk.dcm30_04.services.dicomnetcommons.EnumDataSource;
import cdac.medinfo.sdk.dcm30_04.services.dicomnetcommons.EnumServiceType;
import cdac.medinfo.sdk.dcm30_04.services.dimsecommons.DIMSEResponse;
import cdac.medinfo.sdk.dcm30_04.services.dimsecommons.DicomMessage;
import cdac.medinfo.sdk.dcm30_04.services.dimsecommons.IDataSink;
import cdac.medinfo.sdk.dcm30_04.services.dimsecommons.IDataSource;
import cdac.medinfo.sdk.dcm30_04.services.naction.scp.NActionSCP;
import cdac.medinfo.sdk.dcm30_04.services.ncreate.scp.NCreateSCP;
import cdac.medinfo.sdk.dcm30_04.services.ndelete.scp.NDeleteSCP;
import cdac.medinfo.sdk.dcm30_04.services.nget.scp.NGetSCP;
import cdac.medinfo.sdk.dcm30_04.services.nset.scp.NSetSCP;
import cdac.medinfo.sdk.dcm30_04.services.print.printsinkimpl.PrintDataSinkImpl;
import cdac.medinfo.sdk.dcm30_04.services.print.printsourceimpl.PrintDataSourceImpl;
import cdac.medinfo.sdk.dcm30_04.services.print.printsourceimpl.PrinterConfiguration;
import cdac.medinfo.sdk.dcm30_04.services.scp.commons.ClientSession;
import cdac.medinfo.sdk.dcm30_04.services.scp.commons.ProcessHandler;
import cdac.medinfo.sdk.dcm30_04.services.scp.commons.SCPSession;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConfig;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConstants;
import cdac.medinfo.sdk.dcm30_04.utils.IPairedCollection;
import cdac.medinfo.sdk.dcm30_04.utils.PairedCollection;

/**
 * This sample code defines the customized implementation of SCP for PrintMangement Service Class.
 * This code process the request for all services belonging to PrintManagement service group.
 * Supported services for PrintManagement are :
 * Basic GrayScale Print Management Meta SOP Class -
 *  	This Meta SOP class support following SOP classes
 *  	1) Basic Film Session SOP Class :- This class supports following Services N-Create,N-Set,N-Delete,N-Action services.
 *  	2) Basic Film Box SOP Class :- This class supports following Services N-Create,N-Set,N-Delete,N-Action services.
 *  	3) Basic GrayScale Image Box SOP Class :- This class supports following Services N-Set services.
 *  
 *  Print Queue Management SOP Class
 * 		This SOP class support following services
 * 		1)N-Action to cancel and priortize jobs.
 * 		2)N-Get to get print job information.
 * 
 * Following are the option SOP Class supported by Print Management Service Class with Basic Print Management SOP 
 * 		1)Basic Annotation Box SOP Class :- This class supports following Services N-Set services.
 * 		3)Basic print Image Overlay Box SOP Class.
 * 		4)Presentation LUT Sop Class :- This class supports following Services N-Create and N-Delete services.
 *  
 * This implements all required methods of IProcessHandler for in order to process the request.
 * Connection establishment process : onConnect()
 * Association establishment process : onAssociateReceive()
 * Service Request process : onServiceRequest()
 * To create DB for Print Management Service refer SQL Script PrintServiceDB.sql provided in install.
 */
public class Print_SCP_Cust_ProcHandler
{
	public static void main(String[] args) throws IOException
	{
		try
		{
			DicomConfig objDicomConfig = DicomConfig.createInstance();

			//enable logging,specify the path of the directory where log files are created.
			//User can specify any directory in place of 'c:\DCM_Logs'.
			//If no directory is defined by user to create logs then it is created in User Temp DIR.
			objDicomConfig.enableLogging(EnumLoggingLevel.INFO, "c:/DCM_Logs");
			Print_SCP_Cust_ProcHandler objTestPrintSCP = new Print_SCP_Cust_ProcHandler();
			
			//Creates MPPSServices_SCP.
			PrintServices_SCP objPrint_SCP = new PrintServices_SCP();

			//Create SCP session.
			SCPSession session = new SCPSession();

			/*
			 * Create Sink and Source Impl with ConnectionString and driver String.
			 * PrintDataSourceImpl and PrintDataSinkImpl are default implementation of library which uses JavaDB. 
			 * Sink and Source Impl process the storage , updation, deletion and retrieval process for all Print supported services. 
			 * The user has to start javaDB server before connection creation if Client Server model in java DB is used.
			 * The SQL Script needed to create database is provided at %InstallDir%/SQLScripts/PrintServiceDB.sql
			 * User has to first create the Database then it should be set in the Print SCP.
			 * This DataSink and DataSource should be set on process handler class working as Print SCP.
			 * User can also provide its own implementation of IDataSink and IDataSource interface for MPPS.
			 */
			String dataBasePath = "D:/DataBase/PrintSDKdb";
			String ConnectionString = "jdbc:derby://localhost:5050/" + dataBasePath ;
			String driverString = "org.apache.derby.jdbc.ClientDriver";

			/*
			 * Add Print Handler to Print DataSource Impl to receive created data set 
			 * of Stored Print IOD and HardCopyGrayScale Image IOD
			 */
			IDataSink objPrintDataSink = new PrintDataSinkImpl(ConnectionString,driverString);
			PrintDataSourceImpl objPrintDataSourceImpl = new PrintDataSourceImpl(ConnectionString,driverString);
			PrintHandler objPrintHandler = new PrintHandler();
			objPrintDataSourceImpl.addPrinterHandler(objPrintHandler);
			
//			Set the Printer Details on PrinterConfiguration class.
			PrinterConfiguration objPrinterConfiguration = new PrinterConfiguration();
			PrinterIOD objPrinterIOD = new PrinterIOD();
			objTestPrintSCP.populatePrinterIOD(objPrinterIOD);
			objPrinterConfiguration.setPrintIOD(objPrinterIOD);

			PrinterConfigurationIOD objPrinterConfigurationIOD = new PrinterConfigurationIOD();
			objTestPrintSCP.populatePrinterConfigurationIOD(objPrinterConfigurationIOD);
			objPrinterConfiguration.setPrinterConfigurationInfo(objPrinterConfigurationIOD);
			objPrinterConfiguration.setQueueStatus(EnumQueueStatus.NORMAL);
			
			objPrintDataSourceImpl.setPrinterConfigurationInfo(objPrinterConfiguration);
			
			IDataSource objPrintDataSource = objPrintDataSourceImpl;

			/*
			 * Add Datasink and DataSource on Process Handler.
			 * Here MPPSServices_SCP is acting as the Process handler,hence adding Data Sink and Source to Process Handler.
			 */
			objPrint_SCP.addDataSink(EnumDataSink.PRINT_MANAGEMENT,objPrintDataSink);
			objPrint_SCP.addDataSource(EnumDataSource.PRINT_MANAGEMENT,objPrintDataSource);

			/*
			 * Initializes the supporting service types and sets it on SCP Session
			 * EnumService Type configures SCP Session to load corresponding association context and start
			 * corresponding DIMSE Services.
			 */
			/*
			 * Initializes the service types and populates the default association
			 */
			EnumServiceType[] arrenumServiceType = new EnumServiceType[13];
			arrenumServiceType[0] = EnumServiceType.NCREATE_BASIC_GRAYSCALEPRINT_MANAGEMENT;
			arrenumServiceType[1] = EnumServiceType.NSET_BASIC_GRAYSCALE_PRINT_MANAGEMENT;
			arrenumServiceType[2] = EnumServiceType.NDELETE_BASIC_GRAYSCALE_PRINT_MANAGEMENT;
			arrenumServiceType[3] = EnumServiceType.NACTION_BASIC_GRAYSCALE_PRINT_MANAGEMENT;
			arrenumServiceType[4] = EnumServiceType.NSET_BASIC_ANNOTATION;
			arrenumServiceType[5] = EnumServiceType.NCREATE_PRESENTATION_LUT;
			arrenumServiceType[6] = EnumServiceType.NDELETE_PRESENTATION_LUT;
			arrenumServiceType[7] = EnumServiceType.NCREATE_BASIC_PRINT_IMAGE_OVERLAY;
			arrenumServiceType[8] = EnumServiceType.NSET_BASIC_PRINT_IMAGE_OVERLAY;
			arrenumServiceType[9] = EnumServiceType.NDELETE_BASIC_PRINT_IMAGE_OVERLAY;
			arrenumServiceType[10] = EnumServiceType.NACTION_PRINT_QUEUE_MANAGEMENT;
			arrenumServiceType[11] = EnumServiceType.NGET_PRINTER_CONFIGURATION_RETRIEVAL;
			arrenumServiceType[12] = EnumServiceType.NGET_PRINT_JOB;
			session.selectServices(arrenumServiceType);


			//Set MPPSServices_SCP as ProcessHandler.
			session.setIProcessHandler(objPrint_SCP);
			
			/*
			 * Setting time out as 5000 milli second. It will wait 5000 mili seconds for read and write operation.
			 * If in the time specified (5000 ms) read or write operation is not performed then 
			 * session is time out.
			 */ 
			//session.setTimeOut(5000);

			//Start the Session
			session.start("SDK",9000);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	

	/*
	 * This function populates the Printer IOD.
	 */
	private void populatePrinterIOD(PrinterIOD objPrinterIOD)
	{
		PrinterModule objPrinterModule = objPrinterIOD.getPrinterModule();
		String[] strArrValue = new String[2];
		strArrValue[0] = "19941010";
		strArrValue[1] = "19991010";
		objPrinterModule.setDateOfLastCalibration(strArrValue);
		objPrinterModule.setDeviceSerialNumber("4");
		objPrinterModule.setManufacturer("Manufacture");
		objPrinterModule.setManufacturerModelName("Manufacturer Model Name");
		objPrinterModule.setPrinterName("SDK DICOM Printer");
		objPrinterModule.setPrinterStatus(EnumPrinterStatus.NORMAL);
		objPrinterModule.setPrinterStatusInfo(EnumPrinterStatusInfo.NORMAL);
		String[] strArrValue1 = new String[2];
		strArrValue1[0] = "22";
		strArrValue1[1] = "22";
		objPrinterModule.setSoftwareVersions(strArrValue1);
		String[] strArrValue2 = new String[2];
		strArrValue2[0] = "0710";
		strArrValue2[1] = "0710";
		objPrinterModule.setTimeOfLastCalibration(strArrValue2);

		SOPCommonModule objSOPCommonModule = objPrinterIOD.getSOPCommonModule();
		objSOPCommonModule.setSOPClassUID(EnumSOPClassUIDs.PRINTERIOD.getValue());
		objSOPCommonModule.setSOPInstanceUID("1.2.840.10008.5.1.1.17");
	}

	/*
	 * This function populates the Printer Configuration IOD.
	 */
	private void populatePrinterConfigurationIOD(PrinterConfigurationIOD objPrinterConfigurationIOD)
	{
		PrinterConfigurationModule objPrinterConfigurationModule = objPrinterConfigurationIOD.getPrinterConfigurationModule();

		PrinterConfigurationSequence objPrinterConfigurationSequence = objPrinterConfigurationModule.getPrinterConfigurationSequence();
		PrinterConfigurationSequenceItem objPrinterConfigurationSequenceItem = objPrinterConfigurationSequence.getNewItem();
		objPrinterConfigurationSequenceItem.setConfigurationInformationDescription("IMPLEMENTATION_SPECIFIC_CURVE_TYPE");
		objPrinterConfigurationSequenceItem.setDecimateCropResult(EnumDecimateCropResult.PRINTER_DOES_NOT_SUPPORTS_DECIMATE_CROP_RESULT_CROP);
		objPrinterConfigurationSequenceItem.setDefaultMagnificationType(EnumMagnificationType.BILINEAR);
		objPrinterConfigurationSequenceItem.setDefaultPrinterResolutionID(EnumRequestedResolutionID.HIGH);
		objPrinterConfigurationSequenceItem.setDefaultSmoothingType("SMOOTH");
		objPrinterConfigurationSequenceItem.setMaximumCollatedFilms("2");
		objPrinterConfigurationSequenceItem.setMaximumMemoryAllocation("8");
		objPrinterConfigurationSequenceItem.setMemoryBitDepth((short)0);
		objPrinterConfigurationSequenceItem.setPrintingBitDepth((short)0);
		objPrinterConfigurationSequence.addItem(objPrinterConfigurationSequenceItem);
	}
}

/**
 * Note ProcessHandler is the class which implements interface IProcessHandler or extends ProcessHandler.
 * This class is implemented to process the MPPS service requests.
 * In order to run the following class , please refer to this link($Link) to create the environment.
 * To implement an SCP of a particular we need to do the following things :
 * To create SCP user should either has to implement class IProcessHandler (which is an interface ) or extends Process handler.
 * If test code implements process handler then user has to provide implementation of the methods declared in the interface.
 * Otherwise he can extend the process handler which containts the default implementation for processing of association and service request.
 * Create the SCPSession object which maintains the session of the SCP. 
 * Set the services for which SCP is started and Process handler(reference of test code) in SCPSession.
 * Its "start" method starts the SCP server.
 * When an SCU send connection request to SCP,SCP creates a client session for that SCU.
 * On SCP side a call back will be generated to 'onConnect' method of ProcessHandler whenever a connection request arrives.
 * Now user can retrieve the connection parameters from client session and can decide whether to accept the connection or not.
 * To accpect the connection user has to pass true to acceptConnection function in ClientSession class.
 * After the connection is established the next request expected to arrive at SCP is Association request.
 * When Assocaition request arrives, callback is made to 'onAssociateReceive' method of IProcessHandler.
 * User now can negotioate Association request with the default association and create AssociateAC or AssociationRJ
 * according to the acceptance or rejection.
 * The library provides AssociationNegotiator Class to negotiate and create appropriate response.
 * When a service request arrives the call back is made to 'onServiceRequest' method of ProcessHandler.
 * The user can retrieve the arrived Request from current ClientSession object passed in onServiceRequest method, processes it
 * and create respective Response.
 * SDK provides processRequest method in respective SCP to process the request and to generate response.
 * The SCP can handle multiple request simultaneously.
 * After this, when Association Release-RQ arrives , Create Release response and send it to the SCU.
 * Whenever the SCU goes down its client session is also closed or SCP can close the client session 
 * by calling close method of client session.
 */
class PrintServices_SCP extends ProcessHandler
{
	/**
	 * This method notifies when a new client connection is requested. A decision is to be made whether to
	 * accept or reject the conenction.  
	 * @param objClientSession  object of client session.
	 */
	public void onConnect(ClientSession objClientSession)
	{
		objClientSession.acceptConnection(true);
	}

	/**
	 * This method notifies when Association Request, Associate Release Request or Abort is received from one of the 
	 * SCUs. 
	 * If Association Request is received,
	 * 		Create Association Negotiator which negotiates the request with the existing default association and
	 * 		creates an AgreedAssociation which contains the negotiated association values. AssociationNegotiator
	 * 		returns the Association Response as AssociateAC when request is accepted or returns AssociateRJ is 
	 * 		none of the values in Association Request are acceptable.
	 * 	If Associate Release Request is received,
	 * 		Create a Associate Release Response and send the response to the SCU using the respective ClientSession.
	 *  If Abort is received,
	 *  	An Abort response must be generated and sent using ClientSession
	 *    
	 * @param objClientSession instance of Client Session.
	 */
	public void onAssociateReceive(ClientSession objClientSession) 
	{ 
		//Get Association RQ
		IDIMSEAssociation objIDIMSEAssociation = objClientSession.getDIMSEAssociation();
		EnumPDUType enumPDUType = objIDIMSEAssociation.getPDUType();
		IDIMSEAssociation objAssociationRSP = null;

		//For Association Request negotiate with Default Association and generate Response
		switch(enumPDUType)
		{
		case ASSOCIATE_RQ :
		{
			System.out.println("Association Request Received");
			AssociateRQ objAssociateRQ = (AssociateRQ)objIDIMSEAssociation;

			//get the default association from Client Session.
			DefaultAssociation objDefaultAssociation = objClientSession.getDefaultAssociation();

			//Negotiatie and get Response
			AssociationNegotiator objAssNegotiator = new AssociationNegotiator();
			objAssociationRSP = objAssNegotiator.negotiate(objDefaultAssociation, objAssociateRQ);

			//set agreed association in client Session.
			objClientSession.setAgreedAssociation(objAssNegotiator.getAgreedAssociation());
			System.out.println(objClientSession.getAgreedAssociation().isSOPClassUIDPresent(EnumSOPClassUIDs.PRINTQUEUEMANAGEMENTIOD.getValue()));

			//Send Response
			objClientSession.sendAssociationMessage(objAssociationRSP);
			break;
		}
		case RELEASE_RQ :
		{
			System.out.println("Release Request Received");

			//Create Release Response.
			objAssociationRSP = new AReleaseRQorRP(EnumPDUType.RELEASE_RP);

			//Send Release Response.
			objClientSession.sendAssociationMessage(objAssociationRSP);
			System.out.println("Release Response sent");

			//Close Client Session
			objClientSession.close();
			break;
		}
		case ABORT :
		{
			System.out.println("Abort has arrived Stop Porcessing -- Association is no longer available");
			break;
		}
		}
	}

	/**
	 * This method notifies when a service related request is received.
	 * For Example,
	 * If N-Create-RQ is received,
	 * 		Create NCreateSCP using the ClientSession.
	 * 		Process the reqeust using the NCreateSCP which process the request and returns a NCreateRSP.
	 * 		Send this response using the ClientSession.
	 * @see objClientSession Object of Client Session.
	 */
	public void onServiceRequest(ClientSession objClientSession)
	{
		DIMSEResponse objDResponse = null;

		//Retrieving DicomMessage from ClientSession which contains service request.
		DicomMessage objDicomMessage = objClientSession.getDicomMessage();

		//Populating DataSink and DataSource Collection for processing of supported request for MPPS service class.
		IPairedCollection<EnumDataSink,IDataSink> objDataSinkCollection = new PairedCollection< EnumDataSink,IDataSink >();
		objDataSinkCollection.put(EnumDataSink.PRINT_MANAGEMENT, getDataSink(EnumDataSink.PRINT_MANAGEMENT));

		IPairedCollection<EnumDataSource, IDataSource> objDataSourceCollection = new PairedCollection<EnumDataSource, IDataSource>();
		objDataSourceCollection.put(EnumDataSource.PRINT_MANAGEMENT, getDataSource(EnumDataSource.PRINT_MANAGEMENT));

		//Setting agreed assocaition in Print DataSource Impl. It is required if Print Queue Management is also supported.
		PrintDataSourceImpl objPrintDataSourceImpl = (PrintDataSourceImpl)getDataSource(EnumDataSource.PRINT_MANAGEMENT);
		objPrintDataSourceImpl.setAgreedAssociation(objClientSession.getAgreedAssociation());

		

		try
		{
			/*
			 * If N-Create request for Print is arrived, create NCreate SCP, setDataSink, process request
			 * and send message.
			 */
			if(objDicomMessage.getCommandType() == EnumCommandField.N_CREATE_RQ)
			{
				System.out.println("N-Create Request Received");
				NCreateSCP objNCreateSCP = NCreateSCP.createInstance(objClientSession);

				objNCreateSCP.setDataSinkList(objDataSinkCollection);

				objDResponse = objNCreateSCP.processRequest(objDicomMessage);

				if(objDResponse != null)
					objClientSession.sendServiceMessage(objDResponse);
				System.out.println("N-Create Response Sent");
			}

			/*
			 * If N-Set request for Print is arrived, create NSEt SCP, setDataSink, process request
			 * and send message.
			 */
			if(objDicomMessage.getCommandType() == EnumCommandField.N_SET_RQ)
			{
				System.out.println("N-Set Request Received");
				NSetSCP objNSetSCP  = NSetSCP.createInstance(objClientSession);

				objNSetSCP.setDataSinkList(objDataSinkCollection);

				objDResponse = objNSetSCP.processRequest(objDicomMessage);

				if(objDResponse != null)
					objClientSession.sendServiceMessage(objDResponse);
				System.out.println("N-Set Response Sent");
			}

			/*
			 * If N-Delete request for Print is arrived, create NDelete SCP, setDataSink, process request
			 * and send message.
			 */
			if(objDicomMessage.getCommandType() == EnumCommandField.N_DELETE_RQ)
			{
				System.out.println("N-Delete Request Received");
				NDeleteSCP objNDeleteSCP  = NDeleteSCP.createInstance(objClientSession);

				objNDeleteSCP.setDataSinkList(objDataSinkCollection);

				objDResponse = objNDeleteSCP.processRequest(objDicomMessage);

				if(objDResponse != null)
					objClientSession.sendServiceMessage(objDResponse);
				System.out.println("N-Delete Response Sent");
			}

			/*
			 * If N-Action request for Print is arrived, create NAction SCP, setDataSource, process request
			 * and send message.
			 */
			if(objDicomMessage.getCommandType() == EnumCommandField.N_ACTION_RQ)
			{

				System.out.println("N-Action Request Received");
				NActionSCP objNActionSCP  = NActionSCP.createInstance(objClientSession);

				objNActionSCP.setDataSourceList(objDataSourceCollection);
				objNActionSCP.setDataSinkList(objDataSinkCollection);

				objDResponse = objNActionSCP.processRequest(objDicomMessage);

				if(objDResponse != null)
					objClientSession.sendServiceMessage(objDResponse);
				System.out.println("N-Action Response Sent");
			}

			/*
			 * If N-Get request for Print is arrived, Create NGet SCP, setDataSource, process request
			 * and send message.
			 */
			if(objDicomMessage.getCommandType() == EnumCommandField.N_GET_RQ)
			{
				System.out.println("N-Get Request Received");
				NGetSCP objNGetSCP  = NGetSCP.createInstance(objClientSession);

				objNGetSCP.setDataSourceList(objDataSourceCollection);

				objDResponse = objNGetSCP.processRequest(objDicomMessage);

				if(objDResponse != null)
					objClientSession.sendServiceMessage(objDResponse);
				System.out.println("N-Get Response Sent");
			}
		}
		catch(Exception ioe)
		{
			ioe.printStackTrace();
			objClientSession.close();
		}
	}
}
