Ejemplo n.º 1
0
        ///<summary>Takes any files found in the reports folder for the clearinghouse, and imports them into the database.
        ///Moves the original file into an Archive sub folder.
        ///Returns a string with any errors that occured.</summary>
        private static string ImportReportFiles(Clearinghouse clearinghouseClin, IODProgressExtended progress = null)        //uses clinic-level clearinghouse where necessary.
        {
            progress = progress ?? new ODProgressExtendedNull();
            if (!Directory.Exists(clearinghouseClin.ResponsePath))
            {
                return(Lans.g("FormClaimReports", "Report directory does not exist") + ": " + clearinghouseClin.ResponsePath);
            }
            if (clearinghouseClin.Eformat == ElectronicClaimFormat.Canadian || clearinghouseClin.Eformat == ElectronicClaimFormat.Ramq)
            {
                //the report path is shared with many other important files.  Do not process anything.  Comm is synchronous only.
                return("");
            }
            progress.UpdateProgress(Lans.g(progress.LanThis, "Reading download files"), "reports", "55%", 55);
            if (progress.IsPauseOrCancel())
            {
                return(Lans.g(progress.LanThis, "Import canceled by user."));
            }
            string[] files = null;
            string   archiveDir;

            try {
                files      = Directory.GetFiles(clearinghouseClin.ResponsePath);
                archiveDir = ODFileUtils.CombinePaths(clearinghouseClin.ResponsePath, "Archive" + "_" + DateTime.Now.Year.ToString());
                if (!Directory.Exists(archiveDir))
                {
                    Directory.CreateDirectory(archiveDir);
                }
            }
            catch (UnauthorizedAccessException ex) {
                ex.DoNothing();
                return(Lans.g("FormClaimReports", "Access to the Report Path is denied.  Try running as administrator or contact your network administrator."));
            }
            List <string> listFailedFiles = new List <string>();

            progress.UpdateProgress(Lans.g(progress.LanThis, "Files read."));
            progress.UpdateProgress(Lans.g(progress.LanThis, "Importing files"), "reports", "83%", 83);
            if (files.Length > 0)
            {
                progress.UpdateProgressDetailed(Lans.g(progress.LanThis, "Importing"), tagString: "import");             //add a new progress bar for imports if there are any to import
            }
            else
            {
                progress.UpdateProgress(Lans.g(progress.LanThis, "No files to import."));
            }
            for (int i = 0; i < files.Length; i++)
            {
                int percent = (i / files.Length) * 100;
                progress.UpdateProgress(Lans.g(progress.LanThis, "Importing") + " " + i + " / " + files.Length, "import", percent + "%", percent);
                if (progress.IsPauseOrCancel())
                {
                    return(Lans.g(progress.LanThis, "Import canceled by user."));
                }
                string fileSource      = files[i];
                string fileDestination = ODFileUtils.CombinePaths(archiveDir, Path.GetFileName(files[i]));
                try {
                    File.Move(fileSource, fileDestination);
                }
                catch (Exception ex) {
                    ex.DoNothing();              //OK to continue, since ProcessIncomingReport() above saved the raw report into the etrans table.
                    listFailedFiles.Add(fileSource);
                    continue;                    //Skip current report file and leave in folder to processing later.
                }
                try {
                    Etranss.ProcessIncomingReport(
                        File.GetCreationTime(fileDestination),
                        clearinghouseClin.HqClearinghouseNum,
                        File.ReadAllText(fileDestination),
                        Security.CurUser.UserNum);
                }
                catch (Exception ex) {
                    ex.DoNothing();
                    listFailedFiles.Add(fileSource);
                    File.Move(fileDestination, fileSource);                   //Move file back so that the archived folder only contains succesfully processed reports.
                }
            }
            if (listFailedFiles.Count > 0)
            {
                return(Lans.g("FormClaimReports", "Failed to process the following files due to permission issues or malformed data")
                       + ":\r\n" + string.Join(",\r\n", listFailedFiles));
            }
            return("");
        }
Ejemplo n.º 2
0
        ///<summary>Used for both sending claims and receiving reports.  Set isSilent to true to hide the cmd window popup.
        ///Returns true if the communications were successful, and false if they failed.  If they failed, a rollback will happen automatically by
        ///deleting the previously created X12 file.  The batchnum is supplied for the possible rollback.  Also used for mail retrieval.</summary>
        public static bool Launch(Clearinghouse clearinghouseClin, int batchNum, bool isSilent = false, IODProgressExtended progress = null)
        {
            //called from Eclaims and FormClaimReports.cs. Clinic-level clearinghouse passed in.
            progress = progress ?? new ODProgressExtendedNull();
            string arguments = "";

            try {
                if (!Directory.Exists(clearinghouseClin.ExportPath))
                {
                    throw new Exception(Lans.g(progress.LanThis, "Clearinghouse export path is invalid."));
                }
                if (!Directory.Exists(clearinghouseClin.ResponsePath))
                {
                    throw new Exception(Lans.g(progress.LanThis, "Clearinghouse response path is invalid."));
                }
                if (!File.Exists(clearinghouseClin.ClientProgram))
                {
                    throw new Exception(Lans.g(progress.LanThis, "Client program not installed properly."));
                }
                arguments = "\"" + ODFileUtils.RemoveTrailingSeparators(clearinghouseClin.ExportPath) + "\\" + "*.*\" " //upload claims path
                            + "\"" + ODFileUtils.RemoveTrailingSeparators(clearinghouseClin.ResponsePath) + "\" "       //Mail path
                            + "316 "                                                                                    //vendor number.
                                                                                                                        //LoginID is client number.  Assigned by us, and we have to coordinate for all other 'vendors' of Open Dental,
                                                                                                                        //because there is only one vendor number for OD for now.
                            + clearinghouseClin.LoginID + " "
                            + clearinghouseClin.Password;
                //call the WebMD client program
                Process process = new Process();
                process.EnableRaisingEvents = true;
                if (isSilent)
                {
                    process.StartInfo.UseShellExecute       = false;            //Required to redirect standard input on the next line.
                    process.StartInfo.RedirectStandardInput = true;             //Required to send a newline character into the input stream below.
                    process.StartInfo.CreateNoWindow        = true;
                    process.StartInfo.WindowStyle           = ProcessWindowStyle.Hidden;
                }
                process.StartInfo.FileName  = clearinghouseClin.ClientProgram;
                process.StartInfo.Arguments = arguments;
                progress.UpdateProgress(Lans.g(progress.LanThis, "Contacting web server and downloading reports"), "reports", "17%", 17);
                if (progress.IsPauseOrCancel())
                {
                    progress.UpdateProgress(Lans.g(progress.LanThis, "Canceled by user."));
                    return(false);
                }
                process.Start();
                if (isSilent)
                {
                    //If the LoginID or password are incorrect, then the WebMD client program will show an error message and wait for the user to click enter.
                    //Above we redirected standard input so that we could send a newline into the input.
                    //This way if the LoginID or password are incorrect, then the WebMD client will still exit.
                    //Write an excessive amount of newlines in case the WebMD client asks multiple questions.
                    //If we send the input before the WebMD client is ready, then the input is queued until it is needed.
                    //If no input is needed, then the input will be ignored.
                    for (int i = 0; i < 10; i++)
                    {
                        process.StandardInput.WriteLine();
                    }
                }
                process.WaitForExit();
                //delete the uploaded claims
                progress.UpdateProgress(Lans.g(progress.LanThis, "Contacting web server sucessful."));
                progress.UpdateProgress(Lans.g(progress.LanThis, "Deleting uploaded claims"), "reports", "33%", 33);
                if (progress.IsPauseOrCancel())
                {
                    progress.UpdateProgress(Lans.g(progress.LanThis, "Canceled by user."));
                    return(false);
                }
                string[] files = Directory.GetFiles(clearinghouseClin.ExportPath);
                for (int i = 0; i < files.Length; i++)
                {
                    float overallpercent = 33 + (i / files.Length) * 11;            //33 is starting point. 11 is the amount of bar space we have before our next major spot (44%)
                    progress.UpdateProgress(Lans.g(progress.LanThis, "Getting files"), "reports", overallpercent + "%", (int)overallpercent);
                    //string t=files[i];
                    File.Delete(files[i]);
                }
                //rename the downloaded mail files to end with txt
                progress.UpdateProgress(Lans.g(progress.LanThis, "Deleteing uploaded claims successful."));
                progress.UpdateProgress("Renaming downloaded files", "reports", "44%", 44);
                if (progress.IsPauseOrCancel())
                {
                    progress.UpdateProgress(Lans.g(progress.LanThis, "Canceled by user."));
                    return(false);
                }
                files = Directory.GetFiles(clearinghouseClin.ResponsePath);
                for (int i = 0; i < files.Length; i++)
                {
                    float overallpercent = 44 + (i / files.Length) * 11;            //44 is starting point. 11 is the amount of bar space we have before our next major spot (55%)
                    progress.UpdateProgress(Lans.g(progress.LanThis, "Getting files"), "reports", overallpercent + "%", (int)overallpercent);
                    //string t=files[i];
                    if (Path.GetExtension(files[i]) != ".txt")
                    {
                        File.Move(files[i], files[i] + ".txt");
                    }
                }
                progress.UpdateProgress(Lans.g(progress.LanThis, "File rename successful."));
            }
            catch (Exception e) {
                ErrorMessage = e.Message;
                progress.UpdateProgress(Lans.g(progress.LanThis, "Error encountered:") + "\r\n" + ErrorMessage);
                if (batchNum != 0)
                {
                    progress.UpdateProgress(Lans.g(progress.LanThis, "Rolling back batch."));
                    progress.UpdateProgressDetailed(Lans.g(progress.LanThis, "Rolling back batch"), tagString: "reports", marqSpeed: 20, progStyle: ProgBarStyle.Marquee);
                    x837Controller.Rollback(clearinghouseClin, batchNum);
                    progress.UpdateProgressDetailed(Lans.g(progress.LanThis, "Done rolling back"), tagString: "reports", marqSpeed: 20, progStyle: ProgBarStyle.Marquee);
                    progress.UpdateProgress(Lans.g(progress.LanThis, "Rolling back batch complete."));
                }
                return(false);
            }
            return(true);
        }