예제 #1
0
 ///<summary>Returns true if Update(HL7DefMessage,HL7DefMessage) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(HL7DefMessage hL7DefMessage, HL7DefMessage oldHL7DefMessage)
 {
     if (hL7DefMessage.HL7DefNum != oldHL7DefMessage.HL7DefNum)
     {
         return(true);
     }
     if (hL7DefMessage.MessageType != oldHL7DefMessage.MessageType)
     {
         return(true);
     }
     if (hL7DefMessage.EventType != oldHL7DefMessage.EventType)
     {
         return(true);
     }
     if (hL7DefMessage.InOrOut != oldHL7DefMessage.InOrOut)
     {
         return(true);
     }
     if (hL7DefMessage.ItemOrder != oldHL7DefMessage.ItemOrder)
     {
         return(true);
     }
     if (hL7DefMessage.Note != oldHL7DefMessage.Note)
     {
         return(true);
     }
     if (hL7DefMessage.MessageStructure != oldHL7DefMessage.MessageStructure)
     {
         return(true);
     }
     return(false);
 }
예제 #2
0
 ///<summary>Inserts one HL7DefMessage into the database.  Returns the new priKey.</summary>
 public static long Insert(HL7DefMessage hL7DefMessage)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         hL7DefMessage.HL7DefMessageNum = DbHelper.GetNextOracleKey("hl7defmessage", "HL7DefMessageNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(hL7DefMessage, true));
             }
             catch (Oracle.DataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     hL7DefMessage.HL7DefMessageNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(hL7DefMessage, false));
     }
 }
예제 #3
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<HL7DefMessage> TableToList(DataTable table){
			List<HL7DefMessage> retVal=new List<HL7DefMessage>();
			HL7DefMessage hL7DefMessage;
			for(int i=0;i<table.Rows.Count;i++) {
				hL7DefMessage=new HL7DefMessage();
				hL7DefMessage.HL7DefMessageNum= PIn.Long  (table.Rows[i]["HL7DefMessageNum"].ToString());
				hL7DefMessage.HL7DefNum       = PIn.Long  (table.Rows[i]["HL7DefNum"].ToString());
				string messageType=table.Rows[i]["MessageType"].ToString();
				if(messageType==""){
					hL7DefMessage.MessageType   =(MessageTypeHL7)0;
				}
				else try{
					hL7DefMessage.MessageType   =(MessageTypeHL7)Enum.Parse(typeof(MessageTypeHL7),messageType);
				}
				catch{
					hL7DefMessage.MessageType   =(MessageTypeHL7)0;
				}
				string eventType=table.Rows[i]["EventType"].ToString();
				if(eventType==""){
					hL7DefMessage.EventType     =(EventTypeHL7)0;
				}
				else try{
					hL7DefMessage.EventType     =(EventTypeHL7)Enum.Parse(typeof(EventTypeHL7),eventType);
				}
				catch{
					hL7DefMessage.EventType     =(EventTypeHL7)0;
				}
				hL7DefMessage.InOrOut         = (InOutHL7)PIn.Int(table.Rows[i]["InOrOut"].ToString());
				hL7DefMessage.ItemOrder       = PIn.Int   (table.Rows[i]["ItemOrder"].ToString());
				hL7DefMessage.Note            = PIn.String(table.Rows[i]["Note"].ToString());
				retVal.Add(hL7DefMessage);
			}
			return retVal;
		}
예제 #4
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <HL7DefMessage> TableToList(DataTable table)
        {
            List <HL7DefMessage> retVal = new List <HL7DefMessage>();
            HL7DefMessage        hL7DefMessage;

            foreach (DataRow row in table.Rows)
            {
                hL7DefMessage = new HL7DefMessage();
                hL7DefMessage.HL7DefMessageNum = PIn.Long(row["HL7DefMessageNum"].ToString());
                hL7DefMessage.HL7DefNum        = PIn.Long(row["HL7DefNum"].ToString());
                string messageType = row["MessageType"].ToString();
                if (messageType == "")
                {
                    hL7DefMessage.MessageType = (OpenDentBusiness.MessageTypeHL7) 0;
                }
                else
                {
                    try{
                        hL7DefMessage.MessageType = (OpenDentBusiness.MessageTypeHL7)Enum.Parse(typeof(OpenDentBusiness.MessageTypeHL7), messageType);
                    }
                    catch {
                        hL7DefMessage.MessageType = (OpenDentBusiness.MessageTypeHL7) 0;
                    }
                }
                string eventType = row["EventType"].ToString();
                if (eventType == "")
                {
                    hL7DefMessage.EventType = (OpenDentBusiness.EventTypeHL7) 0;
                }
                else
                {
                    try{
                        hL7DefMessage.EventType = (OpenDentBusiness.EventTypeHL7)Enum.Parse(typeof(OpenDentBusiness.EventTypeHL7), eventType);
                    }
                    catch {
                        hL7DefMessage.EventType = (OpenDentBusiness.EventTypeHL7) 0;
                    }
                }
                hL7DefMessage.InOrOut   = (OpenDentBusiness.InOutHL7)PIn.Int(row["InOrOut"].ToString());
                hL7DefMessage.ItemOrder = PIn.Int(row["ItemOrder"].ToString());
                hL7DefMessage.Note      = PIn.String(row["Note"].ToString());
                string messageStructure = row["MessageStructure"].ToString();
                if (messageStructure == "")
                {
                    hL7DefMessage.MessageStructure = (OpenDentBusiness.MessageStructureHL7) 0;
                }
                else
                {
                    try{
                        hL7DefMessage.MessageStructure = (OpenDentBusiness.MessageStructureHL7)Enum.Parse(typeof(OpenDentBusiness.MessageStructureHL7), messageStructure);
                    }
                    catch {
                        hL7DefMessage.MessageStructure = (OpenDentBusiness.MessageStructureHL7) 0;
                    }
                }
                retVal.Add(hL7DefMessage);
            }
            return(retVal);
        }
예제 #5
0
 ///<summary>Inserts one HL7DefMessage into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(HL7DefMessage hL7DefMessage)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(hL7DefMessage, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             hL7DefMessage.HL7DefMessageNum = DbHelper.GetNextOracleKey("hl7defmessage", "HL7DefMessageNum");                  //Cacheless method
         }
         return(InsertNoCache(hL7DefMessage, true));
     }
 }
예제 #6
0
        ///<summary>Returns null if no HL7 def is enabled or no ACK is defined in the enabled def.</summary>
        public static MessageHL7 GenerateACK(string controlId, bool isAck, string ackEvent)
        {
            MessageHL7 messageHL7 = new MessageHL7(MessageTypeHL7.ACK);

            messageHL7.ControlId = controlId;
            messageHL7.AckEvent  = ackEvent;
            HL7Def hl7Def = HL7Defs.GetOneDeepEnabled();

            if (hl7Def == null)
            {
                return(null);               //no def enabled, return null
            }
            //find an ACK message in the def
            HL7DefMessage hl7DefMessage = null;

            for (int i = 0; i < hl7Def.hl7DefMessages.Count; i++)
            {
                if (hl7Def.hl7DefMessages[i].MessageType == MessageTypeHL7.ACK && hl7Def.hl7DefMessages[i].InOrOut == InOutHL7.Outgoing)
                {
                    hl7DefMessage = hl7Def.hl7DefMessages[i];
                    break;
                }
            }
            if (hl7DefMessage == null)           //ACK message type is not defined so do nothing and return
            {
                return(null);
            }
            //go through each segment in the def
            for (int s = 0; s < hl7DefMessage.hl7DefSegments.Count; s++)
            {
                SegmentHL7 seg = new SegmentHL7(hl7DefMessage.hl7DefSegments[s].SegmentName);
                seg.SetField(0, hl7DefMessage.hl7DefSegments[s].SegmentName.ToString());
                for (int f = 0; f < hl7DefMessage.hl7DefSegments[s].hl7DefFields.Count; f++)
                {
                    string fieldName = hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].FieldName;
                    if (fieldName == "")                   //If fixed text instead of field name just add text to segment
                    {
                        seg.SetField(hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].OrdinalPos, hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].FixedText);
                    }
                    else
                    {
                        seg.SetField(hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].OrdinalPos, FieldConstructor.GenerateACK(hl7Def, fieldName, controlId, isAck, ackEvent));
                    }
                }
                messageHL7.Segments.Add(seg);
            }
            return(messageHL7);
        }
예제 #7
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <HL7DefMessage> TableToList(DataTable table)
        {
            List <HL7DefMessage> retVal = new List <HL7DefMessage>();
            HL7DefMessage        hL7DefMessage;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                hL7DefMessage = new HL7DefMessage();
                hL7DefMessage.HL7DefMessageNum = PIn.Long(table.Rows[i]["HL7DefMessageNum"].ToString());
                hL7DefMessage.HL7DefNum        = PIn.Long(table.Rows[i]["HL7DefNum"].ToString());
                string messageType = table.Rows[i]["MessageType"].ToString();
                if (messageType == "")
                {
                    hL7DefMessage.MessageType = (MessageTypeHL7)0;
                }
                else
                {
                    try{
                        hL7DefMessage.MessageType = (MessageTypeHL7)Enum.Parse(typeof(MessageTypeHL7), messageType);
                    }
                    catch {
                        hL7DefMessage.MessageType = (MessageTypeHL7)0;
                    }
                }
                string eventType = table.Rows[i]["EventType"].ToString();
                if (eventType == "")
                {
                    hL7DefMessage.EventType = (EventTypeHL7)0;
                }
                else
                {
                    try{
                        hL7DefMessage.EventType = (EventTypeHL7)Enum.Parse(typeof(EventTypeHL7), eventType);
                    }
                    catch {
                        hL7DefMessage.EventType = (EventTypeHL7)0;
                    }
                }
                hL7DefMessage.InOrOut   = (InOutHL7)PIn.Int(table.Rows[i]["InOrOut"].ToString());
                hL7DefMessage.ItemOrder = PIn.Int(table.Rows[i]["ItemOrder"].ToString());
                hL7DefMessage.Note      = PIn.String(table.Rows[i]["Note"].ToString());
                retVal.Add(hL7DefMessage);
            }
            return(retVal);
        }
예제 #8
0
        ///<summary>Updates one HL7DefMessage in the database.</summary>
        public static void Update(HL7DefMessage hL7DefMessage)
        {
            string command = "UPDATE hl7defmessage SET "
                             + "HL7DefNum       =  " + POut.Long(hL7DefMessage.HL7DefNum) + ", "
                             + "MessageType     = '" + POut.String(hL7DefMessage.MessageType.ToString()) + "', "
                             + "EventType       = '" + POut.String(hL7DefMessage.EventType.ToString()) + "', "
                             + "InOrOut         =  " + POut.Int((int)hL7DefMessage.InOrOut) + ", "
                             + "ItemOrder       =  " + POut.Int(hL7DefMessage.ItemOrder) + ", "
                             + "Note            =  " + DbHelper.ParamChar + "paramNote "
                             + "WHERE HL7DefMessageNum = " + POut.Long(hL7DefMessage.HL7DefMessageNum);

            if (hL7DefMessage.Note == null)
            {
                hL7DefMessage.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, hL7DefMessage.Note);

            Db.NonQ(command, paramNote);
        }
예제 #9
0
        ///<summary>Inserts one HL7DefMessage into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(HL7DefMessage hL7DefMessage, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO hl7defmessage (";

            if (!useExistingPK && isRandomKeys)
            {
                hL7DefMessage.HL7DefMessageNum = ReplicationServers.GetKeyNoCache("hl7defmessage", "HL7DefMessageNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "HL7DefMessageNum,";
            }
            command += "HL7DefNum,MessageType,EventType,InOrOut,ItemOrder,Note,MessageStructure) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(hL7DefMessage.HL7DefMessageNum) + ",";
            }
            command +=
                POut.Long(hL7DefMessage.HL7DefNum) + ","
                + "'" + POut.String(hL7DefMessage.MessageType.ToString()) + "',"
                + "'" + POut.String(hL7DefMessage.EventType.ToString()) + "',"
                + POut.Int((int)hL7DefMessage.InOrOut) + ","
                + POut.Int(hL7DefMessage.ItemOrder) + ","
                + DbHelper.ParamChar + "paramNote,"
                + "'" + POut.String(hL7DefMessage.MessageStructure.ToString()) + "')";
            if (hL7DefMessage.Note == null)
            {
                hL7DefMessage.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringParam(hL7DefMessage.Note));

            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command, paramNote);
            }
            else
            {
                hL7DefMessage.HL7DefMessageNum = Db.NonQ(command, true, "HL7DefMessageNum", "hL7DefMessage", paramNote);
            }
            return(hL7DefMessage.HL7DefMessageNum);
        }
예제 #10
0
        ///<summary>Inserts one HL7DefMessage into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(HL7DefMessage hL7DefMessage, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                hL7DefMessage.HL7DefMessageNum = ReplicationServers.GetKey("hl7defmessage", "HL7DefMessageNum");
            }
            string command = "INSERT INTO hl7defmessage (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "HL7DefMessageNum,";
            }
            command += "HL7DefNum,MessageType,EventType,InOrOut,ItemOrder,Note) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(hL7DefMessage.HL7DefMessageNum) + ",";
            }
            command +=
                POut.Long(hL7DefMessage.HL7DefNum) + ","
                + "'" + POut.String(hL7DefMessage.MessageType.ToString()) + "',"
                + "'" + POut.String(hL7DefMessage.EventType.ToString()) + "',"
                + POut.Int((int)hL7DefMessage.InOrOut) + ","
                + POut.Int(hL7DefMessage.ItemOrder) + ","
                + DbHelper.ParamChar + "paramNote)";
            if (hL7DefMessage.Note == null)
            {
                hL7DefMessage.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, hL7DefMessage.Note);

            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command, paramNote);
            }
            else
            {
                hL7DefMessage.HL7DefMessageNum = Db.NonQ(command, true, paramNote);
            }
            return(hL7DefMessage.HL7DefMessageNum);
        }
예제 #11
0
        public static void ProcessAck(MessageHL7 msg, bool isVerboseLogging)
        {
            IsVerboseLogging = isVerboseLogging;
            HL7Def def = HL7Defs.GetOneDeepEnabled();

            if (def == null)
            {
                throw new Exception("Could not process ACK.  No HL7 definition is enabled.");
            }
            HL7DefMessage hl7defmsg = null;

            for (int i = 0; i < def.hl7DefMessages.Count; i++)
            {
                if (def.hl7DefMessages[i].MessageType == MessageTypeHL7.ACK && def.hl7DefMessages[i].InOrOut == InOutHL7.Incoming)
                {
                    hl7defmsg = def.hl7DefMessages[i];
                    break;
                }
            }
            if (hl7defmsg == null)           //No incoming ACK defined, do nothing with it
            {
                throw new Exception("Could not process HL7 ACK message.  No definition for this type of message in the enabled HL7Def.");
            }
            for (int i = 0; i < hl7defmsg.hl7DefSegments.Count; i++)
            {
                try {
                    SegmentHL7 seg = msg.GetSegment(hl7defmsg.hl7DefSegments[i].SegmentName, !hl7defmsg.hl7DefSegments[i].IsOptional);
                    if (seg != null)                   //null if segment was not found but is optional
                    {
                        ProcessSeg(null, 0, hl7defmsg.hl7DefSegments[i], seg, msg);
                    }
                }
                catch (ApplicationException ex) {               //Required segment was missing, or other error.
                    throw new Exception("Could not process HL7 message.  " + ex);
                }
            }
        }
예제 #12
0
		///<summary>Inserts one HL7DefMessage into the database.  Returns the new priKey.</summary>
		public static long Insert(HL7DefMessage hL7DefMessage){
			if(DataConnection.DBtype==DatabaseType.Oracle) {
				hL7DefMessage.HL7DefMessageNum=DbHelper.GetNextOracleKey("hl7defmessage","HL7DefMessageNum");
				int loopcount=0;
				while(loopcount<100){
					try {
						return Insert(hL7DefMessage,true);
					}
					catch(Oracle.DataAccess.Client.OracleException ex){
						if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
							hL7DefMessage.HL7DefMessageNum++;
							loopcount++;
						}
						else{
							throw ex;
						}
					}
				}
				throw new ApplicationException("Insert failed.  Could not generate primary key.");
			}
			else {
				return Insert(hL7DefMessage,false);
			}
		}
예제 #13
0
        public static HL7Def GetDeepInternal(HL7Def def)
        {
            //ok to pass in null
            //HL7Def def=HL7Defs.GetInternalFromDb("eCWStandalone");
            if (def == null)           //wasn't in the database
            {
                def                       = new HL7Def();
                def.IsNew                 = true;
                def.Description           = "eCW Standalone";
                def.ModeTx                = ModeTxHL7.File;
                def.IncomingFolder        = "";
                def.OutgoingFolder        = "";
                def.IncomingPort          = "";
                def.OutgoingIpPort        = "";
                def.FieldSeparator        = "|";
                def.ComponentSeparator    = "^";
                def.SubcomponentSeparator = "&";
                def.RepetitionSeparator   = "~";
                def.EscapeCharacter       = @"\";
                def.IsInternal            = true;
                def.InternalType          = "eCWStandalone";
                def.InternalTypeVersion   = Assembly.GetAssembly(typeof(Db)).GetName().Version.ToString();
                def.IsEnabled             = false;
                def.Note                  = "";
                def.ShowDemographics      = HL7ShowDemographics.ChangeAndAdd;
                def.ShowAccount           = true;
                def.ShowAppts             = true;
            }
            def.hl7DefMessages = new List <HL7DefMessage>();         //so that if this is called repeatedly, it won't pile on duplicate messages.
            //in either case, now get all child objects, which can't be in the database.
            //----------------------------------------------------------------------------------------------------------------------------------
            //eCW incoming patient information (ADT).
            HL7DefMessage msg = new HL7DefMessage();

            def.AddMessage(msg, MessageTypeHL7.ADT, EventTypeHL7.A04, InOutHL7.Incoming, 0);
            //MSH segment------------------------------------------------------------------
            HL7DefSegment seg = new HL7DefSegment();

            msg.AddSegment(seg, 0, SegmentNameHL7.MSH);
            //MSH.8, Message Type
            seg.AddField(8, "messageType");
            //MSH.9, Message Control ID
            seg.AddField(9, "messageControlId");
            //PID segment------------------------------------------------------------------
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 2, SegmentNameHL7.PID);
            //PID.2, Patient ID
            seg.AddField(2, "pat.ChartNumber");
            //PID.4, Alternate Patient ID, PID.4 is not saved with using standalone integration
            //PID.5, Patient Name
            seg.AddField(5, "pat.nameLFM");
            //PID.7, Date/Time of Birth
            seg.AddField(7, "pat.birthdateTime");
            //PID.8, Administrative Sex
            seg.AddField(8, "pat.Gender");
            //PID.10, Race
            seg.AddField(10, "pat.Race");
            //PID.11, Patient Address
            seg.AddField(11, "pat.addressCityStateZip");
            //PID.13, Phone Number - Home
            seg.AddField(13, "pat.HmPhone");
            //PID.14, Phone Number - Business
            seg.AddField(14, "pat.WkPhone");
            //PID.16, Marital Status
            seg.AddField(16, "pat.Position");
            //PID.19, SSN - Patient
            seg.AddField(19, "pat.SSN");
            //PID.22, Fee Schedule
            seg.AddField(22, "pat.FeeSched");
            //GT1 segment------------------------------------------------------------------
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 5, SegmentNameHL7.GT1);
            //GT1.2, Guarantor Number
            seg.AddField(2, "guar.ChartNumber");
            //GT1.3, Guarantor Name
            seg.AddField(3, "guar.nameLFM");
            //GT1.5, Guarantor Address
            seg.AddField(5, "guar.addressCityStateZip");
            //GT1.6, Guarantor Phone Number - Home
            seg.AddField(6, "guar.HmPhone");
            //GT1.7, Guarantor Phone Number - Business
            seg.AddField(7, "guar.WkPhone");
            //GT1.8, Guarantor Date/Time of Birth
            seg.AddField(8, "guar.birthdateTime");
            //GT1.9, Guarantor Administrative Sex
            seg.AddField(9, "guar.Gender");
            //GT1.12, Guarantor SSN
            seg.AddField(12, "guar.SSN");
            return(def);
        }
예제 #14
0
 public static HL7Def GetDeepInternal(HL7Def def)
 {
     //ok to pass in null
     //HL7Def def=HL7Defs.GetInternalFromDb("eCWTight");
     if (def == null)           //wasn't in the database
     {
         def                       = new HL7Def();
         def.IsNew                 = true;
         def.Description           = "eCW Tight";
         def.ModeTx                = ModeTxHL7.File;
         def.IncomingFolder        = "";
         def.OutgoingFolder        = "";
         def.IncomingPort          = "";
         def.OutgoingIpPort        = "";
         def.SftpInSocket          = "";
         def.SftpUsername          = "";
         def.SftpPassword          = "";
         def.FieldSeparator        = "|";
         def.ComponentSeparator    = "^";
         def.SubcomponentSeparator = "&";
         def.RepetitionSeparator   = "~";
         def.EscapeCharacter       = @"\";
         def.IsInternal            = true;
         def.InternalType          = HL7InternalType.eCWTight;
         def.InternalTypeVersion   = Assembly.GetAssembly(typeof(Db)).GetName().Version.ToString();
         def.IsEnabled             = false;
         def.Note                  = "";
         def.ShowDemographics      = HL7ShowDemographics.Hide;
         def.ShowAccount           = false;
         def.ShowAppts             = false;
         def.IsQuadAsToothNum      = false;
     }
     def.hl7DefMessages = new List <HL7DefMessage>();         //so that if this is called repeatedly, it won't pile on duplicate messages.
     //in either case, now get all child objects, which can't be in the database.
     #region Inbound Messages
     #region ADT - Patient Demographics (Admits, Discharges, and Transfers)
     //======================================================================================================================
     //eCW incoming patient information (ADT).
     HL7DefMessage msg = new HL7DefMessage();
     def.AddMessage(msg, MessageTypeHL7.ADT, MessageStructureHL7.ADT_A01, InOutHL7.Incoming, 0);
     //MSH segment------------------------------------------------------------------
     HL7DefSegment seg = new HL7DefSegment();
     msg.AddSegment(seg, 0, SegmentNameHL7.MSH);
     //MSH.8, Message Type
     seg.AddField(8, "messageType");
     //MSH.9, Message Control ID
     seg.AddField(9, "messageControlId");
     //PID segment------------------------------------------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 2, SegmentNameHL7.PID);
     //PID.2, Patient ID
     seg.AddField(2, "pat.PatNum");
     //PID.4, Alternate Patient ID
     seg.AddField(4, "pat.ChartNumber");
     //PID.5, Patient Name
     seg.AddField(5, "pat.nameLFM");
     //PID.7, Date/Time of Birth
     seg.AddField(7, "pat.birthdateTime");
     //PID.8, Administrative Sex
     seg.AddField(8, "pat.Gender");
     //PID.10, Race
     seg.AddField(10, "pat.Race");
     //PID.11, Patient Address
     seg.AddField(11, "pat.addressCityStateZip");
     //PID.13, Phone Number - Home
     seg.AddField(13, "pat.HmPhone");
     //PID.14, Phone Number - Business
     seg.AddField(14, "pat.WkPhone");
     //PID.16, Marital Status
     seg.AddField(16, "pat.Position");
     //PID.19, SSN - Patient
     seg.AddField(19, "pat.SSN");
     //PID.22, Fee Schedule
     seg.AddField(22, "pat.FeeSched");
     //GT1 segment------------------------------------------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 5, SegmentNameHL7.GT1);
     //GT1.2, Guarantor Number
     seg.AddField(2, "guar.PatNum");
     //GT1.3, Guarantor Name
     seg.AddField(3, "guar.nameLFM");
     //GT1.5, Guarantor Address
     seg.AddField(5, "guar.addressCityStateZip");
     //GT1.6, Guarantor Phone Number - Home
     seg.AddField(6, "guar.HmPhone");
     //GT1.7, Guarantor Phone Number - Business
     seg.AddField(7, "guar.WkPhone");
     //GT1.8, Guarantor Date/Time of Birth
     seg.AddField(8, "guar.birthdateTime");
     //GT1.9, Guarantor Administrative Sex
     seg.AddField(9, "guar.Gender");
     //GT1.12, Guarantor SSN
     seg.AddField(12, "guar.SSN");
     #endregion ADT - Patient Demographics (Admits, Discharges, and Transfers)
     #region SIU - Schedule Information Unsolicited
     //======================================================================================================================
     //eCW incoming appointment information (SIU - Schedule information unsolicited).
     msg = new HL7DefMessage();
     def.AddMessage(msg, MessageTypeHL7.SIU, MessageStructureHL7.SIU_S12, InOutHL7.Incoming, 1);
     //MSH segment------------------------------------------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 0, SegmentNameHL7.MSH);
     //MSH.8, Message Type
     seg.AddField(8, "messageType");
     //MSH.9, Message Control ID
     seg.AddField(9, "messageControlId");
     //PID segment------------------------------------------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 2, SegmentNameHL7.PID);
     //PID.2
     seg.AddField(2, "pat.PatNum");
     //PID.4, Alternate Patient ID
     seg.AddField(4, "pat.ChartNumber");
     //PID.5, Patient Name
     seg.AddField(5, "pat.nameLFM");
     //PID.7, Date/Time of Birth
     seg.AddField(7, "pat.birthdateTime");
     //PID.8, Administrative Sex
     seg.AddField(8, "pat.Gender");
     //PID.10, Race
     seg.AddField(10, "pat.Race");
     //PID.11, Patient Address
     seg.AddField(11, "pat.addressCityStateZip");
     //PID.13, Phone Number - Home
     seg.AddField(13, "pat.HmPhone");
     //PID.14, Phone Number - Business
     seg.AddField(14, "pat.WkPhone");
     //PID.16, Marital Status
     seg.AddField(16, "pat.Position");
     //PID.19, SSN - Patient
     seg.AddField(19, "pat.SSN");
     //PID.22, Fee Schedule
     seg.AddField(22, "pat.FeeSched");
     //SCH segment------------------------------------------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 1, SegmentNameHL7.SCH);
     //SCH.2, Filler Appointment ID.  In the old eCW interface, we were pulling from SCH.2, which was always the same as SCH.1.
     seg.AddField(2, "apt.AptNum");
     //SCH.7, Appointment Reason
     seg.AddField(7, "apt.Note");
     //SCH.11, Appointment Timing Quantity
     seg.AddField(11, "apt.lengthStartEnd");
     //AIG segment------------------------------------------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 4, false, true, SegmentNameHL7.AIG);
     //AIG.3, Resource ID^Resource Name (Lname, Fname all as a string)
     seg.AddField(3, "prov.provIdName");
     //PV1 segment.-----------------------------------------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 3, false, true, SegmentNameHL7.PV1);
     //PV1.7, Attending/Primary Care Doctor, UPIN^LastName^FirstName^MI
     seg.AddField(7, "prov.provIdNameLFM");
     #endregion SIU - Schedule Information Unsolicited
     #region ACK - General Acknowledgment
     //=======================================================================================================================
     //Acknowledgment message (ACK)
     msg = new HL7DefMessage();
     def.AddMessage(msg, MessageTypeHL7.ACK, MessageStructureHL7.ADT_A01, InOutHL7.Incoming, 2);
     //MSH segment------------------------------------------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 0, SegmentNameHL7.MSH);
     //MSH.8, Message Type
     seg.AddField(8, "messageType");
     //MSA (Message Acknowledgment) segment-----------------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 1, SegmentNameHL7.MSA);
     //MSA.1, Acknowledgment Code
     seg.AddField(1, "ackCode");
     //MSA.2, Message Control ID
     seg.AddField(2, "messageControlId");
     #endregion ACK - General Acknowledgment
     #endregion Inbound Messages
     #region Outbound Messages
     #region DFT - Detailed Financial Transaction
     //=======================================================================================================================
     //Detail financial transaction (DFT)
     msg = new HL7DefMessage();
     def.AddMessage(msg, MessageTypeHL7.DFT, MessageStructureHL7.DFT_P03, InOutHL7.Outgoing, 3);
     //MSH (Message Header) segment-------------------------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 0, SegmentNameHL7.MSH);
     //MSH.1, Encoding Characters (DataType.ST)
     seg.AddField(1, "separators^~\\&");
     //MSH.2, Sending Application
     seg.AddFieldFixed(2, DataTypeHL7.HD, "OD");
     //MSH.4, Receiving Application
     seg.AddFieldFixed(4, DataTypeHL7.HD, "ECW");
     //MSH.6, Message Date and Time (YYYYMMDDHHMMSS)
     seg.AddField(6, "dateTime.Now");
     //MSH.8, Message Type^Event Type, example DFT^P03
     seg.AddField(8, "messageType");
     //MSH.9, Message Control ID
     seg.AddField(9, "messageControlId");
     //MSH.10, Processing ID (P-production, T-test)
     seg.AddFieldFixed(10, DataTypeHL7.PT, "P");
     //MSH.11, Version ID
     seg.AddFieldFixed(11, DataTypeHL7.VID, "2.3");
     //EVN (Event Type) segment-----------------------------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 1, SegmentNameHL7.EVN);
     //EVN.1, Event Type, example P03
     seg.AddField(1, "eventType");
     //EVN.2, Recorded Date/Time
     seg.AddField(2, "dateTime.Now");
     //PID (Patient Identification) segment-----------------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 2, SegmentNameHL7.PID);
     //PID.1, Sequence Number (1 for DFT's)
     seg.AddFieldFixed(1, DataTypeHL7.ST, "1");
     //PID.2, Patient ID (Account number.  eCW requires this to be the same # as came in on PID.4.)
     seg.AddField(2, "pat.ChartNumber");
     //PID.3, Patient MRN number
     seg.AddField(3, "pat.PatNum");
     //PID.5, Patient Name (Last^First^MI)
     seg.AddField(5, "pat.nameLFM");
     //PID.7, Birthdate
     seg.AddField(7, "pat.birthdateTime");
     //PID.8, Gender
     seg.AddField(8, "pat.Gender");
     //PID.10, Race
     seg.AddField(10, "pat.Race");
     //PID.11, Address
     seg.AddField(11, "pat.addressCityStateZip");
     //PID.13, Home Phone
     seg.AddField(13, "pat.HmPhone");
     //PID.14, Work Phone
     seg.AddField(14, "pat.WkPhone");
     //PID.16, Marital Status
     seg.AddField(16, "pat.Position");
     //PID.19, SSN
     seg.AddField(19, "pat.SSN");
     //PV1 (Patient Visit) segment--------------------------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 3, SegmentNameHL7.PV1);
     //PV1.7, Attending/Primary Care Doctor
     seg.AddField(7, "prov.provIdNameLFM");
     //PV1.19, Visit Number
     seg.AddField(19, "apt.AptNum");
     //FT1 (Financial Transaction Information) segment------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 4, true, true, SegmentNameHL7.FT1);
     //FT1.1, Sequence Number (starts with 1)
     seg.AddField(1, "sequenceNum");
     //FT1.4, Transaction Date (YYYYMMDDHHMMSS)
     seg.AddField(4, "proc.procDateTime");
     //FT1.5, Transaction Posting Date (YYYYMMDDHHMMSS)
     seg.AddField(5, "proc.procDateTime");
     //FT1.6, Transaction Type
     seg.AddFieldFixed(6, DataTypeHL7.IS, "CG");
     //FT1.10, Transaction Quantity
     seg.AddFieldFixed(10, DataTypeHL7.NM, "1.0");
     //FT1.19, Diagnosis Code
     seg.AddField(19, "proc.DiagnosticCode");
     //FT1.20, Performed by Code (provider)
     seg.AddField(20, "prov.provIdNameLFM");
     //FT1.21, Ordering Provider
     seg.AddField(21, "prov.provIdNameLFM");
     //FT1.22, Unit Cost (procedure fee)
     seg.AddField(22, "proc.ProcFee");
     //FT1.25, Procedure Code
     seg.AddField(25, "proccode.ProcCode");
     //FT1.26, Modifiers (treatment area)
     seg.AddField(26, "proc.toothSurfRange");
     //DG1 (Diagnosis) segment is optional, skip for now
     //ZX1 (PDF Data) segment-------------------------------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 5, SegmentNameHL7.ZX1);
     //ZX1.1
     seg.AddFieldFixed(1, DataTypeHL7.ST, "6");
     //ZX1.2
     seg.AddFieldFixed(2, DataTypeHL7.ST, "PDF");
     //ZX1.3
     seg.AddFieldFixed(3, DataTypeHL7.ST, "PATHOLOGY^Pathology Report^L");
     //ZX1.4
     seg.AddField(4, "pdfDescription");
     //ZX1.5
     seg.AddField(5, "pdfDataAsBase64");
     #endregion DFT - Detailed Financial Transaction
     #region ACK - General Acknowledgment
     //=======================================================================================================================
     //Message Acknowledgment (ACK)
     msg = new HL7DefMessage();
     def.AddMessage(msg, MessageTypeHL7.ACK, MessageStructureHL7.ADT_A01, InOutHL7.Outgoing, 4);
     //MSH (Message Header) segment-------------------------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 0, SegmentNameHL7.MSH);
     //MSH.1, Encoding Characters (DataType.ST)
     seg.AddField(1, "separators^~\\&");
     //MSH.2, Sending Application
     seg.AddFieldFixed(2, DataTypeHL7.HD, "OD");
     //MSH.4, Receiving Application
     seg.AddFieldFixed(4, DataTypeHL7.HD, "ECW");
     //MSH.6, Message Date and Time (YYYYMMDDHHMMSS)
     seg.AddField(6, "dateTime.Now");
     //MSH.8, Message Type^Event Type, example DFT^P03
     seg.AddField(8, "messageType");
     //MSH.9, Message Control ID
     seg.AddField(9, "messageControlId");
     //MSH.10, Processing ID (P-production, T-test)
     seg.AddFieldFixed(10, DataTypeHL7.PT, "P");
     //MSH.11, Version ID
     seg.AddFieldFixed(11, DataTypeHL7.VID, "2.3");
     //MSA (Message Acknowledgment) segment-----------------------------------------
     seg = new HL7DefSegment();
     msg.AddSegment(seg, 1, SegmentNameHL7.MSA);
     //MSA.1, Acknowledgment Code
     seg.AddField(1, "ackCode");
     //MSA.2, Message Control ID
     seg.AddField(2, "messageControlId");
     #endregion ACK - General Acknowledgment
     #endregion Outbound Messages
     return(def);
 }
예제 #15
0
		///<summary>Inserts one HL7DefMessage into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(HL7DefMessage hL7DefMessage,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				hL7DefMessage.HL7DefMessageNum=ReplicationServers.GetKey("hl7defmessage","HL7DefMessageNum");
			}
			string command="INSERT INTO hl7defmessage (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="HL7DefMessageNum,";
			}
			command+="HL7DefNum,MessageType,EventType,InOrOut,ItemOrder,Note) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(hL7DefMessage.HL7DefMessageNum)+",";
			}
			command+=
				     POut.Long  (hL7DefMessage.HL7DefNum)+","
				+"'"+POut.String(hL7DefMessage.MessageType.ToString())+"',"
				+"'"+POut.String(hL7DefMessage.EventType.ToString())+"',"
				+    POut.Int   ((int)hL7DefMessage.InOrOut)+","
				+    POut.Int   (hL7DefMessage.ItemOrder)+","
				+DbHelper.ParamChar+"paramNote)";
			if(hL7DefMessage.Note==null) {
				hL7DefMessage.Note="";
			}
			OdSqlParameter paramNote=new OdSqlParameter("paramNote",OdDbType.Text,hL7DefMessage.Note);
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command,paramNote);
			}
			else {
				hL7DefMessage.HL7DefMessageNum=Db.NonQ(command,true,paramNote);
			}
			return hL7DefMessage.HL7DefMessageNum;
		}
예제 #16
0
        ///<summary>Gets the patient info from the MedLab.OriginalPIDSegments.  Returns null if there is an error processing the PID segments.</summary>
        private List <string[]> GetPatInfoFromPidSegments()
        {
            List <string[]> listPats  = new List <string[]>();
            HL7Def          hl7DefCur = HL7Defs.GetOneDeepEnabled(true);

            if (hl7DefCur == null)
            {
                MsgBox.Show(this, "There must be an enabled MedLab HL7 interface in order to parse the message details.");
                return(null);
            }
            HL7DefMessage hl7defmsg = null;

            for (int i = 0; i < hl7DefCur.hl7DefMessages.Count; i++)
            {
                //for now there are only incoming ORU messages supported, so there should only be one defined message type and it should be inbound
                if (hl7DefCur.hl7DefMessages[i].MessageType == MessageTypeHL7.ORU && hl7DefCur.hl7DefMessages[i].InOrOut == InOutHL7.Incoming)
                {
                    hl7defmsg = hl7DefCur.hl7DefMessages[i];
                    break;
                }
            }
            if (hl7defmsg == null)
            {
                MsgBox.Show(this, "There must be a message definition for an inbound ORU message in order to parse this message.");
                return(null);
            }
            //for MedLab interfaces, we limit the ability to rearrange the message structure, so the PID segment is always in position 1
            if (hl7defmsg.hl7DefSegments.Count < 2)
            {
                MsgBox.Show(this, "The message definition for an inbound ORU message does not have the correct number of segments.");
                return(null);
            }
            HL7DefSegment pidSegDef = hl7defmsg.hl7DefSegments[1];

            if (pidSegDef.SegmentName != SegmentNameHL7.PID)
            {
                MsgBox.Show(this, "The message definition for an inbound ORU message does not have the PID segment as the second segment.");
                return(null);
            }
            for (int i = 0; i < ListMedLabs.Count; i++)
            {
                string[]        fields     = ListMedLabs[i].OriginalPIDSegment.Split(new string[] { "|" }, StringSplitOptions.None);
                List <FieldHL7> listFields = new List <FieldHL7>();
                for (int j = 0; j < fields.Length; j++)
                {
                    listFields.Add(new FieldHL7(fields[j]));
                }
                string patName   = "";
                string birthdate = "";
                string gender    = "";
                string ssn       = "";
                for (int j = 0; j < pidSegDef.hl7DefFields.Count; j++)
                {
                    int itemOrder = pidSegDef.hl7DefFields[j].OrdinalPos;
                    if (itemOrder > listFields.Count - 1)
                    {
                        continue;
                    }
                    switch (pidSegDef.hl7DefFields[j].FieldName)
                    {
                    case "pat.nameLFM":
                        patName = listFields[itemOrder].GetComponentVal(1);
                        if (patName != "" && listFields[itemOrder].GetComponentVal(2) != "")
                        {
                            patName += " ";
                        }
                        patName += listFields[itemOrder].GetComponentVal(2);
                        if (patName != "" && listFields[itemOrder].GetComponentVal(0) != "")
                        {
                            patName += " ";
                        }
                        patName += listFields[itemOrder].GetComponentVal(0);
                        continue;

                    case "patBirthdateAge":
                        //LabCorp sends the birthdate and age in years, months, and days like yyyyMMdd^YYY^MM^DD
                        birthdate = FieldParser.DateTimeParse(listFields[itemOrder].GetComponentVal(0)).ToShortDateString();
                        continue;

                    case "pat.Gender":
                        gender = Lan.g("enumPatientGender", FieldParser.GenderParse(listFields[itemOrder].GetComponentVal(0)).ToString());
                        continue;

                    case "pat.SSN":
                        if (listFields[itemOrder].GetComponentVal(0).Length > 3)
                        {
                            ssn  = "***-**-";
                            ssn += listFields[itemOrder].GetComponentVal(0).Substring(listFields[itemOrder].GetComponentVal(0).Length - 4, 4);
                        }
                        continue;

                    default:
                        continue;
                    }
                }
                bool isDuplicate = false;
                for (int j = 0; j < listPats.Count; j++)
                {
                    if (listPats[j].Length < 4)                   //should never happen
                    {
                        continue;
                    }
                    if (listPats[j][0] == patName && listPats[j][1] == birthdate && listPats[j][2] == gender && listPats[j][3] == ssn)
                    {
                        isDuplicate = true;
                    }
                }
                if (!isDuplicate)
                {
                    listPats.Add(new string[] { patName, birthdate, gender, ssn });
                }
            }
            return(listPats);
        }
예제 #17
0
        ///<summary>Returns null if no HL7 def is enabled or no SRR is defined in the enabled def.  An SRR - Schedule Request Response message is sent when an SRM - Schedule Request Message is received.  The SRM is acknowledged just like any inbound message, but the SRR notifies the placer application that the requested modification took place.  Currently the only appointment modifications allowed are updating the appt note, setting the dentist and hygienist, updating the confirmation status, and changing the ClinicNum.  Setting the appointment status to Broken is also supported.</summary>
        public static MessageHL7 GenerateSRR(Patient pat, Appointment apt, EventTypeHL7 eventType, string controlId, bool isAck, string ackEvent)
        {
            HL7Def hl7Def = HL7Defs.GetOneDeepEnabled();

            if (hl7Def == null)
            {
                return(null);
            }
            //find an outbound SRR message in the def
            HL7DefMessage hl7DefMessage = null;

            for (int i = 0; i < hl7Def.hl7DefMessages.Count; i++)
            {
                if (hl7Def.hl7DefMessages[i].MessageType == MessageTypeHL7.SRR && hl7Def.hl7DefMessages[i].InOrOut == InOutHL7.Outgoing)
                {
                    hl7DefMessage = hl7Def.hl7DefMessages[i];
                    break;
                }
            }
            if (hl7DefMessage == null)           //SRR message type is not defined so do nothing and return
            {
                return(null);
            }
            if (PrefC.GetBool(PrefName.ShowFeaturePatientClone))
            {
                pat = Patients.GetOriginalPatientForClone(pat);
            }
            MessageHL7 msgHl7  = new MessageHL7(MessageTypeHL7.SRR);
            Provider   provPri = Providers.GetProv(apt.ProvNum);

            //go through each segment in the def
            for (int i = 0; i < hl7DefMessage.hl7DefSegments.Count; i++)
            {
                List <Provider> listProvs = new List <Provider>();
                listProvs.Add(provPri);
                if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.AIP && apt.ProvHyg > 0)
                {
                    listProvs.Add(Providers.GetProv(apt.ProvHyg));
                }
                for (int j = 0; j < listProvs.Count; j++)           //AIP will be repeated if there is a dentist and a hygienist on the appt
                {
                    Provider   prov = listProvs[j];
                    SegmentHL7 seg  = new SegmentHL7(hl7DefMessage.hl7DefSegments[i].SegmentName);
                    seg.SetField(0, hl7DefMessage.hl7DefSegments[i].SegmentName.ToString());
                    for (int k = 0; k < hl7DefMessage.hl7DefSegments[i].hl7DefFields.Count; k++)
                    {
                        string fieldName = hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].FieldName;
                        if (fieldName == "")                       //If fixed text instead of field name just add text to segment
                        {
                            seg.SetField(hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].OrdinalPos, hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].FixedText);
                        }
                        else
                        {
                            string fieldValue = "";
                            if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.MSA)
                            {
                                fieldValue = FieldConstructor.GenerateFieldACK(hl7Def, fieldName, controlId, isAck, ackEvent);
                            }
                            else
                            {
                                fieldValue = FieldConstructor.GenerateFieldSRR(hl7Def, fieldName, pat, prov, apt, j + 1, eventType, seg.Name);
                            }
                            seg.SetField(hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].OrdinalPos, fieldValue);
                        }
                    }
                    msgHl7.Segments.Add(seg);
                }
            }
            return(msgHl7);
        }
예제 #18
0
        ///<summary>Returns null if there is no DFT defined for the enabled HL7Def.</summary>
        public static MessageHL7 GenerateDFT(List <Procedure> procList, EventTypeHL7 eventType, Patient pat, Patient guar, long aptNum, string pdfDescription, string pdfDataString)   //add event (A04 etc) parameters later if needed
        //In \\SERVERFILES\storage\OPEN DENTAL\Programmers Documents\Standards (X12, ADA, etc)\HL7\Version2.6\V26_CH02_Control_M4_JAN2007.doc
        //On page 28, there is a Message Construction Pseudocode as well as a flowchart which might help.
        {
            Provider    prov       = Providers.GetProv(Patients.GetProvNum(pat));
            Appointment apt        = Appointments.GetOneApt(aptNum);
            MessageHL7  messageHL7 = new MessageHL7(MessageTypeHL7.DFT);
            HL7Def      hl7Def     = HL7Defs.GetOneDeepEnabled();

            if (hl7Def == null)
            {
                return(null);
            }
            //find a DFT message in the def
            HL7DefMessage hl7DefMessage = null;

            for (int i = 0; i < hl7Def.hl7DefMessages.Count; i++)
            {
                if (hl7Def.hl7DefMessages[i].MessageType == MessageTypeHL7.DFT)
                {
                    hl7DefMessage = hl7Def.hl7DefMessages[i];
                    //continue;
                    break;
                }
            }
            if (hl7DefMessage == null)           //DFT message type is not defined so do nothing and return
            {
                return(null);
            }
            for (int s = 0; s < hl7DefMessage.hl7DefSegments.Count; s++)
            {
                int countRepeat = 1;
                if (hl7DefMessage.hl7DefSegments[s].SegmentName == SegmentNameHL7.FT1)
                {
                    countRepeat = procList.Count;
                }
                //for example, countRepeat can be zero in the case where we are only sending a PDF of the TP to eCW, and no procs.
                for (int repeat = 0; repeat < countRepeat; repeat++)           //FT1 is optional and can repeat so add as many FT1's as procs in procList
                //if(hl7DefMessage.hl7DefSegments[s].SegmentName==SegmentNameHL7.FT1) {
                {
                    if (hl7DefMessage.hl7DefSegments[s].SegmentName == SegmentNameHL7.FT1 && procList.Count > repeat)
                    {
                        prov = Providers.GetProv(procList[repeat].ProvNum);
                    }
                    SegmentHL7 seg = new SegmentHL7(hl7DefMessage.hl7DefSegments[s].SegmentName);
                    seg.SetField(0, hl7DefMessage.hl7DefSegments[s].SegmentName.ToString());
                    for (int f = 0; f < hl7DefMessage.hl7DefSegments[s].hl7DefFields.Count; f++)
                    {
                        string fieldName = hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].FieldName;
                        if (fieldName == "")                       //If fixed text instead of field name just add text to segment
                        {
                            seg.SetField(hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].OrdinalPos, hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].FixedText);
                        }
                        else
                        {
                            //seg.SetField(hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].OrdinalPos,
                            //FieldConstructor.GenerateDFT(hl7Def,fieldName,pat,prov,procList[repeat],guar,apt,repeat+1,eventType,pdfDescription,pdfDataString));
                            Procedure proc = null;
                            if (procList.Count > repeat)                           //procList could be an empty list
                            {
                                proc = procList[repeat];
                            }
                            seg.SetField(hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].OrdinalPos,
                                         FieldConstructor.GenerateDFT(hl7Def, fieldName, pat, prov, proc, guar, apt, repeat + 1, eventType, pdfDescription, pdfDataString));
                        }
                    }
                    messageHL7.Segments.Add(seg);
                }
            }
            return(messageHL7);
        }
예제 #19
0
		///<summary>listSegs will only contain more than one segment if the segment repeats.
		///prevSegName is only required when processing NTE segment(s) to determine which level NTE we are processing,
		///either a PID NTE, a OBR NTE, or a OBX NTE.</summary>
		public static void ProcessSeg(HL7DefMessage msgDef,List<SegmentHL7> listSegs,MessageHL7 msg,SegmentNameHL7 prevSegName=SegmentNameHL7.Unknown) {
			//if prevSegName=Unknown, segDefCur will be the first segDef with matching name
			HL7DefSegment segDefCur=GetSegDefByName(msgDef,listSegs[0].Name,prevSegName);
			switch(listSegs[0].Name) {
				case SegmentNameHL7.MSH://required segment
					if(segDefCur==null) {
						throw new Exception("Could not process the MedLab HL7 message.  "
							+"The message definition for this type of message did not contain a MSH segment definition.");
					}
					ProcessMSH(segDefCur,listSegs[0],msg);//listSegs will only contain one segment, the MSH segment
					return;
				case SegmentNameHL7.NK1://optional segment
					//NK1 is currently not processed
					if(segDefCur==null) {//do not process the NK1 segment if it's not defined
						return;
					}
					ProcessNK1(segDefCur,listSegs);//Currently does nothing
					return;
				case SegmentNameHL7.NTE://optional segment
					if(segDefCur==null) {//do not process the NTE segment if it's not defined
						return;
					}
					ProcessNTE(segDefCur,listSegs,msg);
					return;
				case SegmentNameHL7.OBR://required segment
					if(segDefCur==null) {
						throw new Exception("Could not process the MedLab HL7 message.  "
							+"The message definition for this type of message did not contain a OBR segment definition.");
					}
					ProcessOBR(segDefCur,listSegs[0],msg);
					return;
				case SegmentNameHL7.OBX://required segment
					if(segDefCur==null) {
						throw new Exception("Could not process the MedLab HL7 message.  "
							+"The message definition for this type of message did not contain a OBX segment definition.");
					}
					//instantiates a new MedLabResult object and sets the MedLabNum FK to the _medLabCur.MedLabNum
					ProcessOBX(segDefCur,listSegs[0]);//listSegs will only contain one OBX segment, not repeatable and not optional
					return;
				case SegmentNameHL7.ORC://required segment
					if(segDefCur==null) {
						throw new Exception("Could not process the MedLab HL7 message.  "
							+"The message definition for this type of message did not contain a ORC segment definition.");
					}
					ProcessORC(segDefCur,listSegs[0]);
					return;
				case SegmentNameHL7.PID://required segment
					if(segDefCur==null) {
						throw new Exception("Could not process the MedLab HL7 message.  "
							+"The message definition for this type of message did not contain a PID segment definition.");
					}
					ProcessPID(segDefCur,listSegs[0]);//listSegs will only contain one segment, the PID segment
					return;
				case SegmentNameHL7.SPM://optional segment
					if(segDefCur==null) {//do not process the SPM segment if it's not defined
						return;
					}
					ProcessSPM(segDefCur,listSegs);
					return;
				case SegmentNameHL7.ZEF://optional segment
					if(segDefCur==null) {//do not process the ZEF segment if it's not defined
						return;
					}
					if(_patCur==null) {
						return;//cannot store the pdf without a patient, need a patient to create an entry in the document table
					}
					ProcessZEF(segDefCur,listSegs);
					return;
				case SegmentNameHL7.ZPS://required segment
					if(segDefCur==null) {
						throw new Exception("Could not process the MedLab HL7 message.  "
							+"The message definition for this type of message did not contain a ZPS segment definition.");
					}
					ProcessZPS(segDefCur,listSegs,msg);
					return;
				default:
					return;
			}
		}
예제 #20
0
		public static HL7Def GetDeepInternal(HL7Def def) {
			//ok to pass in null
			//HL7Def def=HL7Defs.GetInternalFromDb("eCWStandalone");
			if(def==null) {//wasn't in the database
				def=new HL7Def();
				def.IsNew=true;
				def.Description="eCW Standalone";
				def.ModeTx=ModeTxHL7.File;
				def.IncomingFolder="";
				def.OutgoingFolder="";
				def.IncomingPort="";
				def.OutgoingIpPort="";
				def.SftpInSocket="";
				def.SftpUsername="";
				def.SftpPassword="";
				def.FieldSeparator="|";
				def.ComponentSeparator="^";
				def.SubcomponentSeparator="&";
				def.RepetitionSeparator="~";
				def.EscapeCharacter=@"\";
				def.IsInternal=true;
				def.InternalType=HL7InternalType.eCWStandalone;
				def.InternalTypeVersion=Assembly.GetAssembly(typeof(Db)).GetName().Version.ToString();
				def.IsEnabled=false;
				def.Note="";
				def.ShowDemographics=HL7ShowDemographics.ChangeAndAdd;
				def.ShowAccount=true;
				def.ShowAppts=true;
				def.IsQuadAsToothNum=false;
			}
			def.hl7DefMessages=new List<HL7DefMessage>();//so that if this is called repeatedly, it won't pile on duplicate messages.
			//in either case, now get all child objects, which can't be in the database.
			#region Inbound Messages
				#region ADT - Patient Demographics (Admits, Discharges, and Transfers)
				//----------------------------------------------------------------------------------------------------------------------------------
				//eCW incoming patient information (ADT).
				HL7DefMessage msg=new HL7DefMessage();
				def.AddMessage(msg,MessageTypeHL7.ADT,MessageStructureHL7.ADT_A01,InOutHL7.Incoming,0);
				//MSH segment------------------------------------------------------------------
				HL7DefSegment seg=new HL7DefSegment();
				msg.AddSegment(seg,0,SegmentNameHL7.MSH);
				//MSH.8, Message Type
				seg.AddField(8,"messageType");
				//MSH.9, Message Control ID
				seg.AddField(9,"messageControlId");
				//PID segment------------------------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,2,SegmentNameHL7.PID);
				//PID.2, Patient ID
				seg.AddField(2,"pat.ChartNumber");
				//PID.4, Alternate Patient ID, PID.4 is not saved with using standalone integration
				//PID.5, Patient Name
				seg.AddField(5,"pat.nameLFM");
				//PID.7, Date/Time of Birth
				seg.AddField(7,"pat.birthdateTime");
				//PID.8, Administrative Sex
				seg.AddField(8,"pat.Gender");
				//PID.10, Race
				seg.AddField(10,"pat.Race");
				//PID.11, Patient Address
				seg.AddField(11,"pat.addressCityStateZip");
				//PID.13, Phone Number - Home
				seg.AddField(13,"pat.HmPhone");
				//PID.14, Phone Number - Business
				seg.AddField(14,"pat.WkPhone");
				//PID.16, Marital Status
				seg.AddField(16,"pat.Position");
				//PID.19, SSN - Patient
				seg.AddField(19,"pat.SSN");
				//PID.22, Fee Schedule
				seg.AddField(22,"pat.FeeSched");
				//GT1 segment------------------------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,5,SegmentNameHL7.GT1);
				//GT1.2, Guarantor Number
				seg.AddField(2,"guar.ChartNumber");
				//GT1.3, Guarantor Name
				seg.AddField(3,"guar.nameLFM");
				//GT1.5, Guarantor Address
				seg.AddField(5,"guar.addressCityStateZip");
				//GT1.6, Guarantor Phone Number - Home
				seg.AddField(6,"guar.HmPhone");
				//GT1.7, Guarantor Phone Number - Business
				seg.AddField(7,"guar.WkPhone");
				//GT1.8, Guarantor Date/Time of Birth
				seg.AddField(8,"guar.birthdateTime");
				//GT1.9, Guarantor Administrative Sex
				seg.AddField(9,"guar.Gender");
				//GT1.12, Guarantor SSN
				seg.AddField(12,"guar.SSN");
				#endregion ADT - Patient Demographics (Admits, Discharges, and Transfers)
			#endregion Inbound Messages
			return def;
		}
예제 #21
0
		///<summary>Updates one HL7DefMessage in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.</summary>
		public static void Update(HL7DefMessage hL7DefMessage,HL7DefMessage oldHL7DefMessage){
			string command="";
			if(hL7DefMessage.HL7DefNum != oldHL7DefMessage.HL7DefNum) {
				if(command!=""){ command+=",";}
				command+="HL7DefNum = "+POut.Long(hL7DefMessage.HL7DefNum)+"";
			}
			if(hL7DefMessage.MessageType != oldHL7DefMessage.MessageType) {
				if(command!=""){ command+=",";}
				command+="MessageType = '"+POut.String(hL7DefMessage.MessageType.ToString())+"'";
			}
			if(hL7DefMessage.EventType != oldHL7DefMessage.EventType) {
				if(command!=""){ command+=",";}
				command+="EventType = '"+POut.String(hL7DefMessage.EventType.ToString())+"'";
			}
			if(hL7DefMessage.InOrOut != oldHL7DefMessage.InOrOut) {
				if(command!=""){ command+=",";}
				command+="InOrOut = "+POut.Int   ((int)hL7DefMessage.InOrOut)+"";
			}
			if(hL7DefMessage.ItemOrder != oldHL7DefMessage.ItemOrder) {
				if(command!=""){ command+=",";}
				command+="ItemOrder = "+POut.Int(hL7DefMessage.ItemOrder)+"";
			}
			if(hL7DefMessage.Note != oldHL7DefMessage.Note) {
				if(command!=""){ command+=",";}
				command+="Note = "+DbHelper.ParamChar+"paramNote";
			}
			if(command==""){
				return;
			}
			if(hL7DefMessage.Note==null) {
				hL7DefMessage.Note="";
			}
			OdSqlParameter paramNote=new OdSqlParameter("paramNote",OdDbType.Text,hL7DefMessage.Note);
			command="UPDATE hl7defmessage SET "+command
				+" WHERE HL7DefMessageNum = "+POut.Long(hL7DefMessage.HL7DefMessageNum);
			Db.NonQ(command,paramNote);
		}
예제 #22
0
		///<summary>Updates one HL7DefMessage in the database.</summary>
		public static void Update(HL7DefMessage hL7DefMessage){
			string command="UPDATE hl7defmessage SET "
				+"HL7DefNum       =  "+POut.Long  (hL7DefMessage.HL7DefNum)+", "
				+"MessageType     = '"+POut.String(hL7DefMessage.MessageType.ToString())+"', "
				+"EventType       = '"+POut.String(hL7DefMessage.EventType.ToString())+"', "
				+"InOrOut         =  "+POut.Int   ((int)hL7DefMessage.InOrOut)+", "
				+"ItemOrder       =  "+POut.Int   (hL7DefMessage.ItemOrder)+", "
				+"Note            =  "+DbHelper.ParamChar+"paramNote "
				+"WHERE HL7DefMessageNum = "+POut.Long(hL7DefMessage.HL7DefMessageNum);
			if(hL7DefMessage.Note==null) {
				hL7DefMessage.Note="";
			}
			OdSqlParameter paramNote=new OdSqlParameter("paramNote",OdDbType.Text,hL7DefMessage.Note);
			Db.NonQ(command,paramNote);
		}
예제 #23
0
        public static HL7Def GetDeepInternal(HL7Def def)
        {
            //ok to pass in null
            if (def == null)           //wasn't in the database
            {
                def                       = new HL7Def();
                def.IsNew                 = true;
                def.Description           = "Centricity";
                def.ModeTx                = ModeTxHL7.File;
                def.IncomingFolder        = "";
                def.OutgoingFolder        = "";
                def.IncomingPort          = "";
                def.OutgoingIpPort        = "";
                def.SftpInSocket          = "";
                def.SftpUsername          = "";
                def.SftpPassword          = "";
                def.FieldSeparator        = "|";
                def.ComponentSeparator    = "^";
                def.SubcomponentSeparator = "&";
                def.RepetitionSeparator   = "~";
                def.EscapeCharacter       = @"\";
                def.IsInternal            = true;
                def.InternalType          = HL7InternalType.Centricity;
                def.InternalTypeVersion   = Assembly.GetAssembly(typeof(Db)).GetName().Version.ToString();
                def.IsEnabled             = false;
                def.Note                  = "";
                def.ShowDemographics      = HL7ShowDemographics.ChangeAndAdd;
                def.ShowAccount           = true;
                def.ShowAppts             = true;
                def.IsQuadAsToothNum      = false;
            }
            def.hl7DefMessages = new List <HL7DefMessage>();
            HL7DefMessage msg = new HL7DefMessage();
            HL7DefSegment seg = new HL7DefSegment();

            #region Outbound Messages
            #region DFT - Detailed Financial Transaction
            //=======================================================================================================================
            //Detail financial transaction (DFT)
            def.AddMessage(msg, MessageTypeHL7.DFT, MessageStructureHL7.DFT_P03, InOutHL7.Outgoing, 2);
            //MSH (Message Header) segment-------------------------------------------------
            msg.AddSegment(seg, 0, SegmentNameHL7.MSH);
            //HL7 documentation says field 1 is Field Separator.  "This field contains the separator between the segment ID and the first real field.  As such it serves as the separator and defines the character to be used as a separator for the rest of the message." (HL7 v2.6 documentation) The separator is usually | (pipes) and is part of field 0, which is the segment ID followed by a |.  Encoding Characters is the first real field, so it will be numbered starting with 1 in our def.
            //MSH.1, Encoding Characters (DataType.ST)
            seg.AddField(1, "separators^~\\&");
            //MSH.2, Sending Application
            seg.AddFieldFixed(2, DataTypeHL7.HD, "OD");
            //MSH.4, Receiving Application
            seg.AddFieldFixed(4, DataTypeHL7.HD, def.Description);
            //MSH.6, Message Date and Time (YYYYMMDDHHMMSS)
            seg.AddField(6, "dateTime.Now");
            //MSH.8, Message Type^Event Type, example DFT^P03
            seg.AddField(8, "messageType");
            //MSH.9, Message Control ID
            seg.AddField(9, "messageControlId");
            //MSH.10, Processing ID (P-production, T-test)
            seg.AddFieldFixed(10, DataTypeHL7.PT, "P");
            //MSH.11, Version ID
            seg.AddFieldFixed(11, DataTypeHL7.VID, "2.3");
            //MSH.16, Application Ack Type (AL=Always, NE=Never, ER=Error/reject conditions only, SU=Successful completion only)
            seg.AddFieldFixed(15, DataTypeHL7.ID, "NE");
            //EVN (Event Type) segment-----------------------------------------------------
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 1, SegmentNameHL7.EVN);
            //EVN.1, Event Type, example P03
            seg.AddField(1, "eventType");
            //EVN.2, Recorded Date/Time
            seg.AddField(2, "dateTime.Now");
            //EVN.3, Event Reason Code
            seg.AddFieldFixed(3, DataTypeHL7.IS, "01");
            //PID (Patient Identification) segment-----------------------------------------
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 2, SegmentNameHL7.PID);
            //PID.1, Sequence Number (1 for DFT's)  "This field contains the number that identifies this transaction.  For the first occurrence of the segment, the sequence number shall be one, for the second occurrence, the sequence number shall be two, etc." (HL7 v2.6 documentation)  We only send 1 PID segment in DFT's so this number will always be 1.
            seg.AddFieldFixed(1, DataTypeHL7.SI, "1");
            //PID.2, Patient ID (External)
            seg.AddField(2, "pat.ChartNumber");
            //PID.3, Patient ID (Internal)
            seg.AddField(3, "pat.PatNum");
            //PV1 (Patient Visit) segment--------------------------------------------------
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 3, SegmentNameHL7.PV1);
            //PV1.1, Set ID - PV1 (1 for DFT's)  See the comment above for the Sequence Number of the PID segment.  Always 1 since we only send one PV1 segment per DFT message.
            seg.AddFieldFixed(1, DataTypeHL7.SI, "1");
            //PV1.2, Patient Class  (E=Emergency, I=Inpatient, O=Outpatient, P=Preadmit, R=Recurring patient, B=Obstetrics, C=Commercial Account, N=Not Applicable, U=Unkown)  We will just send O for outpatient for every DFT message.
            seg.AddFieldFixed(2, DataTypeHL7.IS, "O");
            //todo: ClinicNum?
            //PV1.3, Assigned Patient Location
            //PV1.7, Attending/Primary Care Doctor
            seg.AddField(7, "prov.provIdNameLFM");
            //todo: Referring Dr?
            //PV1.8, Referring Doctor
            //PV1.19, Visit Number
            seg.AddField(19, "apt.AptNum");
            //PV1.44, Admit Date/Time
            seg.AddField(44, "proc.procDateTime");
            //PV1.50, Alternate Visit ID
            //FT1 (Financial Transaction Information) segment------------------------------
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 4, true, true, SegmentNameHL7.FT1);
            //FT1.1, Sequence Number (starts with 1)
            seg.AddField(1, "sequenceNum");
            //FT1.2, Transaction ID
            seg.AddField(2, "proc.ProcNum");
            //FT1.4, Transaction Date (YYYYMMDDHHMMSS)
            seg.AddField(4, "proc.procDateTime");
            //FT1.5, Transaction Posting Date (YYYYMMDDHHMMSS)
            seg.AddField(5, "proc.procDateTime");
            //FT1.6, Transaction Type
            seg.AddFieldFixed(6, DataTypeHL7.IS, "CG");
            //FT1.10, Transaction Quantity
            seg.AddFieldFixed(10, DataTypeHL7.NM, "1.0");
            //FT1.11, Transaction Amount Extended (Total fee to charge for this procedure, independent of transaction quantity)
            seg.AddField(11, "proc.ProcFee");
            //FT1.12, Transaction Amount Unit (Fee for this procedure for each transaction quantity)
            seg.AddField(12, "proc.ProcFee");
            //todo: ClinicNum?
            //FT1.16, Assigned Patient Location
            //FT1.19, Diagnosis Code
            seg.AddField(19, "proc.DiagnosticCode");
            //FT1.21, Ordering Provider
            seg.AddField(21, "prov.provIdNameLFM");
            //FT1.22, Unit Cost (procedure fee)
            seg.AddField(22, "proc.ProcFee");
            //FT1.25, Procedure Code
            seg.AddField(25, "proccode.ProcCode");
            //FT1.26, Modifiers (treatment area)
            seg.AddField(26, "proc.toothSurfRange");
            //DG1 (Diagnosis) segment is optional, skip for now
            //PR1 (Procedures) segment is optional, skip for now
            #endregion DFT - Detailed Financial Transaction
            #endregion Outbound Messages
            return(def);
        }
예제 #24
0
 ///<summary>Inserts one HL7DefMessage into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(HL7DefMessage hL7DefMessage)
 {
     return(InsertNoCache(hL7DefMessage, false));
 }
예제 #25
0
        ///<summary>Updates one HL7DefMessage in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.</summary>
        public static void Update(HL7DefMessage hL7DefMessage, HL7DefMessage oldHL7DefMessage)
        {
            string command = "";

            if (hL7DefMessage.HL7DefNum != oldHL7DefMessage.HL7DefNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "HL7DefNum = " + POut.Long(hL7DefMessage.HL7DefNum) + "";
            }
            if (hL7DefMessage.MessageType != oldHL7DefMessage.MessageType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "MessageType = '" + POut.String(hL7DefMessage.MessageType.ToString()) + "'";
            }
            if (hL7DefMessage.EventType != oldHL7DefMessage.EventType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "EventType = '" + POut.String(hL7DefMessage.EventType.ToString()) + "'";
            }
            if (hL7DefMessage.InOrOut != oldHL7DefMessage.InOrOut)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "InOrOut = " + POut.Int((int)hL7DefMessage.InOrOut) + "";
            }
            if (hL7DefMessage.ItemOrder != oldHL7DefMessage.ItemOrder)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ItemOrder = " + POut.Int(hL7DefMessage.ItemOrder) + "";
            }
            if (hL7DefMessage.Note != oldHL7DefMessage.Note)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Note = " + DbHelper.ParamChar + "paramNote";
            }
            if (command == "")
            {
                return;
            }
            if (hL7DefMessage.Note == null)
            {
                hL7DefMessage.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, hL7DefMessage.Note);

            command = "UPDATE hl7defmessage SET " + command
                      + " WHERE HL7DefMessageNum = " + POut.Long(hL7DefMessage.HL7DefMessageNum);
            Db.NonQ(command, paramNote);
        }
예제 #26
0
        ///<summary>Returns null if there is no HL7Def enabled or if there is no outbound DFT defined for the enabled HL7Def.</summary>
        public static MessageHL7 GenerateDFT(List <Procedure> listProcs, EventTypeHL7 eventType, Patient pat, Patient guar, long aptNum, string pdfDescription, string pdfDataString)
        {
            //In \\SERVERFILES\storage\OPEN DENTAL\Programmers Documents\Standards (X12, ADA, etc)\HL7\Version2.6\V26_CH02_Control_M4_JAN2007.doc
            //On page 28, there is a Message Construction Pseudocode as well as a flowchart which might help.
            MessageHL7 msgHl7 = new MessageHL7(MessageTypeHL7.DFT);
            HL7Def     hl7Def = HL7Defs.GetOneDeepEnabled();

            if (hl7Def == null)
            {
                return(null);
            }
            //find a DFT message in the def
            HL7DefMessage hl7DefMessage = null;

            for (int i = 0; i < hl7Def.hl7DefMessages.Count; i++)
            {
                if (hl7Def.hl7DefMessages[i].MessageType == MessageTypeHL7.DFT && hl7Def.hl7DefMessages[i].InOrOut == InOutHL7.Outgoing)
                {
                    hl7DefMessage = hl7Def.hl7DefMessages[i];
                    //continue;
                    break;
                }
            }
            if (hl7DefMessage == null)           //DFT message type is not defined so do nothing and return
            {
                return(null);
            }
            if (PrefC.GetBool(PrefName.ShowFeaturePatientClone))
            {
                pat = Patients.GetOriginalPatientForClone(pat);
            }
            Provider       prov         = Providers.GetProv(Patients.GetProvNum(pat));
            Appointment    apt          = Appointments.GetOneApt(aptNum);
            List <PatPlan> listPatPlans = PatPlans.Refresh(pat.PatNum);

            for (int i = 0; i < hl7DefMessage.hl7DefSegments.Count; i++)
            {
                int repeatCount = 1;
                if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.FT1)
                {
                    repeatCount = listProcs.Count;
                }
                else if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.IN1)
                {
                    repeatCount = listPatPlans.Count;
                }
                //for example, countRepeat can be zero in the case where we are only sending a PDF of the TP to eCW, and no procs.
                //or the patient does not have any current insplans for IN1 segments
                for (int j = 0; j < repeatCount; j++)           //FT1 is optional and can repeat so add as many FT1's as procs in procList, IN1 is optional and can repeat as well, repeat for the number of patplans in patplanList
                {
                    if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.FT1 && listProcs.Count > j)
                    {
                        prov = Providers.GetProv(listProcs[j].ProvNum);
                    }
                    Procedure proc = null;
                    if (listProcs.Count > j)                   //procList could be an empty list
                    {
                        proc = listProcs[j];
                    }
                    PatPlan patPlanCur = null;
                    InsPlan insPlanCur = null;
                    InsSub  insSubCur  = null;
                    Carrier carrierCur = null;
                    Patient subscriber = null;
                    if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.IN1)
                    {
                        patPlanCur = listPatPlans[j];
                        insSubCur  = InsSubs.GetOne(patPlanCur.InsSubNum);
                        insPlanCur = InsPlans.RefreshOne(insSubCur.PlanNum);
                        carrierCur = Carriers.GetCarrier(insPlanCur.CarrierNum);
                        subscriber = Patients.GetPat(insSubCur.Subscriber);
                    }
                    SegmentHL7 seg = new SegmentHL7(hl7DefMessage.hl7DefSegments[i].SegmentName);
                    seg.SetField(0, hl7DefMessage.hl7DefSegments[i].SegmentName.ToString());
                    for (int f = 0; f < hl7DefMessage.hl7DefSegments[i].hl7DefFields.Count; f++)
                    {
                        string fieldName = hl7DefMessage.hl7DefSegments[i].hl7DefFields[f].FieldName;
                        if (fieldName == "")                       //If fixed text instead of field name just add text to segment
                        {
                            seg.SetField(hl7DefMessage.hl7DefSegments[i].hl7DefFields[f].OrdinalPos, hl7DefMessage.hl7DefSegments[i].hl7DefFields[f].FixedText);
                        }
                        else
                        {
                            string fieldValue = "";
                            if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.IN1)
                            {
                                fieldValue = FieldConstructor.GenerateFieldIN1(hl7Def, fieldName, j + 1, patPlanCur, insSubCur, insPlanCur, carrierCur, listPatPlans.Count, subscriber);
                            }
                            else
                            {
                                fieldValue = FieldConstructor.GenerateField(hl7Def, fieldName, MessageTypeHL7.DFT, pat, prov, proc, guar, apt, j + 1, eventType,
                                                                            pdfDescription, pdfDataString, MessageStructureHL7.DFT_P03, seg.Name);
                            }
                            seg.SetField(hl7DefMessage.hl7DefSegments[i].hl7DefFields[f].OrdinalPos, fieldValue);
                        }
                    }
                    msgHl7.Segments.Add(seg);
                }
            }
            return(msgHl7);
        }
예제 #27
0
        ///<summary>Returns null if there is no HL7Def enabled or if there is no outbound ADT defined for the enabled HL7Def.</summary>
        public static MessageHL7 GenerateADT(Patient pat, Patient guar, EventTypeHL7 eventType)
        {
            HL7Def hl7Def = HL7Defs.GetOneDeepEnabled();

            if (hl7Def == null)
            {
                return(null);
            }
            //find an outbound ADT message in the def
            HL7DefMessage hl7DefMessage = null;

            for (int i = 0; i < hl7Def.hl7DefMessages.Count; i++)
            {
                if (hl7Def.hl7DefMessages[i].MessageType == MessageTypeHL7.ADT && hl7Def.hl7DefMessages[i].InOrOut == InOutHL7.Outgoing)
                {
                    hl7DefMessage = hl7Def.hl7DefMessages[i];
                    //continue;
                    break;
                }
            }
            if (hl7DefMessage == null)           //ADT message type is not defined so do nothing and return
            {
                return(null);
            }
            if (PrefC.GetBool(PrefName.ShowFeaturePatientClone))
            {
                pat = Patients.GetOriginalPatientForClone(pat);
            }
            MessageHL7     messageHL7   = new MessageHL7(MessageTypeHL7.ADT);
            Provider       prov         = Providers.GetProv(Patients.GetProvNum(pat));
            List <PatPlan> listPatPlans = PatPlans.Refresh(pat.PatNum);

            for (int i = 0; i < hl7DefMessage.hl7DefSegments.Count; i++)
            {
                int countRepeat = 1;
                //IN1 segment can repeat, get the number of current insurance plans attached to the patient
                if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.IN1)
                {
                    countRepeat = listPatPlans.Count;
                }
                //countRepeat is usually 1, but for repeatable/optional fields, it may be 0 or greater than 1
                //for example, countRepeat can be zero if the patient does not have any current insplans, in which case no IN1 segments will be included
                for (int j = 0; j < countRepeat; j++)           //IN1 is optional and can repeat so add as many as listPatplans
                {
                    PatPlan patplanCur = null;
                    InsPlan insplanCur = null;
                    InsSub  inssubCur  = null;
                    Carrier carrierCur = null;
                    Patient patSub     = null;
                    if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.IN1)                   //index repeat is guaranteed to be less than listPatplans.Count
                    {
                        patplanCur = listPatPlans[j];
                        inssubCur  = InsSubs.GetOne(patplanCur.InsSubNum);
                        insplanCur = InsPlans.RefreshOne(inssubCur.PlanNum);
                        carrierCur = Carriers.GetCarrier(insplanCur.CarrierNum);
                        if (pat.PatNum == inssubCur.Subscriber)
                        {
                            patSub = pat.Copy();
                        }
                        else
                        {
                            patSub = Patients.GetPat(inssubCur.Subscriber);
                        }
                    }
                    SegmentHL7 seg = new SegmentHL7(hl7DefMessage.hl7DefSegments[i].SegmentName);
                    seg.SetField(0, hl7DefMessage.hl7DefSegments[i].SegmentName.ToString());
                    for (int k = 0; k < hl7DefMessage.hl7DefSegments[i].hl7DefFields.Count; k++)
                    {
                        string fieldName = hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].FieldName;
                        if (fieldName == "")                       //If fixed text instead of field name just add text to segment
                        {
                            seg.SetField(hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].OrdinalPos, hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].FixedText);
                        }
                        else
                        {
                            string fieldValue = "";
                            if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.IN1)
                            {
                                fieldValue = FieldConstructor.GenerateFieldIN1(hl7Def, fieldName, j + 1, patplanCur, inssubCur, insplanCur, carrierCur, listPatPlans.Count, patSub);
                            }
                            else
                            {
                                fieldValue = FieldConstructor.GenerateFieldADT(hl7Def, fieldName, pat, prov, guar, j + 1, eventType, seg.Name);
                            }
                            seg.SetField(hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].OrdinalPos, fieldValue);
                        }
                    }
                    messageHL7.Segments.Add(seg);
                }
            }
            return(messageHL7);
        }
예제 #28
0
파일: MedLabv2_3.cs 프로젝트: mnisl/OD
		public static HL7Def GetDeepInternal(HL7Def def) {
			//ok to pass in null
			if(def==null) {//wasn't in the database
				def=new HL7Def();
				def.IsNew=true;
				def.Description="MedLab HL7 v2.3";
				def.ModeTx=ModeTxHL7.Sftp;
				def.IncomingFolder="";
				def.OutgoingFolder="";
				def.IncomingPort="";
				def.OutgoingIpPort="";
				def.SftpInSocket="";
				def.SftpUsername="";
				def.SftpPassword="";
				def.FieldSeparator="|";
				def.ComponentSeparator="^";
				def.SubcomponentSeparator="&";
				def.RepetitionSeparator="~";
				def.EscapeCharacter=@"\";
				def.IsInternal=true;
				def.InternalType=HL7InternalType.MedLabv2_3;
				def.InternalTypeVersion=Assembly.GetAssembly(typeof(Db)).GetName().Version.ToString();
				def.IsEnabled=false;
				def.Note="";
				def.ShowDemographics=HL7ShowDemographics.ChangeAndAdd;//these last four properties will not be editable for a lab interface type
				def.ShowAccount=true;
				def.ShowAppts=true;
				def.IsQuadAsToothNum=false;
			}
			def.hl7DefMessages=new List<HL7DefMessage>();
			HL7DefMessage msg=new HL7DefMessage();
			HL7DefSegment seg=new HL7DefSegment();
			#region Inbound Messages
				#region ORU - Unsolicited Observation Message
				def.AddMessage(msg,MessageTypeHL7.ORU,MessageStructureHL7.ORU_R01,InOutHL7.Incoming,0);
					#region MSH - Message Header
					msg.AddSegment(seg,0,SegmentNameHL7.MSH);
						//Fields-------------------------------------------------------------------------------------------------------------
						//MSH.2, Sending Application.  To identify the LabCorp Lab System sending the results.
						//Possible values for LabCorp (as of their v10.7 specs): '1100' - LabCorp Lab System, 'DIANON' - DIANON Systems,
						//'ADL' - Acupath Diagnostic Laboratories, 'EGL' - Esoterix Genetic Laboratories.
						//For backward compatibility only: 'CMBP', 'LITHOLINK', 'USLABS'
						seg.AddField(2,"sendingApp");
						//MSH.3, Sending Facility.  Identifies the LabCorp laboratory responsible for the client.
						//It could be a LabCorp assigned 'Responsible Lab Code' representing the responsible laboratory or it could be a CLIA number.
						seg.AddField(3,"sendingFacility");
						//MSH.8, Message Type
						seg.AddField(8,"messageType");
						//MSH.9, Message Control ID
						seg.AddField(9,"messageControlId");
					#endregion MSH - Message Header
					#region PID - Patient Identification
					seg=new HL7DefSegment();
					msg.AddSegment(seg,1,SegmentNameHL7.PID);
						//Fields-------------------------------------------------------------------------------------------------------------
						//PID.2, External Patient ID.  LabCorp defines this as 'client' assigned patient id, just like they do PID.4.
						//This should be the Open Dental patient number, sent in outbound PID.4 and returned in PID.2.
						seg.AddField(2,"pat.PatNum");
						//PID.3, Lab Assigned Patient ID.  LabCorp assigned specimen number.
						seg.AddField(3,"labPatID");
						//PID.4, Alternate Patient ID.  LabCorp defines this as a 'client' assigned patient id, just like they do PID.2.
						//This will be in outbound PID.2, returned in PID.4.
						seg.AddField(4,"altPatID");
						//PID.5, Patient Name
						//This will contain the last, first, and middle names as well as the title
						//Example:  LName^FName^MiddleI
						seg.AddField(5,"pat.nameLFM");
						//PID.7, Date/Time of Birth with Age
						//LabCorp uses this for the birthdate as well as the age in years, months, and days of the patient in the format bday^years^months^days.
						//All age components are left padded with 0's, the years is padded to 3 chars, the months and days are padded to 2 chars
						//Example: 19811213^033^02^19
						seg.AddField(7,"patBirthdateAge");
						//PID.8, Patient Gender
						//We use this field to assist the user in selecting a patient if one is not found when importing the message, but we don't store it
						seg.AddField(8,"pat.Gender");
						//PID.18.1, Patient Account Number.  LabCorp assigned account number.  This field is also used to send the Fasting flag in component 7.
						//Fasting flag values are 'Y', 'N', or blank
						//Example: AccountNum^^^BillCode^ABNFlag^SpecimenStatus^FastingFlag
						seg.AddField(18,"accountNum");
						//PID.19, Patient SSN Number
						//We use this field to assist the user in selecting a patient if one is not found when importing the message, but we don't store it
						seg.AddField(19,"pat.SSN");
					#endregion PID - Patient Identification
					#region NK1 - Next of Kin
					//This segment is for future use only, nothing is currently imported from this segment
					seg=new HL7DefSegment();
					msg.AddSegment(seg,2,false,true,SegmentNameHL7.NK1);
						//Fields-------------------------------------------------------------------------------------------------------------
						//NK1.2, Next of Kin Name
						//Example: LName^FName^Middle
						//seg.AddField(2,"nextOfKinName");
						//NK1.4, Next of Kin Address
						//Example: Address^Address2^City^State^Zip
						//seg.AddField(4,"nextOfKinAddress");
						//NK1.5, Next of Kin Phone
						//seg.AddField(5,"nextOfKinPhone");
						seg.hl7DefFields=new List<HL7DefField>();
					#endregion NK1 - Next of Kin
					#region NTE - Notes and Comments
					seg=new HL7DefSegment();
					msg.AddSegment(seg,3,true,true,SegmentNameHL7.NTE);
						//Fields-------------------------------------------------------------------------------------------------------------
						//NTE.2, Comment Source, ID data type
						//LabCorp supported values: 'L' - Laboratory is the source of comment, 'AC' - Accession Comment,
						//'RC' - Result comment, 'RI' - Normal Comment, 'UK' - Undefined comment type
						//We might pull out the source and prepend it to the note, but we won't explicitly add it to the definition or store it separately
						//NTE.3, Comment Text, FT data type (formatted text)
						//Stored in the medlab.NotePat field
						seg.AddField(3,"patNote");
					#endregion NTE - Notes and Comments
					#region ORC - Common Order
					seg=new HL7DefSegment();
					msg.AddSegment(seg,4,true,false,SegmentNameHL7.ORC);
						//Fields-------------------------------------------------------------------------------------------------------------
						//ORC.2, Unique Foreign Accession or Specimen ID
						//Must match the value in OBR.2 and is the ID value sent on the specimen container and is unique per patient order, not test order.
						//ORC.2.2 is the constant value 'LAB'
						//Example: L2435^LAB
						seg.AddField(2,"specimenID");
						//ORC.3, Filler Accession ID.  The LabCorp assigned specimen number.  These are reused on a yearly basis, but used with the client
						//specific specimen ID in ORC.2, these two numbers should uniquely identify a specimen/order.  ORC.3.2 is the constant value 'LAB'.
						//This should match OBR.3.
						//Example: 08599499950^LAB
						seg.AddField(3,"specimenIDFiller");
						//ORC.12, Ordering Provider, XCN Data Type
						//ProvID^ProvLName^ProvFName^ProvMiddleI^^^^SourceTable
						//This field repeats for every ID available for the provider with the SourceTable component identifying the type of ID in each repetition.
						//SourceTable possible values: 'U' - UPIN, 'P' - Provider Number (Medicaid or Commercial Insurance Provider ID),
						//'N' - NPI Number (Required for Third Party Billing), 'L' - Local (Physician ID)
						//Example: A12345^LNAME^FNAME^M^^^^U~23462^LNAME^FNAME^M^^^^L~0123456789^LNAME^FNAME^M^^^^N~1234567890^LNAME^FNAME^M^^^^P
						seg.AddField(12,"orderingProv");
					#endregion ORC - Common Order
					#region OBR - Observation Request
					seg=new HL7DefSegment();
					msg.AddSegment(seg,5,true,false,SegmentNameHL7.OBR);
						//Fields-------------------------------------------------------------------------------------------------------------
						//OBR.2, Unique Foreign Accession or Specimen ID
						//Must match the value in ORC.2 and is the ID value sent on the specimen container and is unique per patient order, not test order.
						//OBR.2.2 is the constant value 'LAB'.
						//Example: L2435^LAB
						seg.AddField(2,"specimenID");
						//OBR.3, Internal Accession ID.  The LabCorp assigned specimen number.  These are reused on a yearly basis, but used with the client
						//specific specimen ID in OBR.2, these two numbers should uniquely identify a specimen/order.  OBR.3.2 is the constant value 'LAB'.
						//This should match ORC.3.
						//Example: 08599499950^LAB
						seg.AddField(3,"specimenIDFiller");
						//OBR.4, Universal Service Identifier, CWE data type
						//This identifies the observation.  This will be the ID and text description of the test, as well as the LOINC code and description.
						//Example: 006072^RPR^L^20507-0^Reagin Ab^LN
						seg.AddField(4,"obsTestID");
						//OBR.7, Observation/Specimen Collection Date/Time
						//Format for LabCorp: yyyyMMddHHmm
						seg.AddField(7,"dateTimeCollected");
						//OBR.9, Collection/Urine Volume
						seg.AddField(9,"totalVolume");
						//OBR.11, Action Code
						//Used to identify the type of result being returned.  'A' - Add on, 'G' - Reflex, Blank for standard results
						seg.AddField(11,"specimenAction");
						//OBR.13, Relevant Clinical Information.  Used for informational purposes.
						seg.AddField(13,"clinicalInfo");
						//OBR.14, Date/Time of Specimen Receipt in Lab.
						//LabCorp format: yyyMMddHHmm
						seg.AddField(14,"dateTimeEntered");
						//OBR.16, Ordering Provider.
						//ProvID^ProvLName^ProvFName^ProvMiddleI^^^^SourceTable
						//This field repeats for every ID available for the provider with the SourceTable component identifying the type of ID in each repetition.
						//SourceTable possible values: 'U' - UPIN, 'P' - Provider Number (Medicaid or Commercial Insurance Provider ID),
						//'N' - NPI Number (Required for Third Party Billing), 'L' - Local (Physician ID)
						//Example: A12345^LNAME^FNAME^M^^^^U~23462^LNAME^FNAME^M^^^^L~0123456789^LNAME^FNAME^M^^^^N~1234567890^LNAME^FNAME^M^^^^P
						seg.AddField(16,"orderingProv");
						//OBR.18, Alternate Specimen ID.
						seg.AddField(18,"specimenIDAlt");
						//OBR.22, Date/Time Observation Reported.
						//LabCorp format: yyyyMMddHHmm
						seg.AddField(22,"dateTimeReported");
						//OBR.24, Producer's Section ID, used by LabCorp to identify the facility responsible for performing the testing.
						//This will be the footnote ID of the ZPS segment and will be used to attach a MedLab object to a MedLabFacility object.
						seg.AddField(24,"facilityID");
						//OBR.25, Order Result Status.
						//LabCorp values: 'F' - Final, 'P' - Preliminary, 'X' - Cancelled, 'C' - Corrected
						seg.AddField(25,"resultStatus");
						//OBR.26, Link to Parent Result.
						//If this is a reflex result, the value from the OBX.3.1 field of the parent result will be here.
						seg.AddField(26,"parentObsID");
						//OBR.29, Link to Parent Order.
						//If this is a reflex test, the value from the OBR.4.1 field of the parent test will be here.
						seg.AddField(29,"parentObsTestID");
					#endregion OBR - Observation Request
					#region NTE - Notes and Comments
					seg=new HL7DefSegment();
					msg.AddSegment(seg,6,true,true,SegmentNameHL7.NTE);
						//Fields-------------------------------------------------------------------------------------------------------------
						//NTE.2, Comment Source, ID data type
						//LabCorp supported values: 'L' - Laboratory is the source of comment, 'AC' - Accession Comment,
						//'RC' - Result comment, 'RI' - Normal Comment, 'UK' - Undefined comment type
						//We might pull out the source and prepend it to the note, but we won't explicitly add it to the definition or store it separately
						//NTE.3, Comment Text, FT data type (formatted text)
						//Stored in the medlab.NoteLab field
						seg.AddField(3,"labNote");
					#endregion NTE - Notes and Comments
					#region OBX - Observation/Result
					seg=new HL7DefSegment();
					msg.AddSegment(seg,7,true,false,SegmentNameHL7.OBX);
						//Fields-------------------------------------------------------------------------------------------------------------
						//OBX.2, Value Type.  This field is not stored explicitly, but it is used to determine the value type of the observation.
						//If this field is 'TX' for text, the value will be >21 chars and will be sent in the attached NTEs.
						seg.AddField(2,"obsValueType");
						//OBX.3, Observation ID.  This field has the same structure as the OBR.4.
						//ID^Text^CodeSystem^AltID^AltIDText^AltIDCodeSystem, the AltID is the LOINC code so the AltIDCodeSystem will be 'LN'
						//Example: 006072^RPR^L^20507-0^Reagin Ab^LN
						seg.AddField(3,"obsID");
						//OBX.4, Observation Sub ID.  This field is used to aid in the identification of results with the same observation ID (OBX.3) within a
						//given OBR.  If OBX.5.3 is 'ORM' (organism) this field will link a result to an organism, whether this is for organism #1, organism #2,
						//or organism #3.
						seg.AddField(4,"obsIDSub");
						//OBX.5, Observation Value.  ObsValue^TypeOfData^DataSubtype^Encoding^Data.  LabCorp report will display OBX.5.1 as the result.
						//For value >21 chars in length: OBX.2 will be 'TX' for text, OBX.5 will be NULL (empty field), and the value will be in attached NTEs.
						//"TNP" will be reported for Test Not Performed.
						seg.AddField(5,"obsValue");
						//OBX.6, Units.
						//Identifier^Text^CodeSystem.  Id is units of measure abbreviation, text is full text version of units, coding system is 'L' (local id).
						seg.AddField(6,"obsUnits");
						//OBX.7, Reference Range.
						seg.AddField(7,"obsRefRange");
						//OBX.8, Abnormal Flags.  For values see enum OpenDentBusiness.AbnormalFlag
						seg.AddField(8,"obsAbnormalFlag");
						//OBX.11, Observation Result Status.
						//LabCorp values: 'F' - Final, 'P' - Preliminary, 'X' - Cancelled, 'C' - Corrected, 'I' - Incomplete
						seg.AddField(11,"resultStatus");
						//OBX.14, Date/Time of Observation.
						//LabCorp format yyyyMMddHHmm
						seg.AddField(14,"dateTimeObs");
						//OBX.15, Producer's ID.
						//For LabCorp this is used to report the facility responsible for performing the testing.  This will hold the lab ID that will reference
						//a ZPS segment with the lab name, address, and director details.  Used to link a MedLabResult object to a MedLabFacility object.
						seg.AddField(15,"facilityID");
					#endregion OBX - Observation/Result
					#region ZEF - Encapsulated Data Format
					seg=new HL7DefSegment();
					msg.AddSegment(seg,8,true,true,SegmentNameHL7.ZEF);
						//Fields-------------------------------------------------------------------------------------------------------------
						//ZEF.1, Sequence Number, 1 through 9999
						seg.AddField(1,"sequenceNum");
						//ZEF.2, Embedded File.
						//Base64 embedded file, sent in 50k blocks and will be concatenated together to and converted back into
						seg.AddField(2,"base64File");
					#endregion ZEF - Encapsulated Data Format
					#region NTE - Notes and Comments
					seg=new HL7DefSegment();
					msg.AddSegment(seg,9,true,true,SegmentNameHL7.NTE);
						//Fields-------------------------------------------------------------------------------------------------------------
						//NTE.2, Comment Source, ID data type
						//LabCorp supported values: 'L' - Laboratory is the source of comment, 'AC' - Accession Comment,
						//'RC' - Result comment, 'RI' - Normal Comment, 'UK' - Undefined comment type
						//We might pull out the source and prepend it to the note, but we won't explicitly add it to the definition or store it separately
						//NTE.3, Comment Text, FT data type (formatted text)
						//Stored in the medlabresult.Note field
						seg.AddField(3,"obsNote");
					#endregion NTE - Notes and Comments
					#region SPM - Specimen
					seg=new HL7DefSegment();
					msg.AddSegment(seg,10,true,true,SegmentNameHL7.SPM);
						//Fields-------------------------------------------------------------------------------------------------------------
						//SPM.2, Specimen ID.
						//Unique ID of the specimen as sent on the specimen container.  Same as the value in ORC.2.
						seg.AddField(2,"specimenID");
						//SPM.4, Specimen Type
						//SPM.8, Specimen Source Site
						//SPM.4, Specimen Source Site Modifier
						//SPM.14, Specimen Description.  Text field used to send additional information about the specimen
						seg.AddField(14,"specimenDescript");
						//SPM.17, Date/Time Specimen Collected
						seg.AddField(17,"dateTimeSpecimen");
					#endregion SPM - Specimen
					#region ZPS - Place of Service
					seg=new HL7DefSegment();
					msg.AddSegment(seg,11,true,false,SegmentNameHL7.ZPS);
						//Fields-------------------------------------------------------------------------------------------------------------
						//ZPS.2, Facility Mnemonic.  Footnote ID for the lab facility used to reference this segment from OBX.15.
						seg.AddField(2,"facilityID");
						//ZPS.3, Facility Name.
						seg.AddField(3,"facilityName");
						//ZPS.4, Facility Address.
						//Address^^City^State^Zip
						seg.AddField(4,"facilityAddress");
						//ZPS.5, Facility Phone.  (LabCorp document says numberic characters only, so we can assume no dashes or parentheses.)
						seg.AddField(5,"facilityPhone");
						//ZPS.7, Facility Director.
						//Title^LName^FName^MiddleI
						seg.AddField(7,"facilityDirector");
					#endregion ZPS - Place of Service
				#endregion ORU - Unsolicited Observation Message
			#endregion Inbound Messages
			#region Outbound Messages
				//Results only interface for now, so no outbound messages yet
				//In the future, we will implement the orders portion of the interface and have outbound ORM messages
			#endregion Outbound Messages
			return def;
		}
예제 #29
0
		///<summary>Returns the segment definion based on the name supplied, and only if it follows the previous segment name supplied.  If prevSegName
		///is Unknown, we'll return the first match by segName only.  If a segment can appear in a message definition more than once and in multiple
		///locations, send in the preceding segment name.  For example, the NTE seg can follow the PID (or optional NK1), OBR, and OBX (or optional ZEF)
		///segments. Returns the definition that immediately follows the previous segment name given. If the segment def follows an optional
		///segment, the prevSegName could be any preceding segment up to and including the first preceding required segment. We'll decrement backward
		///through the segments looking for a predecessor with the prevSegName until we get to the first required (IsOptional=false) segment.</summary>
		public static HL7DefSegment GetSegDefByName(HL7DefMessage msgDef,SegmentNameHL7 segName,SegmentNameHL7 prevSegName) {
			HL7DefSegment segDef=null;
			for(int i=0;i<msgDef.hl7DefSegments.Count;i++) {//start with the second segment in the def since the first segment won't have a predecessor
				if(msgDef.hl7DefSegments[i].SegmentName!=segName) {
					continue;
				}
				//if prevSegName is Unkown, we don't care about the preceding segment so this segment must appear at most once in the message
				if(prevSegName==SegmentNameHL7.Unknown) {
					segDef=msgDef.hl7DefSegments[i];
					break;
				}
				//move backward in the list of segments looking for the nearest preceding, required segment
				for(int j=1;j<i+1;j++) {
					if(msgDef.hl7DefSegments[i-j].SegmentName==prevSegName) {
						segDef=msgDef.hl7DefSegments[i];
						break;
					}
					//if the nearest preceding, required (IsOptional=false) segment isn't prevSegName, this is not the repetition we're looking for, continue
					if(!msgDef.hl7DefSegments[i-j].IsOptional) {
						break;
					}
				}
				if(segDef!=null) {
					break;
				}
			}
			return segDef;
		}
예제 #30
0
        ///<summary>Returns null if there is no HL7Def enabled or if there is no outbound SIU defined for the enabled HL7Def.</summary>
        public static MessageHL7 GenerateSIU(Patient pat, Patient guar, EventTypeHL7 eventType, Appointment apt)
        {
            HL7Def hl7Def = HL7Defs.GetOneDeepEnabled();

            if (hl7Def == null)
            {
                return(null);
            }
            //find an outbound SIU message in the def
            HL7DefMessage hl7DefMessage = null;

            for (int i = 0; i < hl7Def.hl7DefMessages.Count; i++)
            {
                if (hl7Def.hl7DefMessages[i].MessageType == MessageTypeHL7.SIU && hl7Def.hl7DefMessages[i].InOrOut == InOutHL7.Outgoing)
                {
                    hl7DefMessage = hl7Def.hl7DefMessages[i];
                    //continue;
                    break;
                }
            }
            if (hl7DefMessage == null)           //SIU message type is not defined so do nothing and return
            {
                return(null);
            }
            if (apt == null)           //SIU messages must have an appointment
            {
                return(null);
            }
            if (PrefC.GetBool(PrefName.ShowFeaturePatientClone))
            {
                pat = Patients.GetOriginalPatientForClone(pat);
            }
            MessageHL7 messageHL7 = new MessageHL7(MessageTypeHL7.SIU);
            Provider   prov       = Providers.GetProv(apt.ProvNum);

            for (int i = 0; i < hl7DefMessage.hl7DefSegments.Count; i++)
            {
                int repeatCount = 1;
                //AIP segment can repeat, once for the dentist on the appt and once for the hygienist
                if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.AIP && apt.ProvHyg > 0)
                {
                    repeatCount = 2;
                }
                for (int j = 0; j < repeatCount; j++)           //AIP will be repeated if there is a dentist and a hygienist on the appt
                {
                    if (j > 0)
                    {
                        prov = Providers.GetProv(apt.ProvHyg);
                        if (prov == null)
                        {
                            break;                            //shouldn't happen, apt.ProvHyg would have to be set to an invalid ProvNum on the appt, just in case
                        }
                    }
                    SegmentHL7 seg = new SegmentHL7(hl7DefMessage.hl7DefSegments[i].SegmentName);
                    seg.SetField(0, hl7DefMessage.hl7DefSegments[i].SegmentName.ToString());
                    for (int k = 0; k < hl7DefMessage.hl7DefSegments[i].hl7DefFields.Count; k++)
                    {
                        string fieldName = hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].FieldName;
                        if (fieldName == "")                       //If fixed text instead of field name just add text to segment
                        {
                            seg.SetField(hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].OrdinalPos, hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].FixedText);
                        }
                        else
                        {
                            string fieldValue = FieldConstructor.GenerateFieldSIU(hl7Def, fieldName, pat, prov, guar, apt, j + 1, eventType, seg.Name);
                            seg.SetField(hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].OrdinalPos, fieldValue);
                        }
                    }
                    messageHL7.Segments.Add(seg);
                }
            }
            return(messageHL7);
        }
예제 #31
0
파일: InternalHL7v2_6.cs 프로젝트: mnisl/OD
		public static HL7Def GetDeepInternal(HL7Def def) {
			//ok to pass in null
			if(def==null) {//wasn't in the database
				def=new HL7Def();
				def.IsNew=true;
				def.Description="HL7 version 2.6";
				def.ModeTx=ModeTxHL7.File;
				def.IncomingFolder="";
				def.OutgoingFolder="";
				def.IncomingPort="";
				def.OutgoingIpPort="";
				def.SftpInSocket="";
				def.SftpUsername="";
				def.SftpPassword="";
				def.FieldSeparator="|";
				def.ComponentSeparator="^";
				def.SubcomponentSeparator="&";
				def.RepetitionSeparator="~";
				def.EscapeCharacter=@"\";
				def.IsInternal=true;
				def.InternalType=HL7InternalType.HL7v2_6;
				def.InternalTypeVersion=Assembly.GetAssembly(typeof(Db)).GetName().Version.ToString();
				def.IsEnabled=false;
				def.Note="";
				def.ShowDemographics=HL7ShowDemographics.ChangeAndAdd;
				def.ShowAccount=true;
				def.ShowAppts=true;
				def.IsQuadAsToothNum=false;
			}
			def.hl7DefMessages=new List<HL7DefMessage>();
			HL7DefMessage msg=new HL7DefMessage();
			HL7DefSegment seg=new HL7DefSegment();
			#region Inbound Messages
				#region ACK - General Acknowledgment
				def.AddMessage(msg,MessageTypeHL7.ACK,MessageStructureHL7.ADT_A01,InOutHL7.Incoming,0);
					#region MSH - Message Header
					msg.AddSegment(seg,0,SegmentNameHL7.MSH);
						//Fields-------------------------------------------------------------------------------------------------------------
						//MSH.8, Message Type
						seg.AddField(8,"messageType");
						//MSH.9, Message Control ID
						seg.AddField(9,"messageControlId");
					#endregion MSH - Message Header
					#region MSA - Message Acknowledgment
					seg=new HL7DefSegment();
					msg.AddSegment(seg,1,SegmentNameHL7.MSA);
						//Fields-------------------------------------------------------------------------------------------------------------
						//MSA.1, Acknowledgment Code
						seg.AddField(1,"ackCode");
						//MSA.2, Message Control ID
						seg.AddField(2,"messageControlId");
					#endregion MSA - Message Acknowledgment
				#endregion ACK - General Acknowledgment
				#region ADT - Patient Demographics (Admits, Discharges, and Transfers)
				msg=new HL7DefMessage();
				def.AddMessage(msg,MessageTypeHL7.ADT,MessageStructureHL7.ADT_A01,InOutHL7.Incoming,1);
					#region MSH - Message Header
					seg=new HL7DefSegment();
					msg.AddSegment(seg,0,SegmentNameHL7.MSH);
					//HL7 documentation says field 1 is Field Separator.  "This field contains the separator between the segment ID and the first real field.  As such it serves as the separator and defines the character to be used as a separator for the rest of the message." (HL7 v2.6 documentation) The separator is usually | (pipes) and is part of field 0, which is the segment ID followed by a |.  Encoding Characters is the first real field, so it will be numbered starting with 1 in our def.
						//Fields-------------------------------------------------------------------------------------------------------------
						//MSH.8, Message Type
						seg.AddField(8,"messageType");
						//MSH.9, Message Control ID
						seg.AddField(9,"messageControlId");
					#endregion MSH - Message Header
					#region PID - Patient Identification
					seg=new HL7DefSegment();
					msg.AddSegment(seg,2,SegmentNameHL7.PID);//order 2 since the EVN segment is order 1.  We don't process anything out of the EVN segment, so only defined for outgoing messages
						//Fields-------------------------------------------------------------------------------------------------------------
						//PID.2, Patient ID (retained for backward compatibility only).  Defined as 'external' ID but we've always used it as our PatNum for eCW.
						//The standard will be to continue to use PID.2 as the PatNum for incoming messages and attempt to locate the patient if this field is populated.
						seg.AddField(2,"pat.PatNum");
						//PID.3, Patient Identifier List, contains a list of identifiers separated by the repetition character (usually ~)
						//We will use the OID root for the office, stored in the table oidinternal with IDType Patient.
						//The Patient ID data type CX contains the Assigning Authority data type HD - Heirarchic Designator.
						//Within the Assigning Authority, sub-component 2 is the Universal ID that needs to have the OID root for the office.
						//Sub-component 3 of the Assigning Authority, Universal ID Type, will be 'HL7' for our PatNums since our root is registered with HL7.
						//The Patient ID CX type will also have the Identifier Type Code of 'PI', Patient internal identifier.
						//Once located, PatNum is the first component
						//Example: |1234^3^M11^&2.16.840.1.113883.3.4337.1486.6566.2&HL7^PI~7684^8^M11^&Other.Software.OID&OIDType^PI|
						seg.AddField(3,"patientIds");
						//PID.4, Alternate Patient ID, (retained for backward compatibility only).
						//We've used PID.4 for ChartNumber in the past and will continue to use this as a backup method for locating a patient if the ID in PID.2 is not present
						//or if no patient can be found using that value.
						seg.AddField(4,"pat.ChartNumber");
						//PID.5, Patient Name
						//This will contain the last, first, and middle names as well as the title
						//Example:  LName^FName^MiddleI^^Title
						seg.AddField(5,"pat.nameLFM");
						//PID.7, Date/Time of Birth
						seg.AddField(7,"pat.birthdateTime");
						//PID.8, Administrative Sex
						seg.AddField(8,"pat.Gender");
						//PID.10, Race
						//The old race parsing will still work and matches to an exact string to find the race.  The string can be the only component of the field or the first of many.
						//The old parse translates the string to the PatRaceOld enum, then reconciles them into one or more of the PatRace enums, then adds/deletes entries in the patientrace table.
						//The old race strings are: "American Indian Or Alaska Native", "Asian", "Native Hawaiian or Other Pacific", "Black or African American", "White", "Hispanic", "Other Race"
						//The new race parse accepts the CWE - Coded with Exceptions data type with 9 fields.
						//The 9 fields are: Code^Description^CodeSystem^AlternateCode^AltDescript^AltCodeSystem^CodeSystemVersionID^AltCodeSystemVersionID^OriginalText
						//We will make sure CodeSystem, PID.10.2, is "CDCREC" and use Code, PID.10.0, to find the correct race from the new PatRace enum and update the patientrace table.
						//The race field can repeat, so any number of races can be sent and will add to the patientrace table.
						seg.AddField(10,"pat.Race");
						//PID.11, Patient Address
						//PID.11.20, comment, is used to populate patient.AddrNote with '\.br\' signaling a line break. (the '\' is the default escape character, may be different and parses correctly)
						//Example: ...^^Emergency Contact: Mom Test\.br\Mother\.br\(503)555-1234
						seg.AddField(11,"pat.addressCityStateZip");
						//PID.13, Phone Number - Home, XTN data type (can repeat)
						//This field will also contain the patient's email address as a repetition as well as the WirelessPhone as a repetition
						//PRN stands for Primary Residence Number, equipment type: PH is Telephone, CP is Cell Phone, Internet is Internet Address (email)
						//Example: ^PRN^PH^^^503^3635432~^PRN^Internet^[email protected]~^PRN^CP^^^503^6895555
						seg.AddField(13,"pat.HmPhone");
						//PID.14, Phone Number - Business, XTN data type (can repeat)
						//We will send just one repetition, the WkPhone, but we will adhere to the data type
						//WPN=Work Number
						//Example: ^WPN^PH^^^503^3635432
						seg.AddField(14,"pat.WkPhone");
						//PID.16, Marital Status
						seg.AddField(16,"pat.Position");
						//PID.19, SSN - Patient
						seg.AddField(19,"pat.SSN");
					#endregion PID - Patient Identification
					#region PV1 - Patient Visit
					seg=new HL7DefSegment();
					msg.AddSegment(seg,3,SegmentNameHL7.PV1);
						//Fields-------------------------------------------------------------------------------------------------------------
						//PV1.2, Patient Class, IS data type (coded value for user-defined tables)
						//If this field is populated, it will set the patient.GradeLevel if the field can be converted to an integer between 1 and 12
						seg.AddField(2,"pat.GradeLevel");
						//PV1.3, Assigned Patient Location, PL - Person Location Data Type: Point of Care^Room^^Facility^^Person Location Type
						//Facility is a HD data type, so Namespace&ID&IDType.  We will just use &PracticeTitle with no namespace or IDType.
						//Example: ClinicDescript^OpName^^&PracticeTitle^^C  (C for clinic)
						//Used to set patient.ClinicNum if the location description matches clinic.Description
						seg.AddField(3,"pat.location");
						//PV1.7, Attending/Primary Care Doctor, XCN data type, ProviderId^LastName^FirstName^MI
						//In the PV1 segment, the primary provider will be set for the patient
						//The ProviderID component will hold the office's OID for a provider+"."+ProvNum if they send us a ProviderID that we have previously sent them
						//If the first component is not the provider root, we will assume this is an external ID and store it in the oidexternals linked to our internal ProvNum
						seg.AddField(7,"prov.provIdNameLFM");
						//PV1.11, Temporary Location, PL - Person Location data type: PointOfCare^^^^^Person Location Type
						//Using the location type field to identify this field as a "Site (or Grade School)", we will attempt to match the description to a site.Description in the db
						//If exact match is found, set the patient.SiteNum=site.SiteNum
						//Example: |West Salem Elementary^^^^^S| ('S' for site)
						seg.AddField(11,"pat.site");
						//PV1.18, Patient Type, 0 - Unknown, 1 - NoProblems, 2 - NeedsCare, 3 - Urgent
						//Stored in the patient.Urgency field for treatment urgnecy, used in public health screening
						seg.AddField(18,"pat.Urgency");
					#endregion PV1 - Patient Visit
					#region GT1 - Guarantor
					seg=new HL7DefSegment();
					msg.AddSegment(seg,4,false,true,SegmentNameHL7.GT1);
						//Fields-------------------------------------------------------------------------------------------------------------
						//GT1.2, Guarantor Number
						//This field is repeatable and will be handled the same as the patientIdList in the PID segment, so it may contain multiple CX data type identifiers that point to a patient.
						seg.AddField(2,"guarIdList");
						//GT1.3, Guarantor Name
						//This will contain the last, first, and middle names as well as the title
						//Example:  LName^FName^MiddleI^^Title
						seg.AddField(3,"guar.nameLFM");
						//GT1.5, Guarantor Address
						//GT1.5.20, comment, is used to populate patient.AddrNote with '\.br\' signaling a line break.
						//The '\' is the default escape character, may be different in the incoming message and parses correctly
						//Example: ...^^Emergency Contact: Mom Test\.br\Mother\.br\(503)555-1234
						seg.AddField(5,"guar.addressCityStateZip");
						//GT1.6, Guarantor Phone Number - Home
						seg.AddField(6,"guar.HmPhone");
						//GT1.7, Guarantor Phone Number - Business
						seg.AddField(7,"guar.WkPhone");
						//GT1.8, Guarantor Date/Time of Birth
						seg.AddField(8,"guar.birthdateTime");
						//GT1.9, Guarantor Administrative Sex
						seg.AddField(9,"guar.Gender");
						//GT1.12, Guarantor SSN
						seg.AddField(12,"guar.SSN");
					#endregion GT1 - Guarantor
					#region OBX - Observation/Result
					seg=new HL7DefSegment();
					msg.AddSegment(seg,5,true,true,SegmentNameHL7.OBX);
						//Fields-------------------------------------------------------------------------------------------------------------
						//OBX.3, Observation ID, ID^Descript^CodeSystem
						//For adding current medications, the value will be a CWE (OBX.2 should hold the value type 'CWE') with RXNORM as the code system and the RxCui for the ID
						//RxNorm Code^^RXNORM, the Description is ignored
						seg.AddField(3,"medicationRxNorm");
					#endregion OBX - Observation/Result
					#region AL1 - Allergy Information
					seg=new HL7DefSegment();
					msg.AddSegment(seg,6,true,true,SegmentNameHL7.AL1);
						//Fields-------------------------------------------------------------------------------------------------------------
						//AL1.2, Allergen Type Code, DA - Drug allergy, FA - Food allergy, MA - Miscellaneous Allergy
						//For now, we only allow DA for drug allergies
						seg.AddField(2,"allergenType");
						//AL1.3, Allergen Code, currently only RxNorm codes are supported
						//Supplied in CWE data type format with 9 components, of which we only need 2 code^^codeSystem^^^^^^
						//codeSystem must be RxNorm, code must match an existing allergydef.MedicationNum
						seg.AddField(3,"allergenRxNorm");
					#endregion AL1 - Allergy Information
					#region PR1 - Procedures
					seg=new HL7DefSegment();
					msg.AddSegment(seg,7,true,true,SegmentNameHL7.PR1);
						//Fields-------------------------------------------------------------------------------------------------------------
						//PR1.3, Procedure Code, CNE data type
						//ProcCode^descript (ignored)^CD2^^^^2014^^Layman Term (ignored)
						//Example: D1351^^CD2^^^^2014
						seg.AddField(3,"proccode.ProcCode");
						//PR1.5, Procedure Date/Time, DTM
						seg.AddField(5,"proc.procDateTime");
						//PR1.16, Procedure Code Modifier, CNE data type
						//This will hold the treatment area for the procedure (tooth,tooth/surf,quad,sextant,arch,tooth range).
						//If this is empty or blank, default will be mouth and the proccode sent must have a treatment area of mouth or the code will not be inserted.
						//We will validate the information conforms to the tooth numbering system in use by the office and will handle international toothnums.
						//If it is for a tooth surface, it will be 2 subcomponents, toothnum&surface(s)
						//Quad, sextant, and arch will be in subcomponent 2 with the first subcomponent blank
						//Tooth range will be comma-delimited list of tooth numbers in subcomponent 1
						//Examples: 1,2,3,4 or 12&MODL or &UL or &2 (sextant 2)
						seg.AddField(16,"proc.toothSurfRange");
						//PR1.19, Procedure Identifier, EI data type
						//Id^^UniversalId
						//They should send us a unique ID for this procedure with their UniversalId root for a procedure object.
						//If we get this data, we will store our procedurelog.ProcNum linked to the external ID and root in the oidexternals table.
						//This will be useful in preventing multiple copies of the same procedure from being inserted due to duplicate messages.
						//However, if they do not specify a unique ID and root, or if it is not in our oidexternals table linked to our ProcNum with type of Procedure, we will insert a new one.
						//This field could be blank and we will insert a new procedure every time, regardless of whether or not there is already a procedure with this code for this patient.
						seg.AddField(19,"proc.uniqueId");
					#endregion PR1 - Procedures
				#endregion ADT - Patient Demographics (Admits, Discharges, and Transfers)
				#region PPR - Patient Problem
				msg=new HL7DefMessage();
				def.AddMessage(msg,MessageTypeHL7.PPR,MessageStructureHL7.PPR_PC1,InOutHL7.Incoming,2);
					#region MSH - Message Header
					seg=new HL7DefSegment();
					msg.AddSegment(seg,0,SegmentNameHL7.MSH);
						//Fields-------------------------------------------------------------------------------------------------------------
						//MSH.8, Message Type
						seg.AddField(8,"messageType");
						//MSH.9, Message Control ID
						seg.AddField(9,"messageControlId");
					#endregion MSH - Message Header
					#region PID - Patient Identification
					seg=new HL7DefSegment();
					msg.AddSegment(seg,1,SegmentNameHL7.PID);//order 1 since PPR's don't have an EVN segment
						//Fields-------------------------------------------------------------------------------------------------------------
						//PID.2, Patient ID (retained for backward compatibility only).  Defined as 'external' ID but we've always used it as our PatNum for eCW.
						//The standard will be to continue to use PID.2 as the PatNum for incoming messages and attempt to locate the patient if this field is populated.
						seg.AddField(2,"pat.PatNum");
						//PID.3, Patient Identifier List, contains a list of identifiers separated by the repetition character (usually ~)
						//We will use the OID root for the office, stored in the table oidinternal with IDType Patient.
						//The Patient ID data type CX contains the Assigning Authority data type HD - Heirarchic Designator.
						//Within the Assigning Authority, sub-component 2 is the Universal ID that needs to have the OID root for the office.
						//Sub-component 3 of the Assigning Authority, Universal ID Type, will be 'HL7' for our PatNums since our root is registered with HL7.
						//The Patient ID CX type will also have the Identifier Type Code of 'PI', Patient internal identifier.
						//Once located, PatNum is the first component
						//Example: |1234^3^M11^&2.16.840.1.113883.3.4337.1486.6566.2&HL7^PI~7684^8^M11^&Other.Software.OID&OIDType^PI|
						seg.AddField(3,"patientIds");
						//PID.4, Alternate Patient ID, (retained for backward compatibility only).
						//We've used PID.4 for ChartNumber in the past and will continue to use this as a backup method for locating a patient if the ID in PID.2 is not present
						//or if no patient can be found using that value.
						seg.AddField(4,"pat.ChartNumber");
						//PID.5, Patient Name
						//This will contain the last, first, and middle names as well as the title
						//Example:  LName^FName^MiddleI^^Title
						seg.AddField(5,"pat.nameLFM");
						//PID.7, Date/Time of Birth
						seg.AddField(7,"pat.birthdateTime");
						//PID.8, Administrative Sex
						seg.AddField(8,"pat.Gender");
						//PID.10, Race
						//The old race parsing will still work and matches to an exact string to find the race.  The string can be the only component of the field or the first of many.
						//The old parse translates the string to the PatRaceOld enum, then reconciles them into one or more of the PatRace enums, then adds/deletes entries in the patientrace table.
						//The old race strings are: "American Indian Or Alaska Native", "Asian", "Native Hawaiian or Other Pacific", "Black or African American", "White", "Hispanic", "Other Race"
						//The new race parse accepts the CWE - Coded with Exceptions data type with 9 fields.
						//The 9 fields are: Code^Description^CodeSystem^AlternateCode^AltDescript^AltCodeSystem^CodeSystemVersionID^AltCodeSystemVersionID^OriginalText
						//We will make sure CodeSystem, PID.10.2, is "CDCREC" and use Code, PID.10.0, to find the correct race from the new PatRace enum and update the patientrace table.
						//The race field can repeat, so any number of races can be sent and will add to the patientrace table.
						seg.AddField(10,"pat.Race");
						//PID.11, Patient Address
						//PID.11.20, comment, is used to populate patient.AddrNote with '\.br\' signaling a line break. (the '\' is the default escape character, may be different and parses correctly)
						//Example: ...^^Emergency Contact: Mom Test\.br\Mother\.br\(503)555-1234
						seg.AddField(11,"pat.addressCityStateZip");
						//PID.13, Phone Number - Home, XTN data type (can repeat)
						//This field will also contain the patient's email address as a repetition as well as the WirelessPhone as a repetition
						//PRN stands for Primary Residence Number, equipment type: PH is Telephone, CP is Cell Phone, Internet is Internet Address (email)
						//Example: ^PRN^PH^^^503^3635432~^PRN^Internet^[email protected]~^PRN^CP^^^503^6895555
						seg.AddField(13,"pat.HmPhone");
						//PID.14, Phone Number - Business, XTN data type (can repeat)
						//We will send just one repetition, the WkPhone, but we will adhere to the data type
						//WPN=Work Number
						//Example: ^WPN^PH^^^503^3635432
						seg.AddField(14,"pat.WkPhone");
						//PID.16, Marital Status
						seg.AddField(16,"pat.Position");
						//PID.19, SSN - Patient
						seg.AddField(19,"pat.SSN");
					#endregion  PID - Patient Identification
					#region PV1 - Patient Visit
					seg=new HL7DefSegment();
					msg.AddSegment(seg,2,false,true,SegmentNameHL7.PV1);
						//Fields-------------------------------------------------------------------------------------------------------------
						//PV1.2, Patient Class, IS data type (coded value for user-defined tables)
						//If this field is populated, it will set the patient.GradeLevel if the field can be converted to an integer between 1 and 12
						seg.AddField(2,"pat.GradeLevel");
						//PV1.3, Assigned Patient Location, PL - Person Location Data Type: Point of Care^Room^^Facility^^Person Location Type
						//Facility is a HD data type, so Namespace&ID&IDType.  We will just use &PracticeTitle with no namespace or IDType.
						//Example: ClinicDescript^OpName^^&PracticeTitle^^C  (C for clinic)
						//Used to set patient.ClinicNum if the location description matches clinic.Description
						seg.AddField(3,"pat.location");
						//PV1.7, Attending/Primary Care Doctor, XCN data type, ProviderId^LastName^FirstName^MI^^Abbr
						//In the PV1 segment, the primary provider will be set for the patient if provider is found by ProviderId or by name and abbr
						//A new provider will not be inserted if not found, the default practice provider will be used
						seg.AddField(7,"prov.provIdNameLFM");
						//PV1.11, Temporary Location, PL - Person Location data type: PointOfCare^^^^^Person Location Type
						//Using the location type field to identify this field as a "Site (or Grade School)", we will attempt to match the description to a site.Description in the db
						//If exact match is found, set the patient.SiteNum=site.SiteNum
						//Example: |West Salem Elementary^^^^^S| ('S' for site)
						seg.AddField(11,"pat.site");
						//PV1.18, Patient Type, 0 - Unknown, 1 - NoProblems, 2 - NeedsCare, 3 - Urgent
						//Stored in the patient.Urgency field for treatment urgnecy, used in public health screening
						seg.AddField(18,"pat.Urgency");
					#endregion PV1 - Patient Visit
					#region PRB - Problem Detail
					seg=new HL7DefSegment();
					msg.AddSegment(seg,3,true,false,SegmentNameHL7.PRB);
						//Fields-------------------------------------------------------------------------------------------------------------
						//PRB.1, Action Code, AD-ADD,CO-Correct,DE-Delete,LI-Link,UC-Unchanged,UN-Unlink,UP-Update.  AD/UP are currently supported and are treated the same
						seg.AddField(1,"problemAction");
						//PRB.2, Action Date/Time, DTM data type
						seg.AddField(2,"dateTime.Now");
						//PRB.3, Problem ID, CWE data type
						//Currently only SNOMEDCT codes are supported, code^descript^codeSystem (descript is not required and is ignored)
						//Example: 1234^^SNM
						seg.AddField(3,"problemCode");
						//PRB.4, Problem Instance ID, EI data type
						//Uniquely identifies this instance of a problem
						//If we were to send this, it would be the oidinternal root for problems (root+".5") with the disease.DiseaseNum as the ID
						//We expect the sending software to send an ID with an assigning authority root ID and we will link that to our disease.DiseaseNum in the oidexternals table
						//Example: |76543^^OtherSoftwareRoot.ProblemOID|
						seg.AddField(4,"problemUniqueId");
						//PRB.7, Problem Established Date/Time
						seg.AddField(7,"problemStartDate");
						//PRB.9, Actual Problem Resolution Date/Time
						seg.AddField(9,"problemStopDate");
					#endregion PRB - Problem Detail
				#endregion PPR - Patient Problem
				#region SRM - Schedule Request
				//The only incoming SRM event types we will accept by default will be S03 - Request Appointment Modification or S04 - Request Appointment Cancellation (for now)
				//The message must refer to an appointment already existing in OD by AptNum
				//The S03 message will only be allowed to modify a limited amount of information about the appointment
				//The S04 message will set the appointment status to Broken (enum 5)
				msg=new HL7DefMessage();
				def.AddMessage(msg,MessageTypeHL7.SRM,MessageStructureHL7.SRM_S01,InOutHL7.Incoming,3);
					#region MSH - Message Header
					seg=new HL7DefSegment();
					msg.AddSegment(seg,0,SegmentNameHL7.MSH);
						//Fields-------------------------------------------------------------------------------------------------------------
						//MSH.8, Message Type
						seg.AddField(8,"messageType");
						//MSH.9, Message Control ID
						seg.AddField(9,"messageControlId");
					#endregion MSH - Message Header
					#region ARQ - Appointment Request Information
					seg=new HL7DefSegment();
					msg.AddSegment(seg,1,SegmentNameHL7.ARQ);
						//Fields-------------------------------------------------------------------------------------------------------------
						//ARQ.1, Placer Appointment ID.  This will be the other software appointment ID.
						//We will store this in the oidexternals table linked to our AptNum.
						//The first component will be the external application appointment ID (stored as IDExternal)
						//The third component will be the external application assigning authority root ID (stored as RootExternal)
						//Example: |12345^^OtherSoftware.Root^|
						seg.AddField(1,"apt.externalAptID");
						//ARQ.2, Filler Appointment ID, EI data type, EntityID^NamespaceID^UniversalID^UniversalIDType
						//We will expect the first component to be our AptNum
						//We could check to make sure the UniversalID is our OID for an appointment, but for this incoming segment we won't enforce it for now and just accept the first component as AptNum
						//Example: 1234^^2.16.840.1.113883.3.4337.1486.6566.6^HL7
						seg.AddField(2,"apt.AptNum");
					#endregion ARQ - Appointment Request Information
					#region NTE - Notes and Comments
					seg=new HL7DefSegment();
					msg.AddSegment(seg,2,true,true,SegmentNameHL7.NTE);
						//Fields-------------------------------------------------------------------------------------------------------------
						//NTE.3, Comment, FT data type (formatted text)
						//We will append this comment to appointment.Note if the Note for this appointment does not already contain the exact text received
						//This is formatted text, so we will allow new lines.
						//As in the address note field (see PID.11) we will accept '\.br\' (where the '\' is the defined escape char, \ by default) to signal a new line.
						seg.AddField(3,"apt.Note");
					#endregion NTE - Notes and Comments
					#region PID - Patient Identification
					seg=new HL7DefSegment();
					msg.AddSegment(seg,3,SegmentNameHL7.PID);
						//Fields-------------------------------------------------------------------------------------------------------------
						//PID.2, Patient ID (retained for backward compatibility only).  Defined as 'external' ID but we've always used it as our PatNum for eCW.
						//The standard will be to continue to use PID.2 as the PatNum for incoming messages and attempt to locate the patient if this field is populated.
						seg.AddField(2,"pat.PatNum");
						//PID.3, Patient Identifier List, contains a list of identifiers separated by the repetition character (usually ~)
						//We will use the OID root for the office, stored in the table oidinternal with IDType Patient.
						//The Patient ID data type CX contains the Assigning Authority data type HD - Heirarchic Designator.
						//Within the Assigning Authority, sub-component 2 is the Universal ID that needs to have the OID root for the office.
						//Sub-component 3 of the Assigning Authority, Universal ID Type, will be 'HL7' for our PatNums since our root is registered with HL7.
						//The Patient ID CX type will also have the Identifier Type Code of 'PI', Patient internal identifier.
						//Once located, PatNum is the first component
						//Example: |1234^3^M11^&2.16.840.1.113883.3.4337.1486.6566.2&HL7^PI~7684^8^M11^&Other.Software.OID&OIDType^PI|
						seg.AddField(3,"patientIds");
						//PID.4, Alternate Patient ID, (retained for backward compatibility only).
						//We've used PID.4 for ChartNumber in the past and will continue to use this as a backup method for locating a patient if the ID in PID.2 is not present
						//or if no patient can be found using that value.
						seg.AddField(4,"pat.ChartNumber");
						//PID.5, Patient Name
						//This will contain the last, first, and middle names as well as the title
						//Example:  LName^FName^MiddleI^^Title
						seg.AddField(5,"pat.nameLFM");
						//PID.7, Date/Time of Birth
						seg.AddField(7,"pat.birthdateTime");
						//PID.8, Administrative Sex
						seg.AddField(8,"pat.Gender");
						//PID.10, Race
						//The old race parsing will still work and matches to an exact string to find the race.  The string can be the only component of the field or the first of many.
						//The old parse translates the string to the PatRaceOld enum, then reconciles them into one or more of the PatRace enums, then adds/deletes entries in the patientrace table.
						//The old race strings are: "American Indian Or Alaska Native", "Asian", "Native Hawaiian or Other Pacific", "Black or African American", "White", "Hispanic", "Other Race"
						//The new race parse accepts the CWE - Coded with Exceptions data type with 9 fields.
						//The 9 fields are: Code^Description^CodeSystem^AlternateCode^AltDescript^AltCodeSystem^CodeSystemVersionID^AltCodeSystemVersionID^OriginalText
						//We will make sure CodeSystem, PID.10.2, is "CDCREC" and use Code, PID.10.0, to find the correct race from the new PatRace enum and update the patientrace table.
						//The race field can repeat, so any number of races can be sent and will add to the patientrace table.
						seg.AddField(10,"pat.Race");
						//PID.11, Patient Address
						//PID.11.20, comment, is used to populate patient.AddrNote with '\.br\' signaling a line break. (the '\' is the default escape character, may be different and parses correctly)
						//Example: ...^^Emergency Contact: Mom Test\.br\Mother\.br\(503)555-1234
						seg.AddField(11,"pat.addressCityStateZip");
						//PID.13, Phone Number - Home, XTN data type (can repeat)
						//This field will also contain the patient's email address as a repetition as well as the WirelessPhone as a repetition
						//PRN stands for Primary Residence Number, equipment type: PH is Telephone, CP is Cell Phone, Internet is Internet Address (email)
						//Example: ^PRN^PH^^^503^3635432~^PRN^Internet^[email protected]~^PRN^CP^^^503^6895555
						seg.AddField(13,"pat.HmPhone");
						//PID.14, Phone Number - Business, XTN data type (can repeat)
						//We will send just one repetition, the WkPhone, but we will adhere to the data type
						//WPN=Work Number
						//Example: ^WPN^PH^^^503^3635432
						seg.AddField(14,"pat.WkPhone");
						//PID.16, Marital Status
						seg.AddField(16,"pat.Position");
						//PID.19, SSN - Patient
						seg.AddField(19,"pat.SSN");
					#endregion PID - Patient Identification
					#region PV1 - Patient Visit
					seg=new HL7DefSegment();
					msg.AddSegment(seg,4,false,true,SegmentNameHL7.PV1);
						//Fields-------------------------------------------------------------------------------------------------------------
						//PV1.2, Patient Class, IS data type (coded value for user-defined tables)
						//If this field is populated, it will set the patient.GradeLevel if the field can be converted to an integer between 1 and 12
						seg.AddField(2,"pat.GradeLevel");
						//PV1.3, Assigned Patient Location, PL - Person Location Data Type: Point of Care^Room^^Facility^^Person Location Type
						//Facility is a HD data type, so Namespace&ID&IDType.  We will just use &PracticeTitle with no namespace or IDType.
						//Example: ClinicDescript^OpName^^&PracticeTitle^^C  (C for clinic)
						//Used to set patient.ClinicNum if the location description matches clinic.Description
						seg.AddField(3,"pat.location");
						//PV1.7, Attending/Primary Care Doctor, XCN data type, ProviderId^LastName^FirstName^MI
						//In the PV1 segment, the primary provider will be set for the patient and the appointment
						//If there is an AIL or AIG segment, the appointment.ProvNum will be set to the provider referenced in that segment.
						seg.AddField(7,"prov.provIdNameLFM");
						//PV1.11, Temporary Location, PL - Person Location data type: PointOfCare^^^^^Person Location Type
						//Using the location type field to identify this field as a "Site (or Grade School)", we will attempt to match the description to a site.Description in the db
						//If exact match is found, set the patient.SiteNum=site.SiteNum
						//Example: |West Salem Elementary^^^^^S| ('S' for site)
						seg.AddField(11,"pat.site");
						//PV1.18, Patient Type, 0 - Unknown, 1 - NoProblems, 2 - NeedsCare, 3 - Urgent
						//Stored in the patient.Urgency field for treatment urgnecy, used in public health screening
						seg.AddField(18,"pat.Urgency");
					#endregion PV1 - Patient Visit
					#region AIG - Appointment Information - General Resource
					//This segment is for setting the provider(s) on the appointment and setting the confirmation status
					//It is repeatable so that the user can send one to set the dentist and one to set the hygienist on the appt
					seg=new HL7DefSegment();
					msg.AddSegment(seg,5,true,true,SegmentNameHL7.AIG);
						//Fields-------------------------------------------------------------------------------------------------------------
						//AIG.3, Resource ID, CWE data type
						//If this is included in the AIG segment for a general resource, we will try to find the provider using the resource ID as the OD ProvNum.
						//If not found by ProvNum, we will try to find the provider using the second component - Text, which should be populated with 'LName, FName',
						//combined with the 4th component - Alternate Identifier, which should be populated with the provider.Abbr.
						//Only if LName, FName, and Abbr all match will we use that provider.
						//When the provider is identified in an AIG or AIP segment, it is used to set the provider on the appointment, not the patient's primary provider.
						//For setting a patient's primary provider, the PV1 segment is used.
						//Example: |1234^Abbott, Sarah^^DrAbbott|
						seg.AddField(3,"prov.provIdName");
						//AIG.4, Resource Type, CWE data type
						//Accepted values are 'd' or 'D' for dentist and 'h' or 'H' for hygienist
						//If included, we will set either the dentist or the hygienist on the appt.
						//If not included, the provider will assumed to refer to the dentist
						seg.AddField(4,"prov.provType");
						//AIG.14, Filler Status Code, CWE data type
						//We will use this to set the confirmation status of the appointment
						//We will use the second component (text) and attempt to match exactly the ItemName (confirm Name) or ItemValue (confirm Abbreviation) from their definition table
						//If there is a match, we will update the confirmation status
						//Example: |^Appointment Confirmed|
						seg.AddField(14,"apt.confirmStatus");
					#endregion AIG - Appointment Information - General Resource
					#region AIL - Appointment Information - Location Resource
					//This segment is used to set the clinic on the appointment.
					//This may differ from the patient's assigned clinic, only the appointment.ClinicNum will be set from this segment.
					//This is not repeatable as we only have one clinic value to assign for the location resource
					seg=new HL7DefSegment();
					msg.AddSegment(seg,6,false,true,SegmentNameHL7.AIL);
						//Fields-------------------------------------------------------------------------------------------------------------
						//AIL.3, Location Resource ID, PL data type: Point of Care^Room^^Facility^^Person Location Type
						//Facility is a HD data type, so Namespace&ID&IDType.  We will just use &PracticeTitle with no namespace or IDType.
						//Example: ClinicDescript^OpName^^&PracticeTitle^^C  (C for clinic)
						//Room-Operatory (not set from inbound messages), Facility-Practice (not set from inbound messages), Building-Clinic (used to set apt.ClinicNum)
						//Used to set the appointment.ClinicNum if this is included in the message
						seg.AddField(3,"apt.location");
						//AIL.12, Filler Status Code, CWE data type
						//We will use this to set the confirmation status of the appointment
						//We will use the second component (text) and attempt to match exactly the ItemName (confirm Name) or ItemValue (confirm Abbreviation) from their definition table
						//If there is a match, we will update the confirmation status
						//Example: |^Appointment Confirmed|
						seg.AddField(12,"apt.confirmStatus");
					#endregion AIL - Appointment Information - Location Resource
					#region AIP - Appointment Information - Personnel Resource
					//This segment is used to set the dentist and/or hygienist on an appointment
					//This may differ from the patient's primary provider and it could cause an appointment to be in an operatory with a provider not assigned to that operatory
					seg=new HL7DefSegment();
					msg.AddSegment(seg,7,true,true,SegmentNameHL7.AIP);
						//Fields-------------------------------------------------------------------------------------------------------------
						//AIP.3, Personnel Resource ID, XCN data type
						//ProviderId^LastName^FirstName^MI^Suffix^Prefix
						//According to the HL7 standards, we are free to use the components as needed to identify the provider
						//We will use ProviderID as the OD ProvNum, and if not found in the db we will use LName, FName and the 'Prefix' component as the Abbr
						//Used to set the appointment.ProvNum or appointment.ProvHyg if this is included in the message
						//Field AIP.4 will determine whether it is the dentist or hygienist for the appt
						//This field is repeatable, but if they want to set both the dentist and the hygienist for the same appointment
						//they would have to repeat the whole segment with different provTypes in field 4
						//Example: |1234^Abbott^Sarah^L^DMD^DrAbbott|
						seg.AddField(3,"prov.provIdNameLFM");
						//AIP.4, Resource Type, CWE data type
						//Accepted values are 'd' or 'D' for dentist and 'h' or 'H' for hygienist
						seg.AddField(4,"prov.provType");
						//AIP.12, Filler Status Code, CWE data type
						//We will use this to set the confirmation status of the appointment
						//We will use the second component (text) and attempt to match exactly the ItemName (confirm Name) or ItemValue (confirm Abbreviation) from their definition table
						//If there is a match, we will update the confirmation status
						//Example: |^Appointment Confirmed|
						seg.AddField(12,"apt.confirmStatus");
					#endregion AIP - Appointment Information - Personnel Resource
				#endregion SRM - Schedule Request
			#endregion Inbound Messages
			#region Outbound Messages
				#region ACK - General Acknowledgment
				msg=new HL7DefMessage();
				def.AddMessage(msg,MessageTypeHL7.ACK,MessageStructureHL7.ADT_A01,InOutHL7.Outgoing,4);
					#region MSH - Message Header
					seg=new HL7DefSegment();
					msg.AddSegment(seg,0,SegmentNameHL7.MSH);
						//Fields-------------------------------------------------------------------------------------------------------------
						//MSH.1, Encoding Characters (DataType.ST)
						seg.AddField(1,"separators^~\\&");
						//MSH.2, Sending Application, HD data type, Namespace ID^Universal ID^Universal ID Type
						//We originally sent 'OD' in this field, but this is a HD data type, so should consist of three components
						//We will send the Open Dental HL7 root assigned to the office and stored in the oidinternal table with the IDType of Root
						//The recommeded value for this field in the table is ^2.16.840.1.113883.3.4337.1486.CustomerPatNum^HL7.
						//If the oidinternal row with IDType=Root does not have an IDRoot assigned, we will revert to sending 'OD'
						seg.AddField(2,"sendingApp");
						//MSH.3, Sending Facility, not used
						//MSH.4, Receiving Application
						//This field will have to be a fixed text field and would have to be modified in a custom definition
						//if they want the outbound messages to have a specific receiving application identifier
						seg.AddField(4,"0361",DataTypeHL7.HD,"","NamespaceID^UniversalID^UniversalIDType");
						//MSH.5, Receiving Facility, not used
						//MSH.6, Message Date and Time (YYYYMMDDHHMMSS)
						seg.AddField(6,"dateTime.Now");
						//MSH.8, Message Type, MSG data type
						//This segment should contain MessageType^EventType^MessageStructure, example SRR^S04^SRR_S04
						seg.AddField(8,"messageType");
						//MSH.9, Message Control ID
						//A GUID that uniquely identifies this message
						seg.AddField(9,"messageControlId");
						//MSH.10, Processing ID, PT data type, Processing ID^Processing Mode
						//Processing mode is optional and not included, we will use P for production (P-Production, T-Training, D-Debugging)
						seg.AddField(10,"0103",DataTypeHL7.PT,"","P");
						//MSH.11, Version ID, VID data type, Version ID^Internationalization Code^International Version ID
						//All components are optional, we will only send Version ID, which is currently 2.6
						seg.AddField(11,"0104",DataTypeHL7.VID,"","2.6");
						//MSH.15, Application Ack Type (AL=Always, NE=Never, ER=Error/reject conditions only, SU=Successful completion only)
						//This is for enhanced acknowledgment mode, which we do not currently support, but we will send our mode just in case
						//With field MSH.15, Accept Ack Type, not present it will default to NE
						//Field MSH.15 set to AL means we will require an ack for every message that is sent, meaning it was processed successfully by the receiving application
						//But MSH.15 not present or null means we do not require a separate accept ACK message, just the accept and validate response meaning the message was accepted and processed
						seg.AddField(15,"0155",DataTypeHL7.ID,"","AL");
					#endregion MSH - Message Header
					#region MSA - Message Acknowledgment
					seg=new HL7DefSegment();
					msg.AddSegment(seg,1,SegmentNameHL7.MSA);
						//Fields-------------------------------------------------------------------------------------------------------------
						//MSA.1, Acknowledgment Code
						seg.AddField(1,"ackCode");
						//MSA.2, Message Control ID
						seg.AddField(2,"messageControlId");
					#endregion MSA - Message Acknowledgment
				#endregion ACK - General Acknowledgment
				#region ADT - Patient Demographics (Admits, Discharges, and Transfers)
				//Outbound ADT messages will be triggered when specific data is changed in OD, but not if the data change is due to an inbound HL7 message.
				//ADT's created when:
				//1. Pressing OK from FormPatientEdit
				//2. Pressing OK from FormPatientAddAll
				//3. Pressing the Set Guarantor button (ContrFamily)
				//4. Pressing the Move button (ContrFamily) to move a patient to a different family
				//5. Retrieving web forms in FormWebForms if a form is for/creates a new patient
				//If the Synch Clone feature is enabled, we would not want the clone to exist in the other software, so we would want to make sure we were not sending ADT's for clones.
				msg=new HL7DefMessage();
				def.AddMessage(msg,MessageTypeHL7.ADT,MessageStructureHL7.ADT_A01,InOutHL7.Outgoing,5);
					#region MSH - Message Header
					seg=new HL7DefSegment();
					msg.AddSegment(seg,0,SegmentNameHL7.MSH);
						//Fields-------------------------------------------------------------------------------------------------------------
						//MSH.1, Encoding Characters (DataType.ST)
						seg.AddField(1,"separators^~\\&");
						//MSH.2, Sending Application, HD data type, Namespace ID^Universal ID^Universal ID Type
						//We originally sent 'OD' in this field, but this is a HD data type, so should consist of three components
						//We will send the Open Dental HL7 root assigned to the office and stored in the oidinternal table with the IDType of Root
						//The recommeded value for this field in the table is ^2.16.840.1.113883.3.4337.1486.CustomerPatNum^HL7.
						//If the oidinternal row with IDType=Root does not have an IDRoot assigned, we will revert to sending 'OD'
						seg.AddField(2,"sendingApp");
						//MSH.3, Sending Facility, not used
						//MSH.4, Receiving Application
						//This field will have to be a fixed text field and would have to be modified in a custom definition
						//if they want the outbound messages to have a specific receiving application identifier
						seg.AddField(4,"0361",DataTypeHL7.HD,"","NamespaceID^UniversalID^UniversalIDType");
						//MSH.5, Receiving Facility, not used
						//MSH.6, Message Date and Time (YYYYMMDDHHMMSS)
						seg.AddField(6,"dateTime.Now");
						//MSH.8, Message Type, MSG data type
						//This segment should contain MessageType^EventType^MessageStructure, example ADT^A04^ADT_A04
						seg.AddField(8,"messageType");
						//MSH.9, Message Control ID
						//A GUID that uniquely identifies this message
						seg.AddField(9,"messageControlId");
						//MSH.10, Processing ID, PT data type, Processing ID^Processing Mode
						//Processing mode is optional and not included, we will use P for production (P-Production, T-Training, D-Debugging)
						seg.AddField(10,"0103",DataTypeHL7.PT,"","P");
						//MSH.11, Version ID, VID data type, Version ID^Internationalization Code^International Version ID
						//All components are optional, we will only send Version ID, which is currently 2.6
						seg.AddField(11,"0104",DataTypeHL7.VID,"","2.6");
						//MSH.15, Application Ack Type (AL=Always, NE=Never, ER=Error/reject conditions only, SU=Successful completion only)
						//This is for enhanced acknowledgment mode, which we do not currently support, but we will send our mode just in case
						//With field MSH.15, Accept Ack Type, not present it will default to NE
						//Field MSH.15 set to AL means we will require an ack for every message that is sent, meaning it was processed successfully by the receiving application
						//But MSH.15 not present or null means we do not require a separate accept ACK message, just the accept and validate response meaning the message was accepted and processed
						seg.AddField(15,"0155",DataTypeHL7.ID,"","AL");
					#endregion MSH - Message Header
					#region EVN - Event Type
					seg=new HL7DefSegment();
					msg.AddSegment(seg,1,SegmentNameHL7.EVN);
						//Fields-------------------------------------------------------------------------------------------------------------
						//EVN.1, Event Type, example P03
						//Retained for backward compatibility only, we will not add this field by default
						//EVN.2, Recorded Date/Time
						seg.AddField(2,"dateTime.Now");
						//EVN.4, Event Reason Code (01 - Patient request; 02 - Physician/health practitioner order;03 - Census Management;O - Other;U - Unknown)
						seg.AddField(4,"0062",DataTypeHL7.IS,"","01");
					#endregion EVN - Event Type
					#region PID - Patient Identification
					seg=new HL7DefSegment();
					msg.AddSegment(seg,2,SegmentNameHL7.PID);
						//Fields-------------------------------------------------------------------------------------------------------------
						//PID.1, Set ID, SI data type
						//"This field contains the number that identifies this transaction.  For the first occurrence of the segment, the sequence number shall be one" (HL7 v2.6 documentation)
						//We only send 1 PID segment in ADT's so this number will always be 1.
						seg.AddFieldFixed(1,DataTypeHL7.SI,"1");
						//PID.2, Patient ID (retained for backward compatibility only).  Defined as 'external' ID, we've always sent the ChartNumber in this field as the eCW patient ID
						//The standard will be to continue to use PID.2 for sending the ChartNumber, which was set from PID.4 of an incoming message.  This could be the other software patient ID.
						seg.AddField(2,"pat.ChartNumber");
						//PID.3, Patient Identifier List, contains a list of identifiers separated by the repetition character (usually ~)
						//PatientID^IDCheckDigit^CheckDigitScheme^AssigningAuthority^IDTypeCode
						//Assigning Authority is a HD data type and is composed of 3 subcomponents, NamespaceID&UniversalID&UniversalIDType
						//Sub-component 2, UniversalID, we will use the OID root for a Patient object stored in the oidinternal table
						//If retrieved from OD it will be 2.16.840.1.113883.3.4337.1486.CustomerNumber.2
						//Sub-component 3, Universal ID Type, will be 'HL7' since our root is registered with HL7.
						//The IDTypeCode will be 'PI', Patient internal identifier.
						//We will also get all of the identifiers in the oidexternals table for the patient and create repetitions for each external ID using the IDExternal and RootExternal
						//Example: |1234^3^M11^&2.16.840.1.113883.3.4337.1486.6566.2&HL7^PI~7684^8^M11^&Other.Software.OID&^PI|
						seg.AddField(3,"patientIds");
						//PID.4, Alternate Patient ID, (retained for backward compatibility only).
						//We've used PID.4 for sending the OD PatNum in the past and will continue to send this in PID.4
						seg.AddField(4,"pat.PatNum");
						//PID.5, Patient Name
						seg.AddField(5,"pat.nameLFM");
						//PID.7, Date/Time of Birth
						seg.AddField(7,"pat.birthdateTime");
						//PID.8, Administrative Sex
						seg.AddField(8,"pat.Gender");
						//PID.10, Race, CWE - Coded with Exceptions data type
						//This data type is composed of 9 fields, Code^Description^CodeSystem^AlternateCode^AltDescript^AltCodeSystem^CodeSystemVersionID^AltCodeSystemVersionID^OriginalText
						//We will send Code^Description^CodeSystem^^^^CodeSystemVersionID
						//The race field can repeat, so any number of races can be sent and will come from the patientrace table.
						//Example: 2106-3^White^CDCREC^^^^1~2186-5^NotHispanic^CDCREC^^^^1
						seg.AddField(10,"pat.Race");
						//PID.11, Patient Address
						//PID.11.20, comment, will come from the patient.AddrNote column and each new line character will be replaced with '\.br\' where the '\' is the defined escape char
						//Example: 123 Main St^Apt 1^Dallas^OR^97338^^^^^^^^^^^^^^^Emergency Contact: Mom Test1\.br\Mother\.br\(503)623-3072
						seg.AddField(11,"pat.addressCityStateZip");
						//PID.13, Phone Number - Home, XTN data type (can repeat)
						//This field will also contain the patient's email address as a repetition as well as the WirelessPhone as a repetition
						//PRN stands for Primary Residence Number, equipment type: PH is Telephone, CP is Cell Phone, Internet is Internet Address (email)
						//Example: ^PRN^PH^^^503^3635432~^PRN^Internet^[email protected]~^PRN^CP^^^503^6895555
						seg.AddField(13,"pat.HmPhone");
						//PID.14, Phone Number - Business, XTN data type (can repeat)
						//We will send just one repetition, the WkPhone, but we will adhere to the data type
						//WPN=Work Number
						//Example: ^WPN^PH^^^503^3635432
						seg.AddField(14,"pat.WkPhone");
						//PID.16, Marital Status
						//S-Single, M-Married, W-Widowed, D-Divorced
						seg.AddField(16,"pat.Position");
						//PID.19, SSN - Patient
						seg.AddField(19,"pat.SSN");
					#endregion PID - Patient Identification
					#region PV1 - Patient Visit
					seg=new HL7DefSegment();
					msg.AddSegment(seg,3,SegmentNameHL7.PV1);
						//Fields-------------------------------------------------------------------------------------------------------------
						//PV1.1, Set ID - PV1
						//See the comment above for the Sequence Number of the PID segment.  Always 1 since we only send one PV1 segment per ADT message.
						seg.AddFieldFixed(1,DataTypeHL7.SI,"1");
						//PV1.2, Patient Class, IS data type (coded value for user-defined tables)
						//Suggested values E=Emergency, I=Inpatient, O=Outpatient, P=Preadmit, R=Recurring patient, B=Obstetrics, C=Commercial Account, N=Not Applicable, U=Unkown
						//We will defualt to send 'O' for outpatient for outbound messages, but for incoming we will use this field for pat.GradeLevel if it's an integer from 1-12
						seg.AddField(2,"0004",DataTypeHL7.IS,"","O");
						//PV1.3, Assigned Patient Location, PL - Person Location Data Type: Point of Care^Room^^Facility^^Person Location Type
						//Facility is a HD data type, so Namespace&ID&IDType.  We will just use &PracticeTitle with no namespace or IDType.
						//Example: ClinicDescript^OpName^^&PracticeTitle^^C  (C for clinic)
						seg.AddField(3,"pat.location");
						//PV1.7, Attending/Primary Care Doctor, ProviderId^LastName^FirstName^MI
						seg.AddField(7,"0010",DataTypeHL7.XCN,"prov.provIdNameLFM","");
						//PV1.11, Temporary Location, PL - Person Location data type: PointOfCare^^^^^Person Location Type
						//Filled with the "Site (or Grade School)" value in the database, using 'S' to designate the location type site and the site.Description value
						//If no site assigned in OD, this will be blank as it is optional
						//Example: |West Salem Elementary^^^^^S| ('S' for site)
						seg.AddField(11,"pat.site");
						//PV1.18, Patient Type, IS data type (coded value for user-defined tables)
						//We will send one of the following values retrieved from the patient.Urgency field for treatment urgency: 0 - Unknown, 1 - NoProblems, 2 - NeedsCare, 3 - Urgent
						seg.AddField(18,"pat.Urgency");
						//PV1.19, Visit Number
						//Outbound ADT messages will not have an appointment number, no appointment selected
						//seg.AddField(19,"apt.AptNum");
						//PV1.44, Admit Date/Time
						//Outbound ADT messages will not have a procedure or appt to get the date/time from
						//seg.AddField(44,"proc.procDateTime");
					#endregion PV1 - Patient Visit
					#region IN1 - Insurance
					seg=new HL7DefSegment();
					msg.AddSegment(seg,4,true,true,SegmentNameHL7.IN1);
						//Fields-------------------------------------------------------------------------------------------------------------
						//IN1.1, Set ID (starts with 1)
						//This will be 1 for primary ins and increment for additional repetitions for secondary ins etc.
						seg.AddField(1,"sequenceNum");
						//IN1.2, Insurance Plan ID, CWE data type
						//We do not have unique ID's for insurance plans.
						//We have created an oidinternal ID for insplan, root+.7, and will use this with the insplan.PlanNum to uniquely identify an insplan.
						//Example: 2.16.840.1.113883.3.4337.1486.6566.7.1234
						seg.AddField(2,"insplan.planNum");
						//IN1.3, Insurance Company ID, CX data type
						seg.AddField(3,"carrier.ElectID");
						//IN1.4, Insurance Company Name, XON data type
						seg.AddField(4,"carrier.CarrierName");
						//IN1.5, Insurance Company Address, XAD data type
						//carrier.Address^Address2^City^State^Zip
						seg.AddField(5,"carrier.addressCityStateZip");
						//IN1.7, Insurance Company Phone Number, XTN data type
						//Example: ^WPN^PH^^^503^3635432
						seg.AddField(7,"carrier.Phone");
						//IN1.8, Group Number, ST data type
						seg.AddField(8,"insplan.GroupNum");
						//IN1.9, Group Name, XON data type
						seg.AddField(9,"insplan.GroupName");
						//IN1.11, Insured's Group Employer Name, XON data type
						//insplan.EmployerNum to employer.EmpName
						seg.AddField(11,"insplan.empName");
						//IN1.12, Plan Effective Date, DT data type
						seg.AddField(12,"inssub.DateEffective");
						//IN1.13, Plan Expiration Date, DT data type
						seg.AddField(13,"inssub.DateTerm");
						//IN1.15, Plan Type, IS data type
						//insplan.PlanType, Category Percentage, PPO Percentage, Medicaid or Flat Copay, Capitation
						seg.AddField(15,"insplan.PlanType");
						//IN1.16, Name of Insured, XPN data type
						//insplan.InsSubNum->inssub.Subscriber->patient name
						seg.AddField(16,"inssub.subscriberName");
						//IN1.17, Insured's Relationship to Patient, CWE data type
						//SEL-Self, SPO-Spouse, DOM-LifePartner, CHD-Child (PAR-Parent), EME-Employee (EMR-Employer)
						//DEP-HandicapDep (GRD-Guardian), DEP-Dependent, OTH-SignifOther (OTH-Other), OTH-InjuredPlantiff
						//We store relationship to subscriber and they want subscriber's relationship to patient, therefore
						//Relat.Child will return "PAR" for Parent, Relat.Employee will return "EMR" for Employer, and Relat.HandicapDep and Relat.Dependent will return "GRD" for Guardian
						seg.AddField(17,"patplan.subRelationToPat");
						//IN1.18, Insured's Date of Birth, DTM data type
						seg.AddField(18,"inssub.subBirthdate");
						//IN1.19, Insured's Address, XAD data type
						seg.AddField(19,"inssub.subAddrCityStateZip");
						//IN1.20, Assignment of Benefits, IS data type
						//inssub.AssignBen 1-Y, 0-N
						seg.AddField(20,"inssub.AssignBen");
						//IN1.21, Coordination of Benefits, IS data type
						//CO-Coordination, IN-Independent.  Will be CO if more than one patplan
						seg.AddField(21,"insplan.cob");
						//IN1.22, Coordination of Benefits Priority, ST data type
						//1-Primary, 2-Secondary, 3,4,5...
						seg.AddField(22,"patplan.Ordinal");
						//IN1.27, Release of Information Code, IS data type
						//inssub.ReleaseInfo, 1-Y, 2-N
						seg.AddField(27,"inssub.ReleaseInfo");
						//IN1.36, Policy Number, ST data type
						//patplan.PatID, if blank then inssub.SubscriberID
						seg.AddField(36,"patplan.policyNum");
						//IN1.47, Coverage Type, IS data type
						//D-Dental, M-Medical using insplan.IsMedical flag
						seg.AddField(47,"insplan.coverageType");
						//IN1.49, Insured's ID Number, CX data type
						seg.AddField(49,"inssub.SubscriberID");
					#endregion IN1 - Insurance
				#endregion ADT - Patient Demographics (Admits, Discharges, and Transfers)
				#region DFT - Detailed Financial Transaction
				//Outbound DFT messages will be triggered by pressing the tool bar button for this enabled definition.
				//In the future there may be automation for sending these when procedures are set complete.
				msg=new HL7DefMessage();
				def.AddMessage(msg,MessageTypeHL7.DFT,MessageStructureHL7.DFT_P03,InOutHL7.Outgoing,6);
					#region MSH - Message Header
					seg=new HL7DefSegment();
					msg.AddSegment(seg,0,SegmentNameHL7.MSH);
						//Fields-------------------------------------------------------------------------------------------------------------
						//MSH.1, Encoding Characters (DataType.ST)
						seg.AddField(1,"separators^~\\&");
						//MSH.2, Sending Application, HD data type, Namespace ID^Universal ID^Universal ID Type
						//We originally sent 'OD' in this field, but this is a HD data type, so should consist of three components
						//We will send the Open Dental HL7 root assigned to the office and stored in the oidinternal table with the IDType of Root
						//The recommeded value for this field in the table is ^2.16.840.1.113883.3.4337.1486.CustomerPatNum^HL7.
						//If the oidinternal row with IDType=Root does not have an IDRoot assigned, we will revert to sending 'OD'
						seg.AddField(2,"sendingApp");
						//MSH.3, Sending Facility, not used
						//MSH.4, Receiving Application
						//This field will have to be a fixed text field and would have to be modified in a custom definition
						//if they want the outbound messages to have a specific receiving application identifier
						seg.AddField(4,"0361",DataTypeHL7.HD,"","NamespaceID^UniversalID^UniversalIDType");
						//MSH.5, Receiving Facility, not used
						//MSH.6, Message Date and Time (YYYYMMDDHHMMSS)
						seg.AddField(6,"dateTime.Now");
						//MSH.8, Message Type, MSG data type
						//This segment should contain MessageType^EventType^MessageStructure, example DFT^P03^DFT_P03
						seg.AddField(8,"messageType");
						//MSH.9, Message Control ID
						//A GUID that uniquely identifies this message
						seg.AddField(9,"messageControlId");
						//MSH.10, Processing ID, PT data type, Processing ID^Processing Mode
						//Processing mode is optional and not included, we will use P for production (P-Production, T-Training, D-Debugging)
						seg.AddField(10,"0103",DataTypeHL7.PT,"","P");
						//MSH.11, Version ID, VID data type, Version ID^Internationalization Code^International Version ID
						//All components are optional, we will only send Version ID, which is currently 2.6
						seg.AddField(11,"0104",DataTypeHL7.VID,"","2.6");
						//MSH.15, Application Ack Type (AL=Always, NE=Never, ER=Error/reject conditions only, SU=Successful completion only)
						//This is for enhanced acknowledgment mode, which we do not currently support, but we will send our mode just in case
						//With field MSH.15, Accept Ack Type, not present it will default to NE
						//Field MSH.15 set to AL means we will require an ack for every message that is sent, meaning it was processed successfully by the receiving application
						//But MSH.15 not present or null means we do not require a separate accept ACK message, just the accept and validate response meaning the message was accepted and processed
						seg.AddField(15,"0155",DataTypeHL7.ID,"","AL");
					#endregion MSH - Message Header
					#region EVN - Event Type
					seg=new HL7DefSegment();
					msg.AddSegment(seg,1,SegmentNameHL7.EVN);
						//Fields-------------------------------------------------------------------------------------------------------------
						//EVN.1, Event Type, example P03
						//Retained for backward compatibility only, we will not add this field by default
						//EVN.2, Recorded Date/Time
						seg.AddField(2,"dateTime.Now");
						//EVN.4, Event Reason Code (01 - Patient request; 02 - Physician/health practitioner order;03 - Census Management;O - Other;U - Unknown)
						seg.AddField(4,"0062",DataTypeHL7.IS,"","01");
					#endregion EVN - Event Type
					#region PID - Patient Identification
					seg=new HL7DefSegment();
					msg.AddSegment(seg,2,SegmentNameHL7.PID);
						//Fields-------------------------------------------------------------------------------------------------------------
						//PID.1, Set ID, SI data type
						//"This field contains the number that identifies this transaction.  For the first occurrence of the segment, the sequence number shall be one" (HL7 v2.6 documentation)
						//We only send 1 PID segment in DFT's so this number will always be 1.
						seg.AddFieldFixed(1,DataTypeHL7.SI,"1");
						//PID.2, Patient ID (retained for backward compatibility only).  Defined as 'external' ID, we've always sent the ChartNumber in this field as the eCW patient ID
						//The standard will be to continue to use PID.2 for sending the ChartNumber, which was set from PID.4 of an incoming message.  This could be the other software patient ID.
						seg.AddField(2,"pat.ChartNumber");
						//PID.3, Patient Identifier List, contains a list of identifiers separated by the repetition character (usually ~)
						//PatientID^IDCheckDigit^CheckDigitScheme^AssigningAuthority^IDTypeCode
						//Assigning Authority is a HD data type and is composed of 3 subcomponents, NamespaceID&UniversalID&UniversalIDType
						//Sub-component 2, UniversalID, we will use the OID root for a Patient object stored in the oidinternal table
						//If retrieved from OD it will be 2.16.840.1.113883.3.4337.1486.CustomerNumber.2
						//Sub-component 3, Universal ID Type, will be 'HL7' since our root is registered with HL7.
						//The IDTypeCode will be 'PI', Patient internal identifier.
						//We will also get all of the identifiers in the oidexternals table for the patient and create repetitions for each external ID using the IDExternal and RootExternal
						//Example: |1234^3^M11^&2.16.840.1.113883.3.4337.1486.6566.2&HL7^PI~7684^8^M11^&Other.Software.OID&^PI|
						seg.AddField(3,"patientIds");
						//PID.4, Alternate Patient ID, (retained for backward compatibility only).
						//We've used PID.4 for sending the OD PatNum in the past and will continue to send this in PID.4
						seg.AddField(4,"pat.PatNum");
						//PID.5, Patient Name
						seg.AddField(5,"pat.nameLFM");
						//PID.7, Date/Time of Birth
						seg.AddField(7,"pat.birthdateTime");
						//PID.8, Administrative Sex
						seg.AddField(8,"pat.Gender");
						//PID.10, Race, CWE - Coded with Exceptions data type
						//This data type is composed of 9 fields, Code^Description^CodeSystem^AlternateCode^AltDescript^AltCodeSystem^CodeSystemVersionID^AltCodeSystemVersionID^OriginalText
						//We will send Code^Description^CodeSystem^^^^CodeSystemVersionID
						//The race field can repeat, so any number of races can be sent and will come from the patientrace table.
						//Example: 2106-3^White^CDCREC^^^^1~2186-5^NotHispanic^CDCREC^^^^1
						seg.AddField(10,"pat.Race");
						//PID.11, Patient Address
						//PID.11.20, comment, will come from the patient.AddrNote column and each new line character will be replaced with '\.br\' where the '\' is the defined escape char
						//Example: 123 Main St^Apt 1^Dallas^OR^97338^^^^^^^^^^^^^^^Emergency Contact: Mom Test1\.br\Mother\.br\(503)623-3072
						seg.AddField(11,"pat.addressCityStateZip");
						//PID.13, Phone Number - Home, XTN data type (can repeat)
						//This field will also contain the patient's email address as a repetition as well as the WirelessPhone as a repetition
						//PRN stands for Primary Residence Number, equipment type: PH is Telephone, CP is Cell Phone, Internet is Internet Address (email)
						//Example: ^PRN^PH^^^503^3635432~^PRN^Internet^[email protected]~^PRN^CP^^^503^6895555
						seg.AddField(13,"pat.HmPhone");
						//PID.14, Phone Number - Business, XTN data type (can repeat)
						//We will send just one repetition, the WkPhone, but we will adhere to the data type
						//WPN=Work Number
						//Example: ^WPN^PH^^^503^3635432
						seg.AddField(14,"pat.WkPhone");
						//PID.16, Marital Status
						//S-Single, M-Married, W-Widowed, D-Divorced
						seg.AddField(16,"pat.Position");
						//PID.19, SSN - Patient
						seg.AddField(19,"pat.SSN");
					#endregion PID - Patient Identification
					#region PV1 - Patient Visit
					seg=new HL7DefSegment();
					msg.AddSegment(seg,3,false,true,SegmentNameHL7.PV1);
						//Fields-------------------------------------------------------------------------------------------------------------
						//PV1.1, Set ID - PV1
						//See the comment above for the Sequence Number of the PID segment.  Always 1 since we only send one PV1 segment per DFT message.
						seg.AddFieldFixed(1,DataTypeHL7.SI,"1");
						//PV1.2, Patient Class, IS data type (coded value for user-defined tables)
						//Suggested values E=Emergency, I=Inpatient, O=Outpatient, P=Preadmit, R=Recurring patient, B=Obstetrics, C=Commercial Account, N=Not Applicable, U=Unkown
						//We will defualt to send 'O' for outpatient for outbound messages, but for incoming we will use this field for pat.GradeLevel if it's an integer from 1-12
						seg.AddField(2,"0004",DataTypeHL7.IS,"","O");
						//PV1.3, Assigned Patient Location, PL - Person Location Data Type: Point of Care^Room^^Facility^^Person Location Type
						//Facility is a HD data type, so Namespace&ID&IDType.  We will just use &PracticeTitle with no namespace or IDType.
						//Example: ClinicDescript^OpName^^&PracticeTitle^^C  (C for clinic)
						seg.AddField(3,"apt.location");
						//PV1.7, Attending/Primary Care Doctor, ProviderId^LastName^FirstName^MI
						seg.AddField(7,"0010",DataTypeHL7.XCN,"prov.provIdNameLFM","");
						//PV1.11, Temporary Location, PL - Person Location data type: PointOfCare^^^^^Person Location Type
						//Filled with the "Site (or Grade School)" value in the database, using 'S' to designate the location type site and the site.Description value
						//If no site assigned in OD, this will be blank as it is optional
						//Example: |West Salem Elementary^^^^^S| ('S' for site)
						seg.AddField(11,"pat.site");
						//PV1.18, Patient Type, IS data type (coded value for user-defined tables)
						//We will send one of the following values retrieved from the patient.Urgency field for treatment urgency: 0 - Unknown, 1 - NoProblems, 2 - NeedsCare, 3 - Urgent
						seg.AddField(18,"pat.Urgency");
						//PV1.19, Visit Number, CX data type, AptNum^CheckDigit^CheckDigitScheme^&AssignAuthorityID&IDType^VN  (VN - Visit Number)
						//We will use AptNum, with check digit scheme M11, with the OIDRoot for an appt object (set in oidinternal), ID Type 'HL7', and 'VN' for Visit Number
						//Example: |1234^3^M11^&2.16.840.1.113883.3.4337.1486.6566.6&HL7^VN|
						seg.AddField(19,"apt.AptNum");
						//PV1.44, Admit Date/Time
						seg.AddField(44,"proc.procDateTime");
					#endregion PV1 - Patient Visit
					#region FT1 - Financial Transaction Information
					seg=new HL7DefSegment();
					msg.AddSegment(seg,4,true,true,SegmentNameHL7.FT1);
						//Fields-------------------------------------------------------------------------------------------------------------
						//FT1.1, Sequence Number (starts with 1)
						seg.AddField(1,"sequenceNum");
						//FT1.2, Transaction ID
						seg.AddField(2,"proc.ProcNum");
						//FT1.4, Transaction Date (YYYYMMDDHHMMSS)
						seg.AddField(4,"proc.procDateTime");
						//FT1.5, Transaction Posting Date (YYYYMMDDHHMMSS)
						seg.AddField(5,"proc.procDateTime");
						//FT1.6, Transaction Type
						seg.AddFieldFixed(6,DataTypeHL7.IS,"CG");
						//FT1.7, Transaction Code, CWE data type
						//This is a required field and should contain "the code assigned by the institution for the purpose of uniquely identifying the transaction based on the Transaction Type (FT1-6)".
						//We will just send the ProcNum, not sure if any receiving application will use it
						seg.AddField(7,"proc.ProcNum");
						//FT1.10, Transaction Quantity
						seg.AddFieldFixed(10,DataTypeHL7.NM,"1.0");
						//FT1.11, Transaction Amount Extended, CP data type
						//Total fee to charge for this procedure, independent of transaction quantity
						seg.AddField(11,"proc.ProcFee");
						//FT1.12, Transaction Amount Unit, CP data type
						//Fee for this procedure for each transaction quantity
						seg.AddField(12,"proc.ProcFee");
						//FT1.16, Assigned Patient Location, PL - Person Location Data Type: Point of Care^Room^^Facility^^Person Location Type
						//Facility is a HD data type, so Namespace&ID&IDType.  We will just use &PracticeTitle with no namespace or IDType.
						//Example: ClinicDescript^OpName^^&PracticeTitle^^C  (C for clinic)
						//In the FT1 segment, we will get the clinic from the specific procedure, but if not set (0) we will get it from the patient
						//If no clinic on the proc or assigned to the patient, this will be blank
						seg.AddField(16,"proc.location");
						//FT1.19, Diagnosis Code, CWE data type, repeatable if they have more than 1 code on the proc (currently 4 allowed)
						//Example: |520.2^Abnormal tooth size/form^I9C^^^^31^^~521.81^Cracked tooth^I9C^^^^31^^|
						seg.AddField(19,"proc.DiagnosticCode");
						//FT1.20, Performed by Code
						seg.AddField(20,"prov.provIdNameLFM");
						//FT1.21, Ordering Provider
						seg.AddField(21,"prov.provIdNameLFM");
						//FT1.22, Unit Cost (procedure fee)
						seg.AddField(22,"proc.ProcFee");
						//FT1.25, Procedure Code, CNE data type
						//ProcNum^Descript^CD2^^^^2014^^LaymanTerm
						//Example: D0150^comprehensive oral evaluation - new or established patient^CD2^^^^2014^^Comprehensive Exam
						seg.AddField(25,"proccode.ProcCode");
						//FT1.26, Modifiers (treatment area)
						seg.AddField(26,"proc.toothSurfRange");
					#endregion FT1 - Financial Transaction Information
					#region IN1 - Insurance (global across all FT1s)
					seg=new HL7DefSegment();
					msg.AddSegment(seg,5,true,true,SegmentNameHL7.IN1);
						//Fields-------------------------------------------------------------------------------------------------------------
						//IN1.1, Set ID (starts with 1)
						//This will be 1 for primary ins and increment for additional repetitions for secondary ins etc.
						seg.AddField(1,"sequenceNum");
						//IN1.2, Insurance Plan ID, CWE data type
						//We do not have unique ID's for insurance plans.
						//We have created an oidinternal ID for insplan, root+.7, and will use this with the insplan.PlanNum to uniquely identify an insplan.
						//Example: 2.16.840.1.113883.3.4337.1486.6566.7.1234
						seg.AddField(2,"insplan.planNum");
						//IN1.3, Insurance Company ID, CX data type
						seg.AddField(3,"carrier.ElectID");
						//IN1.4, Insurance Company Name, XON data type
						seg.AddField(4,"carrier.CarrierName");
						//IN1.5, Insurance Company Address, XAD data type
						//carrier.Address^Address2^City^State^Zip
						seg.AddField(5,"carrier.addressCityStateZip");
						//IN1.7, Insurance Company Phone Number, XTN data type
						//Example: ^WPN^PH^^^503^3635432
						seg.AddField(7,"carrier.Phone");
						//IN1.8, Group Number, ST data type
						seg.AddField(8,"insplan.GroupNum");
						//IN1.9, Group Name, XON data type
						seg.AddField(9,"insplan.GroupName");
						//IN1.11, Insured's Group Employer Name, XON data type
						//insplan.EmployerNum to employer.EmpName
						seg.AddField(11,"insplan.empName");
						//IN1.12, Plan Effective Date, DT data type
						seg.AddField(12,"inssub.DateEffective");
						//IN1.13, Plan Expiration Date, DT data type
						seg.AddField(13,"inssub.DateTerm");
						//IN1.15, Plan Type, IS data type
						//insplan.PlanType, Category Percentage, PPO Percentage, Medicaid or Flat Copay, Capitation
						seg.AddField(15,"insplan.PlanType");
						//IN1.16, Name of Insured, XPN data type
						//insplan.InsSubNum->inssub.Subscriber->patient name
						seg.AddField(16,"inssub.subscriberName");
						//IN1.17, Insured's Relationship to Patient, CWE data type
						//SEL-Self, SPO-Spouse, DOM-LifePartner, CHD-Child (PAR-Parent), EME-Employee (EMR-Employer)
						//DEP-HandicapDep (GRD-Guardian), DEP-Dependent, OTH-SignifOther (OTH-Other), OTH-InjuredPlantiff
						//We store relationship to subscriber and they want subscriber's relationship to patient, therefore
						//Relat.Child will return "PAR" for Parent, Relat.Employee will return "EMR" for Employer, and Relat.HandicapDep and Relat.Dependent will return "GRD" for Guardian
						//We will use the first two components, Identifier^Text
						//Example: |PAR^Parent|
						seg.AddField(17,"patplan.subRelationToPat");
						//IN1.18, Insured's Date of Birth, DTM data type
						seg.AddField(18,"inssub.subBirthdate");
						//IN1.19, Insured's Address, XAD data type
						seg.AddField(19,"inssub.subAddrCityStateZip");
						//IN1.20, Assignment of Benefits, IS data type
						//inssub.AssignBen 1-Y, 0-N
						seg.AddField(20,"inssub.AssignBen");
						//IN1.21, Coordination of Benefits, IS data type
						//CO-Coordination, IN-Independent.  Will be CO if more than one patplan
						seg.AddField(21,"insplan.cob");
						//IN1.22, Coordination of Benefits Priority, ST data type
						//1-Primary, 2-Secondary, 3,4,5...
						seg.AddField(22,"patplan.Ordinal");
						//IN1.27, Release of Information Code, IS data type
						//inssub.ReleaseInfo, 1-Y, 2-N
						seg.AddField(27,"inssub.ReleaseInfo");
						//IN1.36, Policy Number, ST data type
						//patplan.PatID, if blank then inssub.SubscriberID
						seg.AddField(36,"patplan.policyNum");
						//IN1.47, Coverage Type, IS data type
						//D-Dental, M-Medical using insplan.IsMedical flag
						seg.AddField(47,"insplan.coverageType");
						//IN1.49, Insured's ID Number, CX data type
						seg.AddField(49,"inssub.SubscriberID");
					#endregion IN1 - Insurance (global across all FT1s)
				#endregion DFT - Detailed Financial Transaction
				#region SIU - Schedule Information Unsolicited
				//Outbound SIU messages will be triggered when specific data is changed in OD, but not if the data change is due to an inbound HL7 message.
				//SIU's created when creating/modifying/cancelling/breaking an appointment
				msg=new HL7DefMessage();
				def.AddMessage(msg,MessageTypeHL7.SIU,MessageStructureHL7.SIU_S12,InOutHL7.Outgoing,7);
					#region MSH - Message Header
					seg=new HL7DefSegment();
					msg.AddSegment(seg,0,SegmentNameHL7.MSH);
						//Fields-------------------------------------------------------------------------------------------------------------
						//MSH.1, Encoding Characters (DataType.ST)
						seg.AddField(1,"separators^~\\&");
						//MSH.2, Sending Application, HD data type, Namespace ID^Universal ID^Universal ID Type
						//We originally sent 'OD' in this field, but this is a HD data type, so should consist of three components
						//We will send the Open Dental HL7 root assigned to the office and stored in the oidinternal table with the IDType of Root
						//The recommeded value for this field in the table is ^2.16.840.1.113883.3.4337.1486.CustomerPatNum^HL7.
						//If the oidinternal row with IDType=Root does not have an IDRoot assigned, we will revert to sending 'OD'
						seg.AddField(2,"sendingApp");
						//MSH.3, Sending Facility, not used
						//MSH.4, Receiving Application
						//This field will have to be a fixed text field and would have to be modified in a custom definition
						//if they want the outbound messages to have a specific receiving application identifier
						seg.AddField(4,"0361",DataTypeHL7.HD,"","NamespaceID^UniversalID^UniversalIDType");
						//MSH.5, Receiving Facility, not used
						//MSH.6, Message Date and Time (YYYYMMDDHHMMSS)
						seg.AddField(6,"dateTime.Now");
						//MSH.8, Message Type, MSG data type
						//This segment should contain MessageType^EventType^MessageStructure, example SIU^S12^SIU_S12
						seg.AddField(8,"messageType");
						//MSH.9, Message Control ID
						//A GUID that uniquely identifies this message
						seg.AddField(9,"messageControlId");
						//MSH.10, Processing ID, PT data type, Processing ID^Processing Mode
						//Processing mode is optional and not included, we will use P for production (P-Production, T-Training, D-Debugging)
						seg.AddField(10,"0103",DataTypeHL7.PT,"","P");
						//MSH.11, Version ID, VID data type, Version ID^Internationalization Code^International Version ID
						//All components are optional, we will only send Version ID, which is currently 2.6
						seg.AddField(11,"0104",DataTypeHL7.VID,"","2.6");
						//MSH.15, Application Ack Type (AL=Always, NE=Never, ER=Error/reject conditions only, SU=Successful completion only)
						//This is for enhanced acknowledgment mode, which we do not currently support, but we will send our mode just in case
						//With field MSH.15, Accept Ack Type, not present it will default to NE
						//Field MSH.15 set to AL means we will require an ack for every message that is sent, meaning it was processed successfully by the receiving application
						//But MSH.15 not present or null means we do not require a separate accept ACK message, just the accept and validate response meaning the message was accepted and processed
						seg.AddField(15,"0155",DataTypeHL7.ID,"","AL");
					#endregion MSH - Message Header
					#region SCH - Schedule Activity Information
					seg=new HL7DefSegment();
					msg.AddSegment(seg,1,SegmentNameHL7.SCH);
						//Fields-------------------------------------------------------------------------------------------------------------
						//SCH.1, Placer Appointment ID, EI data type, OD is the filler application
						//We will store the exernalAptId from an incoming SRM message ARQ segment if they send it to us, so send it here if we have one
						seg.AddField(1,"apt.externalAptID");
						//SCH.2, Filler Appointment ID, EI data type, OD is the filler application
						//We will populate the first component with the AptNum, the third with the OID for an appointment object, the fourth with "HL7"
						//Example: 1234^^2.16.840.1.113883.3.4337.1486.6566.6^HL7
						seg.AddField(2,"apt.AptNum");
						//SCH.5, Schedule ID, CWE data type
						//We will use this to send the operatory name
						seg.AddField(5,"apt.operatory");
						//SCH.7, Appointment Reason
						seg.AddField(7,"apt.Note");
						//SCH.8, Appointment Type, CWE data type
						//Suggested values are Normal - Routine schedule request type, Tentative, or Complete - Request to add a completed appt
						//We will send Normal for all appointment statuses except complete.
						seg.AddField(8,"apt.type");
						//SCH.16, Filler Contact Person, XCN data type
						//The OD user who created/modified the appointment
						seg.AddField(16,"apt.userOD");
						//SCH.20, Entered by Person, XCN data type
						//The OD user who created/modified the appointment
						seg.AddField(20,"apt.userOD");
						//SCH.25, Filler Status Code, CWE data type
						//This will signal to the other software the AptStatus of the appointment
						//Booked - ApptStatus.Scheduled or ApptStatus.ASAP, Complete - ApptStatus.Complete, Cancelled - ApptStatus.Broken or ApptStatus.UnscheduledList, Deleted (when deleted)
						seg.AddField(25,"apt.aptStatus");
					#endregion SCH - Schedule Activity Information
					#region TQ1 - Timing/Quantity
					seg=new HL7DefSegment();
					msg.AddSegment(seg,2,false,true,SegmentNameHL7.TQ1);
						//Fields-------------------------------------------------------------------------------------------------------------
						//TQ1.1, Set ID, SI data type
						//Always 1, only one timing specification in our outbound SIU messages
						seg.AddFieldFixed(1,DataTypeHL7.SI,"1");
						//TQ1.2, Quantity, CQ data type
						//Always default value 1
						seg.AddFieldFixed(2,DataTypeHL7.CQ,"1");
						//TQ1.6, Service Duration, CQ data type
						//apt.Pattern is filled with X's and /'s, stored in 5 minute increments
						//Example: 60^min&&ANS+, ANS+ is the name of the coding system
						seg.AddField(6,"apt.length");
						//TQ1.7, Start Date/Time, DTM data type
						seg.AddField(7,"apt.AptDateTime");
						//TQ1.8, End Date/Time, DTM data type
						seg.AddField(8,"apt.endAptDateTime");
					#endregion TQ1 - Timing/Quantity
					#region PID - Patient Identification
					seg=new HL7DefSegment();
					msg.AddSegment(seg,3,SegmentNameHL7.PID);
						//Fields-------------------------------------------------------------------------------------------------------------
						//PID.1, Set ID, SI data type
						//"This field contains the number that identifies this transaction.  For the first occurrence of the segment, the sequence number shall be one" (HL7 v2.6 documentation)
						//We only send 1 PID segment in SIU's so this number will always be 1.
						seg.AddFieldFixed(1,DataTypeHL7.SI,"1");
						//PID.2, Patient ID (retained for backward compatibility only).  Defined as 'external' ID, we've always sent the ChartNumber in this field as the eCW patient ID
						//The standard will be to continue to use PID.2 for sending the ChartNumber, which was set from PID.4 of an incoming message.  This could be the other software patient ID.
						seg.AddField(2,"pat.ChartNumber");
						//PID.3, Patient Identifier List, contains a list of identifiers separated by the repetition character (usually ~)
						//PatientID^IDCheckDigit^CheckDigitScheme^AssigningAuthority^IDTypeCode
						//Assigning Authority is a HD data type and is composed of 3 subcomponents, NamespaceID&UniversalID&UniversalIDType
						//Sub-component 2, UniversalID, we will use the OID root for a Patient object stored in the oidinternal table
						//If retrieved from OD it will be 2.16.840.1.113883.3.4337.1486.CustomerNumber.2
						//Sub-component 3, Universal ID Type, will be 'HL7' since our root is registered with HL7.
						//The IDTypeCode will be 'PI', Patient internal identifier.
						//We will also get all of the identifiers in the oidexternals table for the patient and create repetitions for each external ID using the IDExternal and RootExternal
						//Example: |1234^3^M11^&2.16.840.1.113883.3.4337.1486.6566.2&HL7^PI~7684^8^M11^&Other.Software.OID&^PI|
						seg.AddField(3,"patientIds");
						//PID.4, Alternate Patient ID, (retained for backward compatibility only).
						//We've used PID.4 for sending the OD PatNum in the past and will continue to send this in PID.4
						seg.AddField(4,"pat.PatNum");
						//PID.5, Patient Name
						seg.AddField(5,"pat.nameLFM");
						//PID.7, Date/Time of Birth
						seg.AddField(7,"pat.birthdateTime");
						//PID.8, Administrative Sex
						seg.AddField(8,"pat.Gender");
						//PID.10, Race, CWE - Coded with Exceptions data type
						//This data type is composed of 9 fields, Code^Description^CodeSystem^AlternateCode^AltDescript^AltCodeSystem^CodeSystemVersionID^AltCodeSystemVersionID^OriginalText
						//We will send Code^Description^CodeSystem^^^^CodeSystemVersionID
						//The race field can repeat, so any number of races can be sent and will come from the patientrace table.
						//Example: 2106-3^White^CDCREC^^^^1~2186-5^NotHispanic^CDCREC^^^^1
						seg.AddField(10,"pat.Race");
						//PID.11, Patient Address
						//PID.11.20, comment, will come from the patient.AddrNote column and each new line character will be replaced with '\.br\' where the '\' is the defined escape char
						//Example: 123 Main St^Apt 1^Dallas^OR^97338^^^^^^^^^^^^^^^Emergency Contact: Mom Test1\.br\Mother\.br\(503)623-3072
						seg.AddField(11,"pat.addressCityStateZip");
						//PID.13, Phone Number - Home, XTN data type (can repeat)
						//This field will also contain the patient's email address as a repetition as well as the WirelessPhone as a repetition
						//PRN stands for Primary Residence Number, equipment type: PH is Telephone, CP is Cell Phone, Internet is Internet Address (email)
						//Example: ^PRN^PH^^^503^3635432~^PRN^Internet^[email protected]~^PRN^CP^^^503^6895555
						seg.AddField(13,"pat.HmPhone");
						//PID.14, Phone Number - Business, XTN data type (can repeat)
						//We will send just one repetition, the WkPhone, but we will adhere to the data type
						//WPN=Work Number
						//Example: ^WPN^PH^^^503^3635432
						seg.AddField(14,"pat.WkPhone");
						//PID.16, Marital Status
						//S-Single, M-Married, W-Widowed, D-Divorced
						seg.AddField(16,"pat.Position");
						//PID.19, SSN - Patient
						seg.AddField(19,"pat.SSN");
					#endregion PID - Patient Identification
					#region PV1 - Patient Visit
					seg=new HL7DefSegment();
					msg.AddSegment(seg,4,false,true,SegmentNameHL7.PV1);
						//Fields-------------------------------------------------------------------------------------------------------------
						//PV1.1, Set ID - PV1
						//See the comment above for the Sequence Number of the PID segment.  Always 1 since we only send one PV1 segment per SIU message.
						seg.AddFieldFixed(1,DataTypeHL7.SI,"1");
						//PV1.2, Patient Class, IS data type (coded value for user-defined tables)
						//Suggested values E=Emergency, I=Inpatient, O=Outpatient, P=Preadmit, R=Recurring patient, B=Obstetrics, C=Commercial Account, N=Not Applicable, U=Unkown
						//We will defualt to send 'O' for outpatient for outbound messages, but for incoming we will use this field for pat.GradeLevel if it's an integer from 1-12
						seg.AddField(2,"0004",DataTypeHL7.IS,"","O");
						//PV1.3, Assigned Patient Location, PL - Person Location Data Type: Point of Care^Room^^Facility^^Person Location Type
						//Facility is a HD data type, so Namespace&ID&IDType.  We will just use &PracticeTitle with no namespace or IDType.
						//Example: ClinicDescript^OpName^^&PracticeTitle^^C  (C for clinic)
						seg.AddField(3,"apt.location");
						//PV1.7, Attending/Primary Care Doctor, ProviderId^LastName^FirstName^MI
						seg.AddField(7,"0010",DataTypeHL7.XCN,"prov.provIdNameLFM","");
						//PV1.11, Temporary Location, PL - Person Location data type: PointOfCare^^^^^Person Location Type
						//Filled with the "Site (or Grade School)" value in the database, using 'S' to designate the location type site and the site.Description value
						//If no site assigned in OD, this will be blank as it is optional
						//Example: |West Salem Elementary^^^^^S| ('S' for site)
						seg.AddField(11,"pat.site");
						//PV1.18, Patient Type, IS data type (coded value for user-defined tables)
						//We will send one of the following values retrieved from the patient.Urgency field for treatment urgency: 0 - Unknown, 1 - NoProblems, 2 - NeedsCare, 3 - Urgent
						seg.AddField(18,"pat.Urgency");
						//PV1.19, Visit Number, CX data type, AptNum^CheckDigit^CheckDigitScheme^&AssignAuthorityID&IDType^VN  (VN - Visit Number)
						//We will use AptNum, with check digit scheme M11, with the OIDRoot for an appt object (set in oidinternal), ID Type 'HL7', and 'VN' for Visit Number
						//Example: |1234^3^M11^&2.16.840.1.113883.3.4337.1486.6566.6&HL7^VN|
						seg.AddField(19,"apt.AptNum");
						//PV1.44, Admit Date/Time
						seg.AddField(44,"apt.AptDateTime");
					#endregion PV1 - Patient Visit
					#region RGS - Resource Group
					seg=new HL7DefSegment();
					msg.AddSegment(seg,5,SegmentNameHL7.RGS);
						//Fields-------------------------------------------------------------------------------------------------------------
						//RGS.1, Set ID, SI data type
						//Always 1, only one resourece group in our outbound SIU's
						seg.AddFieldFixed(1,DataTypeHL7.SI,"1");
						//RGS.2, Segment Action Code, ID data type
						//A-Add/Insert, D-Delete, U-Update, X-No Change
						seg.AddField(2,"segmentAction");
					#endregion RGB - Resource Group
					#region AIL - Appointment Information - Location Resource
					//We will use the AIL segment to identify the clinic and operatory for the appointment
					seg=new HL7DefSegment();
					msg.AddSegment(seg,6,false,true,SegmentNameHL7.AIL);
						//Fields-------------------------------------------------------------------------------------------------------------
						//AIL.1, Set ID, SI data type
						//Always 1, only one location identified by our SIU messsage
						seg.AddFieldFixed(1,DataTypeHL7.SI,"1");
						//AIL.2, Segment Action Code, ID data type
						//A-Add/Insert, D-Delete, U-Update, X-No Change
						seg.AddField(2,"segmentAction");
						//AIL.3, Location Resource ID, PL - Person Location Data Type: Point of Care^Room^^Facility^^Person Location Type
						//Facility is a HD data type, so Namespace&ID&IDType.  We will just use &PracticeTitle with no namespace or IDType.
						//Example: ClinicDescript^OpName^^&PracticeTitle^^C  (C for clinic)
						seg.AddField(3,"apt.location");
						//AIL.12, Filler Status Code, CWE data type
						//We will use this to send the confirmation status of the appointment
						//We will use the second component (text) and send the ItemName (confirm Name) from the definition table that is set for this appointment
						//Example: |^Appointment Confirmed|
						seg.AddField(12,"apt.confirmStatus");
					#endregion AIL - Appointment Information - Location Resource
					#region AIP - Appointment Information - Personnel Resource
					//We will use the AIP segment to identify the dentist and hygienist on the appointment
					//If there is both a dentist and a hygienist assigned to an appointment, we will send two repetitions of the AIP segment
					seg=new HL7DefSegment();
					msg.AddSegment(seg,7,true,true,SegmentNameHL7.AIP);
						//Fields-------------------------------------------------------------------------------------------------------------
						//AIP.1, Set ID, SI data type
						//This segment can repeat for an appt, sequence 1 will be the dentist, 2 will be the hygienist on the appt
						seg.AddField(1,"sequenceNum");
						//AIP.2, Segment Action Code, ID data type
						//A-Add/Insert, D-Delete, U-Update, X-No Change
						seg.AddField(2,"segmentAction");
						//AIP.3, Personnel Resource ID, XCN data type
						//ProviderId^LastName^FirstName^MI^Suffix^Prefix
						//According to the HL7 standards, we are free to use the components as needed to identify the provider
						//We will use 'ProviderID' to send the OD ProvNum, LName, FName and the 'Prefix' component as the Abbr
						//We will retrieve the provider from the appointment and use AIP.4 to differentiate between the dentist and hygienist
						//Example: |1234^Abbott^Sarah^L^DMD^DrAbbott|
						seg.AddField(3,"prov.provIdNameLFM");
						//AIP.4, Resource Type, CWE data type
						//We will send 'd' for dentist (apt.ProvNum) and 'h' for hygienist (apt.ProvHyg)
						seg.AddField(4,"prov.provType");
						//AIP.12, Filler Status Code, CWE data type
						//We will use this to send the confirmation status of the appointment
						//We will use the second component (text) and send the ItemName (confirm Name) from the definition table that is set for this appointment
						//Example: |^Appointment Confirmed|
						seg.AddField(12,"apt.confirmStatus");
					#endregion AIP - Appointment Information - Personnel Resource
				#endregion SIU - Schedule Information Unsolicited
				#region SRR - Schedule Request Response
				msg=new HL7DefMessage();
				def.AddMessage(msg,MessageTypeHL7.SRR,MessageStructureHL7.SRR_S01,InOutHL7.Outgoing,8);
					#region MSH - Message Header
					seg=new HL7DefSegment();
					msg.AddSegment(seg,0,SegmentNameHL7.MSH);
						//Fields-------------------------------------------------------------------------------------------------------------
						//MSH.1, Encoding Characters (DataType.ST)
						seg.AddField(1,"separators^~\\&");
						//MSH.2, Sending Application, HD data type, Namespace ID^Universal ID^Universal ID Type
						//We originally sent 'OD' in this field, but this is a HD data type, so should consist of three components
						//We will send the Open Dental HL7 root assigned to the office and stored in the oidinternal table with the IDType of Root
						//The recommeded value for this field in the table is ^2.16.840.1.113883.3.4337.1486.CustomerPatNum^HL7.
						//If the oidinternal row with IDType=Root does not have an IDRoot assigned, we will revert to sending 'OD'
						seg.AddField(2,"sendingApp");
						//MSH.3, Sending Facility, not used
						//MSH.4, Receiving Application
						//This field will have to be a fixed text field and would have to be modified in a custom definition
						//if they want the outbound messages to have a specific receiving application identifier
						seg.AddField(4,"0361",DataTypeHL7.HD,"","NamespaceID^UniversalID^UniversalIDType");
						//MSH.5, Receiving Facility, not used
						//MSH.6, Message Date and Time (YYYYMMDDHHMMSS)
						seg.AddField(6,"dateTime.Now");
						//MSH.8, Message Type, MSG data type
						//This segment should contain MessageType^EventType^MessageStructure, example SRR^S04^SRR_S04
						seg.AddField(8,"messageType");
						//MSH.9, Message Control ID
						//A GUID that uniquely identifies this message
						seg.AddField(9,"messageControlId");
						//MSH.10, Processing ID, PT data type, Processing ID^Processing Mode
						//Processing mode is optional and not included, we will use P for production (P-Production, T-Training, D-Debugging)
						seg.AddField(10,"0103",DataTypeHL7.PT,"","P");
						//MSH.11, Version ID, VID data type, Version ID^Internationalization Code^International Version ID
						//All components are optional, we will only send Version ID, which is currently 2.6
						seg.AddField(11,"0104",DataTypeHL7.VID,"","2.6");
						//MSH.15, Application Ack Type (AL=Always, NE=Never, ER=Error/reject conditions only, SU=Successful completion only)
						//This is for enhanced acknowledgment mode, which we do not currently support, but we will send our mode just in case
						//With field MSH.15, Accept Ack Type, not present it will default to NE
						//Field MSH.15 set to AL means we will require an ack for every message that is sent, meaning it was processed successfully by the receiving application
						//But MSH.15 not present or null means we do not require a separate accept ACK message, just the accept and validate response meaning the message was accepted and processed
						seg.AddField(15,"0155",DataTypeHL7.ID,"","AL");
					#endregion MSH - Message Header
					#region MSA - Message Acknowledgment
					seg=new HL7DefSegment();
					msg.AddSegment(seg,1,SegmentNameHL7.MSA);
						//Fields-------------------------------------------------------------------------------------------------------------
						//MSA.1, Acknowledgment Code
						seg.AddField(1,"ackCode");
						//MSA.2, Message Control ID
						seg.AddField(2,"messageControlId");
					#endregion MSA - Message Acknowledgment
					#region SCH - Schedule Activity Information
					seg=new HL7DefSegment();
					msg.AddSegment(seg,2,false,true,SegmentNameHL7.SCH);
						//Fields-------------------------------------------------------------------------------------------------------------
						//SCH.1, Placer Appointment ID, EI data type, OD is the filler application
						//We will store the exernalAptId from an incoming SRM message ARQ segment if they send it to us, so send it here if we have one
						seg.AddField(1,"apt.externalAptID");
						//SCH.2, Filler Appointment ID, EI data type, OD is the filler application
						//AptNum^^AssignAuthorityID^IDType
						//Example: |1234^^2.16.840.1.113883.3.4337.1486.6566.6^HL7|  root.6 is appointment
						seg.AddField(2,"apt.AptNum");
						//SCH.5, Schedule ID, CWE data type
						//We will use this to send the operatory name
						seg.AddField(5,"apt.operatory");
						//SCH.7, Appointment Reason
						seg.AddField(7,"apt.Note");
						//SCH.8, Appointment Type, CWE data type
						//Suggested values are Normal - Routine schedule request type, Tentative, or Complete - Request to add a completed appt
						//We will send Normal for all appointment statuses except complete.
						seg.AddField(8,"apt.type");
						//SCH.16, Filler Contact Person, XCN data type
						//The OD user who created/modified the appointment
						seg.AddField(16,"apt.userOD");
						//SCH.20, Entered by Person, XCN data type
						//The OD user who created/modified the appointment
						seg.AddField(20,"apt.userOD");
						//SCH.25, Filler Status Code, CWE data type
						//This will signal to the other software the AptStatus of the appointment
						//Booked - ApptStatus.Scheduled or ApptStatus.ASAP, Complete - ApptStatus.Complete, Cancelled - ApptStatus.Broken or ApptStatus.UnscheduledList, Deleted (when deleted)
						seg.AddField(25,"apt.aptStatus");
					#endregion SCH - Schedule Activity Information
					#region NTE - Notes and Comments
					seg=new HL7DefSegment();
					msg.AddSegment(seg,2,true,true,SegmentNameHL7.NTE);
						//Fields-------------------------------------------------------------------------------------------------------------
						//NTE.1, Set ID, SI data type
						//We will only ever send one NTE segment in outbound messages, so this will always be 1
						seg.AddFieldFixed(1,DataTypeHL7.SI,"1");
						//NTE.3, Comment, FT data type (formatted text)
						//We will send the appointment.Note value in this field for outbound messages
						//This is formatted text, so new line characters in the appointment.Note will be replaced with
						//the designated new line character sequence '\.br\' (where the '\' is the defined escape char, \ by default)
						seg.AddField(3,"apt.Note");
					#endregion NTE - Notes and Comments
					#region PID - Patient Identification
					seg=new HL7DefSegment();
					msg.AddSegment(seg,3,SegmentNameHL7.PID);
						//Fields-------------------------------------------------------------------------------------------------------------
						//PID.1, Set ID, SI data type
						//"This field contains the number that identifies this transaction.  For the first occurrence of the segment, the sequence number shall be one" (HL7 v2.6 documentation)
						//We only send 1 PID segment in SRR's so this number will always be 1.
						seg.AddFieldFixed(1,DataTypeHL7.SI,"1");
						//PID.2, Patient ID (retained for backward compatibility only).  Defined as 'external' ID, we've always sent the ChartNumber in this field as the eCW patient ID
						//The standard will be to continue to use PID.2 for sending the ChartNumber, which was set from PID.4 of an incoming message.  This could be the other software patient ID.
						seg.AddField(2,"pat.ChartNumber");
						//PID.3, Patient Identifier List, contains a list of identifiers separated by the repetition character (usually ~)
						//PatientID^IDCheckDigit^CheckDigitScheme^AssigningAuthority^IDTypeCode
						//Assigning Authority is a HD data type and is composed of 3 subcomponents, NamespaceID&UniversalID&UniversalIDType
						//Sub-component 2, UniversalID, we will use the OID root for a Patient object stored in the oidinternal table
						//If retrieved from OD it will be 2.16.840.1.113883.3.4337.1486.CustomerNumber.2
						//Sub-component 3, Universal ID Type, will be 'HL7' since our root is registered with HL7.
						//The IDTypeCode will be 'PI', Patient internal identifier.
						//We will also get all of the identifiers in the oidexternals table for the patient and create repetitions for each external ID using the IDExternal and RootExternal
						//Example: |1234^3^M11^&2.16.840.1.113883.3.4337.1486.6566.2&HL7^PI~7684^8^M11^&Other.Software.OID&^PI|
						seg.AddField(3,"patientIds");
						//PID.4, Alternate Patient ID, (retained for backward compatibility only).
						//We've used PID.4 for sending the OD PatNum in the past and will continue to send this in PID.4
						seg.AddField(4,"pat.PatNum");
						//PID.5, Patient Name
						seg.AddField(5,"pat.nameLFM");
						//PID.7, Date/Time of Birth
						seg.AddField(7,"pat.birthdateTime");
						//PID.8, Administrative Sex
						seg.AddField(8,"pat.Gender");
						//PID.10, Race, CWE - Coded with Exceptions data type
						//This data type is composed of 9 fields, Code^Description^CodeSystem^AlternateCode^AltDescript^AltCodeSystem^CodeSystemVersionID^AltCodeSystemVersionID^OriginalText
						//We will send Code^Description^CodeSystem^^^^CodeSystemVersionID
						//The race field can repeat, so any number of races can be sent and will come from the patientrace table.
						//Example: 2106-3^White^CDCREC^^^^1~2186-5^NotHispanic^CDCREC^^^^1
						seg.AddField(10,"pat.Race");
						//PID.11, Patient Address
						//PID.11.20, comment, will come from the patient.AddrNote column and each new line character will be replaced with '\.br\' where the '\' is the defined escape char
						//Example: 123 Main St^Apt 1^Dallas^OR^97338^^^^^^^^^^^^^^^Emergency Contact: Mom Test1\.br\Mother\.br\(503)623-3072
						seg.AddField(11,"pat.addressCityStateZip");
						//PID.13, Phone Number - Home, XTN data type (can repeat)
						//This field will also contain the patient's email address as a repetition as well as the WirelessPhone as a repetition
						//PRN stands for Primary Residence Number, equipment type: PH is Telephone, CP is Cell Phone, Internet is Internet Address (email)
						//Example: ^PRN^PH^^^503^3635432~^PRN^Internet^[email protected]~^PRN^CP^^^503^6895555
						seg.AddField(13,"pat.HmPhone");
						//PID.14, Phone Number - Business, XTN data type (can repeat)
						//We will send just one repetition, the WkPhone, but we will adhere to the data type
						//WPN=Work Number
						//Example: ^WPN^PH^^^503^3635432
						seg.AddField(14,"pat.WkPhone");
						//PID.16, Marital Status
						//S-Single, M-Married, W-Widowed, D-Divorced
						seg.AddField(16,"pat.Position");
						//PID.19, SSN - Patient
						seg.AddField(19,"pat.SSN");
					#endregion PID - Patient Identification
					#region PV1 - Patient Visit
					seg=new HL7DefSegment();
					msg.AddSegment(seg,4,false,true,SegmentNameHL7.PV1);
						//Fields-------------------------------------------------------------------------------------------------------------
						//PV1.1, Set ID - PV1
						//See the comment above for the Sequence Number of the PID segment.  Always 1 since we only send one PV1 segment per SRR message.
						seg.AddFieldFixed(1,DataTypeHL7.SI,"1");
						//PV1.2, Patient Class, IS data type (coded value for user-defined tables)
						//Suggested values E=Emergency, I=Inpatient, O=Outpatient, P=Preadmit, R=Recurring patient, B=Obstetrics, C=Commercial Account, N=Not Applicable, U=Unkown
						//We will defualt to send 'O' for outpatient for outbound messages, but for incoming we will use this field for pat.GradeLevel if it's an integer from 1-15
						seg.AddField(2,"0004",DataTypeHL7.IS,"","O");
						//PV1.3, Assigned Patient Location, PL - Person Location Data Type: Point of Care^Room^^Facility^^Person Location Type
						//Facility is a HD data type, so Namespace&ID&IDType.  We will just use &PracticeTitle with no namespace or IDType.
						//Example: ClinicDescript^OpName^^&PracticeTitle^^C  (C for clinic)
						seg.AddField(3,"apt.location");
						//PV1.7, Attending/Primary Care Doctor, ProviderId^LastName^FirstName^MI
						seg.AddField(7,"0010",DataTypeHL7.XCN,"prov.provIdNameLFM","");
						//PV1.11, Temporary Location, PL - Person Location data type: PointOfCare^^^^^Person Location Type
						//Filled with the "Site (or Grade School)" value in the database, using 'S' to designate the location type site and the site.Description value
						//If no site assigned in OD, this will be blank as it is optional
						//Example: |West Salem Elementary^^^^^S| ('S' for site)
						seg.AddField(11,"pat.site");
						//PV1.18, Patient Type, IS data type (coded value for user-defined tables)
						//We will send one of the following values retrieved from the patient.Urgency field for treatment urgency: 0 - Unknown, 1 - NoProblems, 2 - NeedsCare, 3 - Urgent
						seg.AddField(18,"pat.Urgency");
						//PV1.19, Visit Number, CX data type, AptNum^CheckDigit^CheckDigitScheme^&AssignAuthorityID&IDType^VN  (VN - Visit Number)
						//We will use AptNum, with check digit scheme M11, with the OIDRoot for an appt object (set in oidinternal), ID Type 'HL7', and 'VN' for Visit Number
						//Example: |1234^3^M11^&2.16.840.1.113883.3.4337.1486.6566.6&HL7^VN|
						seg.AddField(19,"apt.AptNum");
						//PV1.44, Admit Date/Time
						seg.AddField(44,"apt.AptDateTime");
					#endregion PV1 - Patient Visit
					#region RGS - Resource Group
					seg=new HL7DefSegment();
					msg.AddSegment(seg,5,SegmentNameHL7.RGS);
						//Fields-------------------------------------------------------------------------------------------------------------
						//RGS.1, Set ID, SI data type
						//Always 1, only one resourece group in our outbound SRR's
						seg.AddFieldFixed(1,DataTypeHL7.SI,"1");
						//RGS.2, Segment Action Code, ID data type
						//A-Add/Insert, D-Delete, U-Update, X-No Change
						seg.AddField(2,"segmentAction");
					#endregion RGB - Resource Group
					#region AIL - Appointment Information - Location Resource
					//We will use the AIL segment to identify the clinic and operatory for the appointment
					seg=new HL7DefSegment();
					msg.AddSegment(seg,6,false,true,SegmentNameHL7.AIL);
						//Fields-------------------------------------------------------------------------------------------------------------
						//AIL.1, Set ID, SI data type
						//Always 1, only one location identified by our SRR messsage
						seg.AddFieldFixed(1,DataTypeHL7.SI,"1");
						//AIL.2, Segment Action Code, ID data type
						//A-Add/Insert, D-Delete, U-Update, X-No Change
						seg.AddField(2,"segmentAction");
						//AIL.3, Location Resource ID, PL - Person Location Data Type: Point of Care^Room^^Facility^^Person Location Type
						//Facility is a HD data type, so Namespace&ID&IDType.  We will just use &PracticeTitle with no namespace or IDType.
						//Example: ClinicDescript^OpName^^&PracticeTitle^^C  (C for clinic)
						seg.AddField(3,"apt.location");
						//AIL.12, Filler Status Code, CWE data type
						//We will use this to send the confirmation status of the appointment
						//We will use the second component (text) and send the ItemName (confirm Name) from the definition table that is set for this appointment
						//Example: |^Appointment Confirmed|
						seg.AddField(12,"apt.confirmStatus");
					#endregion AIL - Appointment Information - Location Resource
					#region AIP - Appointment Information - Personnel Resource
					//We will use the AIP segment to identify the dentist and hygienist on the appointment
					//If there is both a dentist and a hygienist assigned to an appointment, we will send two repetitions of the AIP segment
					seg=new HL7DefSegment();
					msg.AddSegment(seg,7,true,true,SegmentNameHL7.AIP);
						//Fields-------------------------------------------------------------------------------------------------------------
						//AIP.1, Set ID, SI data type
						//This segment can repeat for an appt, sequence 1 will be the dentist, 2 will be the hygienist on the appt
						seg.AddField(1,"sequenceNum");
						//AIP.2, Segment Action Code, ID data type
						//A-Add/Insert, D-Delete, U-Update, X-No Change
						seg.AddField(2,"segmentAction");
						//AIP.3, Personnel Resource ID, XCN data type
						//ProviderId^LastName^FirstName^MI^Suffix^Prefix
						//According to the HL7 standards, we are free to use the components as needed to identify the provider
						//We will use 'ProviderID' to send the OD ProvNum, LName, FName and the 'Prefix' component as the Abbr
						//We will retrieve the provider from the appointment and use AIP.4 to differentiate between the dentist and hygienist
						//Example: |1234^Abbott^Sarah^L^DMD^DrAbbott|
						seg.AddField(3,"prov.provIdNameLFM");
						//AIP.4, Resource Type, CWE data type
						//We will send 'd' for dentist (apt.ProvNum) and 'h' for hygienist (apt.ProvHyg)
						seg.AddField(4,"prov.provType");
						//AIP.12, Filler Status Code, CWE data type
						//We will use this to send the confirmation status of the appointment
						//We will use the second component (text) and send the ItemName (confirm Name) from the definition table that is set for this appointment
						//Example: |^Appointment Confirmed|
						seg.AddField(12,"apt.confirmStatus");
					#endregion AIP - Appointment Information - Personnel Resource
				#endregion SRR - Schedule Request Response
			#endregion Outbound Messages
			return def;
		}
예제 #32
0
파일: InternalEcwFull.cs 프로젝트: mnisl/OD
		public static HL7Def GetDeepInternal(HL7Def def) {
			//ok to pass in null
			if(def==null) {//wasn't in the database
				def=new HL7Def();
				def.IsNew=true;
				def.Description="eCW Full";
				def.ModeTx=ModeTxHL7.File;
				def.IncomingFolder="";
				def.OutgoingFolder="";
				def.IncomingPort="";
				def.OutgoingIpPort="";
				def.SftpInSocket="";
				def.SftpUsername="";
				def.SftpPassword="";
				def.FieldSeparator="|";
				def.ComponentSeparator="^";
				def.SubcomponentSeparator="&";
				def.RepetitionSeparator="~";
				def.EscapeCharacter=@"\";
				def.IsInternal=true;
				def.InternalType=HL7InternalType.eCWFull;
				def.InternalTypeVersion=Assembly.GetAssembly(typeof(Db)).GetName().Version.ToString();
				def.IsEnabled=false;
				def.Note="";
				def.ShowDemographics=HL7ShowDemographics.Show;
				def.ShowAccount=true;
				def.ShowAppts=false;//for now
				def.IsQuadAsToothNum=false;
			}
			def.hl7DefMessages=new List<HL7DefMessage>();//so that if this is called repeatedly, it won't pile on duplicate messages.
			//in either case, now get all child objects, which can't be in the database.
			#region Inbound Messages
				#region ADT - Patient Demographics (Admits, Discharges, and Transfers)
				//======================================================================================================================
				//eCW incoming patient information (ADT).
				HL7DefMessage msg=new HL7DefMessage();
				def.AddMessage(msg,MessageTypeHL7.ADT,MessageStructureHL7.ADT_A01,InOutHL7.Incoming,0);
				//MSH segment------------------------------------------------------------------
				HL7DefSegment seg=new HL7DefSegment();
				msg.AddSegment(seg,0,SegmentNameHL7.MSH);
				//MSH.8, Message Type
				seg.AddField(8,"messageType");
				//MSH.9, Message Control ID
				seg.AddField(9,"messageControlId");
				//PID segment------------------------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,2,SegmentNameHL7.PID);
				//PID.2, Patient ID
				seg.AddField(2,"pat.PatNum");
				//PID.4, Alternate Patient ID
				seg.AddField(4,"pat.ChartNumber");
				//PID.5, Patient Name
				seg.AddField(5,"pat.nameLFM");
				//PID.7, Date/Time of Birth
				seg.AddField(7,"pat.birthdateTime");
				//PID.8, Administrative Sex
				seg.AddField(8,"pat.Gender");
				//PID.10, Race
				seg.AddField(10,"pat.Race");
				//PID.11, Patient Address
				seg.AddField(11,"pat.addressCityStateZip");
				//PID.13, Phone Number - Home
				seg.AddField(13,"pat.HmPhone");
				//PID.14, Phone Number - Business
				seg.AddField(14,"pat.WkPhone");
				//PID.16, Marital Status
				seg.AddField(16,"pat.Position");
				//PID.19, SSN - Patient
				seg.AddField(19,"pat.SSN");
				//PID.22, Fee Schedule
				seg.AddField(22,"pat.FeeSched");
				//GT1 segment------------------------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,5,SegmentNameHL7.GT1);
				//GT1.2, Guarantor Number
				seg.AddField(2,"guar.PatNum");
				//GT1.3, Guarantor Name
				seg.AddField(3,"guar.nameLFM");
				//GT1.5, Guarantor Address
				seg.AddField(5,"guar.addressCityStateZip");
				//GT1.6, Guarantor Phone Number - Home
				seg.AddField(6,"guar.HmPhone");
				//GT1.7, Guarantor Phone Number - Business
				seg.AddField(7,"guar.WkPhone");
				//GT1.8, Guarantor Date/Time of Birth
				seg.AddField(8,"guar.birthdateTime");
				//GT1.9, Guarantor Administrative Sex
				seg.AddField(9,"guar.Gender");
				//GT1.12, Guarantor SSN
				seg.AddField(12,"guar.SSN");
				#endregion ADT - Patient Demographics (Admits, Discharges, and Transfers)
				#region SIU - Schedule Information Unsolicited
				//======================================================================================================================
				//eCW incoming appointment information (SIU - Schedule information unsolicited).
				msg=new HL7DefMessage();
				def.AddMessage(msg,MessageTypeHL7.SIU,MessageStructureHL7.SIU_S12,InOutHL7.Incoming,1);
				//MSH segment------------------------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,0,SegmentNameHL7.MSH);
				//MSH.8, Message Type
				seg.AddField(8,"messageType");
				//MSH.9, Message Control ID
				seg.AddField(9,"messageControlId");
				//PID segment------------------------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,2,SegmentNameHL7.PID);
				//PID.2
				seg.AddField(2,"pat.PatNum");
				//PID.4, Alternate Patient ID
				seg.AddField(4,"pat.ChartNumber");
				//PID.5, Patient Name
				seg.AddField(5,"pat.nameLFM");
				//PID.7, Date/Time of Birth
				seg.AddField(7,"pat.birthdateTime");
				//PID.8, Administrative Sex
				seg.AddField(8,"pat.Gender");
				//PID.10, Race
				seg.AddField(10,"pat.Race");
				//PID.11, Patient Address
				seg.AddField(11,"pat.addressCityStateZip");
				//PID.13, Phone Number - Home
				seg.AddField(13,"pat.HmPhone");
				//PID.14, Phone Number - Business
				seg.AddField(14,"pat.WkPhone");
				//PID.16, Marital Status
				seg.AddField(16,"pat.Position");
				//PID.19, SSN - Patient
				seg.AddField(19,"pat.SSN");
				//PID.22, Fee Schedule
				seg.AddField(22,"pat.FeeSched");
				//SCH segment------------------------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,1,SegmentNameHL7.SCH);
				//SCH.2, Filler Appointment ID.  In the old eCW interface, we were pulling from SCH.2, which was always the same as SCH.1.
				seg.AddField(2,"apt.AptNum");
				//SCH.7, Appointment Reason
				seg.AddField(7,"apt.Note");
				//SCH.11, Appointment Timing Quantity
				seg.AddField(11,"apt.lengthStartEnd");
				//AIG segment------------------------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,4,false,true,SegmentNameHL7.AIG);
				//AIG.3, Resource ID^Resource Name (Lname, Fname all as a string)
				seg.AddField(3,"prov.provIdName");
				//PV1 segment.-----------------------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,3,false,true,SegmentNameHL7.PV1);
				//PV1.7, Attending/Primary Care Doctor, UPIN^LastName^FirstName^MI
				seg.AddField(7,"prov.provIdNameLFM");
				#endregion SIU - Schedule Information Unsolicited
				#region ACK - General Acknowledgment
				//=======================================================================================================================
				//Acknowledgment message (ACK)
				msg=new HL7DefMessage();
				def.AddMessage(msg,MessageTypeHL7.ACK,MessageStructureHL7.ADT_A01,InOutHL7.Incoming,2);
				//MSH segment------------------------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,0,SegmentNameHL7.MSH);
				//MSH.8, Message Type
				seg.AddField(8,"messageType");
				//MSA (Message Acknowledgment) segment-----------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,1,SegmentNameHL7.MSA);
				//MSA.1, Acknowledgment Code
				seg.AddField(1,"ackCode");
				//MSA.2, Message Control ID
				seg.AddField(2,"messageControlId");
				#endregion ACK - General Acknowledgment
			#endregion Inbound Messages
			#region Outbound Messages
				#region DFT - Detailed Financial Transaction
				//=======================================================================================================================
				//Detail financial transaction (DFT)
				msg=new HL7DefMessage();
				def.AddMessage(msg,MessageTypeHL7.DFT,MessageStructureHL7.DFT_P03,InOutHL7.Outgoing,3);
				//MSH (Message Header) segment-------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,0,SegmentNameHL7.MSH);
				//MSH.1, Encoding Characters (DataType.ST)
				seg.AddField(1,"separators^~\\&");
				//MSH.2, Sending Application
				seg.AddFieldFixed(2,DataTypeHL7.HD,"OD");
				//MSH.4, Receiving Application
				seg.AddFieldFixed(4,DataTypeHL7.HD,"ECW");
				//MSH.6, Message Date and Time (YYYYMMDDHHMMSS)
				seg.AddField(6,"dateTime.Now");
				//MSH.8, Message Type^Event Type, example DFT^P03
				seg.AddField(8,"messageType");
				//MSH.9, Message Control ID
				seg.AddField(9,"messageControlId");
				//MSH.10, Processing ID (P-production, T-test)
				seg.AddFieldFixed(10,DataTypeHL7.PT,"P");
				//MSH.11, Version ID
				seg.AddFieldFixed(11,DataTypeHL7.VID,"2.3");
				//EVN (Event Type) segment-----------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,1,SegmentNameHL7.EVN);
				//EVN.1, Event Type, example P03
				seg.AddField(1,"eventType");
				//EVN.2, Recorded Date/Time
				seg.AddField(2,"dateTime.Now");
				//PID (Patient Identification) segment-----------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,2,SegmentNameHL7.PID);
				//PID.1, Sequence Number (1 for DFT's)
				seg.AddFieldFixed(1,DataTypeHL7.ST,"1");
				//PID.2, Patient ID (Account number.  eCW requires this to be the same # as came in on PID.4.)
				seg.AddField(2,"pat.ChartNumber");
				//PID.3, Patient MRN number
				seg.AddField(3,"pat.PatNum");
				//PID.5, Patient Name (Last^First^MI)
				seg.AddField(5,"pat.nameLFM");
				//PID.7, Birthdate
				seg.AddField(7,"pat.birthdateTime");
				//PID.8, Gender
				seg.AddField(8,"pat.Gender");
				//PID.10, Race
				seg.AddField(10,"pat.Race");
				//PID.11, Address
				seg.AddField(11,"pat.addressCityStateZip");
				//PID.13, Home Phone
				seg.AddField(13,"pat.HmPhone");
				//PID.14, Work Phone
				seg.AddField(14,"pat.WkPhone");
				//PID.16, Marital Status
				seg.AddField(16,"pat.Position");
				//PID.19, SSN
				seg.AddField(19,"pat.SSN");
				//PV1 (Patient Visit) segment--------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,3,SegmentNameHL7.PV1);
				//PV1.7, Attending/Primary Care Doctor
				seg.AddField(7,"prov.provIdNameLFM");
				//PV1.19, Visit Number
				seg.AddField(19,"apt.AptNum");
				//FT1 (Financial Transaction Information) segment------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,4,true,true,SegmentNameHL7.FT1);
				//FT1.1, Sequence Number (starts with 1)
				seg.AddField(1,"sequenceNum");
				//FT1.4, Transaction Date (YYYYMMDDHHMMSS)
				seg.AddField(4,"proc.procDateTime");
				//FT1.5, Transaction Posting Date (YYYYMMDDHHMMSS)
				seg.AddField(5,"proc.procDateTime");
				//FT1.6, Transaction Type
				seg.AddFieldFixed(6,DataTypeHL7.IS,"CG");
				//FT1.10, Transaction Quantity
				seg.AddFieldFixed(10,DataTypeHL7.NM,"1.0");
				//FT1.19, Diagnosis Code
				seg.AddField(19,"proc.DiagnosticCode");
				//FT1.20, Performed by Code (provider)
				seg.AddField(20,"prov.provIdNameLFM");
				//FT1.21, Ordering Provider
				seg.AddField(21,"prov.provIdNameLFM");
				//FT1.22, Unit Cost (procedure fee)
				seg.AddField(22,"proc.ProcFee");
				//FT1.25, Procedure Code
				seg.AddField(25,"proccode.ProcCode");
				//FT1.26, Modifiers (treatment area)
				seg.AddField(26,"proc.toothSurfRange");
				//DG1 (Diagnosis) segment is optional, skip for now
				//ZX1 (PDF Data) segment-------------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,5,SegmentNameHL7.ZX1);
				//ZX1.1
				seg.AddFieldFixed(1,DataTypeHL7.ST,"6");
				//ZX1.2
				seg.AddFieldFixed(2,DataTypeHL7.ST,"PDF");
				//ZX1.3
				seg.AddFieldFixed(3,DataTypeHL7.ST,"PATHOLOGY^Pathology Report^L");
				//ZX1.4
				seg.AddField(4,"pdfDescription");
				//ZX1.5
				seg.AddField(5,"pdfDataAsBase64");
				#endregion DFT - Detailed Financial Transaction
				#region ACK - General Acknowledgment
				//=======================================================================================================================
				//Message Acknowledgment (ACK)
				msg=new HL7DefMessage();
				def.AddMessage(msg,MessageTypeHL7.ACK,MessageStructureHL7.ADT_A01,InOutHL7.Outgoing,4);
				//MSH (Message Header) segment-------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,0,SegmentNameHL7.MSH);
				//MSH.1, Encoding Characters (DataType.ST)
				seg.AddField(1,"separators^~\\&");
				//MSH.2, Sending Application
				seg.AddFieldFixed(2,DataTypeHL7.HD,"OD");
				//MSH.4, Receiving Application
				seg.AddFieldFixed(4,DataTypeHL7.HD,"ECW");
				//MSH.6, Message Date and Time (YYYYMMDDHHMMSS)
				seg.AddField(6,"dateTime.Now");
				//MSH.8, Message Type^Event Type, example DFT^P03
				seg.AddField(8,"messageType");
				//MSH.9, Message Control ID
				seg.AddField(9,"messageControlId");
				//MSH.10, Processing ID (P-production, T-test)
				seg.AddFieldFixed(10,DataTypeHL7.PT,"P");
				//MSH.11, Version ID
				seg.AddFieldFixed(11,DataTypeHL7.VID,"2.3");
				//MSA (Message Acknowledgment) segment-----------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,1,SegmentNameHL7.MSA);
				//MSA.1, Acknowledgment Code
				seg.AddField(1,"ackCode");
				//MSA.2, Message Control ID
				seg.AddField(2,"messageControlId");
				#endregion ACK - General Acknowledgment
			#endregion Outbound Messages
			return def;
		}
예제 #33
0
        public static HL7Def GetDeepInternal(HL7Def def)
        {
            //ok to pass in null
            if (def == null)           //wasn't in the database
            {
                def                       = new HL7Def();
                def.IsNew                 = true;
                def.Description           = "MedLab HL7 v2.3";
                def.ModeTx                = ModeTxHL7.Sftp;
                def.IncomingFolder        = "";
                def.OutgoingFolder        = "";
                def.IncomingPort          = "";
                def.OutgoingIpPort        = "";
                def.SftpInSocket          = "";
                def.SftpUsername          = "";
                def.SftpPassword          = "";
                def.FieldSeparator        = "|";
                def.ComponentSeparator    = "^";
                def.SubcomponentSeparator = "&";
                def.RepetitionSeparator   = "~";
                def.EscapeCharacter       = @"\";
                def.IsInternal            = true;
                def.InternalType          = HL7InternalType.MedLabv2_3;
                def.InternalTypeVersion   = Assembly.GetAssembly(typeof(Db)).GetName().Version.ToString();
                def.IsEnabled             = false;
                def.Note                  = "";
                def.ShowDemographics      = HL7ShowDemographics.ChangeAndAdd;         //these last four properties will not be editable for a lab interface type
                def.ShowAccount           = true;
                def.ShowAppts             = true;
                def.IsQuadAsToothNum      = false;
            }
            def.hl7DefMessages = new List <HL7DefMessage>();
            HL7DefMessage msg = new HL7DefMessage();
            HL7DefSegment seg = new HL7DefSegment();

            #region Inbound Messages
            #region ORU - Unsolicited Observation Message
            def.AddMessage(msg, MessageTypeHL7.ORU, MessageStructureHL7.ORU_R01, InOutHL7.Incoming, 0);
            #region MSH - Message Header
            msg.AddSegment(seg, 0, SegmentNameHL7.MSH);
            //Fields-------------------------------------------------------------------------------------------------------------
            //MSH.2, Sending Application.  To identify the LabCorp Lab System sending the results.
            //Possible values for LabCorp (as of their v10.7 specs): '1100' - LabCorp Lab System, 'DIANON' - DIANON Systems,
            //'ADL' - Acupath Diagnostic Laboratories, 'EGL' - Esoterix Genetic Laboratories.
            //For backward compatibility only: 'CMBP', 'LITHOLINK', 'USLABS'
            seg.AddField(2, "sendingApp");
            //MSH.3, Sending Facility.  Identifies the LabCorp laboratory responsible for the client.
            //It could be a LabCorp assigned 'Responsible Lab Code' representing the responsible laboratory or it could be a CLIA number.
            seg.AddField(3, "sendingFacility");
            //MSH.8, Message Type
            seg.AddField(8, "messageType");
            //MSH.9, Message Control ID
            seg.AddField(9, "messageControlId");
            #endregion MSH - Message Header
            #region PID - Patient Identification
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 1, SegmentNameHL7.PID);
            //Fields-------------------------------------------------------------------------------------------------------------
            //PID.2, External Patient ID.  LabCorp defines this as 'client' assigned patient id, just like they do PID.4.
            //This should be the Open Dental patient number, sent in outbound PID.4 and returned in PID.2.
            seg.AddField(2, "pat.PatNum");
            //PID.3, Lab Assigned Patient ID.  LabCorp assigned specimen number.
            seg.AddField(3, "labPatID");
            //PID.4, Alternate Patient ID.  LabCorp defines this as a 'client' assigned patient id, just like they do PID.2.
            //This will be in outbound PID.2, returned in PID.4.
            seg.AddField(4, "altPatID");
            //PID.5, Patient Name
            //This will contain the last, first, and middle names as well as the title
            //Example:  LName^FName^MiddleI
            seg.AddField(5, "pat.nameLFM");
            //PID.7, Date/Time of Birth with Age
            //LabCorp uses this for the birthdate as well as the age in years, months, and days of the patient in the format bday^years^months^days.
            //All age components are left padded with 0's, the years is padded to 3 chars, the months and days are padded to 2 chars
            //Example: 19811213^033^02^19
            seg.AddField(7, "patBirthdateAge");
            //PID.8, Patient Gender
            //We use this field to assist the user in selecting a patient if one is not found when importing the message, but we don't store it
            seg.AddField(8, "pat.Gender");
            //PID.18.1, Patient Account Number.  LabCorp assigned account number.  This field is also used to send the Fasting flag in component 7.
            //Fasting flag values are 'Y', 'N', or blank
            //Example: AccountNum^^^BillCode^ABNFlag^SpecimenStatus^FastingFlag
            seg.AddField(18, "accountNum");
            //PID.19, Patient SSN Number
            //We use this field to assist the user in selecting a patient if one is not found when importing the message, but we don't store it
            seg.AddField(19, "pat.SSN");
            #endregion PID - Patient Identification
            #region NK1 - Next of Kin
            //This segment is for future use only, nothing is currently imported from this segment
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 2, false, true, SegmentNameHL7.NK1);
            //Fields-------------------------------------------------------------------------------------------------------------
            //NK1.2, Next of Kin Name
            //Example: LName^FName^Middle
            //seg.AddField(2,"nextOfKinName");
            //NK1.4, Next of Kin Address
            //Example: Address^Address2^City^State^Zip
            //seg.AddField(4,"nextOfKinAddress");
            //NK1.5, Next of Kin Phone
            //seg.AddField(5,"nextOfKinPhone");
            seg.hl7DefFields = new List <HL7DefField>();
            #endregion NK1 - Next of Kin
            #region NTE - Notes and Comments
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 3, true, true, SegmentNameHL7.NTE);
            //Fields-------------------------------------------------------------------------------------------------------------
            //NTE.2, Comment Source, ID data type
            //LabCorp supported values: 'L' - Laboratory is the source of comment, 'AC' - Accession Comment,
            //'RC' - Result comment, 'RI' - Normal Comment, 'UK' - Undefined comment type
            //We might pull out the source and prepend it to the note, but we won't explicitly add it to the definition or store it separately
            //NTE.3, Comment Text, FT data type (formatted text)
            //Stored in the medlab.NotePat field
            seg.AddField(3, "patNote");
            #endregion NTE - Notes and Comments
            #region ORC - Common Order
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 4, true, false, SegmentNameHL7.ORC);
            //Fields-------------------------------------------------------------------------------------------------------------
            //ORC.2, Unique Foreign Accession or Specimen ID
            //Must match the value in OBR.2 and is the ID value sent on the specimen container and is unique per patient order, not test order.
            //ORC.2.2 is the constant value 'LAB'
            //Example: L2435^LAB
            seg.AddField(2, "specimenID");
            //ORC.3, Filler Accession ID.  The LabCorp assigned specimen number.  These are reused on a yearly basis, but used with the client
            //specific specimen ID in ORC.2, these two numbers should uniquely identify a specimen/order.  ORC.3.2 is the constant value 'LAB'.
            //This should match OBR.3.
            //Example: 08599499950^LAB
            seg.AddField(3, "specimenIDFiller");
            //ORC.12, Ordering Provider, XCN Data Type
            //ProvID^ProvLName^ProvFName^ProvMiddleI^^^^SourceTable
            //This field repeats for every ID available for the provider with the SourceTable component identifying the type of ID in each repetition.
            //SourceTable possible values: 'U' - UPIN, 'P' - Provider Number (Medicaid or Commercial Insurance Provider ID),
            //'N' - NPI Number (Required for Third Party Billing), 'L' - Local (Physician ID)
            //Example: A12345^LNAME^FNAME^M^^^^U~23462^LNAME^FNAME^M^^^^L~0123456789^LNAME^FNAME^M^^^^N~1234567890^LNAME^FNAME^M^^^^P
            seg.AddField(12, "orderingProv");
            #endregion ORC - Common Order
            #region OBR - Observation Request
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 5, true, false, SegmentNameHL7.OBR);
            //Fields-------------------------------------------------------------------------------------------------------------
            //OBR.2, Unique Foreign Accession or Specimen ID
            //Must match the value in ORC.2 and is the ID value sent on the specimen container and is unique per patient order, not test order.
            //OBR.2.2 is the constant value 'LAB'.
            //Example: L2435^LAB
            seg.AddField(2, "specimenID");
            //OBR.3, Internal Accession ID.  The LabCorp assigned specimen number.  These are reused on a yearly basis, but used with the client
            //specific specimen ID in OBR.2, these two numbers should uniquely identify a specimen/order.  OBR.3.2 is the constant value 'LAB'.
            //This should match ORC.3.
            //Example: 08599499950^LAB
            seg.AddField(3, "specimenIDFiller");
            //OBR.4, Universal Service Identifier, CWE data type
            //This identifies the observation.  This will be the ID and text description of the test, as well as the LOINC code and description.
            //Example: 006072^RPR^L^20507-0^Reagin Ab^LN
            seg.AddField(4, "obsTestID");
            //OBR.7, Observation/Specimen Collection Date/Time
            //Format for LabCorp: yyyyMMddHHmm
            seg.AddField(7, "dateTimeCollected");
            //OBR.9, Collection/Urine Volume
            seg.AddField(9, "totalVolume");
            //OBR.11, Action Code
            //Used to identify the type of result being returned.  'A' - Add on, 'G' - Reflex, Blank for standard results
            seg.AddField(11, "specimenAction");
            //OBR.13, Relevant Clinical Information.  Used for informational purposes.
            seg.AddField(13, "clinicalInfo");
            //OBR.14, Date/Time of Specimen Receipt in Lab.
            //LabCorp format: yyyMMddHHmm
            seg.AddField(14, "dateTimeEntered");
            //OBR.16, Ordering Provider.
            //ProvID^ProvLName^ProvFName^ProvMiddleI^^^^SourceTable
            //This field repeats for every ID available for the provider with the SourceTable component identifying the type of ID in each repetition.
            //SourceTable possible values: 'U' - UPIN, 'P' - Provider Number (Medicaid or Commercial Insurance Provider ID),
            //'N' - NPI Number (Required for Third Party Billing), 'L' - Local (Physician ID)
            //Example: A12345^LNAME^FNAME^M^^^^U~23462^LNAME^FNAME^M^^^^L~0123456789^LNAME^FNAME^M^^^^N~1234567890^LNAME^FNAME^M^^^^P
            seg.AddField(16, "orderingProv");
            //OBR.18, Alternate Specimen ID.
            seg.AddField(18, "specimenIDAlt");
            //OBR.22, Date/Time Observation Reported.
            //LabCorp format: yyyyMMddHHmm
            seg.AddField(22, "dateTimeReported");
            //OBR.24, Producer's Section ID, used by LabCorp to identify the facility responsible for performing the testing.
            //This will be the footnote ID of the ZPS segment and will be used to attach a MedLab object to a MedLabFacility object.
            seg.AddField(24, "facilityID");
            //OBR.25, Order Result Status.
            //LabCorp values: 'F' - Final, 'P' - Preliminary, 'X' - Cancelled, 'C' - Corrected
            seg.AddField(25, "resultStatus");
            //OBR.26, Link to Parent Result.
            //If this is a reflex result, the value from the OBX.3.1 field of the parent result will be here.
            seg.AddField(26, "parentObsID");
            //OBR.29, Link to Parent Order.
            //If this is a reflex test, the value from the OBR.4.1 field of the parent test will be here.
            seg.AddField(29, "parentObsTestID");
            #endregion OBR - Observation Request
            #region NTE - Notes and Comments
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 6, true, true, SegmentNameHL7.NTE);
            //Fields-------------------------------------------------------------------------------------------------------------
            //NTE.2, Comment Source, ID data type
            //LabCorp supported values: 'L' - Laboratory is the source of comment, 'AC' - Accession Comment,
            //'RC' - Result comment, 'RI' - Normal Comment, 'UK' - Undefined comment type
            //We might pull out the source and prepend it to the note, but we won't explicitly add it to the definition or store it separately
            //NTE.3, Comment Text, FT data type (formatted text)
            //Stored in the medlab.NoteLab field
            seg.AddField(3, "labNote");
            #endregion NTE - Notes and Comments
            #region OBX - Observation/Result
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 7, true, false, SegmentNameHL7.OBX);
            //Fields-------------------------------------------------------------------------------------------------------------
            //OBX.2, Value Type.  This field is not stored explicitly, but it is used to determine the value type of the observation.
            //If this field is 'TX' for text, the value will be >21 chars and will be sent in the attached NTEs.
            seg.AddField(2, "obsValueType");
            //OBX.3, Observation ID.  This field has the same structure as the OBR.4.
            //ID^Text^CodeSystem^AltID^AltIDText^AltIDCodeSystem, the AltID is the LOINC code so the AltIDCodeSystem will be 'LN'
            //Example: 006072^RPR^L^20507-0^Reagin Ab^LN
            seg.AddField(3, "obsID");
            //OBX.4, Observation Sub ID.  This field is used to aid in the identification of results with the same observation ID (OBX.3) within a
            //given OBR.  If OBX.5.3 is 'ORM' (organism) this field will link a result to an organism, whether this is for organism #1, organism #2,
            //or organism #3.
            seg.AddField(4, "obsIDSub");
            //OBX.5, Observation Value.  ObsValue^TypeOfData^DataSubtype^Encoding^Data.  LabCorp report will display OBX.5.1 as the result.
            //For value >21 chars in length: OBX.2 will be 'TX' for text, OBX.5 will be NULL (empty field), and the value will be in attached NTEs.
            //"TNP" will be reported for Test Not Performed.
            seg.AddField(5, "obsValue");
            //OBX.6, Units.
            //Identifier^Text^CodeSystem.  Id is units of measure abbreviation, text is full text version of units, coding system is 'L' (local id).
            seg.AddField(6, "obsUnits");
            //OBX.7, Reference Range.
            seg.AddField(7, "obsRefRange");
            //OBX.8, Abnormal Flags.  For values see enum OpenDentBusiness.AbnormalFlag
            seg.AddField(8, "obsAbnormalFlag");
            //OBX.11, Observation Result Status.
            //LabCorp values: 'F' - Final, 'P' - Preliminary, 'X' - Cancelled, 'C' - Corrected, 'I' - Incomplete
            seg.AddField(11, "resultStatus");
            //OBX.14, Date/Time of Observation.
            //LabCorp format yyyyMMddHHmm
            seg.AddField(14, "dateTimeObs");
            //OBX.15, Producer's ID.
            //For LabCorp this is used to report the facility responsible for performing the testing.  This will hold the lab ID that will reference
            //a ZPS segment with the lab name, address, and director details.  Used to link a MedLabResult object to a MedLabFacility object.
            seg.AddField(15, "facilityID");
            #endregion OBX - Observation/Result
            #region ZEF - Encapsulated Data Format
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 8, true, true, SegmentNameHL7.ZEF);
            //Fields-------------------------------------------------------------------------------------------------------------
            //ZEF.1, Sequence Number, 1 through 9999
            seg.AddField(1, "sequenceNum");
            //ZEF.2, Embedded File.
            //Base64 embedded file, sent in 50k blocks and will be concatenated together to and converted back into
            seg.AddField(2, "base64File");
            #endregion ZEF - Encapsulated Data Format
            #region NTE - Notes and Comments
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 9, true, true, SegmentNameHL7.NTE);
            //Fields-------------------------------------------------------------------------------------------------------------
            //NTE.2, Comment Source, ID data type
            //LabCorp supported values: 'L' - Laboratory is the source of comment, 'AC' - Accession Comment,
            //'RC' - Result comment, 'RI' - Normal Comment, 'UK' - Undefined comment type
            //We might pull out the source and prepend it to the note, but we won't explicitly add it to the definition or store it separately
            //NTE.3, Comment Text, FT data type (formatted text)
            //Stored in the medlabresult.Note field
            seg.AddField(3, "obsNote");
            #endregion NTE - Notes and Comments
            #region SPM - Specimen
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 10, true, true, SegmentNameHL7.SPM);
            //Fields-------------------------------------------------------------------------------------------------------------
            //SPM.2, Specimen ID.
            //Unique ID of the specimen as sent on the specimen container.  Same as the value in ORC.2.
            seg.AddField(2, "specimenID");
            //SPM.4, Specimen Type
            //SPM.8, Specimen Source Site
            //SPM.4, Specimen Source Site Modifier
            //SPM.14, Specimen Description.  Text field used to send additional information about the specimen
            seg.AddField(14, "specimenDescript");
            //SPM.17, Date/Time Specimen Collected
            seg.AddField(17, "dateTimeSpecimen");
            #endregion SPM - Specimen
            #region ZPS - Place of Service
            seg = new HL7DefSegment();
            msg.AddSegment(seg, 11, true, false, SegmentNameHL7.ZPS);
            //Fields-------------------------------------------------------------------------------------------------------------
            //ZPS.2, Facility Mnemonic.  Footnote ID for the lab facility used to reference this segment from OBX.15.
            seg.AddField(2, "facilityID");
            //ZPS.3, Facility Name.
            seg.AddField(3, "facilityName");
            //ZPS.4, Facility Address.
            //Address^^City^State^Zip
            seg.AddField(4, "facilityAddress");
            //ZPS.5, Facility Phone.  (LabCorp document says numberic characters only, so we can assume no dashes or parentheses.)
            seg.AddField(5, "facilityPhone");
            //ZPS.7, Facility Director.
            //Title^LName^FName^MiddleI
            seg.AddField(7, "facilityDirector");
            #endregion ZPS - Place of Service
            #endregion ORU - Unsolicited Observation Message
            #endregion Inbound Messages
            #region Outbound Messages
            //Results only interface for now, so no outbound messages yet
            //In the future, we will implement the orders portion of the interface and have outbound ORM messages
            #endregion Outbound Messages
            return(def);
        }
예제 #34
0
        //Open \\SERVERFILES\storage\OPEN DENTAL\Programmers Documents\Standards (X12, ADA, etc)\HL7\Version2.6\V26_CH02_Control_M4_JAN2007.doc
        //At the top of page 33, there are rules for the recipient.
        //Basically, they state that parsing should not fail just because there are extra unexpected items.
        //And parsing should also not fail if expected items are missing.

        public static void Process(MessageHL7 msg, bool isVerboseLogging)
        {
            HL7MsgCur           = new HL7Msg();
            HL7MsgCur.HL7Status = HL7MessageStatus.InFailed;          //it will be marked InProcessed once data is inserted.
            HL7MsgCur.MsgText   = msg.ToString();
            HL7MsgCur.PatNum    = 0;
            HL7MsgCur.AptNum    = 0;
            List <HL7Msg> hl7Existing = HL7Msgs.GetOneExisting(HL7MsgCur);

            if (hl7Existing.Count > 0)           //This message is already in the db
            {
                HL7MsgCur.HL7MsgNum = hl7Existing[0].HL7MsgNum;
                HL7Msgs.UpdateDateTStamp(HL7MsgCur);
                msg.ControlId = HL7Msgs.GetControlId(HL7MsgCur);
                return;
            }
            else
            {
                //Insert as InFailed until processing is complete.  Update once complete, PatNum will have correct value, AptNum will have correct value if SIU message or 0 if ADT, and status changed to InProcessed
                HL7Msgs.Insert(HL7MsgCur);
            }
            IsVerboseLogging = isVerboseLogging;
            IsNewPat         = false;
            HL7Def def = HL7Defs.GetOneDeepEnabled();

            if (def == null)
            {
                HL7MsgCur.Note = "Could not process HL7 message.  No HL7 definition is enabled.";
                HL7Msgs.Update(HL7MsgCur);
                throw new Exception("Could not process HL7 message.  No HL7 definition is enabled.");
            }
            HL7DefMessage hl7defmsg = null;

            for (int i = 0; i < def.hl7DefMessages.Count; i++)
            {
                if (def.hl7DefMessages[i].MessageType == msg.MsgType)               //&& def.hl7DefMessages[i].EventType==msg.EventType) { //Ignoring event type for now, we will treat all ADT's and SIU's the same
                {
                    hl7defmsg = def.hl7DefMessages[i];
                }
            }
            if (hl7defmsg == null)           //No message definition matches this message's MessageType and EventType
            {
                HL7MsgCur.Note = "Could not process HL7 message.  No definition for this type of message in the enabled HL7Def.";
                HL7Msgs.Update(HL7MsgCur);
                throw new Exception("Could not process HL7 message.  No definition for this type of message in the enabled HL7Def.");
            }
            string   chartNum      = null;
            long     patNum        = 0;
            DateTime birthdate     = DateTime.MinValue;
            string   patLName      = null;
            string   patFName      = null;
            bool     isExistingPID = false;      //Needed to add note to hl7msg table if there isn't a PID segment in the message.

            //Get patient in question, incoming messages must have a PID segment so use that to find the pat in question
            for (int s = 0; s < hl7defmsg.hl7DefSegments.Count; s++)
            {
                if (hl7defmsg.hl7DefSegments[s].SegmentName != SegmentNameHL7.PID)
                {
                    continue;
                }
                int pidOrder = hl7defmsg.hl7DefSegments[s].ItemOrder;
                //we found the PID segment in the def, make sure it exists in the msg
                if (msg.Segments.Count <= pidOrder ||           //If the number of segments in the message is less than the item order of the PID segment
                    msg.Segments[pidOrder].GetField(0).ToString() != "PID"                      //Or if the segment we expect to be the PID segment is not the PID segment
                    )
                {
                    break;
                }
                isExistingPID = true;
                for (int f = 0; f < hl7defmsg.hl7DefSegments[s].hl7DefFields.Count; f++)           //Go through fields of PID segment and get patnum, chartnum, patient name, and/or birthdate to locate patient
                {
                    if (hl7defmsg.hl7DefSegments[s].hl7DefFields[f].FieldName == "pat.ChartNumber")
                    {
                        int chartNumOrdinal = hl7defmsg.hl7DefSegments[s].hl7DefFields[f].OrdinalPos;
                        chartNum = msg.Segments[pidOrder].Fields[chartNumOrdinal].ToString();
                    }
                    else if (hl7defmsg.hl7DefSegments[s].hl7DefFields[f].FieldName == "pat.PatNum")
                    {
                        int patNumOrdinal = hl7defmsg.hl7DefSegments[s].hl7DefFields[f].OrdinalPos;
                        patNum = PIn.Long(msg.Segments[pidOrder].Fields[patNumOrdinal].ToString());
                    }
                    else if (hl7defmsg.hl7DefSegments[s].hl7DefFields[f].FieldName == "pat.birthdateTime")
                    {
                        int patBdayOrdinal = hl7defmsg.hl7DefSegments[s].hl7DefFields[f].OrdinalPos;
                        birthdate = FieldParser.DateTimeParse(msg.Segments[pidOrder].Fields[patBdayOrdinal].ToString());
                    }
                    else if (hl7defmsg.hl7DefSegments[s].hl7DefFields[f].FieldName == "pat.nameLFM")
                    {
                        int patNameOrdinal = hl7defmsg.hl7DefSegments[s].hl7DefFields[f].OrdinalPos;
                        patLName = msg.Segments[pidOrder].GetFieldComponent(patNameOrdinal, 0);
                        patFName = msg.Segments[pidOrder].GetFieldComponent(patNameOrdinal, 1);
                    }
                }
            }
            if (!isExistingPID)
            {
                HL7MsgCur.Note = "Could not process the HL7 message due to missing PID segment.";
                HL7Msgs.Update(HL7MsgCur);
                throw new Exception("Could not process HL7 message.  Could not process the HL7 message due to missing PID segment.");
            }
            //We now have patnum, chartnum, patname, and/or birthdate so locate pat
            Patient pat    = null;
            Patient patOld = null;

            if (patNum != 0)
            {
                pat = Patients.GetPat(patNum);
            }
            if (def.InternalType != "eCWStandalone" && pat == null)
            {
                IsNewPat = true;
            }
            //In eCWstandalone integration, if we couldn't locate patient by patNum or patNum was 0 then pat will still be null so try to locate by chartNum if chartNum is not null
            if (def.InternalType == "eCWStandalone" && chartNum != null)
            {
                pat = Patients.GetPatByChartNumber(chartNum);
            }
            //In eCWstandalone integration, if pat is still null we need to try to locate patient by name and birthdate
            if (def.InternalType == "eCWStandalone" && pat == null)
            {
                long patNumByName = Patients.GetPatNumByNameAndBirthday(patLName, patFName, birthdate);
                //If patNumByName is 0 we couldn't locate by patNum, chartNum or name and birthdate so this message must be for a new patient
                if (patNumByName == 0)
                {
                    IsNewPat = true;
                }
                else
                {
                    pat             = Patients.GetPat(patNumByName);
                    patOld          = pat.Copy();
                    pat.ChartNumber = chartNum;                  //from now on, we will be able to find pat by chartNumber
                    Patients.Update(pat, patOld);
                }
            }
            if (IsNewPat)
            {
                pat = new Patient();
                if (chartNum != null)
                {
                    pat.ChartNumber = chartNum;
                }
                if (patNum != 0)
                {
                    pat.PatNum    = patNum;
                    pat.Guarantor = patNum;
                }
                pat.PriProv     = PrefC.GetLong(PrefName.PracticeDefaultProv);
                pat.BillingType = PrefC.GetLong(PrefName.PracticeDefaultBillType);
            }
            else
            {
                patOld = pat.Copy();
            }
            //Update hl7msg table with correct PatNum for this message
            HL7MsgCur.PatNum = pat.PatNum;
            HL7Msgs.Update(HL7MsgCur);
            //If this is a message that contains an SCH segment, loop through to find the AptNum.  Pass it to the other segments that will need it.
            long aptNum = 0;

            for (int s = 0; s < hl7defmsg.hl7DefSegments.Count; s++)
            {
                if (hl7defmsg.hl7DefSegments[s].SegmentName != SegmentNameHL7.SCH)
                {
                    continue;
                }
                //we found the SCH segment
                int schOrder = hl7defmsg.hl7DefSegments[s].ItemOrder;
                for (int f = 0; f < hl7defmsg.hl7DefSegments[s].hl7DefFields.Count; f++)           //Go through fields of SCH segment and get AptNum
                {
                    if (hl7defmsg.hl7DefSegments[s].hl7DefFields[f].FieldName == "apt.AptNum")
                    {
                        int aptNumOrdinal = hl7defmsg.hl7DefSegments[s].hl7DefFields[f].OrdinalPos;
                        aptNum = PIn.Long(msg.Segments[schOrder].Fields[aptNumOrdinal].ToString());
                    }
                }
            }
            //We now have a patient object , either loaded from the db or new, and aptNum so process this message for this patient
            //We need to insert the pat to get a patnum so we can compare to guar patnum to see if relationship to guar is self
            if (IsNewPat)
            {
                if (isVerboseLogging)
                {
                    EventLog.WriteEntry("OpenDentHL7", "Inserted patient: " + pat.FName + " " + pat.LName, EventLogEntryType.Information);
                }
                if (pat.PatNum == 0)
                {
                    pat.PatNum = Patients.Insert(pat, false);
                }
                else
                {
                    pat.PatNum = Patients.Insert(pat, true);
                }
                patOld = pat.Copy();
            }
            for (int i = 0; i < hl7defmsg.hl7DefSegments.Count; i++)
            {
                try {
                    SegmentHL7 seg = msg.GetSegment(hl7defmsg.hl7DefSegments[i].SegmentName, !hl7defmsg.hl7DefSegments[i].IsOptional);
                    if (seg != null)                   //null if segment was not found but is optional
                    {
                        ProcessSeg(pat, aptNum, hl7defmsg.hl7DefSegments[i], seg, msg);
                    }
                }
                catch (ApplicationException ex) {               //Required segment was missing, or other error.
                    HL7MsgCur.Note = "Could not process this HL7 message.  " + ex;
                    HL7Msgs.Update(HL7MsgCur);
                    throw new Exception("Could not process HL7 message.  " + ex);
                }
            }
            //We have processed the message so now update or insert the patient
            if (pat.FName == "" || pat.LName == "")
            {
                EventLog.WriteEntry("OpenDentHL7", "Patient demographics not processed due to missing first or last name. PatNum:" + pat.PatNum.ToString()
                                    , EventLogEntryType.Information);
                HL7MsgCur.Note = "Patient demographics not processed due to missing first or last name. PatNum:" + pat.PatNum.ToString();
                HL7Msgs.Update(HL7MsgCur);
                return;
            }
            if (IsNewPat)
            {
                if (pat.Guarantor == 0)
                {
                    pat.Guarantor = pat.PatNum;
                    Patients.Update(pat, patOld);
                }
                else
                {
                    Patients.Update(pat, patOld);
                }
            }
            else
            {
                if (isVerboseLogging)
                {
                    EventLog.WriteEntry("OpenDentHL7", "Updated patient: " + pat.FName + " " + pat.LName, EventLogEntryType.Information);
                }
                Patients.Update(pat, patOld);
            }
            HL7MsgCur.HL7Status = HL7MessageStatus.InProcessed;
            HL7Msgs.Update(HL7MsgCur);
        }
예제 #35
0
		public static HL7Def GetDeepInternal(HL7Def def) {
			//ok to pass in null
			if(def==null) {//wasn't in the database
				def=new HL7Def();
				def.IsNew=true;
				def.Description="Centricity";
				def.ModeTx=ModeTxHL7.File;
				def.IncomingFolder="";
				def.OutgoingFolder="";
				def.IncomingPort="";
				def.OutgoingIpPort="";
				def.SftpInSocket="";
				def.SftpUsername="";
				def.SftpPassword="";
				def.FieldSeparator="|";
				def.ComponentSeparator="^";
				def.SubcomponentSeparator="&";
				def.RepetitionSeparator="~";
				def.EscapeCharacter=@"\";
				def.IsInternal=true;
				def.InternalType=HL7InternalType.Centricity;
				def.InternalTypeVersion=Assembly.GetAssembly(typeof(Db)).GetName().Version.ToString();
				def.IsEnabled=false;
				def.Note="";
				def.ShowDemographics=HL7ShowDemographics.ChangeAndAdd;
				def.ShowAccount=true;
				def.ShowAppts=true;
				def.IsQuadAsToothNum=false;
			}
			def.hl7DefMessages=new List<HL7DefMessage>();
			HL7DefMessage msg=new HL7DefMessage();
			HL7DefSegment seg=new HL7DefSegment();
			#region Outbound Messages
				#region DFT - Detailed Financial Transaction
				//=======================================================================================================================
				//Detail financial transaction (DFT)
				def.AddMessage(msg,MessageTypeHL7.DFT,MessageStructureHL7.DFT_P03,InOutHL7.Outgoing,2);
				//MSH (Message Header) segment-------------------------------------------------
				msg.AddSegment(seg,0,SegmentNameHL7.MSH);
				//HL7 documentation says field 1 is Field Separator.  "This field contains the separator between the segment ID and the first real field.  As such it serves as the separator and defines the character to be used as a separator for the rest of the message." (HL7 v2.6 documentation) The separator is usually | (pipes) and is part of field 0, which is the segment ID followed by a |.  Encoding Characters is the first real field, so it will be numbered starting with 1 in our def.
				//MSH.1, Encoding Characters (DataType.ST)
				seg.AddField(1,"separators^~\\&");
				//MSH.2, Sending Application
				seg.AddFieldFixed(2,DataTypeHL7.HD,"OD");
				//MSH.4, Receiving Application
				seg.AddFieldFixed(4,DataTypeHL7.HD,def.Description);
				//MSH.6, Message Date and Time (YYYYMMDDHHMMSS)
				seg.AddField(6,"dateTime.Now");
				//MSH.8, Message Type^Event Type, example DFT^P03
				seg.AddField(8,"messageType");
				//MSH.9, Message Control ID
				seg.AddField(9,"messageControlId");
				//MSH.10, Processing ID (P-production, T-test)
				seg.AddFieldFixed(10,DataTypeHL7.PT,"P");
				//MSH.11, Version ID
				seg.AddFieldFixed(11,DataTypeHL7.VID,"2.3");
				//MSH.16, Application Ack Type (AL=Always, NE=Never, ER=Error/reject conditions only, SU=Successful completion only)
				seg.AddFieldFixed(15,DataTypeHL7.ID,"NE");
				//EVN (Event Type) segment-----------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,1,SegmentNameHL7.EVN);
				//EVN.1, Event Type, example P03
				seg.AddField(1,"eventType");
				//EVN.2, Recorded Date/Time
				seg.AddField(2,"dateTime.Now");
				//EVN.3, Event Reason Code
				seg.AddFieldFixed(3,DataTypeHL7.IS,"01");
				//PID (Patient Identification) segment-----------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,2,SegmentNameHL7.PID);
				//PID.1, Sequence Number (1 for DFT's)  "This field contains the number that identifies this transaction.  For the first occurrence of the segment, the sequence number shall be one, for the second occurrence, the sequence number shall be two, etc." (HL7 v2.6 documentation)  We only send 1 PID segment in DFT's so this number will always be 1.
				seg.AddFieldFixed(1,DataTypeHL7.SI,"1");
				//PID.2, Patient ID (External)
				seg.AddField(2,"pat.ChartNumber");
				//PID.3, Patient ID (Internal)
				seg.AddField(3,"pat.PatNum");
				//PV1 (Patient Visit) segment--------------------------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,3,SegmentNameHL7.PV1);
				//PV1.1, Set ID - PV1 (1 for DFT's)  See the comment above for the Sequence Number of the PID segment.  Always 1 since we only send one PV1 segment per DFT message.
				seg.AddFieldFixed(1,DataTypeHL7.SI,"1");
				//PV1.2, Patient Class  (E=Emergency, I=Inpatient, O=Outpatient, P=Preadmit, R=Recurring patient, B=Obstetrics, C=Commercial Account, N=Not Applicable, U=Unkown)  We will just send O for outpatient for every DFT message.
				seg.AddFieldFixed(2,DataTypeHL7.IS,"O");
	//todo: ClinicNum?
				//PV1.3, Assigned Patient Location
				//PV1.7, Attending/Primary Care Doctor
				seg.AddField(7,"prov.provIdNameLFM");
	//todo: Referring Dr?
				//PV1.8, Referring Doctor
				//PV1.19, Visit Number
				seg.AddField(19,"apt.AptNum");
				//PV1.44, Admit Date/Time
				seg.AddField(44,"proc.procDateTime");
				//PV1.50, Alternate Visit ID
				//FT1 (Financial Transaction Information) segment------------------------------
				seg=new HL7DefSegment();
				msg.AddSegment(seg,4,true,true,SegmentNameHL7.FT1);
				//FT1.1, Sequence Number (starts with 1)
				seg.AddField(1,"sequenceNum");
				//FT1.2, Transaction ID
				seg.AddField(2,"proc.ProcNum");
				//FT1.4, Transaction Date (YYYYMMDDHHMMSS)
				seg.AddField(4,"proc.procDateTime");
				//FT1.5, Transaction Posting Date (YYYYMMDDHHMMSS)
				seg.AddField(5,"proc.procDateTime");
				//FT1.6, Transaction Type
				seg.AddFieldFixed(6,DataTypeHL7.IS,"CG");
				//FT1.10, Transaction Quantity
				seg.AddFieldFixed(10,DataTypeHL7.NM,"1.0");
				//FT1.11, Transaction Amount Extended (Total fee to charge for this procedure, independent of transaction quantity)
				seg.AddField(11,"proc.ProcFee");
				//FT1.12, Transaction Amount Unit (Fee for this procedure for each transaction quantity)
				seg.AddField(12,"proc.ProcFee");
	//todo: ClinicNum?
				//FT1.16, Assigned Patient Location
				//FT1.19, Diagnosis Code
				seg.AddField(19,"proc.DiagnosticCode");
				//FT1.21, Ordering Provider
				seg.AddField(21,"prov.provIdNameLFM");
				//FT1.22, Unit Cost (procedure fee)
				seg.AddField(22,"proc.ProcFee");
				//FT1.25, Procedure Code
				seg.AddField(25,"proccode.ProcCode");
				//FT1.26, Modifiers (treatment area)
				seg.AddField(26,"proc.toothSurfRange");
				//DG1 (Diagnosis) segment is optional, skip for now
				//PR1 (Procedures) segment is optional, skip for now
				#endregion DFT - Detailed Financial Transaction
			#endregion Outbound Messages
			return def;
		}