/*******************************************************************************
 *  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.DicomV3Factory;
import cdac.medinfo.sdk.dcm30_04.baselibs.ProposedStudySequence;
import cdac.medinfo.sdk.dcm30_04.baselibs.ReferencedFilmBoxSequence;
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.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;

/**
 \* This module describes attributes in Basic Film Session Relationship Module.
 */
public class BasicFilmSessionRelationshipModule extends Module  
{

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


	/**
	 * Instantiates a new basic film session relationship module.
	 * 
	 * @param objIDataSet the obj i data set
	 */
	public BasicFilmSessionRelationshipModule(IDataSet objIDataSet)
	{
		super(objIDataSet);
	}

	static
	{
		objSingleCollection = new SingleCollection<ITag>();
		objSingleCollection.add(new Tag(0x2000,0x0500));
		objSingleCollection.add(new Tag(0x2130,0x00A0));
	}

	/* For normalized IODs, the type(Mandatory/Optional) of a Module depends upon the
	 * Requirement Type which defines if this module is required by a SCP class or an
	 * SCP class. Hence,the validation of Modules in a Normalized IOD totally depends 
	 * upon the decision that the is it an SCU/SCP that needs the module.Also, Type of the Modules
	 * describes the type of the Attributes inside the Module. Ex: Mandatory Modules contain Attributes that are
	 * included in all SOP Instances employing this IOD.
	 * Decision on implementation of this kind of validation is yet to be done. Hence,
	 * i am putting a empty validate method.
	 * @return - returns validation status as success or failure 
	 * @throws InvalidModuleException - If validation of Module fails 	 
	 */
	/* (non-Javadoc)
	 * @see cdac.medinfo.sdk.dcm30_04.dicommodel.modules.Module#validateModule()
	 */
	public boolean validateModule()throws InvalidModuleException
	{
		return true;
	}

	/**
	 * Retrieves a Sequence which provides references to a set of Film Box SOP Class/Instance pairs.
	 * 
	 * @return - instance of {@link ReferencedFilmBoxSequence}
	 */
	public ReferencedFilmBoxSequence getReferencedFilmBoxSequence()
	{
		ReferencedFilmBoxSequence objReferencedFilmBoxSequence = (ReferencedFilmBoxSequence)getDicomValue(0x2000,0x0500);
		if(objReferencedFilmBoxSequence == null)
		{
			/*
			 * If the sequence object is not present in the DataSet, a new sequence object is created and
			 * the TransferSyntax and DictionaryReader is set into it as it is set in the Module. This ensures that 
			 * the DataElements getting added in the DataSet follow the same TransferSyntax and use the same
			 * DictionaryReader object as that of the module.
			 */
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			objReferencedFilmBoxSequence = (ReferencedFilmBoxSequence)objDicomV3Factory.createSequence(0x2000,0x0500, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x2000,0x0500, DicomConstants.DCM_DT_SQ, objReferencedFilmBoxSequence.getValue());
		}
		return objReferencedFilmBoxSequence;
	}

	/**
	 * Retrieves A Sequence that contains attributes that may be used to identify Stored Print
	 * Storage and Hardcopy Image SOP Instances created to store this Film Session.
	 * 
	 * @return - instance of {@link ProposedStudySequence}
	 */
	public ProposedStudySequence getProposedStudySequence()
	{
		ProposedStudySequence objProposedStudySequence = (ProposedStudySequence)getDicomValue(0x2130,0x00A0);
		if(objProposedStudySequence == null)
		{
			/*
			 * If the sequence object is not present in the DataSet, a new sequence object is created and
			 * the TransferSyntax and DictionaryReader is set into it as it is set in the Module. This ensures that 
			 * the DataElements getting added in the DataSet follow the same TransferSyntax and use the same
			 * DictionaryReader object as that of the module.
			 */
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			objProposedStudySequence = (ProposedStudySequence)objDicomV3Factory.createSequence(0x2130,0x00A0, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x2130,0x00A0, DicomConstants.DCM_DT_SQ, objProposedStudySequence.getValue());
		}
		return objProposedStudySequence;
	}

	/**
	 * 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;
	}
}
