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



import cdac.medinfo.sdk.dcm30_04.baselibs.Tag;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITag;
import cdac.medinfo.sdk.dcm30_04.enums.EnumTomoClass;
import cdac.medinfo.sdk.dcm30_04.enums.EnumTomoType;

import cdac.medinfo.sdk.dcm30_04.exceptions.InvalidModuleException;
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;
import cdac.medinfo.sdk.dcm30_04.utils.ISingleCollection;
import cdac.medinfo.sdk.dcm30_04.utils.SingleCollection;

// TODO: Auto-generated Javadoc
/**
 \* This module describes the attributes of a Tomography acquisition (translation of X-Ray source
 * during the acquisition of a single frame image).
 */
public class XRayTomographyAcquisitionModule extends Module  
{


	/**
	 * The obj single collection.
	 */
	public static ISingleCollection<ITag> objSingleCollection = null;


	static
	{
		objSingleCollection = new SingleCollection<ITag>();
		objSingleCollection.add(new Tag(0x0018,0x1460));
		objSingleCollection.add(new Tag(0x0018,0x1470));
		objSingleCollection.add(new Tag(0x0018,0x1480));
		objSingleCollection.add(new Tag(0x0018,0x1490));
		objSingleCollection.add(new Tag(0x0018,0x1491));
		objSingleCollection.add(new Tag(0x0018,0x1495));
	}

	/**
	 * Instantiates a new x ray tomography acquisition module.
	 * 
	 * @param objIDataSet the obj i data set
	 */
	public XRayTomographyAcquisitionModule(IDataSet objIDataSet)
	{
		super(objIDataSet);
	}

	/**
	 * This method validates each Attribute in the Module according to the Type
	 * of the Attribute.Attributes are of 5 types.
	 * Type 1,Type 2 are Mandatory:
	 * Mandatory Attributes have to present in the Module.
	 * Type 1C,2C are Conditional:
	 * Conditional Attributes' presence depend on a condition.
	 * If the condition is satisfied the Attribute has to be present.
	 * Type 3 are Optional
	 * Optional Attributes can be added as and when required.
	 * 
	 * @return boolean - returns validation status as success or failure
	 * 
	 * @throws InvalidModuleException - If validation of Module fails
	 */
	public  boolean validateModule() throws InvalidModuleException
	{

		try
		{	
			if(!isPresent(0x0018, 0x1460))
				throw new MandatoryMissingException("0018,1460");
		}catch(MandatoryMissingException mme)
		{
			if(DicomConfig.createInstance().isLoggingOn())
				DicomLogger.getLogger().log(mme.getMessage());

			
				throw new InvalidModuleException(this.getClass().getSimpleName(),mme);

		}
		return true;
	}

	/**
	 * Sets Distance in mm between the table surface and the sharp image plane.
	 * 
	 * @param strTomoLayerHeight  String value of Tomo Layer Height.
	 */
	public void setTomoLayerHeight(String strTomoLayerHeight)
	{
		/* Accept Tomo Layer Height 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
		 */
		addDataElement(0x0018, 0x1460, DicomConstants.DCM_DT_DS, strTomoLayerHeight);
	}

	/**
	 * Retrieves Distance in mm between the table surface and the sharp image plane.
	 * 
	 * @return String - String value of Tomo Layer Height.
	 */
	public String getTomoLayerHeight()
	{
		Object objValue = getValue(0x0018,0x1460);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets angle span in degrees of rotation of X-Ray Source during X-Ray acquisition.
	 * 
	 * @param strTomoAngle  String value of Tomo Angle.
	 */
	public void setTomoAngle(String strTomoAngle)
	{
		/*Accept Tomo 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 Hash Map
		 */
		addDataElement(0x0018, 0x1470, DicomConstants.DCM_DT_DS, strTomoAngle);
	}

	/**
	 * Retrieves angle span in degrees of rotation of X-Ray Source during X-Ray acquisition.
	 * 
	 * @return the tomo angle
	 */
	public String getTomoAngle()
	{
		Object objValue = getValue(0x0018,0x1470);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets Time in seconds the source has taken to rotate the Tomo Angle during X-Ray
	 * acquisition.
	 * 
	 * @param strTomoTime  String value of Tomo Time.
	 */
	public void setTomoTime(String strTomoTime)
	{
		/* Accept Tomo Time 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
		 */
		addDataElement(0x0018, 0x1480, DicomConstants.DCM_DT_DS, strTomoTime);
	}

	/**
	 * Return Time in seconds the source has taken to rotate the Tomo Angle during X-Ray
	 * acquisition.
	 * 
	 * @return the tomo time
	 */
	public String getTomoTime()
	{
		Object objValue = getValue(0x0018,0x1480);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets Type of tomography.
	 * Defined Terms:LINEAR, SPIRAL,POLYCYCLOIDAL,CIRCULAR.
	 * 
	 * @param enumTomoType  Enum value of Tomo Type.
	 */
	public void setTomoType(EnumTomoType enumTomoType)
	{
		/* Accept Tomo Type 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
		 */
		addDataElement(0x0018, 0x1490, DicomConstants.DCM_DT_CS, enumTomoType.getValue());
	}

	/**
	 * Retrievs Type of tomography.
	 * Defined Terms:LINEAR, SPIRAL,POLYCYCLOIDAL,CIRCULAR.
	 * 
	 * @return strTomoType - String value of Tomo Type.
	 */
	public String getTomoType()
	{
		Object objValue = getValue(0x0018,0x1490);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets form of tomography. Defined Terms: MOTION, TOMOSYNTHESIS,
	 * 
	 * @param enumTomoClass Enum value of Tomo Class.
	 */
	public void setTomoClass(EnumTomoClass enumTomoClass)
	{
		/* Accept Tomo Class 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
		 */
		addDataElement(0x0018, 0x1491, DicomConstants.DCM_DT_CS, enumTomoClass.getValue());
	}

	/**
	 * Retrievs  form of tomography. Defined Terms: MOTION, TOMOSYNTHESIS,
	 * 
	 * @return String - String value of Tomo Class.
	 */
	public String getTomoClass()
	{
		Object objValue = getValue(0x0018,0x1491);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets the number of source images used to construct this tomosynthetic image.
	 * 
	 * @param strNumberOfTomosynthesisSourceImages  String value of Number of Tomosynthesis Source Images.
	 */
	public void setNumberOfTomosynthesisSourceImages(String strNumberOfTomosynthesisSourceImages)
	{
		/* Accept Number of Tomosynthesis Source Images 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
		 */
		addDataElement(0x0018, 0x1495, DicomConstants.DCM_DT_IS, strNumberOfTomosynthesisSourceImages);
	}

	/**
	 * Retrievs  the number of source images used to construct this tomosynthetic image.
	 * 
	 * @return strNumberOfTomosynthesisSourceImages - String value of Number of Tomosynthesis Source Images.
	 */
	public String getNumberOfTomosynthesisSourceImages()
	{
		Object objValue = getValue(0x0018,0x1495);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * This method returns the vector of keys representing the DataElements that belong to this module.
	 * 
	 * @return vector of Tags - returns the vector containing the collection of tags
	 */
	public ISingleCollection<ITag> getVectorOfKeys()
	{
		return objSingleCollection;
	}
}
