/*******************************************************************************
 *  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.services.mediacreation.mediacreationsinkimpl;

import cdac.medinfo.sdk.dcm30_04.baselibs.DicomV3Factory;
import cdac.medinfo.sdk.dcm30_04.baselibs.ReferencedSOPSequence;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDictionaryReader;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITransferSyntax;
import cdac.medinfo.sdk.dcm30_04.enums.EnumAllowLossyCompression;
import cdac.medinfo.sdk.dcm30_04.enums.EnumAllowMediaSplitting;
import cdac.medinfo.sdk.dcm30_04.enums.EnumIncludeDisplayApplication;
import cdac.medinfo.sdk.dcm30_04.enums.EnumIncludeNonDICOMObjects;
import cdac.medinfo.sdk.dcm30_04.enums.EnumLabelUsingInformationExtractedFromInstances;
import cdac.medinfo.sdk.dcm30_04.enums.EnumPreserveCompositeInstancesAfterMediaCreation;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConstants;

/**
 *  This class contains the Attributes required for Query Model. Also contains methods to populate and fill dataset of Query Model.
 */
public class NCreateMediaCreationManageAttribute extends Attributes
{
	public void setSpecificCharacterSet(String[] arrStrSpecificCharacterSet)
	{
		addDataElement(0x0008, 0x0005, DicomConstants.DCM_DT_CS, arrStrSpecificCharacterSet);
	}
	
	public String[] getSpecificCharacterSet()
	{
		Object objValue = getValue(0x0008, 0x0005);
		if(objValue != null)
			return (String[])objValue;
		return null;
	}
	
	/**
	 * The user or implementation specific human readable identifier that identifies a Storage Media on which this SOP Instance resides.
	 * 
	 * @param strStorageMediaFileSetID String value of Storage Media File-Set ID.
	 */
	public void setStorageMediaFileSetID(String strStorageMediaFileSetID)
	{
		/* Accept the Storage Media File-Set ID 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(0x0088, 0x0130, DicomConstants.DCM_DT_SH, strStorageMediaFileSetID);
	}

	/**
	 * Retrieves  The user or implementation specific human readable identifier that identifies a Storage Media on which this SOP Instance resides.
	 * 
	 * @return String - String value of Storage Media File-Set ID.
	 */
	public String getStorageMediaFileSetID()
	{
		Object objValue = getValue(0x0088,0x0130);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Uniquely identifies a Storage Media on which this SOP Instance resides.
	 * 
	 * @param strStorageMediaFileSetID the string storage media file set id
	 */
	public void setStorageMediaFileSetUID(String strStorageMediaFileSetID)
	{
		/* Accept the Storage Media File-Set UID in String format of type UI.
		 * 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(0x0088, 0x0140, DicomConstants.DCM_DT_UI, strStorageMediaFileSetID);
	}

	/**
	 * Retrieves a Unique ID that identifies a Storage Media on which this SOP Instance resides.
	 * 
	 * @return String - String value of Storage Media File-Set UID.
	 */
	public String getStorageMediaFileSetUID()
	{
		Object objValue = getValue(0x0088,0x0140);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets the Specification whether or not to extract label information from the instances.
	 * 
	 * @param enumLabelUsingInformationExtractedFromInstances Enum value of Specification.
	 */
	public void setLabelUsingInformationExtractedFromInstances(EnumLabelUsingInformationExtractedFromInstances enumLabelUsingInformationExtractedFromInstances)
	{
		/* Accept LabelUsingInformationExtractedFromInstances 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(0x2200,0x0001, DicomConstants.DCM_DT_CS, enumLabelUsingInformationExtractedFromInstances.getValue());
	}

	/**
	 * Retrieves the Specification whether or not to extract label information from the instances.
	 * 
	 * @return String - String value of Specification.
	 */
	public String getLabelUsingInformationExtractedFromInstances()
	{
		Object objValue = getValue(0x2200,0x0001);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Unformatted free text to include in the label instead of or in addition to information extracted from the instances.
	 * 
	 * @param strLabelText String value of LabelText.
	 */
	public void setLabelText(String strLabelText)
	{
		/* Accept LabelText in String format of type UT.
		 * 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(0x2200,0x0002, DicomConstants.DCM_DT_UT, strLabelText);
	}

	/**
	 * Return Unformatted free text to include in the label instead of or in addition to information extracted from the instances.
	 * 
	 * @return String - String value of LabelText.
	 */
	public String getLabelText()
	{
		Object objValue = getValue(0x2200,0x0002);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Unformatted free text to include in the label instead of or in addition to information extracted from the instances.
	 * 
	 * @param strLabelStyleSelection String value of Unformatted free text.
	 */
	public void setLabelStyleSelection(String strLabelStyleSelection)
	{
		/* Accept LabelStyleSelection 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(0x2200,0x0003, DicomConstants.DCM_DT_CS, strLabelStyleSelection);
	}

	/**
	 * Return Unformatted free text to include in the label instead of or in addition to information extracted from the instances.
	 * 
	 * @return String - String value of Unformatted free text.
	 */
	public String getLabelStyleSelection()
	{
		Object objValue = getValue(0x2200,0x0003);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets String that describes the bar code value to be printed on the media label.
	 * 
	 * @param strBarcodeValue String Barcode Value.
	 */
	public void setBarcodeValue(String strBarcodeValue)
	{
		/* Accept BarcodeValue in String format of type LT.
		 * 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(0x2200,0x0005, DicomConstants.DCM_DT_LT, strBarcodeValue);
	}

	/**
	 * Return String that describes the bar code value to be printed on the media label.
	 * 
	 * @return String - String Barcode Value.
	 */
	public String getBarcodeValue()
	{
		Object objValue = getValue(0x2200,0x0005);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Code string that describes the bar code symbology that shall be used for printing the Barcode Value.
	 * 
	 * @param strBarcodeSymbology String bar code symbology.
	 */
	public void setBarcodeSymbology(String strBarcodeSymbology)
	{
		/* Accept BarcodeSymbology 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(0x2200,0x0006, DicomConstants.DCM_DT_CS, strBarcodeSymbology);
	}
	
	/**
	 * Sets Unstructured text that describes where and to whom the media is to be sent.
	 * 
	 * @param strMediaDisposition String value of Unstructured text.
	 */
	public void setMediaDisposition(String strMediaDisposition)
	{
		/* Accept MediaDisposition in String format of type LT.
		 * 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(0x2200,0x0004, DicomConstants.DCM_DT_LT, strMediaDisposition);
	}

	/**
	 * Return Unstructured text that describes where and to whom the media is to be sent.
	 * 
	 * @return String - String value of Unstructured text.
	 */
	public String getMediaDisposition()
	{
		Object objValue = getValue(0x2200,0x0004);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets A flag indicating if the SCP is allowed to split this request over more than one piece of media.
	 * 
	 * @param enumAllowMediaSplitting Enum value of flag.
	 */
	public void setAllowMediaSplitting(EnumAllowMediaSplitting enumAllowMediaSplitting)
	{
		/* Accept AllowMediaSplitting 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(0x2200,0x0007, DicomConstants.DCM_DT_CS, enumAllowMediaSplitting.getValue());
	}

	/**
	 * Retrieves A flag indicating if the SCP is allowed to split this request over more than one piece of media.
	 * 
	 * @return String - String value of flag.
	 */
	public String getAllowMediaSplitting()
	{
		Object objValue = getValue(0x2200,0x0007);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets A flag indicating if the SCP is allowed to perform lossy compression.
	 * 
	 * @param enumAllowLossyCompression Enum value of flag.
	 */
	public void setAllowLossyCompression(EnumAllowLossyCompression enumAllowLossyCompression)
	{
		/* Accept AllowLossyCompression 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(0x2200,0x000F, DicomConstants.DCM_DT_CS, enumAllowLossyCompression.getValue());
	}

	/**
	 * Retrieves A flag indicating if the SCP is allowed to perform lossy compression.
	 * 
	 * @return String - String value of flag.
	 */
	public String getAllowLossyCompression()
	{
		Object objValue = getValue(0x2200,0x000F);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets A flag indicating if the SCP should include in the media additional Non-DICOM information/objects.
	 * 
	 * @param enumIncludeNonDICOMObjects Enum value of flag.
	 */
	public void setIncludeNonDICOMObjects(EnumIncludeNonDICOMObjects enumIncludeNonDICOMObjects)
	{
		/* Accept IncludeNonDICOMObjects 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(0x2200,0x0008, DicomConstants.DCM_DT_CS, enumIncludeNonDICOMObjects.getValue());
	}

	/**
	 * Retrieves A flag indicating if the SCP should include in the media additional Non-DICOM information/objects.
	 * 
	 * @return String - String value of flag.
	 */
	public String getIncludeNonDICOMObjects()
	{
		Object objValue = getValue(0x2200,0x0008);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets A flag indicating if the SCP should include on the media a DICOM Instance Display Application.
	 * 
	 * @param enumIncludeDisplayApplication Enum value of flag.
	 */
	public void setIncludeDisplayApplication(EnumIncludeDisplayApplication enumIncludeDisplayApplication)
	{
		/* Accept IncludeDisplayApplication 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(0x2200,0x0009, DicomConstants.DCM_DT_CS, enumIncludeDisplayApplication.getValue());
	}

	/**
	 * Retrieves A flag indicating if the SCP should include on the media a DICOM Instance Display Application.
	 * 
	 * @return String - String value of flag.
	 */
	public String getIncludeDisplayApplication()
	{
		Object objValue = getValue(0x2200,0x0009);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets A flag indicating if the SCP should include on the media a DICOM Instance Display Application.
	 * 
	 * @param enumPreserveCompositeInstancesAfterMediaCreation Enum value of flag.
	 */
	public void setPreserveCompositeInstancesAfterMediaCreation(EnumPreserveCompositeInstancesAfterMediaCreation enumPreserveCompositeInstancesAfterMediaCreation)
	{
		/* Accept PreserveCompositeInstancesAfterMediaCreation 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(0x2200,0x000A, DicomConstants.DCM_DT_CS, enumPreserveCompositeInstancesAfterMediaCreation.getValue());
	}

	/**
	 * Retrieves A flag indicating if the SCP should include on the media a DICOM Instance Display Application.
	 * 
	 * @return String - String value of flag.
	 */
	public String getPreserveCompositeInstancesAfterMediaCreation()
	{
		Object objValue = getValue(0x2200,0x000A);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Retrieves pre-initialized object of ReferencedSOPSequence.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 ReferencedSOPSequence - instance of ReferencedSOPSequence.
	 */
	public ReferencedSOPSequence getReferencedSOPSequence()
	{
		ReferencedSOPSequence objReferencedSOPSequence = (ReferencedSOPSequence)getDicomValue(0x0008,0x1199);
		if(objReferencedSOPSequence == 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.
			 */
			ITransferSyntax objITransferSyntax = getDataSet().getTransferSyntax();
			IDictionaryReader objIDictionaryReader = getDataSet().getDictionaryReader();
			
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			objReferencedSOPSequence = (ReferencedSOPSequence)objDicomV3Factory.createSequence(0x0008,0x1199, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x0008,0x1199, DicomConstants.DCM_DT_SQ, objReferencedSOPSequence.getValue());
		}
		return objReferencedSOPSequence;
	}
	
	/**
	 * Populates the query Model using filled dataset.
	 */
	public void populate(IDataSet objIDataSet)
	{
		super.populate(objIDataSet);
	}	
	
	/**
	 * Fills the dataset using already populated Query Model.
	 */
	public void fill(IDataSet objIDataSet)
	{
		super.fill(objIDataSet);
	}
}
