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.CX;
import cdac.medinfo.sdk.hl7282.baselibs.HD;
import cdac.medinfo.sdk.hl7282.baselibs.MO;
import cdac.medinfo.sdk.hl7282.baselibs.SI;
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;

/**
 * PCE - Patient Charge Cost Center Exception <p>
 * The Patient Charge Cost Center Exception segment identifies the Patient Price associated with Cost Center and Patient Charge 
 * Identifier combinations that should be used in an instance that the item is billed to a patient.
 * <p>Represents an HL7 PCE message segment. 
 * This segment has the following fields:</p><p>
 * PCE-1 : Set ID - PCE (SI) <b>Required</b><br>
 * PCE-2 : Cost Center Account Number(CX) <b>Optional</b><br>
 * PCE-3 : Transaction Code (CWE) <b>Optional</b><br>
 * PCE-4 : Transaction Amount - Unit (CP) <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 PCE extends Segment
{
	/**
	 *  Constructs the PCE segment. 
	 */
	public PCE()
	{super(EnumSegments.HL7_SEG_PCE);
	}
	
	//Integer values used in getter/setter is unique item id defined 
	//for each attribute.
	
	/**
	 * Retrieves the Set ID - PCE.
	 * This field contains a sequential number that identifies this segment within a given material item segment group. 
	 * @return SI - setID_PCE
	 */
	public SI getSetID_PCE() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2228);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (SI)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves the Cost Center Account Number.
	 * This field would contain the specific general ledger cost center account number associated with a department that may issue or charge for this item.  
	 * @return CX - costCenterAccountNumber
	 */
	public CX getCostCenterAccountNumber() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(281);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CX)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves the Transaction Code.
	 * This field contains a code that is used by a billing system to charge for 
	 * the inventory supply item, the descriptive name of the patient charge for that 
	 * system (as it may appear on a patient's bill or charge labels) and the name of the coding system that assigned the charge code.    
	 * @return CWE - transactionCode
	 */
	public CWE getTransactionCode() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(361);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves the Transaction Amount - Unit.
	 * The price that a department charges to a patient for this inventory supply item when using the Patient Charge Billing code present in this segment. 
	 * @return CP - transactionAmountUnit
	 */
	public CP getTransactionAmountUnit() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(366);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CP)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Set the Set ID - PCE.
	 * This field contains a sequential number that identifies this segment within a given material item segment group.  
	 * @param strSetId_PCE Specifies Set Id - PCE
	 */ 
	public void setSetId_PCE (String strSetId_PCE) 
	{
		SI objSI  = (SI)getDataElement(2228);
		objSI.setValue(strSetId_PCE); 
		setSetId_PCE(objSI);

	} 

	/** 
	 * Set the Set ID - PCE.
	 * This field contains a sequential number that identifies this segment within a given material item segment group. 
	 * @param objSetId_PCE Specifies Set Id - PCE
	 */ 
	public void setSetId_PCE(SI objSetId_PCE)
	{
		setDataType(2228,objSetId_PCE);

	}
	
	/**
	 * Set the Cost Center Account Number.
	 * This field would contain the specific general ledger cost center account number associated with a department that may issue or charge for this item.  
	 * @param strIDNumber Specifies the value of the identifier itself.
	 * @param strCheckDigit It is part of the identifying number used in the sending application. 
	 * @param strCheckDigitScheme Contains the code identifying the check digit scheme employed.
	 * 								Suggested Values NP,ISO,M10,M11.[Refer table No.0061].
	 * @param objAssigningAuthority The assigning authority is a unique name of the system (or organization or agency 
	 * 									or department) that creates the data. . 
	 * @param strIdentifierTypeCode Specifies a code corresponding to the type of identifier.In some cases, this code may be
	 * 								 used as a qualifier to the "Assigning authority" component.[Refer table No 0203]
	 * @param objAssigningFacility Specifies the place or location identifier where the identifier was first assigned 
	 * 									to the patient. 
	 * @param strEffectiveDate Specifies the first date, if known, on which the address is valid and active.
	 * @param strExpirationDate Specifies the last date, if known, on which the address is valid and active.
	 * @param objAssigningJurisdiction Specifies the geo-political body that assigned the identifier. 
	 * @param objAssigningAgencyOrDepartment Specifies agency or department that assigned the identifier. 
	 * @param strSecurityCheck is used to communicate the version code. 
	 * @param objSecurityCheckSCheme is used to transmit information intended to validate veracity of the supplied identifier
	 */ 
	public void setCostCenterAccountNumber(String strIDNumber,String strCheckDigit, String strCheckDigitScheme, HD objAssigningAuthority,
			String strIdentifierTypeCode,HD objAssigningFacility,String strEffectiveDate,String strExpirationDate, 
			CWE objAssigningJurisdiction, CWE objAssigningAgencyOrDepartment, String strSecurityCheck, String strSecurityCheckScheme)
	{
		CX cx  = (CX)getDataElement(281);
		cx.setIdNumber(strIDNumber);
		cx.setCheckDigit(strCheckDigit);
		cx.setCheckDigitScheme(strCheckDigitScheme);
		cx.setAssigningAuthority(objAssigningAuthority);
		cx.setIdentifierTypeCode(strIdentifierTypeCode);
		cx.setAssigningFacility(objAssigningFacility);
		cx.setEffectiveDate(strEffectiveDate);
		cx.setExpirationDate(strExpirationDate);
		cx.setAssigningJurisdiction(objAssigningJurisdiction);
		cx.setAssigningAgencyOrDepartment(objAssigningAgencyOrDepartment); 
		cx.setSecurityCheck(strCheckDigit);
		cx.setSecurityCheckScheme(strSecurityCheckScheme); 
		setCostCenterAccountNumber(cx);

	} 

	/**
	 * Set the Cost Center Account Number.
	 * This field would contain the specific general ledger cost center account number associated with a department that may issue or charge for this item.  
	 * @param objCostCenterAccountNumber Object of Cost Center Account Number
	 */ 
	public void setCostCenterAccountNumber(CX objCostCenterAccountNumber)
	{
		setDataType(281,objCostCenterAccountNumber);

	}
	
	/**
	 * Set the Transaction Code.
	 * This field contains a code that is used by a billing system to charge for 
	 * the inventory supply item, the descriptive name of the patient charge for that 
	 * system (as it may appear on a patient's bill or charge labels) and the name of the coding system that assigned the charge code.  
	 * @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 setTransactionCode(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(361);
		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); 
		setTransactionCode(cwe);

	} 
	
	/** 
	 * Set the Transaction Code.
	 * This field contains a code that is used by a billing system to charge for 
	 * the inventory supply item, the descriptive name of the patient charge for that 
	 * system (as it may appear on a patient's bill or charge labels) and the name of the coding system that assigned the charge code. 
	 * @param objTransactionCode Object of Transaction Code.
	 */ 
	public void setTransactionCode(CWE objTransactionCode)
	{
		setDataType(361,objTransactionCode);

	}
	
	/**
	 * Set the Transaction Amount - Unit.
	 * The price that a department charges to a patient for this inventory supply item when using the Patient Charge Billing code present in this segment.
	 * @param objPrice Specifies an amount of money and the denomination in which it is expressed.
	 * @param strPriceType Specifies a coded value, data type ID.[Refer to HL7 Table 0205]
	 * 						  Suggested Values AP,DC,IC,PF,TF,TP,UP. 
	 * @param strFromValue Specifies the "range" along with strToValue.  
	 * @param strToValue Specifies the "range" along with strFromValue.
	 * @param objRangeUnits Specifies This describes the units associated with the range, e.g., seconds, minutes
	 * @param strRangeType Refer to HL7 Table 0298 - CP range type for valid values.(P,F)
	 */ 
	public void setTransactionAmountUnit(MO objPrice,String strPriceType,
			String strFromValue,String strToValue,CWE objRangeUnits,String strRangeType)
	{
		CP objCP = (CP)getDataElement(366);
		objCP.setPrice(objPrice);
		objCP.setPriceType(strPriceType);
		objCP.setFromValue(strFromValue);
		objCP.setToValue(strToValue);
		objCP.setRangeUnits(objRangeUnits);
		objCP.setRangeType(strRangeType); 
		setTransactionAmountUnit(objCP);

	} 

	/** 
	 * Set the Transaction Amount - Unit.
	 * The price that a department charges to a patient for this inventory supply item when using the Patient Charge Billing code present in this segment.
	 * @param objTransactionAmountUnit Object of Transaction Amount - Unit
	 */ 
	public void setTransactionAmountUnit(CP objTransactionAmountUnit)
	{
		setDataType(366,objTransactionAmountUnit);

	}
	
	/**
	 * 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);
		}
	}
}
