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

import cdac.medinfo.sdk.dcm30_04.baselibs.DicomV3Factory;
import cdac.medinfo.sdk.dcm30_04.baselibs.ProposedStudySequence;
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.EnumFilmDestination;
import cdac.medinfo.sdk.dcm30_04.enums.EnumMediumType;
import cdac.medinfo.sdk.dcm30_04.enums.EnumPrintPriority;
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 NSetFilmSessionAttribute extends Attributes
{
	/**
	 * This is default Constructor for NSetFilmSessionAttribute.
	 */
	public NSetFilmSessionAttribute() {
		super();
	}
	/**
	 * Sets number of copies to be printed for each film of the film session.
	 * 
	 * @param strNumberOfCopies String value of Number Of Copies.
	 */
	public void setNumberOfCopies(String strNumberOfCopies)
	{
		/* Accept Number Of Copies in String format of type IS.
		 * 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(0x2000,0x0010, DicomConstants.DCM_DT_IS,strNumberOfCopies);
	}

	/**
	 * Sets the priority of the print job. Enumerated Values: HIGH, MED, LOW.
	 * 
	 * @param enumPrintPriority the enum print priority
	 */
	public void setPrintPriority(EnumPrintPriority enumPrintPriority)
	{
		/* Accept Print Priority 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(0x2000,0x0020, DicomConstants.DCM_DT_CS, enumPrintPriority.getValue());
	}

	/**
	 * Return the priority of the print job.
	 * 
	 * @return String - String value of Print Priority.
	 */
	public String getPrintPriority()
	{
		Object objValue = getValue(0x2000,0x0020);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Return number of copies to be printed for each film of the film session.
	 * 
	 * @return String - String value of Number Of Copies.
	 */
	public String getNumberOfCopies()
	{
		Object objValue = getValue(0x2000,0x0010);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets type of medium on which the print job will be printed.
	 * Defined Terms:PAPER, CLEAR FILM, BLUE FILM, MAMMO CLEAR FILM, MAMMO BLUE FILM.
	 * 
	 * @param enumMediumType the enum medium type
	 */
	public void setMediumType(EnumMediumType enumMediumType)
	{
		/* Accept Medium 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 Hash Map
		 */
		addDataElement(0x2000,0x0030, DicomConstants.DCM_DT_CS, enumMediumType.getValue());
	}

	/**
	 * Return type of medium on which the print job will be printed.
	 * 
	 * @return String -  String value of Medium Type.
	 */
	public String getMediumType()
	{
		Object objValue = getValue(0x2000,0x0030);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Film destination.
	 * Defined Terms:
	 * MAGAZINE  = the exposed film is stored in film magazine.
	 * PROCESSOR = the exposed film is developed in film processor.
	 * BIN_i     = the exposed film is deposited in a sorter bin where I represents the bin
	 * number. Film sorter BINs shall be numbered sequentially starting from
	 * one and no maximum is placed on the number of BINs. The encoding of the
	 * BIN number shall not contain leading zeros.
	 * 
	 * @param enumFilmDestination the enum film destination
	 */
	public void setFilmDestination(EnumFilmDestination  enumFilmDestination)
	{
		/* Accept Film Destination 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(0x2000,0x0040, DicomConstants.DCM_DT_CS, enumFilmDestination.getValue());
	}

	/**
	 * Return Film destination.
	 * 
	 * @return String -  String value of Film destination.
	 */
	public String getFilmDestination()
	{
		Object objValue = getValue(0x2000,0x0040);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets Human readable label that identifies the film session.
	 * 
	 * @param strFilmSessionLabel String value of Film Session Label.
	 */
	public void setFilmSessionLabel(String strFilmSessionLabel)
	{
		/* Accept Film Session Label 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(0x2000,0x0050, DicomConstants.DCM_DT_LO, strFilmSessionLabel);
	}

	/**
	 * Return Human readable label that identifies the film session.
	 * 
	 * @return String  String value of Film Session Label.
	 */
	public String getFilmSessionLabel()
	{
		Object objValue = getValue(0x2000,0x0050);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets Amount of memory allocated for the film session expressed in KB.
	 * 
	 * @param strMemoryAllocation String value of Memory Allocation.
	 */
	public void setMemoryAllocation(String strMemoryAllocation)
	{
		/* Accept Memory Allocation in String format of type IS.
		 * 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(0x2000,0x0060, DicomConstants.DCM_DT_IS, strMemoryAllocation);
	}

	/**
	 * Return Amount of memory allocated for the film session expressed in KB.
	 * 
	 * @return String - String value of Memory Allocation.
	 */
	public String getMemoryAllocation()
	{
		Object objValue = getValue(0x2000,0x0060);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets Identification of the owner of the film session.
	 * 
	 * @param strOwnerID - String value of Owner ID.
	 */
	public void setOwnerID(String strOwnerID)
	{
		/* Accept Owner 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 Hash Map
		 */
		addDataElement(0x2100,0x0160, DicomConstants.DCM_DT_SH, strOwnerID);
	}

	/**
	 * Return identification of the owner of the film session.
	 * 
	 * @return String - String value of Owner ID.
	 */
	public String getOwnerID()
	{
		Object objValue = getValue(0x2100,0x0160);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Retrieves A Sequence that contains attributes that may be used to identify Stored Print
	 * Storage and Hardcopy Image SOP Instances created to store this Film Session.
	 * 
	 * @return - instance of {@link ProposedStudySequence}
	 */
	public ProposedStudySequence getProposedStudySequence()
	{
		ProposedStudySequence objProposedStudySequence = (ProposedStudySequence)getDicomValue(0x2130,0x00A0);
		if(objProposedStudySequence == 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();
			objProposedStudySequence = (ProposedStudySequence)objDicomV3Factory.createSequence(0x2130,0x00A0, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x2130,0x00A0, DicomConstants.DCM_DT_SQ, objProposedStudySequence.getValue());
		}
		return objProposedStudySequence;
	}
	
	/**
	 * 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);
	}
}
