/*******************************************************************************
 *  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.DTM;
import cdac.medinfo.sdk.hl7282.baselibs.FN;
import cdac.medinfo.sdk.hl7282.baselibs.FT;
import cdac.medinfo.sdk.hl7282.baselibs.HD;
import cdac.medinfo.sdk.hl7282.baselibs.ID;
import cdac.medinfo.sdk.hl7282.baselibs.SI;
import cdac.medinfo.sdk.hl7282.baselibs.XCN;
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;
import cdac.medinfo.sdk.hl7282.utils.SingleCollection;

/**
 * NTE - Notes and Comments Segment.<p>
 * The NTE segment is defined here for inclusion in messages defined in other chapters.
 * It is commonly used for sending notes and comments.
 * <p>Represents an HL7 NTE message segment. 
 * This segment has the following fields:</p><p>
 * NTE-1: Set ID - NTE (SI)<b>Optional</b><br> 
 * NTE-2: Source of Comment (ID)<b>Optional</b><br> 
 * NTE-3: Comment (FT)<b>Optional</b><br> 
 * NTE-4: Comment Type (CWE)<b>Optional</b><br>
 * NTE-5: Entered By (XCN)<b>Optional</b><br> 
 * NTE-6: Entered Date/Time (DTM)<b>Optional</b><br> 
 * NTE-7: Effective Start Date (DTM)<b>Optional</b><br> 
 * NTE-8: Expiration Date (DTM)<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 NTE extends Segment   
{
	

	/**
	 * Constructs the NTE segment.
	 */
	public NTE()
	{
		super(EnumSegments.HL7_SEG_NTE);
	}

	/**
	 * Construct the NTE segment with enum.
	 * @param enumSegments Specified enum.
	 */
	public NTE(EnumSegments enumSegments)
	{
		super(enumSegments);
	}

	//Integer values used in getter/setter is unique item id defined 
	//for each attribute.

	/**
	 * Retrieves the Comment.
	 * This field contains the comment contained in the segment.
	 * @return ISingleCollection<FT> - comment
	 */
	public ISingleCollection<FT> getComment() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(98);
		ISingleCollection<FT> objDataList = new SingleCollection<FT>(); 
		if(objDataCollection != null && objDataCollection.size() != 0)
		{
			for(IDataType objDataType : objDataCollection)
			{
				FT objFT = (FT)objDataType;
				objDataList.add(objFT);
			}
		}
		return objDataList;
	}

	/**
	 * Retrieves the Comment Type.
	 * This field contains a value to identify the type of comment text being sent in the specific comment record.
	 * @return CWE - commentType
	 */
	public CWE getCommentType() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1318);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Set ID NTE.
	 * This field is used where multiple NTE segments are included in a message.
	 * @return String - setID_NTE
	 */
	public SI getSetID_NTE() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(96);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (SI)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Source Of Comment.
	 * This field is used when source of comment must be identified. 
	 * @return String - sourceOfComment
	 */
	public ID getSourceOfComment() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(97);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Set the Set ID NTE.
	 * This field is used where multiple NTE segments are included in a message.
	 * @param strSetID NTE segment number.
	 */ 
	public void setSetID_NTE (String strSetID) 
	{
		SI setID_NTE  = (SI)getDataElement(96);
		setID_NTE.setValue(strSetID); 
		setSetID_NTE(setID_NTE);

	} 

	/** 
	 * Set the Set ID NTE.
	 * This field is used where multiple NTE segments are included in a message.
	 * @param objsetID_NTE Object of Set ID NTE.
	 */ 
	public void setSetID_NTE(SI objsetID_NTE)
	{
		setDataType(96,objsetID_NTE);

	}

	/**
	 * Set the Source Of Comment.
	 * This field is used when source of comment must be identified. 
	 * @param strSourceOfComment Specifies source of comment(Refer table 105 for valid values).
	 */ 
	public void setSourceOfComment (String strSourceOfComment) 
	{
		ID sourceOfComment  = (ID)getDataElement(97);
		sourceOfComment.setValue(strSourceOfComment); 
		setSourceOfComment(sourceOfComment);

	} 

	/** 
	 * Set the Source Of Comment.
	 * This field is used when source of comment must be identified. 
	 * @param objsourceOfComment Object of Source Of Comment.
	 */ 
	public void setSourceOfComment(ID objsourceOfComment)
	{
		setDataType(97,objsourceOfComment);

	}

	/**
	 * Add the Comment.
	 * This field contains the comment contained in the segment.
	 * @param strComment Specifies source of comment.
	 */ 
	public void addComment (String strComment) 
	{
		FT comment  = (FT)getDataElement(98);
		comment.setValue(strComment); 
		addComment(comment);

	} 

	/** 
	 * Add the Comment.
	 * This field contains the comment contained in the segment.
	 * @param objcomment Object of Comment.
	 */ 
	public void addComment(FT objcomment)
	{
		addDataType(98,objcomment);

	}

	/**
	 * Set the Comment.
	 * This field contains the comment contained in the segment.
	 * @param objComment List of the Comment
	 */
	@SuppressWarnings("unchecked")
	public void setComment(ISingleCollection<FT> objComment)
	{
		ISingleCollection<IDataType> objCollection = null;
		ISingleCollection<?> objUnknownCollection = (ISingleCollection<?>)objComment;
		objCollection = (ISingleCollection<IDataType>)objUnknownCollection;
		setDataType(98,objCollection);
	}

	/**
	 * Set the Comment Type.
	 * This field contains a value to identify the type of comment text being sent in the specific comment record.
	 * @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 setCommentType (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(1318);
		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); 
		setCommentType(cwe);

	} 

	/** 
	 * Set the Comment Type.
	 * This field contains a value to identify the type of comment text being sent in the specific comment record.
	 * @param objcommentType Object of Comment Type.
	 */ 
	public void setCommentType(CWE objcommentType)
	{
		setDataType(1318,objcommentType);

	}
	
	/**
	 * Retrieves the Entered By.
	 * @return XCN - enteredBy
	 */
	public XCN getEnteredBy() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(224);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (XCN)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Set the Entered By.
	 * @param strIDNumber Refers to the coded ID according to a user-defined table
	 * @param objFamilyName Specifies the surname of a person.
	 * @param strGivenName Specifies First name.
	 * @param strSecondAndFurtherGivenNamesOrInitialsThereof Specifies multiple middle names that may be included by 
	 * 														   separating them with spaces.
	 * @param strSuffix Used to specify a name suffix (e.g., Jr. or III).
	 * @param strPrefix Used to specify a name prefix (e.g., Dr.).
	 * @param strSourceTable Used as the HL7 identifier for the user-defined table of values for this component. [Refer User-defined Table 0297 - CN ID.]
	 * @param objAssigningAuthority Specifies a unique identifier of the system (or organization or agency of department)
	 * 								  that creates the data. [Refer User-defined Table 0363 - Assigning authority]
	 * @param strNameTypeCode Specifies a code that represents the type of name. 
	 * @param strIdentifierCheckDigit Specifies part of the identifying number used in the sending application. 
	 * @param strCheckDigitScheme Specifies the code identifying the check digit scheme employed.[Refer HL7 Table 0061 - Check digit scheme].
	 * @param strIdentifierTypeCode Specifies A code corresponding to the type of identifier.[Refer HL7 Table 0203 - Identifier type].
	 * @param objAssigningFacility Specifies the place or location identifier where the identifier was first assigned to the person
	 * @param strNameRepresentationCode Provides an indication of the representation provided by the data item.  
	 * @param objNameContext Designates the context in which a name is used. [Refer User-defined Table 0448 ]
	 * @param strNameAssemblyOrder Specifies a code that represents the preferred display order of the components of this person name. Suggested values are G,F[Refer table 0444.]
	 * @param strEffectiveDate Specifies the first date, if known, on which the address is valid and active.
	 * @param strExpirationDate Specifies the last date, if known, on which the address is valid and active.
	 * @param strProfessionalSuffix Used to specify an abbreviation, or a string of abbreviations, denoting qualifications that support the person's profession, (e.g., licenses).
	 * @param objAssigningJurisdiction Specifies the geo-political body that assigned the identifier.
	 * @param objAssigningAgencyOrDepratment Specifies the agency or department that assigned the identifier
	 * @param strSecurityCheck Specifies the version code that may be assigned to the person identifier
	 * @param strSecurityCheckScheme Specifies the check digit scheme.
	 */
	public void setEnteredBy (String strIDNumber,FN objFamilyName,String strGivenName,String strSecondAndFurtherGivenNamesOrInitialsThereof,
			String 	strSuffix,String strPrefix,CWE objSourceTable,HD objAssigningAuthority,
			String strNameTypeCode,String strIdentifierCheckDigit,String strCheckDigitScheme,String strIdentifierTypeCode,
			HD objAssigningFacility,String strNameRepresentationCode,CWE objNameContext,
			String strNameAssemblyOrder, String strEffectiveDate,String strExpirationDate,String strProfessionalSuffix,
			CWE objAssigningJurisdiction,CWE objAssigningAgencyOrDepratment, String strSecurityCheck, String strSecurityCheckScheme)
	{
		XCN xcn  = (XCN)getDataElement(224);
		xcn.setIdNumber(strIDNumber);
		xcn.setFamilyName(objFamilyName);
		xcn.setGivenName(strGivenName);
		xcn.setSecondNameOrInitials(strSecondAndFurtherGivenNamesOrInitialsThereof);
		xcn.setSuffix(strSuffix);
		xcn.setPrefix(strPrefix);
 
		xcn.setSourceTable(objSourceTable);
		xcn.setAssigningAuthority(objAssigningAuthority);
		xcn.setNameTypeCode(strNameTypeCode);
		xcn.setIdentifierCheckDigit(strIdentifierCheckDigit);
		xcn.setCheckDigitScheme(strCheckDigitScheme);
		xcn.setIdentifierTypeCode(strIdentifierTypeCode);
		xcn.setAssigningFacility(objAssigningFacility);
		xcn.setNameRepresentationCode(strNameRepresentationCode);
		xcn.setNameContext(objNameContext);
 
		xcn.setNameAssemblyOrder(strNameAssemblyOrder);
		xcn.setEffectiveDate(strEffectiveDate);
		xcn.setExpirationDate(strExpirationDate);
		xcn.setProfessionalSuffix(strProfessionalSuffix);
		xcn.setAssigningJurisdiction(objAssigningJurisdiction);
		xcn.setAssigningAgencyOrDepartment(objAssigningAgencyOrDepratment); 
		xcn.setSecurityCheck(strSecurityCheck);
		xcn.setSecurityCheckScheme(strSecurityCheckScheme);
		setEnteredBy (xcn);

	}

	/**
	 * Set the Entered By.
	 * @param enteredBy Entered By.
	 */
	public void setEnteredBy(XCN enteredBy)
	{
		setDataType(224,enteredBy);
	}
	
	/**
	 * Retrieves the Entered Date/Time.
	 * This field contains the date and time of the last change of the record.
	 * @return DTM - EnteredDateTime
	 */
	public DTM getEnteredDateTime() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(661);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Set the Entered Date/Time.
	 * This field contains the date and time of the last change of the record.
	 * @param strTime The point in time
	 */ 
	public void setEnteredDateTime (String strTime) 
	{
		DTM EnteredDateTime  = (DTM)getDataElement(661);
		EnteredDateTime.setValue(strTime);
		setEnteredDateTime (EnteredDateTime);

	} 

	/** Set the Entered Date/Time.
	 * This field contains the date and time of the last change of the record.
	 * @param objEnteredDateTime
	 */ 
	public void setEnteredDateTime(DTM objEnteredDateTime)
	{
		setDataType(661,objEnteredDateTime);

	}
	
	/**
	 * Retrieves the Effective Start Date.
	 * This field contains the date/time when this CDM entry becomes effective.
	 * @return DTM - effectiveStartDate
	 */
	public DTM getEffectiveStartDate() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1004);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Set the Effective Start Date.
	 * This field contains the date/time when this CDM entry becomes effective.  
	 * @param strDate Specifies a point in time using a 24-hour clock notation. 
	 */ 
	public void setEffectiveStartDate (String strDate) 
	{
		DTM effectiveStartDate  = (DTM)getDataElement(1004);
		effectiveStartDate.setValue(strDate);
		setEffectiveStartDate(effectiveStartDate);

	} 

	/** 
	 * Set the Effective Start Date.
	 * This field contains the date/time when this CDM entry becomes effective.
	 * @param objeffectiveStartDate Object of Effective Start Date.
	 */ 
	public void setEffectiveStartDate(DTM objeffectiveStartDate)
	{
		setDataType(1004,objeffectiveStartDate);

	}
	
	/**
	 * Retrieves the Expiration Date.
	 * This field contains the date the comment becomes or became non-effective.
	 * @return DTM - expirationDate
	 */
	public DTM getExpirationDate() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2185);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Set the Expiration Date.
	 * This field contains the date the comment becomes or became non-effective.
	 * @param strTime Specifies a point in time using a 24-hour clock notation. 
	 */ 
	public void setExpirationDate (String strTime) 
	{
		DTM expirationDate  = (DTM)getDataElement(2185);
		expirationDate.setValue(strTime);
		setExpirationDate(expirationDate);

	} 

	/** 
	 * Set the Expiration Date.
	 * This field contains the date the comment becomes or became non-effective.
	 * @param objexpirationDate Object of Expiration Date.
	 */ 
	public void setExpirationDate(DTM objexpirationDate)
	{
		setDataType(2185,objexpirationDate);

	}

	/**
	 * Validates HL7 Message objects .
	 * Validate method checks for validation each and every segments in side the Message object against specified message Structure. 
	 * Validation checks 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
	{
		super.validate();

		return true;
	}
}