/// <summary>Gets from cache. This will return null if no HL7defs are enabled. Since only one can be enabled, this will return only the enabled one. No need to check RemotingRole, cache is filled by calling GetTableRemotelyIfNeeded.</summary> public static HL7Def GetOneDeepEnabled() { HL7Def retval = null; for (int i = 0; i < Listt.Count; i++) { if (Listt[i].IsEnabled) { retval = Listt[i]; } } if (retval == null) { return(null); } if (retval.IsInternal) //if internal, messages, segments, and fields will not be in the database { GetDeepForInternal(retval); } else { retval.hl7DefMessages = HL7DefMessages.GetDeepFromCache(retval.HL7DefNum); } return(retval); }
///<summary>Gets from C# internal code rather than db</summary> private static void GetDeepForInternal(HL7Def def) { //No need to check RemotingRole; no call to db. if (def.InternalType == HL7InternalType.eCWFull) { def = InternalEcwFull.GetDeepInternal(def); //def that we're passing in is guaranteed to not be null } else if (def.InternalType == HL7InternalType.eCWStandalone) { def = InternalEcwStandalone.GetDeepInternal(def); } else if (def.InternalType == HL7InternalType.eCWTight) { def = InternalEcwTight.GetDeepInternal(def); } else if (def.InternalType == HL7InternalType.Centricity) { def = InternalCentricity.GetDeepInternal(def); } else if (def.InternalType == HL7InternalType.HL7v2_6) { def = InternalHL7v2_6.GetDeepInternal(def); } else if (def.InternalType == HL7InternalType.MedLabv2_3) { def = MedLabv2_3.GetDeepInternal(def); } //no need to return a def because the original reference won't have been lost. }
///<summary>Only used from Unit Tests. Since we clear the db of hl7Defs we have to insert this internal def not update it.</summary> public static void EnableInternalForTests(string internalType) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), internalType); return; } HL7Def hl7Def = null; List <HL7Def> defList = GetDeepInternalList(); for (int i = 0; i < defList.Count; i++) { if (defList[i].InternalType == internalType) { hl7Def = defList[i]; break; } } if (hl7Def == null) { return; } hl7Def.IsEnabled = true; Insert(hl7Def); }
///<summary>Gets the message control ID of the message we are attempting to send, for TCP/IP acknowledgment.</summary> public static string GetControlId(HL7Msg msg) { string retval = ""; if (msg == null) { return(retval); } int controlIdOrder = 0; MessageHL7 msgHl7 = new MessageHL7(msg.MsgText); //creates the segments HL7Def def = HL7Defs.GetOneDeepEnabled(); if (def == null) { return(retval); } HL7DefMessage hl7defmsg = null; for (int i = 0; i < def.hl7DefMessages.Count; i++) { if (def.hl7DefMessages[i].MessageType == msgHl7.MsgType) { hl7defmsg = def.hl7DefMessages[i]; break; } } if (hl7defmsg == null) //No message definition for this type of message in the enabled def { return(retval); } for (int s = 0; s < hl7defmsg.hl7DefSegments.Count; s++) //get MSH segment { if (hl7defmsg.hl7DefSegments[s].SegmentName == SegmentNameHL7.MSH) { for (int f = 0; f < hl7defmsg.hl7DefSegments[s].hl7DefFields.Count; f++) //find messageControlId field in MSH segment def { if (hl7defmsg.hl7DefSegments[s].hl7DefFields[f].FieldName == "messageControlId") { controlIdOrder = hl7defmsg.hl7DefSegments[s].hl7DefFields[f].OrdinalPos; break; } } break; } } if (controlIdOrder == 0) //No messageControlId defined for this MSH segment { return(retval); } for (int i = 0; i < msgHl7.Segments.Count; i++) //get control ID from message located in MSH segment with field determined above { if (msgHl7.Segments[i].Name == SegmentNameHL7.MSH) { retval = msgHl7.Segments[i].Fields[controlIdOrder].ToString(); break; } } return(retval); }
///<summary></summary> public static void Update(HL7Def hL7Def) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), hL7Def); return; } Crud.HL7DefCrud.Update(hL7Def); }
///<summary></summary> public static long Insert(HL7Def hL7Def) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { hL7Def.HL7DefNum = Meth.GetLong(MethodBase.GetCurrentMethod(), hL7Def); return(hL7Def.HL7DefNum); } return(Crud.HL7DefCrud.Insert(hL7Def)); }
///<summary>Gets from cache. If isMedLabHL7 is true, this will only return the enabled def if it is HL7InternalType.MedLabv2_3. ///If false, then only those defs not of that type. This will return null if no HL7defs are enabled. Since only one can be enabled, ///this will return only one. No need to check RemotingRole, cache is filled by calling GetTableRemotelyIfNeeded.</summary> public static HL7Def GetOneDeepEnabled(bool isMedLabHL7) { HL7Def retval = GetFirstOrDefault(x => x.IsEnabled && isMedLabHL7 == (x.InternalType == HL7InternalType.MedLabv2_3)); if (retval == null) { return(null); } if (retval.IsInternal) //if internal, messages, segments, and fields will not be in the database { GetDeepForInternal(retval); } else { retval.hl7DefMessages = HL7DefMessages.GetDeepFromCache(retval.HL7DefNum); } return(retval); }
public void StartManually() { //connect to OD db. XmlDocument document=new XmlDocument(); string pathXml=Path.Combine(Application.StartupPath,"FreeDentalConfig.xml"); try{ document.Load(pathXml); } catch{ EventLog.WriteEntry("OpenDentHL7",DateTime.Now.ToLongTimeString()+" - Could not find "+pathXml,EventLogEntryType.Error); throw new ApplicationException("Could not find "+pathXml); } XPathNavigator Navigator=document.CreateNavigator(); XPathNavigator nav; DataConnection.DBtype=DatabaseType.MySql; nav=Navigator.SelectSingleNode("//DatabaseConnection"); string computerName=nav.SelectSingleNode("ComputerName").Value; string database=nav.SelectSingleNode("Database").Value; string user=nav.SelectSingleNode("User").Value; string password=nav.SelectSingleNode("Password").Value; XPathNavigator verboseNav=Navigator.SelectSingleNode("//HL7verbose"); if(verboseNav!=null && verboseNav.Value=="True") { IsVerboseLogging=true; EventLog.WriteEntry("OpenDentHL7","Verbose mode.",EventLogEntryType.Information); } OpenDentBusiness.DataConnection dcon=new OpenDentBusiness.DataConnection(); //Try to connect to the database directly try { dcon.SetDb(computerName,database,user,password,"","",DataConnection.DBtype); //a direct connection does not utilize lower privileges. RemotingClient.RemotingRole=RemotingRole.ClientDirect; } catch {//(Exception ex){ throw new ApplicationException("Connection to database failed."); } //check db version string dbVersion=PrefC.GetString(PrefName.ProgramVersion); if(Application.ProductVersion.ToString() != dbVersion) { EventLog.WriteEntry("OpenDentHL7","Versions do not match. Db version:"+dbVersion+". Application version:"+Application.ProductVersion.ToString(),EventLogEntryType.Error); throw new ApplicationException("Versions do not match. Db version:"+dbVersion+". Application version:"+Application.ProductVersion.ToString()); } if(Programs.IsEnabled(ProgramName.eClinicalWorks) && !HL7Defs.IsExistingHL7Enabled()) {//eCW enabled, and no HL7def enabled. //prevent startup: long progNum=Programs.GetProgramNum(ProgramName.eClinicalWorks); string hl7Server=ProgramProperties.GetPropVal(progNum,"HL7Server"); string hl7ServiceName=ProgramProperties.GetPropVal(progNum,"HL7ServiceName"); if(hl7Server=="") {//for the first time run ProgramProperties.SetProperty(progNum,"HL7Server",System.Environment.MachineName); hl7Server=System.Environment.MachineName; } if(hl7ServiceName=="") {//for the first time run ProgramProperties.SetProperty(progNum,"HL7ServiceName",this.ServiceName); hl7ServiceName=this.ServiceName; } if(hl7Server.ToLower()!=System.Environment.MachineName.ToLower()) { EventLog.WriteEntry("OpenDentHL7","The HL7 Server name does not match the name set in Program Links eClinicalWorks Setup. Server name: "+System.Environment.MachineName +", Server name in Program Links: "+hl7Server,EventLogEntryType.Error); throw new ApplicationException("The HL7 Server name does not match the name set in Program Links eClinicalWorks Setup. Server name: "+System.Environment.MachineName +", Server name in Program Links: "+hl7Server); } if(hl7ServiceName.ToLower()!=this.ServiceName.ToLower()) { EventLog.WriteEntry("OpenDentHL7","The HL7 Service Name does not match the name set in Program Links eClinicalWorks Setup. Service name: "+this.ServiceName+", Service name in Program Links: " +hl7ServiceName,EventLogEntryType.Error); throw new ApplicationException("The HL7 Service Name does not match the name set in Program Links eClinicalWorks Setup. Service name: "+this.ServiceName+", Service name in Program Links: " +hl7ServiceName); } EcwOldSendAndReceive(); return; } HL7Def hL7Def=HL7Defs.GetOneDeepEnabled(); if(hL7Def==null) { return; } if(hL7Def.HL7Server=="") { hL7Def.HL7Server=System.Environment.MachineName; HL7Defs.Update(hL7Def); } if(hL7Def.HL7ServiceName=="") { hL7Def.HL7ServiceName=this.ServiceName; HL7Defs.Update(hL7Def); } if(hL7Def.HL7Server.ToLower()!=System.Environment.MachineName.ToLower()) { EventLog.WriteEntry("OpenDentHL7","The HL7 Server name does not match the name in the enabled HL7Def Setup. Server name: "+System.Environment.MachineName+", Server name in HL7Def: "+hL7Def.HL7Server, EventLogEntryType.Error); throw new ApplicationException("The HL7 Server name does not match the name in the enabled HL7Def Setup. Server name: "+System.Environment.MachineName+", Server name in HL7Def: "+hL7Def.HL7Server); } if(hL7Def.HL7ServiceName.ToLower()!=this.ServiceName.ToLower()) { EventLog.WriteEntry("OpenDentHL7","The HL7 Service Name does not match the name in the enabled HL7Def Setup. Service name: "+this.ServiceName+", Service name in HL7Def: "+hL7Def.HL7ServiceName, EventLogEntryType.Error); throw new ApplicationException("The HL7 Service Name does not match the name in the enabled HL7Def Setup. Service name: "+this.ServiceName+", Service name in HL7Def: "+hL7Def.HL7ServiceName); } HL7DefEnabled=hL7Def;//so we can access it later from other methods if(HL7DefEnabled.ModeTx==ModeTxHL7.File) { hl7FolderOut=HL7DefEnabled.OutgoingFolder; hl7FolderIn=HL7DefEnabled.IncomingFolder; if(!Directory.Exists(hl7FolderOut)) { EventLog.WriteEntry("OpenDentHL7","The outgoing HL7 folder does not exist. Path is set to: "+hl7FolderOut,EventLogEntryType.Error); throw new ApplicationException("The outgoing HL7 folder does not exist. Path is set to: "+hl7FolderOut); } if(!Directory.Exists(hl7FolderIn)) { EventLog.WriteEntry("OpenDentHL7","The incoming HL7 folder does not exist. Path is set to: "+hl7FolderIn,EventLogEntryType.Error); throw new ApplicationException("The incoming HL7 folder does not exist. Path is set to: "+hl7FolderIn); } //start polling the folder for waiting messages to import. Every 5 seconds. TimerCallback timercallbackReceive=new TimerCallback(TimerCallbackReceiveFiles); timerReceiveFiles=new System.Threading.Timer(timercallbackReceive,null,5000,5000); //start polling the db for new HL7 messages to send. Every 1.8 seconds. TimerCallback timercallbackSend=new TimerCallback(TimerCallbackSendFiles); timerSendFiles=new System.Threading.Timer(timercallbackSend,null,1800,1800); } else {//TCP/IP CreateIncomingTcpListener(); //start a timer to poll the database and to send messages as needed. Every 6 seconds. We increased the time between polling the database from 3 seconds to 6 seconds because we are now waiting 5 seconds for a message acknowledgment from eCW. TimerCallback timercallbackSendTCP=new TimerCallback(TimerCallbackSendTCP); timerSendTCP=new System.Threading.Timer(timercallbackSendTCP,null,1800,6000); } }
///<summary>Gets from C# internal code rather than db</summary> private static void GetDeepForInternal(HL7Def def) { //No need to check RemotingRole; no call to db. if(def.InternalType=="eCWFull") { def=InternalEcwFull.GetDeepInternal(def);//def that we're passing in is guaranteed to not be null } else if(def.InternalType=="eCWStandalone") { def=InternalEcwStandalone.GetDeepInternal(def); } else if(def.InternalType=="eCWTight") { def=InternalEcwTight.GetDeepInternal(def); } else if(def.InternalType=="Centricity") { def=InternalCentricity.GetDeepInternal(def); } //no need to return a def because the original reference won't have been lost. }
///<summary></summary> public static void Update(HL7Def hL7Def) { if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(),hL7Def); return; } Crud.HL7DefCrud.Update(hL7Def); }
///<summary></summary> public static long Insert(HL7Def hL7Def) { if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) { hL7Def.HL7DefNum=Meth.GetLong(MethodBase.GetCurrentMethod(),hL7Def); return hL7Def.HL7DefNum; } return Crud.HL7DefCrud.Insert(hL7Def); }
public void StartManually() { //connect to OD db. XmlDocument document=new XmlDocument(); string pathXml=Path.Combine(Application.StartupPath,"FreeDentalConfig.xml"); try { document.Load(pathXml); } catch { EventLog.WriteEntry("OpenDentHL7",DateTime.Now.ToLongTimeString()+" - Could not find "+pathXml,EventLogEntryType.Error); throw new ApplicationException("Could not find "+pathXml); } XPathNavigator Navigator=document.CreateNavigator(); XPathNavigator nav; DataConnection.DBtype=DatabaseType.MySql; nav=Navigator.SelectSingleNode("//DatabaseConnection"); string computerName=nav.SelectSingleNode("ComputerName").Value; string database=nav.SelectSingleNode("Database").Value; string user=nav.SelectSingleNode("User").Value; string password=nav.SelectSingleNode("Password").Value; XPathNavigator verboseNav=Navigator.SelectSingleNode("//HL7verbose"); if(verboseNav!=null && verboseNav.Value=="True") { IsVerboseLogging=true; EventLog.WriteEntry("OpenDentHL7","Verbose mode.",EventLogEntryType.Information); } OpenDentBusiness.DataConnection dcon=new OpenDentBusiness.DataConnection(); //Try to connect to the database directly try { dcon.SetDb(computerName,database,user,password,"","",DataConnection.DBtype); //a direct connection does not utilize lower privileges. RemotingClient.RemotingRole=RemotingRole.ClientDirect; } catch {//(Exception ex){ throw new ApplicationException("Connection to database failed."); } //check db version string dbVersion=PrefC.GetString(PrefName.ProgramVersion); if(Application.ProductVersion.ToString() != dbVersion) { EventLog.WriteEntry("OpenDentHL7","Versions do not match. Db version:"+dbVersion+". Application version:"+Application.ProductVersion.ToString(),EventLogEntryType.Error); throw new ApplicationException("Versions do not match. Db version:"+dbVersion+". Application version:"+Application.ProductVersion.ToString()); } #region MedLab HL7 _medLabHL7DefEnabled=HL7Defs.GetOneDeepEnabled(true); if(_medLabHL7DefEnabled!=null) { if(_medLabHL7DefEnabled.HL7Server=="") { _medLabHL7DefEnabled.HL7Server=System.Environment.MachineName; HL7Defs.Update(_medLabHL7DefEnabled); } if(_medLabHL7DefEnabled.HL7ServiceName=="") { _medLabHL7DefEnabled.HL7ServiceName=this.ServiceName; HL7Defs.Update(_medLabHL7DefEnabled); } if(_medLabHL7DefEnabled.HL7Server.ToLower()!=System.Environment.MachineName.ToLower()) { EventLog.WriteEntry("OpenDentHL7","The HL7 Server name does not match the name in the enabled MedLab HL7Def Setup. Server name: " +System.Environment.MachineName+", Server name in MedLab HL7Def: "+_medLabHL7DefEnabled.HL7Server,EventLogEntryType.Error); throw new ApplicationException("The HL7 Server name does not match the name in the enabled MedLab HL7Def Setup. Server name: " +System.Environment.MachineName+", Server name in MedLab HL7Def: "+_medLabHL7DefEnabled.HL7Server); } if(_medLabHL7DefEnabled.HL7ServiceName.ToLower()!=this.ServiceName.ToLower()) { EventLog.WriteEntry("OpenDentHL7","The MedLab HL7 Service Name does not match the name in the enabled MedLab HL7Def Setup. Service name: " +this.ServiceName+", Service name in MedLab HL7Def: "+_medLabHL7DefEnabled.HL7ServiceName,EventLogEntryType.Error); throw new ApplicationException("The MedLab HL7 Service Name does not match the name in the enabled MedLab HL7Def Setup. Service name: " +this.ServiceName+", Service name in MedLab HL7Def: "+_medLabHL7DefEnabled.HL7ServiceName); } _sftpModeIsReceiving=false; TimerCallback timerCallbackSftpGetFiles=new TimerCallback(TimerCallbackSftpGetFiles); _timerSftpGetFiles=new System.Threading.Timer(timerCallbackSftpGetFiles,null,1000,60000);//attempt to connect to the sftp server once a minute } #endregion MedLab HL7 #region eCW Send and Receive OLD if(Programs.IsEnabled(ProgramName.eClinicalWorks) && !HL7Defs.IsExistingHL7Enabled()) {//eCW enabled, and no HL7def enabled. //prevent startup: long progNum=Programs.GetProgramNum(ProgramName.eClinicalWorks); string hl7Server=ProgramProperties.GetPropVal(progNum,"HL7Server"); string hl7ServiceName=ProgramProperties.GetPropVal(progNum,"HL7ServiceName"); if(hl7Server=="") {//for the first time run ProgramProperties.SetProperty(progNum,"HL7Server",System.Environment.MachineName); hl7Server=System.Environment.MachineName; } if(hl7ServiceName=="") {//for the first time run ProgramProperties.SetProperty(progNum,"HL7ServiceName",this.ServiceName); hl7ServiceName=this.ServiceName; } if(hl7Server.ToLower()!=System.Environment.MachineName.ToLower()) { EventLog.WriteEntry("OpenDentHL7","The HL7 Server name does not match the name set in Program Links eClinicalWorks Setup. Server name: "+System.Environment.MachineName +", Server name in Program Links: "+hl7Server,EventLogEntryType.Error); throw new ApplicationException("The HL7 Server name does not match the name set in Program Links eClinicalWorks Setup. Server name: "+System.Environment.MachineName +", Server name in Program Links: "+hl7Server); } if(hl7ServiceName.ToLower()!=this.ServiceName.ToLower()) { EventLog.WriteEntry("OpenDentHL7","The HL7 Service Name does not match the name set in Program Links eClinicalWorks Setup. Service name: "+this.ServiceName+", Service name in Program Links: " +hl7ServiceName,EventLogEntryType.Error); throw new ApplicationException("The HL7 Service Name does not match the name set in Program Links eClinicalWorks Setup. Service name: "+this.ServiceName+", Service name in Program Links: " +hl7ServiceName); } EcwOldSendAndReceive(); return; } #endregion eCW Send and Receive OLD #region HL7 Send and Receive New Defs HL7Def hL7Def=HL7Defs.GetOneDeepEnabled(); if(hL7Def==null) { return; } if(hL7Def.HL7Server=="") { hL7Def.HL7Server=System.Environment.MachineName; HL7Defs.Update(hL7Def); } if(hL7Def.HL7ServiceName=="") { hL7Def.HL7ServiceName=this.ServiceName; HL7Defs.Update(hL7Def); } if(hL7Def.HL7Server.ToLower()!=System.Environment.MachineName.ToLower()) { EventLog.WriteEntry("OpenDentHL7","The HL7 Server name does not match the name in the enabled HL7Def Setup. Server name: "+System.Environment.MachineName+", Server name in HL7Def: "+hL7Def.HL7Server, EventLogEntryType.Error); throw new ApplicationException("The HL7 Server name does not match the name in the enabled HL7Def Setup. Server name: "+System.Environment.MachineName+", Server name in HL7Def: "+hL7Def.HL7Server); } if(hL7Def.HL7ServiceName.ToLower()!=this.ServiceName.ToLower()) { EventLog.WriteEntry("OpenDentHL7","The HL7 Service Name does not match the name in the enabled HL7Def Setup. Service name: "+this.ServiceName+", Service name in HL7Def: "+hL7Def.HL7ServiceName, EventLogEntryType.Error); throw new ApplicationException("The HL7 Service Name does not match the name in the enabled HL7Def Setup. Service name: "+this.ServiceName+", Service name in HL7Def: "+hL7Def.HL7ServiceName); } HL7DefEnabled=hL7Def;//so we can access it later from other methods #region File Mode if(HL7DefEnabled.ModeTx==ModeTxHL7.File) { hl7FolderOut=HL7DefEnabled.OutgoingFolder; hl7FolderIn=HL7DefEnabled.IncomingFolder; if(!Directory.Exists(hl7FolderOut)) { EventLog.WriteEntry("OpenDentHL7","The outgoing HL7 folder does not exist. Path is set to: "+hl7FolderOut,EventLogEntryType.Error); throw new ApplicationException("The outgoing HL7 folder does not exist. Path is set to: "+hl7FolderOut); } if(!Directory.Exists(hl7FolderIn)) { EventLog.WriteEntry("OpenDentHL7","The incoming HL7 folder does not exist. Path is set to: "+hl7FolderIn,EventLogEntryType.Error); throw new ApplicationException("The incoming HL7 folder does not exist. Path is set to: "+hl7FolderIn); } _ecwDateTimeOldMsgsDeleted=DateTime.MinValue; _ecwFileModeIsSending=false; //start polling the folder for waiting messages to import. Every 5 seconds. TimerCallback timercallbackReceive=new TimerCallback(TimerCallbackReceiveFiles); timerReceiveFiles=new System.Threading.Timer(timercallbackReceive,null,5000,5000); //start polling the db for new HL7 messages to send. Every 1.8 seconds. TimerCallback timercallbackSend=new TimerCallback(TimerCallbackSendFiles); timerSendFiles=new System.Threading.Timer(timercallbackSend,null,1800,1800); } #endregion File Mode #region TCP/IP Mode else {//TCP/IP CreateIncomingTcpListener();//this method spawns a new thread for receiving, the main thread returns to perform the sending below _ecwTCPSendSocketIsConnected=false; _ecwTCPModeIsSending=false; //start a timer to connect to the send socket every 20 seconds. The socket will be reused, so if _ecwTCPSendSocketIsConnected is true, this will just return TimerCallback timercallbackSendConnectTCP=new TimerCallback(TimerCallbackSendConnectTCP); timerSendConnectTCP=new System.Threading.Timer(timercallbackSendConnectTCP,null,1800,20000);//every 20 seconds, re-connect to the socket if the connection has been closed } #endregion TCP/IP Mode #endregion HL7 Send and Receive New Defs }