/*******************************************************************************
 *  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.EnumFilmSizeID;
import cdac.medinfo.sdk.dcm30_04.enums.EnumMediumType;
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 FilmConsumptionSequence}
 */
public class FilmConsumptionSequenceItem extends Item  
{
	

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

	/**
	 * This constructor creates the item and with default TransferSyntax 
	 */
	FilmConsumptionSequenceItem()
	{
		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
	 */
	FilmConsumptionSequenceItem(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 
	 */
	FilmConsumptionSequenceItem(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 attribute identifies Number of films actually printed.
	 * @param StrNumberofFilms String identifies Number of films actually printed.
	 */	
	public void setNumberofFilms(String StrNumberofFilms)
	{
		/*Accept Number of films actually printed 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(0x2100,0x0170,StrNumberofFilms,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x2100,0x0170, DicomConstants.DCM_DT_IS,StrNumberofFilms);
		addDataElement(objIDataElement);
	}

	/**
	 * Return Number of films actually printed.
	 * @return String - identifies Number of films actually printed.
	 */
	public String getNumberofFilms()
	{
		Object objValue = getValue(0x2100,0x0170);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets Type(s) of medium on which images were printed.
	 * @param enumMediumType Enum value Type(s) of medium
	 */
	public void setMediumType(EnumMediumType enumMediumType)
	{
		/* Accept Type(s) of medium 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(0x2000,0x0030,enumMediumType.getValue(),objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x2000,0x0030,DicomConstants.DCM_DT_CS,enumMediumType.getValue());
		if(objIDataElement != null)
			addDataElement(objIDataElement);
	}

	/**
	 * Retrieves value Type(s) of medium
	 * @return String - value Type(s) of medium
	 */
	public String getMediumType()
	{
		Object objValue = getValue(0x2000,0x0030);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets Size(s) of film on which images were printed.
	 * @param enumFilmSizeID Enum value of Size(s) of film on which images were printed.
	 */
	public void setFilmSizeID(EnumFilmSizeID enumFilmSizeID)
	{
		/* Accept Size(s) of film 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(0x2010,0x0050,enumFilmSizeID.getValue(),objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x2010,0x0050,DicomConstants.DCM_DT_CS,enumFilmSizeID.getValue());
		if(objIDataElement != null)
			addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Size(s) of film on which images were printed.
	 * @return String - value of Size(s) of film on which images were printed.
	 */
	public String getFilmSizeID()
	{
		Object objValue = getValue(0x2010,0x0050);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
}