/*******************************************************************************
 *  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.pet;

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.AcquisitionContextModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.CommonInstanceReferenceModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.DeviceModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.FrameOfReferenceModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.GeneralImageModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.ImageIOD;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.ImagePlaneModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.NMOrPETPatientOrientationModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.OverlayPlaneModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.PETImageModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.PETIsotopeModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.PETMultiGatedAcquisitionModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.PETSeriesModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.SOPCommonModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.SpecimenModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.SynchronizationModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.VOILUTModule;
import cdac.medinfo.sdk.dcm30_04.enums.EnumModuleNames;
import cdac.medinfo.sdk.dcm30_04.enums.EnumSOPClassUIDs;

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.ResourceBundleWrapper;

/**
 * The Positron Emission Tomography (PET) Image Information Object Definition specifies an
 * image that has been created by a Positron Tomograph imaging device, including dedicated PET
 * cameras and Nuclear Medicine imaging devices operating in coincidence mode. This includes
 * data created by external detection devices that create images of the distribution of administered
 * radioactive materials, specifically positron emitters, in the body. Depending on the specific
 * radiopharmaceuticals administered and the particular imaging procedure performed, problems
 * involving changes in metabolism, function, or physiology can be investigated and various region
 * pathologies can be studied. For these problems, quantitation of image data in absolute activity
 * and physiological units is important. In addition, the PET Image IOD specifies attenuation
 * (transmission) images used for correction and anatomical reference of emission images.
 */
public class PETIOD extends ImageIOD 
{
	

	/**
	 * The PE t_ iod.
	 */
	String PET_IOD = "PET IOD" ;

	/**
	 * The obj pet series module.
	 */
	PETSeriesModule objPETSeriesModule = null;

	/**
	 * The obj pet isotope module.
	 */
	PETIsotopeModule objPETIsotopeModule = null;

	/**
	 * The obj pet multi gated acquisition module.
	 */
	PETMultiGatedAcquisitionModule objPETMultiGatedAcquisitionModule = null;

	/**
	 * The obj nm or pet patient orientation module.
	 */
	NMOrPETPatientOrientationModule objNMOrPETPatientOrientationModule = null;

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

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

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

	/**
	 * The obj pet image module.
	 */
	PETImageModule objPETImageModule = null;

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

	/**
	 * The obj voilut module.
	 */
	VOILUTModule objVOILUTModule = null;

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

	/**
	 * The obj Synchronization.
	 */
	SynchronizationModule objSynchronizationModule = null;

	/**
	 * The obj Device module.
	 */
	DeviceModule objDeviceModule = null;

	/**
	 * The obj 	Specimen Module .
	 */
	SpecimenModule objSpecimenModule = null;

	/**
	 * The obj Acquisition Context Module.
	 */
	AcquisitionContextModule objAcquisitionContextModule = null;
	
	/**
	 * The obj Common Instance Reference Module.
	 */
	CommonInstanceReferenceModule objCommonInstanceReferenceModule = null;


	/**
	 * Instantiates a new pETIOD.
	 */
	public PETIOD()
	{
		super();
	}

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

	/**
	 * This constructor initializes the  DictionaryReader
	 * in its superclass IOD.
	 * 
	 * @param objIDictionaryReader_ - specifies the DICOM Dictionary reader to be used .
	 */
	public PETIOD(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 PETIOD(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 PETIOD(ITransferSyntax objITransferSyntax_,IDictionaryReader objIDictionaryReader_)
	{
		super(objITransferSyntax_,objIDictionaryReader_);
	}

	/**
	 * Creates PETIOD IOD from a DICOM file containing PETIOD 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 PETIOD(String strFileName)throws IOException,InvalidIODException
	{
		super(strFileName);
		try
		{
			if(objIDataSet != null)
			{
				String strSOPClassUID = objIDataSet.getSOPClassUID();
				if(strSOPClassUID != null)
				{
					if(!strSOPClassUID.equals(EnumSOPClassUIDs.POSITRONEMISSIONTOMOGRAPHYIOD.getValue()))
					{
						throw new InvalidIODException(ResourceBundleWrapper.getValue("exceptions", "InvalidIOD.FileNotMatched", new Locale(DicomConfig.createInstance().getLocale())) + PET_IOD);
					}
				}
				strSOPClassUID = null;
			}
		}
		catch(InvalidIODException iie)
		{
			if(DicomConfig.createInstance().isLoggingOn())
			{
				DicomLogger.getLogger().log(iie.getMessage());
			}
			throw iie;
		}
	}


	/**
	 * Retrieves pre-initialized instance of PET 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 PETSeriesModule - instance of {@link PETSeriesModule}.
	 */
	public PETSeriesModule getPETSeriesModule()
	{
		if(objPETSeriesModule == null)
		{
			objPETSeriesModule = new PETSeriesModule(objIDataSet);
			return objPETSeriesModule;
		}
		return objPETSeriesModule;
	}

	/**
	 * Retrieves pre-initialized instance of PET Isotope 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 PETIsotopeModule - instance of {@link PETIsotopeModule}.
	 */
	public PETIsotopeModule getPETIsotopeModule()
	{
		if(objPETIsotopeModule == null)
		{
			objPETIsotopeModule = new PETIsotopeModule(objIDataSet);
			return objPETIsotopeModule;
		}
		return objPETIsotopeModule;
	}

	/**
	 * Retrieves pre-initialized instance of PET Multi Gated Acquisition 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 PETMultiGatedAcquisitionModule - instance of {@link PETMultiGatedAcquisitionModule}.
	 */
	public PETMultiGatedAcquisitionModule getPETMultiGatedAcquisitionModule()
	{
		if(objPETMultiGatedAcquisitionModule == null)
		{
			objPETMultiGatedAcquisitionModule = new PETMultiGatedAcquisitionModule(objIDataSet);
			return objPETMultiGatedAcquisitionModule;
		}
		return objPETMultiGatedAcquisitionModule;
	}

	/**
	 * Retrieves pre-initialized instance of NM Or PET Patient Orientation 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 NMOrPETPatientOrientationModule - instance of {@link NMOrPETPatientOrientationModule}.
	 */
	public NMOrPETPatientOrientationModule getNMOrPETPatientOrientationModule()
	{
		if(objNMOrPETPatientOrientationModule == null)
		{
			objNMOrPETPatientOrientationModule = new NMOrPETPatientOrientationModule(objIDataSet);
			return objNMOrPETPatientOrientationModule;
		}
		return objNMOrPETPatientOrientationModule;
	}

	/**
	 * 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 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 PET 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 PETImageModule - instance of {@link PETImageModule}.
	 */
	public PETImageModule getPETImageModule()
	{
		if(objPETImageModule == null)
		{
			objPETImageModule = new PETImageModule(objIDataSet);
			return objPETImageModule;
		}
		return objPETImageModule;
	}

	/**
	 * 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 VOI 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 VOILUTModule - instance of {@link VOILUTModule}.
	 */
	public VOILUTModule getVOILUTModule()
	{
		if(objVOILUTModule == null)
		{
			objVOILUTModule = new VOILUTModule(objIDataSet);
			return objVOILUTModule;
		}
		return objVOILUTModule;
	}

	/**
	 * 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 Specimen 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 SpecimenModule - instance of {@link SpecimenModule}.
	 */
	public SpecimenModule getSpecimenModule()
	{
		if(objSpecimenModule == null)
		{
			objSpecimenModule = new SpecimenModule(objIDataSet);
			return objSpecimenModule;
		}
		return objSpecimenModule;
	}
	/**
	 * 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 Synchronization 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 SynchronizationModule - instance of {@link SynchronizationModule}.
	 */
	public SynchronizationModule getSynchronizationModule() 
	{
		if(objSynchronizationModule == null)
		{
			objSynchronizationModule = new SynchronizationModule(objIDataSet);
			return objSynchronizationModule;
		}
		return objSynchronizationModule;
	}
	
	/**
	 * Retrieves pre-initialized instance of Acquisition Context 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 AcquisitionContextModule - instance of {@link AcquisitionContextModule}.
	 */
	public AcquisitionContextModule getAcquisitionContextModule() 
	{
		if(objAcquisitionContextModule == null)
		{
			objAcquisitionContextModule = new AcquisitionContextModule(objIDataSet);
			return objAcquisitionContextModule;
		}
		return objAcquisitionContextModule;
	}

	/**
	 * Retrieves pre-initialized instance of Device 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 DeviceModule - instance of {@link DeviceModule}.
	 */
	public DeviceModule getDeviceModule()
	{
		if(objDeviceModule == null)
		{
			objDeviceModule = new DeviceModule(objIDataSet);
			return objDeviceModule;
		}
		return objDeviceModule;
	}
	
	/**
	 * This method validates PET IOD 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 - function status indicating success or failure.
	 * 
	 * @throws InvalidIODException  throws when IOD is invalid.
	 */
	public boolean validate() throws InvalidIODException
	{
		super.validate();
		try
		{
			getPETSeriesModule().validateModule();
			getPETIsotopeModule().validateModule();
			getNMOrPETPatientOrientationModule().validateModule();
			getFrameOfReferenceModule().validateModule();
			getGeneralEquipmentModule().validateModule();
			getGeneralImageModule().validateModule();
			getImagePlaneModule().validateModule();
			getPETImageModule().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. 
			 */

			if(isModulePresent(OverlayPlaneModule.objSingleCollection, objIDataSet))
				getOverlayPlaneModule().validateModule();
			
			if(isModulePresent(VOILUTModule.objSingleCollection, objIDataSet))
				getVOILUTModule().validateModule();
			
			if(isModulePresent(SpecimenModule.objSingleCollection, objIDataSet))
				getSpecimenModule().validateModule();
			
			if(isModulePresent(CommonInstanceReferenceModule.objSingleCollection, objIDataSet))
				getCommonInstanceReferenceModule().validateModule();

			if(isModulePresent(SynchronizationModule.objSingleCollection, objIDataSet))
				getSynchronizationModule().validateModule();
			
			if(isModulePresent(DeviceModule.objSingleCollection, objIDataSet))
				getDeviceModule().validateModule();
			
			if(isModulePresent(AcquisitionContextModule.objSingleCollection, objIDataSet))
				getAcquisitionContextModule().validateModule();
			
			/*
			 * PET Multi-gated Acquisition . Required if Series Type (0054,1000) Value 1 is GATED.
			 * Please refer p.d.f. Chapter 3 page no 129
			 */
			
			// checking for presence of Image data
			if(!isPresent(0x7FE0,0x0010))
			{
				InvalidIODException iie= new InvalidIODException(ResourceBundleWrapper.getValue("exceptions", "ImageData", new Locale(DicomConfig.createInstance().getLocale())));
				if(DicomConfig.createInstance().isLoggingOn())
					DicomLogger.getLogger().log(iie.getMessage());
				throw iie;
			}
		}
		catch(InvalidModuleException ime)
		{
			if(DicomConfig.createInstance().isLoggingOn())
				DicomLogger.getLogger().log(ime.getMessage());
			
				throw new InvalidIODException(PET_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(PET_IOD+ "\n");
		super.dumpDICOMInfo(objIDicomStream);

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

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

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

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

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

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

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

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

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

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

		objIDicomStream.writeString("\t" + getSOPCommonModule().getClass().getSimpleName() + "\n");
		getSOPCommonModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getSpecimenModule().getClass().getSimpleName() + "\n");
		getSpecimenModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getCommonInstanceReferenceModule().getClass().getSimpleName() + "\n");
		getCommonInstanceReferenceModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getSynchronizationModule().getClass().getSimpleName() + "\n");
		getSynchronizationModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getDeviceModule().getClass().getSimpleName() + "\n");
		getDeviceModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getAcquisitionContextModule().getClass().getSimpleName() + "\n");
		getAcquisitionContextModule().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.PET_SERIES_MODULE.getValue()) && isModulePresent(PETSeriesModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.PET_ISOTOPE_MODULE.getValue()) && isModulePresent(PETIsotopeModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.PET_MULTI_GATED_ACQUISITION_MODULE.getValue()) && isModulePresent(PETMultiGatedAcquisitionModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.NM_PET_PATIENT_ORIENTATION_MODULE.getValue()) && isModulePresent(NMOrPETPatientOrientationModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.FRAME_OF_REFERENCE_MODULE.getValue()) && isModulePresent(FrameOfReferenceModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.GENERAL_IMAGE_MODULE.getValue()) && isModulePresent(GeneralImageModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.IMAGE_PLANE_MODULE.getValue()) && isModulePresent(ImagePlaneModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.PET_IMAGE_MODULE.getValue()) && isModulePresent(PETImageModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.OVERLAY_PLANE_MODULE.getValue()) && isModulePresent(OverlayPlaneModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.VOI_LUT_MODULE.getValue()) && isModulePresent(VOILUTModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.SOP_COMMON_MODULE.getValue()) && isModulePresent(SOPCommonModule.objSingleCollection))
				return true;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.ACQUISITION_CONTEXT_MODULE.getValue()) && isModulePresent(AcquisitionContextModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.SYNCHRONIZATION_MODULE.getValue()) && isModulePresent(SynchronizationModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.DEVICE_MODULE.getValue()) && isModulePresent(DeviceModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.COMMON_INSTANCE_REFERENCE_MODULE.getValue()) && isModulePresent(CommonInstanceReferenceModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.SPECIMEN_MODULE.getValue()) && isModulePresent(SpecimenModule.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;
	}
}
