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

/***
 * NCK - System Clock Segment.<p>
 * The NCK segment is used to allow the various applications on the network to synchronize
 * their system clocks (system date and time).
 * <p>Represents an HL7 NCK message segment. 
 * This segment has the following fields:</p><p>
 * NCK-1: System Date/Time (DTM)<b>Required</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 NCK extends Segment   
{
	


	/**
	 *  Constructs the NCK segment.
	 */
	public NCK()
	{super(EnumSegments.HL7_SEG_NCK);
	}

	/**
	 * Set the System Date Time.
	 * This field contains an HL7 time stamp.
	 * @param strDate Specifies a point in time using a 24-hour clock notation. 
	 */	
	public void setSystemDateTime(String strDate) 
	{
		DTM systemDate_Time  = (DTM)getDataElement(1172);
		systemDate_Time.setValue(strDate);		
		setSystemDateTime(systemDate_Time);

	}

	/**
	 * Set the System Date Time.
	 * This field contains an HL7 time stamp.
	 * @param systemDate_Time System Date Time
	 */	
	public void setSystemDateTime(DTM systemDate_Time)
	{
		setDataType(1172,systemDate_Time);
	}

	/**
	 * Retrieves the System Date Time.
	 * This field contains an HL7 time stamp.
	 * @return DTM - systemDate_Time
	 */
	public DTM getSystemDateTime() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1172);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * 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
	 */
	@Override
	public boolean validate() throws InvalidSegmentException 
	{
		try
		{
			super.validate();

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