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

// TODO: Auto-generated Javadoc
/*
 * The module holds its map of data in a collection wrapper called SingleCollection
 */
/**
 \* The class FramePointersModule.
 */
public class FramePointersModule extends Module  
{

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

	/**
	 * Instantiates a new frame pointers module.
	 * 
	 * @param objIDataSet the obj i data set
	 */
	public FramePointersModule(IDataSet objIDataSet)
	{
		super(objIDataSet);
	}
	static
	{
		objSingleCollection = new SingleCollection<ITag>();
		objSingleCollection.add(new Tag(0x0028,0x6010));
		objSingleCollection.add(new Tag(0x0028,0x6020));
		objSingleCollection.add(new Tag(0x0028,0x6022));
		objSingleCollection.add(new Tag(0x0028,0x6023));
	}

	/**
	 * 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 - returns validation status as success or failure
	 * 
	 * @throws InvalidModuleException - If validation of Module fails
	 */
	public boolean validateModule() throws InvalidModuleException
	{
		//All the Attributes in this Module are Optional
		return true;
	}

	/**
	 * The frame number selected for use as a pictorial representation (e.g. icon) of
	 * the Multi-frame Image
	 * 
	 * @param sRepresentativeFrameNumber - the representative frame number
	 */
	public void setRepresentativeFrameNumber(short sRepresentativeFrameNumber)
	{
		/*Accept Representative Frame Number 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, 0x6010, DicomConstants.DCM_DT_US, sRepresentativeFrameNumber);
	}

	/**
	 * Retrieves frame number selected for use as a pictorial representation (e.g. icon) of
	 * the Multi-frame Image
	 * 
	 * @return the representative frame number
	 */
	public short getRepresentativeFrameNumber()
	{Object objectValue = getValue(0x0028, 0x6010);
		if(objectValue!=null)
			return Short.parseShort(objectValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}

	/**
	 * Frame number(s) selected as frames of interest. A frame number may appear more than once.
	 * 
	 * @param arrShFrameNumbersOfInterest - the frame numbers of interest
	 */
	public void setFrameNumbersOfInterest(short[] arrShFrameNumbersOfInterest)
	{
		/*Accept Frame Numbers of Interest in Array of 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, 0x6020, DicomConstants.DCM_DT_US, arrShFrameNumbersOfInterest);
	}

	/**
	 * Retrieves Frame number(s) selected as frames of interest. A frame number may appear more than once.
	 * 
	 * @return the frame numbers of interest
	 */
	public short[] getFrameNumbersOfInterest()
	{
		Object objectValue = getValue(0x0028, 0x6020);
		if(objectValue!=null)
			return (short[])objectValue;
		return null;
	}

	/**
	 * Description of each one of the Frame(s) of Interest selected in (0028,6020). If multiple Frames of
	 * Interest are selected and this Attribute is used, it shall contain the same number of values as
	 * are in Frame Numbers of Interest (0028,6020).
	 * 
	 * @param arrStrFramesOfInterestDescription - the frames of interest description
	 */
	public void setFramesOfInterestDescription(String[] arrStrFramesOfInterestDescription)
	{
		/*Accept Frame(s) of Interest Description in Array of 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
		 */
		addDataElement(0x0028, 0x6022, DicomConstants.DCM_DT_LO, arrStrFramesOfInterestDescription);
	}

	/**
	 * Retrieves Description of each one of the Frame(s) of Interest selected in (0028,6020).
	 * 
	 * @return the frames of interest description
	 */
	public String[] getFramesOfInterestDescription()
	{Object objectValue = getValue(0x0028,0x6022);
		if(objectValue!=null)
			return (String[])objectValue;
		return null;
	}

	/**
	 * A defined term for each one of the Frame(s) of Interest (0028,6020) that identifies the significance of the frame.
	 * Defined Terms are: HIGHMI = a frame acquired at the time of the high power pulse that destroys acoustic contrast
	 * ,RWAVE = the frame closest to the RWave TRIGGER = a trigger frame, for example a set delay from the R Wave,
	 * ENDSYSTOLE = the frame closest to end of systole, at the end of the T-wave
	 * 
	 * @param enumFrameOfInterestType - array of the frame of interest type
	 */
	public void setFrameOfInterestType(EnumFrameOfInterestType[] enumFrameOfInterestType)
	{
		/*Accept Frame of Interest Type in Array of 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
		 */
		String[] arrStrFrameOfInterestType = new String[enumFrameOfInterestType.length];
		for(int i=0;i < enumFrameOfInterestType.length ; i++)
		{
			arrStrFrameOfInterestType[i] = enumFrameOfInterestType[i].getValue();
		}
		addDataElement(0x0028, 0x6023, DicomConstants.DCM_DT_CS, arrStrFrameOfInterestType);
	}

	/**
	 * Retrieves Frames Of Interest Type.
	 * 
	 * @return the frame of interest type
	 */
	public String[] getFrameOfInterestType()
	{
		Object objectValue = getValue(0x0028, 0x6023);
		if(objectValue!=null)
			return (String[])objectValue;
		return null;
	}

	/*
	 * This method is used by the Module Iterator to iterate through the DataSet and return only
	 * those elements that belong to the respective Module class whose this is called.
	 */
	/**
	 * This method returns the collection of keys representing the DataElements
	 * that belong to this module.
	 * 
	 * @return ISingleCollection - the customized collection containing the dataelement tags
	 * that beling to this module
	 */
	public ISingleCollection<ITag> getVectorOfKeys()
	{
		return objSingleCollection;
	}
	
	
}
