/*******************************************************************************
 *  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.baselibs;


import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataElement;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDictionaryReader;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITransferSyntax;
import cdac.medinfo.sdk.dcm30_04.enums.EnumDirectoryRecordType;
import cdac.medinfo.sdk.dcm30_04.enums.EnumRecordInUseFlag;
import cdac.medinfo.sdk.dcm30_04.exceptions.ConditionFailedException;
import cdac.medinfo.sdk.dcm30_04.exceptions.InvalidItemException;
import cdac.medinfo.sdk.dcm30_04.exceptions.MandatoryMissingException;
import cdac.medinfo.sdk.dcm30_04.exceptions.ValidationException;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConfig;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConstants;
import cdac.medinfo.sdk.dcm30_04.utils.DicomLogger;


/**
 * Sequence of zero or more repeating Items where each Item 
 * contains a Directory Record by including the Directory Elements 
 * from (0004,1400) to (0004,1511) and Record selection Keys.
 * A zero length Value indicates that no Directory Records are contained in the Root Directory Entity.
 */
public class DirectoryRecordSequenceItem extends Item  
{
	        
	private static final long serialVersionUID = 1L;
	
	IDataSet objRecordSelectionKeys = null;

	/**
	 * This constructor creates the item with default TransferSyntax 
	 */
	DirectoryRecordSequenceItem()
	{
		super();
	}

	/*
	 * This constructor calls the respective superclass constructor
	 * This constructor should throw exception if null TS is tried to be set
	 */
	/**
	 * This constructor creates the item with default TransferSyntax 
	 * and default DictionaryReader
	 * @param objITransferSyntax specifies the DICOM Standard defined TransfeSyntax
	 */
	DirectoryRecordSequenceItem(ITransferSyntax objITransferSyntax)
	{
		super(objITransferSyntax);
	}

	/**
	 * This constructor creates DirectoryRecordSequenceItem with specified TransferSyntax and
	 * specified DictionaryReader
	 * @param objTransferSyntax specifies the DICOM Standard defined TransfeSyntax
	 * @param objDictionaryReader specifies the DICOM Dictionary reader to be used 
	 */
	DirectoryRecordSequenceItem(ITransferSyntax objTransferSyntax, IDictionaryReader objDictionaryReader)
	{
		super(objTransferSyntax,objDictionaryReader);
	}

	/**
	 * Sets Offset of the first byte (of the Item Data Element) of the next 
	 * Directory Record of the same Directory Entity. This Offset is an 
	 * unsigned integer representing a number of bytes starting with 
	 * the first byte of the File Meta-information. A zero offset shall be
	 * used to mean that there is no other Directory Record in this Directory Entity.
	 * Required if the Directory Record Sequence (0004,1220) is not zero length.
	 * @param iOffsetOfNextDirectoryRecord long value of Offset Of Next Directory Record.
	 */
	public void setOffsetOfNextDirectoryRecord(int iOffsetOfNextDirectoryRecord)
	{
		/* Accept the Offset Of Next Directory Record of type UL.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0004,0x1400, iOffsetOfNextDirectoryRecord,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0004,0x1400,DicomConstants.DCM_DT_UL, iOffsetOfNextDirectoryRecord);
		//Add the DataElement to the Item
		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves uniquely identifies a set of dimensions referenced within the containing SOP Instance.
	 * @return long - value of Dimension Organization UID.
	 */
	public int getOffsetOfNextDirectoryRecord()
	{
		Object objValue = getValue(0x0004,0x1400);
		if(objValue != null)
			return Integer.parseInt(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}

	/**
	 * This flag facilitates the deletion of referenced files.
	 * Enumerated Values:
	 * FFFFH = record is in use.
	 * 0000H = record is inactive.
	 * Other Values are reserved and shall not be set by File-set 
	 * Creators, but if present shall be interpreted as FFFFH by File-set Readers or Updaters.
	 * Required if the Directory Record Sequence (0004,1220) is not zero length.
	 * If a Directory Record is changed from in use to inactive, the FSU 
	 * shall ensure that all Directory Records of referenced lower-level Directory Entities are changed to inactive.
	 * @param enumRecordInUseFlag enum value of Record in use flag.
	 */
	public void setRecordInUseFlag(EnumRecordInUseFlag enumRecordInUseFlag)
	{
		/* Accept Record In Use Flag of type US.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0004,0x1410, enumRecordInUseFlag.getValue(),objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0004,0x1410,DicomConstants.DCM_DT_US, enumRecordInUseFlag.getValue());
		//Add the DataElement to the Item
		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves uniquely identifies a set of dimensions referenced within the containing SOP Instance.
	 * @return short - value of Dimension Organization UID.
	 */
	public short getRecordInUseFlag()
	{
		Object objValue = getValue(0x0004,0x1410);
		if(objValue != null)
			return Short.parseShort(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}

	/**
	 * Sets Offset of the first byte (of the Item Data Element) of the first
	 * Directory Record of the Referenced Lower Level Directory Entity.
	 * This Offset is a number of bytes starting with the first byte of the
	 * File Meta Information. Required if the Directory Record
	 * Sequence (0004,1220) is not zero length. When no lower-level 
	 * Directory Entity (containing at least one Directory Record) is 
	 * referenced, this Attribute shall have a Value of 00000000H.
	 * @param iOffsetOfReferencedLowerLevelDirectoryEntity long value of Offset of Referenced Lower-Level Directory Entity.
	 */
	public void setOffsetOfReferencedLowerLevelDirectoryEntity(int iOffsetOfReferencedLowerLevelDirectoryEntity)
	{
		/* Accept Offset Of Referenced Lower Level Directory Entity of type UL.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0004,0x1420, iOffsetOfReferencedLowerLevelDirectoryEntity,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0004,0x1420,DicomConstants.DCM_DT_UL, iOffsetOfReferencedLowerLevelDirectoryEntity);
		//Add the DataElement to the Item
		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Offset of the first byte (of the Item Data Element) of the first Directory Record of the Referenced Lower Level Directory Entity.
	 * @return String - value of Offset of Referenced Lower-Level Directory Entity.
	 */
	public int getOffsetOfReferencedLowerLevelDirectoryEntity()
	{
		Object objValue = getValue(0x0004,0x1420);
		if(objValue != null)
			return Integer.parseInt(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}

	/**
	 * Defines a specialized type of Directory Record by reference to its
	 * position in the Media Storage Directory Information Model.
	 * Required if the Directory Record Sequence (0004,1220) is not zero length.
	 * Enumerated Values (see Section F.5):
	 * PATIENT, STUDY, SERIES, IMAGE, OVERLAY, MODALITY LUT, VOI LUT
	 * CURVE, TOPIC, VISIT, RESULTS, INTERPRETATION, STUDY COMPONENT, STORED PRINT
	 * RT DOSE, RT STRUCTURE SET, RT PLAN, RT TREAT RECORD, PRESENTATION,
	 * WAVEFORM, SR DOCUMENT, KEY OBJECT DOC, SPECTROSCOPY, RAW DATA, REGISTRATION
	 * FIDUCIAL, PRIVATE, MRDR.
	 * @param enumDirectoryRecordType Enum value of Directory Record Type.
	 */
	public void setDirectoryRecordType(EnumDirectoryRecordType enumDirectoryRecordType)
	{
		/* Accept  Directory Record Type of type CS.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0004,0x1430, enumDirectoryRecordType.getValue(),objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0004,0x1430,DicomConstants.DCM_DT_CS, enumDirectoryRecordType.getValue());
		//Add the DataElement to the Item
		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Directory Record Type.
	 * @return String - value of  Directory Record Type.
	 */
	public String getDirectoryRecordType()
	{
		Object objValue = getValue(0x0004,0x1430);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Required if the Directory Record Type (0004,1430) is of Value
	 * PRIVATE. This UID is used to define a non-standard type of
	 * Directory Record by reference to its position in a private extension to the Basic Directory IOD Information Model
	 * @param strPrivateRecordUID String value of Private Record UID.
	 */
	public void setPrivateRecordUID(String strPrivateRecordUID)
	{
		/* Accept  Private Record UID of type UI.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0004,0x1432, strPrivateRecordUID,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0004,0x1432,DicomConstants.DCM_DT_UI, strPrivateRecordUID);
		//Add the DataElement to the Item
		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Private Record UID.
	 * @return String - value of Private Record UID.
	 */
	public String getPrivateRecordUID()
	{
		Object objValue = getValue(0x0004,0x1432);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * A Multiple Value which represents the ordered components of the File ID containing a "referenced object" or
	 * Referenced SOP Instance. A maximum of 8 components, each from 1 to 8 characters shall be used.
	 * @param strArrReferencedFileID String array of Referenced File ID.
	 */
	public void setReferencedFileID(String[] strArrReferencedFileID)
	{
		/* Accept  Referenced File ID of type CS.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		for(int i=0;i<strArrReferencedFileID.length;i++)
		{
			String temp = strArrReferencedFileID[i];
			if(temp.length() > DicomConstants.DCM_CS_MAXLENGTH)
			{
				temp = temp.substring((int)(temp.length() - DicomConstants.DCM_CS_MAXLENGTH));
			}
			strArrReferencedFileID[i] = temp;
		}
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0004,0x1500, strArrReferencedFileID,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0004,0x1500,DicomConstants.DCM_DT_CS, strArrReferencedFileID);
		//Add the DataElement to the Item
		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Referenced File ID.
	 * @return String - value of Referenced File ID.
	 */
	public String[] getReferencedFileID()
	{
		Object objValue = getValue(0x0004,0x1500);
		if(objValue != null)
		{
			if(objValue instanceof String)
			{
				String[] strArr = new String[1];
				strArr[0] = (String)objValue;
				return strArr;
			}
			return (String[])objValue;
		}
		return null;
	}

	/**
	 * Sets Offset of the first byte (of the Item Data Element) of the Multi-Referenced File Directory Record.
	 * This Offset is a number of bytes starting with the first byte of the File Meta Information.
	 * When the Directory Record does not reference any SOP Instance this attribute shall not be present.
	 * Required if the Directory Record indirectly references a SOP Instance by a MRDR.
	 * Shall not be present if the Referenced File ID (0004,1500) is used for direct reference.
	 * @param iMRDRDirectoryRecordOffset long value of MRDR Directory Record Offset.
	 */
	public void setMRDRDirectoryRecordOffset(int iMRDRDirectoryRecordOffset)
	{
		/* Accept MRDR Directory Record Offset of type UL.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0004,0x1504, iMRDRDirectoryRecordOffset,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0004,0x1504,DicomConstants.DCM_DT_UL, iMRDRDirectoryRecordOffset);
		//Add the DataElement to the Item
		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves OOffset of the first byte (of the Item Data Element) of the Multi-Referenced File Directory Record.
	 * @return int - value of MRDR Directory Record Offset.
	 */
	public int getMRDRDirectoryRecordOffset()
	{
		Object objValue = getValue(0x0004,0x1504);
		if(objValue != null)
			return Integer.parseInt(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}

	/**
	 * Unique ID for the SOP Class of the Instance stored in the referenced File.
	 * This UID shall be present whether the File is referenced directly by Referenced File ID (0004,1500) or
	 * indirectly by an MRDR Directory Record Offset (0004,1504).
	 * @param strReferencedSOPClassUIDInFile String value of Referenced SOP Class UID in File.
	 */
	public void setReferencedSOPClassUIDInFile(String strReferencedSOPClassUIDInFile)
	{
		/* Accept Referenced SOP Class UID in File of type UI.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0004,0x1510, strReferencedSOPClassUIDInFile,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0004,0x1510,DicomConstants.DCM_DT_UI, strReferencedSOPClassUIDInFile);
		//Add the DataElement to the Item
		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Referenced SOP Class UID in File.
	 * @return String - value of Referenced SOP Class UID in File.
	 */
	public String getReferencedSOPClassUIDInFile()
	{
		Object objValue = getValue(0x0004,0x1510);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Unique Identifier for the SOP Instance stored in the referenced file.
	 * This UID shall be present whether the File is referenced directly by Referenced File ID (0004,1500) or indirectly by an
	 * MRDR Directory Record Offset.
	 * @param strReferencedSOPInstanceUIDInFile String value of Referenced SOP Instance UID in File.
	 */
	public void setReferencedSOPInstanceUIDInFile(String strReferencedSOPInstanceUIDInFile)
	{
		/* Accept Referenced SOP Instance UID in File of type UI.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0004,0x1511, strReferencedSOPInstanceUIDInFile,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0004,0x1511,DicomConstants.DCM_DT_UI, strReferencedSOPInstanceUIDInFile);
		//Add the DataElement to the Item
		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Referenced SOP Instance UID in File.
	 * @return String - value of Referenced SOP Instance UID in File.
	 */
	public String getReferencedSOPInstanceUIDInFile()
	{
		Object objValue = getValue(0x0004,0x1511);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Unique Identifier for the Transfer Syntax used to encode the Instance stored in the referenced file.
	 * This UID shall be present whether the File is referenced directly by Referenced File ID (0004,1500) or indirectly by an
	 * MRDR Directory Record Offset.
	 * @param strReferencedTransferSyntaxUIDInFile String value of Referenced Transfer Syntax UID in File.
	 */
	public void setReferencedTransferSyntaxUIDInFile(String strReferencedTransferSyntaxUIDInFile)
	{
		/* Accept Referenced Transfer Syntax UID In File of type UI.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0004,0x1512, strReferencedTransferSyntaxUIDInFile,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0004,0x1512,DicomConstants.DCM_DT_UI, strReferencedTransferSyntaxUIDInFile);
		//Add the DataElement to the Item
		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Referenced Transfer Syntax UID in File.
	 * @return String - value of Referenced Transfer Syntax UID in File.
	 */
	public String getReferencedTransferSyntaxUIDInFile()
	{
		Object objValue = getValue(0x0004,0x1512);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Unique ID for the Related General SOP Class(es) related to the SOP Class of the Instance stored in the referenced file.
	 * @param strArrReferencedRelatedGeneralSOPClassUIDInFile String array of Referenced Related General SOP Class UID in File.
	 */
	public void setReferencedRelatedGeneralSOPClassUIDInFile(String[] strArrReferencedRelatedGeneralSOPClassUIDInFile)
	{
		/* Accept Referenced Related General SOP Class UID In File of type UI.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0004,0x151A, strArrReferencedRelatedGeneralSOPClassUIDInFile,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0004,0x151A,DicomConstants.DCM_DT_UI, strArrReferencedRelatedGeneralSOPClassUIDInFile);
		//Add the DataElement to the Item
		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Referenced Related General SOP Class UID in File.
	 * @return String[] - value of Referenced Related General SOP Class UID in File.
	 */
	public String[] getReferencedRelatedGeneralSOPClassUIDInFile()
	{
		Object objValue = getValue(0x0004,0x151A);
		if(objValue != null)
			return (String[])objValue;
		return null;
	}

	/**
	 * Validates all the attributes in DirectoryRecordSequenceItem that are present in the DataSet
	 * @return boolean - Success -true, Failure - false
	 * @throws InvalidItemException throws InvalidItemException If Mandatory or Conditional element fails.
	 */
	public boolean validateForModule() throws InvalidItemException
	{
		try
		{
			super.validateForModule();
			if(!contains(0x0004,0x1400))
				throw new MandatoryMissingException("0004,1400");
			if(!contains(0x0004,0x1410))
				throw new MandatoryMissingException("0004,1410");
			if(!contains(0x0004,0x1420))
				throw new MandatoryMissingException("0004,1420");
			if(!contains(0x0004,0x1430))
				throw new MandatoryMissingException("0004,1430");
			if(contains(0x0004,0x1430) && getDirectoryRecordType().equals(EnumDirectoryRecordType.PRIVATE.getValue()) && !contains(0x0004,0x1432))
				throw new ConditionFailedException("0004,1432");
			/*
			 * The condition for Attribute 0004,1500 is not clear
			 * When the Directory Record does not reference any SOP Instance this attribute shall not be present.
			 * To reference a single File by more than one Directory Record, a special Directory
			 * Record of Directory Record Type (0004,1430) MRDR is used.The Referenced File ID (0004,1500) shall be absent and the
			 * MRDR Directory Record Offset (0004, 1504) shall be used to reference the MRDR which indirectly references the File.
			 * please refer chapter 3 page no - 830
			 */

			/*
			 * The condition for attribute 0004,1504 0004,1510 0004,1511 0004,1512 is nor clear
			 * Required only if the Directory Record references a SOP Instance.
			 * Shall not be used in a Multi-Referenced File Directory Record.
			 *  please refer chapter 3 page no - 830
			 */

			/*
			 *The condition for attribute  0004,151A 
			 *Required if the Directory Record references a SOP Instance that encodes the Related General SOP Class UID (0008,001A).
			 *Shall not be used in a Multi-Referenced File Directory Record.
			 * please refer chapter 3 page no - 831
			 */
		}
		catch( ConditionFailedException ce)
		{
			if(DicomConfig.createInstance().isLoggingOn())
			{
				DicomLogger.getLogger().log(ce.getMessage());
			}
			if(DicomConfig.createInstance().isLoggingOn())
			{
				DicomLogger.getLogger().log(ce.getMessage());
			}
			throw new InvalidItemException(this.getClass().getSimpleName(),ce); 
		}catch(MandatoryMissingException me)
		{
			if(DicomConfig.createInstance().isLoggingOn())
			{
				DicomLogger.getLogger().log(me.getMessage());
			}
			throw new ValidationException(this.getClass().getSimpleName(),me);
		}
		return true;
	}
}
