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

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.ContrastBolusModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.CurveModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.DXAnatomyImagedModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.DXDetectorModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.DXImageModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.DXPositioningModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.DXSeriesModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.DeviceModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.DisplayShutterModule;
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.ImageHistogramModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.ImageIOD;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.InterventionModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.IntraOralImageModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.IntraOralSeriesModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.OverlayPlaneModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.SOPCommonModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.SpecimenIdentificationModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.SpecimenModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.VOILUTModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.XRayAcquisitionDoseModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.XRayCollimatorModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.XRayFiltrationModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.XRayGenerationModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.XRayGridModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.XRayTomographyAcquisitionModule;
import cdac.medinfo.sdk.dcm30_04.enums.EnumModuleNames;
import cdac.medinfo.sdk.dcm30_04.enums.EnumPresentationIntentType;
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.ResourceBundleWrapper;

/**
 * The Digital Intra-oral X-Ray Image Information Object Definition specifies an image that has been
 * created by an intra-oral projection radiography imaging device.
 * 
 * 
 */
public class DigitalIntraOralXRayImageIOD extends ImageIOD 
{
	

	/**
	 * The Constant DIGITAL_INTRA_ORAL_XRAY_IMAGE_IOD.
	 */
	public static final String DIGITAL_INTRA_ORAL_XRAY_IMAGE_IOD = "Digital Intra Oral X-Ray Image IOD";

	/**
	 * The obj acquisition context module.
	 */
	AcquisitionContextModule objAcquisitionContextModule = null;

	/**
	 * The obj contrast bolus module.
	 */
	ContrastBolusModule objContrastBolusModule = null;

	/**
	 * The obj display shutter module.
	 */
	DisplayShutterModule objDisplayShutterModule = null;

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

	/**
	 * The obj dx anatomy imaged module.
	 */
	DXAnatomyImagedModule objDXAnatomyImagedModule = null;

	/**
	 * The obj dx detector module.
	 */
	DXDetectorModule objDXDetectorModule = null;

	/**
	 * The obj dx image module.
	 */
	DXImageModule objDXImageModule = null;

	/**
	 * The obj dx positioning module.
	 */
	DXPositioningModule objDXPositioningModule = null;

	/**
	 * The obj dx series module.
	 */
	DXSeriesModule objDXSeriesModule = null;

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

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

	/**
	 * The obj image histogram module.
	 */
	ImageHistogramModule objImageHistogramModule = null;

	/**
	 * The obj intervention module.
	 */
	InterventionModule objInterventionModule = null;

	/**
	 * The obj intra oral image module.
	 */
	IntraOralImageModule objIntraOralImageModule = null;

	/**
	 * The obj intra oral series module.
	 */
	IntraOralSeriesModule objIntraOralSeriesModule = null;

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

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

	/**
	 * The obj specimen identification module.
	 */
	SpecimenIdentificationModule objSpecimenIdentificationModule = null;

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

	/**
	 * The obj x ray collimator module.
	 */
	XRayCollimatorModule objXRayCollimatorModule = null;

	/**
	 * The obj x ray tomography acquisition module.
	 */
	XRayTomographyAcquisitionModule objXRayTomographyAcquisitionModule = null;

	/**
	 * The obj x ray acquisition dose module.
	 */
	XRayAcquisitionDoseModule objXRayAcquisitionDoseModule = null;

	/**
	 * The obj x ray generation module.
	 */
	XRayGenerationModule objXRayGenerationModule = null;

	/**
	 * The obj x ray filtration module.
	 */
	XRayFiltrationModule objXRayFiltrationModule = null;

	/**
	 * The obj x ray grid module.
	 */
	XRayGridModule objXRayGridModule = null;
	
	/**
	 * The obj 	Specimen Module .
	 */
	SpecimenModule objSpecimenModule = null;

	/**
	 * The obj Common Instance Reference Module.
	 */
	CommonInstanceReferenceModule objCommonInstanceReferenceModule = null;

	
	/**
	 * Instantiates a new digital intra oral x ray image iod.
	 */
	public DigitalIntraOralXRayImageIOD()
	{
		super();
	}

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

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

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

	/**
	 * 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 Contrast Bolus 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 ContrastBolusModule - instance of {@link ContrastBolusModule}.
	 */
	public ContrastBolusModule getContrastBolusModule()
	{
		if(objContrastBolusModule == null)
		{
			objContrastBolusModule = new ContrastBolusModule(objIDataSet);
			return objContrastBolusModule;
		}
		return objContrastBolusModule;
	}


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

	/**
	 * Retrieves pre-initialized instance of Display Shutter 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 DisplayShutterModule - instance of {@link DisplayShutterModule}.
	 */
	public DisplayShutterModule getDisplayShutterModule()
	{
		if(objDisplayShutterModule == null)
		{
			objDisplayShutterModule = new DisplayShutterModule(objIDataSet);
			return objDisplayShutterModule;
		}
		return objDisplayShutterModule;
	}

	/**
	 * Retrieves pre-initialized instance of DX Anatomy Imaged 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 DXAnatomyImagedModule - instance of {@link DXAnatomyImagedModule}.
	 */
	public DXAnatomyImagedModule getDXAnatomyImagedModule() 
	{
		if(objDXAnatomyImagedModule == null)
		{
			objDXAnatomyImagedModule = new DXAnatomyImagedModule(objIDataSet);
			return objDXAnatomyImagedModule;
		}
		return objDXAnatomyImagedModule;
	}

	/**
	 * Retrieves pre-initialized instance of DX Detector 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 DXDetectorModule - instance of {@link DXDetectorModule}.
	 */
	public DXDetectorModule getDXDetectorModule() 
	{
		if(objDXDetectorModule == null)
		{
			objDXDetectorModule = new DXDetectorModule(objIDataSet);
			return objDXDetectorModule;
		}
		return objDXDetectorModule;
	}

	/**
	 * Retrieves pre-initialized instance of DX 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 DXImageModule - instance of {@link DXImageModule}.
	 */
	public DXImageModule getDXImageModule() 
	{
		if(objDXImageModule == null)
		{
			objDXImageModule = new DXImageModule(objIDataSet);
			return objDXImageModule;
		}
		return objDXImageModule;
	}

	/**
	 * Retrieves pre-initialized instance of DX Positioning 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 DXPositioningModule - instance of {@link DXPositioningModule}.
	 */
	public DXPositioningModule getDXPositioningModule()
	{
		if(objDXPositioningModule == null)
		{
			objDXPositioningModule = new DXPositioningModule(objIDataSet);
			return objDXPositioningModule;
		}
		return objDXPositioningModule;
	}

	/**
	 * Retrieves pre-initialized instance of DX 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 DXSeriesModule - instance of {@link DXSeriesModule}.
	 */
	public DXSeriesModule getDXSeriesModule() 
	{
		if(objDXSeriesModule == null)
		{
			objDXSeriesModule = new DXSeriesModule(objIDataSet);
			return objDXSeriesModule;
		}
		return objDXSeriesModule;
	}

	/**
	 * 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 Histogram 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 ImageHistogramModule - instance of {@link ImageHistogramModule}.
	 */
	public ImageHistogramModule getImageHistogramModule()
	{
		if(objImageHistogramModule == null)
		{
			objImageHistogramModule = new ImageHistogramModule(objIDataSet);
			return objImageHistogramModule;
		}
		return objImageHistogramModule;
	}

	/**
	 * Retrieves pre-initialized instance of Intervention 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 InterventionModule - instance of {@link InterventionModule}.
	 */
	public InterventionModule getInterventionModule() 
	{
		if(objInterventionModule == null)
		{
			objInterventionModule = new InterventionModule(objIDataSet);
			return objInterventionModule;
		}
		return objInterventionModule;
	}

	/**
	 * Retrieves pre-initialized instance of Intra Oral 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 IntraOralImageModule - instance of {@link IntraOralImageModule}.
	 */
	public IntraOralImageModule getIntraOralImageModule() 
	{
		if(objIntraOralImageModule == null)
		{
			objIntraOralImageModule = new IntraOralImageModule(objIDataSet);
			return objIntraOralImageModule;
		}
		return objIntraOralImageModule;
	}

	/**
	 * Retrieves pre-initialized instance of Intra Oral 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 IntraOralSeriesModule - instance of {@link IntraOralSeriesModule}.
	 */
	public IntraOralSeriesModule getIntraOralSeriesModule() 
	{
		if(objIntraOralSeriesModule == null)
		{
			objIntraOralSeriesModule = new IntraOralSeriesModule(objIDataSet);
			return objIntraOralSeriesModule;
		}
		return objIntraOralSeriesModule;
	}

	/**
	 * 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 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 Identification 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 SpecimenIdentificationModule - instance of {@link SpecimenIdentificationModule}.
	 */
	public SpecimenIdentificationModule getSpecimenIdentificationModule() 
	{
		if(objSpecimenIdentificationModule == null)
		{
			objSpecimenIdentificationModule = new SpecimenIdentificationModule(objIDataSet);
			return objSpecimenIdentificationModule;
		}
		return objSpecimenIdentificationModule;
	}

	/**
	 * 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 XRay Acquisition 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 XRayAcquisitionDoseModule - instance of {@link XRayAcquisitionDoseModule}.
	 */
	public XRayAcquisitionDoseModule getXRayAcquisitionDoseModule() 
	{
		if(objXRayAcquisitionDoseModule == null)
		{
			objXRayAcquisitionDoseModule = new XRayAcquisitionDoseModule(objIDataSet);
			return objXRayAcquisitionDoseModule;
		}
		return objXRayAcquisitionDoseModule;
	}

	/**
	 * Retrieves pre-initialized instance of XRay Collimator 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 XRayCollimatorModule - instance of {@link XRayCollimatorModule}.
	 */
	public XRayCollimatorModule getXRayCollimatorModule() 
	{
		if(objXRayCollimatorModule == null)
		{
			objXRayCollimatorModule = new XRayCollimatorModule(objIDataSet);
			return objXRayCollimatorModule;
		}
		return objXRayCollimatorModule;
	}

	/**
	 * Retrieves pre-initialized instance of XRay Filtration 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 XRayFiltrationModule - instance of {@link XRayFiltrationModule}.
	 */
	public XRayFiltrationModule getXRayFiltrationModule() 
	{
		if(objXRayFiltrationModule == null)
		{
			objXRayFiltrationModule = new XRayFiltrationModule(objIDataSet);
			return objXRayFiltrationModule;
		}
		return objXRayFiltrationModule;
	}

	/**
	 * Retrieves pre-initialized instance of XRay Generation 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 XRayGenerationModule - instance of {@link XRayGenerationModule}.
	 */
	public XRayGenerationModule getXRayGenerationModule() 
	{
		if(objXRayGenerationModule == null)
		{
			objXRayGenerationModule = new XRayGenerationModule(objIDataSet);
			return objXRayGenerationModule;
		}
		return objXRayGenerationModule;
	}

	/**
	 * Retrieves pre-initialized instance of XRay Grid 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 XRayGridModule - instance of {@link XRayGridModule}.
	 */
	public XRayGridModule getXRayGridModule() 
	{
		if(objXRayGridModule == null)
		{
			objXRayGridModule = new XRayGridModule(objIDataSet);
			return objXRayGridModule;
		}
		return objXRayGridModule;
	}

	/**
	 * Retrieves pre-initialized instance of XRay Tomography 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 XRayTomographyAcquisitionModule - instance of {@link XRayTomographyAcquisitionModule}.
	 */
	public XRayTomographyAcquisitionModule getXRayTomographyAcquisitionModule() 
	{
		if(objXRayTomographyAcquisitionModule == null)
		{
			objXRayTomographyAcquisitionModule = new XRayTomographyAcquisitionModule(objIDataSet);
			return objXRayTomographyAcquisitionModule;
		}
		return objXRayTomographyAcquisitionModule;
	}
	

	/**
	 * 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;
	}
	/**
	 * Validates all the modules 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 - when IOD is invalid.
	 */
	public boolean validate() throws InvalidIODException
	{
		try
		{
			super.validate();
			getGeneralEquipmentModule().validateModule();
			getDXSeriesModule().validateModule();
			getIntraOralSeriesModule().validateModule();
			getGeneralEquipmentModule().validateModule();
			getGeneralImageModule().validateModule();
			getDXAnatomyImagedModule().validateModule();
			getDXImageModule().validateModule();
			getDXDetectorModule().validateModule();
			getIntraOralImageModule().validateModule();
			getAcquisitionContextModule().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 DOES NOT CONTAIN ANY MODULE containing THESE ATTRIBUTES.
			 */
			if( !getGeneralImageModule().isPresent(0x0020,0x0020))
			{
				ConditionFailedException cce = new ConditionFailedException("0020,0020");
				if(DicomConfig.createInstance().isLoggingOn())
					DicomLogger.getLogger().log(cce.getMessage());
				throw cce;

			}

			/*
			 * Condition for Overlay Plane not understood. PDF 3, Pg. No. 140.
			 */
			if(isPresent(0x0008, 0x0068))
			{
				DXSeriesModule objDXSeriesModule = new DXSeriesModule(objIDataSet);
				String strValue = objDXSeriesModule.getPresentationIntentType();

				if(!strValue.trim().equalsIgnoreCase(EnumPresentationIntentType.FOR_PRESENTATION.getValue().trim()))
					throw new InvalidModuleException("VOILUT Module required if value for Presentation Intent Type(0008,0068) is FOR PRESENTATION");
			}

			/*
			 * This condition checks for Digital Intra Oral XRay Image IOD's User Optional modules validation
			 * For conditional modules, first the presence of the modules should be checked. Because
			 * absence of optional modules is not a problem whereas presence but invalid status of the
			 * optional module is a problem.
			 */
			if(isModulePresent(SpecimenIdentificationModule.objSingleCollection, objIDataSet))
				getSpecimenIdentificationModule().validateModule();
			
			if(isModulePresent(FrameOfReferenceModule.objSingleCollection, objIDataSet))
				getFrameOfReferenceModule().validateModule();
			
			if(isModulePresent(ContrastBolusModule.objSingleCollection, objIDataSet))
				getContrastBolusModule().validateModule();
			
			if(isModulePresent(DisplayShutterModule.objSingleCollection, objIDataSet))
				getDisplayShutterModule().validateModule();
			
			if(isModulePresent(DeviceModule.objSingleCollection, objIDataSet))
				getDeviceModule().validateModule();
			
			if(isModulePresent(InterventionModule.objSingleCollection, objIDataSet))
				getInterventionModule().validateModule();
		
			if(isModulePresent(XRayCollimatorModule.objSingleCollection, objIDataSet))
				getXRayCollimatorModule().validateModule();
			
			if(isModulePresent(DXPositioningModule.objSingleCollection, objIDataSet))
				getDXPositioningModule().validateModule();
		
			if(isModulePresent(XRayTomographyAcquisitionModule.objSingleCollection, objIDataSet))
				getXRayTomographyAcquisitionModule().validateModule();
			
			if(isModulePresent(XRayAcquisitionDoseModule.objSingleCollection, objIDataSet))
				getXRayAcquisitionDoseModule().validateModule();
			
			if(isModulePresent(XRayGenerationModule.objSingleCollection, objIDataSet))
				getXRayGenerationModule().validateModule();
			
			if(isModulePresent(XRayFiltrationModule.objSingleCollection, objIDataSet))
				getXRayFiltrationModule().validateModule();
			
			if(isModulePresent(XRayGridModule.objSingleCollection, objIDataSet))
				getXRayGridModule().validateModule();
			
			if(isModulePresent(ImageHistogramModule.objSingleCollection, objIDataSet))
				getImageHistogramModule().validateModule();
			
			if(isModulePresent(SpecimenModule.objSingleCollection, objIDataSet))
				getSpecimenModule().validateModule();
			
			if(isModulePresent(CommonInstanceReferenceModule.objSingleCollection, objIDataSet))
				getCommonInstanceReferenceModule().validateModule();
			
			// 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(DIGITAL_INTRA_ORAL_XRAY_IMAGE_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(DIGITAL_INTRA_ORAL_XRAY_IMAGE_IOD + "\n");
		super.dumpDICOMInfo(objIDicomStream);

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

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

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

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

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

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

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

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

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

		objIDicomStream.writeString("\t" + getDXSeriesModule().getClass().getSimpleName() + "\n");
		getDXSeriesModule().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" + getImageHistogramModule().getClass().getSimpleName() + "\n");
		getImageHistogramModule().dumpDICOMInfo(objIDicomStream);

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

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

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

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

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

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

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

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

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

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

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

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

		objIDicomStream.writeString("\t" + getXRayGridModule().getClass().getSimpleName() + "\n");
		getXRayGridModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getCommonInstanceReferenceModule().getClass().getSimpleName() + "\n");
		getCommonInstanceReferenceModule().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.CONTRAST_BOLUS_MODULE.getValue()) && isModulePresent(ContrastBolusModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.CURVE_MODULE.getValue()) && isModulePresent(CurveModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.DEVICE_MODULE.getValue()) && isModulePresent(DeviceModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.DISPLAY_SHUTTER_MODULE.getValue()) && isModulePresent(DisplayShutterModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.DX_DETECTOR_MODULE.getValue()) && isModulePresent(DXDetectorModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.GENERAL_IMAGE_MODULE.getValue()) && isModulePresent(GeneralImageModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.FRAME_OF_REFERENCE_MODULE.getValue()) && isModulePresent(FrameOfReferenceModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.INTERVENTION_MODULE.getValue()) && isModulePresent(InterventionModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.SOP_COMMON_MODULE.getValue()) && isModulePresent(SOPCommonModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.ACQUISITION_CONTEXT_MODULE.getValue()) && isModulePresent(AcquisitionContextModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.DX_SERIES_MODULE.getValue()) && isModulePresent(DXSeriesModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.DX_ANATOMY_IMAGED_MODULE.getValue()) && isModulePresent(DXAnatomyImagedModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.DX_IMAGE_MODULE.getValue()) && isModulePresent(DXImageModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.DX_POSITIONING_MODULE.getValue()) && isModulePresent(DXPositioningModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.IMAGE_HISTOGRAM_MODULE.getValue()) && isModulePresent(ImageHistogramModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.OVERLAY_PLANE_MODULE.getValue()) && isModulePresent(OverlayPlaneModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.SPECIMEN_IDENTIFICATION_MODULE.getValue()) && isModulePresent(SpecimenIdentificationModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.VOI_LUT_MODULE.getValue()) && isModulePresent(VOILUTModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.X_RAY_COLLIMATOR_MODULE.getValue()) && isModulePresent(XRayCollimatorModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.X_RAY_FILTRATION_MODULE.getValue()) && isModulePresent(XRayFiltrationModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.X_RAY_GENERATION_MODULE.getValue()) && isModulePresent(XRayGenerationModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.X_RAY_GRID_MODULE.getValue()) && isModulePresent(XRayGridModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.X_RAY_ACQUISITION_DOSE_MODULE.getValue()) && isModulePresent(XRayAcquisitionDoseModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.X_RAY_TOMOGRAPHY_ACQUISITION_MODULE.getValue()) && isModulePresent(XRayTomographyAcquisitionModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.INTRA_ORAL_IMAGE_MODULE.getValue()) && isModulePresent(IntraOralImageModule.objSingleCollection))
				return true;
			else if(strModuleName.equalsIgnoreCase(EnumModuleNames.INTRA_ORAL_SERIES_MODULE.getValue()) && isModulePresent(IntraOralSeriesModule.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;
	}
}
