/*******************************************************************************
 *  Copyright 2017 Centre for Development of Advanced Computing(C-DAC), Pune
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *    http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *******************************************************************************/
package cdac.medinfo.sdk.hl7282.baselibs.segments;

import cdac.medinfo.sdk.hl7282.baselibs.CWE;
import cdac.medinfo.sdk.hl7282.baselibs.DTM;
import cdac.medinfo.sdk.hl7282.baselibs.FT;
import cdac.medinfo.sdk.hl7282.baselibs.ST;
import cdac.medinfo.sdk.hl7282.commoninterface.IDataType;
import cdac.medinfo.sdk.hl7282.commoninterface.ISingleCollection;
import cdac.medinfo.sdk.hl7282.exceptions.FieldMissingException;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidSegmentException;
import cdac.medinfo.sdk.hl7282.utils.EnumSegments;

/***
 * EQP - Equipment Log/Service Segment <p>
 * The equipment log/service segment is the data necessary to maintain an adequate audit trail of events that have occurred on a particular piece of equipment.
 * <p>Represents an HL7 EQP message segment. 
 * This segment has the following fields:</p><p>
 * EQP-1: Event type (CWE)<b>Required</b><br> 
 * EQP-2: File Name (ST)<b>Optional</b><br> 
 * EQP-3: Start Date/Time (DTM)<b>Required</b><br> 
 * EQP-4: End Date/Time (DTM)<b>Optional</b><br> 
 * EQP-5: Transaction Data (FT)<b>Required</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 EQP extends Segment   
{
	

	/**
	 *  Constructs the EQP segment.
	 */
	public EQP()
	{super(EnumSegments.HL7_SEG_EQP);
	}

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

	/**
	 * Set the Event type.
	 * This field identify the type of event of the message.
	 * @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 setEventtype(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(1430);
		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);
		setEventtype(cwe);
	}

	/**
	 * Set the Event type.
	 * This field identify the type of event of the message.
	 * @param objEventtype
	 */
	public void setEventtype(CWE objEventtype)
	{
		setDataType(1430,objEventtype);
	}

	/**
	 * Set the File Name.
	 * This field specify the physical file name that is use to store information about the transmitted log and/or service event.
	 * @param strFileName The name of the party
	 */
	public void setFileName(String strFileName) 
	{
		ST fileName  = (ST)getDataElement(1431);
		fileName.setValue(strFileName);
		setFileName(fileName);
	}

	/**
	 * Set the File Name.
	 * This field specify the physical file name that is use to store information about the transmitted log and/or service event.
	 * @param objFileName Object of File Name.
	 */
	public void setFileName(ST objFileName)
	{
		setDataType(1431,objFileName);
	}

	/**
	 * Set the Start Date Time.
	 * This field specify the date/time of the started event.
	 * @param strDate Specifies a point in time using a 24-hour clock notation.	 * 
	 */	
	public void setStartDate_Time(String strDate) 
	{
		DTM startDate_Time  = (DTM)getDataElement(1202);
		startDate_Time.setValue(strDate);		
		setStartDate_Time(startDate_Time);
	}

	/**
	 * Set the Start Date Time.
	 * This field specify the date/time of the started event.
	 * @param strDate Specifies a point in time using a 24-hour clock notation.
	 * @param objStartDate_Time Object of Start Date Time.
	 */
	public void setStartDate_Time(DTM objStartDate_Time)
	{
		setDataType(1202,objStartDate_Time);
	}

	/**
	 * Set the End Date Time.
	 * This field specify the date/time of the event  completion.
	 * @param strDate Specifies a point in time using a 24-hour clock notation.	 * 
	 */	
	public void setEndDate_Time(String strDate) 
	{
		DTM endDate_Time  = (DTM)getDataElement(1432);
		endDate_Time.setValue(strDate);		
		setEndDate_Time(endDate_Time);
	}

	/**
	 * Set the End Date Time.
	 * This field specify the date/time of the event  completion.
	 * @param objEndDate_Time Object of End Date Time.
	 */
	public void setEndDate_Time(DTM objEndDate_Time)
	{
		setDataType(1432,objEndDate_Time);
	}

	/**
	 * Set the Transaction Data.
	 * This field specify the data of the log and/or service event.
	 * @param strTransactionData This field contains the String Value of Sender Comment 
	 */
	public void setTransactionData(String strTransactionData) 
	{
		FT transactionData  = (FT)getDataElement(1433);
		transactionData.setValue(strTransactionData);
		setTransactionData(transactionData);
	}

	/**
	 * Set the Transaction Data.
	 * This field specify the data of the log and/or service event.
	 * @param objTransactionData Object of Transaction Data.
	 */
	public void setTransactionData(FT objTransactionData)
	{
		setDataType(1433,objTransactionData);
	}

	/**
	 * Retrieves the End Date Time.
	 * This field specify the date/time of the event  completion.
	 * @return DTM - endDate_Time
	 */
	public DTM getEndDate_Time() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1432);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Event type.
	 * This field identify the type of event of the message.
	 * @return CWE - eventtype
	 */
	public CWE getEventtype() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1430);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the File Name.
	 * This field specify the physical file name that is use to store information about the transmitted log and/or service event.
	 * @return String - fileName
	 */
	public ST getFileName() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1431);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Start Date Time.
	 * This field specify the date/time of the started event. 
	 * @return DTM - startDate_Time
	 */
	public DTM getStartDate_Time() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1202);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Transaction Data.
	 * This field specify the data of the log and/or service event. 
	 * @return String - transactionData
	 */
	public FT getTransactionData() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1433);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (FT)objDataCollection.elementAt(0);
		else
			return null;
	}

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

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