/*******************************************************************************
 *  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.services.mwl.mwlsourceimpl;

import cdac.medinfo.sdk.dcm30_04.baselibs.DicomV3Factory;
import cdac.medinfo.sdk.dcm30_04.baselibs.InstitutionCodeSequence;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConstants;

/**
 *  This class contains the Attributes required for Query Model. Also contains methods to populate and fill data set of Query Model.
 */
public class VisitIdentificationAttributes extends Attributes
{
	/**
	 * Identification number of the visit as assigned by the health care 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);
	}
	
	/**
	 * Retrieves Identification number of the visit as assigned by the health care provider.
	 * 
	 * @return String - String value of Admission ID
	 */
	public String getAdmissionID()
	{
		Object objectValue = getValue(0x0038, 0x0010);
		if(objectValue!=null)
			return objectValue.toString();
		return null;
	}
	
	/**
	 * 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 health care 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, getDataSet().getTransferSyntax(), getDataSet().getDictionaryReader());
			
			// This will add Data Element of SQ to the DataSet.
			addDataElement(0x0008,0x0082, DicomConstants.DCM_DT_SQ, objInstitutionCodeSequence.getValue());
		}
		return objInstitutionCodeSequence;
	}

	/**
	 * Name of health care provider which issued the Admission ID.
	 * 
	 * @param strIssuerOfAdmissionID String value of Issuer of Admission ID.
	 */
	public void setIssuerOfAdmissionID(String strIssuerOfAdmissionID)
	{
		/*Accept Issuer of 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, 0x0011, DicomConstants.DCM_DT_LO, strIssuerOfAdmissionID);
	}

	/**
	 * 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 Name of health care provider which issued the Admission ID.
	 * 
	 * @return String - String value of Issuer of Admission ID
	 */
	public String getIssuerOfAdmissionID()
	{
		Object objectValue = getValue(0x0038, 0x0011);
		if(objectValue!=null)
			return objectValue.toString();
		return null;
	}
	
	/**
	 * Populates the query Model using filled data set.
	 */
	public void populate(IDataSet objIDataSet)
	{
		super.populate(objIDataSet);
	}	
	
	/**
	 * Fills the data set using already populated Query Model.
	 */
	public void fill(IDataSet objIDataSet)
	{
		super.fill(objIDataSet);
	}
}
