/*******************************************************************************
 *  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.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;
/**
 * This class specifies the attributes that identify and describe the piece of equipment that produced a Series of Composite Instances.
 * @author saloni
 *
 */
public class EnhancedGeneralEquipmentModule extends Module  
{


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


	/**
	 * Creates Enhanced General Equipment Module with default initialization.
	 * 
	 * @param objIDataSet the obj i data set
	 */
	public EnhancedGeneralEquipmentModule(IDataSet objIDataSet)
	{
		super(objIDataSet);
	}

	static
	{
		objSingleCollection = new SingleCollection<ITag>();
		objSingleCollection.add(new Tag(0x0008,0x0070));
		objSingleCollection.add(new Tag(0x0008,0x1090));
		objSingleCollection.add(new Tag(0x0018,0x1000));
		objSingleCollection.add(new Tag(0x0018,0x1020));
	}

	/**
	 * 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 true, if validate module
	 * 
	 * @throws InvalidModuleException - If validation of Module fails
	 */
	public  boolean validateModule() throws InvalidModuleException
	{

		try
		{			/*
		 * Validation Rules for Mandatory Elements
		 */
			if(!isPresent(0x0008,0x0070))
				throw new MandatoryMissingException("0008,0070");
			if(!isPresent(0x0008,0x1090))
				throw new MandatoryMissingException("0008,1090");
			if(!isPresent(0x0018,0x1000))
				throw new MandatoryMissingException("0018,1000");
			if(!isPresent(0x0018,0x1020))
				throw new MandatoryMissingException("0018,1020");
		}
		catch(MandatoryMissingException mme)
		{
			if(DicomConfig.createInstance().isLoggingOn())
				DicomLogger.getLogger().log(mme.getMessage());

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

		}
		return true;
	}
	
	/**
	 * Sets Manufacturer.
	 * Manufacturer of the equipment that produced the composite instances.
	 * @param strManufacturer :The name of the Manufacturer of the equipment
	 * 
	 * 
	 */
	public void setManufacturer(String strManufacturer)
	{
		/*Accept Manufacturer of the equipment that produced the composite instances 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 Hash Map
		 */
		addDataElement(0x0008, 0x0070, DicomConstants.DCM_DT_LO, strManufacturer);
	}
	
	/**
	 * Gets the manufacturer.
	 * 
	 * @return the manufacturer
	 */
	public String getManufacturer()
	{
		Object objValue = objIDataSet.getValue(0x0008, 0x0070);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets Manufacturers Model Name.
	 * Manufacturer's model name of the equipment that produced the composite instances.
	 * @param strManufacturersModelName :The name of the Manufacturers Model
	 * 
	 * 
	 */
	public void setManufacturersModelName(String strManufacturersModelName)
	{
		/*Accept Manufacturers Model 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 Hash Map
		 */
		addDataElement(0x0008, 0x1090, DicomConstants.DCM_DT_LO, strManufacturersModelName);
	}
	
	/**
	 * Gets the Manufacturers Model Name.
	 * Manufacturer's model name of the equipment that produced the composite instances.
	 * @return the Manufacturers Model Name.
	 */
	public String getManufacturersModelName()
	{
		Object objValue = objIDataSet.getValue(0x0008, 0x1090);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Device Serial Number.
	 * @param strDeviceSerialNumber :Device Serial Number
	 * 
	 * 
	 */
	public void setDeviceSerialNumber(String strDeviceSerialNumber)
	{
		/*Accept Device Serial Number 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 Hash Map
		 */
		addDataElement(0x0018, 0x1000, DicomConstants.DCM_DT_LO, strDeviceSerialNumber);
	}
	
	/**
	 * Gets the Device Serial Number.
	 * @return the Device Serial Number.
	 */
	public String getDeviceSerialNumber()
	{
		Object objValue = objIDataSet.getValue(0x0018, 0x1000);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * This method is used to set Manufacturers designation of software version of the equipment that produced the composite instances.
	 * The function accepts a String Value and creates the
	 * DE based on the transfer syntax and populates the DE with right values.
	 * This De is then added to the Module HashMap
	 * 
	 * @param arrStrSoftwareVersions :StrSoftware Versions
	 * 
	 * 
	 */
	public void setSoftwareVersions(String[] arrStrSoftwareVersions)
	{
		/*Accept Manufacturers designation of software version of the equipment that produced the composite instances.
		 * in String Array 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(0x0018, 0x1020, DicomConstants.DCM_DT_LO, arrStrSoftwareVersions);
	}
	
	/**
	 * Gets the software versions.
	 * 
	 * @return the software versions
	 */
	public String[] getSoftwareVersions()
	{
		Object objValue = objIDataSet.getValue(0x0018, 0x1020);
		if(objValue != null)
			return (String[])objValue;
		else
			return null;
	}

	/**
	 * This method returns the collection of keys representing the DataElements that belong to this module.
	 * 
	 * @return Collection of Tags - returns the collection containing the tags
	 */
	public ISingleCollection<ITag> getVectorOfKeys()
	{
		return objSingleCollection;
	}


}