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




/**
* This item class contains methods to validate,set and get the attributes of {@link OriginalImageSequence}.
 */

public class OriginalImageSequenceItem extends ReferencedSequenceDependentItem  
{
	



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

	OriginalImageSequenceItem()
	{
		super();
	}

	/*
	 * This constructor calls the respective superclass constructor
	 * This constructor should throw exception if null TS is tried to be set
	 */
	/**
	 * This constructor creates the item and internal code sequence macro with default TransferSyntax. 
	 * @param objTransferSyntax specifies the DICOM Standard defined TransfeSyntax. 
	 */
	OriginalImageSequenceItem(ITransferSyntax objITransferSyntax)
	{
		super(objITransferSyntax);
	}

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

	/**
	 * Validates all the attributes in AcquisitionContextSequenceItem 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
	{
		/*Since this Sequence is part of a Normalized IOD Module the validation of attributes 
		 * cannot be done. Documents does not describe the type of the attributes in the Sequence.
		 */
		return super.validateForModule();
	}

	/**
	 * Sets the value of Study Instance UID.
	 * @param strStudyInstanceUID String value of Study Instance UID.
	 */
	public void setStudyInstanceUID(String strStudyInstanceUID)
	{
		/*Accept the StudyInstanceUID in String format of type UI.
		 * 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(0x0020, 0x000D, strStudyInstanceUID,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0020, 0x000D,DicomConstants.DCM_DT_UI, strStudyInstanceUID);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Study Instance UID.
	 * @return String - value of Study Instance UID.
	 */
	public String getStudyInstanceUID()
	{
		Object objValue = getValue(0x0020, 0x000D);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets the value of Series Instance UID.
	 * @param strSeriesInstanceUID String value of Series Instance UID.
	 */
	public void setSeriesInstanceUID(String strSeriesInstanceUID)
	{
		/*Accept the SeriesInstanceUID in String format of type UI.
		 * 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(0x0020, 0x000E, strSeriesInstanceUID,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0020, 0x000E,DicomConstants.DCM_DT_UI, strSeriesInstanceUID);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Series Instance UID.
	 * @return String - value of Series Instance UID.
	 */
	public String getSeriesInstanceUID()
	{
		Object objValue = getValue(0x0020, 0x000E);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets the strPatient ID in Patient Module.
	 * @param strPatientID Primary hospital identification number or code for the patient.
	 */	
	public void setPatientID(String strPatientID)
	{
		/*Accept the Patient ID in String format of type LO.
		 * 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
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0010, 0x0020, strPatientID,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0010, 0x0020, DicomConstants.DCM_DT_LO, strPatientID);

		addDataElement(objIDataElement);
	}

	/**
	 * Return the String value of the attribute Patient ID.
	 * @return String - returns the patient ID.
	 */
	public String getPatientID()
	{
		Object objValue = getValue(0x0010, 0x0020);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets Referenced Frame Number.
	 * @param strReferencedFrameNumber Specifies String value of Referenced Frame Number.
	 */
	public void setReferencedFrameNumber(String strReferencedFrameNumber)
	{
		/* Accept the ReferencedFrameNumber in String format of type PN.
		 * 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(0x0008, 0x1160, strReferencedFrameNumber,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0008, 0x1160,DicomConstants.DCM_DT_UI, strReferencedFrameNumber);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Referenced Frame Number.
	 * @return String - value of Referenced Frame Number.
	 */
	public String getReferencedFrameNumber()
	{
		Object objValue = getValue(0x0008, 0x1160);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets a number that identifies this image.
	 * @param strInstanceNumber String value of Instance Number.
	 */
	public void setInstanceNumber(String strInstanceNumber)
	{
		/*Accept A number that identifies this image in String format of type IS.
		 * 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
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0020, 0x0013,strInstanceNumber,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0020, 0x0013, DicomConstants.DCM_DT_IS,strInstanceNumber);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves the Instance number.
	 * @return - the instance number.
	 */
	public String getInstanceNumber()
	{
		Object objValue = getValue(0x0020, 0x0013);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
}
