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

/**
 * MFI - Master File Identification Segment<p>
 * The Technical Steward for the MFI segment is CQ.
 * <p>Represents an HL7 MFI message segment. 
 * This segment has the following fields:</p><p>
 * MFI-1: Master File Identifier (CWE)<b>Required</b><br> 
 * MFI-2: Master File Application Identifier (HD)<b>Optional</b><br> 
 * MFI-3: File-Level Event Code (ID)<b>Required</b><br> 
 * MFI-4: Entered Date/Time (DTM)<b>Optional</b><br> 
 * MFI-5: Effective Date/Time (DTM)<b>Optional</b><br> 
 * MFI-6: Response Level Code (ID)<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 MFI extends Segment   
{
	

	/**
	 * Constructs the MFI segment.
	 */
	public MFI()
	{super(EnumSegments.HL7_SEG_MFI);
	}

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

	/**
	 * Retrieves the Effective Date Time.
	 * This field contains the effective date/time, which can be included for file-level action specified.
	 * @return DTM - effectiveDateTime
	 */
	public DTM getEffectiveDateTime() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(662);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Entered Date Time.
	 * This field contains the time stamp for file-level event on originating system.
	 * @return DTM - enteredDateTime
	 */
	public DTM getEnteredDateTime() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(661);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the File Level Event Code.
	 * This field defines the file-level event code.
	 * @return ID - fileLevelEventCode
	 */
	public ID getFileLevelEventCode() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(660);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Master File Application Identifier.
	 * This field contains an optional code of up to 180 characters which 
	 * (if applicable) uniquely identifies the application responsible for 
	 * maintaining this file at a particular site.
	 * @return HD - masterFileApplicationIdentifier
	 */
	public HD getMasterFileApplicationIdentifier() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(659);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (HD)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Master File Identifier.
	 * This field identify a standard HL7 master file. 
	 * @return CWE - masterFileIdentifier
	 */
	public CWE getMasterFileIdentifier() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(658);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Response Level Code.
	 * This field specify the application response level defined for a given Master
	 *  File Message at the MFE segment level.
	 * @return ID - responseLevelCode
	 */
	public ID getResponseLevelCode() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(663);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Set the Master File Identifier.
	 * This field identify a standard HL7 master file. 
	 * @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 setMasterFileIdentifier  (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(658);
		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);
		setMasterFileIdentifier(cwe);
	} 

	/** 
	 * Set the Master File Identifier.
	 * This field identify a standard HL7 master file. 
	 * @param objmasterFileIdentifier Object of Master File Identifier.
	 */ 
	public void setMasterFileIdentifier(CWE objmasterFileIdentifier)
	{
		setDataType(658,objmasterFileIdentifier);

	}

	/**
	 * Set the Master File Application Identifier.
	 * This field contains an optional code of up to 180 characters which 
	 * (if applicable) uniquely identifies the application responsible for 
	 * maintaining this file at a particular site.
	 * @param strNamespaceID Specifies Specifies  the HL7 identifier for the user-defined table of values for this component.[Refer Table No.300]
	 * @param strUniversalID Specifies a string formatted according to the scheme defined by the component, <universal ID type> (UID type). 
	 * @param strUniversalIDType Governs the interpretation of the strUniversalId. 
	 */ 
	public void setMasterFileApplicationIdentifier (String strNamespaceID,String strUniversalID,String strUniversalIDType) 
	{
		HD masterFileApplicationIdentifier  = (HD)getDataElement(659);
		masterFileApplicationIdentifier.setNamespaceId(strNamespaceID);
		masterFileApplicationIdentifier.setUniversalId(strUniversalID);
		masterFileApplicationIdentifier.setUniversalIdType(strUniversalIDType); 
		setMasterFileApplicationIdentifier(masterFileApplicationIdentifier);

	} 

	/** 
	 * Set the Master File Application Identifier.
	 * This field contains an optional code of up to 180 characters which 
	 * (if applicable) uniquely identifies the application responsible for 
	 * maintaining this file at a particular site.
	 * @param objmasterFileApplicationIdentifier Object of Master File Application Identifier.
	 */ 
	public void setMasterFileApplicationIdentifier(HD objmasterFileApplicationIdentifier)
	{
		setDataType(659,objmasterFileApplicationIdentifier);

	}

	/**
	 * Set the File Level Event Code.
	 * This field defines the file-level event code.
	 * @param strFileLevelEventCode This field defines the file-level event code. 
	 */ 
	public void setFileLevelEventCode (String strFileLevelEventCode) 
	{
		ID fileLevelEventCode  = (ID)getDataElement(660);
		fileLevelEventCode.setValue(strFileLevelEventCode); 
		setFileLevelEventCode(fileLevelEventCode);

	} 

	/** 
	 * Set the File Level Event Code.
	 * This field defines the file-level event code.
	 * @param objfileLevelEventCode Object of File Level Event Code.
	 */ 
	public void setFileLevelEventCode(ID objfileLevelEventCode)
	{
		setDataType(660,objfileLevelEventCode);

	}

	/**
	 * Set the Entered Date Time.
	 * This field contains the time stamp for file-level event on originating system.
	 * @param strTime Specifies a point in time using a 24-hour clock notation. 
	 */ 
	public void setEnteredDateTime (String strTime) 
	{
		DTM enteredDateTime  = (DTM)getDataElement(661);
		enteredDateTime.setValue(strTime);
		setEnteredDateTime(enteredDateTime);

	} 

	/** Set the Entered Date Time.
	 * This field contains the time stamp for file-level event on originating system.
	 * @param objenteredDateTime Object of Entered Date Time.
	 */ 
	public void setEnteredDateTime(DTM objenteredDateTime)
	{
		setDataType(661,objenteredDateTime);

	}

	/**
	 * Set the Effective Date Time.
	 * This field contains the effective date/time, which can be included for file-level action specified.
	 * @param strTime Specifies a point in time using a 24-hour clock notation. 
	 */ 
	public void setEffectiveDateTime (String strTime) 
	{
		DTM effectiveDateTime  = (DTM)getDataElement(662);
		effectiveDateTime.setValue(strTime);
		setEffectiveDateTime(effectiveDateTime);
	} 

	/** 
	 * Set the Effective Date Time.
	 * This field contains the effective date/time, which can be included for file-level action specified. 
	 * @param objeffectiveDateTime Object of Effective Date Time.
	 */ 
	public void setEffectiveDateTime(DTM objeffectiveDateTime)
	{
		setDataType(662,objeffectiveDateTime);

	}

	/**
	 * Set the Response Level Code.
	 * This field specify the application response level defined for a given Master
	 *  File Message at the MFE segment level.
	 * @param strFileLevelEventCode This field defines the Response Level Code. 
	 */ 
	public void setResponseLevelCode (String strFileLevelEventCode) 
	{
		ID responseLevelCode  = (ID)getDataElement(663);
		responseLevelCode.setValue(strFileLevelEventCode); 
		setResponseLevelCode(responseLevelCode);

	} 

	/** Set the Response Level Code.
	 * This field specify the application response level defined for a given Master
	 *  File Message at the MFE segment level.
	 * @param objresponseLevelCode Object of the Response Level Code. 
	 */ 
	public void setResponseLevelCode(ID objresponseLevelCode)
	{
		setDataType(663,objresponseLevelCode);

	}

	/**
	 * 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 Throws when Segment Validation fails 
	 */
	@Override
	public boolean validate() throws InvalidSegmentException 
	{
		/*
		 * Validate mandatory conditions. masterFileIdentifier , fileLevelEventCode and responseLevelCode are required.
		 */
		try
		{
			super.validate();

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