/*******************************************************************************
 *  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 the methods to set, get and validate the attribute present in Patient Clinical Trial Participation Sequence .
 */

public class PatientClinicalTrialParticipationSequenceItem extends Item  
{
	

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


	/**
	 * This constructor creates the item with default TransferSyntax 
	 */
	PatientClinicalTrialParticipationSequenceItem()
	{
		super();
	}


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

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

	/**
	 * Validates all the attributes in Patient Clinical Trial Participation SequenceItem 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
		{
		}
		catch(MandatoryMissingException me)
		{
			if(DicomConfig.createInstance().isLoggingOn())
			{
				DicomLogger.getLogger().log(me.getMessage());
			}
			throw new InvalidItemException(this.getClass().getSimpleName(),me);
		}
		return true;
	}
	
	/**
	 * Sets Clinical Trial Sponsor Name.
	 * @param strClinicalTrialSponsorName String value of Clinical Trial Sponsor Name.
	 */
	public void setClinicalTrialSponsorName(String strClinicalTrialSponsorName)
	{
		/* Accept the Clinical Trial Sponsor Name 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 Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0012,0x0010, strClinicalTrialSponsorName,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0012,0x0010,DicomConstants.DCM_DT_LO, strClinicalTrialSponsorName);

		addDataElement(objIDataElement);
	}

	/**
	 * Return Clinical Trial Sponsor Name.
	 * @return String - value of Clinical Trial Sponsor Name.
	 */
	public String getClinicalTrialSponsorName()
	{
		Object objValue = getValue(0x0012,0x0010);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Clinical Trial Protocol ID.
	 * @param strClinicalTrialProtocolID String value of Clinical Trial Protocol ID.
	 */
	public void setClinicalTrialProtocolID(String strClinicalTrialProtocolID)
	{
		/* Accept the Clinical Trial Protocol ID 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 Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0012,0x0020, strClinicalTrialProtocolID,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0012,0x0020,DicomConstants.DCM_DT_LO, strClinicalTrialProtocolID);

		addDataElement(objIDataElement);
	}

	/**
	 * Return Clinical Trial Protocol ID.
	 * @return String - value of Clinical Trial Protocol ID.
	 */
	public String getClinicalTrialProtocolID()
	{
		Object objValue = getValue(0x0012,0x0020);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Clinical Trial Protocol Name.
	 * @param strClinicalTrialProtocolName String value of Clinical Trial Protocol Name.
	 */
	public void setClinicalTrialProtocolName(String strClinicalTrialProtocolName)
	{
		/* Accept the Clinical Trial Protocol Name 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 Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0012,0x0021, strClinicalTrialProtocolName,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0012,0x0021,DicomConstants.DCM_DT_LO, strClinicalTrialProtocolName);

		addDataElement(objIDataElement);
	}

	/**
	 * Return Clinical Trial Protocol Name.
	 * @return String - value of Clinical Trial Protocol Name.
	 */
	public String getClinicalTrialProtocolName()
	{
		Object objValue = getValue(0x0012,0x0021);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Clinical Trial Site ID.
	 * @param strClinicalTrialSiteID String value of Clinical Trial Site ID.
	 */
	public void setClinicalTrialSiteID(String strClinicalTrialSiteID)
	{
		/* Accept the Clinical Trial Site ID 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 Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0012,0x0030, strClinicalTrialSiteID,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0012,0x0030,DicomConstants.DCM_DT_LO, strClinicalTrialSiteID);

		addDataElement(objIDataElement);
	}

	/**
	 * Return Clinical Trial Site ID.
	 * @return String - value of Clinical Trial Site ID.
	 */
	public String getClinicalTrialSiteID()
	{
		Object objValue = getValue(0x0012,0x0030);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Clinical Trial Site Name.
	 * @param strClinicalTrialSiteName String value of Clinical Trial Site Name.
	 */
	public void setClinicalTrialSiteName(String strClinicalTrialSiteName)
	{
		/* Accept the Clinical Trial Site Name 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 Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0012,0x0031, strClinicalTrialSiteName,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0012,0x0031,DicomConstants.DCM_DT_LO, strClinicalTrialSiteName);

		addDataElement(objIDataElement);
	}

	/**
	 * Return Clinical Trial Site Name.
	 * @return String - value of Clinical Trial Site Name.
	 */
	public String getClinicalTrialSiteName()
	{
		Object objValue = getValue(0x0012,0x0031);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Clinical Trial Subject ID.
	 * @param strClinicalTrialSubjectID String value of Clinical Trial Subject ID.
	 */
	public void setClinicalTrialSubjectID(String strClinicalTrialSubjectID)
	{
		/* Accept the Clinical Trial Subject ID 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 Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0012,0x0040, strClinicalTrialSubjectID,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0012,0x0040,DicomConstants.DCM_DT_LO, strClinicalTrialSubjectID);

		addDataElement(objIDataElement);
	}

	/**
	 * Return Clinical Trial Subject ID.
	 * @return String - value of Clinical Trial Subject ID.
	 */
	public String getClinicalTrialSubjectID()
	{
		Object objValue = getValue(0x0012,0x0040);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Clinical Trial Subject Reading ID.
	 * @param strClinicalTrialSubjectReadingID String value of Clinical Trial Subject Reading ID.
	 */
	public void setClinicalTrialSubjectReadingID(String strClinicalTrialSubjectReadingID)
	{
		/* Accept the Clinical Trial Subject Reading ID 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 Data Set
		 */
		IDataElement objIDataElement = null;
		if(objITransferSyntax.getVRTransferSyntax() == DicomConstants.DCM_VR_IMPLICIT)
			objIDataElement = new ImplicitDE(0x0012,0x0042, strClinicalTrialSubjectReadingID,getDictionaryReader());
		else
			objIDataElement = new ExplicitDE(0x0012,0x0042,DicomConstants.DCM_DT_LO, strClinicalTrialSubjectReadingID);

		addDataElement(objIDataElement);
	}

	/**
	 * Return Clinical Trial Subject Reading ID.
	 * @return String - value of Clinical Trial Subject Reading ID.
	 */
	public String getClinicalTrialSubjectReadingID()
	{
		Object objValue = getValue(0x0012,0x0042);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
}
