/*******************************************************************************
 *  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.EnumRTImagePlane;
import cdac.medinfo.sdk.dcm30_04.exceptions.InvalidItemException;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConstants;




/**
* This item class contains the methods to set,get and validate the attribute present in Planned Verification Image Sequence.
 */
public class PlannedVerificationImageSequenceItem extends Item  
{
	

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

	/**
	 * This constructor creates the item and internal code sequence macro with default TransferSyntax 
	 */
	PlannedVerificationImageSequenceItem()
	{
		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
	 */
	PlannedVerificationImageSequenceItem(ITransferSyntax objITransferSyntax)
	{
		super(objITransferSyntax);
	}

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


	/**
	 * Sets Cumulative Meterset Weight within current Beam at which image acquisition starts.
	 * @param strStartCumulativeMetersetWeight String value of Start Cumulative Meterset Weight.
	 */
	public void setStartCumulativeMetersetWeight (String strStartCumulativeMetersetWeight )
	{
		/*Accept the Start Cumulative Meterset Weight 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(0x300C,0x0008, strStartCumulativeMetersetWeight ,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300C,0x0008,DicomConstants.DCM_DT_DS, strStartCumulativeMetersetWeight );

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Cumulative Meterset Weight within current Beam at which image acquisition starts.
	 * @return String - value of  Start Cumulative Meterset Weight.
	 */
	public String getStartCumulativeMetersetWeight()
	{
		Object objValue = getValue(0x300C,0x0008);
		if(objValue != null)
			return objValue.toString();
		return null;
	}


	/**
	 * Sets Meterset duration over which image is to be acquired, specified in Monitor units (MU) or minutes as defined by Primary Dosimeter Unit (300A,00B3).
	 * @param strMetersetExposure String value of Meterset Exposure.
	 */
	public void setMetersetExposure(String strMetersetExposure )
	{
		/*Accept the 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 Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x3002,0x0032, strMetersetExposure ,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x3002,0x0032,DicomConstants.DCM_DT_DS, strMetersetExposure);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Meterset duration over which image is to be 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 Cumulative Meterset Weight within current Beam at which image acquisition ends.
	 * @param strEndCumulativeMetersetWeight String value of End Cumulative Meterset Weight.
	 */
	public void setEndCumulativeMetersetWeight (String strEndCumulativeMetersetWeight )
	{
		/*Accept the End Cumulative Meterset Weight 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(0x300C,0x0009, strEndCumulativeMetersetWeight ,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300C,0x0009,DicomConstants.DCM_DT_DS, strEndCumulativeMetersetWeight );

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Cumulative Meterset Weight within current Beam at which image acquisition ends.
	 * @return String - value of  End Cumulative Meterset Weight.
	 */
	public String getEndCumulativeMetersetWeight()
	{
		Object objValue = getValue(0x300C,0x0009);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets whether or not image plane is normal to beam axis.
	 * Enumerated Values:
	 * NORMAL = image plane normal to beam axis,
	 * NON_NORMAL = image plane non-normal to beam axis.
	 * @param enumRTImagePlane Enum value of RT Image Plane.
	 */
	public void setRTImagePlane(EnumRTImagePlane enumRTImagePlane )
	{
		/*Accept the RT Image Plane 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(0x3002,0x000C, enumRTImagePlane.getValue() ,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x3002,0x000C,DicomConstants.DCM_DT_CS, enumRTImagePlane.getValue() );

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves whether or not image plane is normal to beam axis.
	 * @return String - value of  of RT Image Plane.
	 */
	public String getRTImagePlane()
	{
		Object objValue = getValue(0x3002,0x000C);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets X-Ray Image Receptor Angle i.e. orientation of IEC X-RAY IMAGE RECEPTOR coordinate system with respect to IEC GANTRY coordinate system (degrees).
	 * @param strXRayImageReceptorAngle String value of X-Ray Image Receptor Angle.
	 */
	public void setXRayImageReceptorAngle(String strXRayImageReceptorAngle )
	{
		/*Accept the End Cumulative Meterset Weight 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(0x3002,0x000E, strXRayImageReceptorAngle ,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x3002,0x000E,DicomConstants.DCM_DT_DS, strXRayImageReceptorAngle );

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves X-Ray Image Receptor Angle.
	 * @return String - value of  X-Ray Image Receptor Angle.
	 */
	public String getXRayImageReceptorAngle()
	{
		Object objValue = getValue(0x3002,0x000E);
		if(objValue != null)
			return objValue.toString();
		return null;
	}


	/**
	 * Sets The direction cosines of the first row and the first column with respect to the IEC XRAY IMAGE RECEPTOR coordinate System.
	 * @param arrRTImageOrientation String array of RT Image Orientation.
	 */	
	public void setRTImageOrientation(String[] arrRTImageOrientation)
	{
		/* Accept the RT Image Orientation in String Array format of type DS.
		 * 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,0x0010,arrRTImageOrientation,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x3002,0x0010,DicomConstants.DCM_DT_DS,arrRTImageOrientation);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves RT Image Orientation. The direction cosines of the first row and the first column with respect to the IEC XRAY IMAGE RECEPTOR coordinate System.
	 * @return arrRTImageOrientation - String value ofRT Image Orientation.
	 */
	public String[] getRTImageOrientation()
	{
		Object objValue = getValue(0x3002,0x0010);
		if(objValue != null)
			return (String[])objValue;
		return null;
	}


	/**
	 * Sets The x and y coordinates (in mm) of the upper left hand corner of the image, in the IEC X-RAY IMAGE RECEPTOR coordinate system.
	 * This is the center of the first pixel transmitted.
	 * @param arrRTImagePosition String array of RT Image Position.
	 */	
	public void setRTImagePosition(String[] arrRTImagePosition)
	{
		/* Accept the RT Image Position in String Array format of type DS.
		 * 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,0x0012,arrRTImagePosition,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x3002,0x0012,DicomConstants.DCM_DT_DS,arrRTImagePosition);
		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves RT Image Orientation. The direction cosines of the first row and the first column with respect to the IEC XRAY IMAGE RECEPTOR coordinate System.
	 * @return arrRTImageOrientation - String value ofRT Image Orientation.
	 */
	public String[] getRTImagePosition()
	{
		Object objValue = getValue(0x3002,0x0012);
		if(objValue != null)
			return (String[])objValue;
		return null;
	}

	/**
	 * Sets Radiation machine source to image plane distance (mm).
	 * @param strRTImageSID String value of RT Image SID.
	 */
	public void setRTImageSID(String strRTImageSID )
	{
		/*Accept the RT Image SID 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(0x3002,0x0026, strRTImageSID ,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x3002,0x0026,DicomConstants.DCM_DT_DS, strRTImageSID );

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Radiation machine source to image plane distance (mm).
	 * @return String - value of   RT Image SID.
	 */
	public String getRTImageSID()
	{
		Object objValue = getValue(0x3002,0x0026);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets User-specified device-specific parameters that describe how the imager will acquire the image.
	 * @param arrImagingDeviceSpecificAcquisitionParameters String array of Imaging Device-Specific Acquisition Parameters.
	 */
	public void setImagingDeviceSpecificAcquisitionParameters(String[] arrImagingDeviceSpecificAcquisitionParameters)
	{
		/*Accept the Imaging Device Specific Acquisition Parameters 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,0x00CC, arrImagingDeviceSpecificAcquisitionParameters,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x00CC,DicomConstants.DCM_DT_LO, arrImagingDeviceSpecificAcquisitionParameters);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Imaging Device Specific Acquisition Parameters
	 * @return String - array of Imaging Device-Specific Acquisition Parameters.
	 */
	public String[] getImagingDeviceSpecificAcquisitionParameters()
	{
		Object objValue = getValue(0x300A,0x00CC);
		if(objValue != null)
			return (String[])objValue;
		return null;
	}


	/**
	 * Sets Referenced Reference Image Number. Uniquely identifies Reference Image to which planned verification image is related, 
	 * specified by Reference Image Number (300A,00C8) within Referenced Reference Image Sequence (300A,0042).
	 * @param strReferencedReferenceImageNumber String value of Referenced Reference Image Number.
	 */
	public void setReferencedReferenceImageNumber (String strReferencedReferenceImageNumber )
	{
		/*Accept the Referenced Reference Image Number  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(0x300C,0x0007, strReferencedReferenceImageNumber ,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300C,0x0007,DicomConstants.DCM_DT_IS, strReferencedReferenceImageNumber );

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Referenced Reference Image Number. Uniquely identifies Reference Image to which planned verification image is related, 
	 * specified by Reference Image Number (300A,00C8) within Referenced Reference Image Sequence (300A,0042).
	 * @return String - value of Referenced Reference Image Number.
	 */
	public String getReferencedReferenceImageNumber()
	{
		Object objValue = getValue(0x300C,0x0007);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Validates all the attributes in PlannedVerificationImageSequenceItem 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
	{
		return true;
	}
}
