package cdac.medinfo.sdk.hl7282.baselibs.segments;

import cdac.medinfo.sdk.hl7282.baselibs.CNE;
import cdac.medinfo.sdk.hl7282.baselibs.EI;
import cdac.medinfo.sdk.hl7282.baselibs.SI;
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;

/**
 * VND - Purchasing Vendor Segment <p>
 * This segment contains purchasing vendors that supply the inventory supply item specified in the ITM segment.   
 * <p>Represents an HL7 VND message segment. 
 * This segment has the following fields:</p><p>
 * VND-1 : Set Id - VND(SI) <b>Required</b><br>
 * VND-2 : Vendor Identifier(EI) <b> Required </b><br>
 * VND-3 : Vendor Name (ST) <b>Optional</b><br>
 * VND-4 : Vendor Catalog Number (EI) <b>Optional</b><br>
 * VND-5 : Primary Vendor Indicator(CNE) <b>Optional</b><br>
 * 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 VND extends Segment 
{
	/**
	 *  Constructs the VND segment. 
	 */
	public VND()
	{super(EnumSegments.HL7_SEG_VND);
	}
	
	//Integer values used in getter/setter is unique item id defined 
	//for each attribute.
	
	/**
	 * Retrieves the Set Id - VND.
	 * This field contains a sequential number that identifies this segment within a given PURCHASING_VENDOR segment group. 
	 * @return SI - setIdVND
	 */
	public SI getSetIdVND() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2217);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (SI)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves the Vendor Identifier.
	 * This field contains the identifier of the vendor in the system.
	 * @return EI - vendorIdentifier
	 */
	public EI getVendorIdentifier() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2218);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (EI)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves the Vendor Name.
	 * This field contains the name of the vendor identified in VND-2.
	 * @return ST - vendorName
	 */
	public ST getVendorName() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2276);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves the Vendor Catalog Number.
	 * This field contains the catalog number assigned to the item by a purchasing vendor.
	 * @return EI - vendorCatalogNumber
	 */
	public EI getVendorCatalogNumber() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2219);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (EI)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves the Primary Vendor Indicator.
	 * This field contains an indicator to communicate whether this purchasing vendor is the primary vendor used to place orders for inventory supply item.  
	 * @return CNE - primaryVendorIndicator
	 */
	public CNE getPrimaryVendorIndicator() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2220);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CNE)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Set the Set Id - VND.
	 * This field contains a sequential number that identifies this segment within a given PURCHASING_VENDOR segment group. 
	 * @param strSetIdVND Specifies Set Id – VND
	 */ 
	public void setSetIdVND (String strSetIdVND) 
	{
		SI setID_VND  = (SI)getDataElement(2217);
		setID_VND.setValue(strSetIdVND); 
		setSetIdVND(setID_VND);

	} 

	/** 
	 * Set the Set Id - VND.
	 * This field contains a sequential number that identifies this segment within a given PURCHASING_VENDOR segment group. 
	 * @param objSetIdVND Specifies Set Id – VND
	 */ 
	public void setSetIdVND(SI objSetIdVND)
	{
		setDataType(2217,objSetIdVND);

	}
	
	/**
	 * Set the Vendor Identifier.
	 * This field contains the identifier of the vendor in the system.  
	 * @param strEntityIdentifier Specifies to be unique within the series of identifiers created by the 
	 * 								assigning authority, defined by a hierarchic designator
	 * @param strNamespaceId Specifies the assigning authority is a unique identifier of the system 
	 * 							(or organization or agency or department) that creates the data. 
	 * @param strUniversalId Specifies a string formatted according to the scheme defined by the third component universal ID type.
	 * 							It is intended to be unique over time within the UID type.
	 * @param strUniversalIdType Governs the interpretation of the Universal ID.
	 */ 
	public void setVendorIdentifier(String strEntityIdentifier,String strNamespaceId,String strUniversalId,
			String strUniversalIdType)
	{
		EI objEI  = (EI)getDataElement(2218);
		objEI.setEntityIdentifier(strEntityIdentifier);
		objEI.setNamespaceId(strNamespaceId);
		objEI.setUniversalId(strUniversalId);
		objEI.setUniversalIdType(strUniversalIdType);
		setVendorIdentifier(objEI);

	} 
	
	/** 
	 * Set the Vendor Identifier.
	 * This field contains the identifier of the vendor in the system.   
	 * @param objVendorIdentifier Object of Vendor Identifier
	 */ 
	public void setVendorIdentifier(EI objVendorIdentifier)
	{
		setDataType(2218,objVendorIdentifier);

	}
	
	/**
	 * Set the Vendor Name.
	 * This field contains the name of the vendor identified in VND-2.
	 * @param strVendorName Used as Vendor Name.
	 */ 
	public void setVendorName(String strVendorName) 
	{
		ST objST  = (ST)getDataElement(2276);
		objST.setValue(strVendorName); 
		setVendorName(objST);

	} 

	/** 
	 * Set the Vendor Name.
	 * This field contains the name of the vendor identified in VND-2.
	 * @param objVendorName Object of Vendor Name.
	 */ 
	public void setVendorName(ST objVendorName)
	{
		setDataType(2276,objVendorName);

	}
	
	/**
	 * Set the Vendor Catalog Number.
	 * This field contains the catalog number assigned to the item by a purchasing vendor. 
	 * @param strEntityIdentifier Specifies to be unique within the series of identifiers created by the 
	 * 								assigning authority, defined by a hierarchic designator
	 * @param strNamespaceId Specifies the assigning authority is a unique identifier of the system 
	 * 							(or organization or agency or department) that creates the data. 
	 * @param strUniversalId Specifies a string formatted according to the scheme defined by the third component universal ID type.
	 * 							It is intended to be unique over time within the UID type.
	 * @param strUniversalIdType Governs the interpretation of the Universal ID.
	 */ 
	public void setVendorCatalogNumber(String strEntityIdentifier,String strNamespaceId,String strUniversalId,
			String strUniversalIdType)
	{
		EI objEI  = (EI)getDataElement(2219);
		objEI.setEntityIdentifier(strEntityIdentifier);
		objEI.setNamespaceId(strNamespaceId);
		objEI.setUniversalId(strUniversalId);
		objEI.setUniversalIdType(strUniversalIdType);
		setVendorCatalogNumber(objEI);

	} 
	
	/** 
	 * Set the Vendor Catalog Number.
	 * This field contains the catalog number assigned to the item by a purchasing vendor.   
	 * @param objVendorCatalogNumber Object of Vendor Catalog Number
	 */ 
	public void setVendorCatalogNumber(EI objVendorCatalogNumber)
	{
		setDataType(2219,objVendorCatalogNumber);

	}
	
	/**
	 * Set the Primary Vendor Indicator.
	 * This field contains an indicator to communicate whether this purchasing vendor is the primary vendor used to place orders for inventory supply item.  
	 * @param strIdentifier Specifies sequence of characters (the code) that uniquely identifies
	 * 						 the item being referenced by the CNE.
	 * @param strText Specifies descriptive or textual name of the identifier, e.g., myocardial infarction 
	 * @param strNameOfCodingSystem Specifies the coding scheme being used in the identifier component. 
	 * @param strAlternateIdentifier Specifies the local or user seen code as described. 
	 * @param strAlternateText Specifies descriptive or textual name of the alternate identifier.  
	 * @param strNameOfAlternateCodingSystem Specifies the coding scheme being used in the alternate identifier 
	 * 											component.  
	 * @param strCodingSystemVersionID Specifies the version ID for the coding system. 
	 * @param strAlternateCodingSystemVersionID Specifies the version ID for the coding system .
	 * @param strOriginalText Specifies the original text that was available to an automated process or a human 
	 * 							before a specific code was assigned.
	 * @param strSecondAlternateIdentifier Specifies a sequence of characters that uniquely identifies the second alternate code
	 * @param strSecondAlternateText Specifies a the textual information of the second alternate code
	 * @param strNameOfSecondAltenateCodingSystem Specifies the second coding scheme being used in the identifier component.
	 * @param strSecondAlternateCodingSystemVersionID Specifies version ID of Second alternative coding system.
	 * @param strCodingSystemOID contains the ISO Object identifier for the coding system.
	 * @param strValueSetOID contains the value set from which CNE-1 is obtained 
	 * @param strValueSetVersionID contains the version of the value set identified by CNE-15. 
	 * @param strAlternateCodingSystemOID contains the ISO Object identifier for the alternate coding system
	 * @param strAlternateValueSetOID contains the value set from which CNE-4 is obtained
	 * @param strAlternateValueSetVersionID contains the version of the value set identified by CNE-18. 
	 * @param strSecondAlternateCodingSystemOID contains the value set from which CNE-12 is obtained
	 * @param strSecondAlternateValueSetOID contains the value set from which CNE-10 is obtained
	 * @param strSecondAlternateValueSetVersionID contains the version of the value set identified by CNE-21. 
	 */ 
	public void setPrimaryVendorIndicator(String strIdentifier,String strText,String strNameOfCodingSystem,String strAlternateIdentifier,
			String strAlternateText,String strNameOfAlternateCodingSystem,String strCodingSystemVersionID,
			String strAlternateCodingSystemVersionID,String strOriginalText, String strSecondAlternateIdentifier, String strSecondAlternateText,
			String strNameOfSecondAltenateCodingSystem, String strSecondAlternateCodingSystemVersionID, String strCodingSystemOID, 
			String strValueSetOID, String strValueSetVersionID, String strAlternateCodingSystemOID, String strAlternateValueSetOID,
			String strAlternateValueSetVersionID, String strSecondAlternateCodingSystemOID, String strSecondAlternateValueSetOID,
			String strSecondAlternateValueSetVersionID)
	{
		CNE cne  = (CNE)getDataElement(2220);
		cne.setIdentifier(strIdentifier);
		cne.setText(strText);
		cne.setNameOfCodingSystem(strNameOfCodingSystem);
		cne.setAlternateIdentifier(strAlternateIdentifier);
		cne.setAlternateText(strAlternateText);
		cne.setNameOfAlternateCodingSystem(strNameOfAlternateCodingSystem);
		cne.setCodingSystemVersionID(strCodingSystemVersionID);
		cne.setAlternateCodingSystemVersionID(strAlternateCodingSystemVersionID);
		cne.setOriginalText(strOriginalText); 
		cne.setSecondAlternateIdentifier(strSecondAlternateIdentifier);
		cne.setSecondAlternateText(strSecondAlternateText);
		cne.setNameofSecondAlternateCodingSystem(strNameOfSecondAltenateCodingSystem);
		cne.setSecondAlternateCodingSystemVersionID(strSecondAlternateCodingSystemVersionID);
		cne.setCodingSystemOID(strCodingSystemOID);
		cne.setValueSetOID(strValueSetOID);
		cne.setValueSetVersionID(strValueSetVersionID);
		cne.setAlternateCodingSystemOID(strAlternateCodingSystemOID);
		cne.setAlternateValueSetOID(strAlternateValueSetOID);
		cne.setAlternateValueSetVersionID(strAlternateValueSetVersionID);
		cne.setSecondAlternateCodingSystemOID(strSecondAlternateCodingSystemOID);
		cne.setSecondAlternateValueSetOID(strSecondAlternateValueSetOID);
		cne.setSecondAlternateValueSetVersionID(strSecondAlternateValueSetVersionID); 
		setPrimaryVendorIndicator(cne);

	} 

	/** 
	 * Set the Primary Vendor Indicator.
	 * This field contains an indicator to communicate whether this purchasing vendor is the primary vendor used to place orders for inventory supply item.      
	 * @param objPrimaryVendorIndicator Object of Primary Vendor Indicator. 
	 */ 
	public void setPrimaryVendorIndicator(CNE objPrimaryVendorIndicator)
	{
		setDataType(2220,objPrimaryVendorIndicator);

	}
	
	/**
	 * 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 If Segment Validation fails 
	 */
	@Override
	public boolean validate() throws InvalidSegmentException 
	{
		try
		{
			/*
			 * Item Identifier is required fields of this segment.
			 */
			super.validate();

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