/*******************************************************************************
 *  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.dicommodel.modules;



import cdac.medinfo.sdk.dcm30_04.baselibs.DicomV3Factory;
import cdac.medinfo.sdk.dcm30_04.baselibs.IntendedRecipientsofResultsIdentificationSequence;
import cdac.medinfo.sdk.dcm30_04.baselibs.ReasonForRequestedProcedureCodeSequence;
import cdac.medinfo.sdk.dcm30_04.baselibs.ReferencedStudySequence;
import cdac.medinfo.sdk.dcm30_04.baselibs.RequestedProcedureCodeSequence;
import cdac.medinfo.sdk.dcm30_04.baselibs.Tag;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITag;
import cdac.medinfo.sdk.dcm30_04.exceptions.InvalidModuleException;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConstants;
import cdac.medinfo.sdk.dcm30_04.utils.ISingleCollection;
import cdac.medinfo.sdk.dcm30_04.utils.SingleCollection;

/**
 \* This module describes the attributes in Requested Procedure Module.
 */
public class RequestedProcedureModule extends Module
{

	
	/**
	 * The obj single collection.
	 */
	public static ISingleCollection<ITag> objSingleCollection = null;
	
	/**
	 * Creates Imaging Service Request Module with default initialization.
	 * @param objIDataSet the obj i data set
	 */
	public RequestedProcedureModule(IDataSet objIDataSet)
	{
		super(objIDataSet);
	}
	
	static
	{
		objSingleCollection = new SingleCollection<ITag>();
		objSingleCollection.add(new Tag(0x0040,0x1001));
		objSingleCollection.add(new Tag(0x0040,0x1002));
		objSingleCollection.add(new Tag(0x0040,0x1400));
		objSingleCollection.add(new Tag(0x0040,0x100A));
		objSingleCollection.add(new Tag(0x0032,0x1064));
		objSingleCollection.add(new Tag(0x0020,0x000D));
		objSingleCollection.add(new Tag(0x0008,0x0020));
		objSingleCollection.add(new Tag(0x0008,0x0030));
		objSingleCollection.add(new Tag(0x0008,0x1110));
		objSingleCollection.add(new Tag(0x0032,0x1060));
		objSingleCollection.add(new Tag(0x0040,0x1003));
		objSingleCollection.add(new Tag(0x0040,0x1004));
		objSingleCollection.add(new Tag(0x0040,0x1005));
		objSingleCollection.add(new Tag(0x0040,0x1008));
		objSingleCollection.add(new Tag(0x0040,0x1009));
		objSingleCollection.add(new Tag(0x0040,0x1010));
		objSingleCollection.add(new Tag(0x0040,0x1011));
	}
	
	/**
	 * This method validates each Attribute in the Module according to the Type
	 * of the Attribute.Attributes are of 5 types.
	 * Type 1,Type 2 are Mandatory:
	 * Mandatory Attributes have to present in the Module.
	 * Type 1C,2C are Conditional:
	 * Conditional Attributes' presence depend on a condition.
	 * If the condition is satisfied the Attribute has to be present.
	 * Type 3 are Optional
	 * Optional Attributes can be added as and when required.
	 * @return true, if validate module
	 * @throws InvalidModuleException - If validation of Module fails
	 */
	public boolean validateModule()throws InvalidModuleException
	{
		//All Attributes are optional.
		return true;
	}
	
	/**
	 * This method returns the vector of keys representing the DataElements
	 * that belong to this module.
	 * @return vector of Tags - returns the vector containing the collection of tags
	 */
	public ISingleCollection<ITag> getVectorOfKeys()
	{
		return objSingleCollection;
	}
	
	/**
	 * Sets Identifier that identifies the Requested Procedure in the Imaging Service Request.
	 * @param StrRequestedProcedureID
	 */
	public void setRequestedProcedureID(String StrRequestedProcedureID)
	{
		/* Accept Identifier in String format of type SH.
		 * Read the Transfer Syntax and check to create ImplicitDE or ExplicitDE .
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Hash Map
		 */
		addDataElement(0x0040,0x1001, DicomConstants.DCM_DT_SH, StrRequestedProcedureID);
		
	}
	
	/**
	 * Retrieves Identifier that identifies the Requested Procedure in the Imaging Service Request.
	 * @return String - Identifier that identifies the Requested Procedure in the Imaging Service Request.
	 */
	public String getRequestedProcedureID()
	{
		Object objValue = getValue(0x0040,0x1001);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Reason for requesting this imaging procedure.
	 * @param StrReasonfortheRequestedProcedure Reason for requesting this imaging procedure.
	 */
	public void setReasonfortheRequestedProcedure(String StrReasonfortheRequestedProcedure)
	{
		/* Accept imaging procedure in String format of type LO.
		 * Read the Transfer Syntax and check to create ImplicitDE or ExplicitDE .
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Hash Map
		 */
		addDataElement(0x0040,0x1002, DicomConstants.DCM_DT_LO, StrReasonfortheRequestedProcedure);
		
	}
	
	/**
	 * Sets Reason for requesting this imaging procedure.
	 * @return String - Reason for requesting this imaging procedure.
	 */
	public String getReasonfortheRequestedProcedure()
	{
		Object objValue = getValue(0x0040,0x1002);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets User-defined comments on the Requested Procedure.
	 * @param StrRequestedProcedureComments User-defined comments on the Requested Procedure.
	 */
	public void setRequestedProcedureComments(String StrRequestedProcedureComments)
	{
		/* Accept user-defined comments on the Requested Procedure in String format of type LT.
		 * Read the Transfer Syntax and check to create ImplicitDE or ExplicitDE .
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Hash Map
		 */
		addDataElement(0x0040,0x1400, DicomConstants.DCM_DT_LT, StrRequestedProcedureComments);
		
	}
	
	/**
	 * Retrieves User-defined comments on the Requested Procedure.
	 * @return String - User-defined comments on the Requested Procedure.
	 */
	public String setRequestedProcedureComments()
	{
		Object objValue = getValue(0x0040,0x1400);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Retrieves Coded Reason for requesting this procedure.
	 * @return ReasonForRequestedProcedureCodeSequence - instance of ReasonForRequestedProcedureCodeSequence.
	 */
	public ReasonForRequestedProcedureCodeSequence getReasonforRequestedProcedureCodeSequence()
	{
		ReasonForRequestedProcedureCodeSequence objReasonForRequestedProcedureCodeSequence = (ReasonForRequestedProcedureCodeSequence)getDicomValue(0x0040,0x100A);
		if(objReasonForRequestedProcedureCodeSequence == 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.
			 */
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			objReasonForRequestedProcedureCodeSequence = (ReasonForRequestedProcedureCodeSequence)objDicomV3Factory.createSequence(0x0040,0x100A, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x0040,0x100A, DicomConstants.DCM_DT_SQ, objReasonForRequestedProcedureCodeSequence.getValue());
		}
		return objReasonForRequestedProcedureCodeSequence;
	}
	
	
	/**
	 * Retrieves sequence that conveys the Requested Procedure of one Procedure Type.
	 * @return RequestedProcedureCodeSequence - sequence that conveys the Requested Procedure of one Procedure Type.
	 */
	public RequestedProcedureCodeSequence getRequestedProcedureCodeSequence()
	{
		RequestedProcedureCodeSequence objRequestedProcedureCodeSequence = (RequestedProcedureCodeSequence)getDicomValue(0x0032,0x1064);
		if(objRequestedProcedureCodeSequence == 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.
			 */
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			objRequestedProcedureCodeSequence = (RequestedProcedureCodeSequence)objDicomV3Factory.createSequence(0x0032,0x1064, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x0032,0x1064, DicomConstants.DCM_DT_SQ, objRequestedProcedureCodeSequence.getValue());
		}
		return objRequestedProcedureCodeSequence;
	}
	
	/**
	 * Sets Unique identifier to be used to identify the Study
	 * @param StrStudyInstanceUID Unique identifier to be used to identify the Study
	 */
	public void setStudyInstanceUID(String StrStudyInstanceUID)
	{
		/* Accept Unique identifier for the Study 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 Hash Map
		 */
		addDataElement(0x0020, 0x000D, DicomConstants.DCM_DT_UI, StrStudyInstanceUID);
	}
	
	/**
	 * Retrieves Unique identifier to be used to identify the Study
	 * @return String Unique identifier to be used to identify the Study
	 */
	public String getStudyInstanceUID()
	{
		Object objValue = getValue(0x0020,0x000D);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Date the Study started, if any previous procedure steps 
	 * within the same study have already been performed.
	 * 
	 * @param strStudyDate String value of Study Date.
	 */
	public void setStudyDate(String strStudyDate)
	{
		/*Accept Study Date in String format of type DA.
		 * 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(0x0008, 0x0020, DicomConstants.DCM_DT_DA, strStudyDate);
	}

	/**
	 * Retrieves Study Date.
	 * 
	 * @return the Study Date
	 */ 
	public String getStudyDate()
	{
		Object objValue = getValue(0x0008,0x0020);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Time the Study started, if any previous procedure steps 
	 * within the same study have already been performed.
	 * 
	 * @param strStudyTime String value of Study Time.
	 */
	public void setStudyTime(String strStudyTime)
	{
		/* Accept Study Time in String format of type TM.
		 * 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(0x0008, 0x0030, DicomConstants.DCM_DT_TM, strStudyTime);
	}

	/**
	 * Retrieves Study Time.
	 * 
	 * @return the Study Time
	 */ 
	public String getStudyTime()
	{
		Object objValue = getValue(0x0008,0x0030);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Retrieves Uniquely identifies the Study SOP Instances associated with this SOP Instance.
	 * @return String - Uniquely identifies the Study SOP Instances associated with this SOP Instance.
	 */
	public ReferencedStudySequence getReferencedStudySequence()
	{
		ReferencedStudySequence objReferencedStudySequence = (ReferencedStudySequence)getDicomValue(0x0008, 0x1110);
		if(objReferencedStudySequence == 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.
			 */
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			objReferencedStudySequence = (ReferencedStudySequence)objDicomV3Factory.createSequence(0x0008, 0x1110, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x0008, 0x1110, DicomConstants.DCM_DT_SQ, objReferencedStudySequence.getValue());
		}
		return objReferencedStudySequence;
	}
	
	/**
	 * Sets Institution-generated administrative description or classification of Requested Procedure
	 * @param StrRequestedProcedureDescription Institution-generated administrative description or classification of Requested Procedure
	 */
	public void setRequestedProcedureDescription(String StrRequestedProcedureDescription)
	{
		/* Accept Institution-generated administrative description in String format of type LO.
		 * Read the Transfer Syntax and check to create ImplicitDE or ExplicitDE .
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Hash Map
		 */
		addDataElement(0x0032,0x1060, DicomConstants.DCM_DT_LO, StrRequestedProcedureDescription);
		
	}
	
	/**
	 * Retrieves Institution-generated administrative description or classification of Requested Procedure
	 * @return String - Institution-generated administrative description or classification of Requested Procedure
	 */
	public String getRequestedProcedureDescription()
	{
		Object objValue = getValue(0x0032,0x1060);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Requested Procedure Type Urgency. Defined Terms: STAT, HIGH, ROUTINE, MEDIUM, LOW
	 * @param strRequestedProcedurePriority Requested Procedure Type Urgency
	 */
	public void setRequestedProcedurePriority(String strRequestedProcedurePriority)
	{
		/* Accept Requested Procedure Type Urgency in String format of type SH.
		 * Read the Transfer Syntax and check to create ImplicitDE or ExplicitDE .
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Hash Map
		 */
		addDataElement(0x0040,0x1003, DicomConstants.DCM_DT_SH, strRequestedProcedurePriority);
		
	}
	
	/**
	 * Retrieves Requested Procedure Type Urgency. Defined Terms: STAT, HIGH, ROUTINE, MEDIUM, LOW
	 * @return String - Requested Procedure Type Urgency.
	 */
	public String getRequestedProcedurePriority()
	{
		Object objValue = getValue(0x0040,0x1003);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Mode of transportation of the patient to the location of examination.
	 * @param StrPatientTransportArrangements Mode of transportation of the patient to the location of examination.
	 */
	public void setPatientTransportArrangements(String StrPatientTransportArrangements)
	{
		/* Accept Mode of transportation in String format of type LO.
		 * Read the Transfer Syntax and check to create ImplicitDE or ExplicitDE .
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Hash Map
		 */
		addDataElement(0x0040,0x1004, DicomConstants.DCM_DT_LO, StrPatientTransportArrangements);
		
	}
	
	/**
	 * Retrieves Patient Transport Arrangements.
	 * @return String - Patient Transport Arrangements.
	 */
	public String getPatientTransportArrangements()
	{
		Object objValue = getValue(0x0040,0x1004);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Physical location at which the Requested Procedure is to be performed.
	 * @param StrRequestedProcedureLocation Physical location at which the Requested Procedure is to be performed.
	 */
	public void setRequestedProcedureLocation(String StrRequestedProcedureLocation)
	{
		/* Accept Requested Procedure in String format of type LO.
		 * Read the Transfer Syntax and check to create ImplicitDE or ExplicitDE .
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Hash Map
		 */
		addDataElement(0x0040,0x1005, DicomConstants.DCM_DT_LO, StrRequestedProcedureLocation);
	}
	
	/**
	 * Retrieves Requested Procedure Location.
	 * @return String - Requested Procedure Location.
	 */
	public String getRequestedProcedureLocation()
	{
		Object objValue = getValue(0x0040,0x1005);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Confidentiality Constraints on the Requested Procedure by the party filling the order.
	 * @param StrConfidentialityCode Confidentiality Constraints on the Requested Procedure by the party filling the order.
	 */
	public void setConfidentialityCode(String StrConfidentialityCode)
	{
		/* Accept Confidentiality Constraints in String format of type LO.
		 * Read the Transfer Syntax and check to create ImplicitDE or ExplicitDE .
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Hash Map
		 */
		addDataElement(0x0040,0x1008, DicomConstants.DCM_DT_LO, StrConfidentialityCode);
	}
	
	/**
	 * Retrieves Confidentiality Code.
	 * @return String - Confidentiality Code.
	 */
	public String getConfidentialityCode()
	{
		Object objValue = getValue(0x0040,0x1008);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Requested Reporting Priority. Defined Terms: HIGH, ROUTINE, MEDIUM, LOW.
	 * @param StrReportingPriority Requested Reporting Priority
	 */
	public void setReportingPriority(String StrReportingPriority)
	{
		/* Accept Requested Reporting Priority in String format of type SH.
		 * Read the Transfer Syntax and check to create ImplicitDE or ExplicitDE .
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Hash Map
		 */
		addDataElement(0x0040,0x1009, DicomConstants.DCM_DT_SH, StrReportingPriority);
	}
	
	/**
	 * Retrieves Reporting Priority.
	 * @return String - Reporting Priority.
	 */
	public String getReportingPriority()
	{
		Object objValue = getValue(0x0040,0x1009);
		if(objValue != null)
			return objValue.toString();
		return null;
	}
	
	/**
	 * Sets Names of the physicians, who are intended recipients of results.
	 * @param StrNamesofIntendedRecipientsofResults - String array of Names of Intended Recipients of Results.
	 */
	public void setNamesofIntendedRecipientsofResults(String[] StrNamesofIntendedRecipientsofResults)
	{
		/* Accept Names of the physicians in String format of type PN.
		 * Read the Transfer Syntax and check to create ImplicitDE or ExplicitDE .
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Hash Map
		 */
		addDataElement(0x0040,0x1010, DicomConstants.DCM_DT_PN, StrNamesofIntendedRecipientsofResults);
	}
	
	/**
	 * Retrieves Names of Intended Recipients of Results.
	 * @return String[] - String array of Names of Intended Recipients of Results.
	 */
	public String[] getNamesofIntendedRecipientsofResults()
	{
		Object objValue = getValue(0x0040,0x1010);
		if(objValue != null)
			return (String[])objValue;
		return null;
	}
	
	/**
	 * Retrieves Identification of the physicians who are intended recipients of results. One or more items shall be
	 * included in this sequence. If more than one Item, the number and order shall correspond to the value
	 * of Names of Intended Recipients of Results (0040,1010), if present.
	 * @return IntendedRecipientsofResultsIdentificationSequence - instance of Intended Recipients of Results Identification Sequence.
	 */
	public IntendedRecipientsofResultsIdentificationSequence getIntendedRecipientsofResultsIdentificationSequence()
	{
		IntendedRecipientsofResultsIdentificationSequence objIntendedRecipientsofResultsIdentificationSequence = (IntendedRecipientsofResultsIdentificationSequence)getDicomValue(0x0040,0x1011);
		if(objIntendedRecipientsofResultsIdentificationSequence == 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.
			 */
			DicomV3Factory objDicomV3Factory = DicomV3Factory.createInstance();
			objIntendedRecipientsofResultsIdentificationSequence = (IntendedRecipientsofResultsIdentificationSequence)objDicomV3Factory.createSequence(0x0040,0x1011, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x0040,0x1011, DicomConstants.DCM_DT_SQ, objIntendedRecipientsofResultsIdentificationSequence.getValue());
		}
		return objIntendedRecipientsofResultsIdentificationSequence;
	}
}