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



import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataElement;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDictionaryReader;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITransferSyntax;
import cdac.medinfo.sdk.dcm30_04.enums.EnumShieldingDeviceType;
import cdac.medinfo.sdk.dcm30_04.exceptions.InvalidItemException;
import cdac.medinfo.sdk.dcm30_04.exceptions.MandatoryMissingException;
import cdac.medinfo.sdk.dcm30_04.exceptions.ValidationException;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConfig;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConstants;
import cdac.medinfo.sdk.dcm30_04.utils.DicomLogger;




/**
* This item class contains methods to validate, set and get the attributes of {@link ShieldingDeviceSequence}.
 */
public class ShieldingDeviceSequenceItem extends Item  
{
	


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * This constructor creates the item and internal code sequence macro with default TransferSyntax 
	 */
	ShieldingDeviceSequenceItem()
	{
		super();
	}

	/*
	 * This constructor calls the respective superclass constructor
	 * This constructor should throw exception if null TS is tried to be set
	 */
	/**
	 * This constructor creates the item and internal code sequence macro with default TransferSyntax 
	 * and default DictionaryReader
	 * @param objITransferSyntax specifies the DICOM Standard defined TransfeSyntax
	 */
	ShieldingDeviceSequenceItem(ITransferSyntax objITransferSyntax)
	{
		super(objITransferSyntax);
	}

	/**
	 * This constructor creates ShieldingDeviceSequenceItem with specified TransferSyntax and
	 * specified DictionaryReader.
	 * @param objTransferSyntax specifies the DICOM Standard defined TransfeSyntax.
	 * @param objDictionaryReader specifies the DICOM Dictionary reader to be used.
	 */
	ShieldingDeviceSequenceItem(ITransferSyntax objTransferSyntax, IDictionaryReader objDictionaryReader)
	{
		super(objTransferSyntax,objDictionaryReader);
	}

	/*
	 * (non-Javadoc) This mathod validates the contents of the Item
	 * @see cdac.medinfo.sdk.dcm30_04.commoninterface.IItem#validate()
	 */
	/**
	 * Validates all the attributes in ShieldingDeviceSequence that are present in the DataSet
	 * @return boolean - Success -true, Failure - false
	 * @throws InvalidItemException throws InvalidItemException If Mandatory or Conditional element fails.
	 */
	public boolean validateForModule()  throws InvalidItemException
	{
		try{
			if(!contains(0x300A,0x01A2))
				throw new MandatoryMissingException("300A,01A2");
			if(!contains(0x300A,0x01A4))
				throw new MandatoryMissingException("300A,01A4");
		}
		catch(MandatoryMissingException me)
		{
			if(DicomConfig.createInstance().isLoggingOn())
			{
				DicomLogger.getLogger().log(me.getMessage());
			}
			throw new ValidationException(this.getClass().getSimpleName(),me);
		}
		return true;
	}

	/**
	 * Sets type of Shielding Device used in Patient Setup.
	 *  Defined Terms:
	 *	1) GUM.
	 * 	2) EYE.
	 *	3) GONAD.
	 * @param enumShieldingDeviceType enum value of Shielding Device Type.
	 */
	public void setShieldingDeviceType(EnumShieldingDeviceType enumShieldingDeviceType)
	{
		/* Accept the Shielding Device 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
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x300A,0x01A2, enumShieldingDeviceType.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x01A2,DicomConstants.DCM_DT_CS, enumShieldingDeviceType.getValue());

		addDataElement(objIDataElement);


	}

	/**
	 * Return type of Shielding Device used in Patient Setup.
	 * @return String - value of Shielding Device Type.
	 */
	public String getShieldingDeviceType()
	{
		Object objValue = getValue(0x300A,0x01A2);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets user-defined label for Shielding Device.
	 * @param strShieldingDeviceLabel String value of Shielding Device Label.
	 */
	public void setShieldingDeviceLabel(String strShieldingDeviceLabel)
	{
		/* Accept the Shielding Device Label 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
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x300A,0x01A4, strShieldingDeviceLabel,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x01A4,DicomConstants.DCM_DT_SH, strShieldingDeviceLabel);

		addDataElement(objIDataElement);


	}

	/**
	 * Return user-defined label for Shielding Device.
	 * @return String - value of Shielding Device Label.
	 */
	public String getShieldingDeviceLabel()
	{
		Object objValue = getValue(0x300A,0x01A4);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets user-defined description of Shielding Device.
	 * @param strShieldingDeviceDescription String value of Shielding Device Description.
	 */
	public void setShieldingDeviceDescription(String strShieldingDeviceDescription)
	{
		/* Accept the Shielding Device Description 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
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x300A,0x01A6, strShieldingDeviceDescription,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x01A6,DicomConstants.DCM_DT_ST, strShieldingDeviceDescription);

		addDataElement(objIDataElement);


	}

	/**
	 * Return user-defined description of Shielding Device.
	 * @return String - value of Shielding Device Description.
	 */
	public String getShieldingDeviceDescription()
	{
		Object objValue = getValue(0x300A,0x01A6);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets position/notch number of Shielding Device.
	 * @param strShieldingDevicePosition String value of Shielding Device Position.
	 */
	public void setShieldingDevicePosition(String strShieldingDevicePosition)
	{
		/* Accept the Shielding Device Position 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
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x300A,0x01A8, strShieldingDevicePosition,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x01A8,DicomConstants.DCM_DT_SH, strShieldingDevicePosition);

		addDataElement(objIDataElement);


	}

	/**
	 * Return position/notch number of Shielding Device.
	 * @return String - value of Shielding Device Position.
	 */
	public String getShieldingDevicePosition()
	{
		Object objValue = getValue(0x300A,0x01A8);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets an identifier for the accessory intended to be read by a device such as a bar-code reader.
	 * @param strAccessoryCode String value of Accessory Code.
	 */
	public void setAccessoryCode(String strAccessoryCode)
	{
		/* Accept the Accessory Code 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
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x300A,0x00F9, strAccessoryCode,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x00F9,DicomConstants.DCM_DT_LO, strAccessoryCode);

		addDataElement(objIDataElement);


	}

	/**
	 * Return an identifier for the accessory intended to be read by a device such as a bar-code reader.
	 * @return String - value of Accessory Code.
	 */
	public String sgetAccessoryCode()
	{
		Object objValue = getValue(0x300A,0x00F9);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
}
