/*******************************************************************************
 *  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.DicomV3Factory;
import cdac.medinfo.sdk.dcm30_04.baselibs.PertinentDocumentsSequence;
import cdac.medinfo.sdk.dcm30_04.baselibs.ProductParameterSequence;
import cdac.medinfo.sdk.dcm30_04.baselibs.ProductTypeCodeSequence;
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.utils.DicomConstants;
import cdac.medinfo.sdk.dcm30_04.utils.ISingleCollection;
import cdac.medinfo.sdk.dcm30_04.utils.SingleCollection;
/**
 \* This module specifies the attributes of Product Characteristics Module.
 */
public class ProductCharacteristicsModule extends Module
{

	 /**
	  * The obj single collection.
	  */
	 public static ISingleCollection<ITag> objSingleCollection = null;
		 

		/**
		 * Instantiates a new ProductCharacteristicsModule
		 * 
		 * @param objIDataSet the obj i data set
		 */
		public ProductCharacteristicsModule(IDataSet objIDataSet)
		{
			super(objIDataSet);
		}

		static
		{
			objSingleCollection = new SingleCollection<ITag>();
			objSingleCollection.add(new Tag(0x0044,0x0001));
			objSingleCollection.add(new Tag(0x0008,0x0070));
			objSingleCollection.add(new Tag(0x0044,0x0008));
			objSingleCollection.add(new Tag(0x0044,0x0009));
			objSingleCollection.add(new Tag(0x0044,0x000A));
			objSingleCollection.add(new Tag(0x0044,0x000B));
			objSingleCollection.add(new Tag(0x0044,0x0013));
			objSingleCollection.add(new Tag(0x0038,0x0100));
			objSingleCollection.add(new Tag(0x0044,0x0007));

		}

		/**
		 * This method validates each Attribute in the Module according to the Type
		 * of the Attribute.Attributes are of 5 types.
		 * Type 1,Type 2 are Mandatory:
		 * Mandatory Attributes have to present in the Module.
		 * Type 1C,2C are Conditional:
		 * Conditional Attributes' presence depend on a condition.
		 * If the condition is satisfied the Attribute has to be present.
		 * Type 3 are Optional
		 * Optional Attributes can be added as and when required.
		 * 
		 * @return boolean - returns validation status as success or failure
		 * 
		 * @throws InvalidModuleException - If validation of Module fails
		 */	
		public  boolean validateModule() throws InvalidModuleException
		{
			return true;
		}
		/**
		 * Sets the Identifier of the contrast agent, drug, or device being characterized, typicallyfrom a package bar code, RFID, or other materials management ID.
		 * @param strProductPackageIdentifier Product Package Identifier
		 */
		public void setProductPackageIdentifier(String strProductPackageIdentifier)
		{
			/*Accept the Product Package Identifier 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 the Identifier of the contrast agent, drug, or device being characterized, typicallyfrom a package bar code, RFID, or other materials management ID.
		 * @return String value of Product Package Identifier
		 */
		public String getProductPackageIdentifier()
		{
			Object objValue = getValue(0x0040, 0x0310);
			if(objValue != null)
				return objValue.toString();
			return null;
		}
		/**
		 * Sets the Manufacturer of product.
		 * @param strManufacturer -Manufacturer
		 */
		public void setManufacturer(String strManufacturer)
		{
			/*Accept the Product Package Identifier 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(0x0008, 0x0070, DicomConstants.DCM_DT_LO,strManufacturer);
		}
		/**
		 * Retrieves the Manufacturer of product.
		 * @return String value of Manufacturer
		 */
		public String getManufacturer()
		{
			Object objValue = getValue(0x0008, 0x0070);
			if(objValue != null)
				return objValue.toString();
			return null;
		}
		

		/**
		 * Sets Trade or generic name of product.
		 * @param strArrProductName String value of Rescale Type.
		 */
		public void setProductName(String[] strArrProductName)
		{
			/* Accept the Trade or generic name of product 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, 0x0000, DicomConstants.DCM_DT_LO,strArrProductName);
		}

		/**
		 * Return Trade or generic name of product.
		 * @return String - value of Product Name.
		 */
		public String[] getProductName()
		{
			Object objValue = getValue(0x0028,0x1054);
			if(objValue != null)
				return (String[])objValue;
			return null;
		}
		/**
		 * Sets the Further description in free form text describing the drug or device.
		 * @param strProductDescription Product Description
		 */
		public void setProductDescription(String strProductDescription)
		{
			/*Accept the Product Package Identifier 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, 0x0009, DicomConstants.DCM_DT_LT,strProductDescription);
		}
		/**
		 * Retrieves the Further description in free form text describing the drug or device.
		 * @return String value of Product Description
		 */
		public String getProductDescription()
		{
			Object objValue = getValue(0x0044, 0x0009);
			if(objValue != null)
				return objValue.toString();
			return null;
		}
		/**
		 * Sets Product Expiration DateTime
		 * @param strProductExpirationDateTime String value of Product Expiration DateTime
		 */
		public void setProductExpirationDateTime(String strProductExpirationDateTime)
		{
			/* Accept the Product Expiration DateTime of type DT.
			 * 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, 0x000B, DicomConstants.DCM_DT_DT,strProductExpirationDateTime);
		}

		/**
		 * Retrieves Product Expiration DateTime
		 * @return String - value of Product Expiration DateTime
		 */
		public String getProductExpirationDateTime()
		{
			Object objValue = getValue(0x0044, 0x000B);
			if(objValue != null)
				return objValue.toString();
			return null;
		}
		/**
		 * Retrieves Product Parameter Sequence.  
		 * @return - instance of Product Parameter Sequence.
		 */
		public ProductParameterSequence getProductParameterSequence()
		{
			ProductParameterSequence objProductParameterSequence = (ProductParameterSequence)getDicomValue(0x0044, 0x0013);
			if(objProductParameterSequence == 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();
				objProductParameterSequence = (ProductParameterSequence)objDicomV3Factory.createSequence(0x0044, 0x0013, objITransferSyntax, objIDictionaryReader);
				
				// This will add Data Element of SQ to the DataSet.
				addDataElement(0x0044, 0x0013, DicomConstants.DCM_DT_SQ, objProductParameterSequence.getValue());
			}
			return objProductParameterSequence;
		}
		/**
		 * Retrieves Pertinent Documents Sequence  
		 * @return - instance of Pertinent Documents Sequence
		 */
		public PertinentDocumentsSequence getPertinentDocumentsSequence()
		{
			PertinentDocumentsSequence objPertinentDocumentsSequence = (PertinentDocumentsSequence)getDicomValue(0x0038, 0x0100);
			if(objPertinentDocumentsSequence == 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();
				objPertinentDocumentsSequence = (PertinentDocumentsSequence)objDicomV3Factory.createSequence(0x0038, 0x0100, objITransferSyntax, objIDictionaryReader);
				
				// This will add Data Element of SQ to the DataSet.
				addDataElement(0x0038, 0x0100, DicomConstants.DCM_DT_SQ, objPertinentDocumentsSequence.getValue());
			}
			return objPertinentDocumentsSequence;
		}
		
		/**
		 * Retrieves Product Type Code Sequence.  
		 * @return - instance of Product Type Code Sequence
		 */
		public ProductTypeCodeSequence getProductTypeCodeSequence()
		{
			ProductTypeCodeSequence objProductTypeCodeSequence = (ProductTypeCodeSequence)getDicomValue(0x0044, 0x0007);
			if(objProductTypeCodeSequence == 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();
				objProductTypeCodeSequence = (ProductTypeCodeSequence)objDicomV3Factory.createSequence(0x0044, 0x0007, objITransferSyntax, objIDictionaryReader);
				
				// This will add Data Element of SQ to the DataSet.
				addDataElement(0x0044, 0x0007, DicomConstants.DCM_DT_SQ, objProductTypeCodeSequence.getValue());
			}
			return objProductTypeCodeSequence;
		}
		
		/**
		 * This method returns the vector of keys representing the DataElements
		 * that belong to this module.
		 * 
		 * @return vector of Tags - returns the vector containing the collection of tags
		 */
		public ISingleCollection<ITag> getVectorOfKeys()
		{
			return objSingleCollection;
		}
}
