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

import cdac.medinfo.sdk.dcm30_04.baselibs.AdministrationRouteCodeSequence;
import cdac.medinfo.sdk.dcm30_04.baselibs.DicomV3Factory;
import cdac.medinfo.sdk.dcm30_04.baselibs.IssuerOfAdmissionIDSequence;
import cdac.medinfo.sdk.dcm30_04.baselibs.IssuerofPatientIDMacro;
import cdac.medinfo.sdk.dcm30_04.baselibs.OperatorIdentificationSequence;
import cdac.medinfo.sdk.dcm30_04.baselibs.SubstanceAdministrationParameterSequence;
import cdac.medinfo.sdk.dcm30_04.baselibs.Tag;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITag;

import cdac.medinfo.sdk.dcm30_04.exceptions.InvalidModuleException;
import cdac.medinfo.sdk.dcm30_04.exceptions.MandatoryMissingException;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConfig;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConstants;
import cdac.medinfo.sdk.dcm30_04.utils.DicomLogger;
import cdac.medinfo.sdk.dcm30_04.utils.ISingleCollection;
import cdac.medinfo.sdk.dcm30_04.utils.SingleCollection;

//TODO: Auto-generated Javadoc
/**
\* This module specifies the Attributes that describe Substance Administration Log  Module.
*/
public class SubstanceAdministrationLogModule extends Module
{
	/**
	 * The obj single collection.
	 */
	public static ISingleCollection<ITag> objSingleCollection = null;
	/**
	 * Instantiates a new SubstanceAdministrationLogModule
	 * 
	 * @param objIDataSet the obj i data set
	 */
	
	IssuerofPatientIDMacro objIssuerofPatientIDMacro=null;
	public SubstanceAdministrationLogModule(IDataSet objIDataSet)
	{
		super(objIDataSet);
	}

	static
	{
		objSingleCollection = new SingleCollection<ITag>();
		objSingleCollection.add(new Tag(0x0010, 0x0010));
		objSingleCollection.add(new Tag(0x0010, 0x0020));
		objSingleCollection.add(new Tag(0x0038, 0x0010));
		objSingleCollection.add(new Tag(0x0044, 0x0001));
		objSingleCollection.add(new Tag(0x0044, 0x0008));
		objSingleCollection.add(new Tag(0x0044, 0x0009));
		objSingleCollection.add(new Tag(0x0044, 0x0010));
		objSingleCollection.add(new Tag(0x0044, 0x0011));
		objSingleCollection.add(new Tag(0x0044, 0x0012));
		objSingleCollection.add(new Tag(0x0054, 0x0302));
		objSingleCollection.add(new Tag(0x0044, 0x0019));
		objSingleCollection.add(new Tag(0x0008, 0x1072));
		objSingleCollection.add(new Tag(0x0038, 0x0014));


	}
	public boolean validateModule() throws InvalidModuleException 
	{

		try
		{

		}
		catch(MandatoryMissingException mme)
		{
			if(DicomConfig.createInstance().isLoggingOn())
				DicomLogger.getLogger().log(mme.getMessage());

			
				throw new InvalidModuleException(this.getClass().getSimpleName(),mme);

		}
		return true;
	}
	/**
	 * Sets Patient Name.
	 * @param strPatientName String Patient Name.
	 */	
	public void setPatientName(String strPatientName)
	{
		/*Accept Patient Name in String format of type PN.
		 * Read the Transfer Syntax and check to create ImplicitDE or ExplicitDE .
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Hash Map
		 */
		addDataElement(0x0010, 0x0010, DicomConstants.DCM_DT_PN,strPatientName);
	}

	/**
	 * Retrieves Patient Name
	 * @return String - PatientName.
	 */
	public String getPatientName()
	{
		Object objValue = getValue(0x0010,0x0010);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	/**
	 * Sets Patient ID
	 * @param strPatientID String value of Patient ID
	 */
	public void setPatientID(String strPatientID)
	{
		/* Accept the Patient ID in String format of type LO.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		addDataElement(0x0010, 0x0020, DicomConstants.DCM_DT_LO,strPatientID);
	}

	/**
	 * Return Patient ID
	 * @return String - value of Patient ID
	 */
	public String getPatientID()
	{
		Object objValue = getValue(0x0010,0x0020);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Get the Instance of Issuer of Patient ID Macro.Calling this method multiple times will return the same Marco instance that was created at first. Hence, any attributes in this Macro,if set multiple times will contain the value that was set in the last call to its setter method.
	 * @return - object of Issuer of Patient ID Macro which the user programmer can populate
	 */
	public IssuerofPatientIDMacro getIssuerofPatientIDMacro()
	{
		if(objIssuerofPatientIDMacro == null)
			objIssuerofPatientIDMacro = new IssuerofPatientIDMacro(objIDataSet);
		return objIssuerofPatientIDMacro; 
	}
	/**
	 * Sets Admission ID
	 * @param strAdmissionID String value of Admission ID
	 */
	public void setAdmissionID(String strAdmissionID)
	{
		/* Accept the Admission ID in String format of type LO.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		addDataElement(0x0038, 0x0010, DicomConstants.DCM_DT_LO,strAdmissionID);
	}

	/**
	 * Return Admission ID
	 * @return String - value of Admission ID
	 */
	public String getAdmissionID()
	{
		Object objValue = getValue(0x0038,0x0010);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets the Identifier of the contrast agent, drug, or device administered, typically from a package bar code, RFID, or other materials managementID. This ID might not be globally unique and might conflict with otherIDs used within the scope of the institution.
	 * @param strProductPackageIdentifier 
	 */
	public void setProductPackageIdentifier(String strProductPackageIdentifier)
	{
		/*Accept the Coding Scheme Name in String format of type ST.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		addDataElement(0x0044, 0x0001, DicomConstants.DCM_DT_ST,strProductPackageIdentifier);
	}

	/**
	 * Retrieves Identifier of the contrast agent, drug, or device administered, typically from a package bar code, RFID, or other materials managementID. This ID might not be globally unique and might conflict with otherIDs used within the scope of the institution.
	 * @return String value of ProductPackageIdentifier
	 */
	public String getProductPackageIdentifier()
	{
		Object objValue = getValue(0x0044, 0x0001);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Product Name
	 * @param strArrProductName String value of Product Name
	 */
	public void setProductName(String[] strArrProductName)
	{
		/* Accept the Product Name in String format of type LO.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		addDataElement(0x0044, 0x0008, DicomConstants.DCM_DT_LO,strArrProductName);
	}

	/**
	 * Return Product Name
	 * @return String - value of Product Name
	 */
	public String[] getProductName()
	{
		Object objValue = getValue(0x0044, 0x0008);
		if(objValue != null)
			return (String[])objValue;
		return null;
	}
	
	/**
	 * Sets the Text description of the contrast agent, drug, or device administered.
	 * @param strProductDescription String value of text description of the contrast agent, drug, or device administered.
	 */
	public void setProductDescription(String strProductDescription)
	{
		/* Accept ProductDescription of type LT.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		addDataElement(0x0044, 0x0009, DicomConstants.DCM_DT_LT,strProductDescription);
	}

	/**
	 * Retrieves text description of the contrast agent, drug, or device administered.
	 * @return String - value of text description of the contrast agent, drug, or device administered.
	 */
	public String getProductDescription()
	{
		Object objValue = getValue(0x0044, 0x0009);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets the Substance Administration Date Time
	 * @param strSubstanceAdministrationDateTime String value of Substance Administration Date Time
	 */
	public void setSubstanceAdministrationDateTime(String strSubstanceAdministrationDateTime)
	{
		/* Accept Substance Administration Date Time of type LT.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		addDataElement(0x0044, 0x0010, DicomConstants.DCM_DT_DT,strSubstanceAdministrationDateTime);
	}

	/**
	 * Retrieves Substance Administration Date Time
	 * @return String - value of Substance Administration Date Time
	 */
	public String getSubstanceAdministrationDateTime()
	{
		Object objValue = getValue(0x0044, 0x0010);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets the Substance Administration Notes
	 * @param strSubstanceAdministrationNotes String value of Substance Administration Notes
	 */
	public void setSubstanceAdministrationNotes(String strSubstanceAdministrationNotes)
	{
		/* Accept Substance Administration Notes of type LT.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		addDataElement(0x0044, 0x0011, DicomConstants.DCM_DT_LO,strSubstanceAdministrationNotes);
	}

	/**
	 * Retrieves Substance Administration Notes
	 * @return String - value of Substance Administration Notes
	 */
	public String getSubstanceAdministrationNotes()
	{
		Object objValue = getValue(0x0044, 0x0011);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets the Substance Administration Device ID
	 * @param strSubstanceAdministrationDeviceID String value of Substance Administration Device ID
	 */
	public void setSubstanceAdministrationDeviceID(String strSubstanceAdministrationDeviceID)
	{
		/* Accept Substance Administration Notes of type LT.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Data Set
		 */
		addDataElement(0x0044, 0x0012, DicomConstants.DCM_DT_LO,strSubstanceAdministrationDeviceID);
	}

	/**
	 * Retrieves Substance Administration Device ID
	 * @return String - value of Substance Administration Device ID
	 */
	public String getSubstanceAdministrationDeviceID()
	{
		Object objValue = getValue(0x0044, 0x0012);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	/**
	 * Retrieves pre-initialized object of AdministrationRouteCodeSequence. If the module contains the sequence object
	 * it returns the same otherwise it creates the sequence adds to the module with proper initialization
	 * and then returns the object of sequence
	 * 
	 * @return AdministrationRouteCodeSequence 
	 */
	public AdministrationRouteCodeSequence getAdministrationRouteCodeSequence()
	{
		AdministrationRouteCodeSequence objAdministrationRouteCodeSequence= (AdministrationRouteCodeSequence)getDicomValue(0x0054, 0x0302);
		if(objAdministrationRouteCodeSequence == null)
		{
			/*
			 * If the sequence object is not present in the DataSet, a new sequence object is created and
			 * the TransferSyntax and DictionaryReader is set into it as it is set in the Module. This ensures that 
			 * the DataElements getting added in the DataSet follow the same TransferSyntax and use the same
			 * DictionaryReader object as that of the module.
			 */
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			objAdministrationRouteCodeSequence = (AdministrationRouteCodeSequence)objDicomV3Factory.createSequence(0x0054, 0x0302, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x0054, 0x0302, DicomConstants.DCM_DT_SQ, objAdministrationRouteCodeSequence.getValue());
		}
		return objAdministrationRouteCodeSequence;
	}
	/**
	 * Retrieves pre-initialized object of SubstanceAdministrationParameterSequence. If the module contains the sequence object
	 * it returns the same otherwise it creates the sequence adds to the module with proper initialization
	 * and then returns the object of sequence
	 * 
	 * @return SubstanceAdministrationParameterSequence 
	 */
	public SubstanceAdministrationParameterSequence getSubstanceAdministrationParameterSequence()
	{
		SubstanceAdministrationParameterSequence objSubstanceAdministrationParameterSequence= (SubstanceAdministrationParameterSequence)getDicomValue(0x0044, 0x0019);
		if(objSubstanceAdministrationParameterSequence == null)
		{
			/*
			 * If the sequence object is not present in the DataSet, a new sequence object is created and
			 * the TransferSyntax and DictionaryReader is set into it as it is set in the Module. This ensures that 
			 * the DataElements getting added in the DataSet follow the same TransferSyntax and use the same
			 * DictionaryReader object as that of the module.
			 */
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			objSubstanceAdministrationParameterSequence = (SubstanceAdministrationParameterSequence)objDicomV3Factory.createSequence(0x0044, 0x0019, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x0044, 0x0019, DicomConstants.DCM_DT_SQ, objSubstanceAdministrationParameterSequence.getValue());
		}
		return objSubstanceAdministrationParameterSequence;
	}
	
	/**
	 * Retrieves pre-initialized object of OperatorIdentificationSequence. If the module contains the sequence object
	 * it returns the same otherwise it creates the sequence adds to the module with proper initialization
	 * and then returns the object of sequence
	 * 
	 * @return OperatorIdentificationSequence 
	 */
	public OperatorIdentificationSequence getOperatorIdentificationSequence()
	{
		OperatorIdentificationSequence objOperatorIdentificationSequence= (OperatorIdentificationSequence)getDicomValue(0x0008, 0x1072);
		if(objOperatorIdentificationSequence == null)
		{
			/*
			 * If the sequence object is not present in the DataSet, a new sequence object is created and
			 * the TransferSyntax and DictionaryReader is set into it as it is set in the Module. This ensures that 
			 * the DataElements getting added in the DataSet follow the same TransferSyntax and use the same
			 * DictionaryReader object as that of the module.
			 */
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			objOperatorIdentificationSequence = (OperatorIdentificationSequence)objDicomV3Factory.createSequence(0x0008, 0x1072, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x0008, 0x1072, DicomConstants.DCM_DT_SQ, objOperatorIdentificationSequence.getValue());
		}
		return objOperatorIdentificationSequence;
	}
	
	/**
	 * Retrieves pre-initialized object of IssuerOfAdmissionIDSequence. If the module contains the sequence object
	 * it returns the same otherwise it creates the sequence adds to the module with proper initialization
	 * and then returns the object of sequence
	 * 
	 * @return IssuerOfAdmissionIDSequence 
	 */
	public IssuerOfAdmissionIDSequence getIssuerOfAdmissionIDSequence()
	{
		IssuerOfAdmissionIDSequence objIssuerOfAdmissionIDSequence= (IssuerOfAdmissionIDSequence)getDicomValue(0x0038, 0x0014);
		if(objIssuerOfAdmissionIDSequence == null)
		{
			/*
			 * If the sequence object is not present in the DataSet, a new sequence object is created and
			 * the TransferSyntax and DictionaryReader is set into it as it is set in the Module. This ensures that 
			 * the DataElements getting added in the DataSet follow the same TransferSyntax and use the same
			 * DictionaryReader object as that of the module.
			 */
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			objIssuerOfAdmissionIDSequence = (IssuerOfAdmissionIDSequence)objDicomV3Factory.createSequence(0x0038, 0x0014, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x0038, 0x0014, DicomConstants.DCM_DT_SQ, objIssuerOfAdmissionIDSequence.getValue());
		}
		return objIssuerOfAdmissionIDSequence;
	}
	/*
	 * This method is used by the Module Iterator to iterate through the DataSet and return only
	 * those elements that belong to the respective Module class whose this is called.
	 */
	/**
	 * This method returns the collection of keys representing the DataElements
	 * that belong to this module.
	 * 
	 * @return ISingleCollection - the customized collection containing the dataelement tags
	 * that beling to this module
	 */
	public ISingleCollection<ITag> getVectorOfKeys()
	{
		return objSingleCollection;
	}

}
