/*******************************************************************************
 *  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.IDicomValue;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDictionaryReader;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITransferSyntax;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConstants;

/**
* This item class contains the methods to set, get and validate the attribute present in Display Subsystem Sequence .
 */
public class DisplaySubsystemSequenceItem extends Item{
	


	private static final long serialVersionUID = 1L;
	/**
	 * This constructor creates the item and internal code sequence macro with default TransferSyntax 
	 */
	DisplaySubsystemSequenceItem()
	{
		super();
	}


	/**
	 * This constructor creates the item and internal code sequence macro with specified TransferSyntax 
	 * and default DictionaryReader
	 * @param objITransferSyntax specifies the DICOM Standard defined TransfeSyntax
	 */
	DisplaySubsystemSequenceItem(ITransferSyntax objITransferSyntax)
	{
		super(objITransferSyntax);
	}

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

	/**
	 * Sets Number that identifies a specific display subsystem within a Display System.
	 * @param shDisplaySubsystemID short value of Number of significant bits
	 */
	public void setDisplaySubsystemID(short shDisplaySubsystemID)
	{
		/* Accept the DisplaySubsystemID of type US.
		 * Number that identifies a specific display subsystem within a Display System.
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0028,0x7003,shDisplaySubsystemID,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0028,0x7003,DicomConstants.DCM_DT_US, shDisplaySubsystemID);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Number that identifies a specific display subsystem within a Display System.
	 * @return short - short value of DisplaySubsystemID 
	 */
	public short getDisplaySubsystemID()
	{
		Object objValue = getValue(0x0028,0x7003);
		if(objValue != null)
			return Short.parseShort(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Sets the DisplaySubsystemName.
	 * @param strDisplaySubsystemName
	 */
	public void setDisplaySubsystemName(String strDisplaySubsystemName)
	{
		/* Accept the strDisplaySubsystemName in String format of type SH.
		 * User-defined name for the Display Subsystem.
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0028, 0x7004, strDisplaySubsystemName,objIDictionaryReader);
		else
			objIDataElement = new ExplicitDE(0x0028, 0x7004,DicomConstants.DCM_DT_SH, strDisplaySubsystemName);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves DisplaySubsystemName.User-defined name for the Display Subsystem.
	 * @return String - value of DisplaySubsystemName.
	 */
	public String getDisplaySubsystemName()
	{
		Object objValue = getValue(0x0028, 0x7004);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	/**
	 * Sets DisplaySubsystemDescription.A free text description of the Display Subsystem.
	 * @param strDisplaySubsystemDescription String value of Rescale Type.
	 */
	public void setDisplaySubsystemDescription(String strDisplaySubsystemDescription)
	{
		/* Accept the DisplaySubsystemDescription in String format of type LO.
		 * A free text description of the Display Subsystem.
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0028,0x7005, strDisplaySubsystemDescription,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0028,0x7005,DicomConstants.DCM_DT_LO, strDisplaySubsystemDescription);

		addDataElement(objIDataElement);
	}

	/**
	 * Return user-defined label identifier for DisplaySubsystemDescription.
	 * A free text description of the Display Subsystem.
	 * @return String - value of Display Sub system Description.
	 */
	public String getDisplaySubsystemDescription()
	{
		Object objValue = getValue(0x0028,0x7005);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Retrieves pre-initialized object of Display Device Type Code Sequence.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 DisplayDeviceTypeCodeSequence - instance of DisplayDeviceTypeCodeSequence. 
	 */
	public DisplayDeviceTypeCodeSequence getDisplayDeviceTypeCodeSequence()
	{
		DisplayDeviceTypeCodeSequence objDisplayDeviceTypeCodeSequence = null;
		IDataElement objIDataElement =  getDataForTag(0x0028, 0x7022);
		if(objIDataElement != null)
		{
			IDicomValue objIDicomValue = objIDataElement.getDicomValue();
			if(objIDicomValue != null)
				objDisplayDeviceTypeCodeSequence = (DisplayDeviceTypeCodeSequence)objIDicomValue;
		}
		else
		{
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			int iVRTransferSyntax = objITransferSyntax.getVRTransferSyntax();
			objIDataElement = null;
			objDisplayDeviceTypeCodeSequence = (DisplayDeviceTypeCodeSequence)objDicomV3Factory.createSequence(0x0028, 0x7022, objITransferSyntax, objIDictionaryReader);

			if(iVRTransferSyntax == DicomConstants.DCM_VR_IMPLICIT)
				objIDataElement = new ImplicitDE(0x0028, 0x7022, objDisplayDeviceTypeCodeSequence.getValue(),objIDictionaryReader);
			else
				objIDataElement = new ExplicitDE(0x0028, 0x7022, DicomConstants.DCM_DT_SQ, objDisplayDeviceTypeCodeSequence.getValue());
			objIDataElement.setTransferSyntax(objITransferSyntax);
			if(objIDataElement != null)
				addDataElement(objIDataElement);
		}
		return objDisplayDeviceTypeCodeSequence;
	}

	/**
	 * Sets Manufacturer.Manufacturer of the Display Device in the Display Subsystem.
	 * @param strManufacturer String value of Rescale Type.
	 */
	public void setManufacturer(String strManufacturer)
	{
		/* Accept the Manufacturer in String format of type LO.
		 * Manufacturer of the Display Device in the Display Subsystem.
		 * If the Display Subsystem is provided integrated into the Display System (e.g. for a tablet) and the Manufacturer is not otherwise known, 
		 * the Manufacturer of the Display System may be recorded here.
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0008,0x0070, strManufacturer,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0008,0x0070,DicomConstants.DCM_DT_LO, strManufacturer);

		addDataElement(objIDataElement);
	}

	/**
	 * Return Manufacturer of the Display Device in the Display Subsystem.
	 * @return String - value of Manufacturer.
	 */
	public String getManufacturer()
	{
		Object objValue = getValue(0x0008,0x0070);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	/**
	 * Sets DeviceSerialNumber.Manufacturer's serial number of the Display Device (i.e. monitor device) in the Display Subsystem.
	 * @param strDeviceSerialNumber String value of Rescale Type.
	 */
	public void setDeviceSerialNumber(String strDeviceSerialNumber)
	{
		/* Accept the DeviceSerialNumber in String format of type LO.
		 * Manufacturer's serial number of the Display Device (i.e. monitor device) in the Display Subsystem.
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0018,0x1000, strDeviceSerialNumber,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0018,0x1000,DicomConstants.DCM_DT_LO, strDeviceSerialNumber);

		addDataElement(objIDataElement);
	}

	/**
	 * Return Manufacturer of the Device Serial Number
	 * @return String - value of DeviceSerialNumber.
	 */
	public String getDeviceSerialNumber()
	{
		Object objValue = getValue(0x0018,0x1000);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets ManufacturersModelName.Manufacturer's model name of the Display Device in the Display Subsystem
	 * @param strManufacturersModelName String value of Rescale Type.
	 */
	public void setManufacturersModelName(String strManufacturersModelName)
	{
		/* Accept the DeviceSerialNumber in String format of type LO.
		 * Manufacturer's model name of the Display Device in the Display Subsystem
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0008,0x1090, strManufacturersModelName,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0008,0x1090,DicomConstants.DCM_DT_LO, strManufacturersModelName);

		addDataElement(objIDataElement);
	}

	/**
	 * Return Manufacturer's model name of the Display Device in the Display Subsystem
	 * @return String - value of DeviceSerialNumber.
	 */
	public String getManufacturersModelName()
	{
		Object objValue = getValue(0x0008,0x1090);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets the SystemStatus Defined in Terms of TEXT,NUMERIC,CODE,DATE,TIME,PNAME
	 * @param strSystemStatus Specifies type of the value encoded in this Item
	 */
	public void setSystemStatus(String strSystemStatus)
	{
		/* Accept the System Status in String format of type CS.
		 * Current overall status of the Display Subsystem.
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0028, 0x7006, strSystemStatus,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0028, 0x7006,DicomConstants.DCM_DT_CS, strSystemStatus);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves SystemStatus Current overall status of the Display Subsystem.
	 * @return String - Type of the value encoded in this Item
	 */
	public String getSystemStatus()
	{
		Object objValue = getValue(0x0028, 0x7006);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	/**
	 * Sets SystemStatusComment.A free text comment about the status of the Display Subsystem.
	 * @param strSystemStatusComment String value of System Status Comment.
	 */
	public void setSystemStatusComment(String strSystemStatusComment)
	{
		/* Accept the SystemStatusComment in String format of type LO.
		 * A free text comment about the status of the Display Subsystem.
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0028,0x7007, strSystemStatusComment,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0028,0x7007,DicomConstants.DCM_DT_LO, strSystemStatusComment);

		addDataElement(objIDataElement);
	}

	/**
	 * Return A free text comment about the status of the Display Subsystem.
	 * @return String - value of System Status Comment.
	 */
	public String getSystemStatusComment()
	{
		Object objValue = getValue(0x0028,0x7007);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Retrieves pre-initialized object of Display Sub system Configuration Sequence.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 DisplayDeviceTypeCodeSequence - instance of DisplaySubsystemConfigurationSequence. 
	 */
	public DisplaySubsystemConfigurationSequence getDisplaySubsystemConfigurationSequence()
	{
		DisplaySubsystemConfigurationSequence objDisplaySubsystemConfigurationSequence = null;
		IDataElement objIDataElement =  getDataForTag(0x0028, 0x700A);
		if(objIDataElement != null)
		{
			IDicomValue objIDicomValue = objIDataElement.getDicomValue();
			if(objIDicomValue != null)
				objDisplaySubsystemConfigurationSequence = (DisplaySubsystemConfigurationSequence)objIDicomValue;
		}
		else
		{
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			int iVRTransferSyntax = objITransferSyntax.getVRTransferSyntax();
			objIDataElement = null;
			objDisplaySubsystemConfigurationSequence = (DisplaySubsystemConfigurationSequence)objDicomV3Factory.createSequence(0x0028, 0x700A, objITransferSyntax, objIDictionaryReader);

			if(iVRTransferSyntax == DicomConstants.DCM_VR_IMPLICIT)
				objIDataElement = new ImplicitDE(0x0028, 0x700A, objDisplaySubsystemConfigurationSequence.getValue(),objIDictionaryReader);
			else
				objIDataElement = new ExplicitDE(0x0028, 0x700A, DicomConstants.DCM_DT_SQ, objDisplaySubsystemConfigurationSequence.getValue());
			objIDataElement.setTransferSyntax(objITransferSyntax);
			if(objIDataElement != null)
				addDataElement(objIDataElement);
		}
		return objDisplaySubsystemConfigurationSequence;
	}
	
	/**
	 * Sets Number of significant bits within the waveform samples
	 * References the current configuration of the Display Subsystem
	 * @param shCurrentConfigurationID short value of Number of significant bits
	 */
	public void setCurrentConfigurationID(short shCurrentConfigurationID)
	{
		/* Accept the CurrentConfigurationID of type US.
		 * References the current configuration of the Display Subsystem
		 * Add this element to the Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)	
			objIDataElement = new ImplicitDE(0x0028,0x7002,shCurrentConfigurationID,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0028,0x7002,DicomConstants.DCM_DT_US, shCurrentConfigurationID);

		addDataElement(objIDataElement);
	}

	/**
	 * Retrieves Number of significant bits within the CurrentConfigurationID samples
	 * @return short - short value of Number of CurrentConfigurationID
	 */
	public short getCurrentConfigurationID()
	{
		Object objValue = getValue(0x0028,0x7002);
		if(objValue != null)
			return Short.parseShort(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	
	/**
	 * Retrieves pre-initialized object of Measurement Equipment Sequence.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 MeasurementEquipmentSequence - instance of MeasurementEquipmentSequence. 
	 */
	public MeasurementEquipmentSequence getMeasurementEquipmentSequence()
	{
		MeasurementEquipmentSequence objMeasurementEquipmentSequence = null;
		IDataElement objIDataElement =  getDataForTag(0x0028, 0x7012);
		if(objIDataElement != null)
		{
			IDicomValue objIDicomValue = objIDataElement.getDicomValue();
			if(objIDicomValue != null)
				objMeasurementEquipmentSequence = (MeasurementEquipmentSequence)objIDicomValue;
		}
		else
		{
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			int iVRTransferSyntax = objITransferSyntax.getVRTransferSyntax();
			objIDataElement = null;
			objMeasurementEquipmentSequence = (MeasurementEquipmentSequence)objDicomV3Factory.createSequence(0x0028, 0x7012, objITransferSyntax, objIDictionaryReader);

			if(iVRTransferSyntax == DicomConstants.DCM_VR_IMPLICIT)
				objIDataElement = new ImplicitDE(0x0028, 0x7012, objMeasurementEquipmentSequence.getValue(),objIDictionaryReader);
			else
				objIDataElement = new ExplicitDE(0x0028, 0x7012, DicomConstants.DCM_DT_SQ, objMeasurementEquipmentSequence.getValue());
			objIDataElement.setTransferSyntax(objITransferSyntax);
			if(objIDataElement != null)
				addDataElement(objIDataElement);
		}
		return objMeasurementEquipmentSequence;
	}
	
	
}
