/*******************************************************************************
 *  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.IDictionaryReader;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITransferSyntax;
import cdac.medinfo.sdk.dcm30_04.enums.EnumCompensatorDivergence;
import cdac.medinfo.sdk.dcm30_04.enums.EnumCompensatorMountingPosition;
import cdac.medinfo.sdk.dcm30_04.enums.EnumCompensatorType;
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.utils.DicomConfig;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConstants;
import cdac.medinfo.sdk.dcm30_04.utils.DicomLogger;




/**
* This item class contains the methods to set,get and validate the attribute present in Compensator Sequence.
 */
public class CompensatorSequenceItem extends Item  
{
	

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	/**
	 * This constructor creates the item and internal code sequence macro with default TransferSyntax 
	 */
	CompensatorSequenceItem()
	{
		super();
	}

	/**
	 * This constructor creates the item and internal code sequence macro with default TransferSyntax 
	 * and default DictionaryReader
	 * @param objITransferSyntax specifies the DICOM Standard defined TransfeSyntax
	 */
	CompensatorSequenceItem(ITransferSyntax objITransferSyntax)
	{
		super(objITransferSyntax);
	}

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

	/**
	 * Identification number of the Compensator.It should be unique within the beam in which it is created.
	 * @param strCompensatorNumber String value of Compensator Number.
	 */
	public void setCompensatorNumber(String strCompensatorNumber)
	{
		/*Accept the CompensatorNumber in String format of type IS.
		 * 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(0x300A,0x00E4, strCompensatorNumber,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x00E4,DicomConstants.DCM_DT_IS, strCompensatorNumber);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Identification number of the Compensator.It should be unique within the beam in which it is created.
	 * @return String - value of Compensator Number.
	 */
	public String getCompensatorNumber()
	{
		Object objValue = getValue(0x300A,0x00E4);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets Type of compensator
	 * Defined Terms:
	 * STANDARD = physical (static) compensator.
	 * DYNAMIC = moving Beam Limiting Device (collimator) simulating physical compensator.
	 * @param enumCompensatorType- Enum value of Compensator Type.
	 */
	public void setCompensatorType(EnumCompensatorType enumCompensatorType)
	{
		/*Accept the Compensator Type in enum.
		 * 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(0x3004,0x00EE, enumCompensatorType.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x3004,0x00EE,DicomConstants.DCM_DT_CS, enumCompensatorType.getValue());

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Type of compensator.
	 * @return String - value of Compensator Type.
	 */
	public String getCompensatorType()
	{
		Object objValue = getValue(0x3004,0x00EE);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets user-supplied identifier for material used to manufacture Compensator.
	 * @param strMaterialID String value of Material ID.
	 */
	public void setMaterialID(String strMaterialID)
	{
		/*Accept the MaterialID in String format of type SH.
		 * 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(0x300A,0x00E1, strMaterialID,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x00E1,DicomConstants.DCM_DT_SH, strMaterialID);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves user-supplied identifier for material used to manufacture Compensator.
	 * @return String - value of Material ID.
	 */
	public String getMaterialID()
	{
		Object objValue = getValue(0x300A,0x00E1);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets Compensator ID.
	 * @param strCompensatorID -String value of Compensator ID.
	 */
	public void setCompensatorID(String strCompensatorID)
	{
		/*Accept the Compensator ID in String format of type SH.
		 * 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(0x300A,0x00E5, strCompensatorID,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x00E5,DicomConstants.DCM_DT_SH, strCompensatorID);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Compensator ID.
	 * @return String - value of Compensator ID.
	 */
	public String getCompensatorID()
	{
		Object objValue = getValue(0x300A,0x00E5);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets an identifier for the accessory intended to be read by a device such as a bar-code reader.
	 * @param strAccessoryCode String value of Accessory Code.
	 */
	public void setAccessoryCode(String strAccessoryCode)
	{
		/* Accept the Accessory Code of Points in String format of type LO.
		 * 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(0x300A,0x00F9, strAccessoryCode,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x00F9,DicomConstants.DCM_DT_LO, strAccessoryCode);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Accessory Code.
	 * @return String value of Accessory Code.
	 */
	public String getAccessoryCode()
	{
		Object objValue = getValue(0x300A,0x00F9);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets radiation source to compensator tray attachment edge distance (in mm) for current compensator.
	 * @param strSourcetoCompensatorTrayDistance String value of Source to Compensator Tray Distance.
	 */
	public void setSourcetoCompensatorTrayDistance(String strSourcetoCompensatorTrayDistance)
	{
		/* Accept the Source to Compensator Tray Distance of Points in String format of type DS.
		 * 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(0x300A,0x00E6, strSourcetoCompensatorTrayDistance,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x00E6,DicomConstants.DCM_DT_DS, strSourcetoCompensatorTrayDistance);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves radiation source to compensator tray attachment edge distance (in mm) for current compensator.
	 * @return String value of Source to Compensator Tray Distance.
	 */
	public String getSourcetoCompensatorTrayDistance()
	{
		Object objValue = getValue(0x300A,0x00E6);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets on which side of the Compensator Tray the compensator is mounted.
	 * Enumerated Values:
	 * PATIENT_SIDE = the compensator is mounted on the side of the Compensator Tray which is towards the patient,
	 * SOURCE_SIDE = the compensator is mounted on the side of the Compensator Tray which is towards the radiation source.
	 * DOUBLE_SIDED = the compensator has a shaped (i.e. non-flat) surface on both sides of the Compensator Tray.
	 * @param enumCompensatorMountingPosition- Enum value of Compensator Mounting Position.
	 */
	public void setCompensatorMountingPosition(EnumCompensatorMountingPosition enumCompensatorMountingPosition)
	{
		/* Accept the Compensator Mounting Position of Points in String format 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(0x300A,0x02E1,enumCompensatorMountingPosition.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x02E1,DicomConstants.DCM_DT_CS, enumCompensatorMountingPosition.getValue());

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves the side of the Compensator Tray on which compensator is mounted.
	 * @return String - value of Compensator Mounting Position.
	 */
	public String getCompensatorMountingPosition()
	{
		Object objValue = getValue(0x300A,0x02E1);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets  presence or absence of geometrical divergence of the compensator.
	 * Enumerated Values:
	 * PRESENT = the compensator is shaped according to the beam geometrical divergence.
	 * ABSENT = the compensator is not shaped according to the beam geometrical divergence.
	 * @param enumCompensatorDivergence Enum value of Compensator Divergence.
	 */
	public void setCompensatorDivergence(EnumCompensatorDivergence enumCompensatorDivergence)
	{
		/* Accept the Compensator Divergence of Points in String format 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(0x300A,0x02E0,enumCompensatorDivergence.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x02E0,DicomConstants.DCM_DT_CS, enumCompensatorDivergence.getValue());

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves  presence or absence of geometrical divergence of the compensator.
	 * @return String value of Compensator Divergence.
	 */
	public String getCompensatorDivergence()
	{
		Object objValue = getValue(0x300A,0x02E0);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	/**
	 * Sets Number of rows in the compensator.
	 * @param strCompensatorRows String value of Compensator Rows.
	 */
	public void setCompensatorRows(String strCompensatorRows)
	{
		/*Accept the Value Type in String format of type IS.
		 * 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(0x300A,0x00E7, strCompensatorRows,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x00E7,DicomConstants.DCM_DT_IS, strCompensatorRows);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Number of rows in the compensator.
	 * @return String - value of Compensator Rows.
	 */
	public String getCompensatorRows()
	{
		Object objValue = getValue(0x300A,0x00E7);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets Number of Columns in the compensator.
	 * @param strCompensatorColumns String value of Compensator Columns.
	 */
	public void setCompensatorColumns(String strCompensatorColumns)
	{
		/*Accept the Compensator Columns in String format of type IS.
		 * 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(0x300A,0x00E8, strCompensatorColumns,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x00E8,DicomConstants.DCM_DT_IS, strCompensatorColumns);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Number of Columns in the compensator.
	 * @return String - value of Compensator Columns.
	 */
	public String getCompensatorColumns()
	{
		Object objValue = getValue(0x300A,0x00E8);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets Physical distance (in mm) between the center of each pixel projected onto machine isocentric plane.
	 * Specified by a numeric pair - adjacent row spacing (delimiter) adjacent column spacing.
	 * @param arrCompensatorPixelSpacing String array of Compensator Pixel Spacing.
	 */
	public void setCompensatorPixelSpacing(String[] arrCompensatorPixelSpacing)
	{
		/*Accept the Compensator Pixel Spacing in  String array format of type DS.
		 * 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(0x300A,0x00E9, arrCompensatorPixelSpacing,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x00E9,DicomConstants.DCM_DT_DS, arrCompensatorPixelSpacing);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Physical distance (in mm) between the center of each pixel projected onto machine isocentric plane.
	 * @return String[] - String array of Compensator Pixel Spacing.
	 */
	public String[] getCompensatorPixelSpacing()
	{
		Object objValue = getValue(0x300A,0x00E9);
		if(objValue != null)
			return (String[])objValue;
		return null;
	}

	/**
	 * Sets The x and y coordinates of the upper left hand corner (first pixel transmitted) of the compensator, projected onto the machine isocentric plane in the IEC BEAM LIMITING DEVICE coordinate system (mm).
	 * @param arrCompensatorPosition String array of Compensator Position.
	 */
	public void setCompensatorPosition(String[] arrCompensatorPosition)
	{
		/*Accept the Compensator Pixel Spacing in  String array format of type DS.
		 * 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(0x300A,0x00EA, arrCompensatorPosition,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x00EA,DicomConstants.DCM_DT_DS, arrCompensatorPosition);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Compensator Position.
	 * @return String[] - String array of Compensator Position.
	 */
	public String[] getCompensatorPosition()
	{
		Object objValue = getValue(0x300A,0x00EA);
		if(objValue != null)
			return (String[])objValue;
		return null;
	}


	/**
	 * Sets Compensator Transmission Data.
	 * @param arrCompensatorTransmissionData String array of Compensator Transmission Data.
	 */
	public void setCompensatorTransmissionData(String[] arrCompensatorTransmissionData)
	{
		/*Accept the Compensator Pixel Spacing in  String array format of type DS.
		 * 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(0x300A,0x00EB, arrCompensatorTransmissionData,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x00EB,DicomConstants.DCM_DT_DS, arrCompensatorTransmissionData);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Compensator Transmission Data.
	 * @return String[] - String array of Compensator Transmission Data.
	 */
	public String[] getCompensatorTransmissionData()
	{
		Object objValue = getValue(0x300A,0x00EB);
		if(objValue != null)
			return (String[])objValue;
		return null;
	}

	/**
	 * Sets Compensator Thickness Data. A data stream of the pixel samples which comprise the compensator, expressed as thicknesses (in mm).
	 * @param arrCompensatorThicknessData String array of Compensator Thickness Data.
	 */
	public void setCompensatorThicknessData(String[] arrCompensatorThicknessData)
	{
		/*Accept the Compensator Pixel Spacing in  String array format of type DS.
		 * 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(0x300A,0x00EC, arrCompensatorThicknessData,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x00EC,DicomConstants.DCM_DT_DS, arrCompensatorThicknessData);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Compensator Thickness Data. A data stream of the pixel samples which comprise the compensator, expressed as thicknesses (in mm).
	 * @return String[] - String array of Compensator Thickness Data.
	 */
	public String[] getCompensatorThicknessData()
	{
		Object objValue = getValue(0x300A,0x00EC);
		if(objValue != null)
			return (String[])objValue;
		return null;
	}


	/**
	 * Sets Source to Compensator Distance. A data stream of the pixel samples which comprise the distance from the radiation source to the compensator surface closest to the radiation source (in mm).
	 * The order of pixel sent is left to right, top to bottom.
	 * @param arrSourcetoCompensatorDistance String array of Source to Compensator Distance.
	 */
	public void setSourcetoCompensatorDistance(String[] arrSourcetoCompensatorDistance)
	{
		/*Accept the Compensator Pixel Spacing in  String array format of type DS.
		 * 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(0x300A,0x02E2, arrSourcetoCompensatorDistance,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x02E2,DicomConstants.DCM_DT_DS, arrSourcetoCompensatorDistance);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Source to Compensator Distance. A data stream of the pixel samples which comprise the distance from the radiation source to the compensator surface closest to the radiation source (in mm).
	 * @return String[] - String array of Source to Compensator Distancea.
	 */
	public String[] getSourcetoCompensatorDistance()
	{
		Object objValue = getValue(0x300A,0x02E2);
		if(objValue != null)
			return (String[])objValue;
		return null;
	}


	/**
	 * Validates all the attributes in CompensatorSequenceItem  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
		{
			String strCompensatorNumber = "0";

			int iMaterialIDLength =0;

			String strValueCompensatorNumber = getCompensatorNumber();
			String strCompensatorMountingPosition = getCompensatorMountingPosition();		
			String strMaterialID = getMaterialID();


			if(!(strValueCompensatorNumber.equals(strCompensatorNumber))&&(!contains(0x300A,0x00E4)))
				throw new ConditionFailedException("300A,00E4 is required if Number of Compensators is non zero");

			if(!(strValueCompensatorNumber.equals(strCompensatorNumber))&&(!contains(0x300A,0x00E1)))
				throw new ConditionFailedException("300A,00E1 is required if Number of Compensators is non zero");


			if((!contains(0x300A,0x00E7)))
				throw new MandatoryMissingException("300A,00E7 is required if Compensator Sequence (300A,00E3) is sent");

			if((!contains(0x300A,0x00E8)))
				throw new MandatoryMissingException("300A,00E8 is required if Compensator Sequence (300A,00E3) is sent");

			if((!contains(0x300A,0x00E9)))
				throw new MandatoryMissingException("300A,00E9 is required if Compensator Sequence (300A,00E3) is sent");

			if((!contains(0x300A,0x00EA)))
				throw new MandatoryMissingException("300A,00EA is required if Compensator Sequence (300A,00E3) is sent");

			if(strMaterialID.length()== iMaterialIDLength &&(!contains(0x300A,0x00EB)))
				throw new ConditionFailedException("300A,00EB is required if Compensator Sequence (300A,00E3) is sent and Material ID (300A,00E1) is zero length");

			if((!(strMaterialID.length()== iMaterialIDLength)) &&(!contains(0x300A,0x00EC)))
				throw new ConditionFailedException("300A,00EC is required if Compensator Sequence (300A,00E3) is sent and Material ID (300A,00E1) is non zero length");

			if((!(strMaterialID.length()== iMaterialIDLength)) && (!strCompensatorMountingPosition.equalsIgnoreCase(EnumCompensatorMountingPosition.COMPENSATOR_SHAPED_SURFACE_BOTHSIDE_COMPENSATORTRAY.getValue())) &&(!contains(0x300A,0x02E2)))
				throw new ConditionFailedException("300A,00EC is required if Compensator Sequence (300A,00E3) is sent and Material ID (300A,00E1) is non zero length and Compensator Mounting Position (300A,02E1) is DOUBLE_SIDED ");
		}
		catch( ConditionFailedException ce)
		{
			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 InvalidItemException(this.getClass().getSimpleName(),me);
		}
		return true;
	}

	/**
	 * Sets the CompensatorTrayID.
	 * @param strCompensatorTrayID
	 */
	public void setCompensatorTrayID(String strCompensatorTrayID)
	{
		/*Accept the ABC in String format of type SH.
		 * 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(0x300A,0x00EF, strCompensatorTrayID,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x300A,0x00EF,DicomConstants.DCM_DT_SH, strCompensatorTrayID);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves CompensatorTrayID.
	 * @return String - value of CompensatorTrayID.
	 */
	public String getCompensatorTrayID()
	{
		Object objValue = getValue(0x300A,0x00EF);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	/**
	 * Sets CompensatorDescription.
	 * @param strCompensatorDescription String value of Compensator Description.
	 */
	public void setCompensatorDescription(String strCompensatorDescription)
	{
		/* Accept CompensatorDescription of type LT.
		 * 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(0x300A,0x02EB, strCompensatorDescription,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x02EB,DicomConstants.DCM_DT_LT, strCompensatorDescription);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Compensator Description.
	 * @return String - value of Compensator Description.
	 */
	public String getCompensatorDescription()
	{
		Object objValue = getValue(0x300A,0x02EB);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
}

