Exemple #1
0
        public void ProcessFile(string fileName)
        {
            bool hl7v2 = false;
            bool hl7v3 = false;

            string message = string.Empty;

            Logger.Debug("Processing " + fileName);

            try
            {
                StreamReader infile = new StreamReader(fileName);

                while (!infile.EndOfStream)
                {
                    message += infile.ReadLine();
                    message += "\n";
                }

                infile.Close();
            }
            catch(Exception e)
            {
                Logger.Fatal(e.Message);
            }

            bool SQLstored = false;

            PatientInfo p = new PatientInfo();

            if (fileName.EndsWith("hl7"))
            {
                string searchFor = ".v2.hl7";

                int first = fileName.IndexOf(searchFor);

                if (first != -1)
                {
                    hl7v2 = true;
                }
                else
                {
                    searchFor = ".v3.hl7";

                    first = fileName.IndexOf(searchFor);

                    if (first != -1)
                    {
                        hl7v3 = true;
                    }
                }

                if (hl7v2 == false && hl7v3 == false)
                {
                    // Not a TCP received file. Perhaps somebody has put it in our directory.
                    // Let's assume it is a hl7v2. If it isn't fromHL7v2toSQL will simply fail and return false :p
                    hl7v2 = true;
                }

                if (hl7v2)
                {
                    SQLstored = p.fromHL7v2toSQL(message);

                }
                else if (hl7v3)
                {
                    SQLstored = p.fromHL7v3toSQL(message);
                }

            }
            else if (fileName.EndsWith("csv"))
            {
                SQLstored = p.fromCSVtoSQL(message, csv_field_delimiter);
            }
            else if (fileName.EndsWith("txt"))
            {
                SQLstored = p.fromTXTtoSQL(message);
            }
            else if (fileName.EndsWith("xls") || fileName.EndsWith("xlsx"))
            {
                SQLstored = p.fromXLStoSQL(fileName);
            }

            if (SQLstored)
            {
                Logger.Debug(fileName + " done!");
                // File.Move(fileName, fileName + ".done");
                File.Delete(fileName);
            }
            else
            {
                // Something bad happened (wrong data, wrong SQL...)
                // We put it at the end of the queue to try again later.
                Logger.Debug("Error with " + fileName + ", putting it at the end of the queue.");
                files.Enqueue(fileName);
            }
        }
Exemple #2
0
        public void ProcessFile(string fileName)
        {
            bool hl7v2 = false;
            bool hl7v3 = false;

            string message = string.Empty;

            Logger.Debug("Processing " + fileName);

            try
            {
                StreamReader infile = new StreamReader(fileName);

                while (!infile.EndOfStream)
                {
                    message += infile.ReadLine();
                    message += "\n";
                }

                infile.Close();
            }
            catch (Exception e)
            {
                Logger.Fatal(e.Message);
            }

            bool SQLstored = false;

            PatientInfo p = new PatientInfo();

            if (fileName.EndsWith("hl7"))
            {
                string searchFor = ".v2.hl7";

                int first = fileName.IndexOf(searchFor);

                if (first != -1)
                {
                    hl7v2 = true;
                }
                else
                {
                    searchFor = ".v3.hl7";

                    first = fileName.IndexOf(searchFor);

                    if (first != -1)
                    {
                        hl7v3 = true;
                    }
                }

                if (hl7v2 == false && hl7v3 == false)
                {
                    // Not a TCP received file. Perhaps somebody has put it in our directory.
                    // Let's assume it is a hl7v2. If it isn't fromHL7v2toSQL will simply fail and return false :p
                    hl7v2 = true;
                }

                if (hl7v2)
                {
                    SQLstored = p.fromHL7v2toSQL(message);
                }
                else if (hl7v3)
                {
                    SQLstored = p.fromHL7v3toSQL(message);
                }
            }
            else if (fileName.EndsWith("csv"))
            {
                SQLstored = p.fromCSVtoSQL(message, csv_field_delimiter);
            }
            else if (fileName.EndsWith("txt"))
            {
                SQLstored = p.fromTXTtoSQL(message);
            }
            else if (fileName.EndsWith("xls") || fileName.EndsWith("xlsx"))
            {
                SQLstored = p.fromXLStoSQL(fileName);
            }

            if (SQLstored)
            {
                Logger.Debug(fileName + " done!");
                // File.Move(fileName, fileName + ".done");
                File.Delete(fileName);
            }
            else
            {
                // Something bad happened (wrong data, wrong SQL...)
                // We put it at the end of the queue to try again later.
                Logger.Debug("Error with " + fileName + ", putting it at the end of the queue.");
                files.Enqueue(fileName);
            }
        }