/*******************************************************************************
 *  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.EnumCatchTrialsDataFlag;
import cdac.medinfo.sdk.dcm30_04.enums.EnumExcessiveFalseNegatives;
import cdac.medinfo.sdk.dcm30_04.enums.EnumExcessiveFalseNegativesDataFlag;
import cdac.medinfo.sdk.dcm30_04.enums.EnumExcessiveFalsePositives;
import cdac.medinfo.sdk.dcm30_04.enums.EnumExcessiveFalsePositivesDataFlag;
import cdac.medinfo.sdk.dcm30_04.enums.EnumFalseNegativesEstimateFlag;
import cdac.medinfo.sdk.dcm30_04.enums.EnumFalsePositivesEstimateFlag;
import cdac.medinfo.sdk.dcm30_04.exceptions.ConditionFailedException;
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 Visual Field Catch Trial Sequence {@link VisualFieldCatchTrialSequence }.
 */

public class VisualFieldCatchTrialSequenceItem extends Item
{
	

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

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

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

	/**
	 * This constructor creates Verifying Observer Sequence Item with specified TransferSyntax and
	 * specified DictionaryReader
	 * @param objTransferSyntax specifies the DICOM Standard defined TransfeSyntax
	 * @param objDictionaryReader specifies the DICOM Dictionary reader to be used 
	 */
	VisualFieldCatchTrialSequenceItem(ITransferSyntax objTransferSyntax, IDictionaryReader objDictionaryReader)
	{
		super(objTransferSyntax,objDictionaryReader);
	}
	/**
	 * Validates all the attributes in {@link VisualFieldCatchTrialSequenceItem} 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(0x0024,0x0055))
				throw new MandatoryMissingException("0024,0055");
			if(!contains(0x0024,0x0045))
				throw new MandatoryMissingException("(0024,0045");
			if(!contains(0x0024,0x0051))
				throw new MandatoryMissingException("0024,0051");
			if(!contains(0x0024,0x0053))
				throw new MandatoryMissingException("0024,0053");
			if(!contains(0x0024,0x0061))
				throw new MandatoryMissingException("0024,0061");
			if(getDataForTag(0x0024, 0x0055).getValue().toString().equals(EnumCatchTrialsDataFlag.YES))
				if(!contains(0x0024,0x0048))
					throw new ConditionFailedException("value for conditional Element (0024,0048) required if value of Catch Trials Data Flag (0024,0055) is YES.");
			if(getDataForTag(0x0024, 0x0055).getValue().toString().equals(EnumCatchTrialsDataFlag.YES))
				if(!contains(0x0024,0x0050))
					throw new ConditionFailedException("value for conditional Element (0024,0050) required if value of Catch Trials Data Flag (0024,0055) is YES.");
			if(getDataForTag(0x0024, 0x0045).getValue().toString().equals(EnumFalseNegativesEstimateFlag.YES))
				if(!contains(0x0024,0x0046))
					throw new ConditionFailedException("value for conditional Element (0024,0046) required if value of False Negatives Estimate Flag (0024,0045) is YES.");
			if(getDataForTag(0x0024, 0x0051).getValue().toString().equals(EnumExcessiveFalseNegativesDataFlag.YES))
				if(!contains(0x0024,0x0052))
					throw new ConditionFailedException("value for conditional Element (0024,0052) required if value of Excessive False Negatives Data Flag (0024,0051) is YES.");
			if(getDataForTag(0x0024, 0x0055).getValue().toString().equals(EnumCatchTrialsDataFlag.YES))
				if(!contains(0x0024,0x0056))
					throw new ConditionFailedException("value for conditional Element (0024,0056) required if value of Catch Trials Data Flag (0024,0055) is YES.");
			if(getDataForTag(0x0024, 0x0055).getValue().toString().equals(EnumCatchTrialsDataFlag.YES))
				if(!contains(0x0024,0x0060))
					throw new ConditionFailedException("value for conditional Element (0024,0060) required if value of Catch Trials Data Flag (0024,0055) is YES.");
			if(getDataForTag(0x0024, 0x0053).getValue().toString().equals(EnumFalsePositivesEstimateFlag.YES))
				if(!contains(0x0024,0x0054))
					throw new ConditionFailedException("value for conditional Element (0024,0054) required if value of False Positives Estimate Flag (0024,0053) is YES.");
			if(getDataForTag(0x0024, 0x0061).getValue().toString().equals(EnumExcessiveFalsePositivesDataFlag.YES))
				if(!contains(0x0024,0x0062))
					throw new ConditionFailedException("value for conditional Element (0024,0062) required if value of Excessive False Positives Data Flag (0024,0061) is YES.");
		
		}
		catch(MandatoryMissingException me)
		{
			if(DicomConfig.createInstance().isLoggingOn())
			{
				DicomLogger.getLogger().log(me.getMessage());
			}
			throw new ValidationException(this.getClass().getSimpleName(),me);
		}
		return true;
	}
	/**
	 * Sets whether catch trials data were performed.
	 *Enumerated Values:
	 *YES
	 *NO
	 * @param enumCatchTrialsDataFlag enum value of Catch Trials Data Flag
	 */
	public void setCatchTrialsDataFlag(EnumCatchTrialsDataFlag enumCatchTrialsDataFlag)
	{
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0024,0x0055, enumCatchTrialsDataFlag.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0024,0x0055,DicomConstants.DCM_DT_CS, enumCatchTrialsDataFlag.getValue());

		addDataElement(objIDataElement);
	}
	/**
	 * Returns Catch Trials Data Flag.
	 * @return String - value of Catch Trials Data Flag.
	 */
	public String getCatchTrialsDataFlag()
	{
		Object objValue = getValue(0x0024,0x0055);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	/**
	 * Sets Total number of times the patient's visual attention was tested usingstimuli brighter than previously seen luminance (negative catchtrials).
	 * @param shNegativeCatchTrialsQuantity short value of Negative Catch Trials Quantity
	 */
	public void setNegativeCatchTrialsQuantity(short shNegativeCatchTrialsQuantity)
	{
		/* Accept the Negative Catch Trials Quantity of type US.
		 * 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(0x0024,0x0048,shNegativeCatchTrialsQuantity,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0024,0x0048,DicomConstants.DCM_DT_US, shNegativeCatchTrialsQuantity);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Total number of times the patient's visual attention was tested usingstimuli brighter than previously seen luminance (negative catchtrials).
	 * @return short - short value of Negative Catch Trials Quantity
	 */
	public short getNegativeCatchTrialsQuantity()
	{
		Object objValue = getValue(0x0024,0x0048);
		if(objValue != null)
			return Short.parseShort(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	/**
	 * Sets Total number of stimuli that were not seen by the patient but werepreviously seen at a lower luminance earlier in the visual field test(false negatives).
	 * @param shFalseNegativesQuantity short value of Negative Catch Trials Quantity
	 */
	public void setFalseNegativesQuantity(short shFalseNegativesQuantity)
	{
		/* Accept the FalseNegativesQuantity of type US.
		 * 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(0x0024,0x0050,shFalseNegativesQuantity,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0024,0x0050,DicomConstants.DCM_DT_US, shFalseNegativesQuantity);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Total number of stimuli that were not seen by the patient but werepreviously seen at a lower luminance earlier in the visual field test(false negatives).
	 * @return short - short value of FalseNegativesQuantity
	 */
	public short getFalseNegativesQuantity()
	{
		Object objValue = getValue(0x0024,0x0050);
		if(objValue != null)
			return Short.parseShort(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	/**
	 * Sets whether False Negatives Estimate Flag  were performed.
	 *Enumerated Values:
	 *YES
	 *NO
	 * @param enumFalseNegativesEstimateFlag  enum value of False Negatives Estimate Flag 
	 */
	public void setFalseNegativesEstimateFlag (EnumFalseNegativesEstimateFlag enumFalseNegativesEstimateFlag)
	{
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0024,0x0045, enumFalseNegativesEstimateFlag.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0024,0x0045,DicomConstants.DCM_DT_CS, enumFalseNegativesEstimateFlag.getValue());

		addDataElement(objIDataElement);
	}
	/**
	 * Returns Catch Trials Data Flag.
	 * @return String - value of Catch Trials Data Flag.
	 */
	public String getFalseNegativesEstimateFlag ()
	{
		Object objValue = getValue(0x0024,0x0045);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets estimated percentage of all stimuli that were not seen by the patientbut were previously seen at a lower luminance earlier in the visualfield test (false negative responses), as percent.
	 * @param shFalseNegativesEstimate short value of False Negatives Estimate.
	 */
	public void setFalseNegativesEstimate(short shFalseNegativesEstimate)
	{
		/* Accept the False Negatives Estimate of type FL.
		 * 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(0x0024,0x0046,shFalseNegativesEstimate,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0024,0x0046,DicomConstants.DCM_DT_FL, shFalseNegativesEstimate);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the estimated percentage of all stimuli that were not seen by the patientbut were previously seen at a lower luminance earlier in the visualfield test (false negative responses), as percent.
	 * @return short - short value of False Negatives Estimate.
	 */
	public short getFalseNegativesEstimate()
	{
		Object objValue = getValue(0x0024,0x0046);
		if(objValue != null)
			return Short.parseShort(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	/**
	 * Sets whether Excessive False Negatives Data Flag were performed.
	 *Enumerated Values:
	 *YES
	 *NO
	 * @param enumExcessiveFalseNegativesDataFlag  enum value of Excessive False Negatives Data Flag
	 */
	public void setExcessiveFalseNegativesDataFlag(EnumExcessiveFalseNegativesDataFlag enumExcessiveFalseNegativesDataFlag)
	{
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0024,0x0051, enumExcessiveFalseNegativesDataFlag.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0024,0x0051,DicomConstants.DCM_DT_CS, enumExcessiveFalseNegativesDataFlag.getValue());

		addDataElement(objIDataElement);
	}
	/**
	 * Returns Excessive False Negatives Data Flag
	 * @return String - value of Excessive False Negatives Data Flag.
	 */
	public String getExcessiveFalseNegativesDataFlag()
	{
		Object objValue = getValue(0x0024,0x0051);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	/**
	 * Sets whether Excessive False Negatives were performed.
	 *Enumerated Values:
	 *YES
	 *NO
	 * @param enumExcessiveFalseNegatives  enum value of Excessive False Negatives
	 */
	public void setExcessiveFalseNegatives(EnumExcessiveFalseNegatives enumExcessiveFalseNegatives)
	{
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0024,0x0052, enumExcessiveFalseNegatives.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0024,0x0052,DicomConstants.DCM_DT_CS, enumExcessiveFalseNegatives.getValue());

		addDataElement(objIDataElement);
	}
	/**
	 * Returns Excessive False Negatives
	 * @return String - value of Excessive False Negatives
	 */
	public String getExcessiveFalseNegatives()
	{
		Object objValue = getValue(0x0024,0x0052);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	/**
	 * Sets the total number of times the device behaved as if it was going topresent a visual stimulus but did not actually present the stimulus(positive catch trials).
	 *  @param shPositiveCatchTrialsQuantity short value of Positive Catch Trials Quantity
	 */
	public void setPositiveCatchTrialsQuantity(short shPositiveCatchTrialsQuantity)
	{
		/* Accept the Positive Catch Trials Quantity of type US.
		 * 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(0x0024,0x0056,shPositiveCatchTrialsQuantity,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0024,0x0056,DicomConstants.DCM_DT_US, shPositiveCatchTrialsQuantity);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the total number of times the device behaved as if it was going topresent a visual stimulus but did not actually present the stimulus(positive catch trials).
	 *  @return short - short value of Positive Catch Trials Quantity
	 */
	public short getPositiveCatchTrialsQuantity()
	{
		Object objValue = getValue(0x0024,0x0056);
		if(objValue != null)
			return Short.parseShort(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	/**
	 * Sets the total number of patient responses that occurred at a time whenno visual stimulus was present (false positive responses).
	 * @param shFalsePositivesQuantity short value of False Positives Quantity
	 */
	public void setFalsePositivesQuantity(short shFalsePositivesQuantity)
	{
		/* Accept the False Positives Quantity of type US.
		 * 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(0x0024,0x0060,shFalsePositivesQuantity,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0024,0x0060,DicomConstants.DCM_DT_US, shFalsePositivesQuantity);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the total number of patient responses that occurred at a time when no visual stimulus was present (false positive responses).
	 * @return short - short value of False Positives Quantity
	 */
	public short getFalsePositivesQuantity()
	{
		Object objValue = getValue(0x0024,0x0060);
		if(objValue != null)
			return Short.parseShort(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	/**
	 * Sets whether False Positives Estimate Flag were performed.
	 *Enumerated Values:
	 *YES
	 *NO
	 * @param enumFalsePositivesEstimateFlag enum value of False Positives Estimate Flag
	 */
	public void setFalsePositivesEstimateFlag(EnumFalsePositivesEstimateFlag enumFalsePositivesEstimateFlag)
	{
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0024,0x0053, enumFalsePositivesEstimateFlag.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0024,0x0053,DicomConstants.DCM_DT_CS, enumFalsePositivesEstimateFlag.getValue());

		addDataElement(objIDataElement);
	}
	/**
	 * Returns False Positives Estimate Flag
	 * @return String - value of False Positives Estimate Flag
	 */
	public String getFalsePositivesEstimateFlag()
	{
		Object objValue = getValue(0x0024,0x0053);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets the estimated percentage of all patient responses that occurred at atime when no visual stimulus was present (false positive responses),as percent.
	 * @param shFalsePositivesEstimate value of FalsePositivesEstimate
	 */
	public void setFalsePositivesEstimate(short shFalsePositivesEstimate)
	{
		/* Accept the FalsePositivesEstimate of type US.
		 * 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(0x0024,0x0054,shFalsePositivesEstimate,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0024,0x0054,DicomConstants.DCM_DT_US, shFalsePositivesEstimate);
	
		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the estimated percentage of all patient responses that occurred at atime when no visual stimulus was present (false positive responses),as percent.
	 * @return short - short value of FalsePositivesEstimate
	 */
	public short getFalsePositivesEstimate()
	{
		Object objValue = getValue(0x0024,0x0054);
		if(objValue != null)
			return Short.parseShort(objValue.toString());
		return DicomConstants.DCM_NO_VALUE;
	}
	/**
	 * Sets whether Excessive False Positives Data Flag were performed.
	 *Enumerated Values:
	 *YES
	 *NO
	 * @param enumExcessiveFalsePositivesDataFlag  enum value of ExcessiveFalsePositivesDataFlag
	 */
	public void setExcessiveFalsePositivesDataFlag(EnumExcessiveFalsePositivesDataFlag enumExcessiveFalsePositivesDataFlag)
	{
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0024,0x0061, enumExcessiveFalsePositivesDataFlag.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0024,0x0061,DicomConstants.DCM_DT_CS, enumExcessiveFalsePositivesDataFlag.getValue());

		addDataElement(objIDataElement);
	}
	/**
	 * Returns ExcessiveFalsePositivesDataFlag
	 * @return String - value of ExcessiveFalsePositivesDataFlag
	 */
	public String getExcessiveFalsePositivesDataFlag()
	{
		Object objValue = getValue(0x0024,0x0061);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	/**
	 * Sets whether Excessive False Positives were performed.
	 *Enumerated Values:
	 *YES
	 *NO
	 * @param enumExcessiveFalsePositives  enum value of ExcessiveFalsePositives
	 */
	public void setExcessiveFalsePositives(EnumExcessiveFalsePositives enumExcessiveFalsePositives)
	{
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0024,0x0062, enumExcessiveFalsePositives.getValue(),getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0024,0x0062,DicomConstants.DCM_DT_CS, enumExcessiveFalsePositives.getValue());

		addDataElement(objIDataElement);
	}
	/**
	 * Returns ExcessiveFalsePositives
	 * @return String - value of ExcessiveFalsePositives
	 */
	public String getExcessiveFalsePositives()
	{
		Object objValue = getValue(0x0024,0x0062);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
		
}
