/*******************************************************************************
 *  Copyright 2017-2018 Centre for Development of Advanced Computing(C-DAC), Pune
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *   http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package cdac.medinfo.sdk.dcm30_04.dicommodel.rt;

import java.io.IOException;
import java.util.Locale;

import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDicomStream;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDictionaryReader;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITransferSyntax;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.ApprovalModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.ClinicalTrialSeriesModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.ClinicalTrialStudyModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.CommonInstanceReferenceModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.FrameOfReferenceModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.GeneralEquipmentModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.GeneralStudyModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.NormalizedIOD;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.PatientModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.PatientStudyModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.RTFractionSchemeModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.RTGeneralPlanModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.RTIonBeamsModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.RTIonToleranceTablesModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.RTPatientSetupModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.RTPrescriptionModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.RTSeriesModule;
import cdac.medinfo.sdk.dcm30_04.dicommodel.modules.SOPCommonModule;
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 focus for this Radiotherapy Ion Plan IOD (RT Ion Plan IOD) is to address the requirements for transfer of treatment plans generatedby manual entry, a virtual simulation system, or a treatment planning system before or during a course of Ion therapy treatment.
 * @author saloni
 *
 */
public class RTIonPlanIOD extends NormalizedIOD{
	
	public static final String  RT_ION_PLAN_IOD = "RT Ion Plan IOD";
	
	/**
	 * Patient Module
	 */
	PatientModule objPatientModule = null;
	
	/**
	 * Clinical Trial Subject
	 */
	ClinicalTrialSeriesModule objClinicalTrialSeriesModule = null;
	
	/**
	 * General Study
	 */
	GeneralStudyModule objGeneralStudyModule = null;
	
	/**
	 * Patient Study
	 */
	PatientStudyModule objPatientStudyModule = null;
	
	/**
	 * Clinical Trial Study
	 */
	ClinicalTrialStudyModule objClinicalTrialStudyModule = null;
	
	/**
	 * RT Series
	 */
	RTSeriesModule objRTSeriesModule = null;
	
	/**
	 * Frame of Reference
	 */
	FrameOfReferenceModule objFrameOfReferenceModule = null;
	
	/**
	 * General Equipment
	 */
	GeneralEquipmentModule objGeneralEquipmentModule = null;
	
	/**
	 * RT General Plan
	 */
	RTGeneralPlanModule objRTGeneralPlanModule = null;
	
	/**
	 * RT Prescription
	 */
	RTPrescriptionModule objRTPrescriptionModule = null;
	
	/**
	 * RT Ion Tolerance Tables
	 */
	RTIonToleranceTablesModule objRTIonToleranceTablesModule = null;
	
	/**
	 * RT Patient Setup
	 */
	RTPatientSetupModule objRTPatientSetupModule = null;
	
	/**
	 * RT Fraction Scheme
	 */
	RTFractionSchemeModule objRTFractionSchemeModule = null;
	
	/**
	 * RT Ion Beams
	 */
	RTIonBeamsModule objRTIonBeamsModule = null;
	
	/**
	 * Approval 
	 */
	ApprovalModule objApprovalModule = null;
	
	/**
	 * SOP Common 
	 */
	SOPCommonModule objSOPCommonModule = null;
	
	/**
	 * Common Instance Reference
	 */
	CommonInstanceReferenceModule objCommonInstanceReferenceModule = null;
	

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

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

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

	/**
	 * Creates XAImageIOD 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 RTIonPlanIOD(String strFileName)throws IOException,InvalidIODException
	{
		super(strFileName);
		try
		{
			if(objIDataSet != null)
			{
				String strSOPClassUID = objIDataSet.getSOPClassUID();
				if(strSOPClassUID != null)
				{
					if(!strSOPClassUID.equals(EnumSOPClassUIDs.RTIonPlanIOD.getValue()))
					{
						throw new InvalidIODException(ResourceBundleWrapper.getValue("exceptions", "InvalidIOD.FileNotMatched", new Locale(DicomConfig.createInstance().getLocale())) + RT_ION_PLAN_IOD);
					}
				}
				strSOPClassUID = null;
			}
		}
		catch(InvalidIODException iie)
		{
			if(DicomConfig.createInstance().isLoggingOn())
			{
				DicomLogger.getLogger().log(iie.getMessage());
			}
			throw iie;
		}
	}
	
	/**
	 * Retrieves pre-initialized instance of PatientModule. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return PatientModule - instance of {@link PatientModule}.
	 */
	public PatientModule getPatientModule() 
	{
		if(objPatientModule == null)
		{
			objPatientModule = new PatientModule(objIDataSet);
			return objPatientModule;
		}
		return objPatientModule;
	}
	/**
	 * Retrieves pre-initialized instance of ClinicalTrialSeriesModule. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return ClinicalTrialSeriesModule - instance of {@link ClinicalTrialSeriesModule}.
	 */
	public ClinicalTrialSeriesModule getClinicalTrialSeriesModule() 
	{
		if(objClinicalTrialSeriesModule == null)
		{
			objClinicalTrialSeriesModule = new ClinicalTrialSeriesModule(objIDataSet);
			return objClinicalTrialSeriesModule;
		}
		return objClinicalTrialSeriesModule;
	}

	/**
	 * Retrieves pre-initialized instance of GeneralStudyModule. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return GeneralStudyModule - instance of {@link GeneralStudyModule}.
	 */
	public GeneralStudyModule getGeneralStudyModule() 
	{
		if(objGeneralStudyModule == null)
		{
			objGeneralStudyModule = new GeneralStudyModule(objIDataSet);
			return objGeneralStudyModule;
		}
		return objGeneralStudyModule;
	}
	/**
	 * Retrieves pre-initialized instance of PatientStudyModule. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return PatientStudyModule - instance of {@link PatientStudyModule}.
	 */
	public PatientStudyModule getPatientStudyModule() 
	{
		if(objPatientStudyModule == null)
		{
			objPatientStudyModule = new PatientStudyModule(objIDataSet);
			return objPatientStudyModule;
		}
		return objPatientStudyModule;
	}
	/**
	 * This method returns the ClinicalTrialStudyModule with preinitializing it.
	 * 
	 * @return the clinical trial study module
	 */
	public ClinicalTrialStudyModule getClinicalTrialStudyModule()
	{
		if(objClinicalTrialStudyModule == null)
		{
			objClinicalTrialStudyModule = new ClinicalTrialStudyModule(objIDataSet);
			return objClinicalTrialStudyModule;
		}
		return objClinicalTrialStudyModule;
	}
	/**
	 * Retrieves pre-initialized instance of RT Series Module. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return - instance of {@link RTSeriesModule}.
	 */
	public RTSeriesModule getRTSeriesModule() {
		if(objRTSeriesModule == null)
		{
			objRTSeriesModule = new RTSeriesModule(objIDataSet);
			return objRTSeriesModule;
		}
		return objRTSeriesModule;
	}
	/**
	 * 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 GeneralEquipmentModule. Creates a new instance
	 * if no pre-existing module instance is available.If previously created instance is
	 * present then returns the same module instance.
	 * 
	 * @return GeneralEquipmentModule - instance of {@link GeneralEquipmentModule}.
	 */
	public GeneralEquipmentModule getGeneralEquipmentModule() 
	{
		if(objGeneralEquipmentModule == null)
		{
			objGeneralEquipmentModule = new GeneralEquipmentModule(objIDataSet);
			return objGeneralEquipmentModule;
		}
		return objGeneralEquipmentModule;
	}

	
	
	/**
	 * Retrieves pre-initialized instance of GeneralEquipmentModule. 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 RTGeneralPlanModule - instance of {@link RTGeneralPlanModule}.
	 */
	public RTGeneralPlanModule getRTGeneralPlanModule() 
	{
		if(objRTGeneralPlanModule == null)
		{
			objRTGeneralPlanModule = new RTGeneralPlanModule(objIDataSet);
			return objRTGeneralPlanModule;
		}
		return objRTGeneralPlanModule;
	}
	/**
	 * Retrieves pre-initialized instance of RT Prescription 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 RTPrescriptionModule - instance of {@link RTPrescriptionModule}.
	 */
	public RTPrescriptionModule getRTPrescriptionModule() 
	{
		if(objRTPrescriptionModule  == null)
		{
			objRTPrescriptionModule  = new RTPrescriptionModule(objIDataSet);
			return objRTPrescriptionModule ;
		}
		return objRTPrescriptionModule ;
	}
	
	
	/**
	 * Retrieves pre-initialized instance of RT Ion Tolerance Tables 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 RTIonToleranceTablesModule - instance of {@link RTIonToleranceTablesModule}.
	 */
	public RTIonToleranceTablesModule getRTIonToleranceTablesModule() 
	{
		if(objRTIonToleranceTablesModule  == null)
		{
			objRTIonToleranceTablesModule  = new RTIonToleranceTablesModule(objIDataSet);
			return objRTIonToleranceTablesModule ;
		}
		return objRTIonToleranceTablesModule ;
	}
	
	/**
	 * Retrieves pre-initialized instance of RT Patient Setup 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 RTPatientSetupModule}.
	 */
	public RTPatientSetupModule getRTPatientSetupModule() {
		if(objRTPatientSetupModule == null)
		{
			objRTPatientSetupModule = new RTPatientSetupModule(objIDataSet);
			return objRTPatientSetupModule;
		}
		return objRTPatientSetupModule;
	}
	/**
	 * Retrieves pre-initialized instance of RT Fraction Scheme 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 RTFractionSchemeModule - instance of {@link RTFractionSchemeModule}.
	 */
	public RTFractionSchemeModule getRTFractionSchemeModule() 
	{
		if(objRTFractionSchemeModule == null)
		{
			objRTFractionSchemeModule  = new RTFractionSchemeModule(objIDataSet);
			return objRTFractionSchemeModule ;
		}
		return objRTFractionSchemeModule ;
	}
	
	/**
	 * Retrieves pre-initialized instance of RT Ion Beams 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 RTIonBeamsModule - instance of {@link RTIonBeamsModule}.
	 */
	public RTIonBeamsModule getRTIonBeamsModule() 
	{
		if(objRTIonBeamsModule == null)
		{
			objRTIonBeamsModule  = new RTIonBeamsModule(objIDataSet);
			return objRTIonBeamsModule ;
		}
		return objRTIonBeamsModule ;
	}
	
	/**
	 * Retrieves pre-initialized instance of Approval 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 ApprovalModule - instance of {@link ApprovalModule}.
	 */
	public ApprovalModule getApprovalModule() 
	{
		if(objApprovalModule == null)
		{
			objApprovalModule = new ApprovalModule(objIDataSet);
			return objApprovalModule;
		}
		return objApprovalModule;
	}
	/**
	 * 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 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 CommonInstanceReferenceModule - instance of {@link CommonInstanceReferenceModule}.
	 */
	public CommonInstanceReferenceModule getCommonInstanceReferenceModule()
	{
		if(objCommonInstanceReferenceModule == null)
		{
			objCommonInstanceReferenceModule = new CommonInstanceReferenceModule(objIDataSet);
			return objCommonInstanceReferenceModule;
		}
		return objCommonInstanceReferenceModule;
	}
	
	/**
	 * This method validates Digital XRay 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 - function status indicating success or failure
	 * 
	 * @throws InvalidIODException - throws when the IOD is invalid
	 */
	public boolean validate() throws InvalidIODException
	{
		try{
			/*
			 * This condition calls ImageIOD class's validation which checks for common modules validation
			 */
			if(super.validate())	
				return false;

			getGeneralEquipmentModule().validateModule();
			getGeneralStudyModule().validateModule();
			getSOPCommonModule().validateModule();
			getRTSeriesModule().validateModule();
			getFrameOfReferenceModule().validateModule();
			getGeneralEquipmentModule().validateModule();
		    getRTGeneralPlanModule().validateModule();
		    getSOPCommonModule().validateModule();
			/*
			 * This condition checks for Digital XRay 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(ClinicalTrialStudyModule.objSingleCollection, objIDataSet))
				getClinicalTrialStudyModule().validateModule();
			if(isModulePresent(PatientStudyModule.objSingleCollection, objIDataSet))
				getPatientStudyModule().validateModule();
			if(isModulePresent(ClinicalTrialStudyModule.objSingleCollection, objIDataSet))
				getClinicalTrialStudyModule().validateModule();
			
			if(isModulePresent(ClinicalTrialSeriesModule.objSingleCollection, objIDataSet))
				getClinicalTrialSeriesModule().validateModule();
			
			if(isModulePresent(RTPrescriptionModule.objSingleCollection, objIDataSet))
				getRTPrescriptionModule().validateModule();
			
			if(isModulePresent(RTIonToleranceTablesModule.objSingleCollection, objIDataSet))
				getRTIonToleranceTablesModule().validateModule();
			
			if(isModulePresent(RTPatientSetupModule.objSingleCollection, objIDataSet))
				getRTPatientSetupModule().validateModule();
			
			if(isModulePresent(RTFractionSchemeModule.objSingleCollection, objIDataSet))
				getRTFractionSchemeModule().validateModule();
			
			if(isModulePresent(ApprovalModule.objSingleCollection, objIDataSet))
				getApprovalModule().validateModule();
			
			if(isModulePresent(CommonInstanceReferenceModule.objSingleCollection, objIDataSet))
				getCommonInstanceReferenceModule().validateModule();
			
		
		}catch(InvalidModuleException ime)
		{
			if(DicomConfig.createInstance().isLoggingOn())
				DicomLogger.getLogger().log(ime.getMessage());
			
				throw new InvalidIODException(RT_ION_PLAN_IOD, ime);
		}
		return true;
	}
	
	/**
	 *  Dumps the Name of IOD,Module and corresponding Attributs of Module.
	 *  @param objIDicomStream - the Stream on which the Data is to be written.
	 *  @throws IOException - Exception is thrown indicating runtime failure of writing operation.
	 */
	public void dumpDICOMInfo(IDicomStream objIDicomStream) throws IOException
	{
		objIDicomStream.writeString(RT_ION_PLAN_IOD + "\n");
		super.dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getPatientModule().getClass().getSimpleName() + "\n");
		getPatientModule().dumpDICOMInfo(objIDicomStream);

		objIDicomStream.writeString("\t" + getClinicalTrialSeriesModule().getClass().getSimpleName() + "\n");
		getClinicalTrialSeriesModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getGeneralStudyModule().getClass().getSimpleName() + "\n");
		getGeneralStudyModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getPatientStudyModule().getClass().getSimpleName() + "\n");
		getPatientStudyModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getClinicalTrialStudyModule().getClass().getSimpleName() + "\n");
		getClinicalTrialStudyModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getRTSeriesModule().getClass().getSimpleName() + "\n");
		getRTSeriesModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getFrameOfReferenceModule().getClass().getSimpleName() + "\n");
		getFrameOfReferenceModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getGeneralEquipmentModule().getClass().getSimpleName() + "\n");
		getGeneralEquipmentModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getRTGeneralPlanModule().getClass().getSimpleName() + "\n");
		getRTGeneralPlanModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getRTPrescriptionModule().getClass().getSimpleName() + "\n");
		getRTPrescriptionModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getRTIonToleranceTablesModule().getClass().getSimpleName() + "\n");
		getRTIonToleranceTablesModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getRTPatientSetupModule().getClass().getSimpleName() + "\n");
		getRTPatientSetupModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getRTIonBeamsModule().getClass().getSimpleName() + "\n");
		getRTFractionSchemeModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getApprovalModule().getClass().getSimpleName() + "\n");
		getApprovalModule().dumpDICOMInfo(objIDicomStream);
		
		objIDicomStream.writeString("\t" + getSOPCommonModule().getClass().getSimpleName() + "\n");
		getSOPCommonModule().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.PATIENT_MODULE.getValue()) && isModulePresent(PatientModule.objSingleCollection))
				return true;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.CLINICAL_TRIAL_SERIES_MODULE.getValue()) && isModulePresent(ClinicalTrialSeriesModule.objSingleCollection))
				return true;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.RT_SERIES_MODULE.getValue()) && isModulePresent(RTSeriesModule.objSingleCollection))
				return true;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.PATIENT_STUDY_MODULE.getValue()) && isModulePresent(PatientStudyModule.objSingleCollection))
				return true;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.CLINICAL_TRIAL_STUDY_MODULE.getValue()) && isModulePresent(ClinicalTrialStudyModule.objSingleCollection))
				return true;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.FRAME_OF_REFERENCE_MODULE.getValue()) && isModulePresent(FrameOfReferenceModule.objSingleCollection))
				return true;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.GENERAL_EQUIPMENT_MODULE.getValue()) && isModulePresent(GeneralEquipmentModule.objSingleCollection))
				return true;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.RT_GENERAL_PLAN_MODULE.getValue()) && isModulePresent(RTGeneralPlanModule.objSingleCollection))
				return true;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.GENERAL_STUDY_MODULE.getValue()) && isModulePresent(GeneralStudyModule.objSingleCollection))
				return true;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.RT_PRESCRIPTION_MODULE.getValue()) && isModulePresent(RTPrescriptionModule.objSingleCollection))
				return true;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.RT_ION_TOLERANCE_TABLES_MODULE.getValue()) && isModulePresent(RTIonToleranceTablesModule.objSingleCollection))
				return true;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.RT_PATIENT_SETUP_MODULE.getValue()) && isModulePresent(RTPatientSetupModule.objSingleCollection))
				return true;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.RT_FRACTION_SCHEME_MODULE.getValue()) && isModulePresent(RTFractionSchemeModule.objSingleCollection))
				return true;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.RT_ION_BEAMS_MODULE.getValue()) && isModulePresent(RTIonBeamsModule.objSingleCollection))
				return true;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.APPROVAL_MODULE.getValue()) && isModulePresent(ApprovalModule.objSingleCollection))
				return true;
			if(strModuleName.equalsIgnoreCase(EnumModuleNames.SOP_COMMON_MODULE.getValue()) && isModulePresent(SOPCommonModule.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;
	}

	
	
	
}
