/*******************************************************************************
 *  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.cservices.withdb.testcases.customizedscp;


import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.dicommodel.xray.XRayAngiographicIOD;
import cdac.medinfo.sdk.dcm30_04.enums.EnumLoggingLevel;

import cdac.medinfo.sdk.dcm30_04.services.dimsecommons.DicomMessage;
import cdac.medinfo.sdk.dcm30_04.services.javadbhelper.CServices_QueryModel;
import cdac.medinfo.sdk.dcm30_04.services.javadbhelper.DataSinkImpl;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConfig;

public class CServicesQueryModel 
{

	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		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");
		
			
			String strFilePath = null;
			System.out.println("Enter the X-Ray Angiogram Dicom File with complete path");
			
			strFilePath = "D:\\TestDicomFiles\\0003.dcm";

			// Creates the object of corresponding IOD by calling its constructor which takes File Name as a parameter and give its DataSet.
			XRayAngiographicIOD objXRayAngiographicIOD = new XRayAngiographicIOD(strFilePath);
			
			IDataSet objIDataSet = objXRayAngiographicIOD.getDataSet();
			
			CServices_QueryModel objCServicesQueryModel = new CServices_QueryModel();
			
			// populate Query Model from dataset.
			objCServicesQueryModel.decode(objIDataSet);
			
			/*
			 * Create DataSourceImpl with ConnectionString and driver String.
			 * DataSourceImpl is default implementation of library which uses JavaDB to 
			 * Find Data Elements.The user has to start javaDB server before connection
			 * if Client Server model in java DB is used.
			 * This DataSource should be set in CFind SCP.
			 * User can also provide its own implementation of IDataSource interface
			 * to find the attributes.
			 */
			String dataBasePath = "C:\\DataBase\\SDKdb";
			String ConnectionString = "jdbc:derby://localhost:1527/" + dataBasePath;
			String driverString = "org.apache.derby.jdbc.ClientDriver";

			DataSinkImpl objDataSinkImpl = new DataSinkImpl(ConnectionString, driverString);
			
			//short shResult = objDataSinkImpl.store(objCServicesQueryModel, "C:\\StoragePath");
			
			DicomMessage objDicomMessage  = new DicomMessage();
			objDicomMessage.setDataSet(objXRayAngiographicIOD.getDataSet());
			short shResult = objDataSinkImpl.store(objDicomMessage, "C:\\StoragePath");
			
			System.out.println("\n\n shResult = " + shResult);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}

	}

}
