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


import cdac.medinfo.sdk.hl7282.baselibs.AD;
import cdac.medinfo.sdk.hl7282.baselibs.AUI;
import cdac.medinfo.sdk.hl7282.baselibs.CCD;
import cdac.medinfo.sdk.hl7282.baselibs.CCP;
import cdac.medinfo.sdk.hl7282.baselibs.CD;
import cdac.medinfo.sdk.hl7282.baselibs.CF;
import cdac.medinfo.sdk.hl7282.baselibs.CNE;
import cdac.medinfo.sdk.hl7282.baselibs.CNN;
import cdac.medinfo.sdk.hl7282.baselibs.CP;
import cdac.medinfo.sdk.hl7282.baselibs.CQ;
import cdac.medinfo.sdk.hl7282.baselibs.CWE;
import cdac.medinfo.sdk.hl7282.baselibs.CX;
import cdac.medinfo.sdk.hl7282.baselibs.DDI;
import cdac.medinfo.sdk.hl7282.baselibs.DIN;
import cdac.medinfo.sdk.hl7282.baselibs.DLD;
import cdac.medinfo.sdk.hl7282.baselibs.DLN;
import cdac.medinfo.sdk.hl7282.baselibs.DLT;
import cdac.medinfo.sdk.hl7282.baselibs.DR;
import cdac.medinfo.sdk.hl7282.baselibs.DT;
import cdac.medinfo.sdk.hl7282.baselibs.DTM;
import cdac.medinfo.sdk.hl7282.baselibs.DTN;
import cdac.medinfo.sdk.hl7282.baselibs.ED;
import cdac.medinfo.sdk.hl7282.baselibs.EI;
import cdac.medinfo.sdk.hl7282.baselibs.EIP;
import cdac.medinfo.sdk.hl7282.baselibs.ERL;
import cdac.medinfo.sdk.hl7282.baselibs.FC;
import cdac.medinfo.sdk.hl7282.baselibs.FN;
import cdac.medinfo.sdk.hl7282.baselibs.FT;
import cdac.medinfo.sdk.hl7282.baselibs.GTS;
import cdac.medinfo.sdk.hl7282.baselibs.HD;
import cdac.medinfo.sdk.hl7282.baselibs.ICD;
import cdac.medinfo.sdk.hl7282.baselibs.ID;
import cdac.medinfo.sdk.hl7282.baselibs.IS;
import cdac.medinfo.sdk.hl7282.baselibs.JCC;
import cdac.medinfo.sdk.hl7282.baselibs.MA;
import cdac.medinfo.sdk.hl7282.baselibs.MO;
import cdac.medinfo.sdk.hl7282.baselibs.MOC;
import cdac.medinfo.sdk.hl7282.baselibs.MOP;
import cdac.medinfo.sdk.hl7282.baselibs.MSG;
import cdac.medinfo.sdk.hl7282.baselibs.NA;
import cdac.medinfo.sdk.hl7282.baselibs.NDL;
import cdac.medinfo.sdk.hl7282.baselibs.NM;
import cdac.medinfo.sdk.hl7282.baselibs.NR;
import cdac.medinfo.sdk.hl7282.baselibs.OCD;
import cdac.medinfo.sdk.hl7282.baselibs.OG;
import cdac.medinfo.sdk.hl7282.baselibs.OSP;
import cdac.medinfo.sdk.hl7282.baselibs.PIP;
import cdac.medinfo.sdk.hl7282.baselibs.PL;
import cdac.medinfo.sdk.hl7282.baselibs.PLN;
import cdac.medinfo.sdk.hl7282.baselibs.PPN;
import cdac.medinfo.sdk.hl7282.baselibs.PRL;
import cdac.medinfo.sdk.hl7282.baselibs.PT;
import cdac.medinfo.sdk.hl7282.baselibs.PTA;
import cdac.medinfo.sdk.hl7282.baselibs.QIP;
import cdac.medinfo.sdk.hl7282.baselibs.QSC;
import cdac.medinfo.sdk.hl7282.baselibs.RCD;
import cdac.medinfo.sdk.hl7282.baselibs.RFR;
import cdac.medinfo.sdk.hl7282.baselibs.RI;
import cdac.medinfo.sdk.hl7282.baselibs.RMC;
import cdac.medinfo.sdk.hl7282.baselibs.RP;
import cdac.medinfo.sdk.hl7282.baselibs.RPT;
import cdac.medinfo.sdk.hl7282.baselibs.SAD;
import cdac.medinfo.sdk.hl7282.baselibs.SCV;
import cdac.medinfo.sdk.hl7282.baselibs.SI;
import cdac.medinfo.sdk.hl7282.baselibs.SN;
import cdac.medinfo.sdk.hl7282.baselibs.SNM;
import cdac.medinfo.sdk.hl7282.baselibs.SPD;
import cdac.medinfo.sdk.hl7282.baselibs.SRT;
import cdac.medinfo.sdk.hl7282.baselibs.ST;
import cdac.medinfo.sdk.hl7282.baselibs.TM;
import cdac.medinfo.sdk.hl7282.baselibs.TX;
import cdac.medinfo.sdk.hl7282.baselibs.UN;
import cdac.medinfo.sdk.hl7282.baselibs.UVC;
import cdac.medinfo.sdk.hl7282.baselibs.VH;
import cdac.medinfo.sdk.hl7282.baselibs.VID;
import cdac.medinfo.sdk.hl7282.baselibs.VR;
import cdac.medinfo.sdk.hl7282.baselibs.WVI;
import cdac.medinfo.sdk.hl7282.baselibs.WVS;
import cdac.medinfo.sdk.hl7282.baselibs.XAD;
import cdac.medinfo.sdk.hl7282.baselibs.XCN;
import cdac.medinfo.sdk.hl7282.baselibs.XON;
import cdac.medinfo.sdk.hl7282.baselibs.XPN;
import cdac.medinfo.sdk.hl7282.baselibs.XTN;
import cdac.medinfo.sdk.hl7282.baselibs.datatypefactory.DataTypeMapReader;
import cdac.medinfo.sdk.hl7282.commoninterface.IDataType;
import cdac.medinfo.sdk.hl7282.utils.EnumDataType;
import cdac.medinfo.sdk.hl7282.utils.HL7Constants;
import cdac.medinfo.sdk.hl7282.utils.IDataTypeMap;
import cdac.medinfo.sdk.hl7282.utils.IDataTypeMapReader;
import cdac.medinfo.sdk.hl7282.utils.ISegmentMap;
import cdac.medinfo.sdk.hl7282.utils.ISegmentMapReader;

/**
 * DataElementFactory class provides support for the creation of HL7 Data Type. 
 * This class provides the methods to create Data Type.
 */
public class DataElementFactory 
{
	
	
	private static DataElementFactory objDataElementFactory = null;
	ISegmentMapReader objDictionaryReader = null;
	IDataTypeMapReader objIDataTypeMapReader = null;
	
	/**
	 * Constructor of DataElementFactory
	 */
	private DataElementFactory()
	{
		objDictionaryReader = SegmentMapReader.createInstance();
		objIDataTypeMapReader = DataTypeMapReader.createInstance();
	}
	
	/**
	 * Returns instance of DataElementFactory if not created.
	 * @return DataElementFactory - instance of DataElementFactory.
	 */
	public static DataElementFactory createInstance()
	{
		if(objDataElementFactory == null)
		{
			objDataElementFactory = new DataElementFactory();
		}
		return objDataElementFactory;
	}
	
	public IDataType getDataElement(String strSegmentname,int iItemID)
	{
		ISegmentMap objSegmentMap = objDictionaryReader.getSegmentMap(strSegmentname);
		int[] iValTable = objSegmentMap.getValueTable(iItemID);
		int iMinLength = objSegmentMap.getItemMinimumLength(iItemID);
		int iMaxLength = objSegmentMap.getItemMaximumLength(iItemID);
		String strCLength = objSegmentMap.getItemConformanceLength(iItemID);
		String strDataType = objSegmentMap.getDataTypeName(iItemID);
		
		int HL7Component = HL7Constants.HL7_COMPONENT;
		return getDataElement(iValTable, iMinLength,iMaxLength,strCLength, strDataType,HL7Component);
	}
	/**
	 * This method returns the Data Type component as per the value table ,Minimum Length,Maximum Length and Conformance Length. 
	 * @param strDataTypename name of DataType for which to create component.
	 * @param SequenceId retrieves the particular component as per the sequence.
	 * @return IDataType component as per the requirement.
	 */
	public IDataType getDataTypeComponent(String strDataTypename,int SequenceId)
	{
		IDataTypeMap objIDataTypeMap = objIDataTypeMapReader.getDataTypeMap(strDataTypename);
		int[] iValTable = objIDataTypeMap.getValueTable(SequenceId);
		int iMinLength = objIDataTypeMap.getItemMinimumLength(SequenceId);
		int iMaxLength = objIDataTypeMap.getItemMaximumLength(SequenceId);
		String strCLength= objIDataTypeMap.getItemConformanceLength(SequenceId);
		String strDataType = objIDataTypeMap.getDataTypeName(SequenceId);
		
		boolean isComponentType = isComponentType(strDataTypename);
		int HL7Component;
		if(isComponentType)
			HL7Component = HL7Constants.HL7_COMPONENT;
		else
			HL7Component = HL7Constants.HL7_SUBCOMPONENT;
		return getDataElement(iValTable, iMinLength,iMaxLength,strCLength, strDataType,HL7Component);
	}
	//This method returns true if it is primitive else false.  
	private boolean isComponentType(String strDataType)
	{
		if(strDataType.equalsIgnoreCase("ST")||
				strDataType.equalsIgnoreCase("DT")||
				strDataType.equalsIgnoreCase("NM")||
				strDataType.equalsIgnoreCase("TM")||
				strDataType.equalsIgnoreCase("TX")||
				strDataType.equalsIgnoreCase("SN")||
				strDataType.equalsIgnoreCase("SI")||
				strDataType.equalsIgnoreCase("IS")||
				strDataType.equalsIgnoreCase("ID")||
				strDataType.equalsIgnoreCase("GTS")||
				strDataType.equalsIgnoreCase("FT")||
				strDataType.equalsIgnoreCase("DTM")||
				strDataType.equalsIgnoreCase("SNM")
		)		
		return true;
		else
			return false;
	}
	/**
	 * Returns the instance of Datatype.
	 * @param iMinLength Integer value of Minimum Length
	 * @param iMaxLength Integer value of Maximum Length
	 * @param strCLength String value of Conformance Length
	 * @param strDTName String value of DataType
	 * @return IDataType - specified DataType
	 */
	public IDataType getDataElement(int iMinLength,int iMaxLength ,String strCLength,String strDTName)
	{
		int HL7Component = HL7Constants.HL7_COMPONENT;
		return getDataElement(0, iMinLength, iMaxLength , strCLength , strDTName,HL7Component);
	}
	
	/**
	 * Returns the instance of Datatype.
	 * @param iValueTable Array of integer value of Table
	 * @param iMinLength Integer value of Minimum Length
	 * @param iMaxLength Integer value of Maximum Length
	 * @param strCLength String value of Conformance Length
	 * @param strDTName String value of DataType
	 * @return IDataType - specified DataType
	 */
	public IDataType getDataElement(int[] iValueTable,int iMinLength,int iMaxLength ,String strCLength,String strDTName,int HL7Component)
	{
		if(iValueTable != null)
			return getDataElement(iValueTable[0], iMinLength,iMaxLength ,strCLength, strDTName,HL7Component);
		else
			return getDataElement(0, iMinLength,iMaxLength ,strCLength, strDTName,HL7Component);
	}
	
	/**
	 * Returns the instance of Datatype.
	 * @param iValueTable Integer value of Table
	 * @param iLength Integer value of Length
	 * @param strDTName String value of DataType
	 * @return IDataType - specified DataType
	 */
	public IDataType getDataElement(int iValueTable,int iMinLength ,int iMaxLength ,String strCLength,String strDTName,int HL7Component)
	{
		IDataType objIDataType = null;
		if(strDTName != null)
		{
			if(strDTName.equalsIgnoreCase("CWE"))
				{
					objIDataType = new CWE(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
				}
			else if(strDTName.equalsIgnoreCase("AUI"))
			{
				objIDataType = new AUI(iMinLength , iMaxLength , strCLength, iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("CCD"))
			{
				objIDataType = new CCD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("CCP"))
			{
				objIDataType = new CCP(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("CD"))
			{
				objIDataType = new CD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("CF"))
			{
				objIDataType = new CF(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("CNE"))
			{
				objIDataType = new CNE(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("CNN"))
			{
				objIDataType = new CNN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("CP"))
			{
				objIDataType = new CP(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("CQ"))
			{
				objIDataType = new CQ(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("AD"))
			{
				objIDataType = new AD(iMinLength , iMaxLength , strCLength ,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("CWE"))
			{
				objIDataType = new CWE(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("CX"))
			{
				objIDataType = new CX(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("DDI"))
			{
				objIDataType = new DDI(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("DIN"))
			{
				objIDataType = new DIN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("DLD"))
			{
				objIDataType = new DLD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("DLN"))
			{
				objIDataType = new DLN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("DLT"))
			{
				objIDataType = new DLT(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("DR"))
			{
				objIDataType = new DR(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("DT"))
			{
				objIDataType = new DT(iMinLength , iMaxLength , strCLength,iValueTable);
			}
			else if(strDTName.equalsIgnoreCase("DTM"))
			{
				objIDataType = new DTM(iMinLength , iMaxLength , strCLength,iValueTable);
			}
			else if(strDTName.equalsIgnoreCase("DTN"))
			{
				objIDataType = new DTN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("ED"))
			{
				objIDataType = new ED(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("EI"))
			{
				objIDataType = new EI(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("EIP"))
			{
				objIDataType = new EIP(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("ERL"))
			{
				objIDataType = new ERL(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("FC"))
			{
				objIDataType = new FC(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("FN"))
			{
				objIDataType = new FN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("FT"))
			{
				objIDataType = new FT(iMinLength , iMaxLength , strCLength,iValueTable);
			}
			else if(strDTName.equalsIgnoreCase("GTS"))
			{
				objIDataType = new GTS(iMinLength , iMaxLength , strCLength,iValueTable);
			}
			else if(strDTName.equalsIgnoreCase("HD"))
			{
				objIDataType = new HD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("ICD"))
			{
				objIDataType = new ICD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("ID"))
			{
				objIDataType = new ID(iMinLength , iMaxLength , strCLength,iValueTable);
			}
			else if(strDTName.equalsIgnoreCase("IS"))
			{
				objIDataType = new IS(iMinLength , iMaxLength , strCLength,iValueTable);
			}
			else if(strDTName.equalsIgnoreCase("JCC"))
			{
				objIDataType = new JCC(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("MA"))
			{
				objIDataType = new MA(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("MO"))
			{
				objIDataType = new MO(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("MOC"))
			{
				objIDataType = new MOC(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("MOP"))
			{
				objIDataType = new MOP(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("MSG"))
			{
				objIDataType = new MSG(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("NA"))
			{
				objIDataType = new NA(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("NDL"))
			{
				objIDataType = new NDL(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("NM"))
			{
				objIDataType = new NM(iMinLength , iMaxLength , strCLength,iValueTable);
			}
			else if(strDTName.equalsIgnoreCase("NR"))
			{
				objIDataType = new NR(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("OCD"))
			{
				objIDataType = new OCD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("OSP"))
			{
				objIDataType = new OSP(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("PIP"))
			{
				objIDataType = new PIP(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("PL"))
			{
				objIDataType = new PL(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("PLN"))
			{
				objIDataType = new PLN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("PPN"))
			{
				objIDataType = new PPN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("PRL"))
			{
				objIDataType = new PRL(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("PT"))
			{
				objIDataType = new PT(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("PTA"))
			{
				objIDataType = new PTA(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("QIP"))
			{
				objIDataType = new QIP(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("QSC"))
			{
				objIDataType = new QSC(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("RCD"))
			{
				objIDataType = new RCD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("RFR"))
			{
				objIDataType = new RFR(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("RI"))
			{
				objIDataType = new RI(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("RMC"))
			{
				objIDataType = new RMC(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("RP"))
			{
				objIDataType = new RP(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("RPT"))
			{
				objIDataType = new RPT(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("SAD"))
			{
				objIDataType = new SAD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("SCV"))
			{
				objIDataType = new SCV(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("SI"))
			{
				objIDataType = new SI(iMinLength , iMaxLength , strCLength,iValueTable);
			}
			else if(strDTName.equalsIgnoreCase("SN"))
			{
				objIDataType = new SN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("SPD"))
			{
				objIDataType = new SPD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("SRT"))
			{
				objIDataType = new SRT(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("ST"))
			{
				objIDataType = new ST(iMinLength , iMaxLength , strCLength,iValueTable);
			}
			else if(strDTName.equalsIgnoreCase("TM"))
			{
				objIDataType = new TM(iMinLength , iMaxLength , strCLength,iValueTable);
			}
			else if(strDTName.equalsIgnoreCase("TX"))
			{
				objIDataType = new TX(iMinLength , iMaxLength , strCLength,iValueTable);
			}
			else if(strDTName.equalsIgnoreCase("UN"))
			{
				objIDataType = new UN();
			}
			else if(strDTName.equalsIgnoreCase("UVC"))
			{
				objIDataType = new UVC(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("VH"))
			{
				objIDataType = new VH(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("VID"))
			{
				objIDataType = new VID(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("VR"))
			{
				objIDataType = new VR(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("WVI"))
			{
				objIDataType = new WVI(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("WVS"))
			{
				objIDataType = new WVS(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("XAD"))
			{
				objIDataType = new XAD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("XCN"))
			{
				objIDataType = new XCN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("XON"))
			{
				objIDataType = new XON(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("XPN"))
			{
				objIDataType = new XPN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("XTN"))
			{
				objIDataType = new XTN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
			else if(strDTName.equalsIgnoreCase("SNM"))
			{
				objIDataType = new SNM(iMinLength , iMaxLength , strCLength,iValueTable);
			}
			else if(strDTName.equalsIgnoreCase("OG"))
			{
				objIDataType = new OG(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
			}
		}
		
		return objIDataType;
	}
	
	/**
	 * Returns the instance of Datatype.
	 * @param iValueTable Integer value of Table
	 * @param iLength Integer value of Length
	 * @param strDTName String value of DataType
	 * @return IDataType - specified DataType
	 */
	public IDataType getDataElement1(int iValueTable,int iMinLength, int iMaxLength,String strCLength ,String strDTName,int HL7Component)
	{
		IDataType objIDataType = null;
		
		if(strDTName != null)
		{
			strDTName = strDTName.toUpperCase();
			
			EnumDataType enumDataType = EnumDataType.valueOf(strDTName);
			
			switch (enumDataType) {
			case HL7_DT_AD:
				objIDataType = new AD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
				break;
				
			case HL7_DT_CWE:
				objIDataType = new CWE(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
				break;
				
			case HL7_DT_AUI:
				objIDataType = new AUI(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
				break;
				
			case HL7_DT_CCD:
				objIDataType = new CCD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
				break;
				
			case HL7_DT_CCP:
				objIDataType = new CCP(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
				break;
				
			case HL7_DT_CD:
				objIDataType = new CD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
				break;
				
			default:
				break;
			}
			
//			if(strDTName.equalsIgnoreCase("AD"))
//			if(strDTName.equalsIgnoreCase("AUI"))
//			if(strDTName.equalsIgnoreCase("CCD"))
//			else if(strDTName.equalsIgnoreCase("CCP"))
//			if(strDTName.equalsIgnoreCase("CD"))
//			{
//				
//			}
//			if(strDTName.equalsIgnoreCase("CE"))
//			{
//				objIDataType = new CE(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("CF"))
//			{
//				objIDataType = new CF(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("CNE"))
//			{
//				objIDataType = new CNE(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("CNN"))
//			{
//				objIDataType = new CNN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("CP"))
//			{
//				objIDataType = new CP(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("CQ"))
//			{
//				objIDataType = new CQ(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("CSU"))
//			{
//				objIDataType = new CSU(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("CWE"))
//			{
//				objIDataType = new CWE(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("CX"))
//			{
//				objIDataType = new CX(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("DDI"))
//			{
//				objIDataType = new DDI(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("DIN"))
//			{
//				objIDataType = new DIN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("DLD"))
//			{
//				objIDataType = new DLD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("DLN"))
//			{
//				objIDataType = new DLN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("DLT"))
//			{
//				objIDataType = new DLT(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("DR"))
//			{
//				objIDataType = new DR(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("DT"))
//			{
//				objIDataType = new DT(iMinLength , iMaxLength , strCLength,iValueTable);
//			}
//			if(strDTName.equalsIgnoreCase("DTM"))
//			{
//				objIDataType = new DTM(iMinLength , iMaxLength , strCLength,iValueTable);
//			}
//			if(strDTName.equalsIgnoreCase("DTN"))
//			{
//				objIDataType = new DTN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("ED"))
//			{
//				objIDataType = new ED(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("EI"))
//			{
//				objIDataType = new EI(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("EIP"))
//			{
//				objIDataType = new EIP(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("ELD"))
//			{
//				objIDataType = new ELD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("ERL"))
//			{
//				objIDataType = new ERL(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("FC"))
//			{
//				objIDataType = new FC(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("FN"))
//			{
//				objIDataType = new FN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("FT"))
//			{
//				objIDataType = new FT(iMinLength , iMaxLength , strCLength,iValueTable);
//			}
//			else if(strDTName.equalsIgnoreCase("GTS"))
//			{
//				objIDataType = new GTS(iMinLength , iMaxLength , strCLength,iValueTable);
//			}
//			if(strDTName.equalsIgnoreCase("HD"))
//			{
//				objIDataType = new HD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("ICD"))
//			{
//				objIDataType = new ICD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("ID"))
//			{
//				objIDataType = new ID(iMinLength , iMaxLength , strCLength,iValueTable);
//			}
//			if(strDTName.equalsIgnoreCase("IS"))
//			{
//				objIDataType = new IS(iMinLength , iMaxLength , strCLength,iValueTable);
//			}
//			if(strDTName.equalsIgnoreCase("JCC"))
//			{
//				objIDataType = new JCC(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("LA1"))
//			{
//				objIDataType = new LA1(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("LA2"))
//			{
//				objIDataType = new LA2(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("MA"))
//			{
//				objIDataType = new MA(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("MO"))
//			{
//				objIDataType = new MO(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("MOC"))
//			{
//				objIDataType = new MOC(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("MOP"))
//			{
//				objIDataType = new MOP(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("MSG"))
//			{
//				objIDataType = new MSG(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("NA"))
//			{
//				objIDataType = new NA(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("NDL"))
//			{
//				objIDataType = new NDL(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("NM"))
//			{
//				objIDataType = new NM(iMinLength , iMaxLength , strCLength,iValueTable);
//			}
//			else if(strDTName.equalsIgnoreCase("NR"))
//			{
//				objIDataType = new NR(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("OCD"))
//			{
//				objIDataType = new OCD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("OSD"))
//			{
//				objIDataType = new OSD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("OSP"))
//			{
//				objIDataType = new OSP(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("PIP"))
//			{
//				objIDataType = new PIP(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("PL"))
//			{
//				objIDataType = new PL(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("PLN"))
//			{
//				objIDataType = new PLN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("PPN"))
//			{
//				objIDataType = new PPN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("PRL"))
//			{
//				objIDataType = new PRL(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("PT"))
//			{
//				objIDataType = new PT(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("PTA"))
//			{
//				objIDataType = new PTA(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("QIP"))
//			{
//				objIDataType = new QIP(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("QSC"))
//			{
//				objIDataType = new QSC(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("RCD"))
//			{
//				objIDataType = new RCD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("RFR"))
//			{
//				objIDataType = new RFR(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("RI"))
//			{
//				objIDataType = new RI(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("RMC"))
//			{
//				objIDataType = new RMC(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("RP"))
//			{
//				objIDataType = new RP(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("RPT"))
//			{
//				objIDataType = new RPT(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("SAD"))
//			{
//				objIDataType = new SAD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("SCV"))
//			{
//				objIDataType = new SCV(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("SI"))
//			{
//				objIDataType = new SI(iMinLength , iMaxLength , strCLength,iValueTable);
//			}
//			else if(strDTName.equalsIgnoreCase("SN"))
//			{
//				objIDataType = new SN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("SPD"))
//			{
//				objIDataType = new SPD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("SPS"))
//			{
//				objIDataType = new SPS(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("SRT"))
//			{
//				objIDataType = new SRT(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("ST"))
//			{
//				objIDataType = new ST(iMinLength , iMaxLength , strCLength,iValueTable);
//			}
//			if(strDTName.equalsIgnoreCase("TM"))
//			{
//				objIDataType = new TM(iMinLength , iMaxLength , strCLength,iValueTable);
//			}
//			else if(strDTName.equalsIgnoreCase("TQ"))
//			{
//				objIDataType = new TQ(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("TS"))
//			{
//				objIDataType = new TS(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			 if(strDTName.equalsIgnoreCase("TX"))
//			{
//				objIDataType = new TX(iMinLength , iMaxLength , strCLength,iValueTable);
//			}
//			if(strDTName.equalsIgnoreCase("UN"))
//			{
//				objIDataType = new UN();
//			}
//			else if(strDTName.equalsIgnoreCase("UVC"))
//			{
//				objIDataType = new UVC(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("VH"))
//			{
//				objIDataType = new VH(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("VID"))
//			{
//				objIDataType = new VID(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("VR"))
//			{
//				objIDataType = new VR(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("WVI"))
//			{
//				objIDataType = new WVI(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("WVS"))
//			{
//				objIDataType = new WVS(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("XAD"))
//			{
//				objIDataType = new XAD(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("XCN"))
//			{
//				objIDataType = new XCN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("XON"))
//			{
//				objIDataType = new XON(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			else if(strDTName.equalsIgnoreCase("XPN"))
//			{
//				objIDataType = new XPN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
//			if(strDTName.equalsIgnoreCase("XTN"))
//			{
//				objIDataType = new XTN(iMinLength , iMaxLength , strCLength,iValueTable,HL7Component);
//			}
		}
		
		return objIDataType;
	}
}
