/*******************************************************************************
 *  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.exceptions.InvalidItemException;
import cdac.medinfo.sdk.dcm30_04.exceptions.MandatoryMissingException;
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 in {@link ReferencedDoseReferenceSequence}.
 */
public class ReferencedDoseReferenceSequenceItem extends Item  
{
	


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * This constructor creates the item and internal code sequence macro with default TransferSyntax.
	 */
	ReferencedDoseReferenceSequenceItem()
	{
		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. 
	 * @param objTransferSyntax specifies the DICOM Standard defined TransfeSyntax. 
	 */
	ReferencedDoseReferenceSequenceItem(ITransferSyntax objITransferSyntax)
	{
		super(objITransferSyntax);
	}

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

	/**
	 * Validates all the attributes in ReferencedDoseReferenceSequenceItem that are present in the DataSet.
	 * @return boolean - returns validation success as success or Failure
	 * @throws InvalidItemException throws InvalidItemException If Mandatory or Conditional element fails.
	 */
	public boolean validateForModule()  throws InvalidItemException
	{
		try{
			if(!contains(0x300C, 0x0051))
				throw new MandatoryMissingException("300C, 0051");

		}
		catch(MandatoryMissingException me)
		{
			if(DicomConfig.createInstance().isLoggingOn())
			{
				DicomLogger.getLogger().log(me.getMessage());
			}
			throw new InvalidItemException(this.getClass().getSimpleName(),me);
		}
		return true;
	}

	/**
	 * Sets Referenced Dose Reference Number .Uniquely identifies Dose Reference specified by Dose Reference Number (300A, 0012) in Dose Reference Sequence (300A, 0010) in RT Prescription Module of referenced RT Plan.
	 * @param strReferencedDoseReferenceNumber String value of Referenced Dose Reference Number.
	 */
	public void setReferencedDoseReferenceNumber(String strReferencedDoseReferenceNumber)
	{
		/*Accept the ReferencedDoseReferenceNumber 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 Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x300C,0x0051, strReferencedDoseReferenceNumber,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300C,0x0051,DicomConstants.DCM_DT_IS, strReferencedDoseReferenceNumber);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Referenced Dose Reference Number.
	 * @return String - value of Referenced Dose Reference Number.
	 */
	public String getReferencedDoseReferenceNumber()
	{
		Object objValue = getValue(0x300C,0x0051);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets value that describes relative importance of satisfying constraint, where high values represent
	 * more important constraints.
	 * @param strConstraintWeight String value of Constraint Weight.
	 */
	public void setConstraintWeight(String strConstraintWeight)
	{
		/*Accept the Constraint Weight in String format of type DS.
		 * 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,0x0021, strConstraintWeight,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x0021,DicomConstants.DCM_DT_DS, strConstraintWeight);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves value that describes relative importance of satisfying constraint, where high values represent
	 * more important constraints.
	 * @return String - value of Constraint Weight.
	 */
	public String getConstraintWeight()
	{
		Object objValue = getValue(0x300A,0x0021);
		if(objValue != null)
			return objValue.toString();
		return null;
	}	

	/**
	 * Sets the dose (in Gy) which when reached or exceeded should cause some action to be taken.
	 * @param strDeliveryWarningDose String value of Delivery Warning Dose.
	 */
	public void setDeliveryWarningDose(String strDeliveryWarningDose)
	{
		/*Accept the Delivery Warning Dose in String format of type DS.
		 * 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,0x0022, strDeliveryWarningDose,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x0022,DicomConstants.DCM_DT_DS, strDeliveryWarningDose);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the dose (in Gy) which when reached or exceeded should cause some action to be taken.
	 * @return String - value of Delivery Warning Dose.
	 */
	public String getDeliveryWarningDose()
	{
		Object objValue = getValue(0x300A,0x0022);
		if(objValue != null)
			return objValue.toString();
		return null;
	}	

	/**
	 * Sets the maximum dose (in Gy) which can be delivered to the dose reference.
	 * @param strDeliveryMaximumDose String value of Delivery Maximum Dose.
	 */
	public void setDeliveryMaximumDose(String strDeliveryMaximumDose)
	{
		/*Accept the Delivery Maximum Dose in String format of type DS.
		 * 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,0x0023, strDeliveryMaximumDose,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x0023,DicomConstants.DCM_DT_DS, strDeliveryMaximumDose);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves the maximum dose (in Gy) which can be delivered to the dose reference.
	 * @return String - value of Delivery Maximum Dose.
	 */
	public String getDeliveryMaximumDose()
	{
		Object objValue = getValue(0x300A,0x0023);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets minimum permitted dose (in Gy) to Dose Reference if Dose Reference Type (300A,0020) of referenced Dose Reference
	 * is TARGET.
	 * @param strTargetMinimumDose String value of Target Minimum Dose.
	 */
	public void setTargetMinimumDose(String strTargetMinimumDose)
	{
		/*Accept the Target Minimum Dose in String format of type DS.
		 * 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,0x0025, strTargetMinimumDose,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x0025,DicomConstants.DCM_DT_DS, strTargetMinimumDose);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves minimum permitted dose (in Gy) to Dose Reference if Dose Reference Type (300A,0020) of referenced Dose Reference
	 * is TARGET.
	 * @return String - value of Target Minimum Dose.
	 */
	public String getTargetMinimumDose()
	{
		Object objValue = getValue(0x300A,0x0025);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets prescribed dose (in Gy) to Dose Reference if Dose Reference Type (300A,0020) of
	 * referenced Dose Reference is TARGET.
	 * @param strTargetPrescriptionDose String value of Target Prescription Dose.
	 */
	public void setTargetPrescriptionDose(String strTargetPrescriptionDose)
	{
		/*Accept the Target Prescription Dose in String format of type DS.
		 * 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,0x0026, strTargetPrescriptionDose,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x0026,DicomConstants.DCM_DT_DS, strTargetPrescriptionDose);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves prescribed dose (in Gy) to Dose Reference if Dose Reference Type (300A,0020) of
	 * referenced Dose Reference is TARGET.
	 * @return String - value of Target Prescription Dose.
	 */
	public String getTargetPrescriptionDose()
	{
		Object objValue = getValue(0x300A,0x0026);
		if(objValue != null)
			return objValue.toString();
		return null;
	}


	/**
	 * Sets maximum permitted dose (in Gy) to Dose Reference if Dose Reference Type
	 * (300A,0020) of referenced Dose Reference is TARGET.
	 * @param strTargetMaximumDose String value of Target Maximum Dose.
	 */
	public void setTargetMaximumDose(String strTargetMaximumDose)
	{
		/*Accept the Target Prescription Dose in String format of type DS.
		 * 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,0x0027, strTargetMaximumDose,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x0027,DicomConstants.DCM_DT_DS, strTargetMaximumDose);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves maximum permitted dose (in Gy) to Dose Reference if Dose Reference Type
	 * (300A,0020) of referenced Dose Reference is TARGET.
	 * @return String - value of Target Maximum Dose.
	 */
	public String getTargetMaximumDose()
	{
		Object objValue = getValue(0x300A,0x0027);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets maximum permitted fraction (in percent) of Target to receive less than the Target
	 * Prescription Dose (300A,0027).
	 * @param strTargetUnderdoseVolumeFraction String value of Target Underdose Volume Fraction.
	 */
	public void setTargetUnderdoseVolumeFraction(String strTargetUnderdoseVolumeFraction)
	{
		/*Accept the Target Underdose Volume Fraction in String format of type DS.
		 * 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,0x0028, strTargetUnderdoseVolumeFraction,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x0028,DicomConstants.DCM_DT_DS, strTargetUnderdoseVolumeFraction);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves maximum permitted fraction (in percent) of Target to receive less than the Target
	 * Prescription Dose (300A,0027).
	 * @return String - value of Target Underdose Volume Fraction.
	 */
	public String getTargetUnderdoseVolumeFraction()
	{
		Object objValue = getValue(0x300A,0x0028);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets maximum dose (in Gy) to entire Dose Reference if Dose Reference Type
	 * (300A,0020) of referenced Dose Reference is ORGAN_AT_RISK and Dose Reference
	 * Structure Type (300A,0014) of referenced Dose Reference is VOLUME.
	 * @param strOrganAtRiskFullVolumeDose String value of Organ at Risk Full-volume Dose.
	 */
	public void setOrganAtRiskFullVolumeDose(String strOrganAtRiskFullVolumeDose)
	{
		/*Accept the Organ at Risk Full-volume Dose in String format of type DS.
		 * 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,0x002A, strOrganAtRiskFullVolumeDose,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x002A,DicomConstants.DCM_DT_DS, strOrganAtRiskFullVolumeDose);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves maximum dose (in Gy) to entire Dose Reference if Dose Reference Type
	 * (300A,0020) of referenced Dose Reference is ORGAN_AT_RISK and Dose Reference
	 * Structure Type (300A,0014) of referenced Dose Reference is VOLUME.
	 * @return String - value of Organ at Risk Full-volume Dose.
	 */
	public String getOrganAtRiskFullVolumeDose()
	{
		Object objValue = getValue(0x300A,0x002A);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets maximum permitted dose (in Gy) to any part of Dose Reference if Dose Reference
	 *  Type (300A,0020) of referenced Dose Reference is ORGAN_AT_RISK and Dose
	 *  Reference Structure Type (300A,0014) of referenced Dose Reference is VOLUME.
	 * @param strOrganAtRiskLimitDose String value of Organ at Organ at Risk Limit Dose.
	 */
	public void setOrganAtRiskLimitDose(String strOrganAtRiskLimitDose)
	{
		/*Accept the Organ at Risk Limit Dose in String format of type DS.
		 * 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,0x002B, strOrganAtRiskLimitDose,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x002B,DicomConstants.DCM_DT_DS, strOrganAtRiskLimitDose);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves maximum permitted dose (in Gy) to any part of Dose Reference if Dose Reference
	 *  Type (300A,0020) of referenced Dose Reference is ORGAN_AT_RISK and Dose
	 *  Reference Structure Type (300A,0014) of referenced Dose Reference is VOLUME.
	 * @return String - value of Organ at Organ at Risk Limit Dose.
	 */
	public String getOrganAtRiskLimitDose()
	{
		Object objValue = getValue(0x300A,0x002B);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets maximum dose (in Gy) to non-overdosed part of Dose Reference if Dose Reference
	 * Type (300A,0020) of referenced Dose Reference is ORGAN_AT_RISK and Dose
	 * Reference Structure Type (300A,0014) of referenced Dose Reference is VOLUME.
	 * @param strOrganAtRiskMaximumDose String value of Organ at Organ at Risk Maximum Dose.
	 */
	public void setOrganAtRiskMaximumDose(String strOrganAtRiskMaximumDose)
	{
		/*Accept the Organ at Risk Maximum Dose in String format of type DS.
		 * 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,0x002C, strOrganAtRiskMaximumDose,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x002C,DicomConstants.DCM_DT_DS, strOrganAtRiskMaximumDose);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves maximum dose (in Gy) to non-overdosed part of Dose Reference if Dose Reference
	 * Type (300A,0020) of referenced Dose Reference is ORGAN_AT_RISK and Dose
	 * Reference Structure Type (300A,0014) of referenced Dose Reference is VOLUME.
	 * @return String - value of Organ at Organ at Risk Maximum Dose.
	 */
	public String getOrganAtRiskMaximumDose()
	{
		Object objValue = getValue(0x300A,0x002C);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets maximum permitted fraction (in percent) of Organ at Risk to receive more than the
	 *  Organ at Risk Maximum Dose if Dose Reference Type (300A,0020) of referenced
	 *  Dose Reference is ORGAN_AT_RISK and Dose Reference Structure Type
	 *  (300A,0014) of referenced Dose Reference is VOLUME.
	 * @param strOrganAtRiskOverdoseVolumeFraction String value of Organ at Organ at Risk Overdose Volume Fraction.
	 */
	public void setOrganAtRiskOverdoseVolumeFraction(String strOrganAtRiskOverdoseVolumeFraction)
	{
		/*Accept the Organ at Risk Overdose Volume Fraction in String format of type DS.
		 * 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,0x002D, strOrganAtRiskOverdoseVolumeFraction,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x002D,DicomConstants.DCM_DT_DS, strOrganAtRiskOverdoseVolumeFraction);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves maximum permitted fraction (in percent) of Organ at Risk to receive more than the
	 *  Organ at Risk Maximum Dose if Dose Reference Type (300A,0020) of referenced
	 *  Dose Reference is ORGAN_AT_RISK and Dose Reference Structure Type
	 *  (300A,0014) of referenced Dose Reference is VOLUME.
	 * @return String - value of Organ at Organ at Risk Overdose Volume Fraction.
	 */
	public String getOrganAtRiskOverdoseVolumeFraction()
	{
		Object objValue = getValue(0x300A,0x002D);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Sets Coefficient used to calculate cumulative dose contribution from this Beam to the referenced Dose Reference at the current Control Point.
	 * @param strCumulativeDoseReferenceCoefficient String value of Cumulative Dose Reference Coefficient.
	 */
	public void setCumulativeDoseReferenceCoefficient(String strCumulativeDoseReferenceCoefficient)
	{
		/*Accept the Cumulative Dose Reference Coefficient in String format of type DS.
		 * 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,0x010C, strCumulativeDoseReferenceCoefficient,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x300A,0x010C,DicomConstants.DCM_DT_DS, strCumulativeDoseReferenceCoefficient);

		addDataElement(objIDataElement);
	}
	/**
	 * Retrieves Coefficient used to calculate cumulative dose contribution from this Beam to the referenced Dose Reference at the current Control Point.
	 * @return String - value of String value of Cumulative Dose Reference Coefficient.
	 */
	public String getCumulativeDoseReferenceCoefficient()
	{
		Object objValue = getValue(0x300A,0x010C);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
}
