/*******************************************************************************
 *  Copyright 2017 Center 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.CP;
import cdac.medinfo.sdk.hl7282.baselibs.CWE;
import cdac.medinfo.sdk.hl7282.baselibs.EI;
import cdac.medinfo.sdk.hl7282.baselibs.MO;
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;


/**
 * PSS -  Product/Service Section Segment
 * The Product/Service Section segment is used to form a logical grouping of Product/Service Group segments,
 * Patients and Response Summaries for a particular Invoice.  
 * <p>Represents an HL7 PSS message segment.
 * This segment has the following fields:</p><p>
 * PSS-1 :  Provider Product/Service Section Number(EI)<b>Required</b><br>
 * PSS-2 :  Payer Product/Service Section Number(EI)<b>Optional</b><br>
 * PSS-3 :  Product/Service Section Sequence Number(SI)<b>Required</b><br>
 * PSS-4 :  Billed Amount(CP)<b>Required</b><br>  
 * PSS-5 :  Section Description or Heading(ST)<b>Required</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 PSS extends Segment{

	/**
	 * Constructs the PSS segment.
	 */
	public PSS() 
	{
		super(EnumSegments.HL7_SEG_PSS);
	}
	
	/**
	 * Retrieve Provider Product/Service Section Number
	 * @return EI - providerProductOrServiceSectionNumber - Unique Product/Service Section Number assigned by the Provider Application.
	 */
	public EI getProviderProductOrServiceSectionNumber()
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1946);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (EI)objDataCollection.elementAt(0);
		else
			return null;
	}  
	
	/**
	 * Retrieve Payer Product/Service Section Number(EI)
	 * @return EI - payerProductOrServiceSectionNumber - Unique Product/Service Section Number assigned by the Payer Application.
	 */
	public EI getPayerProductOrServiceSectionNumber()
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1947);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (EI)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieve Product Or Service Section Sequence Number(SI)
	 * @return String - productOrServiceSectionSequenceNumber - Unique sequence number for the Product/Service – starts with 1, then 2, etc.
	 * for each unique Product/Service Section in this Invoice. 
	 */
	public SI getProductOrServiceSectionSequenceNumber()
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1948);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (SI)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieve Billed Amount(CP)
	 * @return CP - billedAmount - Sum of all Product/Service Billed Amounts for all Product/Service Line Items for this Product/Service Section.
	 */
	public CP getBilledAmount()
	{

		ISingleCollection<IDataType> objDataCollection =getDataType(1949);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CP)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieve Section Description or Heading(ST)
	 * @return ST - sectionDescriptionOrHeading
	 */
	public ST getSectionDescriptionOrHeading()
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2043);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Set Provider Product/Service Section Number(EI)
	 * This Field Contain unique Product/Service Section Number assigned by the Provider Application.
	 * @param strEntityIdentifier - string of character use to identify the entity.
	 * @param strNamespaceID - Use to identify the name space id..
	 * @param strUniversalID - Use to identify the name space identity.
	 * @param strUniversalIDType - String of characters describe Universal Id Type.
	 */
	public void setProviderProductOrServiceSectionNumber(String strEntityIdentifier,String strNamespaceID,String strUniversalID,String strUniversalIDType)
	{
		EI objProviderProductOrServiceSectionNumber = (EI)getDataElement(1946);
		objProviderProductOrServiceSectionNumber.setEntityIdentifier(strEntityIdentifier);
		objProviderProductOrServiceSectionNumber.setNamespaceId(strNamespaceID);
		objProviderProductOrServiceSectionNumber.setUniversalId(strUniversalID);
		objProviderProductOrServiceSectionNumber.setUniversalIdType(strUniversalIDType);
		setProviderProductOrServiceSectionNumber(objProviderProductOrServiceSectionNumber);
	}
	
	/**
	 * Set Provider Product/Service Section Number(EI)
	 * This Field Contain unique Product/Service Section Number assigned by the Provider Application.
	 * @param objProviderProductOrServiceSectionNumber - object of Provider Product Or Service Section Number.
	 */
	public void setProviderProductOrServiceSectionNumber(EI objProviderProductOrServiceSectionNumber)
	{
		setDataType(1946, objProviderProductOrServiceSectionNumber);
	}
	
	/**
	 * Set Payer Product/Service Section Number   (EI)   
	 * This Field Contain unique Product/Service Section Number assigned by the Provider Application.
	 * @param strEntityIdentifier - string of character use to identify the entity.
	 * @param strNamespaceID - Use to identify the name space id..
	 * @param strUniversalID - Use to identify the name space identity.
	 * @param strUniversalIDType - String of characters describe Universal Id Type.
	 */
	public void setPayerProductOrServiceSectionNumber(String strEntityIdentifier,String strNamespaceID,String strUniversalID,String strUniversalIDType)
	{
		EI objPayerProductOrServiceSectionNumber = (EI)getDataElement(1947);
		objPayerProductOrServiceSectionNumber.setEntityIdentifier(strEntityIdentifier);
		objPayerProductOrServiceSectionNumber.setNamespaceId(strNamespaceID);
		objPayerProductOrServiceSectionNumber.setUniversalId(strUniversalID);
		objPayerProductOrServiceSectionNumber.setUniversalIdType(strUniversalIDType);
		setPayerProductOrServiceSectionNumber(objPayerProductOrServiceSectionNumber);
	}
	
	/**
	 * Set Payer Product Or Service Section Number (EI)
	 * This Field is Unique Product/Service Section Number assigned by the Payer Application.
	 * @param objPayerProductOrServiceSectionNumber object of Payer Product Or Service Section Number
	 */
	public void setPayerProductOrServiceSectionNumber(EI objPayerProductOrServiceSectionNumber)
	{
		setDataType(1947, objPayerProductOrServiceSectionNumber);
	}
	
	/**
	 * Set Product/Service Section Sequence Number   (SI)
	 * This field is Unique sequence number for the Product/Service Section (3) – starts with 1, then 2, etc. for each unique Product/Service Section in this Invoice.
	 * @param strSequenceID - string  of character which gives Sequence Id.
	 */
	public void setProductOrServiceSectionSequenceNumber(String strSequenceID)
	{
		SI objProductOrServiceSectionSequenceNumber = (SI)getDataElement(1948);
		objProductOrServiceSectionSequenceNumber.setValue(strSequenceID);
	}
	
	/**
	 * Set Product/Service Section Sequence Number   (SI)
	 * This field is Unique sequence number for the Product/Service Section (3) – starts with 1, then 2, etc. for each unique Product/Service Section in this Invoice.
	 * @param objProductOrServiceSectionSequenceNumber - object of Product Or Service Section Sequence Number which gives Sequence Id.
	 */
	public void setProductOrServiceSectionSequenceNumber(SI objProductOrServiceSectionSequenceNumber)
	{
		setDataType(1948, objProductOrServiceSectionSequenceNumber);
	}
	
	/**
	 * Set Billed Amount (CP)
	 * This field gives Sum of all Product/Service Billed Amounts for all Product/Service Line Items for this Product/Service Section.
	 * @param objPrice - Gives information about the Price.
	 * @param strPriceType - Gives information about Type of Price.
	 * @param strFormValue - Gives information about Form Value.
	 * @param strToValue - Tell about the To value.
	 * @param objRangeUnits - Specifies about the range of the units.
	 * @param strRangeType - Specifies obut the Type of range.
	 */
	public void setBilledAmount(MO objPrice,String strPriceType,String strFormValue,String strToValue,CWE objRangeUnits,String strRangeType)
	{
		CP objBilledAmount = (CP)getDataElement(1949);
		objBilledAmount.setPrice(objPrice);
		objBilledAmount.setPriceType(strPriceType);
		objBilledAmount.setFromValue(strFormValue);
		objBilledAmount.setToValue(strToValue);
		objBilledAmount.setRangeType(strRangeType);
		objBilledAmount.setRangeUnits(objRangeUnits);
		objBilledAmount.setRangeType(strRangeType);
		setBilledAmount(objBilledAmount);
	}
	/**
	 * Set Billed Amount (CP)
	 * This field gives Sum of all Product/Service Billed Amounts for all Product/Service Line Items for this Product/Service Section.
	 * @param objBilledAmount - Gives information about the billed Amount.
	 */
	public void setBilledAmount(CP objBilledAmount)
	{
		setDataType(1949, objBilledAmount);
	}
	
	/**
	 * Section Description or Heading (ST)
	 * This Field describe about Section description or heading.
	 * @param strSectiondescriptionOrheading. - string of section of description or heading.
	 */
	public void setSectionDescriptionOrheading(String strSectionDescriptionOrHeading)
	{
		ST objSectionDescriptionOrheading = (ST)getDataElement(2043);
		objSectionDescriptionOrheading.setValue(strSectionDescriptionOrHeading);
		setSectionDescriptionOrheading(objSectionDescriptionOrheading);
	}
	
	/**
	 * Section Description or Heading (ST)
	 * This Field describe about Section description or heading.
	 * @param objSectiondescriptionOrheading. - object of section of description or heading.
	 */
	public void setSectionDescriptionOrheading(ST objSectionDescriptionOrheading)
	{
		setDataType(2043, objSectionDescriptionOrheading);
	}
	
	/**
	 * 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 
	 * {PSS} while parsing PSS segment validate method will check for its mandatory presence.
	 * [PSS] in this case validate will throw exception if one tries to enter more than one PSS segment.
	 * @return boolean - true or false.
	 * @throws InvalidSegmentException Throws when Segment Validation fails.
	 */
	public boolean validate() throws InvalidSegmentException
	{
		try
		{
			super.validate();
			return true;
		}
		catch(FieldMissingException ex)
		{
			throw new InvalidSegmentException(enumSegments.getValue(),ex);
		}
	}
}
