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




/**
* This item class contains methods to validate, set and get attributes in {@link ExposureDoseSequence}
 */
public class ExposureDoseSequenceItem extends Item  
{
	

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

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

	/*
	 * This constructor calls the respective superclass constructor
	 * This constructor should throw exception if null TS is tried to be set
	 */
	/**
	 * This constructor creates Item with specified transferSyntax
	 * @param objTransferSyntax specifies the DICOM Standard defined TransfeSyntax
	 */
	ExposureDoseSequenceItem(ITransferSyntax objITransferSyntax)
	{
		super(objITransferSyntax);
	}

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

	/**
	 * Validates all the attributes in Presentation LUT Sequence Item 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;
	}

	/**
	 * Sets X-Ray radiation mode.
	 * @param enumRadiationMode Enum value of X-Ray radiation mode.
	 */
	public void setRadiationMode(EnumRadiationMode enumRadiationMode)
	{
		/* Accept X-Ray radiation mode in Enum 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(0x0018,0x115A,enumRadiationMode.getValue(),objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0018,0x115A,DicomConstants.DCM_DT_CS,enumRadiationMode.getValue());
		if(objIDataElement != null)
			addDataElement(objIDataElement);
	}

	/**
	 * Retrieves X-Ray radiation mode.
	 * @return String - value of X-Ray radiation mode.
	 */
	public String getRadiationMode()
	{
		Object objValue = getValue(0x0018,0x115A);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets attribute identifies Peak kilo voltage output of the x-ray generator used.
	 * An average in the case of fluoroscopy
	 * @param StrKVP String identifies the Peak kilo voltage output of the x-ray generator used.
	 * 				  an average in the case of fluoroscopy
	 */	
	public void setKVP(String StrKVP)
	{
		/*Accept Peak kilo voltage String 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(0x0018,0x0060,StrKVP,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0018,0x0060, DicomConstants.DCM_DT_DS,StrKVP);
		addDataElement(objIDataElement);
	}

	/**
	 * Return Peak kilo voltage output of the x-ray generator
	 * @return String - identifies Peak kilo voltage output of the x-ray generator
	 */
	public String getKVP()
	{
		Object objValue = getValue(0x0018,0x0060);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets attribute identifies the X-ray Tube Current in macroampere. An average in the case of
	 * fluoroscopy
	 * @param StrXrayTubeCurrentinMacroAmpere String identifies X-ray Tube Current in macroampere.
	 */	
	public void setXrayTubeCurrentinMacroAmpere(String StrXrayTubeCurrentinMacroAmpere)
	{
		/*Accept Xray Tube Current in MacroAmpere in String 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(0x0018,0x8151,StrXrayTubeCurrentinMacroAmpere,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0018,0x8151, DicomConstants.DCM_DT_DS,StrXrayTubeCurrentinMacroAmpere);
		addDataElement(objIDataElement);
	}

	/**
	 * Return X-ray Tube Current in macroampere. An average in the case of fluoroscopy
	 * @return String - identifies X-ray Tube Current in macroampere.
	 */
	public String getXrayTubeCurrentinMacroAmpere()
	{
		Object objValue = getValue(0x0018,0x8151);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets attribute Time of x-ray exposure or fluoroscopy in msec.
	 * @param StrExposureTime String identifies Time of x-ray exposure or fluoroscopy in msec.
	 */	
	public void setExposureTime(String StrExposureTime)
	{
		/*Accept Time of x-ray exposure or fluoroscopy in msec in String format of type IS.
		 * 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(0x0018,0x1150,StrExposureTime,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0018,0x1150, DicomConstants.DCM_DT_IS,StrExposureTime);
		addDataElement(objIDataElement);
	}

	/**
	 * Return Time of x-ray exposure or fluoroscopy in msec.
	 * @return String - identifies Time of x-ray exposure or fluoroscopy in msec.
	 */
	public String getExposureTime()
	{
		Object objValue = getValue(0x0018,0x1150);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets attribute identifies Type of filter(s) inserted into the X-Ray beam
	 * @param StrFilterType String identifies Type of filter(s) 
	 */	
	public void setFilterType(String StrFilterType)
	{
		/*Accept Filter Type in String format of type SH.
		 * 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(0x0018,0x1160,StrFilterType,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0018,0x1160, DicomConstants.DCM_DT_SH,StrFilterType);
		addDataElement(objIDataElement);
	}

	/**
	 * Return Type of filter(s) inserted into the X-Ray beam
	 * @return String - identifies Type of filter(s)
	 */
	public String getFilterType()
	{
		Object objValue = getValue(0x0018,0x1160);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets the X-Ray absorbing material used in the filter.
	 * @param enumFilterMaterial Enum value of X-Ray absorbing material used in the filter.
	 */
	public void setFilterMaterial(EnumFilterMaterial[] enumFilterMaterial)
	{
		/* Accept Filter Material 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
		 */
		//int intSize = enumFilterMaterial.length;
		String[] arrstrTissueHeterogeneityCorrection = new String[enumFilterMaterial.length];
		for(int i=0;i < enumFilterMaterial.length ; i++)
		{
			arrstrTissueHeterogeneityCorrection[i] = enumFilterMaterial[i].getValue();
		}
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax()==DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0018,0x7050,arrstrTissueHeterogeneityCorrection,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0018,0x7050,DicomConstants.DCM_DT_CS,arrstrTissueHeterogeneityCorrection);
		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves X-Ray absorbing material used in the filter.
	 * @return String[] - String Array of X-Ray absorbing material used in the filter.
	 */
	public String[] getFilterMaterial()
	{
		Object objValue = getValue(0x0018,0x7050);
		if(objValue != null)
			return (String[])objValue;
		return null;
	}
	
	/**
	 * Sets the Comments on Radiation Dose for user defined comments on any special conditions related to radiation encountered during the episode described by this Exposure Dose Sequence Item.
	 * @param strCommentsonRadiationDose user-defined comments
	 */
	public void setCommentsonRadiationDose(String strCommentsonRadiationDose)
	{
		/*Accept the Coding Scheme Name in String format of type ST.
		 * 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(0x0040, 0x0310, strCommentsonRadiationDose,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0040, 0x0310,DicomConstants.DCM_DT_ST, strCommentsonRadiationDose);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves the Comments on Radiation Dose for user defined comments on any special conditions related to radiation encountered during the episode described by this Exposure Dose Sequence Item..
	 * @return String value of Radiation Dose for user-defined comments.
	 */
	public String getCommentsonRadiationDose()
	{
		Object objValue = getValue(0x0040, 0x0310);
		if(objValue != null)
			return objValue.toString();
		return null;
	}	
	
}