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

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.CTSeriesModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.CardiacSynchronizationModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.EnhancedCTImageModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.EnhancedContrastBolusModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.FrameOfReferenceModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.ImageIOD;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.MultiFrameDimensionModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.MultiFrameFunctionalGroupsModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.RespiratorySynchronizationModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.SOPCommonModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.SoftcopyPresentationLUTModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.SpecimenIdentificationModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.SupplementalPaletteColorLookupTableModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.SynchronizationModule;
import cdac.medinfo.sdk.dcm30_04.enums.EnumCardiacSynchronizationTechnique;
import cdac.medinfo.sdk.dcm30_04.enums.EnumImageType;
import cdac.medinfo.sdk.dcm30_04.enums.EnumModuleNames;
import cdac.medinfo.sdk.dcm30_04.enums.EnumPixelPresentation;
import cdac.medinfo.sdk.dcm30_04.enums.EnumRespiratoryMotionCompensation;
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 Enhanced Computed Tomography (CT) Image Information Object Definition (IOD) specifies
 * an image that has been created by a computed tomography imaging device.
 * 
 */
public class EnhancedCTIOD extends ImageIOD 
{
	

	/**
	 * The Constant ENHANCED_CT_IOD.
	 */
	public static final String ENHANCED_CT_IOD = "Enhanced CT Image IOD";

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

	/**
	 * The obj cardiac synchronization module.
	 */
	CardiacSynchronizationModule objCardiacSynchronizationModule = null;

	/**
	 * The obj ct series module.
	 */
	CTSeriesModule objCTSeriesModule = null;

	/**
	 * The obj enhanced contrast bolus module.
	 */
	EnhancedContrastBolusModule objEnhancedContrastBolusModule = null;

	/**
	 * The obj enhanced ct image module.
	 */
	EnhancedCTImageModule objEnhancedCTImageModule = null;

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

	/**
	 * The obj multi frame dimension module.
	 */
	MultiFrameDimensionModule objMultiFrameDimensionModule = null;

	/**
	 * The obj multi frame functional groups module.
	 */
	MultiFrameFunctionalGroupsModule objMultiFrameFunctionalGroupsModule = null;

	/**
	 * The obj respiratory synchronization module.
	 */
	RespiratorySynchronizationModule objRespiratorySynchronizationModule = null;

	/**
	 * The obj softcopy presentation lut module.
	 */
	SoftcopyPresentationLUTModule objSoftcopyPresentationLUTModule = null;

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

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

	/**
	 * The obj supplemental palette color lookup table module.
	 */
	SupplementalPaletteColorLookupTableModule objSupplementalPaletteColorLookupTableModule = null;

	/**
	 * The obj synchronization module.
	 */
	SynchronizationModule objSynchronizationModule = null;

	/**
	 * Instantiates a new enhanced ctiod.
	 */
	public EnhancedCTIOD()
	{
		super();
	}

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

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

	/**
	 * Creates EnhancedCTIOD IOD from a DICOM file containing EnhancedCTIOD 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 EnhancedCTIOD(String strFileName)throws IOException,InvalidIODException
	{
		super(strFileName);
		try
		{
			if(objIDataSet != null)
			{
				String strSOPClassUID = objIDataSet.getSOPClassUID();
				if(strSOPClassUID != null)
				{
					if(!strSOPClassUID.equals(EnumSOPClassUIDs.ENHANCEDCTIOD.getValue()))
					{
						throw new InvalidIODException(ResourceBundleWrapper.getValue("exceptions", "InvalidIOD.FileNotMatched", new Locale(DicomConfig.createInstance().getLocale())) + ENHANCED_CT_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 Cardiac 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 CardiacSynchronizationModule - instance of {@link CardiacSynchronizationModule}.
	 */
	public CardiacSynchronizationModule getCardiacSynchronizationModule() 
	{
		if(objCardiacSynchronizationModule == null)
		{
			objCardiacSynchronizationModule = new CardiacSynchronizationModule(objIDataSet);
			return objCardiacSynchronizationModule;
		}
		return objCardiacSynchronizationModule;
	}

	/**
	 * Retrieves pre-initialized instance of Enhanced 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 EnhancedContrastBolusModule - instance of {@link EnhancedContrastBolusModule}.
	 */
	public EnhancedContrastBolusModule getEnhancedContrastBolusModule() 
	{
		if(objEnhancedContrastBolusModule == null)
		{
			objEnhancedContrastBolusModule = new EnhancedContrastBolusModule(objIDataSet);
			return objEnhancedContrastBolusModule;
		}
		return objEnhancedContrastBolusModule;
	}

	/**
	 * Retrieves pre-initialized instance of Enhanced CT 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 EnhancedCTImageModule - instance of {@link EnhancedCTImageModule}.
	 */
	public EnhancedCTImageModule getEnhancedCTImageModule() 
	{
		if(objEnhancedCTImageModule == null)
		{
			objEnhancedCTImageModule = new EnhancedCTImageModule(objIDataSet);
			return objEnhancedCTImageModule;
		}
		return objEnhancedCTImageModule;
	}

	/**
	 * 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 CT 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 CTSeriesModule - instance of {@link CTSeriesModule}.
	 */
	public CTSeriesModule getCTSeriesModule() 
	{
		if(objCTSeriesModule == null)
		{
			objCTSeriesModule = new CTSeriesModule(objIDataSet);
			return objCTSeriesModule;
		}
		return objCTSeriesModule;
	}

	/**
	 * Retrieves pre-initialized instance of Multi Frame Dimension 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 MultiFrameDimensionModule - instance of {@link MultiFrameDimensionModule}.
	 */
	public MultiFrameDimensionModule getMultiFrameDimensionModule() 
	{
		if(objMultiFrameDimensionModule == null)
		{
			objMultiFrameDimensionModule = new MultiFrameDimensionModule(objIDataSet);
			return objMultiFrameDimensionModule;
		}
		return objMultiFrameDimensionModule;
	}

	/**
	 * Retrieves pre-initialized instance of Multi Frame Functional Groups 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 MultiFrameFunctionalGroupsModule - instance of {@link MultiFrameFunctionalGroupsModule}.
	 */
	public MultiFrameFunctionalGroupsModule getMultiFrameFunctionalGroupsModule()
	{
		if(objMultiFrameFunctionalGroupsModule == null)
		{
			objMultiFrameFunctionalGroupsModule = new MultiFrameFunctionalGroupsModule(objIDataSet);
			return objMultiFrameFunctionalGroupsModule;
		}
		return objMultiFrameFunctionalGroupsModule;
	}

	/**
	 * Retrieves pre-initialized instance of Respiratory 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 RespiratorySynchronizationModule - instance of {@link RespiratorySynchronizationModule}.
	 */
	public RespiratorySynchronizationModule getRespiratorySynchronizationModule()
	{
		if(objRespiratorySynchronizationModule == null)
		{
			objRespiratorySynchronizationModule = new RespiratorySynchronizationModule(objIDataSet);
			return objRespiratorySynchronizationModule;
		}
		return objRespiratorySynchronizationModule;
	}

	/**
	 * Retrieves pre-initialized instance of Softcopy Presentation 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 SoftcopyPresentationLUTModule - instance of {@link SoftcopyPresentationLUTModule}.
	 */
	public SoftcopyPresentationLUTModule getSoftcopyPresentationLUTModule() 
	{
		if(objSoftcopyPresentationLUTModule == null)
		{
			objSoftcopyPresentationLUTModule = new SoftcopyPresentationLUTModule(objIDataSet);
			return objSoftcopyPresentationLUTModule;
		}
		return objSoftcopyPresentationLUTModule;
	}

	/**
	 * 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 Supplemental Palette Color Lookup Table 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 SupplementalPaletteColorLookupTableModule - instance of {@link SupplementalPaletteColorLookupTableModule}.
	 */
	public SupplementalPaletteColorLookupTableModule getSupplementalPaletteColorLookupTableModule() 
	{
		if(objSupplementalPaletteColorLookupTableModule == null)
		{
			objSupplementalPaletteColorLookupTableModule = new SupplementalPaletteColorLookupTableModule(objIDataSet);
			return objSupplementalPaletteColorLookupTableModule;
		}
		return objSupplementalPaletteColorLookupTableModule;
	}

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

	/**
	 * This method validates Enhanced CT 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
		{
			/*
			 * This condition checks for mandatory modules validation
			 */
			getGeneralEquipmentModule().validateModule();
			getCTSeriesModule().validateModule();
			getFrameOfReferenceModule().validateModule();
			getMultiFrameFunctionalGroupsModule().validateModule();
			getMultiFrameDimensionModule().validateModule();
			getAcquisitionContextModule().validateModule();
			getEnhancedCTImageModule().validateModule();
			getSoftcopyPresentationLUTModule().validateModule();
			getSOPCommonModule().validateModule();
			/*
			 * This condition checks for User Optional/Conditional 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();
			}

			/*
			 * Module level validation at IOD level for RespiratorySynchronizationModule and CardiacSynchronizationModule.
			 * Attirbutes in these modules depends upon ImageType and module containing ImageType and these modules are not always together in all IODs.
			 */
			String[] arrStrImageType = getEnhancedCTImageModule().getImageType();
			if(arrStrImageType != null)
			{
				CardiacSynchronizationModule objCardiacSynchronizationModule = getCardiacSynchronizationModule();
				String strCardiacSynchronizationTechnique = objCardiacSynchronizationModule.getCardiacSynchronizationTechnique();

				RespiratorySynchronizationModule objRespiratorySynchronizationModule = getRespiratorySynchronizationModule();
				String strRespiratoryMotionCompensationTechnique = objRespiratorySynchronizationModule.getRespiratoryMotionCompensationTechnique();
				//Validation for RespiratorySynchronizationModule
				if((EnumImageType.Value1.ORIGINAL.getValue().equalsIgnoreCase(arrStrImageType[0]))||(EnumImageType.Value1.MIXED.getValue().equalsIgnoreCase(arrStrImageType[0]))
						&& !objRespiratorySynchronizationModule.isPresent(0x0018,0x9170))
					throw new ConditionFailedException("element 0018,9170 should be present if Image Type(0008,0008) value is ORIGINAL or MIXED");
				else if((EnumImageType.Value1.ORIGINAL.getValue().equalsIgnoreCase(arrStrImageType[0]))||(EnumImageType.Value1.MIXED.getValue().equalsIgnoreCase(arrStrImageType[0]))||(EnumImageType.Value1.DERIVED.getValue().equalsIgnoreCase(arrStrImageType[0]))
						&& !EnumRespiratoryMotionCompensation.NONE.getValue().equalsIgnoreCase(strRespiratoryMotionCompensationTechnique) && !objRespiratorySynchronizationModule.isPresent(0x0018,0x9171))
					throw new ConditionFailedException("element 0018,9171 should be present if Image Type(0008,0008) value is ORIGINAL or MIXED or DERIVED and Respiratory Motion Compensation Technique(0018,9170) value is other than NONE");
				//Validation for CardiacSynchronizationModule
				//Cardiac Synchronization Technique, Required if Image Type (0008,0008) Value 1 is ORIGINAL or MIXED.
				else if(!((EnumImageType.Value1.ORIGINAL.getValue().equalsIgnoreCase(arrStrImageType[0])) || (EnumImageType.Value1.MIXED.getValue().equalsIgnoreCase(arrStrImageType[0]))) &&  !objCardiacSynchronizationModule.isPresent(0x0018, 0x9037))
					throw new ConditionFailedException("Cardiac Synchronization Technique (0018,9037) should be present if Image Type(0008,0008) is ORIGINAL or MIXED");
				//Required if Image Type (0008,0008) Value 1 is ORIGINAL or MIXED and Cardiac Synchronization Technique
				//(0018,9037) equals other than NONE.
				else if(objCardiacSynchronizationModule.isPresent(0x0018, 0x9037))
				{
					if(((EnumImageType.Value1.ORIGINAL.getValue().equalsIgnoreCase(arrStrImageType[0])) || (EnumImageType.Value1.MIXED.getValue().equalsIgnoreCase(arrStrImageType[0]))))
					{
						if(!EnumCardiacSynchronizationTechnique.NONE.getValue().equalsIgnoreCase(strCardiacSynchronizationTechnique))
						{
							if(!objCardiacSynchronizationModule.isPresent(0x0018, 0x9085))
								throw new ConditionFailedException("Cardiac Signal Source(0018,9085) should be present if Image Type(0008,0008) is ORIGINAL or MIXED or DERIVED and Cardiac Synchronization Technique value is other than NONE");
							else if(!objCardiacSynchronizationModule.isPresent(0x0018, 0x9070))
								throw new ConditionFailedException("Cardiac RR Interval Specified(0018,9070) should be present if Image Type(0008,0008) is ORIGINAL or MIXED or DERIVED and Cardiac Synchronization Technique value is other than NONE");
							else if(!objCardiacSynchronizationModule.isPresent(0x0018, 0x1083))
								throw new ConditionFailedException("Intervals Acquired(0018,1083) should be present if Image Type(0008,0008) is ORIGINAL or MIXED or DERIVED and Cardiac Synchronization Technique value is other than NONE");
							else if(!objCardiacSynchronizationModule.isPresent(0x0018, 0x1084))
								throw new ConditionFailedException("Intervals Rejected(0018,1084) should be present if Image Type(0008,0008) is ORIGINAL or MIXED or DERIVED and Cardiac Synchronization Technique value is other than NONE");
						}
						else if(EnumCardiacSynchronizationTechnique.PROSPECTIVE.getValue().equalsIgnoreCase(strCardiacSynchronizationTechnique) || EnumCardiacSynchronizationTechnique.RETROSPECTIVE.getValue().equalsIgnoreCase(strCardiacSynchronizationTechnique))
						{
							if(!objCardiacSynchronizationModule.isPresent(0x0018, 0x9169))
								throw new ConditionFailedException("Cardiac Beat Rejection Technique(0018,9169) should be present if Image Type(0008,0008) is ORIGINAL or MIXED or DERIVED and Cardiac Synchronization Technique value is equals PROSPECTIVE or RETROSPECTIVE.");
							else if(!objCardiacSynchronizationModule.isPresent(0x0018, 0x1081))
								throw new ConditionFailedException("Low R-R Value(0018,1081) should be present if Image Type(0008,0008) is ORIGINAL or MIXED or DERIVED and Cardiac Synchronization Technique value is equals PROSPECTIVE or RETROSPECTIVE.");
							else if(!objCardiacSynchronizationModule.isPresent(0x0018, 0x1082))
								throw new ConditionFailedException("High R-R Value(0018,1082) should be present if Image Type(0008,0008) is ORIGINAL or MIXED or DERIVED and Cardiac Synchronization Technique value is equals PROSPECTIVE or RETROSPECTIVE.");
						}
					}
				}
			}

			/*
			 * Conditions for following modules not understood. PDF 3, Pg. No. 182.
			 * Synchronization,
			 * Enhanced Contrast/Bolus,
			 * Cardiac Synchronization,
			 * Respiratory Synchronization,
			 * Bulk Motion Synchronization
			 */
			if(isModulePresent(SupplementalPaletteColorLookupTableModule.objSingleCollection,objIDataSet))
			{
				String strPixelPresentation = getEnhancedCTImageModule().getCommonCTOrMRImageDescriptionMacro().getPixelPresentation();
				if(!strPixelPresentation.equalsIgnoreCase(EnumPixelPresentation.COLOR.getValue()) || !strPixelPresentation.equalsIgnoreCase(EnumPixelPresentation.MIXED.getValue()))
					throw new InvalidIODException("Supplemental Palette Color Lookup Table Module should be present if Pixel Representation(0008,9205) is COLOR or MIXED");
			}

			// 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(ENHANCED_CT_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(ENHANCED_CT_IOD+ "\n");
	super.dumpDICOMInfo(objIDicomStream);

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

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

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

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

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

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

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

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

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

	objIDicomStream.writeString("\t" + getSynchronizationModule().getClass().getSimpleName() + "\n");
	getSynchronizationModule().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.ACQUISITION_CONTEXT_MODULE.getValue()) && isModulePresent(AcquisitionContextModule.objSingleCollection))
			return true;
		else if(strModuleName.equalsIgnoreCase(EnumModuleNames.CARDIAC_SYNCHRONIZATION_MODULE.getValue()) && isModulePresent(CardiacSynchronizationModule.objSingleCollection))
			return true;
		else if(strModuleName.equalsIgnoreCase(EnumModuleNames.CT_SERIES_MODULE.getValue()) && isModulePresent(CTSeriesModule.objSingleCollection))
			return true;
		else if(strModuleName.equalsIgnoreCase(EnumModuleNames.ENHANCED_CONTRAST_BOLUS_MODULE.getValue()) && isModulePresent(EnhancedContrastBolusModule.objSingleCollection))
			return true;
		else if(strModuleName.equalsIgnoreCase(EnumModuleNames.ENHANCED_CT_IMAGE_MODULE.getValue()) && isModulePresent(EnhancedCTImageModule.objSingleCollection))
			return true;
		else if(strModuleName.equalsIgnoreCase(EnumModuleNames.FRAME_OF_REFERENCE_MODULE.getValue()) && isModulePresent(FrameOfReferenceModule.objSingleCollection))
			return true;
		else if(strModuleName.equalsIgnoreCase(EnumModuleNames.MULTI_FRAME_DIMENSION_MODULE.getValue()) && isModulePresent(MultiFrameDimensionModule.objSingleCollection))
			return true;
		else if(strModuleName.equalsIgnoreCase(EnumModuleNames.MULTI_FRAME_FUNCTIONAL_GROUPS_MODULE.getValue()) && isModulePresent(MultiFrameFunctionalGroupsModule.objSingleCollection))
			return true;
		else if(strModuleName.equalsIgnoreCase(EnumModuleNames.RESPIRATORY_SYNCHRONIZATION_MODULE.getValue()) && isModulePresent(RespiratorySynchronizationModule.objSingleCollection))
			return true;
		else if(strModuleName.equalsIgnoreCase(EnumModuleNames.SOFTCOPY_PRESENTATION_LUT_MODULE.getValue()) && isModulePresent(SoftcopyPresentationLUTModule.objSingleCollection))
			return true;
		else if(strModuleName.equalsIgnoreCase(EnumModuleNames.SOP_COMMON_MODULE.getValue()) && isModulePresent(SOPCommonModule.objSingleCollection))
			return true;
		else if(strModuleName.equalsIgnoreCase(EnumModuleNames.SPECIMEN_IDENTIFICATION_MODULE.getValue()) && isModulePresent(SpecimenIdentificationModule.objSingleCollection))
			return true;
		else if(strModuleName.equalsIgnoreCase(EnumModuleNames.SUPPLEMENTAL_PALETTE_COLOR_LOOKUP_TABLE_MODULE.getValue()) && isModulePresent(SupplementalPaletteColorLookupTableModule.objSingleCollection))
			return true;
		else if(strModuleName.equalsIgnoreCase(EnumModuleNames.SYNCHRONIZATION_MODULE.getValue()) && isModulePresent(SynchronizationModule.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;
}
}
