/*******************************************************************************
 *  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.rt;
import java.io.IOException;
import java.util.Locale;


import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDicomStream;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDictionaryReader;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITransferSyntax;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.AudioModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.ClinicalTrialSeriesModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.CommonInstanceReferenceModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.FrameExtractionModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.FrameOfReferenceModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.GeneralEquipmentModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.GeneralImageModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.GeneralStudyModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.ImagePixelModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.ImagePlaneModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.ModalityLUTModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.MultiFrameModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.MultiFrameOverlayModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.NonImageIOD;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.OverlayPlaneModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.PatientModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.PatientStudyModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.ROIContourModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.RTDVHModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.RTDoseModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.RTDoseROIModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.RTSeriesModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.SOPCommonModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.StructureSetModule;
import cdac.medinfo.sdk.dcm30_04.enums.EnumModuleNames;
import cdac.medinfo.sdk.dcm30_04.enums.EnumSOPClassUIDs;

import cdac.medinfo.sdk.dcm30_04.exceptions.ConditionFailedException;
import cdac.medinfo.sdk.dcm30_04.exceptions.InvalidIODException;
import cdac.medinfo.sdk.dcm30_04.exceptions.InvalidModuleException;
import cdac.medinfo.sdk.dcm30_04.exceptions.ParseException;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConfig;
import cdac.medinfo.sdk.dcm30_04.utils.DicomLogger;
import cdac.medinfo.sdk.dcm30_04.utils.ISingleCollection;
import cdac.medinfo.sdk.dcm30_04.utils.ResourceBundleWrapper;

/**
 * The focus for this Radiotherapy Dose IOD (RT Dose IOD) is to address the requirements for
 * transfer of dose distributions calculated by radiotherapy treatment planning systems. These
 * distributions may be represented as 2D or 3D grids, as isodose curves, or as named or unnamed
 * dose points scattered throughout the volume. This IOD may also contain dose-volume histogram
 * data, single or multi-frame overlays, audio annotations, and application-defined lookup tables.
 * This IOD does not provide for definition of doses in beam or other coordinate systems. The
 * application is responsible for transforming data in other, non-patient based coordinate systems to
 * the patient based coordinate system described in C.7.6.2.1.1.
 */
public class RTDoseIOD extends NonImageIOD 
{
	

	/**
	 * The Constant RT_DOSE_IOD.
	 */
	public static final String RT_DOSE_IOD = "RT Dose IOD";

	
	/**
	 * The obj clinical trial series module.
	 */
	ClinicalTrialSeriesModule objClinicalTrialSeriesModule = null;

	/**
	 * The obj frame of reference module.
	 */
	FrameOfReferenceModule objFrameOfReferenceModule = null;

	/**
	 * The obj general equipment module.
	 */
	GeneralEquipmentModule objGeneralEquipmentModule = null;

	/**
	 * The obj general image module.
	 */
	GeneralImageModule objGeneralImageModule = null;

	/**
	 * The obj general study module.
	 */
	GeneralStudyModule objGeneralStudyModule = null;

	/**
	 * The obj image plane module.
	 */
	ImagePlaneModule objImagePlaneModule = null;

	/**
	 * The obj image pixel module.
	 */
	ImagePixelModule objImagePixelModule = null;

	/**
	 * The obj multi frame module.
	 */
	MultiFrameModule objMultiFrameModule = null;

	/**
	 * The obj multi frame overlay module.
	 */
	MultiFrameOverlayModule objMultiFrameOverlayModule =null;

	/**
	 * The obj modality lut module.
	 */
	ModalityLUTModule objModalityLUTModule = null;

	/**
	 * The obj overlay plane module.
	 */
	OverlayPlaneModule objOverlayPlaneModule =null;

	/**
	 * The obj patient module.
	 */
	PatientModule objPatientModule = null;

	/**
	 * The obj patient study module.
	 */
	PatientStudyModule objPatientStudyModule = null;

	/**
	 * The obj rt dose module.
	 */
	RTDoseModule objRTDoseModule =null;

	/**
	 * The obj rtdvh module.
	 */
	RTDVHModule objRTDVHModule = null;

	/**
	 * The obj roi contour module.
	 */
	ROIContourModule objROIContourModule = null;

	/**
	 * The obj rt dose roi module.
	 */
	RTDoseROIModule objRTDoseROIModule = null;

	/**
	 * The obj rt series module.
	 */
	RTSeriesModule objRTSeriesModule = null;

	/**
	 * The obj structure set module.
	 */
	StructureSetModule objStructureSetModule =null;

	/**
	 * The obj sop common module.
	 */
	SOPCommonModule objSOPCommonModule = null;

	/**
	 * The obj Common Instance Reference Module .
	 */
	CommonInstanceReferenceModule objCommonInstanceReferenceModule = null;
	
	/**
	 * The obj Frame Extraction Module .
	 */
	FrameExtractionModule objFrameExtractionModule = null;
	
	/**
	 * Instantiates a new rT dose iod.
	 */
	public RTDoseIOD()
	{
		super();
	}

	/**
	 * This constructor initializes the TransferSyntax  in its superclass IOD.
	 * 
	 * @param objITransferSyntax_ - specifies the DICOM Standard defined TransfeSyntax.
	 */
	public RTDoseIOD(ITransferSyntax objITransferSyntax_)
	{
		super(objITransferSyntax_);
	}

	/**
	 * This constructor initializes the  DictionaryReader
	 * in its superclass IOD.
	 * 
	 * @param objIDictionaryReader_ - specifies the DICOM Dictionary reader to be used .
	 */
	public RTDoseIOD(IDictionaryReader objIDictionaryReader_)
	{
		super(objIDictionaryReader_);
	}

	/**
	 * This constructor accepts the DataSet from the user   in its superclass IOD.
	 * 
	 * @param objIDataSet_ - specifies the data set to be set in the IOD.
	 */
	public RTDoseIOD(IDataSet objIDataSet_)
	{
		super(objIDataSet_);
	}

	/**
	 * This constructor initializes the TransferSyntax and DictionaryReader in its super class IOD.
	 * 
	 * @param objITransferSyntax_ specifies the DICOM Standard defined TransfeSyntax.
	 * @param objIDictionaryReader_ specifies the DICOM Dictionary reader to be used .
	 */
	public RTDoseIOD(ITransferSyntax objITransferSyntax_,IDictionaryReader objIDictionaryReader_)
	{
		super(objITransferSyntax_,objIDictionaryReader_);
	}

	/**
	 * Creates RTDoseIOD IOD from a DICOM file containing RTDoseIOD DICOM data.
	 * @param strFileName DICOM File with absolute path.
	 * @throws IOException Exception caused due to wrong I/O operations. 
	 * @throws ParseException signals if some parse exceptions are occurred.
	 * @throws InvalidIODException signals if some IOD exceptions are occurred.
	 */
	public RTDoseIOD(String strFileName)throws IOException,InvalidIODException
	{
		super(strFileName);
		try
		{
			if(objIDataSet != null)
			{
				String strSOPClassUID = objIDataSet.getSOPClassUID();
				if(strSOPClassUID != null)
				{
					if(!strSOPClassUID.equals(EnumSOPClassUIDs.RTDOSEIOD.getValue()))
					{
						throw new InvalidIODException(ResourceBundleWrapper.getValue("exceptions", "InvalidIOD.FileNotMatched", new Locale(DicomConfig.createInstance().getLocale())) + RT_DOSE_IOD);
					}
				}
				strSOPClassUID = null;
			}
		}
		catch(InvalidIODException iie)
		{
			if(DicomConfig.createInstance().isLoggingOn())
			{
				DicomLogger.getLogger().log(iie.getMessage());
			}
			throw iie;
		}
	}

	/**
	 * Retrieves pre-initialized instance of Clinical Trial Series Module. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return ClinicalTrialSeriesModule - instance of {@link ClinicalTrialSeriesModule}.
	 */
	public ClinicalTrialSeriesModule getClinicalTrialSeriesModule() 
	{
		if(objClinicalTrialSeriesModule == null)
		{
			objClinicalTrialSeriesModule = new ClinicalTrialSeriesModule(objIDataSet);
			return objClinicalTrialSeriesModule;
		}
		return objClinicalTrialSeriesModule;
	}

	/**
	 * Retrieves pre-initialized instance of Frame Of Reference Module. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return FrameOfReferenceModule - instance of {@link FrameOfReferenceModule}.
	 */
	public FrameOfReferenceModule getFrameOfReferenceModule() 
	{
		if(objFrameOfReferenceModule == null)
		{
			objFrameOfReferenceModule = new FrameOfReferenceModule(objIDataSet);
			return objFrameOfReferenceModule;
		}
		return objFrameOfReferenceModule;
	}

	/**
	 * Retrieves pre-initialized instance of General Equipment Module. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return GeneralEquipmentModule - instance of {@link GeneralEquipmentModule}.
	 */
	public GeneralEquipmentModule getGeneralEquipmentModule()
	{
		if(objGeneralEquipmentModule == null)
		{
			objGeneralEquipmentModule = new GeneralEquipmentModule(objIDataSet);
			return objGeneralEquipmentModule;
		}
		return objGeneralEquipmentModule;
	}

	/**
	 * Retrieves pre-initialized instance of General Study Module. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return GeneralStudyModule - instance of {@link GeneralStudyModule}.
	 */
	public GeneralStudyModule getGeneralStudyModule() 
	{
		if(objGeneralStudyModule == null)
		{
			objGeneralStudyModule = new GeneralStudyModule(objIDataSet);
			return objGeneralStudyModule;
		}
		return objGeneralStudyModule;
	}

	/**
	 * Retrieves pre-initialized instance of Patient Module. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return PatientModule - instance of {@link PatientModule}.
	 */
	public PatientModule getPatientModule() 
	{
		if(objPatientModule == null)
		{
			objPatientModule = new PatientModule(objIDataSet);
			return objPatientModule;
		}
		return objPatientModule;
	}

	/**
	 * Retrieves pre-initialized instance of Patient Study Module. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return PatientStudyModule - instance of {@link PatientStudyModule}.
	 */
	public PatientStudyModule getPatientStudyModule()
	{
		if(objPatientStudyModule == null)
		{
			objPatientStudyModule = new PatientStudyModule(objIDataSet);
			return objPatientStudyModule;
		}
		return objPatientStudyModule;
	}

	/**
	 * Retrieves pre-initialized instance of SOP Common Module. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return SOPCommonModule - instance of {@link SOPCommonModule}.
	 */
	public SOPCommonModule getSOPCommonModule() 
	{
		if(objSOPCommonModule == null)
		{
			objSOPCommonModule = new SOPCommonModule(objIDataSet);
			return objSOPCommonModule;
		}
		return objSOPCommonModule;
	}

	/**
	 * Retrieves pre-initialized instance of RT Series Module. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return RTSeriesModule - instance of {@link RTSeriesModule}.
	 */
	public RTSeriesModule getRTSeriesModule() 
	{
		if(objRTSeriesModule == null)
		{
			objRTSeriesModule = new RTSeriesModule(objIDataSet);
			return objRTSeriesModule;
		}
		return objRTSeriesModule;
	}

	/**
	 * Retrieves pre-initialized instance of General Image Module. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return GeneralImageModule - instance of {@link GeneralImageModule}.
	 */
	public GeneralImageModule getGeneralImageModule()
	{
		if(objGeneralImageModule == null)
		{
			objGeneralImageModule = new GeneralImageModule(objIDataSet);
			return objGeneralImageModule;
		}
		return objGeneralImageModule;
	}

	/**
	 * Retrieves pre-initialized instance of Image Plane Module. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return ImagePlaneModule - instance of {@link ImagePlaneModule}.
	 */
	public ImagePlaneModule getImagePlaneModule()
	{
		if(objImagePlaneModule == null)
		{
			objImagePlaneModule = new ImagePlaneModule(objIDataSet);
			return objImagePlaneModule;
		}
		return objImagePlaneModule;
	}

	/**
	 * Retrieves pre-initialized instance of Modality LUT Module. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return ModalityLUTModule - instance of {@link ModalityLUTModule}.
	 */
	public ModalityLUTModule getModalityLUTModule()
	{
		if(objModalityLUTModule == null)
		{
			objModalityLUTModule = new ModalityLUTModule(objIDataSet);
			return objModalityLUTModule;
		}
		return objModalityLUTModule;
	}

	/**
	 * Retrieves pre-initialized instance of Overlay Plane Module. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return OverlayPlaneModule - instance of {@link OverlayPlaneModule}.
	 */
	public OverlayPlaneModule getOverlayPlaneModule()
	{
		if(objOverlayPlaneModule == null)
		{
			objOverlayPlaneModule = new OverlayPlaneModule(objIDataSet);
			return objOverlayPlaneModule;
		}
		return objOverlayPlaneModule;
	}

	/**
	 * Retrieves pre-initialized instance of Image Pixel Module. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return ImagePixelModule - instance of {@link ImagePixelModule}.
	 */
	public ImagePixelModule getImagePixelModule()
	{
		if(objImagePixelModule == null)
		{
			objImagePixelModule = new ImagePixelModule(objIDataSet);
			return objImagePixelModule;
		}
		return objImagePixelModule;
	}

	/**
	 * Retrieves pre-initialized instance of Multi Frame Module . Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return MultiFrameModule - instance of {@link MultiFrameModule }.
	 */
	public MultiFrameModule getMultiFrameModule()
	{
		if(objMultiFrameModule  == null)
		{
			objMultiFrameModule = new MultiFrameModule(objIDataSet);
			return objMultiFrameModule;
		}
		return objMultiFrameModule;
	}

	/**
	 * Retrieves pre-initialized instance of Multi Frame Overlay Module . Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return MultiFrameOverlayModule - instance of {@link MultiFrameOverlayModule}.
	 */
	public MultiFrameOverlayModule  getMultiFrameOverlayModule ()
	{
		if(objMultiFrameOverlayModule   == null)
		{
			objMultiFrameOverlayModule = new MultiFrameOverlayModule(objIDataSet);
			return objMultiFrameOverlayModule;
		}
		return objMultiFrameOverlayModule;
	}

	/**
	 * Retrieves pre-initialized instance of RT Dose Module . Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return RTDoseModule- instance of {@link RTDoseModule }.
	 */
	public RTDoseModule getRTDoseModule()
	{
		if(objRTDoseModule == null)
		{
			objRTDoseModule = new RTDoseModule(objIDataSet);
			return objRTDoseModule;
		}
		return objRTDoseModule;
	}

	/**
	 * Retrieves pre-initialized instance of RT DVH Module . Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return RTDVHModule - instance of {@link RTDVHModule }.
	 */
	public RTDVHModule getRTDVHModule ()
	{
		if(objRTDVHModule  == null)
		{
			objRTDVHModule = new RTDVHModule(objIDataSet);
			return objRTDVHModule;
		}
		return objRTDVHModule;
	}

	/**
	 * Retrieves pre-initialized instance of ROI Contour Module  . Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return ROIContourModule - instance of {@link ROIContourModule }.
	 */
	public ROIContourModule getROIContourModule()
	{
		if(objROIContourModule == null)
		{
			objROIContourModule = new ROIContourModule(objIDataSet);
		}
		return objROIContourModule;
	}

	/**
	 * Retrieves pre-initialized instance of RT Dose ROI Module . Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return RTDoseROIModule - instance of {@link RTDoseROIModule  }.
	 */
	public RTDoseROIModule getRTDoseROIModule()
	{
		if(objRTDoseROIModule  == null)
		{
			objRTDoseROIModule = new RTDoseROIModule(objIDataSet);
			return objRTDoseROIModule;
		}
		return objRTDoseROIModule;
	}

	/**
	 * Retrieves pre-initialized instance of Structure Set Module . Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return StructureSetModule - instance of {@link StructureSetModule }.
	 */
	public StructureSetModule getStructureSetModule()
	{
		if(objStructureSetModule == null)
		{
			objStructureSetModule = new StructureSetModule(objIDataSet);
			return objStructureSetModule;
		}
		return objStructureSetModule;
	}

	/**
	 * Retrieves pre-initialized instance of Common Instance Reference Module. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return - instance of {@link CommonInstanceReferenceModule}.
	 */
	public CommonInstanceReferenceModule getCommonInstanceReferenceModule() 
	{
		if(objCommonInstanceReferenceModule == null)
		{
			objCommonInstanceReferenceModule = new CommonInstanceReferenceModule(objIDataSet);
			return objCommonInstanceReferenceModule;
		}
		return objCommonInstanceReferenceModule;
	}
	
	/**
	 * Retrieves pre-initialized instance of Frame Extraction Module . Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return - instance of {@link FrameExtractionModule}.
	 */
	public FrameExtractionModule getFrameExtractionModule() 
	{
		if(objFrameExtractionModule == null)
		{
			objFrameExtractionModule = new FrameExtractionModule(objIDataSet);
			return objFrameExtractionModule;
		}
		return objFrameExtractionModule;
	}
	
	/**
	 * This method validates Non-Image IOD RTDoseIOD according to the Module Table given in The DICOM Standard.
	 * The validate method fails if one of the mandatory modules are absent or any of the
	 * modules are invalid. The validate method also checks for conditional modules.
	 * 
	 * @return boolean - status of validation as success or failure
	 * 
	 * @throws InvalidIODException -  throws when the IOD is invalid.
	 */
	public boolean validate() throws InvalidIODException
	{
		try
		{
			super.validate();

			/*Validate the mandatory elements*/
			getPatientModule().validateModule();
			getGeneralStudyModule().validateModule();
			getRTSeriesModule().validateModule();
			getFrameOfReferenceModule().validateModule();
			getGeneralEquipmentModule().validateModule();
			getRTDoseModule().validateModule();
			getSOPCommonModule().validateModule();

			/*
			 * Validation for attribute PatientOrientation(0020,0020) of GeneralImageModule is implemented at IOD level.
			 * condition :- Required if image does not require Image Orientation (Patient)(0020,0037) and Image Position (Patient)
			 * 				(0020,0032). See C.7.6.1.1.1 for further explanation.
			 * Right now we are taking it as if IOD contains any module which has (0020,0037) and (0020,0032)
			 * and if that module and attribute are compulsory then (0020,0020) is not mandatory.
			 * If no module is there in IOD then (0020,0020) is mandatory.
			 * and if attribute or module is optional or conditional then 0020,0020 is also conditional.
			 * THIS IOD CONTAINS IMAGE PLANE MODULE WHICH HAS BOTH THE ATTRIBUTES AS MANDATORY BUT MODULE IS CONDITIONAL. 
			 */
			if(!isModulePresent(ImagePlaneModule.objSingleCollection,objIDataSet) && (isModulePresent(GeneralImageModule.objSingleCollection,objIDataSet)))
			{
				if( !getGeneralImageModule().isPresent(0x0020,0x0020))
				{
					ConditionFailedException cce = new ConditionFailedException("0020,0020");
					if(DicomConfig.createInstance().isLoggingOn())
						DicomLogger.getLogger().log(cce.getMessage());
					throw cce;

				}
				
			}

			/*Validate conditional modules*/
			/*
			 * Condition for validating conditional modules are not clear
			 * Hence not validated.
			 * Refer p.d.f Chapter 3
			 * Page No :- 123
			 */
			/*
			 * Multi-Frame Required if dose data contains grid-based doses and pixel data is grid-based doses and pixel data is.
			 * How to know dose data contains grid-based doses.
			 */
			if(isModulePresent(ImagePixelModule.objSingleCollection,objIDataSet))
			{
				ISingleCollection<byte[]> objISingleCollection = getImagePixelModule().getImagePixelMacro().getPixelData();
				if(objISingleCollection != null)
				{
					if(objISingleCollection.size()>1 && (!isModulePresent(MultiFrameModule.objSingleCollection,objIDataSet)))
					{
						throw new InvalidIODException("Multi-Frame Module is required if pixel data is multi-frame data.");
					}
					else
						getMultiFrameModule().validateModule();
				}
			}

			/*Validate optional modules*/

			if(isModulePresent(PatientStudyModule.objSingleCollection,objIDataSet))
				getPatientStudyModule().validateModule();

			if(isModulePresent(ClinicalTrialSeriesModule.objSingleCollection,objIDataSet))
				getClinicalTrialSeriesModule().validateModule();

			if(isModulePresent(OverlayPlaneModule.objSingleCollection,objIDataSet))
				getOverlayPlaneModule().validateModule();

			if(isModulePresent(MultiFrameOverlayModule.objSingleCollection,objIDataSet))
				getMultiFrameOverlayModule().validateModule();

			if(isModulePresent(ModalityLUTModule.objSingleCollection,objIDataSet))
				getModalityLUTModule().validateModule();

			if(isModulePresent(RTDVHModule.objSingleCollection,objIDataSet))
				getRTDVHModule().validateModule();

			if(isModulePresent(CommonInstanceReferenceModule.objSingleCollection, objIDataSet))
				getCommonInstanceReferenceModule().validateModule();
			
			if(isModulePresent(FrameExtractionModule.objSingleCollection, objIDataSet))
				getFrameExtractionModule().validateModule();
			
		}
		catch(InvalidModuleException ime)
		{
			if(DicomConfig.createInstance().isLoggingOn())
				DicomLogger.getLogger().log(ime.getMessage());
			
				throw new InvalidIODException(RT_DOSE_IOD,ime);
		}
		return true;
	}

	/**
	 *  Dumps the Name of IOD,Module and corresponding Attributs of Module.
	 *  @param objIDicomStream - the Stream on which the Data is to be written.
	 *  @throws IOException - Exception is thrown indicating runtime failure of writing operation.
	 */
	public void dumpDICOMInfo(IDicomStream objIDicomStream) throws IOException
	{
		objIDicomStream.writeString(RT_DOSE_IOD + "\n");
		super.dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getClinicalTrialSeriesModule().getClass().getSimpleName() + "\n");
		getClinicalTrialSeriesModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getFrameOfReferenceModule().getClass().getSimpleName() + "\n");
		getFrameOfReferenceModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getGeneralEquipmentModule().getClass().getSimpleName() + "\n");
		getGeneralEquipmentModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getGeneralImageModule().getClass().getSimpleName() + "\n");
		getGeneralImageModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getGeneralStudyModule().getClass().getSimpleName() + "\n");
		getGeneralStudyModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getImagePlaneModule().getClass().getSimpleName() + "\n");
		getImagePlaneModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getImagePixelModule().getClass().getSimpleName() + "\n");
		getImagePixelModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getMultiFrameModule().getClass().getSimpleName() + "\n");
		getMultiFrameModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getMultiFrameOverlayModule().getClass().getSimpleName() + "\n");
		getMultiFrameOverlayModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getModalityLUTModule().getClass().getSimpleName() + "\n");
		getModalityLUTModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getOverlayPlaneModule().getClass().getSimpleName() + "\n");
		getOverlayPlaneModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getPatientModule().getClass().getSimpleName() + "\n");
		getPatientModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getPatientStudyModule().getClass().getSimpleName() + "\n");
		getPatientStudyModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getRTDoseModule().getClass().getSimpleName() + "\n");
		getRTDoseModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getRTDVHModule().getClass().getSimpleName() + "\n");
		getRTDVHModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getROIContourModule().getClass().getSimpleName() + "\n");
		getROIContourModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getRTDoseROIModule().getClass().getSimpleName() + "\n");
		getRTDoseROIModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getRTSeriesModule().getClass().getSimpleName() + "\n");
		getRTSeriesModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getStructureSetModule().getClass().getSimpleName() + "\n");
		getStructureSetModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getSOPCommonModule().getClass().getSimpleName() + "\n");
		getSOPCommonModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getCommonInstanceReferenceModule().getClass().getSimpleName() + "\n");
		getCommonInstanceReferenceModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getFrameExtractionModule().getClass().getSimpleName() + "\n");
		getFrameExtractionModule().dumpDICOMInfo(objIDicomStream);
	}

	/**
	 * Checks whether the Module is present in the IOD or not.
	 * @param strModuleName String value of module name 
	 * @return boolean - true if the module is present in the IOD, else false is returned.
	 */
	public boolean isModulePresent(String strModuleName)
	{
		if(!super.isModulePresent(strModuleName))
		{
			if(strModuleName == null || strModuleName.equals(""))
				return false;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.AUDIO_MODULE.getValue()) && isModulePresent(AudioModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.CLINICAL_TRIAL_SERIES_MODULE.getValue()) && isModulePresent(ClinicalTrialSeriesModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.FRAME_OF_REFERENCE_MODULE.getValue()) && isModulePresent(FrameOfReferenceModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.GENERAL_EQUIPMENT_MODULE.getValue()) && isModulePresent(GeneralEquipmentModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.GENERAL_IMAGE_MODULE.getValue()) && isModulePresent(GeneralImageModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.GENERAL_STUDY_MODULE.getValue()) && isModulePresent(GeneralStudyModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.IMAGE_PLANE_MODULE.getValue()) && isModulePresent(ImagePlaneModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.IMAGE_PIXEL_MODULE.getValue()) && isModulePresent(ImagePixelModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.MULTI_FRAME_MODULE.getValue()) && isModulePresent(MultiFrameModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.MULTI_FRAME_OVERLAY_MODULE.getValue()) && isModulePresent(MultiFrameOverlayModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.MODALITY_LUT_MODULE.getValue()) && isModulePresent(ModalityLUTModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.OVERLAY_PLANE_MODULE.getValue()) && isModulePresent(OverlayPlaneModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.PATIENT_MODULE.getValue()) && isModulePresent(PatientModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.PATIENT_STUDY_MODULE.getValue()) && isModulePresent(PatientStudyModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.RT_DOSE_MODULE.getValue()) && isModulePresent(RTDoseModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.RT_DVH_MODULE.getValue()) && isModulePresent(RTDVHModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.ROI_CONTOUR_MODULE.getValue()) && isModulePresent(ROIContourModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.RT_DOSE_ROI_MODULE.getValue()) && isModulePresent(RTDoseROIModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.RT_SERIES_MODULE.getValue()) && isModulePresent(RTSeriesModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.STRUCTURE_SET_MODULE.getValue()) && isModulePresent(StructureSetModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.SOP_COMMON_MODULE.getValue()) && isModulePresent(SOPCommonModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.COMMON_INSTANCE_REFERENCE_MODULE.getValue()) && isModulePresent(CommonInstanceReferenceModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.FRAME_EXTRACTION_MODULE.getValue()) && isModulePresent(FrameExtractionModule.objSingleCollection))
				return true;
			else
			{
				if(DicomConfig.createInstance().isLoggingOn())
				{
					DicomLogger objDicomLogger = DicomLogger.getLogger();
					objDicomLogger.log(this.getClass().getName() + " : " +ResourceBundleWrapper.getValue("status","ModuleNotPresent",new Locale(DicomConfig.createInstance().getLocale())) + strModuleName);
				}
				return false;
			}
		}
		return true;
	}
}
