/*******************************************************************************
 *  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.IDicomValue;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDictionaryReader;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITransferSyntax;
import cdac.medinfo.sdk.dcm30_04.enums.EnumImageType;
import cdac.medinfo.sdk.dcm30_04.exceptions.ConditionFailedException;
import cdac.medinfo.sdk.dcm30_04.exceptions.InvalidItemException;
import cdac.medinfo.sdk.dcm30_04.exceptions.InvalidMacroException;
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 methods used to validate, set and get the attributes in {@link ExposureSequence}
 */
public class ExposureSequenceItem extends Item  
{
	


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

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

	/**
	 * This constructor creates the item and internal code sequence macro with specified TS
	 * @param objTransferSyntax specifies the DICOM Standard defined TransfeSyntax 
	 */
	ExposureSequenceItem(ITransferSyntax objITransferSyntax)
	{
		super(objITransferSyntax);
	}

	/**
	 * This constructor creates the item and internal code sequence macro with default TransferSyntax 
	 * and default DictionaryReader
	 * @param objTransferSyntax specifies the DICOM Standard defined TransfeSyntax
	 * @param objDictionaryReader specifies the DICOM Dictionary reader to be used 
	 */
	ExposureSequenceItem(ITransferSyntax objTransferSyntax, IDictionaryReader objDictionaryReader)
	{
		super(objTransferSyntax,objDictionaryReader);
	}

	/**
	 * Validates all the attributes in ExposureSequenceItem 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();
			/*
			 * Condition for Referenced Frame Number(0008,1160),
			 * "Required if Exposure Sequence (3002,0030) is sent, there is more than one item in Exposure Sequence
			 * (3002,0030), and image is a multi-frame image" not understood.
			 * PDF 3, Pg. No. 443.
			 */
			IDataElement objIDataElement = getDataForTag(0x0008, 0x0008);
			String[] arrStrImageType = (String[])objIDataElement.getDicomValue().getValue();
			if(contains(0x0018,0x0060) &&
					!(EnumImageType.Value3.PORTAL.getValue().equals(arrStrImageType[2])||EnumImageType.Value3.SIMULATOR.getValue().equals(arrStrImageType[2])||EnumImageType.Value3.RADIOGRAPH.getValue().equals(arrStrImageType[2])))
				throw new ConditionFailedException("value of conditional Element 0008,0008 should be " + EnumImageType.Value3.PORTAL.getValue() + " or " + EnumImageType.Value3.SIMULATOR.getValue() + "or" + EnumImageType.Value3.RADIOGRAPH.getValue() +  "required for Tag 0018,0060") ;
			else if(contains(0x0018,0x1151) &&
					!(EnumImageType.Value3.SIMULATOR.getValue().equals(arrStrImageType[2])||EnumImageType.Value3.RADIOGRAPH.getValue().equalsIgnoreCase(arrStrImageType[2])))
				throw new ConditionFailedException("value of conditional Element 0008,0008 should be " + EnumImageType.Value3.SIMULATOR.getValue() + " or " + EnumImageType.Value3.RADIOGRAPH.getValue() + " required for Tag 0018,1151") ;
			else if(contains(0x3002,0x0032) &&
					!(EnumImageType.Value3.PORTAL.getValue().equalsIgnoreCase(arrStrImageType[2])))
				throw new ConditionFailedException("value of conditional Element 0008,0008 should be " + EnumImageType.Value3.PORTAL.getValue() + " or " + EnumImageType.Value3.SIMULATOR.getValue() + " or " + EnumImageType.Value3.RADIOGRAPH.getValue() + " required for Tag 3002,0032") ;

		}
		catch(ConditionFailedException ce)
		{
			if(DicomConfig.createInstance().isLoggingOn())
			{
				DicomLogger.getLogger().log(ce.getMessage());
			}
			throw new InvalidItemException(this.getClass().getSimpleName(),ce);
		}
		catch( InvalidMacroException ime)
		{
			if(DicomConfig.createInstance().isLoggingOn())
			{
				DicomLogger.getLogger().log(ime.getMessage());
			}
			throw new InvalidItemException(this.getClass().getSimpleName(),ime);
		}
		return true;
	}

	/**
	 * Sets Referenced Frame Number.
	 * @param strReferencedFrameNumber Specifies String value of Referenced Frame Number.
	 */
	public void setReferencedFrameNumber(String strReferencedFrameNumber)
	{
		/* Accept the ReferencedFrameNumber in String format of type PN.
		 * 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(0x0008, 0x1160, strReferencedFrameNumber,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0008, 0x1160,DicomConstants.DCM_DT_UI, strReferencedFrameNumber);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Referenced Frame Number.
	 * @return String - value of Referenced Frame Number.
	 */
	public String getReferencedFrameNumber()
	{
		Object objValue = getValue(0x0008, 0x1160);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets Peak kilo voltage output of the x-ray generator used.
	 * @param strKVP  String value of Rescale Scope.
	 */
	public void setKVP(String strKVP)
	{
		/* Accept Peak kilo voltage output of the x-ray generator used.
		 * 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 Hash Map
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0018, 0x0060,strKVP,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0018, 0x0060, DicomConstants.DCM_DT_DS,strKVP);
		addDataElement(objIDataElement);
	}

	/**
	 * Peak kilo voltage output of the x-ray generator used.
	 * @return strRescaleScope - String value of Rescale Scope.
	 */
	public String getKVP()
	{
		Object objValue = getValue(0x0018, 0x0060);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Retrieves pre-initialized object of Primary Fluence Mode Sequence.If the module contains the sequence object
	 * it returns the same otherwise it creates the sequence adds to the module with proper initialization
	 * and then returns the object of sequence.
	 * @return PrimaryFluenceModeSequence - instance of PrimaryFluenceModeSequence. 
	 */
	public PrimaryFluenceModeSequence getPrimaryFluenceModeSequence()
	{
		PrimaryFluenceModeSequence objPrimaryFluenceModeSequence = null;
		IDataElement objIDataElement =  getDataForTag(0x3002, 0x0050);
		if(objIDataElement != null)
		{
			IDicomValue objIDicomValue = objIDataElement.getDicomValue();
			if(objIDicomValue != null)
				objPrimaryFluenceModeSequence = (PrimaryFluenceModeSequence)objIDicomValue;
		}
		else
		{
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			int iVRTransferSyntax = objITransferSyntax.getVRTransferSyntax();
			objIDataElement = null;
			objPrimaryFluenceModeSequence = (PrimaryFluenceModeSequence)objDicomV3Factory.createSequence(0x3002, 0x0050, objITransferSyntax, objIDictionaryReader);

			if(iVRTransferSyntax == DicomConstants.DCM_VR_IMPLICIT)
				objIDataElement = new ImplicitDE(0x3002, 0x0050, objPrimaryFluenceModeSequence.getValue(),objIDictionaryReader);
			else
				objIDataElement = new ExplicitDE(0x3002, 0x0050, DicomConstants.DCM_DT_SQ, objPrimaryFluenceModeSequence.getValue());
			objIDataElement.setTransferSyntax(objITransferSyntax);
			if(objIDataElement != null)
				addDataElement(objIDataElement);
		}
		return objPrimaryFluenceModeSequence;
	}

	/**
	 * Sets X-Ray Tube Current in MilliA.
	 * @param strXRayTubeCurrent String value of X-Ray Tube Current in MilliA
	 */
	public void setXRayTubeCurrent(String strXRayTubeCurrent)
	{
		/* Accept X-Ray Tube Current 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 Hash Map
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0018, 0x1151,strXRayTubeCurrent,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0018, 0x1151, DicomConstants.DCM_DT_IS,strXRayTubeCurrent);
		addDataElement(objIDataElement);
	}


	/**
	 * Retrieves X-Ray Tube Current in mA.
	 * @return String - value of X-Ray Tube Current
	 */
	public String getXRayTubeCurrent()
	{
		Object objValue = getValue(0x0018,0x1151);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets X-Ray Tube Current in MilliA.
	 * @param strXRayTubeCurrentinmA String value of X-Ray Tube Current in MilliA
	 */
	public void setXRayTubeCurrentinmA(String strXRayTubeCurrentinmA)
	{
		/* Accept X-Ray Tube Current in String format of type FD.
		 * 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 Hash Map
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0018, 0x9330,strXRayTubeCurrentinmA,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0018, 0x9330, DicomConstants.DCM_DT_FD,strXRayTubeCurrentinmA);
		addDataElement(objIDataElement);
	}


	/**
	 * Retrieves X-Ray Tube Current in mA.
	 * @return String - value of X-Ray Tube Current in mA
	 */
	public String getXRayTubeCurrentinmA()
	{
		Object objValue = getValue(0x0018,0x9330);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets time of x-ray exposure in msec.
	 * @param strExposureTime String value of Time of x-ray exposure in msec
	 */
	public void setExposureTime(String strExposureTime)
	{
		/* Accept Time of x-ray exposure in msec 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 Hash Map
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0018, 0x1150,strExposureTime,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0018, 0x1150, DicomConstants.DCM_DT_IS,strExposureTime);
		addDataElement(objIDataElement);
	}
	/**
	 * Return the String value of the attribute Exposure Time.
	 * @return String - return the Tiem of Exposure
	 */
	public String getExposureTime()
	{
		Object objValue = getValue(0x0018, 0x1150);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Exposure Time in ms.
	 * @param strExposureTimeinms String value of Exposure Time in ms
	 */
	public void setExposureTimeinms(String strExposureTimeinms)
	{
		/* Accept Exposure Time in ms in String format of type FD.
		 * 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 Hash Map
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0018, 0x9328,strExposureTimeinms,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0018, 0x9328, DicomConstants.DCM_DT_FD,strExposureTimeinms);
		addDataElement(objIDataElement);
	}


	/**
	 * Retrieves Exposure Time in ms.
	 * @return String - value of Exposure Time in ms
	 */
	public String getExposureTimeinms()
	{
		Object objValue = getValue(0x0018,0x9328);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets treatment machine Meterset duration over which image has been acquired, specified
	 * in Monitor units (MU) or minutes as defined by Primary Dosimeter Unit (300A,00B3).
	 * Required if Value 3 of Image Type (0008,0008) is PORTAL and Exposure Sequence (3002,0030) is sent.
	 * @param strMetersetExposure String value of Meterset Exposure.
	 */
	public void setMetersetExposure(String strMetersetExposure)
	{
		/* Accept Meterset Exposure 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 Hash Map
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x3002, 0x0032,strMetersetExposure,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x3002, 0x0032, DicomConstants.DCM_DT_DS,strMetersetExposure);
		addDataElement(objIDataElement);
	}
	/**
	 * Return treatment machine Meterset duration over which image has been acquired, specified
	 * in Monitor units (MU) or minutes as defined by Primary Dosimeter Unit (300A,00B3).
	 * @return String - value of Meterset Exposure.
	 */
	public String getMetersetExposure()
	{
		Object objValue = getValue(0x3002, 0x0032);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets positions of diaphragm jaw pairs (in mm) in IEC BEAM LIMITING DEVICE coordinate
	 * axis in the IEC order X1, X2, Y1, Y2.
	 * @param arrStrDiaphragmPosition String value of  Diaphragm Position.
	 */	
	public void setDiaphragmPosition(String[] arrStrDiaphragmPosition)
	{
		/* Accept the Diaphragm Position value in String Array format of type PN.
		 * Read the Transfer Syntax and check to create ImplicitDE or ExplicitDE .
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Hash Map
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x3002, 0x0034,arrStrDiaphragmPosition,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x3002, 0x0034, DicomConstants.DCM_DT_DS,arrStrDiaphragmPosition);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves positions of diaphragm jaw pairs (in mm) in IEC BEAM LIMITING DEVICE coordinate
	 * axis in the IEC order X1, X2, Y1, Y2.
	 * @return arrStrOperatorNames - String value of  Diaphragm Position.
	 */
	public String[] getDiaphragmPosition()
	{
		Object objValue = getValue(0x3002, 0x0034);
		if(objValue != null)
			return (String[])objValue;
		return null;
	}

	/**
	 * Retrieves pre-initialized object of Beam Limiting Device Sequence.If the module contains the sequence object
	 * it returns the same otherwise it creates the sequence adds to the module with proper initialization
	 * and then returns the object of sequence.
	 * @return BeamLimitingDeviceSequence - instance of BeamLimitingDeviceSequence. 
	 */
	public BeamLimitingDeviceSequence getBeamLimitingDeviceSequence()
	{
		BeamLimitingDeviceSequence objBeamLimitingDeviceSequence = null;
		IDataElement objIDataElement =  getDataForTag(0x300A, 0x00B6);
		if(objIDataElement != null)
		{
			IDicomValue objIDicomValue = objIDataElement.getDicomValue();
			if(objIDicomValue != null)
				objBeamLimitingDeviceSequence = (BeamLimitingDeviceSequence)objIDicomValue;
		}
		else
		{
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			int iVRTransferSyntax = objITransferSyntax.getVRTransferSyntax();
			objIDataElement = null;
			objBeamLimitingDeviceSequence = (BeamLimitingDeviceSequence)objDicomV3Factory.createSequence(0x300A, 0x00B6, objITransferSyntax, objIDictionaryReader);

			if(iVRTransferSyntax == DicomConstants.DCM_VR_IMPLICIT)
				objIDataElement = new ImplicitDE(0x300A, 0x00B6, objBeamLimitingDeviceSequence.getValue(),objIDictionaryReader);
			else
				objIDataElement = new ExplicitDE(0x300A, 0x00B6, DicomConstants.DCM_DT_SQ, objBeamLimitingDeviceSequence.getValue());
			objIDataElement.setTransferSyntax(objITransferSyntax);
			if(objIDataElement != null)
				addDataElement(objIDataElement);
		}
		return objBeamLimitingDeviceSequence;
	}
	
	/**
	 * Sets Gantry Angle.
	 * @param strGantryAngle String value of Gantry Angle.
	 */
	public void setGantryAngle(String strGantryAngle)
	{
		/*Accept the Gantry Angle 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,0x011E, strGantryAngle,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x011E,DicomConstants.DCM_DT_DS, strGantryAngle);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Gantry Angle.
	 * @return String - value of Gantry Angle.
	 */
	public String getGantryAngle()
	{
		Object objValue = getValue(0x300A,0x011E);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Gantry Pitch Angle.
	 * @param fGantryPitchAngle float  value of Gantry Pitch Angle.
	 */
	public void setGantryPitchAngle(float  fGantryPitchAngle)
	{
		/*Accept the Gantry Pitch Angle in float  format of type FL.
		 * 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,0x014A, fGantryPitchAngle,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x014A,DicomConstants.DCM_DT_FL, fGantryPitchAngle);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Gantry Pitch Angle.
	 * @return float  - value of Gantry Pitch Angle.
	 */
	public float  getGantryPitchAngle()
	{
		Object objValue = getValue(0x300A,0x014A);
		if(objValue != null)
			return Float.parseFloat(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}

	/**
	 * Sets Beam Limiting Device Angle.
	 * @param strBeamLimitingDeviceAngle String value of Beam Limiting Device Angle.
	 */
	public void setBeamLimitingDeviceAngle(String strBeamLimitingDeviceAngle)
	{
		/*Accept the Beam Limiting Device Angle 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,0x0120, strBeamLimitingDeviceAngle,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x0120,DicomConstants.DCM_DT_DS, strBeamLimitingDeviceAngle);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Beam Limiting Device Angle.
	 * @return String - value of Beam Limiting Device Angle.
	 */
	public String getBeamLimitingDeviceAngle()
	{
		Object objValue = getValue(0x300A,0x0120);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Patient Support Angle.
	 * @param strPatientSupportAngle String value of Patient Support Angle.
	 */
	public void setPatientSupportAngle(String strPatientSupportAngle)
	{
		/*Accept the Patient Support Angle 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,0x0122, strPatientSupportAngle,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x0122,DicomConstants.DCM_DT_DS, strPatientSupportAngle);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Patient Support Angle.
	 * @return String - value of Patient Support Angle.
	 */
	public String getPatientSupportAngle()
	{
		Object objValue = getValue(0x300A,0x0122);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Table Top Pitch Angle.
	 * @param strTableTopPitchAngle String value of Table Top Pitch Angle.
	 */
	public void setTableTopPitchAngle(String strTableTopPitchAngle)
	{
		/*Accept the Table Top Pitch Angle in String format of type FL.
		 * 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,0x0140, strTableTopPitchAngle,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x0140,DicomConstants.DCM_DT_FL, strTableTopPitchAngle);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Table Top Pitch Angle.
	 * @return String - value of Table Top Pitch Angle.
	 */
	public String getTableTopPitchAngle()
	{
		Object objValue = getValue(0x300A,0x0140);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Table Top Roll Angle.
	 * @param strTableTopRollAngle String value of Table Top Roll Angle.
	 */
	public void setTableTopRollAngle(String strTableTopRollAngle)
	{
		/*Accept the Table Top Roll Angle in String format of type FL.
		 * 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,0x0144, strTableTopRollAngle,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x0144,DicomConstants.DCM_DT_FL, strTableTopRollAngle);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Table Top Roll Angle.
	 * @return String - value of Table Top Roll Angle.
	 */
	public String getTableTopRollAngle()
	{
		Object objValue = getValue(0x300A,0x0144);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Table Top Vertical Position.
	 * @param strTableTopVerticalPosition String value of Table Top Vertical Position.
	 */
	public void setTableTopVerticalPosition(String strTableTopVerticalPosition)
	{
		/*Accept the Table Top Vertical Position 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,0x0128, strTableTopVerticalPosition,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x0128,DicomConstants.DCM_DT_DS, strTableTopVerticalPosition);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Table Top Vertical Position.
	 * @return String - value of Table Top Vertical Position.
	 */
	public String getTableTopVerticalPosition()
	{
		Object objValue = getValue(0x300A,0x0128);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Table Top Longitudinal Position.
	 * @param strTableTopLongitudinalPosition String value of Table Top Longitudinal Position.
	 */
	public void setTableTopLongitudinalPosition(String strTableTopVerticalPosition)
	{
		/*Accept the Table Top Longitudinal Position 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,0x0129, strTableTopVerticalPosition,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x0129,DicomConstants.DCM_DT_DS, strTableTopVerticalPosition);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Table Top Longitudinal Position.
	 * @return String - value of Table Top Longitudinal Position.
	 */
	public String getTableTopLongitudinalPosition()
	{
		Object objValue = getValue(0x300A,0x0129);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Table Top Lateral Position.
	 * @param strTableTopLateralPosition String value of Table Top Lateral Position.
	 */
	public void setTableTopLateralPosition(String strTableTopLateralPosition)
	{
		/*Accept the Table Top Lateral Position 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,0x012A, strTableTopLateralPosition,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x012A,DicomConstants.DCM_DT_DS, strTableTopLateralPosition);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Table Top Lateral Position.
	 * @return String - value of Table Top Lateral Position.
	 */
	public String getTableTopLateralPosition()
	{
		Object objValue = getValue(0x300A,0x012A);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Retrieves pre-initialized object of ApplicatorSequence.If the module contains the sequence object
	 * it returns the same otherwise it creates the sequence adds to the module with proper initialization
	 * and then returns the object of sequence.
	 * @return ApplicatorSequence - instance of Applicator Sequence. 
	 */
	public ApplicatorSequence getApplicatorSequence()
	{
		ApplicatorSequence objApplicatorSequence = null;
		IDataElement objIDataElement =  getDataForTag(0x300A, 0x0107);
		if(objIDataElement != null)
		{
			IDicomValue objIDicomValue = objIDataElement.getDicomValue();
			if(objIDicomValue != null)
				objApplicatorSequence = (ApplicatorSequence)objIDicomValue;
		}
		else
		{
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			int iVRTransferSyntax = objITransferSyntax.getVRTransferSyntax();
			objIDataElement = null;
			objApplicatorSequence = (ApplicatorSequence)objDicomV3Factory.createSequence(0x300A, 0x0107, objITransferSyntax, objIDictionaryReader);

			if(iVRTransferSyntax == DicomConstants.DCM_VR_IMPLICIT)
				objIDataElement = new ImplicitDE(0x300A, 0x0107, objApplicatorSequence.getValue(),objIDictionaryReader);
			else
				objIDataElement = new ExplicitDE(0x300A, 0x0107, DicomConstants.DCM_DT_SQ, objApplicatorSequence.getValue());
			objIDataElement.setTransferSyntax(objITransferSyntax);
			if(objIDataElement != null)
				addDataElement(objIDataElement);
		}
		return objApplicatorSequence;
	}
	
	/**
	 * Retrieves pre-initialized object of GeneralAccessorySequence.If the module contains the sequence object
	 * it returns the same otherwise it creates the sequence adds to the module with proper initialization
	 * and then returns the object of sequence.
	 * @return GeneralAccessorySequence - instance of General Accessory Sequence. 
	 */
	public GeneralAccessorySequence getGeneralAccessorySequence()
	{
		GeneralAccessorySequence objGeneralAccessorySequence = null;
		IDataElement objIDataElement =  getDataForTag(0x300A, 0x0420);
		if(objIDataElement != null)
		{
			IDicomValue objIDicomValue = objIDataElement.getDicomValue();
			if(objIDicomValue != null)
				objGeneralAccessorySequence = (GeneralAccessorySequence)objIDicomValue;
		}
		else
		{
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			int iVRTransferSyntax = objITransferSyntax.getVRTransferSyntax();
			objIDataElement = null;
			objGeneralAccessorySequence = (GeneralAccessorySequence)objDicomV3Factory.createSequence(0x300A, 0x0420, objITransferSyntax, objIDictionaryReader);

			if(iVRTransferSyntax == DicomConstants.DCM_VR_IMPLICIT)
				objIDataElement = new ImplicitDE(0x300A, 0x0420, objGeneralAccessorySequence.getValue(),objIDictionaryReader);
			else
				objIDataElement = new ExplicitDE(0x300A, 0x0420, DicomConstants.DCM_DT_SQ, objGeneralAccessorySequence.getValue());
			objIDataElement.setTransferSyntax(objITransferSyntax);
			if(objIDataElement != null)
				addDataElement(objIDataElement);
		}
		return objGeneralAccessorySequence;
	}
	
	/**
	 * Sets Number of Blocks.
	 * @param strNumberofBlocks String value of Number of Blocks.
	 */
	public void setNumberofBlocks (String strNumberofBlocks )
	{
		/*Accept the Number of Blocks 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,0x00F0, strNumberofBlocks ,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x00F0,DicomConstants.DCM_DT_IS, strNumberofBlocks );

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Number of Blocks.
	 * @return String - value of Number of Blocks.
	 */
	public String getNumberofBlocks()
	{
		Object objValue = getValue(0x300A,0x00F0);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Retrieves pre-initialized object of BlockSequence.If the module contains the sequence object
	 * it returns the same otherwise it creates the sequence adds to the module with proper initialization
	 * and then returns the object of sequence.
	 * @return BlockSequence - instance of Block Sequence. 
	 */
	public BlockSequence getBlockSequence()
	{
		BlockSequence objBlockSequence = null;
		IDataElement objIDataElement =  getDataForTag(0x300A, 0x00F4);
		if(objIDataElement != null)
		{
			IDicomValue objIDicomValue = objIDataElement.getDicomValue();
			if(objIDicomValue != null)
				objBlockSequence = (BlockSequence)objIDicomValue;
		}
		else
		{
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			int iVRTransferSyntax = objITransferSyntax.getVRTransferSyntax();
			objIDataElement = null;
			objBlockSequence = (BlockSequence)objDicomV3Factory.createSequence(0x300A, 0x00F4, objITransferSyntax, objIDictionaryReader);

			if(iVRTransferSyntax == DicomConstants.DCM_VR_IMPLICIT)
				objIDataElement = new ImplicitDE(0x300A, 0x00F4, objBlockSequence.getValue(),objIDictionaryReader);
			else
				objIDataElement = new ExplicitDE(0x300A, 0x00F4, DicomConstants.DCM_DT_SQ, objBlockSequence.getValue());
			objIDataElement.setTransferSyntax(objITransferSyntax);
			if(objIDataElement != null)
				addDataElement(objIDataElement);
		}
		return objBlockSequence;
	}
}
