package cdac.medinfo.sdk.hl7282.hl7net.testnetwork.localmessages;

import cdac.medinfo.sdk.hl7282.baselibs.CWE;
import cdac.medinfo.sdk.hl7282.baselibs.DR;
import cdac.medinfo.sdk.hl7282.baselibs.DTM;
import cdac.medinfo.sdk.hl7282.baselibs.FN;
import cdac.medinfo.sdk.hl7282.baselibs.HD;
import cdac.medinfo.sdk.hl7282.baselibs.ID;
import cdac.medinfo.sdk.hl7282.baselibs.IS;
import cdac.medinfo.sdk.hl7282.baselibs.XCN;
import cdac.medinfo.sdk.hl7282.baselibs.segmentfactory.AttributeItem;
import cdac.medinfo.sdk.hl7282.baselibs.segmentfactory.SegmentMapReader;
import cdac.medinfo.sdk.hl7282.baselibs.segments.Segment;
import cdac.medinfo.sdk.hl7282.commoninterface.IDataType;
import cdac.medinfo.sdk.hl7282.commoninterface.ISingleCollection;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidDataTypeException;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidFieldException;
import cdac.medinfo.sdk.hl7282.utils.EnumMapModifyMode;
import cdac.medinfo.sdk.hl7282.utils.EnumSegments;
import cdac.medinfo.sdk.hl7282.utils.IAttributeItem;
import cdac.medinfo.sdk.hl7282.utils.ISegmentMap;
import cdac.medinfo.sdk.hl7282.utils.ISegmentMapReader;
import cdac.medinfo.sdk.hl7282.utils.SingleCollection;

public class ZL7 extends Segment
{
	/*Instance of MessageMap*/
	public static ISegmentMap objSegmentMap = null;

	static
	{
		//Initializing SegmentMapReader for the PATIENTADMINISTRATION System. 
		ISegmentMapReader objSegmentMapReader = SegmentMapReader.createInstance();

		//Taking SegmentMap for Segment ZL7 from EVN Message.
		ISegmentMap objTempSegmentMap = objSegmentMapReader.getSegmentMap(EnumSegments.HL7_SEG_EVN.getValue());

		/*Making clone of the SegmentMap of ZL7 which leads to EVN*/
		objSegmentMap = objTempSegmentMap.clone();

		/*Creating custom Attribute for Segment by creating AttributeItem */
		IAttributeItem objAttributeItem = new AttributeItem("simplefield",2000,4,0,3,null,"IS");

		/* Adding this attribute item in SegmentMap.
		 * This EnumMapModifyMode specifies the values like
		 * AFTER i.e. Adding value it in Segment after position specified.
		 * CURRENT i.e. Adding value it in Segment at Current position specified.
		 * REPLACE i.e. Adding value it in Segment at Current position specified by replacing the existing. 
		 * */
		objSegmentMap.addAttributeItem(objAttributeItem,3,EnumMapModifyMode.AFTER);
	}

	public ZL7()
	{
		super(UserDefinedSegmentEnumeration.ZL7,objSegmentMap);
	}

	/**
	 * Retrieves SIMPLE FIELD.
	 * @return
	 */
	public IS getSimpleField() 
	{
		ISingleCollection<IDataType> objDataCollection = getDataType(2000);
		if(objDataCollection != null) 
			return (IS)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Sets simple field.
	 * @param simpleField
	 */
	public void setSimpleField(String strSimpleField)
	{
		IS SetID_PID = new IS();
		SetID_PID.setValue(strSimpleField); 
		setDataType(2000,SetID_PID);
	}
	/**
	 * Sets simple field.
	 * @param simpleField
	 */
	public void setSimpleField(IS objSimpleField)
	{
		setDataType(2000,objSimpleField);
	}

	/**
	 * Retrieves the Date Time Planned Event.
	 * This field contains the date/time of the event is plan. 
	 * @return TS - dateTimePlannedEvent
	 */
	public DTM getDateTimePlannedEvent()
	{
		ISingleCollection<IDataType> objDataCollection = getDataType(101);
		if(objDataCollection != null) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Event Facility.
	 * This field identify the actual facility where the event occurs and differentiate from the sending facility (MSH-4).
	 * @return HD - eventFacility
	 */
	public HD getEventFacility()
	{
		ISingleCollection<IDataType> objDataCollection = getDataType(1534);
		if(objDataCollection != null) 
			return (HD)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Event Occurred.
	 * This field contains the date/time of the event actually occurs.  
	 * @return TS - eventOccurred
	 */
	public DTM getEventOccurred()
	{
		ISingleCollection<IDataType> objDataCollection = getDataType(1278);
		if(objDataCollection != null) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Event Reason Code.
	 * This field contains the reason for this event.  
	 * @return String - eventReasonCode
	 */
	public IS getEventReasonCode() 
	{
		ISingleCollection<IDataType> objDataCollection = getDataType(102);
		if(objDataCollection != null) 
			return (IS)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Event Type Code.
	 * This field contains the events corresponding to the trigger events described in this section.
	 * @return String - eventTypeCode
	 */
	public ID getEventTypeCode() 
	{
		ISingleCollection<IDataType> objDataCollection = getDataType(99);
		if(objDataCollection != null) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Operator ID.
	 * This field identify the individual, responsible for triggering the event.  
	 * @return ISingleCollection<XCN> - operatorID
	 */
	public ISingleCollection<XCN> getOperatorID()
	{
		ISingleCollection<IDataType> objDataCollection = getDataType(103);
		ISingleCollection<XCN> objDataList = new SingleCollection<XCN>();
		if(objDataCollection != null && objDataCollection.size() != 0)
		{
			for(IDataType objDataType : objDataCollection)
			{
				XCN objXCN = (XCN)objDataType;
				objDataList.add(objXCN);
			}
		}
		return objDataList;
	}

	/**
	 * Retrieves the Recorded Date Time.
	 * @return TS - recordedDateTime
	 */
	public DTM getRecordedDateTime() 
	{
		ISingleCollection<IDataType> objDataCollection = getDataType(100);
		if(objDataCollection != null) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Set the Event Type Code.
	 * This field contains the events corresponding to the trigger events described in this section.
	 * @param strEventTypeCode Specifies the events corresponding to the trigger events described in this section, e.g.,
	 * 					         admission, transfer, or registration.This field has been retained for backward compatibility only.    
	 * @throws InvalidFieldException Thrown when Field Validation fails.
	 */ 
	public void setEventTypeCode (String strEventTypeCode) throws InvalidFieldException
	{
		try
		{
			ID EventTypeCode = new ID();
			EventTypeCode.setValue(strEventTypeCode); 
			setEventTypeCode(EventTypeCode);
		}
		catch(InvalidDataTypeException ex)
		{
			throw new InvalidFieldException (objSegmentMap.getFieldName(99), ex);
		}
	} 

	/** Set the Event Type Code.
	 * This field contains the events corresponding to the trigger events described in this section.
	 * @param objEventTypeCode object of Event Type Code.     
	 * @throws InvalidFieldException Thrown when Field Validation fails.
	 */ 
	public void setEventTypeCode(ID objEventTypeCode) throws InvalidFieldException 
	{ 
		try 
		{ 
			setDataType(99,objEventTypeCode);
		}
		catch(InvalidDataTypeException ex)
		{
			throw new InvalidFieldException (objSegmentMap.getFieldName(99), ex);
		}
	}	/**
	 * Set the Recorded Date Time.
	 * @param strTime Specifies a point in time using a 24-hour clock notation. 
	 * @param strDegreeOfPrecision The degree of precision of the time stamp .Suggested Values Y,L,D,H,M,S [Refer to HL7 Table 0529].
	 * @throws InvalidFieldException Thrown when Field Validation fails.
	 */ 
	public void setRecordedDateTime (String strTime,String strDegreeOfPrecision) throws InvalidFieldException 
	{
		try
		{
			DTM recordedDateTime =new DTM();
			recordedDateTime.setValue(strTime);
			setRecordedDateTime(recordedDateTime);
		}
		catch(InvalidDataTypeException ex)
		{
			throw new InvalidFieldException (objSegmentMap.getFieldName(100), ex);
		}
	} 

	/** Set the Recorded Date Time.
	 * @param objrecordedDateTime object of Recorded Date Time.
	 * @throws InvalidFieldException Thrown when Field Validation fails.
	 */ 
	public void setRecordedDateTime(DTM objrecordedDateTime) throws InvalidFieldException 
	{ 
		try 
		{ 
			setDataType(100,objrecordedDateTime);
		}
		catch(InvalidDataTypeException ex)
		{
			throw new InvalidFieldException (objSegmentMap.getFieldName(100), ex);
		}
	}	/**
	 * Set the Date Time Planned Event.
	 * This field contains the date/time of the event is plan. 
	 * @param strTime Specifies a point in time using a 24-hour clock notation. 
	 * @param strDegreeOfPrecision The degree of precision of the time stamp .Suggested Values Y,L,D,H,M,S [Refer to HL7 Table 0529].
	 * @return int - function status [success/failure].
	 * @throws InvalidFieldException Thrown when Field Validation fails.
	 */ 
	public void setDateTimePlannedEvent (String strTime,String strDegreeOfPrecision) throws InvalidFieldException 
	{
		try
		{
			DTM dateTimePlannedEvent = new DTM();
			dateTimePlannedEvent.setValue(strTime);
			setDateTimePlannedEvent(dateTimePlannedEvent);
		}
		catch(InvalidDataTypeException ex)
		{
			throw new InvalidFieldException (objSegmentMap.getFieldName(101), ex);
		}
	} 

	/**
	 * set the Date Time Planned Event.
	 * @param objDateTimePlannedEvent object of Date Time Planned Event.
	 * @throws InvalidFieldException
	 */
	public void setDateTimePlannedEvent(DTM objDateTimePlannedEvent) throws InvalidFieldException 
	{ 
		try 
		{ 
			setDataType(101,objDateTimePlannedEvent);

		}
		catch(InvalidDataTypeException ex)
		{
			throw new InvalidFieldException (objSegmentMap.getFieldName(101), ex);
		}
	}
	/**
	 * Set the Event Reason Code.
	 * This field contains the reason for this event.  
	 * @param strEventReasonCode Specifies the reason for this event. 
	 * @throws InvalidFieldException Thrown when Field Validation fails.
	 */	
	public void setEventReasonCode(String strEventReasonCode) throws InvalidFieldException 
	{
		try
		{
			IS eventReasonCode = new IS();
			eventReasonCode.setValue(strEventReasonCode);
			setEventReasonCode(eventReasonCode);
		}
		catch(InvalidDataTypeException ex)
		{
			throw new InvalidFieldException (objSegmentMap.getFieldName(102), ex);
		}
	}
	/**
	 * set the Event Reason Code.
	 * @param objEventReasonCode object of Event Reason Code.
	 * @throws InvalidFieldException
	 */
	public void setEventReasonCode(IS objEventReasonCode) throws InvalidFieldException 
	{ 
		try 
		{ 
			setDataType(102,objEventReasonCode);
		}
		catch(InvalidDataTypeException ex)
		{
			throw new InvalidFieldException (objSegmentMap.getFieldName(102), ex);
		}
	}
	/**
	 * Set the Operator ID.
	 * This field identify the individual, responsible for triggering the event.  
	 * @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 strDegree Used to specify an educational degree (e.g., MD).Suggested values are PN,AAS,AA,ABA...[Refer table 0360.]
	 * @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 objNameValidityRange Contains the start and end date/times.
	 * @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 objEffectiveDate Specifies the first date, if known, on which the address is valid and active.
	 * @param objExpirationDate 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
	 * @throws InvalidFieldException Thrown when Field Validation fails.
	 */ 
	public void addOperatorID (String strIDNumber,FN objFamilyName,String strGivenName,String strSecondAndFurtherGivenNamesOrInitialsThereof,
			String 	strSuffix,String strPrefix,String strDegree,String strSourceTable,HD objAssigningAuthority,
			String strNameTypeCode,String strIdentifierCheckDigit,String strCheckDigitScheme,String strIdentifierTypeCode,
			HD objAssigningFacility,String strNameRepresentationCode,CWE objNameContext,DR objNameValidityRange,
			String strNameAssemblyOrder,DTM objEffectiveDate,DTM objExpirationDate,String strProfessionalSuffix,
			CWE objAssigningJurisdiction,CWE objAssigningAgencyOrDepratment) throws InvalidFieldException
			{
		try
		{
			XCN DiagnosingClinician = new XCN();
			DiagnosingClinician.setIdNumber(strIDNumber);
			DiagnosingClinician.setFamilyName(objFamilyName);
			DiagnosingClinician.setGivenName(strGivenName);
			DiagnosingClinician.setSecondNameOrInitials(strSecondAndFurtherGivenNamesOrInitialsThereof);
			DiagnosingClinician.setSuffix(strSuffix);
			DiagnosingClinician.setPrefix(strPrefix);
			DiagnosingClinician.setSourceTable(strSourceTable);
			DiagnosingClinician.setAssigningAuthority(objAssigningAuthority);
			DiagnosingClinician.setNameTypeCode(strNameTypeCode);
			DiagnosingClinician.setIdentifierCheckDigit(strIdentifierCheckDigit);
			DiagnosingClinician.setCheckDigitScheme(strCheckDigitScheme);
			DiagnosingClinician.setIdentifierTypeCode(strIdentifierTypeCode);
			DiagnosingClinician.setAssigningFacility(objAssigningFacility);
			DiagnosingClinician.setNameRepresentationCode(strNameRepresentationCode);
			DiagnosingClinician.setNameContext(objNameContext);
			DiagnosingClinician.setNameAssemblyOrder(strNameAssemblyOrder);
			DiagnosingClinician.setEffectiveDate(objEffectiveDate);
			DiagnosingClinician.setExpirationDate(objExpirationDate);
			DiagnosingClinician.setProfessionalSuffix(strProfessionalSuffix);
			DiagnosingClinician.setAssigningJurisdiction(objAssigningJurisdiction);
			DiagnosingClinician.setAssigningAgencyOrDepartment(objAssigningAgencyOrDepratment); 
			addOperatorID(DiagnosingClinician);
		}
		catch(InvalidDataTypeException ex)
		{
			throw new InvalidFieldException (objSegmentMap.getFieldName(103), ex);
		}
			} 

	/** Sets the Operator ID.
	 * @param objOperatorID object of Operator ID.
	 * @throws InvalidFieldException Thrown when Field Validation fails.
	 */ 
	public void addOperatorID(XCN objOperatorID) throws InvalidFieldException 
	{ 
		try 
		{ 
			addDataType(103,objOperatorID);
		}
		catch(InvalidDataTypeException ex)
		{
			throw new InvalidFieldException (objSegmentMap.getFieldName(103), ex);
		}
	}	
	/**
	 * This sets the Operator ID.
	 * @param objOpeartorID Collection of Operator ID.
	 * @throws InvalidFieldException Thrown when Field Validation fails.
	 */
	@SuppressWarnings("unchecked")
	public void setOperatorID(ISingleCollection<XCN> objOpeartorID)throws InvalidFieldException 
	{
		ISingleCollection<IDataType> objCollection = null;
		ISingleCollection<?> objUnknownCollection = (ISingleCollection<?>)objOpeartorID;
		objCollection = (ISingleCollection<IDataType>)objUnknownCollection;
		setDataType(103,objCollection);
	}
	
	/**
	 * Set the Event Occurred.
	 * This field contains the date/time of the event actually occurr.  
	 * @param strTime Specifies a point in time using a 24-hour clock notation. 
	 * @param strDegreeOfPrecision The degree of precision of the time stamp .Suggested Values Y,L,D,H,M,S [Refer to HL7 Table 0529].
	 * @throws InvalidFieldException Thrown when Field Validation fails.
	 */ 
	public void setEventOccurred (String strTime,String strDegreeOfPrecision) throws InvalidFieldException
	{
		try
		{
			DTM eventOccurred = new DTM();
			eventOccurred.setValue(strTime);
			setEventOccurred(eventOccurred);
		}
		catch(InvalidDataTypeException ex)
		{
			throw new InvalidFieldException (objSegmentMap.getFieldName(1278), ex);
		}
	} 

	/**Sets the Event Occurred.
	 * @param objeventOccurred object of Event Occurred.
	 * @throws InvalidFieldException Thrown when Field Validation fails.
	 */ 
	public void setEventOccurred(DTM objeventOccurred) throws InvalidFieldException 
	{ 
		try 
		{ 
			setDataType(1278,objeventOccurred);
		}
		catch(InvalidDataTypeException ex)
		{
			throw new InvalidFieldException (objSegmentMap.getFieldName(1278), ex);
		}
	}	/**
	 * Set the Event Facility.
	 * This field identify the actual facility where the event occurr and differentiate from the sending facility (MSH-4).
	 * @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. 
	 * @throws InvalidFieldException Thrown when Field Validation fails.
	 */ 
	public void setEventFacility (String strNamespaceID,String strUniversalID,String strUniversalIDType) throws InvalidFieldException 
	{
		try
		{
			HD eventFacility = new HD();
			eventFacility.setNamespaceId(strNamespaceID);
			eventFacility.setUniversalId(strUniversalID);
			eventFacility.setUniversalIdType(strUniversalIDType); 
			setEventFacility(eventFacility);
		}
		catch(InvalidDataTypeException ex)
		{
			throw new InvalidFieldException (objSegmentMap.getFieldName(1534), ex);
		}
	} 

	/** Set the Event Facility.
	 * This field identify the actual facility where the event occurr and differentiate from the sending facility (MSH-4).
	 * @param objeventFacility object of Event Facility. 
	 * @throws InvalidFieldException Thrown when Field Validation fails.
	 */ 
	public void setEventFacility(HD objeventFacility) throws InvalidFieldException 
	{ 
		try 
		{ 
			setDataType(1534,objeventFacility);
		}
		catch(InvalidDataTypeException ex)
		{
			throw new InvalidFieldException (objSegmentMap.getFieldName(1534), ex);
		}
	}
}
