예제 #1
0
        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);
            }
        }