/*******************************************************************************
 *  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.IDataElement;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDicomValue;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITag;
import cdac.medinfo.sdk.dcm30_04.enums.EnumConversionType;
import cdac.medinfo.sdk.dcm30_04.enums.EnumModality;

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 describes equipment used to convert images into a DICOM format.
 */

public class SCEquipmentModule extends Module  
{
	/**
	 * The obj single collection.
	 */
	public static ISingleCollection<ITag> objSingleCollection = null;
	/**
	 * Instantiates a new sC equipment module.
	 * 
	 * @param objIDataSet the obj i data set
	 */
	public SCEquipmentModule(IDataSet objIDataSet)
	{
		super(objIDataSet);
	}

	static
	{
		objSingleCollection = new SingleCollection<ITag>();
		objSingleCollection.add(new Tag(0x0008,0x0060));
		objSingleCollection.add(new Tag(0x0008,0x0064));
		objSingleCollection.add(new Tag(0x0018,0x1010));
		objSingleCollection.add(new Tag(0x0018,0x1016));
		objSingleCollection.add(new Tag(0x0018,0x1018));
		objSingleCollection.add(new Tag(0x0018,0x1019));
		objSingleCollection.add(new Tag(0x0018,0x1022));
		objSingleCollection.add(new Tag(0x0018,0x1023));
	}

	/**
	 * 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
	{

		try
		{			
			if(!isPresent(0x0008,0x0064))
				throw new MandatoryMissingException("Missing Mandatory Data Element 0008,0064");
		}
		catch(MandatoryMissingException mme)
		{
			if(DicomConfig.createInstance().isLoggingOn())
				DicomLogger.getLogger().log(mme.getMessage());

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

		}


		return true;
	}

	/**
	 * Sets describes the kind of image conversion.
	 * Defined Terms:
	 * 1) DV = Digitized Video
	 * 2) DI = Digital Interface
	 * 3) DF = Digitized Film
	 * 4) WSD = Workstation
	 * 5) SD = Scanned Document
	 * 6) SI = Scanned Image
	 * 7) DRW = Drawing
	 * 8) SYN = Synthetic Image
	 * 
	 * @param enumConversionType - enum value of Conversion Type.
	 */
	public void setConversionType(EnumConversionType enumConversionType)
	{
		/* Accept Conversion Type in String format of type CS.
		 * 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, 0x0064, DicomConstants.DCM_DT_CS, enumConversionType.getValue());
	}

	/**
	 * Retrieves describes the kind of image conversion.
	 * 
	 * @return String - String value of Conversion Type.
	 */
	public String getConversionType()
	{
		if (objIDataSet == null)
			return null;
		IDataElement objIDataElement = objIDataSet.getDataForTag(0x0008, 0x0064);
		if(objIDataElement == null)
			return null;
		IDicomValue objIDicomValue = objIDataElement.getDicomValue();
		if(objIDicomValue == null)
			return null;
		if(objIDicomValue.getValue() == null)
			return null;
		return objIDicomValue.getValue().toString();
		//return objIDataSet.getDataForTag(0x0008, 0x0064).getDicomValue().getValue().toString();
	}

	/**
	 * Sets the Modality.
	 * 
	 * @param enumModality : Type of equipment that originally acquired
	 * the data used to create the images in this
	 * Series.
	 */	
	public void setModality(EnumModality enumModality)
	{
		/*Accept the Modality value in String format of type CS.
		 * 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, 0x0060, DicomConstants.DCM_DT_CS, enumModality.getValue());
	}

	/**
	 * Retrieves Type of equipment that originally acquired the data used to create the images in this Series.
	 * 
	 * @return String - String value of Modality.
	 */
	public String getModality()
	{
		Object objectValue = getValue(0x0008, 0x0060);
		if(objectValue!=null)
			return objectValue.toString();
		return null;
	}

	/**
	 * Sets user defined identification of the device that converted the image.
	 * 
	 * @param strSecondaryCaptureDeviceID - String value of Secondary Capture Device ID.
	 */
	public void setSecondaryCaptureDeviceID(String strSecondaryCaptureDeviceID)
	{
		/* Accept Secondary Capture Device 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(0x0018, 0x1010, DicomConstants.DCM_DT_LO, strSecondaryCaptureDeviceID);
	}

	/**
	 * Retrieves user defined identification of the device that converted the image.
	 * 
	 * @return String - String value of Secondary Capture Device ID.
	 */
	public String getSecondaryCaptureDeviceID()
	{
		Object objectValue = getValue(0x0018, 0x1010);
		if(objectValue!=null)
			return objectValue.toString();
		return null;
	}

	/**
	 * Sets manufacturer of the Secondary Capture Device.
	 * 
	 * @param strSecondaryCaptureDeviceManufacturer - String value of Secondary Capture Device Manufacturer.
	 */
	public void setSecondaryCaptureDeviceManufacturer(String strSecondaryCaptureDeviceManufacturer)
	{
		/* Accept Secondary Capture Device Manufacturer 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(0x0018, 0x1016, DicomConstants.DCM_DT_LO, strSecondaryCaptureDeviceManufacturer);
	}

	/**
	 * Retrieves manufacturer of the Secondary Capture Device.
	 * 
	 * @return String - String value of Secondary Capture Device Manufacturer.
	 */
	public String getSecondaryCaptureDeviceManufacturer()
	{
		Object objectValue = getValue(0x0018, 0x1016);
		if(objectValue!=null)
			return objectValue.toString();
		return null;
	}


	/**
	 * Sets manufacturer's model number of the Secondary Capture Device.
	 * 
	 * @param strSecondaryCaptureDeviceManufacturerModelName - String value of Secondary Capture Device Manufacturer's Model Name.
	 */
	public void setSecondaryCaptureDeviceManufacturerModelName(String strSecondaryCaptureDeviceManufacturerModelName)
	{
		/* Accept Secondary Capture Device Manufacturer 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 Data Set
		 */
		addDataElement(0x0018, 0x1018, DicomConstants.DCM_DT_LO, strSecondaryCaptureDeviceManufacturerModelName);
	}

	/**
	 * Retrieves manufacturer's model number of the Secondary Capture Device.
	 * 
	 * @return String - String value of Secondary Capture Device Manufacturer's Model Name.
	 */
	public String getSecondaryCaptureDeviceManufacturerModelName()
	{
		Object objectValue = getValue(0x0018, 0x1018);
		if(objectValue!=null)
			return objectValue.toString();
		return null;
	}

	/**
	 * Sets manufacturer's designation of software version of the Secondary Capture Device.
	 * 
	 * @param arrStrSecondaryCaptureDeviceSoftwareVersions - String value of Secondary Capture Device Software Version(s).
	 */	
	public void setSecondaryCaptureDeviceSoftwareVersions(String[] arrStrSecondaryCaptureDeviceSoftwareVersions)
	{
		/* Accept the Secondary Capture Device Software Version(s) value 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, 0x1019, DicomConstants.DCM_DT_LO, arrStrSecondaryCaptureDeviceSoftwareVersions);
	}

	/**
	 * Retrieves manufacturer's designation of software version of the Secondary Capture Device.
	 * 
	 * @return String[] - String value of Secondary Capture Device Software Version(s).
	 */
	public String[] getSecondaryCaptureDeviceSoftwareVersions()
	{
		 Object objValue = getValue(0x0018,0x1019);
   if(objValue!=null)
      return (String[])objValue;
   return null;

	}

	/**
	 * Sets original format of the captured video image (e.g. NTSC, PAL, Videomed-H).
	 * 
	 * @param strVideoImageFormatAcquired - String value of Video Image Format Acquired.
	 */
	public void setVideoImageFormatAcquired(String strVideoImageFormatAcquired)
	{
		/* Accept Video Image Format Acquired in String format of type SH.
		 * 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(0x0018, 0x1022, DicomConstants.DCM_DT_SH, strVideoImageFormatAcquired);
	}

	/**
	 * Retrieves original format of the captured video image.
	 * 
	 * @return String - String value of Video Image Format Acquired.
	 */
	public String getVideoImageFormatAcquired()
	{
		Object objectValue = getValue(0x0018, 0x1022);
		if(objectValue!=null)
			return objectValue.toString();
		return null;
	}

	/**
	 * Sets additional information about digital interface used to acquire the image.
	 * 
	 * @param strDigitalImageFormatAcquired - String value of Digital Image Format Acquired.
	 */
	public void setDigitalImageFormatAcquired(String strDigitalImageFormatAcquired)
	{
		/* Accept Digital Image Format Acquired 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(0x0018, 0x1023, DicomConstants.DCM_DT_LO, strDigitalImageFormatAcquired);
	}

	/**
	 * Retrieves additional information about digital interface used to acquire the image.
	 * 
	 * @return String - String value of Digital Image Format Acquired.
	 */
	public String getDigitalImageFormatAcquired()
	{
		Object objectValue = getValue(0x0018, 0x1023);
		if(objectValue!=null)
			return objectValue.toString();
		return null;
	}

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