/*******************************************************************************
 *  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.CX;
import cdac.medinfo.sdk.hl7282.baselibs.DT;
import cdac.medinfo.sdk.hl7282.baselibs.HD;
import cdac.medinfo.sdk.hl7282.baselibs.ID;
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;
import cdac.medinfo.sdk.hl7282.utils.SingleCollection;

/**
 * DB1 - Disability Segment.<p>
 * The disability segment contains information related to the disability of a person.  
 * <p>Represents an HL7 DB1 message segment. 
 * This segment has the following fields:</p><p>
 * DB1-1: Set ID - DB1 (SI)<b>Required</b><br> 
 * DB1-2: Disabled Person Code (CWE)<b>Optional</b><br> 
 * DB1-3: Disabled Person Identifier (CX)<b>Optional</b><br> 
 * DB1-4: Disabled Indicator (ID)<b>Optional</b><br> 
 * DB1-5: Disability Start Date (DT)<b>Optional</b><br> 
 * DB1-6: Disability End Date (DT)<b>Optional</b><br> 
 * DB1-7: Disability Return to Work Date (DT)<b>Optional</b><br> 
 * DB1-8: Disability Unable to Work Date (DT)<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 DB1 extends Segment   
{
	


	/**
	 * Constructs the DB1 segment.
	 */
	public DB1()
	{super(EnumSegments.HL7_SEG_DB1);
	}
	//Integer values used in getter/setter is unique item id defined 
	//for each attribute.

	/**
	 * Retrieves the Disability End Date.
	 * This field specify the ending date of the person's disability.
	 * @return String - disabilityEndDate
	 */
	public DT getDisabilityEndDate() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1288);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DT)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Disability Return To Work Date.
	 * This field indicate the authorize date on which the patient can return to work for a specified disability case.
	 * @return String - disabilityReturnToWorkDate
	 */
	public DT getDisabilityReturnToWorkDate() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1289);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DT)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Disability Start Date.
	 * This field specify the date of the person become disable.
	 * @return String - disabilityStartDate
	 */
	public DT getDisabilityStartDate() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1287);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DT)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Disability Unable To Work Date.
	 * this field specify the first date in the date span that the patient is unable to work due to disability.
	 * @return String - disabilityUnableToWorkDate
	 */
	public DT getDisabilityUnableToWorkDate() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1290);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DT)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Disabled Indicator.
	 * This field indicates if the person's visit is a disability visit.  
	 * @return String - disabledIndicator
	 */
	public ID getDisabledIndicator()
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1286);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Disabled Person Code.
	 * This field indicates person to which the disability information relates in the message. 
	 * @return String - disabledPersonCode
	 */
	public CWE getDisabledPersonCode() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1284);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Disabled Person Identifier.
	 * This field specify the identifier (or identifiers) for the person whose disability information is sent on the segment.
	 * @return ISingleCollection<CX> - disabledPersonIdentifier
	 */
	public ISingleCollection<CX> getDisabledPersonIdentifier()
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1285);
		ISingleCollection<CX> objDataList = new SingleCollection<CX>();
		if(objDataCollection != null && objDataCollection.size() != 0)
		{
			for(IDataType objDataType : objDataCollection)
			{
				CX objCX = (CX)objDataType;
				objDataList.add(objCX);
			}
		}

		return objDataList;
	}

	/**
	 * Retrieves the Set ID DB1.
	 * This field contains the number that identify this transaction.  
	 * @return String - setID_DB1
	 */
	public SI getSetID_DB1() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1283);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (SI)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Set the Set ID DB1.
	 * This field contains the number that identify this transaction.
	 * @param strSetID_DB1 Used for SetID_DB1.
	 */ 
	public void setSetID_DB1 (String strSetID_DB1)
	{
		SI setID_DB1  = (SI)getDataElement(1283); 
		setID_DB1.setValue(strSetID_DB1); 
		setSetID_DB1(setID_DB1);

	} 

	/** Set the Set ID DB1.
	 * This field contains the number that identify this transaction.
	 * @param objsetID_DB1 object of Set ID DB1.
	 */ 
	public void setSetID_DB1(SI objsetID_DB1)
	{
		setDataType(1283,objsetID_DB1);

	}

	/**
	 * Set the Disabled Person Code.
	 * This field indicates person to which the disability information relates in 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 setDisabledPersonCode (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 disabledPersonCode  = (CWE)getDataElement(1284); 
		disabledPersonCode.setIdentifier(strIdentifier);
		disabledPersonCode.setText(strText);
		disabledPersonCode.setNameOfCodingSystem(strNameOfCodingSystem);
		disabledPersonCode.setAlternateIdentifier(strAlternateIdentifier);
		disabledPersonCode.setAlternateText(strAlternateText);
		disabledPersonCode.setNameOfAlternateCodingSystem(strNameOfAlternateCodingSystem); 
		disabledPersonCode.setCodingSystemVersionID(strCodingSystemVersionID);
		disabledPersonCode.setAlternateCodingSystemVersionId(strAlternateCodingSystemVersionId);
		disabledPersonCode.setOriginalText(strOriginalText);
		disabledPersonCode.setSecondAlternateIdentifier(strSecondAlternateIdentifier);
		disabledPersonCode.setSecondAlternateText(strSecondAlternateText);
		disabledPersonCode.setNameofSecondAlternateCodingSystem(strNameofSecondAlternateCodingSystem);
		disabledPersonCode.setSecondAlternateCodingSystemVersionID(strSecondAlternateCodingSystemVersionID);
		disabledPersonCode.setCodingSystemOID(strCodingSystemOID);
		disabledPersonCode.setValueSetOID(strValueSetOID);
		disabledPersonCode.setValueSetVersionID(strValueSetVersionID);
		disabledPersonCode.setAlternateCodingSystemOID(strAlternateCodingSystemOID);
		disabledPersonCode.setAlternateValueSetOID(strAlternateValueSetOID);
		disabledPersonCode.setAlternateValueSetVersionID(strAlternateValueSetVersionID);
		disabledPersonCode.setSecondAlternateCodingSystemOID(strSecondAlternateCodingSystemOID);
		disabledPersonCode.setSecondAlternateValueSetOID(strSecondAlternateValueSetOID);
		disabledPersonCode.setSecondAlternateValueSetVersionID(strSecondAlternateValueSetVersionID); 
		setDisabledPersonCode(disabledPersonCode);
	} 

	/** Set the Disabled Person Code.
	 * This field indicates person to which the disability information relates in the message. 
	 * @param objdisabledPersonCode object of Disabled Person Code.
	 */ 
	public void setDisabledPersonCode(CWE objdisabledPersonCode)
	{
		setDataType(1284,objdisabledPersonCode);

	}

	/**
	 * Set the Disabled Person Identifier.
	 * This field specify the identifier (or identifiers) for the person whose disability information is sent on the segment.
	 * @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 addDisabledPersonIdentifier (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 tempDisabledPersonIdentifier  = (CX)getDataElement(1285);
		tempDisabledPersonIdentifier.setIdNumber(strIDNumber);
		tempDisabledPersonIdentifier.setCheckDigit(strCheckDigit);
		tempDisabledPersonIdentifier.setCheckDigitScheme(strCheckDigitScheme);
		tempDisabledPersonIdentifier.setAssigningAuthority(objAssigningAuthority);
		tempDisabledPersonIdentifier.setIdentifierTypeCode(strIdentifierTypeCode);
		tempDisabledPersonIdentifier.setAssigningFacility(objAssigningFacility);
		tempDisabledPersonIdentifier.setEffectiveDate(strEffectiveDate);
		tempDisabledPersonIdentifier.setExpirationDate(strExpirationDate);
		tempDisabledPersonIdentifier.setAssigningJurisdiction(objAssigningJurisdiction);
		tempDisabledPersonIdentifier.setAssigningAgencyOrDepartment(objAssigningAgencyOrDepartment); 
		tempDisabledPersonIdentifier.setSecurityCheck(strCheckDigit);
		tempDisabledPersonIdentifier.setSecurityCheckScheme(strSecurityCheckScheme);
		addDisabledPersonIdentifier(tempDisabledPersonIdentifier);

	} 

	/** Set the Disabled Person Identifier.
	 * This field specify the identifier (or identifiers) for the person whose disability information is sent on the segment.
	 * @param objtempDisabledPersonIdentifier object of Disabled Person Identifier.
	 */ 
	public void addDisabledPersonIdentifier(CX objtempDisabledPersonIdentifier)
	{
		addDataType(1285,objtempDisabledPersonIdentifier);
	}
	/**
	 * Set the Disabled Person Identifier.
	 * @param objDisabledPersonIdentifierList List of Disabled Person Identifier.
	 */	
	@SuppressWarnings("unchecked")
	public void setDisabledPersonIdentifier(ISingleCollection<CX> objDisabledPersonIdentifierList)
	{
		ISingleCollection<IDataType> objCollection = null;
		ISingleCollection<?> objUnknownCollection = (ISingleCollection<?>)objDisabledPersonIdentifierList;
		objCollection = (ISingleCollection<IDataType>)objUnknownCollection;
		setDataType(1285,objCollection);
	}

	/**
	 * Set the Disabled Indicator.
	 * This field indicates if the person's visit is a disability visit.  
	 * @param strDisabledIndicator Used for DisabledIndicator.
	 */ 
	public void setDisabledIndicator (String strDisabledIndicator)
	{
		ID disabledIndicator  = (ID)getDataElement(1286); 
		disabledIndicator.setValue(strDisabledIndicator); 
		setDisabledIndicator(disabledIndicator);

	} 

	/** Set the Disabled Indicator.
	 * This field indicates if the person's visit is a disability visit.  
	 * @param objdisabledIndicator object of  Disabled Indicator. 
	 */ 
	public void setDisabledIndicator(ID objdisabledIndicator)
	{
		setDataType(1286,objdisabledIndicator);
	}

	/**
	 * Set the Disability Start Date.
	 * This field specify the date of the person become disable.
	 * @param strDisabilityStartDate Used for DisabilityStartDate.
	 */
	public void setDisabilityStartDate(String strDisabilityStartDate)
	{
		DT disabilityStartDate  = (DT)getDataElement(1287);; 
		disabilityStartDate.setValue(strDisabilityStartDate);
		setDisabilityStartDate(disabilityStartDate);
	}
	/**
	 * Set the Disability Start Date.
	 * This field specify the date of the person become disable.
	 * @param objDisabilityStartDate object of Disability Start Date.
	 */
	public void setDisabilityStartDate(DT objDisabilityStartDate)
	{
		setDataType(1287,objDisabilityStartDate);
	}

	/**
	 * Set the Disability End Date.
	 * This field specify the ending date of the person's disability.
	 * @param strDisabilityEndDate sed for DisabilityEndDate.
	 */
	public void setDisabilityEndDate(String strDisabilityEndDate)
	{
		DT disabilityEndDate  = (DT)getDataElement(1288);; 
		disabilityEndDate.setValue(strDisabilityEndDate);
		setDisabilityEndDate(disabilityEndDate);
	}

	/**
	 * Set the Disability End Date.
	 * This field specify the ending date of the person's disability.
	 * @param objDisabilityStartDate object of Disability End Date.
	 */
	public void setDisabilityEndDate(DT objdisabilityEndDate)
	{
		setDataType(1288,objdisabilityEndDate);
	}

	/**
	 * Set the Disability Return To Work Date.
	 * This field indicate the authorize date on which the patient can return to work for a specified disability case.
	 * @param strDisabilityReturnToWorkDate Used for DisabilityReturnToWorkDate.
	 */
	public void setDisabilityReturnToWorkDate(String strDisabilityReturnToWorkDate)
	{
		DT disabilityReturnToWorkDate  = (DT)getDataElement(1289); 
		disabilityReturnToWorkDate.setValue(strDisabilityReturnToWorkDate);
		setDisabilityReturnToWorkDate(disabilityReturnToWorkDate);
	}

	/**
	 * Set the Disability Return To Work Date.
	 * This field indicate the authorize date on which the patient can return to work for a specified disability case.
	 * @param objdisabilityReturnToWorkDate object of Disability Return To Work Date.
	 */
	public void setDisabilityReturnToWorkDate(DT objdisabilityReturnToWorkDate)
	{
		setDataType(1289,objdisabilityReturnToWorkDate);
	}

	/**
	 * Set the Disability Unable To Work Date.
	 * this field specify the first date in the date span that the patient is unable to work due to disability.
	 * @param strDisabilityUnableToWorkDate Used for DisabilityUnableToWorkDate.
	 */ 
	public void setDisabilityUnableToWorkDate (String strDisabilityUnableToWorkDate)
	{
		DT disabilityUnableToWorkDate  = (DT)getDataElement(1290); 
		disabilityUnableToWorkDate.setValue(strDisabilityUnableToWorkDate); 
		setDisabilityUnableToWorkDate(disabilityUnableToWorkDate);

	} 

	/** Set the Disability Unable To Work Date.
	 * this field specify the first date in the date span that the patient is unable to work due to disability.
	 * @param objdisabilityUnableToWorkDate object of Disability Unable To Work Date.
	 */ 
	public void setDisabilityUnableToWorkDate(DT objdisabilityUnableToWorkDate)
	{
		setDataType(1290,objdisabilityUnableToWorkDate);

	}

	/**
	 * 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 Thrown when Segment Validation Fails.
	 */
	public boolean validate()throws InvalidSegmentException
	{
		try
		{
			super.validate();
			return true;
		}
		catch(FieldMissingException ex)
		{
			throw new InvalidSegmentException(enumSegments.getValue(),ex);
		}
	}
}