/*******************************************************************************
 *  Copyright 2017 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.hl7282.baselibs.segments;

import cdac.medinfo.sdk.hl7282.baselibs.CWE;
import cdac.medinfo.sdk.hl7282.baselibs.ID;
import cdac.medinfo.sdk.hl7282.baselibs.NM;
import cdac.medinfo.sdk.hl7282.baselibs.ST;
import cdac.medinfo.sdk.hl7282.commoninterface.IDataType;
import cdac.medinfo.sdk.hl7282.commoninterface.ISingleCollection;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidSegmentException;
import cdac.medinfo.sdk.hl7282.utils.EnumSegments;

/**
 * QAK - Query Acknowledgment Segment.<p>
 * QAK segment contains information sent with responses to a query.
 * Although the QAK segment is required in the responses to the enhanced queries 
 * it may appear as an optional segment placed after the (optional) ERR segment 
 * in any query response (message) to any original mode query.
 * <p>Represents an HL7 QAK message segment. 
 * This segment has the following fields:</p><p>
 * QAK-1: Query Tag (ST)<b>Conditional</b><br> 
 * QAK-2: Query Response Status (ID)<b>Optional</b><br> 
 * QAK-3: Message Query Name (CWE)<b>Optional</b><br> 
 * QAK-4: Hit Count (NM)<b>Optional</b><br> 
 * QAK-5: This payload (NM)<b>Optional</b><br> 
 * QAK-6: Hits remaining (NM)<b>Optional</b><br><p>
 * This class provides mechanism to validate message against HL7 v 2.8.2 standard.
 * The class provides accessors & mutators for the elements mentioned above.
 * The class has validate method which validates Message against HL7 v 2.8.2 standard.
 *
 * <p>User can also create Segment through {@link SegmentFactory}
 */
 public class QAK extends Segment   
{
	




	/**
	 * Constucts the QAK segment.
	 */
	public QAK()
	{super(EnumSegments.HL7_SEG_QAK);
	}

	/**
	 * Retrieves the Hit Count Total.
	 * This field contains the total number of records found by the Server that match the query. 
	 * @return NM - hitCount
	 */
	public NM getHitCountTotal() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1434);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Hits remaining.
	 * This field contains the number of matching records found by the Server that have yet to be sent.  
	 * @return NM - hitsremaining
	 */
	public NM getHitsremaining() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1623);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Message Query Name.  
	 * @return CWE - messageQueryName
	 */
	public CWE getMessageQueryName() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1375);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Query Response Status.
	 * This field allows the responding system to return a precise response status.  
	 * @return ID - queryResponseStatus
	 */
	public ID getQueryResponseStatus() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(708);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Query Tag.
	 * This field value by the initiating system to identify the query and use to match response messages to the originating query. 
	 * @return ST - queryTag
	 */
	public ST getQueryTag() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(696);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the This payload.
	 * This field contains the total number of matching records that the Server sent in the current response.
	 * @return NM - thispayload
	 */
	public NM getThispayload() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1622);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Set the Hit Count Total.
	 * This field contains the total number of records found by the Server that match the query. 
	 * @param strHitCountTotal Contains the total number of records found by the Server that matched the query. 
	 */ 
	public void setHitCountTotal (String strHitCountTotal) 
	{
		NM hitCount  = (NM)getDataElement(1434);
		hitCount.setValue(strHitCountTotal); 
		setHitCountTotal(hitCount);

	} 

	/** Set the Hit Count Total.
	 * This field contains the total number of records found by the Server that match the query. 
	 * @param objhitCount object of Hit Count Total. 
	 */ 
	public void setHitCountTotal(NM objhitCount)
	{
		setDataType(1434,objhitCount);
	}

	/**
	 * Set the Hits remaining.
	 * This field contains the number of matching records found by the Server that have yet to be sent.  
	 * @param strHitsremaining Contains the number of matching records found by the Server that have yet to be sent.
	 */ 
	public void setHitsremaining (String strHitsremaining) 
	{
		NM hitsremaining  = (NM)getDataElement(1623);
		hitsremaining.setValue(strHitsremaining); 
		setHitsremaining(hitsremaining);
	} 

	/** Set the Hits remaining.
	 * This field contains the number of matching records found by the Server that have yet to be sent.  
	 * @param objhitsremaining object of Hits Remaining.
	 */ 
	public void setHitsremaining(NM objhitsremaining)
	{
		setDataType(1623,objhitsremaining);
	}

	/**
	 * Set the Message Query Name.
	 * @param strIdentifier Specifies of characters (the code) that uniquely identifies the item being referenced. 
	 * @param strText Specifies The descriptive or textual name of the identifier, e.g., myocardial infarction. 
	 * @param strNameOfCodingSystem Identifies the coding scheme being used in the identifier component.
	 * @param strAlternateIdentifier Specifies an alternate sequence of characters (the code) that uniquely identifies the item being referenced.
	 * @param strAlternateText Specifies the descriptive or textual name of the alternate identifier. See usage note in section introduction.
	 * @param strNameOfAlternateCodingSystem Identifies the coding scheme being used in the alternate identifier component. 
	 * @param strCodingSystemVersionID A sequence of characters that uniquely identifies a second alternate code.
	 * @param strAlternateCodingSystemVersionId This component carries the version for the coding system identified by components 4-6.
	 * @param strOriginalText The text as seen and/or selected by the user who entered the data.
	 * @param strSecondAlternateIdentifier A sequence of characters that uniquely identifies a second alternate code.
	 * @param strSecondAlternateText The descriptive or textual name of the alternate identifier.
	 * @param strNameofSecondAlternateCodingSystem Identifies the coding scheme being used in the alternate identifier component.
	 * @param strSecondAlternateCodingSystemVersionID This component carries the version for the coding system identified by components 10-12.
	 * @param strCodingSystemOID This component contains the ISO Object Identifier (OID) for the coding system or value set named in CWE.3.
	 * @param strValueSetOID This component contains the ISO Object Identifier (OID) to allow identification of the value set from which the value in CWE.1 is obtained.
	 * @param strValueSetVersionID This component carries the version for the value set identified by CWE.15. The version is a date. The date is the date/time that the value set being used was published.
	 * @param strAlternateCodingSystemOID This component contains the ISO Object Identifier (OID) for the coding system or value set named in CWE.6.
	 * @param strAlternateValueSetOID This component contains the ISO Object Identifier (OID) to allow identification of the value set from which the value in CWE.4 is obtained.
	 * @param strAlternateValueSetVersionID This component carries the version for the value set identified by CWE.18. The version is a date.
	 * @param strSecondAlternateCodingSystemOID This component contains the ISO Object Identifier (OID) for the coding system or value set named in CWE.12.
	 * @param strSecondAlternateValueSetOID This component contains the ISO Object Identifier (OID) to allow identification of the value set from which the value in CWE.10 is obtained.
	 * @param strSecondAlternateValueSetVersionID This component carries the version for the value set identified by CWE.21. The version is a date.
	 */ 
	public void setMessageQueryName(String strIdentifier,String strText,String strNameOfCodingSystem,
			String strAlternateIdentifier,String strAlternateText,String strNameOfAlternateCodingSystem, String strCodingSystemVersionID, String 				strAlternateCodingSystemVersionId,
			String strOriginalText, String  strSecondAlternateIdentifier, String strSecondAlternateText, 
			String strNameofSecondAlternateCodingSystem, String strSecondAlternateCodingSystemVersionID, String strCodingSystemOID, String strValueSetOID,
			String strValueSetVersionID, String strAlternateCodingSystemOID, String strAlternateValueSetOID, String strAlternateValueSetVersionID,
			String  strSecondAlternateCodingSystemOID, String strSecondAlternateValueSetOID, String strSecondAlternateValueSetVersionID)
	{
		CWE cwe  = (CWE)getDataElement(1375);
		cwe.setIdentifier(strIdentifier);
		cwe.setText(strText);
		cwe.setNameOfCodingSystem(strNameOfCodingSystem);
		cwe.setAlternateIdentifier(strAlternateIdentifier);
		cwe.setAlternateText(strAlternateText);
		cwe.setNameOfAlternateCodingSystem(strNameOfAlternateCodingSystem); 
		cwe.setCodingSystemVersionID(strCodingSystemVersionID);
		cwe.setAlternateCodingSystemVersionId(strAlternateCodingSystemVersionId);
		cwe.setOriginalText(strOriginalText);
		cwe.setSecondAlternateIdentifier(strSecondAlternateIdentifier);
		cwe.setSecondAlternateText(strSecondAlternateText);
		cwe.setNameofSecondAlternateCodingSystem(strNameofSecondAlternateCodingSystem);
		cwe.setSecondAlternateCodingSystemVersionID(strSecondAlternateCodingSystemVersionID);
		cwe.setCodingSystemOID(strCodingSystemOID);
		cwe.setValueSetOID(strValueSetOID);
		cwe.setValueSetVersionID(strValueSetVersionID);
		cwe.setAlternateCodingSystemOID(strAlternateCodingSystemOID);
		cwe.setAlternateValueSetOID(strAlternateValueSetOID);
		cwe.setAlternateValueSetVersionID(strAlternateValueSetVersionID);
		cwe.setSecondAlternateCodingSystemOID(strSecondAlternateCodingSystemOID);
		cwe.setSecondAlternateValueSetOID(strSecondAlternateValueSetOID);
		cwe.setSecondAlternateValueSetVersionID(strSecondAlternateValueSetVersionID);
		setMessageQueryName(cwe);

	} 

	/** Set the Message Query Name.
	 * @param objmessageQueryName object of message Query Name.
	 */ 
	public void setMessageQueryName(CWE objmessageQueryName)
	{
		setDataType(1375,objmessageQueryName);

	}

	/**
	 * Set the Query Response Status.
	 * This field allows the responding system to return a precise response status.  
	 * @param strQueryResponseStatus Use as QueryResponseStatus.
	 */ 
	public void setQueryResponseStatus (String strQueryResponseStatus) 
	{
		ID queryResponseStatus  = (ID)getDataElement(708);
		queryResponseStatus.setValue(strQueryResponseStatus); 
		setQueryResponseStatus(queryResponseStatus);

	} 

	/** Set the Query Response Status.
	 * This field allows the responding system to return a precise response status.  
	 * @param objqueryResponseStatus object of Query Response Status.
	 */ 
	public void setQueryResponseStatus(ID objqueryResponseStatus)
	{
		setDataType(708,objqueryResponseStatus);

	}

	/**
	 * Set the Query Tag.
	 * This field value by the initiating system to identify the query and use to match response messages to the originating query.
	 * @param strQueryTag Use as QueryTag.
	 */ 
	public void setQueryTag (String strQueryTag) 
	{
		ST queryTag  = (ST)getDataElement(696);
		queryTag.setValue(strQueryTag); 
		setQueryTag(queryTag);

	} 

	/** Set the Query Tag.
	 * This field value by the initiating system to identify the query and use to match response messages to the originating query.
	 * @param objqueryTag object of Query Tag.
	 */ 
	public void setQueryTag(ST objqueryTag)
	{
		setDataType(696,objqueryTag);

	}

	/**
	 * Set the This payload.
	 * This field contains the total number of matching records that the Server sent in the current response.  
	 * @param strThispayload Contains the total number of matching records that the Server sent in the current response.
	 */ 
	public void setThispayload (String strThispayload) 
	{
		NM thispayload  = (NM)getDataElement(1622);
		thispayload.setValue(strThispayload); 
		setThispayload(thispayload);

	} 

	/** Set the This payload.
	 * This field contains the total number of matching records that the Server sent in the current response.  
	 * @param objthispayload object of This payload.
	 */ 
	public void setThispayload(NM objthispayload)
	{
		setDataType(1622,objthispayload);

	}

	/**
	 * Validates HL7 Message objects .
	 * Validate method checks for validation each and every segments in side the Message object against specified message Structure. 
	 * Validation chcecks include optionality of segment or group.
	 * It also verifies the number of times segment or group is repeated in message.
	 * e.g 
	 * {PSH} while parsing PSH segment validate method will check for its mandatory presence.
	 * [PSH] in this case validate will throw exception if one tries to enter more than one PSH segment.
	 * @return boolean - true or false.
	 * @throws InvalidSegmentException Throws when Segment Validation fails.
	 */
	public boolean validate() throws InvalidSegmentException
	{
		/*
		 * Yet the condition is not decided.
		 */
		super.validate();
		return true;
	}
}