/*******************************************************************************
 *  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 java.io.IOException;
import java.util.Locale;

import cdac.medinfo.sdk.hl7282.baselibs.CWE;
import cdac.medinfo.sdk.hl7282.baselibs.DTM;
import cdac.medinfo.sdk.hl7282.baselibs.EI;
import cdac.medinfo.sdk.hl7282.baselibs.HD;
import cdac.medinfo.sdk.hl7282.baselibs.ID;
import cdac.medinfo.sdk.hl7282.baselibs.MSG;
import cdac.medinfo.sdk.hl7282.baselibs.NM;
import cdac.medinfo.sdk.hl7282.baselibs.PT;
import cdac.medinfo.sdk.hl7282.baselibs.ST;
import cdac.medinfo.sdk.hl7282.baselibs.VID;
import cdac.medinfo.sdk.hl7282.baselibs.XON;
import cdac.medinfo.sdk.hl7282.commoninterface.IDataType;
import cdac.medinfo.sdk.hl7282.commoninterface.IDelimiter;
import cdac.medinfo.sdk.hl7282.commoninterface.IHL7Stream;
import cdac.medinfo.sdk.hl7282.commoninterface.ISingleCollection;
import cdac.medinfo.sdk.hl7282.exceptions.DelimiterMissingException;
import cdac.medinfo.sdk.hl7282.exceptions.FieldMissingException;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidDataTypeException;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidDelimiterException;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidFieldException;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidSegmentException;
import cdac.medinfo.sdk.hl7282.exceptions.SerializeException;
import cdac.medinfo.sdk.hl7282.utils.EnumSegments;
import cdac.medinfo.sdk.hl7282.utils.HL7Config;
import cdac.medinfo.sdk.hl7282.utils.HL7Constants;
import cdac.medinfo.sdk.hl7282.utils.ResourceBundleWrapper;
import cdac.medinfo.sdk.hl7282.utils.SingleCollection;

/**
 * MSH - message header segment <p>
 * The MSH segment defines the intent, source, destination, and some specifics of the
 * syntax of a message.
 * <p>Represents an HL7 MSH message segment. 
 * This segment has the following fields:</p><p>
 * MSH-1: Field Separator (ST)<b>Required</b><br> 
 * MSH-2: Encoding Characters (ST)<b>Required</b><br> 
 * MSH-3: Sending Application (HD)<b>Optional</b><br> 
 * MSH-4: Sending Facility (HD)<b>Optional</b><br> 
 * MSH-5: Receiving Application (HD)<b>Optional</b><br> 
 * MSH-6: Receiving Facility (HD)<b>Optional</b><br> 
 * MSH-7: Date/Time Of Message (DTM)<b>Required</b><br> 
 * MSH-8: Security (ST)<b>Optional</b><br> 
 * MSH-9: Message Type (MSG)<b>Required</b><br> 
 * MSH-10: Message Control ID (ST)<b>Required</b><br> 
 * MSH-11: Processing ID (PT)<b>Required</b><br> 
 * MSH-12: Version ID (VID)<b>Required</b><br> 
 * MSH-13: Sequence Number (NM)<b>Optional</b><br> 
 * MSH-14: Continuation Pointer (ST)<b>Optional</b><br> 
 * MSH-15: Accept Acknowledgment Type (ID)<b>Optional</b><br> 
 * MSH-16: Application Acknowledgment Type (ID)<b>Optional</b><br> 
 * MSH-17: Country Code (ID)<b>Optional</b><br> 
 * MSH-18: Character Set (ID)<b>Optional</b><br> 
 * MSH-19: Principal Language Of Message (CWE)<b>Optional</b><br> 
 * MSH-20: Alternate Character Set Handling Scheme (ID)<b>Optional</b><br> 
 * MSH-21: Message Profile Identifier (EI)<b>Optional</b>
 * MSH-22: Sending Responsible Organization (XON)<b>Optional</b><br> 
 * MSH-23: Receiving Responsible Organization (XON)<b>Optional</b><br> 
 * MSH-24: Sending Network Address (HD)<b>Optional</b><br> 
 * MSH-25: Receiving Network Address (HD)<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 MSH extends Segment   
{	
	protected Delimiter objDelimiter;

	/**
	 * Constructs the MSH segment.
	 */
	public MSH()
	{
		super(EnumSegments.HL7_SEG_MSH);
		objDelimiter = new Delimiter();	
	}

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

	/**
	 * Retrieves the Accept Acknowledgment Type.
	 * This field identify the conditions under which accept 
	 * acknowledgments are required to be returned in response to this message. 
	 * @return ID - acceptAcknowledgmentType
	 */
	public ID getAcceptAcknowledgmentType() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(15);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Alternate Character Set Handling Scheme.
	 * This field specify the Alternate Character Set Handling Scheme.
	 * @return ID - alternateCharacterSetHandlingScheme
	 */
	public ID getAlternateCharacterSetHandlingScheme() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1317);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Application Acknowledgment Type.
	 * This field contains the conditions under which application 
	 * acknowledgments are required to be returned in response to this message.  
	 * @return ID - applicationAcknowledgmentType
	 */
	public ID getApplicationAcknowledgmentType() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(16);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Character Set.
	 * This field contains the character set for the entire message. 
	 * @return ISingleCollection<ID> - characterSet
	 */
	public ISingleCollection<ID> getCharacterSet() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(692);
		ISingleCollection<ID> objDataList = new SingleCollection<ID>(); 
		if(objDataCollection != null && objDataCollection.size() != 0)
		{
			for(IDataType objDataType : objDataCollection)
			{
				ID objID = (ID)objDataType;
				objDataList.add(objID);
			}
		}
		return objDataList;
	}
	/**
	 * Retrieves the Continuation Pointer.
	 * This field is used to define continuations in application-specific ways.
	 * @return ST - continuationPointer
	 */
	public ST getContinuationPointer() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(14);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Country Code.
	 * This field contains the country of origin for the message. 
	 * @return ID - countryCode
	 */
	public ID getCountryCode() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(17);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Date Time Of Message.
	 * This field contains the date/time that the sending system created the message.
	 * @return DTM - dateTimeOfMessage
	 */
	public DTM getDateTimeOfMessage() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(7);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Encoding Char.
	 * This field contains the four characters in the following order: the 
	 * component separator, repetition separator, escape character, and subcomponent separator.
	 * @return ST - encodingChar
	 */
	public ST getEncodingChar() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Field Separator.
	 * This field contains the separator between the segment ID and the first real field.
	 * @return ST - fieldSeparator
	 */
	public ST getFieldSeparator() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Message Control ID.
	 * This field contains a number or other identifier that uniquely identifies the message. 
	 * @return ST - messageControlID
	 */
	public ST getMessageControlID() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(10);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Message Profile Identifier.
	 * This field specify that Sites may use this field to assert adherence to, or reference, a 
	 * message profile. Message profiles contain detailed explanations of grammar, syntax, 
	 * and usage for a particular message or set of messages. 
	 * @return ISingleCollection<EI> - messageProfileIdentifier
	 */
	public ISingleCollection<EI> getMessageProfileIdentifier() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1598);
		ISingleCollection<EI> objDataList = new SingleCollection<EI>(); 
		if(objDataCollection != null && objDataCollection.size() != 0)
		{
			for(IDataType objDataType : objDataCollection)
			{
				EI objEI = (EI)objDataType;
				objDataList.add(objEI);
			}
		}
		return objDataList;
	}
	/**
	 * Retrieves the Principal Language Of Message.
	 * This field contains the principal language of the message. Codes come from ISO 639. 
	 * @return CWE - principalLanguageOfMessage
	 */
	public CWE getPrincipalLanguageOfMessage() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(693);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Processing ID.
	 * This field is use to decide whether to process the message as defined in HL7 Application or not.
	 * @return PT - processingID
	 */
	public PT getProcessingID() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(11);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (PT)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Receiving Application.
	 * This field uniquely identify the receiving application among all other applications within the network enterprise
	 * @return HD - receivingApplication
	 */
	public HD getReceivingApplication() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(5);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (HD)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Receiving Facility.
	 * This field identify the receiving application among multiple identical instances of 
	 * the application running on behalf of different organizations. 
	 * @return HD - receivingFacility
	 */
	public HD getReceivingFacility() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(6);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (HD)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Security.
	 * @return ST - security
	 */
	public ST getSecurity() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(8);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Sending Application.
	 * This field uniquely identifies the sending application among all other applications within the network enterprise.
	 * @return HD - sendingApplication
	 */
	public HD getSendingApplication() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(3);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (HD)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Sending Facility.
	 * This field used as the HL7 identifier for the user-defined table of values for the first component.
	 * @return HD - sendingFacility
	 */
	public HD getSendingFacility() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(4);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (HD)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Sequence Number.
	 * This field implies that the sequence number protocol is in use. 
	 * @return NM - sequenceNumber
	 */
	public NM getSequenceNumber() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(13);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Delimiter.
	 * @return IDelimiter - delimiter.
	 */	
	public IDelimiter getDelimiter()
	{
		return objDelimiter;
	}

	/**
	 * Retrieves the Message Type.
	 * This field contains the message type, trigger event, and the message structure ID for the message.
	 * @return MSG - messageType
	 */
	public MSG getMessageType() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(9);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (MSG)objDataCollection.elementAt(0);
		else
			return null;
	}
	/**
	 * Retrieves the Version ID.
	 * This field is matched by the receiving system to its own version to be sure the message
	 * will be interpreted correctly. 
	 * @return VID - versionID
	 */
	public VID getVersionID() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(12);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (VID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Set the Field Separator.
	 * This field contains the separator between the segment ID and the first real field.
	 * @param cfieldSeparator Use as cfieldSeparator.
	 */
	public void setFieldSeparator(char cfieldSeparator) 
	{
		String strFSSeparator = "" + cfieldSeparator;
		ST fieldSeparator = (ST)getDataElement(1);
		fieldSeparator.setValue(strFSSeparator);
		objDelimiter.cFieldSeparator = cfieldSeparator;

		setFieldSeparator(fieldSeparator);
	}
	/**
	 * Set the Field Separator.
	 * This field contains the separator between the segment ID and the first real field.
	 * @param objfieldSeparator object of fieldSeparator.
	 */
	public void setFieldSeparator(ST objfieldSeparator) 
	{ 
		String strFSSeparator;
		strFSSeparator =(String)objfieldSeparator.getValue();
		char cfieldSeparator =strFSSeparator.charAt(0);
		objDelimiter.cFieldSeparator = cfieldSeparator;
		setDataType(1,objfieldSeparator);
	}
	/**
	 * Set the Encoding Char.
	 * This field contains the four characters in the following order: the 
	 * component separator, repetition separator, escape character, and subcomponent separator.
	 * @param cComponentSeparator Delimiter Use as ComponentSeparator
	 * @param cSubComponentSeparator Delimiter Use as SubComponentSeparator
	 * @param cRepetitionSeparator Delimiter Use as RepetitionSeparator
	 * @param cEscapeCharacter Delimiter Use as EscapeCharacter
	 * @param cTruncationCharacter Delimiter Use as TruncationCharacter
	 */
	public void setEncodingChars(char cComponentSeparator, char cSubComponentSeparator, char cRepetitionSeparator, char cEscapeCharacter, char cTruncationCharacter) 
	{
		objDelimiter.cComponentSeparator = cComponentSeparator;
		objDelimiter.cSubComponentSeparator = cSubComponentSeparator;
		objDelimiter.cRepetitionSeparator = cRepetitionSeparator;
		objDelimiter.cEscapeCharacter = cEscapeCharacter;
		objDelimiter.cTruncationCharacter = cTruncationCharacter;
		String strEncodingChar = "";
		strEncodingChar = strEncodingChar + cComponentSeparator +cRepetitionSeparator + cEscapeCharacter + cSubComponentSeparator + cTruncationCharacter; 
		ST encodingChar = (ST)getDataElement(2);
		encodingChar.setValue(strEncodingChar);
		setEncodingChars(encodingChar);
	}
	/**
	 * Set the Encoding Char.
	 * This field contains the four characters in the following order: the
	 * component separator, repetition separator, escape character, and subcomponent separator. 
	 * @param objencodingChar object of Encoding Char.
	 */
	public void setEncodingChars(ST objencodingChar) 
	{ 
		String strEncodingChar = (String)objencodingChar.getValue();
		objDelimiter.cComponentSeparator = strEncodingChar.charAt(0);
		objDelimiter.cRepetitionSeparator = strEncodingChar.charAt(1);
		objDelimiter.cEscapeCharacter = strEncodingChar.charAt(2);
		objDelimiter.cSubComponentSeparator = strEncodingChar.charAt(3);
		objDelimiter.cTruncationCharacter = strEncodingChar.charAt(4);
		setDataType(2,objencodingChar);
	}


	/**
	 * Set the Accept Acknowledgment Type.
	 * This field identify the conditions under which accept 
	 * acknowledgments are required to be returned in response to this message. 
	 * @param strAcceptAcknowledgmentType Specifies the conditions under which accept acknowledgments are required 
	 * 										to be returned in response to this message.Suggested Values AL,NE,ER,SU.
	 * 										[Refer Table No 0155]
	 * 
	 */ 
	public void setAcceptAcknowledgmentType (String strAcceptAcknowledgmentType) 
	{
		ID acceptAcknowledgmentType  = (ID)getDataElement(15);
		acceptAcknowledgmentType.setValue(strAcceptAcknowledgmentType); 
		setAcceptAcknowledgmentType(acceptAcknowledgmentType);
	} 

	/** Set the Accept Acknowledgment Type.
	 * This field identify the conditions under which accept 
	 * acknowledgments are required to be returned in response to this message. 
	 * @param objacceptAcknowledgmentType object of Accept Acknowledgment Type.
	 * 
	 */ 
	public void setAcceptAcknowledgmentType(ID objacceptAcknowledgmentType)
	{
		setDataType(15,objacceptAcknowledgmentType);
	}

	/** 
	 * Set the Alternate Character Set Handling Scheme.
	 * This field specify the Alternate Character Set Handling Scheme.
	 * @param strAlternateCharacterSetHandlingScheme Specifies any special handling scheme that is needed.Suggested 
	 * 												   Values ISO 2022-1994,2.3,<null>.[Refer Table No 0356]
	 */ 
	public void setAlternateCharacterSetHandlingScheme (String strAlternateCharacterSetHandlingScheme) 
	{
		ID alternateCharacterSetHandlingScheme  = (ID)getDataElement(1317);
		alternateCharacterSetHandlingScheme.setValue(strAlternateCharacterSetHandlingScheme); 
		setAlternateCharacterSetHandlingScheme(alternateCharacterSetHandlingScheme);
	} 

	/** Set the Alternate Character Set Handling Scheme.
	 * This field specify the Alternate Character Set Handling Scheme.
	 * @param objalternateCharacterSetHandlingScheme object of Alternate Character Set Handling Scheme.
	 */ 
	public void setAlternateCharacterSetHandlingScheme(ID objalternateCharacterSetHandlingScheme)
	{
		setDataType(1317,objalternateCharacterSetHandlingScheme);
	}	/**
	 * Set the Application Acknowledgment Type.
	 * This field contains the conditions under which application 
	 * acknowledgments are required to be returned in response to this message.  
	 * @param strApplicationAcknowledgmentType Specifies the conditions under which application acknowledgments are required 
	 * 										to be returned in response to this message.Suggested Values AL,NE,ER,SU.
	 * 										[Refer Table No 0155]
	 */ 
	public void setApplicationAcknowledgmentType (String strApplicationAcknowledgmentType) 
	{
		ID applicationAcknowledgmentType  = (ID)getDataElement(16);
		applicationAcknowledgmentType.setValue(strApplicationAcknowledgmentType); 
		setApplicationAcknowledgmentType(applicationAcknowledgmentType);
	} 

	/** Set the Application Acknowledgment Type.
	 * This field contains the conditions under which application 
	 * acknowledgments are required to be returned in response to this message.  
	 * @param objapplicationAcknowledgmentType object of Application Acknowledgment Type.
	 */ 
	public void setApplicationAcknowledgmentType(ID objapplicationAcknowledgmentType)
	{
		setDataType(16,objapplicationAcknowledgmentType);
	}	/** 
	 * Set the Character Set.
	 * This field contains the character set for the entire message. 
	 * @param strCharacterSet Specifies the character set for the entire message.Suggested Values ASCII,8859/1 ...
	 * 							[Refer Table No 0211]. 
	 */ 
	public void addCharacterSet (String strCharacterSet) 
	{
		ID tempCharacterSet  = (ID)getDataElement(692);
		tempCharacterSet.setValue(strCharacterSet); 
		addCharacterSet(tempCharacterSet);

	} 

	/** Set the object of Character Set  
	 * @param objtempCharacterSet object of  Character Set.  						
	 */ 
	public void addCharacterSet(ID objtempCharacterSet)
	{
		addDataType(692,objtempCharacterSet);
	}
	/**
	 * Set the CharacterSet list.
	 * @param objCharacterSetList List of CharacterSet
	 */	
	@SuppressWarnings("unchecked")
	public void setCharacterSet(ISingleCollection<ID> objCharacterSetList)
	{
		ISingleCollection<IDataType> objCollection = null;
		ISingleCollection<?> objUnknownCollection = (ISingleCollection<?>)objCharacterSetList;
		objCollection = (ISingleCollection<IDataType>)objUnknownCollection;
		setDataType(692,objCollection);
	}

	/** 
	 * Set the Continuation Pointer.
	 * This field is used to define continuations in application-specific ways.
	 * @param strContinuationPointer Specifies continuations in application-specific ways.
								   Only the sender of a fragmented message values this field.

	 */ 
	public void setContinuationPointer (String strContinuationPointer) 
	{
		ST continuationPointer  = (ST)getDataElement(14);
		continuationPointer.setValue(strContinuationPointer); 
		setContinuationPointer(continuationPointer);
	} 

	/** Set the Continuation Pointer.
	 * This field is used to define continuations in application-specific ways.
	 * @param objcontinuationPointer object of Continuation Pointer.
	 */ 
	public void setContinuationPointer(ST objcontinuationPointer)
	{
		setDataType(14,objcontinuationPointer);
	}	/** 
	 * Set the Country Code.
	 * This field contains the country of origin for the message. 
	 * @param strCountryCode  Specifies the country of origin for the message. It will be used primarily to specify 
	 * 						   default elements, such as currency denominations.No Suggested Values.Use 3-character 
	 * 						   (alphabetic) form of ISO 3166.[Refer Table No 0399]. 
	 */ 
	public void setCountryCode (String strCountryCode) 
	{
		ID countryCode  = (ID)getDataElement(17);
		countryCode.setValue(strCountryCode); 
		setCountryCode(countryCode);
	} 

	/** Set the Country Code.
	 * This field contains the country of origin for the message. 
	 * @param objcountryCode object of Country Code.
	 */ 
	public void setCountryCode(ID objcountryCode)
	{
		setDataType(17,objcountryCode);
	}	/** 
	 * Set the Date Time Of Message.
	 * This field contains the date/time that the sending system created the message.
	 * @param strTime Specifies a point in time using a 24-hour clock notation. 
	 */ 
	public void setDateTimeOfMessage (String strTime) 
	{
		DTM dateTimeOfMessage  = (DTM)getDataElement(7);
		dateTimeOfMessage.setValue(strTime);
		setDateTimeOfMessage(dateTimeOfMessage);
	} 

	/** 
	 * Set the  Date Time Of Message.
	 * @param objdateTimeOfMessage object of Date Time Of Message.
	 */ 
	public void setDateTimeOfMessage(DTM objdateTimeOfMessage)
	{
		setDataType(7,objdateTimeOfMessage);
	}	/** 
	 * Set the Message Control ID.
	 * This field contains a number or other identifier that uniquely identifies the message. 
	 * @param strMessageControlID Specifies a number or other identifier that uniquely identifies the message. 
	 */ 
	public void setMessageControlID (String strMessageControlID) 
	{
		ST messageControlID  = (ST)getDataElement(10);
		messageControlID.setValue(strMessageControlID); 
		setMessageControlID(messageControlID);

	} 

	/** Set the Message Control ID.
	 * This field contains a number or other identifier that uniquely identifies the message. 
	 * @param objmessageControlID object of MessageControlID 
	 */ 
	public void setMessageControlID(ST objmessageControlID)
	{
		setDataType(10,objmessageControlID);

	}	/** 
	 * Set the Message Profile Identifier.
	 * This field specify that Sites may use this field to assert adherence to, or reference, a 
	 * message profile. Message profiles contain detailed explanations of grammar, syntax, 
	 * and usage for a particular message or set of messages. 
	 * @param strEntityIdentifier Specifies defined by a hierarchic designator, represented by components 2 through 4.
	 * 								[Reference Section 2.A.33, "HD - hierarchic designator".] 
	 * @param strNamespaceId Specifies  the HL7 identifier for the user-defined table of values for this component.
	 * 						   [Refer to User-defined Table 0363 - Assigning authority] 	 
	 * @param strUniversalId Specifies string formatted according to the scheme defined by the component, 
	 * 							<universal ID type> (UID type). 
	 * @param strUniversalIdType Specifies  the interpretation of the second component of the HD. 
	 */ 
	public void addMessageProfileIdentifier (String strEntityIdentifier,String strNamespaceId,String strUniversalId,
			String strUniversalIdType)
	{
		EI tempMessageProfileIdentifier  = (EI)getDataElement(1598);
		tempMessageProfileIdentifier.setEntityIdentifier(strEntityIdentifier);
		tempMessageProfileIdentifier.setNamespaceId(strNamespaceId);
		tempMessageProfileIdentifier.setUniversalId(strUniversalId);
		tempMessageProfileIdentifier.setUniversalIdType(strUniversalIdType); 
		addMessageProfileIdentifier(tempMessageProfileIdentifier);
	} 

	/** Set the Message Profile Identifier.
	 * This field specify that Sites may use this field to assert adherence to, or reference, a 
	 * message profile. Message profiles contain detailed explanations of grammar, syntax, 
	 * and usage for a particular message or set of messages. 
	 * @param objtempMessageProfileIdentifier object of Message Profile Identifier. 
	 */ 
	public void addMessageProfileIdentifier(EI objtempMessageProfileIdentifier)
	{
		addDataType(1598,objtempMessageProfileIdentifier);
	}
	/**
	 * Set the MessageProfileIdentifier list.
	 * @param objMessageProfileIdentifierList List of MessageProfileIdentifier
	 */	


	@SuppressWarnings("unchecked")
	public void setMessageProfileIdentifier(ISingleCollection<EI> objMessageProfileIdentifierList)
	{
		ISingleCollection<IDataType> objCollection = null;
		ISingleCollection<?> objUnknownCollection = (ISingleCollection<?>)objMessageProfileIdentifierList;
		objCollection = (ISingleCollection<IDataType>)objUnknownCollection;
		setDataType(1598,objCollection);
	}

	/** 
	 * Set the Message Type.
	 * This field contains the message type, trigger event, and the message structure ID for the message.
	 * @param strMessageCode Specifies the message type code.Suggested values such as ACK, ADT, ORM, ORU etc.
	 * @param strTriggerEvent Specifies the trigger event code. 
	 * @param strMessageStructure Specifies the abstract message structure code. 
	 */ 
	public void setMessageType (String strMessageCode,String strTriggerEvent,String strMessageStructure) 
	{
		MSG messageType  = (MSG)getDataElement(9);
		messageType.setMessageCode(strMessageCode);
		messageType.setTriggerEvent(strTriggerEvent);
		messageType.setMessageStructure(strMessageStructure);
		setMessageType(messageType);
	} 

	/** Set the Message Type.
	 * This field contains the message type, trigger event, and the message structure ID for the message.
	 * @param objmessageType object of Message Type. 
	 */ 
	public void setMessageType(MSG objmessageType)
	{
		setDataType(9,objmessageType);
	}	/** 
	 * Set the Principal Language Of Message.
	 * This field contains the principal language of the message. Codes come from ISO 639. 
	 * @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 setPrincipalLanguageOfMessage (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(693);
		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); 
		setPrincipalLanguageOfMessage(cwe);

	} 

	/** Set the Principal Language Of Message.
	 * This field contains the principal language of the message. Codes come from ISO 639. 
	 * @param objprincipalLanguageOfMessage object of Principal Language Of Message.
	 */ 
	public void setPrincipalLanguageOfMessage(CWE objprincipalLanguageOfMessage)
	{
		setDataType(693,objprincipalLanguageOfMessage);
	}	/** 
	 * Set the Processing ID.
	 * This field is use to decide whether to process the message as defined in HL7 Application or not. 
	 * @param strProcessingId Specifies a value that defines whether the message is part of a production, training, 
	 * 							or debugging system. 
	 * @param strProcessingMode Specifies a value that defines whether the message is part of an archival process or
	 * 							  an initial load.
	 */ 
	public void setProcessingID (String strProcessingId,String strProcessingMode) 
	{
		PT processingID  = (PT)getDataElement(11);
		processingID.setProcessingId(strProcessingId);
		processingID.setProcessingMode(strProcessingMode);
		setProcessingID(processingID);
	} 

	/** Set the Processing ID.
	 * This field is use to decide whether to process the message as defined in HL7 Application or not. 
	 * @param objprocessingID object of Processing ID. 
	 */ 
	public void setProcessingID(PT objprocessingID)
	{
		setDataType(11,objprocessingID);
	}	/** 
	 * Set the Receiving Application.
	 * This field uniquely identify the receiving application among all other applications within the network enterprise
	 * @param strNamespaceId Specifies Specifies  the HL7 identifier for the user-defined table of values for this component.[Refer Table No.300]
	 * @param strUniversalId Specifies a string formatted according to the scheme defined by the component, <universal ID type> (UID type). 
	 * @param strUniversalIdType Governs the interpretation of the strUniversalId. 
	 */ 
	public void setReceivingApplication (String strNamespaceId,String strUniversalId,String strUniversalIdType) 
	{
		HD receivingApplication  = (HD)getDataElement(5);
		receivingApplication.setNamespaceId(strNamespaceId);
		receivingApplication.setUniversalId(strUniversalId);
		receivingApplication.setUniversalIdType(strUniversalIdType);
		setReceivingApplication(receivingApplication);
	} 

	/** Set the Receiving Application.
	 * This field uniquely identify the receiving application among all other applications within the network enterprise
	 * @param objreceivingApplication object of Receiving Application. 
	 */ 
	public void setReceivingApplication(HD objreceivingApplication)
	{
		setDataType(5,objreceivingApplication);
	}	/** 
	 * Set the Receiving Facility.
	 * This field identify the receiving application among multiple identical instances of 
	 * the application running on behalf of different organizations.
	 * @param strNamespaceId Specifies Specifies  the HL7 identifier for the user-defined table of values for this component.[Refer Table No.300]
	 * @param strUniversalId Specifies a string formatted according to the scheme defined by the component, <universal ID type> (UID type). 
	 * @param strUniversalIdType Governs the interpretation of the strUniversalId. 
	 */ 
	public void setReceivingFacility (String strNamespaceId,String strUniversalId,String strUniversalIdType) 
	{
		HD receivingFacility  = (HD)getDataElement(6);
		receivingFacility.setNamespaceId(strNamespaceId);
		receivingFacility.setUniversalId(strUniversalId);
		receivingFacility.setUniversalIdType(strUniversalIdType); 
		setReceivingFacility(receivingFacility);
	} 

	/** Set the Receiving Facility.
	 * This field identify the receiving application among multiple identical instances of 
	 * the application running on behalf of different organizations.
	 * @param objreceivingFacility object of Receiving Facility. 
	 */ 
	public void setReceivingFacility(HD objreceivingFacility)
	{
		setDataType(6,objreceivingFacility);
	}	/** 
	 * Set the Security.
	 * @param strSecurity Specifies a field ,that is used to implement security features. 
	 */ 
	public void setSecurity (String strSecurity) 
	{
		ST security  = (ST)getDataElement(8);
		security.setValue(strSecurity); 
		setSecurity(security);
	} 

	/** Set the Security.
	 * @param objsecurity object of Security. 
	 */ 
	public void setSecurity(ST objsecurity)
	{
		setDataType(8,objsecurity);
	}	/** 
	 * Set the Sending Application.
	 * This field uniquely identifies the sending application among all other applications within the network enterprise.
	 * @param strNamespaceId Specifies Specifies  the HL7 identifier for the user-defined table of values for this component.[Refer Table No.300]
	 * @param strUniversalId Specifies a string formatted according to the scheme defined by the component, <universal ID type> (UID type). 
	 * @param strUniversalIdType Governs the interpretation of the strUniversalId. 
	 */ 
	public void setSendingApplication (String strNamespaceId,String strUniversalId,String strUniversalIdType) 
	{
		HD sendingApplication  = (HD)getDataElement(3);
		sendingApplication.setNamespaceId(strNamespaceId);
		sendingApplication.setUniversalId(strUniversalId);
		sendingApplication.setUniversalIdType(strUniversalIdType); 
		setSendingApplication(sendingApplication);
	} 

	/** Set the Sending Application.
	 * This field uniquely identifies the sending application among all other applications within the network enterprise.
	 * @param objsendingApplication object of Sending Application. 
	 */ 
	public void setSendingApplication(HD objsendingApplication)
	{
		setDataType(3,objsendingApplication);
	}	/** 
	 * Set the Sending Facility.
	 * This field used as the HL7 identifier for the user-defined table of values for the first component.
	 * @param strNamespaceId Specifies Specifies  the HL7 identifier for the user-defined table of values for this component.[Refer Table No.300]
	 * @param strUniversalId Specifies a string formatted according to the scheme defined by the component, <universal ID type> (UID type). 
	 * @param strUniversalIdType Governs the interpretation of the strUniversalId. 
	 */ 
	public void setSendingFacility (String strNamespaceId,String strUniversalId,String strUniversalIdType) 
	{
		HD sendingFacility  = (HD)getDataElement(4);
		sendingFacility.setNamespaceId(strNamespaceId);
		sendingFacility.setUniversalId(strUniversalId);
		sendingFacility.setUniversalIdType(strUniversalIdType); 
		setSendingFacility(sendingFacility);
	} 

	/** Set the Sending Facility.
	 * This field used as the HL7 identifier for the user-defined table of values for the first component.
	 * @param objsendingFacility object of Sending Facility. 
	 */ 
	public void setSendingFacility(HD objsendingFacility)
	{
		setDataType(4,objsendingFacility);
	}	/** 
	 * Set the Sequence Number.
	 * This field implies that the sequence number protocol is in use.
	 * @param strSequenceNumber Specifies a non null value in this field implies that the sequence number protocol is in use. 
	 */ 
	public void setSequenceNumber (String strSequenceNumber) 
	{
		NM sequenceNumber  = (NM)getDataElement(13);
		sequenceNumber.setValue(strSequenceNumber); 
		setSequenceNumber(sequenceNumber);
	} 

	/** Set the Sequence Number.
	 * This field implies that the sequence number protocol is in use.
	 * @param objsequenceNumber object of Sequence Number. 
	 */ 
	public void setSequenceNumber(NM objsequenceNumber)
	{
		setDataType(13,objsequenceNumber);
	}	/** 
	 * Set the Version ID.
	 * This field is matched by the receiving system to its own version to be sure the message
	 * will be interpreted correctly. 
	 * @param strVersionId Used to identify the HL7 version. 
	 * @param objInternationalizationCode Used to identify the international affiliate country code. 
	 * @param objInternationalVersionId International affiliate's version.
	 */ 
	public void setVersionID (String strVersionId,CWE objInternationalizationCode,CWE objInternationalVersionId) 
	{
		VID versionID  = (VID)getDataElement(12);
		versionID.setVersionId(strVersionId);
		versionID.setInternationalizationCode(objInternationalizationCode);
		versionID.setInternationalVersionId(objInternationalVersionId);
		setVersionID(versionID);
	} 

	/** Set the Version ID.
	 * This field is matched by the receiving system to its own version to be sure the message
	 * will be interpreted correctly. 
	 * @param objversionID object of Version ID.
	 */ 
	public void setVersionID(VID objversionID)
	{
		setDataType(12,objversionID);

	}
	
	/**
	 * Retrieves the Sending Responsible Organization.
	 * Business organization that originated and is accountable for the content of the message.  
	 * @return XON - SendingResponsibleOrganization
	 */
	public XON getSendingResponsibleOrganization() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1823);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (XON)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Set the Sending Responsible Organization.
	 * Business organization that originated and is accountable for the content of the message.  
	 * @param strOrganizationName Specifies name of the specified organization.
	 * @param strOrganizationNameTypeCode Specifies a code that represents the type of name i.e., legal name, display name.
	 * 										Suggested Values A,L,D,SL.[Refer to table No.0204]  
	 * @param objAssigningAuthority Specifies The assigning authority is a unique identifier of the system 
	 * 									(or organization or agency or department) that creates the data. 
	 * @param strIdentifierTypeCode Specifies a code corresponding to the type of identifier. 
	 * @param objAssigningFacility Specifies The place or location identifier where the identifier was first assigned to the person. 
	 * @param strNameRepresentationCode Specifies representations of the same name/address Suggested values are I,A,P [Refer table 0465] 
	 * @param strOrganizationIdentifier This component contains the sequence of characters (the code) that uniquely 
	 * 									  identifies the item being referenced by XON.1 Organization Name. 
	 * 									  This component replaces XON.3 ID Number as of v 2.5.
	 */ 
	public void setSendingResponsibleOrganization (String strOrganizationName, CWE objOrganizationNameTypeCode,
			 HD objAssigningAuthority,
			String strIdentifierTypeCode, HD objAssigningFacility, String strNameRepresentationCode,
			String strOrganizationIdentifier)
	{
		XON SendingResponsibleOrganization  = (XON)getDataElement(1823);
		SendingResponsibleOrganization.setOrganizationName(strOrganizationName);
		SendingResponsibleOrganization.setOrganizationNameTypeCode(objOrganizationNameTypeCode);
		SendingResponsibleOrganization.setAssigningAuthority(objAssigningAuthority);
		SendingResponsibleOrganization.setIdentifierTypeCode(strIdentifierTypeCode);
		SendingResponsibleOrganization.setAssigningFacility(objAssigningFacility);
		SendingResponsibleOrganization.setNameRepresentationCode(strNameRepresentationCode);
		SendingResponsibleOrganization.setOrganizationIdentifier(strOrganizationIdentifier); 
		setSendingResponsibleOrganization(SendingResponsibleOrganization);
	} 

	/**
	 * Ses the Sending Responsible Organization.
	 * Business organization that originated and is accountable for the content of the message.  
	 * @param objSendingResponsibleOrganization object of Sending Responsible Organization. 
	 */ 
	public void setSendingResponsibleOrganization(XON objSendingResponsibleOrganization)
	{
		setDataType(1823,objSendingResponsibleOrganization);
	}
	
	/**
	 * Retrieves the Receiving Responsible Organization.
	 * Business organization that is the intended receiver of the message and is accountable for acting on the data conveyed by the transaction.  
	 * @return XON - ReceivingResponsibleOrganization
	 */
	public XON getReceivingResponsibleOrganization() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1824);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (XON)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Set the Receiving Responsible Organization.
	 * Business organization that is the intended receiver of the message and is accountable for acting on the data conveyed by the transaction.  
	 * @param strOrganizationName Specifies name of the specified organization.
	 * @param strOrganizationNameTypeCode Specifies a code that represents the type of name i.e., legal name, display name.
	 * 										Suggested Values A,L,D,SL.[Refer to table No.0204]  
	 * @param objAssigningAuthority Specifies The assigning authority is a unique identifier of the system 
	 * 									(or organization or agency or department) that creates the data. 
	 * @param strIdentifierTypeCode Specifies a code corresponding to the type of identifier. 
	 * @param objAssigningFacility Specifies The place or location identifier where the identifier was first assigned to the person. 
	 * @param strNameRepresentationCode Specifies representations of the same name/address Suggested values are I,A,P [Refer table 0465] 
	 * @param strOrganizationIdentifier This component contains the sequence of characters (the code) that uniquely 
	 * 									  identifies the item being referenced by XON.1 Organization Name. 
	 * 									  This component replaces XON.3 ID Number as of v 2.5.
	 */ 
	public void setReceivingResponsibleOrganization (String strOrganizationName, CWE objOrganizationNameTypeCode,
			 HD objAssigningAuthority,
			String strIdentifierTypeCode, HD objAssigningFacility, String strNameRepresentationCode,
			String strOrganizationIdentifier)
	{
		XON ReceivingResponsibleOrganization  = (XON)getDataElement(1824);
		ReceivingResponsibleOrganization.setOrganizationName(strOrganizationName);
		ReceivingResponsibleOrganization.setOrganizationNameTypeCode(objOrganizationNameTypeCode);
		ReceivingResponsibleOrganization.setAssigningAuthority(objAssigningAuthority);
		ReceivingResponsibleOrganization.setIdentifierTypeCode(strIdentifierTypeCode);
		ReceivingResponsibleOrganization.setAssigningFacility(objAssigningFacility);
		ReceivingResponsibleOrganization.setNameRepresentationCode(strNameRepresentationCode);
		ReceivingResponsibleOrganization.setOrganizationIdentifier(strOrganizationIdentifier); 
		setReceivingResponsibleOrganization(ReceivingResponsibleOrganization);
	} 

	/**
	 * Ses the Receiving Responsible Organization.
	 * Business organization that is the intended receiver of the message and is accountable for acting on the data conveyed by the transaction.  
	 * @param objReceivingResponsibleOrganization object of Receiving Responsible Organization. 
	 */ 
	public void setReceivingResponsibleOrganization(XON objReceivingResponsibleOrganization)
	{
		setDataType(1824,objReceivingResponsibleOrganization);
	}
	
	/**
	 * Retrieves the Sending Network Address.
	 * Identifier of the network location the message was transmitted from.    
	 * @return HD - receivingApplication
	 */
	public HD getSendingNetworkAddress()
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1825);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (HD)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/** 
	 * Set the Sending Network Address.
	 * Identifier of the network location the message was transmitted from.    
	 * @param strNamespaceId Specifies Specifies  the HL7 identifier for the user-defined table of values for this component.[Refer Table No.300]
	 * @param strUniversalId Specifies a string formatted according to the scheme defined by the component, <universal ID type> (UID type). 
	 * @param strUniversalIdType Governs the interpretation of the strUniversalId. 
	 */
	public void setSendingNetworkAddress(String strNamespaceId,String strUniversalId,String strUniversalIdType) 
	{
		HD receivingApplication  = (HD)getDataElement(1825);
		receivingApplication.setNamespaceId(strNamespaceId);
		receivingApplication.setUniversalId(strUniversalId);
		receivingApplication.setUniversalIdType(strUniversalIdType);
		setSendingNetworkAddress(receivingApplication);
	}

	/**
	 * Set the Sending Network Address.
	 * Identifier of the network location the message was transmitted from.    
	 * @param objReceivingApplication Object of Receiving Application.
	 */
	public void setSendingNetworkAddress(HD objReceivingApplication)
	{
		setDataType(1825,objReceivingApplication);
	}
	
	/**
	 * Retrieves the Receiving Network Address.
	 * Identifier of the network location the message was transmitted to.  
	 * @return HD - receivingApplication
	 */
	public HD getReceivingNetworkAddress()
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1826);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (HD)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/** 
	 * Set the Receiving Network Address.
	 * Identifier of the network location the message was transmitted to.  
	 * @param strNamespaceId Specifies Specifies  the HL7 identifier for the user-defined table of values for this component.[Refer Table No.300]
	 * @param strUniversalId Specifies a string formatted according to the scheme defined by the component, <universal ID type> (UID type). 
	 * @param strUniversalIdType Governs the interpretation of the strUniversalId. 
	 */
	public void setReceivingNetworkAddress(String strNamespaceId,String strUniversalId,String strUniversalIdType) 
	{
		HD receivingApplication  = (HD)getDataElement(1826);
		receivingApplication.setNamespaceId(strNamespaceId);
		receivingApplication.setUniversalId(strUniversalId);
		receivingApplication.setUniversalIdType(strUniversalIdType);
		setReceivingNetworkAddress(receivingApplication);
	}

	/**
	 * Set the Receiving Network Address.
	 * Identifier of the network location the message was transmitted to.  
	 * @param objReceivingApplication Object of Receiving Application.
	 */
	public void setReceivingNetworkAddress(HD objReceivingApplication)
	{
		setDataType(1826,objReceivingApplication);
	}
	
	/**
	 * 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 Thrown when Any of required filed is missing.
	 */
	public boolean validate() throws InvalidSegmentException
	{
		try
		{
			super.validate();

			return true;
		}
		catch(FieldMissingException ex)
		{
			throw new InvalidSegmentException(enumSegments.getValue(),ex);
		}
	}

	/**
	 * Serializes HL7 Message objects.
	 * Before serializaton it validates Message as per HL7 v2.5 standard.
	 * For successfull serialization , Message Object should follow order of segments as per its corresponding Message Structure. 
	 * Serialize method fails if given stream is null.
	 * It mandates presence of required segments and the number of occurences specified by the standard.
	 * This method also checks for presence of Mandatory Groups.It also verifies repeatability of Group.
	 * @param objIHL7Stream Object of IHL7Stream.
	 * @param objIDelimiter Object of class Delimiter.
	 * @return int - [failure or success].
	 * @throws SerializeException Thrown when serialization of Message fails. 
	 * @throws IOException  Signals that an I/O exception of some sort has occurred.
	 */
	public int serialize(IHL7Stream objIHL7Stream,IDelimiter objIDelimiter) throws SerializeException,IOException
	{
		try
		{
			ISingleCollection<Integer> objItemIDList = objSegmentMap.getItemIDList();
			// get the Character used as the repetition Seperator for the repeating field. 
			char cRSeparator = objIDelimiter.getRepetitionSeparator();
			if(cRSeparator == '\0')
				throw new DelimiterMissingException(ResourceBundleWrapper.getValue("exceptions", "RepetitionSeparatorMissing", new Locale(HL7Config.createInstance().getLocale())));			//get the Character used as the Field Seperator for Seperating the field. 
			char cFSeparator = objIDelimiter.getFieldSeparator();
			if(cFSeparator == '\0')
				throw new DelimiterMissingException(ResourceBundleWrapper.getValue("exceptions", "FieldSeparatorMissing", new Locale(HL7Config.createInstance().getLocale())));
			//write name of Segment.
			objIHL7Stream.writeString(EnumSegments.HL7_SEG_MSH.getValue());
			objIHL7Stream.writeChar(cFSeparator);
			//This write is called in plase of write on "encodingChar" field of MSH.
			objDelimiter.writeDelimiters(objIHL7Stream);
			objIHL7Stream.writeChar(cFSeparator);
			
			for(int seqno = 2; seqno < objItemIDList.size();seqno++)
			{
				int itemID = objItemIDList.elementAt(seqno);

				ISingleCollection<IDataType> objDataTypeList = objDataElementList.get(itemID);

				if(objDataTypeList != null)
				{
					int iSize = objDataTypeList.size();
					for(int index = 0; index < objDataTypeList.size(); index++)
					{
						IDataType objIDataType = objDataTypeList.elementAt(index);
						objIDataType.write(objIHL7Stream,objIDelimiter);

						if(index != iSize - 1)
							objIHL7Stream.writeChar(cRSeparator);
					}
				}
				if(seqno != objItemIDList.size() - 1)
				{
					//This Code checks next elements are present or not
					for(int i= seqno+1 ; i<objItemIDList.size();i++)
					{
						int itemID1 = objItemIDList.elementAt(i);
						ISingleCollection<IDataType> objDataTypeList1 = objDataElementList.get(itemID1);
						//If next element is present then it appends Field Separator
						if(objDataTypeList1 != null)
						{
							objIHL7Stream.writeChar(cFSeparator);
							break;
						}
					}
				}
			}

			//This character shows the end of the segment.
			objIHL7Stream.writeChar('\r');
			return HL7Constants.HL7_FUNCTION_SUCCESS;
		}
		catch(InvalidSegmentException ex)
		{
			throw new SerializeException(this.getClass().getSimpleName(),ex);
		}
		catch(DelimiterMissingException ex)
		{
			throw new SerializeException(this.getClass().getSimpleName(),ex);
		}
	}
	
	/**
	 * Parses HL7 Segment Strings from any Stream into HL7 Segment object.
	 * This method checks for the Repetition of the fields in the Segment.
	 * It also checks for the optionality of the fields as whether they are mandatory or optional.
	 * Successful parsing of the segment populates the object with the data present on the stream and provides
	 * easy accessor and mutator methods to navigate the message.
	 * It also leads to failure if version of given HL7 Message is not 2.8.2.
	 * This method raises exception if there is Segment which is not valid as per HL7 v 2.8.2 standard.
	 * @param strSegmentStream String from HL7Stream.
	 * @param objIDelimiter Object of class Delimiter.
	 * @return int - Success if segment is valid.
	 * 			   - Fail if segment in not valid.
	 * @throws InvalidSegmentException Thrown when Field Validation Fails.
	 * @throws IOException Signals that an I/O exception of some sort has occurred.
	 */
		
	public int parse(String strSegmentStream,IDelimiter objIDelimiter) throws InvalidSegmentException,IOException
	{
		int iRetVal = HL7Constants.HL7_FUNCTION_FAIL;
		char cReadChar = '\0';
		try
		{
			int i = -1;
			
			do
			{	
				String strTemp = "";
				String strField="";
				//After MSH the next character is field separator.
				//Read Field Seperator
				cReadChar =strSegmentStream.charAt(++i);
				//Read value of field seperator to Delimiter
				objDelimiter.cFieldSeparator = cReadChar;
				strTemp = "" + cReadChar;
				ST fieldSeparator = (ST)getDataElement(1);
				
				fieldSeparator.setValue(strTemp);
				setDataType(1, fieldSeparator);
				//Read encoding char

				String encodingChars="";
				char ch;
				do
				{
					ch=strSegmentStream.charAt(++i);
					encodingChars=encodingChars+ch;
						
				}while(ch!='|');
				iRetVal = objDelimiter.readDelimiters(encodingChars);
				if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					setUnRecognizedField("MSH", "Encoding Characters", encodingChars);
					return iRetVal;
				}
				strTemp = "";
				strTemp = strTemp + objDelimiter.cComponentSeparator + objDelimiter.cRepetitionSeparator; 
				if(objDelimiter.cEscapeCharacter != '\0')
					strTemp = strTemp+ objDelimiter.cEscapeCharacter + objDelimiter.cSubComponentSeparator;
				
				if(objDelimiter.cTruncationCharacter != '\0')
					strTemp = strTemp+ objDelimiter.cTruncationCharacter;
				
				ST encodingChar = (ST)getDataElement(2);
				encodingChar.setValue(strTemp);
				setDataType(2, encodingChar);
				objIDelimiter = objDelimiter;
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;
				//Read Sending Application
				HD sendingApplication = (HD)getDataElement(3);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = sendingApplication.read(strField, objIDelimiter);
				if(iRetVal == 0)
				{
					sendingApplication = null;
				}
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					sendingApplication = null;
					setUnRecognizedField("MSH","Sending Application",strField);
				}
				else
				{
					setDataType(3, sendingApplication);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Sending Facility
				HD sendingFacility = (HD)getDataElement(4);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = sendingFacility.read(strField, objIDelimiter);
				if(iRetVal == 0)
				{
					sendingFacility = null;
				}
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					sendingFacility = null;
					setUnRecognizedField("MSH","Sending Facility",strField);
				}
				else
				{
					setDataType(4, sendingFacility);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Receiving Application
				HD receivingApplication = (HD)getDataElement(5);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = receivingApplication.read(strField, objIDelimiter);
				if(iRetVal == 0)
					receivingApplication = null;
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					receivingApplication = null;
					setUnRecognizedField("MSH","Receiving Application",strField);
				}
				else
				{
					setDataType(5, receivingApplication);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Receiving Facility
				HD receivingFacility = (HD)getDataElement(6);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = receivingFacility.read(strField, objIDelimiter);
				if(iRetVal == 0)
					receivingFacility = null;
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					receivingFacility = null;
					setUnRecognizedField("MSH","Receiving Facility",strField);
				}
				else
				{
					setDataType(6, receivingFacility);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Date-Time Of Message
				DTM dateTimeOfMessage = (DTM)getDataElement(7);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = dateTimeOfMessage.read(strField, objIDelimiter);
				if(iRetVal == 0)
				{
					dateTimeOfMessage = null;
					throw new FieldMissingException(ResourceBundleWrapper.getValue("exceptions", "REQUIRED_FIELD_MISSING", new Locale(HL7Config.createInstance().getLocale())));
				}
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					dateTimeOfMessage = null;
					setUnRecognizedField("MSH","DateTime Of Message",strField);
					return iRetVal;
				}
				else
				{
					setDataType(7, dateTimeOfMessage);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Security
				ST security = (ST)getDataElement(8);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = security.read(strField, objIDelimiter);
				if(iRetVal == 0)
					security = null;
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					security = null;
					setUnRecognizedField("MSH","Security",strField);
				}
				else
				{
					setDataType(8, security);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Message Type
				MSG messageType = (MSG)getDataElement(9);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = messageType.read(strField, objIDelimiter);
				if(iRetVal == 0)
				{
					messageType = null;
					throw new FieldMissingException(ResourceBundleWrapper.getValue("exceptions", "REQUIRED_FIELD_MISSING", new Locale(HL7Config.createInstance().getLocale())));
				}
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					messageType = null;
					setUnRecognizedField("MSH","Message Type",strField);
					return iRetVal;
				}
				else
				{
					setDataType(9, messageType);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Message Control ID
				ST messageControlID = (ST)getDataElement(10);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = messageControlID.read(strField, objIDelimiter);
				if(iRetVal == 0)
				{
					messageControlID = null;
					throw new FieldMissingException(ResourceBundleWrapper.getValue("exceptions", "REQUIRED_FIELD_MISSING", new Locale(HL7Config.createInstance().getLocale())));
				}
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					messageControlID = null;
					setUnRecognizedField("MSH","Message Control ID",strField);
					return iRetVal;
				}
				else
				{
					setDataType(10, messageControlID);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Processing ID
				PT processingID = (PT)getDataElement(11);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = processingID.read(strField, objIDelimiter);
				if(iRetVal == 0)
				{
					processingID = null;
					throw new FieldMissingException(ResourceBundleWrapper.getValue("exceptions", "REQUIRED_FIELD_MISSING", new Locale(HL7Config.createInstance().getLocale())));
				}
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					processingID = null;
					setUnRecognizedField("MSH","Processing ID",strField);
					return iRetVal;
				}
				else
				{
					setDataType(11, processingID);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Version ID
				VID versionID = (VID)getDataElement(12);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = versionID.read(strField, objIDelimiter);
				if(iRetVal == 0)
				{
					versionID = null;
					throw new FieldMissingException(ResourceBundleWrapper.getValue("exceptions", "REQUIRED_FIELD_MISSING", new Locale(HL7Config.createInstance().getLocale())));
				}
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					versionID = null;
					setUnRecognizedField("MSH","Version ID",strField);
					return iRetVal;
				}
				else
				{
					setDataType(12, versionID);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Sequence Number
				NM sequenceNumber = (NM)getDataElement(13);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = sequenceNumber.read(strField, objIDelimiter);
				if(iRetVal == 0)
					sequenceNumber = null;
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					sequenceNumber = null;
					setUnRecognizedField("MSH","Sequence Number",strField);
					moveToNextSegment(strField);
				}
				else
				{
					setDataType(13, sequenceNumber);
				}
				strField=""; 
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Continuation Pointer
				ST continuationPointer = (ST)getDataElement(14);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = continuationPointer.read(strField, objIDelimiter);
				if(iRetVal == 0)
					continuationPointer = null;
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					continuationPointer = null;
					setUnRecognizedField("MSH","Continuation Pointer",strField);
				}
				else
				{
					setDataType(14, continuationPointer);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Accept Acknowledgment Type
				ID acceptAcknowledgmentType = (ID)getDataElement(15);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = acceptAcknowledgmentType.read(strField, objIDelimiter);
				if(iRetVal == 0)
					acceptAcknowledgmentType = null;
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					acceptAcknowledgmentType = null;
					setUnRecognizedField("MSH","Accept Acknowledgment Type",strField);	
				}
				else
				{
					setDataType(15, acceptAcknowledgmentType);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Application Acknowledgment Type
				ID applicationAcknowledgmentType = (ID)getDataElement(16);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = applicationAcknowledgmentType.read(strField, objIDelimiter);
				if(iRetVal == 0)
					applicationAcknowledgmentType = null;
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					applicationAcknowledgmentType = null;
					setUnRecognizedField("MSH","Application Acknowledgment Type",strField);			
				}
				else
				{
					setDataType(16, applicationAcknowledgmentType);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Country Code
				ID countryCode = (ID)getDataElement(17);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = countryCode.read(strField, objIDelimiter);
				if(iRetVal == 0)
					countryCode = null;
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					countryCode = null;
					setUnRecognizedField("MSH","Country Code",strField);		
				}
				else
				{
					setDataType(17, countryCode);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Character Set
				  
				do
				{
					ID tempCharacterSet = (ID)getDataElement(692);
					do
					{
						strField=strField+strSegmentStream.charAt(++i);
					
					}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
					iRetVal = tempCharacterSet.read(strField, objIDelimiter);
					if(iRetVal == 0)
					{
						tempCharacterSet = null;
						strField="";
						cReadChar = '\0';
						cReadChar = strSegmentStream.charAt(i);
						break;
					}
					else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
					{
						tempCharacterSet = null;
						setUnRecognizedField("MSH","Character Set",strField);					
					}
					else
					{
						addDataType(692, tempCharacterSet);
						strField="";
						cReadChar = '\0';
						cReadChar = strSegmentStream.charAt(i);
					}
				}while(cReadChar == objDelimiter.cRepetitionSeparator);

				if(cReadChar != objDelimiter.cFieldSeparator)
					break;
				//Read Principal Language Of Message
				CWE principalLanguageOfMessage = (CWE)getDataElement(693);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = principalLanguageOfMessage.read(strField, objIDelimiter);
				if(iRetVal == 0)
					principalLanguageOfMessage = null;
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					principalLanguageOfMessage = null;
					setUnRecognizedField("MSH","Principal Language Of Message",strField);
				}
				else
				{
					setDataType(693, principalLanguageOfMessage);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Alternate Character Set Handling Scheme
				ID alternateCharacterSetHandlingScheme = (ID)getDataElement(1317);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = alternateCharacterSetHandlingScheme.read(strField, objIDelimiter);
				if(iRetVal == 0)
					alternateCharacterSetHandlingScheme = null;
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					alternateCharacterSetHandlingScheme = null;
					setUnRecognizedField("MSH","Alternate Character Set Handling Scheme",strField);
				}
				else
				{
					setDataType(1317, alternateCharacterSetHandlingScheme);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

				//Read Message Profile Identifier
				  
				do
				{
					EI tempMessageProfileIdentifier = (EI)getDataElement(1598);
					do
					{
						strField=strField+strSegmentStream.charAt(++i);
					
					}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
					iRetVal = tempMessageProfileIdentifier.read(strField, objIDelimiter);
					if(iRetVal == 0)
					{
						tempMessageProfileIdentifier = null;
						strField="";
						cReadChar = '\0';
						cReadChar = strSegmentStream.charAt(i);
						break;
					}
					else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
					{
						tempMessageProfileIdentifier = null;
						setUnRecognizedField("MSH ","Message Profile Identifier",strField);
					}
					else
					{
						addDataType(1598, tempMessageProfileIdentifier);
						strField="";
						cReadChar = '\0';
						cReadChar = strSegmentStream.charAt(i);
					}
				}while(cReadChar == objDelimiter.cRepetitionSeparator);

				if(cReadChar != objDelimiter.cFieldSeparator)
					break;
				
				//Sending Responsible Organization
				XON sendingRespOrg = (XON)getDataElement(1823);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = sendingRespOrg.read(strField, objIDelimiter);
				if(iRetVal == 0)
					sendingRespOrg = null;
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					sendingRespOrg = null;
					setUnRecognizedField("MSH","Sending Responsible Organization",strField);
				}
				else
				{
					setDataType(1823, sendingRespOrg);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;
				
				//Receiving Responsible Organization
				XON receivingRespOrg = (XON)getDataElement(1824);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = receivingRespOrg.read(strField, objIDelimiter);
				if(iRetVal == 0)
					receivingRespOrg = null;
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					receivingRespOrg = null;
					setUnRecognizedField("MSH","Receiving Responsible Organization",strField);
				}
				else
				{
					setDataType(1824, receivingRespOrg);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;
				
				//Sending Network Address
				HD sendingNetAdd = (HD)getDataElement(1825);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = sendingNetAdd.read(strField, objIDelimiter);
				if(iRetVal == 0)
					sendingNetAdd = null;
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					sendingNetAdd = null;
					setUnRecognizedField("MSH","Sending Network Address",strField);
				}
				else
				{
					setDataType(1825, sendingNetAdd);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;
				
				//Receiving Network Address
				HD receivingNetAdd = (HD)getDataElement(1826);
				  
				do
				{
					strField=strField+strSegmentStream.charAt(++i);
				
				}while(strSegmentStream.charAt(i)!='|' && strSegmentStream.charAt(i)!='\r');
				iRetVal = receivingNetAdd.read(strField, objIDelimiter);
				if(iRetVal == 0)
					receivingNetAdd = null;
				else if(iRetVal == HL7Constants.HL7_FUNCTION_FAIL)
				{
					receivingNetAdd = null;
					setUnRecognizedField("MSH","Receiving Network Address",strField);
				}
				else
				{
					setDataType(1826, receivingNetAdd);
				}
				strField="";
				cReadChar = '\0';
				cReadChar = strSegmentStream.charAt(i);
				if(cReadChar != objDelimiter.cFieldSeparator)
					break;

			}while((strSegmentStream.charAt(i) != '\0') &&  (strSegmentStream.charAt(i) != '\r'));		

			if((cReadChar == '\r'))
			{
					return HL7Constants.HL7_FUNCTION_SUCCESS;		
			}
			else
				throw new InvalidDelimiterException(ResourceBundleWrapper.getValue("exceptions", "InvalidSegmentTeminator", new Locale(HL7Config.createInstance().getLocale())));
		}
		catch(InvalidDataTypeException ex)
		{
			throw new InvalidSegmentException(this.getClass().getSimpleName(), ex);
		}
		catch(FieldMissingException ex)
		{
			throw new InvalidSegmentException(this.getClass().getSimpleName(),ex);
		}
		catch(InvalidFieldException ex)
		{
			throw new InvalidSegmentException(this.getClass().getSimpleName(),ex);
		}
		catch(InvalidDelimiterException ex)
		{
			throw new InvalidSegmentException(this.getClass().getSimpleName(),ex);
		}
	}
}
