/*******************************************************************************
 *  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.IDataElement;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDicomValue;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITag;
import cdac.medinfo.sdk.dcm30_04.enums.EnumDataRepresentation;
import cdac.medinfo.sdk.dcm30_04.enums.EnumSignalDomainColumns;
import cdac.medinfo.sdk.dcm30_04.enums.EnumSignalDomainRows;

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 specifies the attributes of the MR Spectroscopy Data Module.
 */
public class MRSpectroscopyDataModule extends Module   
{


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


	/**
	 * Instantiates a new mR spectroscopy data module.
	 * 
	 * @param objIDataSet the obj i data set
	 */
	public MRSpectroscopyDataModule(IDataSet objIDataSet)
	{
		super(objIDataSet);
	}

	static
	{
		objSingleCollection = new SingleCollection<ITag>();
		objSingleCollection.add(new Tag(0x0028,0x0010));
		objSingleCollection.add(new Tag(0x0028,0x0011));
		objSingleCollection.add(new Tag(0x0028,0x9001));
		objSingleCollection.add(new Tag(0x0028,0x9002));
		objSingleCollection.add(new Tag(0x0028,0x9108));
		objSingleCollection.add(new Tag(0x0028,0x9003));
		objSingleCollection.add(new Tag(0x0028,0x9235));
		objSingleCollection.add(new Tag(0x5600,0x0010));
		objSingleCollection.add(new Tag(0x5600,0x0020));
	}

	/**
	 * 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
		{			// TODO Auto-generated method stub
		}
		catch(MandatoryMissingException mme)
		{
			if(DicomConfig.createInstance().isLoggingOn())
				DicomLogger.getLogger().log(mme.getMessage());

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

		}
		return true;
	}

	/**
	 * Sets Number of voxels in the vertical direction in the frame.
	 * 
	 * @param shRows - short Number of voxels in the vertical direction in the frame.
	 */
	public void setRows(short shRows)
	{
		/*Accept Number of Rows in this image in short format of type US.
		 * 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
		 */
		addDataElement(0x0028, 0x0010, DicomConstants.DCM_DT_US, shRows);
	}

	/**
	 * Retrieves Number of voxels in the vertical direction in the frame.
	 * 
	 * @return short -  Number of voxels in the vertical direction in the frame.
	 */
	public short getRows()
	{
		IDataElement objIDataElement = objIDataSet.getDataForTag(0x0028,0x0010);
		if(objIDataElement == null)
			return DicomConstants.DCM_NO_VALUE;
		IDicomValue objIDicomValue = objIDataElement.getDicomValue();
		if(objIDicomValue == null)
			return DicomConstants.DCM_NO_VALUE;
		if(objIDicomValue.getValue()==null)
			return DicomConstants.DCM_NO_VALUE;
		return Short.parseShort(objIDicomValue.getValue().toString());
	}

	/**
	 * Sets Number of voxels in the horizontal direction in the frame.
	 * 
	 * @param shColumns - short Number of voxels in the horizontal direction in the frame.
	 */
	public void setColumns(short shColumns)
	{
		/*Accept Number of Columns in this image in short format of type US.
		 * 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
		 */
		addDataElement(0x0028, 0x0011, DicomConstants.DCM_DT_US, shColumns);
	}

	/**
	 * Retrieves Number of voxels in the vertical direction in the frame.
	 * 
	 * @return short -  Number of voxels in the vertical direction in the frame.
	 */
	public short getColumns()
	{
		IDataElement objIDataElement = objIDataSet.getDataForTag(0x0028,0x0011);
		if(objIDataElement == null)
			return DicomConstants.DCM_NO_VALUE;
		IDicomValue objIDicomValue = objIDataElement.getDicomValue();
		if(objIDicomValue == null)
			return DicomConstants.DCM_NO_VALUE;
		if(objIDicomValue.getValue()==null)
			return DicomConstants.DCM_NO_VALUE;
		return Short.parseShort(objIDicomValue.getValue().toString());
	}

	/**
	 * Sets Number of rows of data points in spectroscopic data.
	 * 
	 * @param lDataPointRows - long Number of rows of data points in spectroscopic data.
	 */
	public void setDataPointRows(long lDataPointRows)
	{
		/*Accept value of Columns in short format of type UL.
		 * 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
		 */
		addDataElement(0x0018, 0x9001, DicomConstants.DCM_DT_UL, lDataPointRows);
	}

	/**
	 * Retrieves Number of rows of data points in spectroscopic data.
	 * 
	 * @return long -  Number of rows of data points in spectroscopic data.
	 */
	public long getDataPointRows()
	{
		Object objectValue = getValue(0x0028,0x9001);
		if(objectValue!=null)
			return Long.parseLong(objectValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}

	/**
	 * Sets Number of columns of data points in spectroscopic data.
	 * 
	 * @param lDataPointColumns the l data point columns
	 */
	public void setDataPointColumns(long lDataPointColumns)
	{
		/*Accept value of Columns in short format of type UL.
		 * 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
		 */
		addDataElement(0x0018, 0x9002, DicomConstants.DCM_DT_UL, lDataPointColumns);
	}

	/**
	 * Retrieves Number of columns of data points in spectroscopic data.
	 * 
	 * @return long -  Number of columns of data points in spectroscopic data.
	 */
	public long getDataPointColumns()
	{
		Object objectValue = getValue(0x0028,0x9002);
		if(objectValue!=null)
			return Long.parseLong(objectValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}


	/**
	 * Sets value of Data representation of the data points.
	 * 
	 * @param enumDataRepresentation the enum data representation
	 */
	public void setDataRepresentation(EnumDataRepresentation enumDataRepresentation)
	{
		/*Accept value of Data Representation in Enumeration 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
		 */
		addDataElement(0x0028, 0x9108, DicomConstants.DCM_DT_CS, enumDataRepresentation.getValue());
	}

	/**
	 * Retrieves value Data representation of the data points.
	 * 
	 * @return String - String value of Data representation of the data points.
	 */
	public String getDataRepresentation()
	{
		IDataElement objIDataElement = objIDataSet.getDataForTag(0x0028,0x9108);
		if(objIDataElement == null)
			return null;
		IDicomValue objIDicomValue = objIDataElement.getDicomValue();
		if(objIDicomValue == null)
			return null;
		if(objIDicomValue.getValue()==null)
			return null;
		return objIDicomValue.getValue().toString();
	}

	/**
	 * Sets value of Domain of represented signal in column direction.
	 * 
	 * @param enumSignalDomainColumns the enum signal domain columns
	 */
	public void setSignalDomainColumns(EnumSignalDomainColumns enumSignalDomainColumns)
	{
		/*Accept value of Signal Domain Columns in Enumeration 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
		 */
		addDataElement(0x0028, 0x9003, DicomConstants.DCM_DT_CS, enumSignalDomainColumns.getValue());
	}

	/**
	 * Retrieves value of Domain of represented signal in column direction.
	 * 
	 * @return String - String value of Domain of represented signal in column direction.
	 */
	public String getSignalDomainColumns()
	{
		IDataElement objIDataElement = objIDataSet.getDataForTag(0x0028,0x9003);
		if(objIDataElement == null)
			return null;
		IDicomValue objIDicomValue = objIDataElement.getDicomValue();
		if(objIDicomValue == null)
			return null;
		if(objIDicomValue.getValue()==null)
			return null;
		return objIDicomValue.getValue().toString();
	}

	/**
	 * Sets value of Domain of represented signal in row direction.
	 * 
	 * @param enumSignalDomainColumns the enum signal domain columns
	 */
	public void setSignalDomainRows(EnumSignalDomainRows enumSignalDomainColumns)
	{
		/*Accept value of Signal Domain Rows in Enumeration 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
		 */
		addDataElement(0x0028, 0x9235, DicomConstants.DCM_DT_CS, enumSignalDomainColumns.getValue());
	}

	/**
	 * Retrieves value of Domain of represented signal in row direction.
	 * 
	 * @return String - String value of Domain of represented signal in row direction.
	 */
	public String getSignalDomainRows()
	{
		IDataElement objIDataElement = objIDataSet.getDataForTag(0x0028,0x9235);
		if(objIDataElement == null)
			return null;
		IDicomValue objIDicomValue = objIDataElement.getDicomValue();
		if(objIDicomValue == null)
			return null;
		if(objIDicomValue.getValue()==null)
			return null;
		return objIDicomValue.getValue().toString();
	}

	/**
	 * Sets Number of columns of data points in spectroscopic data.
	 * 
	 * @param fFirstOrderPhaseCorrectionAngle the f first order phase correction angle
	 */
	public void setFirstOrderPhaseCorrectionAngle(float fFirstOrderPhaseCorrectionAngle)
	{
		/*Accept value of First Order Phase Correction Angle in float format of type OF.
		 * 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
		 */
		addDataElement(0x5600, 0x0010, DicomConstants.DCM_DT_OF, fFirstOrderPhaseCorrectionAngle);
	}

	/**
	 * Retrieves Number of columns of data points in spectroscopic data.
	 * 
	 * @return float -  Number of columns of data points in spectroscopic data.
	 */
	public float getFirstOrderPhaseCorrectionAngle()
	{
		IDataElement objIDataElement = objIDataSet.getDataForTag(0x5600, 0x0010);
		if(objIDataElement == null)
			return DicomConstants.DCM_NO_VALUE;
		IDicomValue objIDicomValue = objIDataElement.getDicomValue();
		if(objIDicomValue == null)
			return DicomConstants.DCM_NO_VALUE;
		if(objIDicomValue.getValue()==null)
			return DicomConstants.DCM_NO_VALUE;
		return Float.parseFloat(objIDicomValue.getValue().toString());
	}

	/**
	 * Sets A data stream of the signal intensities that comprise the spectroscopic data.
	 * 
	 * @param fSpectroscopyData - float value of A data stream of the signal intensities that comprise the spectroscopic data.
	 */
	public void setSpectroscopyData(float fSpectroscopyData)
	{
		/*Accept value of SpectroscopyData in float format of type OF.
		 * 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
		 */
		addDataElement(0x5600, 0x0020, DicomConstants.DCM_DT_OF, fSpectroscopyData);
	}

	/**
	 * Retrieves A data stream of the signal intensities that comprise the spectroscopic data.
	 * 
	 * @return float -  Number of columns of data points in spectroscopic data.
	 */
	public float getSpectroscopyData()
	{
		IDataElement objIDataElement = objIDataSet.getDataForTag(0x5600, 0x0020);
		if(objIDataElement == null)
			return DicomConstants.DCM_NO_VALUE;
		IDicomValue objIDicomValue = objIDataElement.getDicomValue();
		if(objIDicomValue == null)
			return DicomConstants.DCM_NO_VALUE;
		if(objIDicomValue.getValue()==null)
			return DicomConstants.DCM_NO_VALUE;
		return Float.parseFloat(objIDicomValue.getValue().toString());
	}
	/**
	 * 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;
	}
}
