/*******************************************************************************
 *  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.util.Locale;

import cdac.medinfo.sdk.hl7282.baselibs.CWE;
import cdac.medinfo.sdk.hl7282.baselibs.ID;
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.InvalidFieldException;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidSegmentException;
import cdac.medinfo.sdk.hl7282.utils.EnumSegments;
import cdac.medinfo.sdk.hl7282.utils.HL7Config;
import cdac.medinfo.sdk.hl7282.utils.ResourceBundleWrapper;

/**
 * RQ1 - Requisition Detail-1 Segment.<p>
 * RQ1 contains additional detail for each nonstock requisitioned item. 
 * <p>Represents an HL7 RQ1 message segment. 
 * This segment has the following fields:</p><p>
 * RQ1-1: Anticipated Price (ST)<b>Optional</b><br> 
 * RQ1-2: Manufacturer Identifier (CWE)<b>Conditional</b><br> 
 * RQ1-3: Manufacturer's Catalog (ST)<b>Conditional</b><br> 
 * RQ1-4: Vendor ID (CWE)<b>Conditional</b><br> 
 * RQ1-5: Vendor Catalog (ST)<b>Conditional</b><br> 
 * RQ1-6: Taxable (ID)<b>Optional</b><br> 
 * RQ1-7: Substitute Allowed (ID)<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 RQ1 extends Segment    
{
	

	/**
	 * Constructs the RQ1 segment.
	 */
	public RQ1()
	{super(EnumSegments.HL7_SEG_RQ1);
	}

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

	/**
	 * Retrieves the Anticipated Price.
	 * This field specify the reference price for the requisition unit of measure that is known to the requisition application. 
	 * @return ST - anticipatedPrice
	 */
	public ST getAnticipatedPrice() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(285);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Manufacturer Catalog.
	 * This field specify the manufacturer's catalog number or code for this item.
	 * @return ST - manufacturerCatalog
	 */
	public ST getManufacturerCatalog() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(287);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Manufacturer Identifier.
	 * This field specify the unique code that identifies the manufacturer on the application receiving the requisition.
	 * @return CWE - manufacturerIdentifier
	 */
	public CWE getManufacturerIdentifier() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(286);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Substitute Allowed.
	 * This field specify the field which indicates whether the ancillary department may substitute
	 * an equivalent version of the item(s) ordered or not.
	 * @return ID - substituteAllowed
	 */
	public ID getSubstituteAllowed() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(291);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Taxable.
	 * This field specify the field which indicates whether this item is subject to tax or not.
	 * @return ID - taxable
	 */
	public ID getTaxable() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(290);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Vendor Catalog.
	 * This field specify the vendor's catalog number, name, or code for this item.  
	 * @return ST - vendorCatalog
	 */
	public ST getVendorCatalog() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(289);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Vendor ID.
	 * This field specify the unique code that identifies the vendor on the application receiving the requisition.
	 * @return CWE - vendorID
	 */
	public CWE getVendorID() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(288);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Set the Anticipated Price.
	 * This field specify the reference price for the requisition unit of measure that is known to the requisition application. 
	 * @param strAnticipatedPrice Specifies Anticipated Price.
	 */ 
	public void setAnticipatedPrice (String strAnticipatedPrice) 
	{
		ST anticipatedPrice  = (ST)getDataElement(285);
		anticipatedPrice.setValue(strAnticipatedPrice); 
		setAnticipatedPrice(anticipatedPrice);

	} 

	/** 
	 * Set the Anticipated Price.
	 * This field specify the reference price for the requisition unit of measure that is known to the requisition application. 
	 * @param objanticipatedPrice Object of Anticipated Price.
	 */ 
	public void setAnticipatedPrice(ST objanticipatedPrice)
	{
		setDataType(285,objanticipatedPrice);

	}

	/**
	 * Set the Manufacturer Catalog.
	 * This field specify the manufacturer's catalog number or code for this item.
	 * @param strManufacturerCatalog Specifies Manufacturer Catalog.
	 */ 
	public void setManufacturerCatalog (String strManufacturerCatalog) 
	{
		ST manufacturerCatalog  = (ST)getDataElement(287);
		manufacturerCatalog.setValue(strManufacturerCatalog); 
		setManufacturerCatalog(manufacturerCatalog);

	} 

	/** 
	 * Set the Manufacturer Catalog.
	 * This field specify the manufacturer's catalog number or code for this item.
	 * @param objmanufacturerCatalog Object of Manufacturer Catalog.
	 */ 
	public void setManufacturerCatalog(ST objmanufacturerCatalog)
	{
		setDataType(287,objmanufacturerCatalog);

	}

	/**
	 * Set the Manufacturer Identifier.
	 * This field specify the unique code that identifies the manufacturer on the application receiving the requisition.
	 * @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 setManufacturerIdentifier(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(286);
		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);
		setManufacturerIdentifier(cwe);

	} 

	/** 
	 * Set the Manufacturer Identifier.
	 * This field specify the unique code that identifies the manufacturer on the application receiving the requisition.
	 * @param objmanufacturerIdentifier Object of Manufacturer Identifier.
	 */ 
	public void setManufacturerIdentifier(CWE objmanufacturerIdentifier)
	{
		setDataType(286,objmanufacturerIdentifier);

	}

	/**
	 * Set the Substitute Allowed.
	 * This field specify the field which indicates whether the ancillary department may substitute
	 * an equivalent version of the item(s) ordered or not.
	 * @param strSubstituteAllowed Specifies Substitute Allowed. 
	 */ 
	public void setSubstituteAllowed (String strSubstituteAllowed)  
	{
		ID substituteAllowed  = (ID)getDataElement(291);
		substituteAllowed.setValue(strSubstituteAllowed); 
		setSubstituteAllowed(substituteAllowed);

	} 

	/** 
	 * Set the Substitute Allowed.
	 * This field specify the field which indicates whether the ancillary department may substitute
	 * an equivalent version of the item(s) ordered or not.
	 * @param objsubstituteAllowed Object of Substitute Allowed.
	 */ 
	public void setSubstituteAllowed(ID objsubstituteAllowed)
	{
		setDataType(291,objsubstituteAllowed);

	}

	/**
	 * Set the Taxable.
	 * This field specify the field which indicates whether this item is subject to tax or not.
	 * @param strTaxable Specifies Taxable. 
	 */ 
	public void setTaxable (String strTaxable) 
	{
		ID taxable  = (ID)getDataElement(290);
		taxable.setValue(strTaxable); 
		setTaxable(taxable);

	} 

	/** 
	 * Set the Taxable.
	 * This field specify the field which indicates whether this item is subject to tax or not.
	 * @param objtaxable Object of Taxable.
	 */ 
	public void setTaxable(ID objtaxable)
	{
		setDataType(290,objtaxable);

	}

	/**
	 * Set the Vendor Catalog.
	 * This field specify the vendor's catalog number, name, or code for this item.
	 * @param strVendorCatalog Specifies Vendor Catalog. 
	 */ 
	public void setVendorCatalog (String strVendorCatalog) 
	{
		ST vendorCatalog  = (ST)getDataElement(289);
		vendorCatalog.setValue(strVendorCatalog); 
		setVendorCatalog(vendorCatalog);

	} 

	/** 
	 * Set the Vendor Catalog.
	 * This field specify the vendor's catalog number, name, or code for this item.
	 * @param objvendorCatalog Object of Vendor Catalog. 
	 */ 
	public void setVendorCatalog(ST objvendorCatalog)
	{
		setDataType(289,objvendorCatalog);

	}

	/**
	 * Set the Vendor ID.
	 * This field specify the unique code that identifies the vendor on the application receiving the requisition.
	 * @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 setVendorID (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(288);
		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); 
		setVendorID(cwe);

	} 

	/** 
	 * Set the Vendor ID.
	 * This field specify the unique code that identifies the vendor on the application receiving the requisition.
	 * @param objvendorID Object of Vendor ID.
	 */ 
	public void setVendorID(CWE objvendorID)
	{
		setDataType(288,objvendorID);

	}

	/**
	 * 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 Throws when Segment Validation fails.
	 */

	public boolean validate() 
	{
		try
		{
			super.validate();
			CWE manufacturerIdentifier = getManufacturerIdentifier();
			ST manufacturerCatalog = getManufacturerCatalog();
			CWE vendorID = getVendorID();
			ST vendorCatalog = getVendorCatalog();

			if(!(((manufacturerIdentifier != null) && (manufacturerCatalog != null)) || 
					((vendorID != null)&& (vendorCatalog != null))))
			{
				String strMessage = objSegmentMap.getFieldName(286) + ":" + objSegmentMap.getFieldName(287) + ":" + objSegmentMap.getFieldName(288) + ":" + objSegmentMap.getFieldName(289) + ResourceBundleWrapper.getValue("exceptions", "SegmentCondition", new Locale(HL7Config.createInstance().getLocale()));
				
					throw new InvalidFieldException(strMessage);
			}
			return true;
		}
		catch(FieldMissingException ex)
		{
			throw new InvalidSegmentException(enumSegments.getValue(),ex);
		}
	}
}