/*******************************************************************************
 *  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.DT;
import cdac.medinfo.sdk.hl7282.baselibs.DTM;
import cdac.medinfo.sdk.hl7282.baselibs.EI;
import cdac.medinfo.sdk.hl7282.baselibs.FN;
import cdac.medinfo.sdk.hl7282.baselibs.HD;
import cdac.medinfo.sdk.hl7282.baselibs.NM;
import cdac.medinfo.sdk.hl7282.baselibs.SAD;
import cdac.medinfo.sdk.hl7282.baselibs.SI;
import cdac.medinfo.sdk.hl7282.baselibs.ST;
import cdac.medinfo.sdk.hl7282.baselibs.XAD;
import cdac.medinfo.sdk.hl7282.baselibs.XCN;
import cdac.medinfo.sdk.hl7282.baselibs.XTN;
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;

/**
 * CM0 - Clinical Study Master Segment.<p>
 * The Technical Steward for the CM0 segment is ORDERS.
 * The Clinical Study Master (CM0) segment contains the information about the study itself.All of the fields
 * in the segment describe the study status at the sending facility unless otherwise agreed upon.  
 * <p>Represents an HL7 CM0 message segment. 
 * This segment has the following fields:</p><p>
 * CM0-1: Set ID - CM0 (SI)<b>Optional</b><br> 
 * CM0-2: Sponsor Study ID (EI)<b>Required</b><br> 
 * CM0-3: Alternate Study ID (EI)<b>Optional</b><br> 
 * CM0-4: Title of Study (ST)<b>Required</b><br> 
 * CM0-5: Chairman of Study (XCN)<b>Optional</b><br> 
 * CM0-6: Last IRB Approval Date (DT)<b>Optional</b><br> 
 * CM0-7: Total Accrual to Date (NM)<b>Optional</b><br> 
 * CM0-8: Last Accrual Date (DT)<b>Optional</b><br> 
 * CM0-9: Contact for Study (XCN)<b>Optional</b><br> 
 * CM0-10: Contact's Telephone Number (XTN)<b>Optional</b><br> 
 * CM0-11: Contact's Address (XAD)<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 CM0 extends Segment   
{
	


	/**
	 * Constructs the CM0 segment.
	 */
	public CM0()
	{super(EnumSegments.HL7_SEG_CM0);
	}

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

	/**
	 * Retrieves the Alternate Study ID.
	 * This field contains the local or collaborators' cross-referenced study numbers.
	 * @return ISingleCollection<EI> - alternateStudyID
	 */
	public ISingleCollection<EI> getAlternateStudyID() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1036);
		ISingleCollection<EI> objDataList = new SingleCollection<EI>(); 
		if(objDataCollection != null && objDataCollection.size() != 0)
		{
			for(IDataType objDataType : objDataCollection)
			{
				EI objEI = (EI)objDataType;
				objDataList.add(objEI);
			}
		}
		return objDataList;
	}

	/**
	 * Retrieves the Chairman of Study.
	 * This field contains the sending institution's chairman.  
	 * @return ISingleCollection<XCN> - chairmanofStudy
	 */
	public ISingleCollection<XCN> getChairmanofStudy() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1014);
		ISingleCollection<XCN> objDataList = new SingleCollection<XCN>(); 
		if(objDataCollection != null && objDataCollection.size() != 0)
		{
			for(IDataType objDataType : objDataCollection)
			{
				XCN objXCN = (XCN)objDataType;
				objDataList.add(objXCN);
			}
		}
		return objDataList;
	}

	/**
	 * Retrieves the Contact Address.
	 * This field contains the address of the study contact.
	 * @return ISingleCollection<XAD> - contactAddress
	 */
	public ISingleCollection<XAD> getContactAddress() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1020);
		ISingleCollection<XAD> objDataList = new SingleCollection<XAD>(); 
		if(objDataCollection != null && objDataCollection.size() != 0)
		{
			for(IDataType objDataType : objDataCollection)
			{
				XAD objXAD = (XAD)objDataType;
				objDataList.add(objXAD);
			}
		}
		return objDataList;
	}

	/**
	 * Retrieves the Contact for Study.
	 * This field contains the name of the individual who should be
	 * contacted for inquiries about data transmitted for this study.
	 * @return ISingleCollection<XCN> - contactforStudy
	 */
	public ISingleCollection<XCN> getContactforStudy() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1018);
		ISingleCollection<XCN> objDataList = new SingleCollection<XCN>(); 
		if(objDataCollection != null && objDataCollection.size() != 0)
		{
			for(IDataType objDataType : objDataCollection)
			{
				XCN objXCN = (XCN)objDataType;
				objDataList.add(objXCN);
			}
		}
		return objDataList;
	}

	/**
	 * Retrieves the Contact Telephone Number.
	 * This field contains the phone number of the study contact.
	 * @return XTN - contactTelephoneNumber
	 */
	public XTN getContactTelephoneNumber() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1019);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (XTN)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Last Accrual Date.
	 * This field contains the status information on the patient 
	 * registration activity for quality control and operations purposes.
	 * @return DT - lastAccrualDate
	 */
	public DT getLastAccrualDate() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1017);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DT)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Last IRB Approval Date.
	 * This field contains an institution's Internal Review Board 
	 * approval dates which are required annually to continue participation in a clinical trial.
	 * @return DT - lastIRBApprovalDate
	 */
	public DT getLastIRBApprovalDate() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1015);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DT)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Set ID CM0.
	 * This field contains a number that uniquely identify this 
	 * transaction for the purpose of adding, changing, or deleting the transaction.
	 * @return SI - setID_CM0
	 */
	public SI getSetID_CM0() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1010);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (SI)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Sponsor Study ID.
	 * This field contains the study number established by the study sponsor.  
	 * @return EI - sponsorStudyID
	 */
	public EI getSponsorStudyID() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1011);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (EI)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Title of Study.
	 * This field contains the sending institution's title for the clinical trial. 
	 * @return ST - titleofStudy
	 */
	public ST getTitleofStudy() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1013);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Total Accrual to Date.
	 * This field is a quality control field to enable checks the patient data
	 * have been transmitted on all registered patients.
	 * @return NM - totalAccrualtoDate
	 */
	public NM getTotalAccrualtoDate() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1016);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Add the Alternate Study ID.
	 * This field contains the local or collaborators' cross-referenced study numbers.
	 * @param strEntityIdentifier Specifies defined by a hierarchic designator, represented by components 2 through 4.
	 * 								[Reference Section 2.A.33, "HD - hierarchic designator".] 
	 * @param strNamespaceId Specifies  the HL7 identifier for the user-defined table of values for this component.
	 * 						   [Refer to User-defined Table 0363 - Assigning authority] 	 
	 * @param strUniversalId Specifies string formatted according to the scheme defined by the component, 
	 * 							<universal ID type> (UID type). 
	 * @param strUniversalIdType Specifies  the interpretation of the second component of the HD. 
	 */
	public void addAlternateStudyID(String strEntityIdentifier,String strNamespaceId,
			String strUniversalId,String strUniversalIdType)
	{
		EI alternateStudyID  = (EI)getDataElement(1036);
		alternateStudyID.setEntityIdentifier(strEntityIdentifier);
		alternateStudyID.setNamespaceId(strNamespaceId);
		alternateStudyID.setUniversalId(strUniversalId);
		alternateStudyID.setUniversalIdType(strUniversalIdType);
		addAlternateStudyID(alternateStudyID);
	}

	/**
	 * Add the Alternate Study ID.
	 * This field contains the local or collaborators' cross-referenced study numbers.
	 * @param objalternateStudyID Object of Alternate Study ID.
	 */
	public void addAlternateStudyID(EI objalternateStudyID)
	{
		addDataType(1036,objalternateStudyID);
	}

	/**
	 * Set the Alternate Study ID.
	 * This field contains the local or collaborators' cross-referenced study numbers.
	 * @param objalternateStudyIDList List of Alternate Study ID.
	 */
	@SuppressWarnings("unchecked")
	public void setAlternateStudyID(ISingleCollection<EI> objalternateStudyIDList)
	{
		ISingleCollection<IDataType> objCollection = null;
		ISingleCollection<?> objUnknownCollection = (ISingleCollection<?>)objalternateStudyIDList;
		objCollection = (ISingleCollection<IDataType>)objUnknownCollection;
		setDataType(1036,objCollection);
	}

	/**
	 * Add the Chairman of Study.
	 * This field contains the sending institution's chairman.
	 * @param strIDNumber Refers to the coded ID according to a user-defined table
	 * @param objFamilyName Specifies the surname of a person.
	 * @param strGivenName Specifies First name.
	 * @param strSecondAndFurtherGivenNamesOrInitialsThereof Specifies multiple middle names that may be included by 
	 * 														   separating them with spaces.
	 * @param strSuffix Used to specify a name suffix (e.g., Jr. or III).
	 * @param strPrefix Used to specify a name prefix (e.g., Dr.).
	 * @param objSourceTable Used as the HL7 identifier for the user-defined table of values for this component. [Refer User-defined Table 0297 - CN ID.]
	 * @param objAssigningAuthority Specifies a unique identifier of the system (or organization or agency of department)
	 * 								  that creates the data. [Refer User-defined Table 0363 - Assigning authority]
	 * @param strNameTypeCode Specifies a code that represents the type of name. 
	 * @param strIdentifierCheckDigit Specifies part of the identifying number used in the sending application. 
	 * @param strCheckDigitScheme Specifies the code identifying the check digit scheme employed.[Refer HL7 Table 0061 - Check digit scheme].
	 * @param strIdentifierTypeCode Specifies A code corresponding to the type of identifier.[Refer HL7 Table 0203 - Identifier type].
	 * @param objAssigningFacility Specifies the place or location identifier where the identifier was first assigned to the person
	 * @param strNameRepresentationCode Provides an indication of the representation provided by the data item.  
	 * @param objNameContext Designates the context in which a name is used. [Refer User-defined Table 0448 ]
	 * @param strNameAssemblyOrder Specifies a code that represents the preferred display order of the components of this person name. Suggested values are G,F[Refer table 0444.]
	 * @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 strProfessionalSuffix Used to specify an abbreviation, or a string of abbreviations, denoting qualifications that support the person's profession, (e.g., licenses).
	 * @param objAssigningJurisdiction Specifies the geo-political body that assigned the identifier.
	 * @param objAssigningAgencyOrDepratment Specifies the agency or department that assigned the identifier
	 * @param strSecurityCheck Specifies the version code that may be assigned to the person identifier
	 * @param strSecurityCheckScheme Specifies the check digit scheme.
	 */
	public void addChairmanofStudy (String strIDNumber,FN objFamilyName,String strGivenName,String strSecondAndFurtherGivenNamesOrInitialsThereof,
			String 	strSuffix,String strPrefix,CWE objSourceTable,HD objAssigningAuthority,
			String strNameTypeCode,String strIdentifierCheckDigit,String strCheckDigitScheme,String strIdentifierTypeCode,
			HD objAssigningFacility,String strNameRepresentationCode,CWE objNameContext,
			String strNameAssemblyOrder, String strEffectiveDate,String strExpirationDate,String strProfessionalSuffix,
			CWE objAssigningJurisdiction,CWE objAssigningAgencyOrDepratment, String strSecurityCheck, String strSecurityCheckScheme)
	{
		XCN xcn  = (XCN)getDataElement(1014);
		xcn.setIdNumber(strIDNumber);
		xcn.setFamilyName(objFamilyName);
		xcn.setGivenName(strGivenName);
		xcn.setSecondNameOrInitials(strSecondAndFurtherGivenNamesOrInitialsThereof);
		xcn.setSuffix(strSuffix);
		xcn.setPrefix(strPrefix);
 
		xcn.setSourceTable(objSourceTable);
		xcn.setAssigningAuthority(objAssigningAuthority);
		xcn.setNameTypeCode(strNameTypeCode);
		xcn.setIdentifierCheckDigit(strIdentifierCheckDigit);
		xcn.setCheckDigitScheme(strCheckDigitScheme);
		xcn.setIdentifierTypeCode(strIdentifierTypeCode);
		xcn.setAssigningFacility(objAssigningFacility);
		xcn.setNameRepresentationCode(strNameRepresentationCode);
		xcn.setNameContext(objNameContext);
 
		xcn.setNameAssemblyOrder(strNameAssemblyOrder);
		xcn.setEffectiveDate(strEffectiveDate);
		xcn.setExpirationDate(strExpirationDate);
		xcn.setProfessionalSuffix(strProfessionalSuffix);
		xcn.setAssigningJurisdiction(objAssigningJurisdiction);
		xcn.setAssigningAgencyOrDepartment(objAssigningAgencyOrDepratment); 
		xcn.setSecurityCheck(strSecurityCheck);
		xcn.setSecurityCheckScheme(strSecurityCheckScheme);
		addChairmanofStudy(xcn);
	}

	/**
	 * Add the Chairman of Study.
	 * This field contains the sending institution's chairman.
	 * @param objchairmanofStudy Object of Chairman of Study.
	 */
	public void addChairmanofStudy(XCN objchairmanofStudy)
	{
		addDataType(1014,objchairmanofStudy);
	}

	/**
	 * Set the Chairman of Study.
	 * This field contains the sending institution's chairman.
	 * @param objchairmanofStudyList List of Chairman of Study.
	 */
	@SuppressWarnings("unchecked")
	public void setChairmanofStudy(ISingleCollection<XCN> objchairmanofStudyList)
	{
		ISingleCollection<IDataType> objCollection = null;
		ISingleCollection<?> objUnknownCollection = (ISingleCollection<?>)objchairmanofStudyList;
		objCollection = (ISingleCollection<IDataType>)objUnknownCollection;
		setDataType(1014,objCollection);
	}

	/**
	 * Add the Contact Address.
	 * This field contains the address of the study contact.
	 * @param objStreetAddress Specifies the street address.
	 * @param strOtherDesignation Specifies the Second line of address. 
	 * @param strCity The city, or district or place where the addressee is located. 
	 * @param strStateOrProvince Specifies the state or province where the addressee is located.
	 * @param strZipOrPostalCode Specifies the zip or postal code where the addressee is located. 
	 * @param strCountry Specifies the country where the addressee is located.
	 * @param strAddressType Specifies the kind or type of address.
	 * @param strOtherGeographicDesignation Specifies any other geographic designation. 
	 * @param objCountyParishCode Specifies a code that represents the county in which the specified address resides. 
	 * @param objCensusTract Specifies a code that represents the census tract in which the specified address resides. 
	 * @param strAddressRepresentationCode Specifies representations of the same name/address Suggested values are I,A,P [Refer table 0465]
	 * @param objEffectiveDate It is The first date, if known, on which the address is valid and active.
	 * @param objExpirationDate It is The last date, if known, on which the address is valid and active.
	 * @param objExpirationReason indicates why this address was marked as ended.
	 * @param strTemporaryIndicator indicates whether address is considered temporary .
	 * @param strBadAddressIndicator indicates whether it is possible to contact the owning entity.
	 * @param strAddressUsage indicates how the address is intended to be used.
	 * @param strAddressee indicates the name of the person whose address is intended to be used.
	 * @param strComment indicated descriptive information
	 * @param strPreferenceOrder preference order
	 * @param objProtectionCode indicates that an address need to be protected
	 * @param objAddressIdentifier indicates a unique identifier for address
	 */	
	public void addContactAddress(SAD objStreetAddress,String strOtherDesignation,String strCity,
			String strStateOrProvince,String strZipOrPostalCode,String strCountry,String strAddressType,
			String strOtherGeographicDesignation,CWE objCountyParishCode,CWE objCensusTract,
			String strAddressRepresentationCode,DTM objEffectiveDate,
			DTM objExpirationDate, CWE objEXpirationReason, String strTemporaryIndicator,
			String strBadAddressIndicator, String strAddressUsage, String strAddressee, String strComment,
			String strPreferenceOrder, CWE objProtectionCode, EI objAddressIdentifier)
	{
		XAD xad = (XAD)getDataElement(1020);
		xad.setStreetAddress(objStreetAddress);
		xad.setOtherDesignation(strOtherDesignation);
		xad.setCity(strCity);
		xad.setStateOrProvince(strStateOrProvince);
		xad.setZipOrPostalCode(strZipOrPostalCode);
		xad.setCountry(strCountry);
		xad.setAddressType(strAddressType);
		xad.setOtherGeographicDesignation(strOtherGeographicDesignation);
		xad.setCountyParishCode(objCountyParishCode);
		xad.setCensusTract(objCensusTract);
		xad.setAddressRepresentationCode(strAddressRepresentationCode);
 
		xad.setEffectiveDate(objEffectiveDate);
		xad.setExpirationDate(objExpirationDate); 
		xad.setExpirationReason(objEXpirationReason);
		xad.setTemporaryIndicator(strTemporaryIndicator);
		xad.setBadAddressIndicator(strBadAddressIndicator);
		xad.setAddressUsage(strAddressUsage);
		xad.setAddressee(strAddressee);
		xad.setComment(strComment);
		xad.setPreferenceOrder(strPreferenceOrder);
		xad.setProtectionCode(objProtectionCode);
		xad.setAddressIdentifier(objAddressIdentifier);
		addContactAddress(xad);
	}

	/**
	 * Add the Contact Address.
	 * This field contains the address of the study contact.
	 * @param objcontactAddress Object of Contact Address.
	 */
	public void addContactAddress(XAD objcontactAddress)
	{
		addDataType(1020,objcontactAddress);
	}

	/**
	 * Set the Contact Address.
	 * This field contains the address of the study contact.
	 * @param objcontactAddressList List of Contact Address.
	 */
	@SuppressWarnings("unchecked")
	public void setContactAddress(ISingleCollection<XAD> objcontactAddressList)
	{
		ISingleCollection<IDataType> objCollection = null;
		ISingleCollection<?> objUnknownCollection = (ISingleCollection<?>)objcontactAddressList;
		objCollection = (ISingleCollection<IDataType>)objUnknownCollection;
		setDataType(1020,objCollection);
	}

	/**
	 * Add the Contact for Study.
	 * This field contains the name of the individual who should be
	 * contacted for inquiries about data transmitted for this study.
	 * @param strIDNumber Refers to the coded ID according to a user-defined table
	 * @param objFamilyName Specifies the surname of a person.
	 * @param strGivenName Specifies First name.
	 * @param strSecondAndFurtherGivenNamesOrInitialsThereof Specifies multiple middle names that may be included by 
	 * 														   separating them with spaces.
	 * @param strSuffix Used to specify a name suffix (e.g., Jr. or III).
	 * @param strPrefix Used to specify a name prefix (e.g., Dr.).
	 * @param objSourceTable Used as the HL7 identifier for the user-defined table of values for this component. [Refer User-defined Table 0297 - CN ID.]
	 * @param objAssigningAuthority Specifies a unique identifier of the system (or organization or agency of department)
	 * 								  that creates the data. [Refer User-defined Table 0363 - Assigning authority]
	 * @param strNameTypeCode Specifies a code that represents the type of name. 
	 * @param strIdentifierCheckDigit Specifies part of the identifying number used in the sending application. 
	 * @param strCheckDigitScheme Specifies the code identifying the check digit scheme employed.[Refer HL7 Table 0061 - Check digit scheme].
	 * @param strIdentifierTypeCode Specifies A code corresponding to the type of identifier.[Refer HL7 Table 0203 - Identifier type].
	 * @param objAssigningFacility Specifies the place or location identifier where the identifier was first assigned to the person
	 * @param strNameRepresentationCode Provides an indication of the representation provided by the data item.  
	 * @param objNameContext Designates the context in which a name is used. [Refer User-defined Table 0448 ]
	 * @param strNameAssemblyOrder Specifies a code that represents the preferred display order of the components of this person name. Suggested values are G,F[Refer table 0444.]
	 * @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 strProfessionalSuffix Used to specify an abbreviation, or a string of abbreviations, denoting qualifications that support the person's profession, (e.g., licenses).
	 * @param objAssigningJurisdiction Specifies the geo-political body that assigned the identifier.
	 * @param objAssigningAgencyOrDepratment Specifies the agency or department that assigned the identifier
	 * @param strSecurityCheck Specifies the version code that may be assigned to the person identifier
	 * @param strSecurityCheckScheme Specifies the check digit scheme.
	 */
	public void addContactforStudy (String strIDNumber,FN objFamilyName,String strGivenName,String strSecondAndFurtherGivenNamesOrInitialsThereof,
			String 	strSuffix,String strPrefix,CWE objSourceTable,HD objAssigningAuthority,
			String strNameTypeCode,String strIdentifierCheckDigit,String strCheckDigitScheme,String strIdentifierTypeCode,
			HD objAssigningFacility,String strNameRepresentationCode,CWE objNameContext,
			String strNameAssemblyOrder, String strEffectiveDate,String strExpirationDate,String strProfessionalSuffix,
			CWE objAssigningJurisdiction,CWE objAssigningAgencyOrDepratment, String strSecurityCheck, String strSecurityCheckScheme)
	{
		XCN xcn  = (XCN)getDataElement(1018);
		xcn.setIdNumber(strIDNumber);
		xcn.setFamilyName(objFamilyName);
		xcn.setGivenName(strGivenName);
		xcn.setSecondNameOrInitials(strSecondAndFurtherGivenNamesOrInitialsThereof);
		xcn.setSuffix(strSuffix);
		xcn.setPrefix(strPrefix);
 
		xcn.setSourceTable(objSourceTable);
		xcn.setAssigningAuthority(objAssigningAuthority);
		xcn.setNameTypeCode(strNameTypeCode);
		xcn.setIdentifierCheckDigit(strIdentifierCheckDigit);
		xcn.setCheckDigitScheme(strCheckDigitScheme);
		xcn.setIdentifierTypeCode(strIdentifierTypeCode);
		xcn.setAssigningFacility(objAssigningFacility);
		xcn.setNameRepresentationCode(strNameRepresentationCode);
		xcn.setNameContext(objNameContext);
 
		xcn.setNameAssemblyOrder(strNameAssemblyOrder);
		xcn.setEffectiveDate(strEffectiveDate);
		xcn.setExpirationDate(strExpirationDate);
		xcn.setProfessionalSuffix(strProfessionalSuffix);
		xcn.setAssigningJurisdiction(objAssigningJurisdiction);
		xcn.setAssigningAgencyOrDepartment(objAssigningAgencyOrDepratment); 
		xcn.setSecurityCheck(strSecurityCheck);
		xcn.setSecurityCheckScheme(strSecurityCheckScheme); 
		addContactforStudy(xcn);
	}

	/**
	 * Add the Contact for Study.
	 * This field contains the name of the individual who should be
	 * contacted for inquiries about data transmitted for this study.
	 * @param objcontactforStudy Object of Contact for Study.
	 */
	public void addContactforStudy(XCN objcontactforStudy)
	{
		addDataType(1018,objcontactforStudy);
	}

	/**
	 * Set the Contact for Study.
	 * This field contains the name of the individual who should be
	 * contacted for inquiries about data transmitted for this study.
	 * @param objcontactforStudyList List of Contact for Study.
	 */
	@SuppressWarnings("unchecked")
	public void setContactforStudy(ISingleCollection<XCN> objcontactforStudyList)
	{
		ISingleCollection<IDataType> objCollection = null;
		ISingleCollection<?> objUnknownCollection = (ISingleCollection<?>)objcontactforStudyList;
		objCollection = (ISingleCollection<IDataType>)objUnknownCollection;
		setDataType(1018,objCollection);
	}

	/**
	 * Set the Contact Telephone Number.
	 * This field contains the phone number of the study contact.
	 * @param strTeleCommunicationUseCode Specifies a code that represents a specific use of a telecommunication number.
	 										Suggested values are PRN,ORN,WPN,VHN,ASN,EMR,NET,BPN  [Refer table 0201.]
	 * @param strTeleCommunicationEquipmentType Specifies a code that represents the type of telecommunication equipment.
	 * 											  Suggested values are PH,FX,MD,CP,BP,Internet,X.400,TDD,TTY  [Refer table 0202.]
	 * @param strCommuinicationAddress Specifies Email address.
	 * @param strCountryCode Specifies the Country code.
	 * @param strAreaCityCode Specifies the area /City Code.
	 * @param strLocalNumber Specifies an Local Number.
	 * @param strExtension Specifies an Extension.
	 * @param strAnyText Contains comments with respect to the telephone number.
	 * @param strExtensionPrefix Specifies the characters established within a company's 
	 * 							   internal telephone system network used as a prefix to the Extension component for internal dialing. 
	 * @param strSpeedDialCode Specifies The characters established within a 
	 * 							 company's internal telephone system used in place of the (external) telephone number.
	 * @param strUnformattedTelephoneNumber Specifies an expression of the telephone number as an unparsible string.
	 * @param strEffectiveStartDate Specifies start date.
	 * @param strExpirationDate Specifies expiration date.
	 * @param objExpirationReason Specifies reason why this contact is marked as ended.
	 * @param objProtectionCode Specifies reason why this information is sensitive or protected.
	 * @param objSharedTelecommunicationIdentifier Specifies a unique phone number phone telephone number or email-id.
	 * @param strPreferenceOrder Specifies the preference order for an entity..
	 */ 
	public void setContactTelephoneNumber (String strTeleCommunicationUseCode,String strTeleCommunicationEquipmentType
			,String strCommuinicationAddress,String strCountryCode,String strAreaCityCode,String strLocalNumber,String strExtension,String strAnyText,
			String strExtensionPrefix,String strSpeedDialCode,String strUnformattedTelephoneNumber, String strEffectiveStartDate, String strExpirationDate,
			CWE objExpirationReason, CWE objProtectionCode, EI objSharedTelecommunicationIdentifier, String strPreferenceOrder)
	{
		XTN xtn  = (XTN)getDataElement(1019);
//		xtn.setTelephoneNumber(strTelephoneNumber);
		xtn.setTelecommunicationUseCode(strTeleCommunicationUseCode);
		xtn.setTelecommunicationEquipmentType(strTeleCommunicationEquipmentType);
		xtn.setCommuinicationAddress(strCommuinicationAddress);
		xtn.setCountryCode(strCountryCode);
		xtn.setAreaCityCode(strAreaCityCode);
		xtn.setLocalNumber(strLocalNumber);
		xtn.setExtension(strExtension);
		xtn.setAnyText(strAnyText);
		xtn.setExtensionPrefix(strExtensionPrefix);
		xtn.setSpeedDialCode(strSpeedDialCode);
		xtn.setUnformattedTelephonenumber(strUnformattedTelephoneNumber); 
		xtn.setEffectiveStartDate(strEffectiveStartDate);
		xtn.setExpirationDate(strExpirationDate);
		xtn.setExpirationReason(objExpirationReason);
		xtn.setProtectionCode(objProtectionCode);
		xtn.setSharedTelecommunicationIdentifier(objSharedTelecommunicationIdentifier);
		xtn.setPreferenceOrder(strPreferenceOrder); 
		setContactTelephoneNumber(xtn);

	} 

	/** 
	 * Set the Contact Telephone Number.
	 * This field contains the phone number of the study contact.
	 * @param objcontactTelephoneNumber Object of Contact Telephone Number. 
	 */ 
	public void setContactTelephoneNumber(XTN objcontactTelephoneNumber)
	{
		setDataType(1019,objcontactTelephoneNumber);

	}

	/**
	 * Set the Last Accrual Date.
	 * This field contains the status information on the patient 
	 * registration activity for quality control and operations purposes.
	 * @param strLastAccrualDate String which to set as Last Accrual Date
	 */ 
	public void setLastAccrualDate (String strLastAccrualDate) 
	{
		DT lastAccrualDate  = (DT)getDataElement(1017);
		lastAccrualDate.setValue(strLastAccrualDate); 
		setLastAccrualDate(lastAccrualDate);

	} 

	/** 
	 * Set the Last Accrual Date.
	 * This field contains the status information on the patient 
	 * registration activity for quality control and operations purposes.
	 * @param objlastAccrualDate Object of Last Accrual Date.
	 */ 
	public void setLastAccrualDate(DT objlastAccrualDate)
	{
		setDataType(1017,objlastAccrualDate);

	}
	/**
	 * Set the Last IRB Approval Date.
	 * This field contains an institution's Internal Review Board 
	 * approval dates which are required annually to continue participation in a clinical trial.
	 * @param strLastIRBApprovalDate String which to set as Last IRB Approval Date
	 */ 
	public void setLastIRBApprovalDate (String strLastIRBApprovalDate) 
	{
		DT lastIRBApprovalDate  = (DT)getDataElement(1015);
		lastIRBApprovalDate.setValue(strLastIRBApprovalDate); 
		setLastIRBApprovalDate(lastIRBApprovalDate);

	} 

	/** 
	 * Set the Last IRB Approval Date.
	 * This field contains an institution's Internal Review Board 
	 * approval dates which are required annually to continue participation in a clinical trial.
	 * @param objlastIRBApprovalDate Object of Last IRB Approval Date.
	 */ 
	public void setLastIRBApprovalDate(DT objlastIRBApprovalDate)
	{
		setDataType(1015,objlastIRBApprovalDate);

	}
	/**
	 * Set the Set ID CM0.
	 * This field contains a number that uniquely identify this 
	 * transaction for the purpose of adding, changing, or deleting the transaction.
	 * @param strSetID_CM0 This field contains the number that identifies CM0 transaction.
	 */ 
	public void setSetID_CM0 (String strSetID_CM0) 
	{
		SI setID_CM0  = (SI)getDataElement(1010);
		setID_CM0.setValue(strSetID_CM0); 
		setSetID_CM0(setID_CM0);

	} 

	/** 
	 * Set the Set ID CM0.
	 * This field contains a number that uniquely identify this 
	 * transaction for the purpose of adding, changing, or deleting the transaction.
	 * @param objsetID_CM0 Object of Set ID CM0.
	 */ 
	public void setSetID_CM0(SI objsetID_CM0)
	{
		setDataType(1010,objsetID_CM0);

	}
	/**
	 * Set the Sponsor Study ID.
	 * This field contains the study number established by the study sponsor.
	 * @param strEntityIdentifier Specifies defined by a hierarchic designator, represented by components 2 through 4.
	 * 								[Reference Section 2.A.33, "HD - hierarchic designator".] 
	 * @param strNamespaceId Specifies  the HL7 identifier for the user-defined table of values for this component.
	 * 						   [Refer to User-defined Table 0363 - Assigning authority] 	 
	 * @param strUniversalId Specifies string formatted according to the scheme defined by the component, 
	 * 							<universal ID type> (UID type). 
	 * @param strUniversalIdType Specifies  the interpretation of the second component of the HD. 
	 */ 
	public void setSponsorStudyID (String strEntityIdentifier,String strNamespaceId,
			String strUniversalId,String strUniversalIdType)
	{
		EI sponsorStudyID  = (EI)getDataElement(1011);
		sponsorStudyID.setEntityIdentifier(strEntityIdentifier);
		sponsorStudyID.setNamespaceId(strNamespaceId);
		sponsorStudyID.setUniversalId(strUniversalId);
		sponsorStudyID.setUniversalIdType(strUniversalIdType); 
		setSponsorStudyID(sponsorStudyID);

	} 

	/** 
	 * Set the Sponsor Study ID.
	 * This field contains the study number established by the study sponsor.
	 * @param objsponsorStudyID Object of Sponsor Study ID.
	 */ 
	public void setSponsorStudyID(EI objsponsorStudyID)
	{
		setDataType(1011,objsponsorStudyID);

	}
	/**
	 * Set the Title of Study.
	 * This field contains the sending institution's title for the clinical trial.
	 * @param strTitleofStudy String which to set as Title of Study
	 */ 
	public void setTitleofStudy (String strTitleofStudy) 
	{
		ST titleofStudy  = (ST)getDataElement(1013);
		titleofStudy.setValue(strTitleofStudy); 
		setTitleofStudy(titleofStudy);

	} 

	/** 
	 * Set the Title of Study.
	 * This field contains the sending institution's title for the clinical trial.
	 * @param objtitleofStudy Object of Title of Study.
	 */ 
	public void setTitleofStudy(ST objtitleofStudy)
	{
		setDataType(1013,objtitleofStudy);

	}
	/**
	 * Set the Total Accrual to Date.
	 * This field is a quality control field to enable checks the patient data
	 * have been transmitted on all registered patients.
	 * @param strTotalAccrualtoDate String which to set as Total Accrualto Date
	 */ 
	public void setTotalAccrualtoDate (String strTotalAccrualtoDate) 
	{
		NM totalAccrualtoDate  = (NM)getDataElement(1016);
		totalAccrualtoDate.setValue(strTotalAccrualtoDate); 
		setTotalAccrualtoDate(totalAccrualtoDate);

	} 

	/** 
	 * Set the Total Accrual to Date.
	 * This field is a quality control field to enable checks the patient data
	 * have been transmitted on all registered patients.
	 * @param objtotalAccrualtoDate Object of Total Accrual to Date.
	 */ 
	public void setTotalAccrualtoDate(NM objtotalAccrualtoDate)
	{
		setDataType(1016,objtotalAccrualtoDate);

	}

	/**
	 * 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 Thrown when Segment Validation Fails.
	 */
	public boolean validate() throws InvalidSegmentException
	{
		/*
		 * Sponsor Study ID,Title of Study are required fields
		 */
		try
		{
			super.validate();

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