/*******************************************************************************
 *  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.substanceadministration.sourceimpl;

import cdac.medinfo.sdk.dcm30_04.baselibs.DataSet;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITransferSyntax;
import cdac.medinfo.sdk.dcm30_04.services.dimsecommons.IQueryModel;
import cdac.medinfo.sdk.dcm30_04.utils.ICollectionIterator;
import cdac.medinfo.sdk.dcm30_04.utils.ISingleCollection;
import cdac.medinfo.sdk.dcm30_04.utils.SingleCollection;

/**
 *  This class represents Query Model for Substance Administration. This class contains methods to encode and decode Query Model.
 */
public class SubstanceAdministration_QueryModel implements IQueryModel
{

	ISingleCollection<SubstanceAdministration_Attributes> objSubstanceAdministration_AttributesList = null;
	/**
	 * Default Constructor for SubstanceAdministration_QueryModel class.
	 */
	public SubstanceAdministration_QueryModel()
	{
		this.objSubstanceAdministration_AttributesList = new SingleCollection<SubstanceAdministration_Attributes>();
	}
	
	/**
	 * Retrieves Attributes List of Substance Administration.
	 * @return object of SubstanceAdministration_AttributesList
	 */
	public ISingleCollection<SubstanceAdministration_Attributes> getSubstanceAdministration_AttributesList() 
	{
		return objSubstanceAdministration_AttributesList;
	}
	/**
	 * Sets Attributes List of Substance Administration.
	 * @param objSubstanceAdministrationAttributesList
	 */
	public void setSubstanceAdministration_AttributesList(ISingleCollection<SubstanceAdministration_Attributes> objSubstanceAdministrationAttributesList) 
	{
		objSubstanceAdministration_AttributesList = objSubstanceAdministrationAttributesList;
	}
	
	/**
	 * Populates the query Model using filled data set.
	 * @param objIDataSet Object of IDataSet.
	 * @return True - if Query Model populated successfully else False.
	 */
	public boolean decode(IDataSet objIDataSet)
	{
		if(this.objSubstanceAdministration_AttributesList == null)
			this.objSubstanceAdministration_AttributesList = new SingleCollection<SubstanceAdministration_Attributes>();
		
		SubstanceAdministration_Attributes objSubstanceAdministrationAttributesList = new SubstanceAdministration_Attributes();
		
		objSubstanceAdministrationAttributesList.populate(objIDataSet);
		
		objSubstanceAdministration_AttributesList.add(objSubstanceAdministrationAttributesList);
		return true;
	}
	
	
	/**
	 * Gets the filled DataSet list from already populated Query Model. 
	 * @param objITransferSyntax Object of ITransferSyntax. 
	 * @param objDataSetList Single collect of DataSet.
	 * @return True - Dataset List filled successfully else False.
	 */
	public boolean encode(ITransferSyntax objITransferSyntax, ISingleCollection<IDataSet> objDataSetList)
	{
		if(objSubstanceAdministration_AttributesList != null)
		{
			ICollectionIterator<SubstanceAdministration_Attributes> objSubstanceAdministration_AttributesIterator = objSubstanceAdministration_AttributesList.iterator();
			while(objSubstanceAdministration_AttributesIterator.hasNext())
			{
				SubstanceAdministration_Attributes objSubstanceAdministrationAttributesList = objSubstanceAdministration_AttributesIterator.next();
				if(objSubstanceAdministrationAttributesList != null)
				{
					IDataSet objIDataSet = new DataSet(objITransferSyntax);
					objSubstanceAdministrationAttributesList.fill(objIDataSet);
					objDataSetList.add(objIDataSet);
				}
			}
			return true;
		}
		else
			return false;
	}
}
