/*******************************************************************************
 *  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.InstitutionCodeSequence;
import cdac.medinfo.sdk.dcm30_04.baselibs.IssuerOfAdmissionIDSequence;
import cdac.medinfo.sdk.dcm30_04.baselibs.IssuerofServiceEpisodeIDSequence;
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.utils.DicomConstants;
import cdac.medinfo.sdk.dcm30_04.utils.ISingleCollection;
import cdac.medinfo.sdk.dcm30_04.utils.SingleCollection;

// TODO: Auto-generated Javadoc
/**
 \* This module Class defines the Attributes relevant to identifying a visit.
*/
public class VisitIdentificationModule extends Module  
{

 
 /**
  * The obj single collection.
  */
 public static ISingleCollection<ITag> objSingleCollection = null;
	

	/**
	 * Instantiates a new visit identification module.
	 * 
	 * @param objIDataSet the obj i data set
	 */
	public VisitIdentificationModule(IDataSet objIDataSet)
	{
		super(objIDataSet);
	}

	static
	{
		objSingleCollection = new SingleCollection<ITag>();
		objSingleCollection.add(new Tag(0x0008,0x0080));
		objSingleCollection.add(new Tag(0x0008,0x0081));
		objSingleCollection.add(new Tag(0x0008,0x0082));
		objSingleCollection.add(new Tag(0x0038,0x0010));
		objSingleCollection.add(new Tag(0x0038,0x0014));
		objSingleCollection.add(new Tag(0x0038,0x0060));
		objSingleCollection.add(new Tag(0x0038,0x0064));
		objSingleCollection.add(new Tag(0x0038,0x0062));
	}

	/* (non-Javadoc)
	 * @see cdac.medinfo.sdk.dcm30_04.dicommodel.modules.Module#validateModule()
	 */
	public boolean validateModule()
	{
		return true;
	}

	/**
	 * Sets The name of Institution.
	 * 
	 * @param strInstitutionName String value of Institution Name
	 */
	public void setInstitutionName(String strInstitutionName)
	{
		/*Accept name of Institution where the equipment that produced the composite instances is located 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(0x0008, 0x0080, DicomConstants.DCM_DT_LO, strInstitutionName);
	}

	/**
	 * The address of Institution.
	 * 
	 * @param strInstitutionAddress String value of Institution Address
	 */
	public void setInstitutionAddress(String strInstitutionAddress)
	{
		/*Accept Mailing address of the institution where the equipment that produced 
		 * the composite instances is located 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(0x0008, 0x0081, DicomConstants.DCM_DT_ST, strInstitutionAddress);
	}

	/**
	 * A sequence that conveys the healthcare facility identification.
	 * Only a single Item shall be permitted in this Sequence.
	 * 
	 * @return objInstitutionCodeSequence - Instance of Institution Code Sequence.
	 */
	public InstitutionCodeSequence getInstitutionCodeSequence()
	{
		InstitutionCodeSequence objInstitutionCodeSequence = (InstitutionCodeSequence)getDicomValue(0x0008,0x0082);
		if(objInstitutionCodeSequence == 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();
			objInstitutionCodeSequence = (InstitutionCodeSequence)objDicomV3Factory.createSequence(0x0008,0x0082, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x0008,0x0082, DicomConstants.DCM_DT_SQ, objInstitutionCodeSequence.getValue());
		}
		return objInstitutionCodeSequence;
	}


	/**
	 * Identification number of the visit as assigned by the healthcare provider.
	 * 
	 * @param strAdmissionID String value of Admission ID.
	 */
	public void setAdmissionID(String strAdmissionID)
	{
		/*Accept Admission ID that produced the composite instances 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(0x0038, 0x0010, DicomConstants.DCM_DT_LO, strAdmissionID);
	}

	/**
	 * Sets Identifier of the Service Episode as assigned by the healthcare provider.
	 * 
	 * @param strServiceEpisodeID String value of Service Episode ID
	 */
	public void setServiceEpisodeID(String strServiceEpisodeID)
	{
		/*Accept name of Service Episode 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 Hash Map
		 */
		addDataElement(0x0038, 0x0060, DicomConstants.DCM_DT_LO, strServiceEpisodeID);
	}
	
	/**
	 * Sets Description of the type of service episode.
	 * 
	 * @param strServiceEpisodeDescription String value of Service Episode Description
	 */
	public void setServiceEpisodeDescription(String strServiceEpisodeDescription)
	{
		/*Accept Service Episode Description 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(0x0038, 0x0062, DicomConstants.DCM_DT_LO, strServiceEpisodeDescription);
	}

	/**
	 * Retrieves Institution where the equipment is located.
	 * 
	 * @return String - String value of Institution Name
	 */
	public String getInstitutionName()
	{
		Object objectValue = getValue(0x0008, 0x0080);
		if(objectValue!=null)
			return objectValue.toString();
		return null;
	}

	/**
	 * Retrieves Mailing Address of the institution where the equipment is located.
	 * 
	 * @return String  - String value of Institution Address
	 */
	public String getInstitutionAddress()
	{
		Object objectValue = getValue(0x0008, 0x0081);
		if(objectValue!=null)
			return objectValue.toString();
		return null;
	}

	/**
	 * Retrieves Identification number of the visit as assigned by the healthcare provider.
	 * 
	 * @return String - String value of Admission ID
	 */
	public String getAdmissionID()
	{
		Object objectValue = getValue(0x0038, 0x0010);
		if(objectValue!=null)
			return objectValue.toString();
		return null;
	}

	/**
	 * This method provides the pre-initialized object of Issuer Of Admission ID Sequence.
	 * 
	 * @return - object of Issuer Of Admission ID Sequence. If the module contains the sequence object
	 * it returns the same otherwise it creates the sequence adds to the module with proper initialization
	 * and then returns the object of sequence
	 */
	public IssuerOfAdmissionIDSequence getIssuerOfAdmissionIDSequence()
	{
		IssuerOfAdmissionIDSequence objIssuerOfAdmissionIDSequence = (IssuerOfAdmissionIDSequence)getDicomValue(0x0038, 0x0014);
		if(objIssuerOfAdmissionIDSequence == 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();
			objIssuerOfAdmissionIDSequence = (IssuerOfAdmissionIDSequence)objDicomV3Factory.createSequence(0x0038, 0x0014, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x0038, 0x0014, DicomConstants.DCM_DT_SQ, objIssuerOfAdmissionIDSequence.getValue());
		}
		return objIssuerOfAdmissionIDSequence;
	}
	
	/**
	 * Retrieves Service Episode ID.
	 * 
	 * @return String - String value of Service Episode ID
	 */
	public String getServiceEpisodeID()
	{
		Object objectValue = getValue(0x0038, 0x0060);
		if(objectValue!=null)
			return objectValue.toString();
		return null;
	}
	
	/**
	 * This method provides the pre-initialized object of Issuer of Service Episode ID Sequence.
	 * 
	 * @return - object of Issuer of Service Episode ID Sequence. If the module contains the sequence object
	 * it returns the same otherwise it creates the sequence adds to the module with proper initialization
	 * and then returns the object of sequence
	 */
	public IssuerofServiceEpisodeIDSequence getIssuerofServiceEpisodeIDSequence()
	{
		IssuerofServiceEpisodeIDSequence objIssuerofServiceEpisodeIDSequence = (IssuerofServiceEpisodeIDSequence)getDicomValue(0x0038, 0x0064);
		if(objIssuerofServiceEpisodeIDSequence == 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();
			objIssuerofServiceEpisodeIDSequence = (IssuerofServiceEpisodeIDSequence)objDicomV3Factory.createSequence(0x0038, 0x0064, objITransferSyntax, objIDictionaryReader);
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x0038, 0x0064, DicomConstants.DCM_DT_SQ, objIssuerofServiceEpisodeIDSequence.getValue());
		}
		return objIssuerofServiceEpisodeIDSequence;
	}
	
	/**
	 * Retrieves Service Episode Description.
	 * 
	 * @return String - String value of Service Episode Description
	 */
	public String getServiceEpisodeDescription()
	{
		Object objectValue = getValue(0x0038, 0x0062);
		if(objectValue!=null)
			return objectValue.toString();
		return null;
	}
	
	/* 
	 * I have modified the collection type from vector to custom class
	 * This method is used by the Module Iterator to iterate through the DataSet and return only
	 * those elements that belong to the respective Module class whose getVectorOfKeys is called.
	 */
	/**
	 * 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;
	}
}
