Ejemplo n.º 1
0
        private void butImport_Click(object sender, EventArgs e)
        {
            if (!MsgBox.Show(this, true, "If you want a clean slate, the current fee schedule should be cleared first.  When imported, any fees that are found in the text file will overwrite values of the current fee schedule showing in the main window.  Are you sure you want to continue?"))
            {
                return;
            }
            Cursor = Cursors.WaitCursor;
            OpenFileDialog Dlg = new OpenFileDialog();

            if (Directory.Exists(PrefC.GetString(PrefName.ExportPath)))
            {
                Dlg.InitialDirectory = PrefC.GetString(PrefName.ExportPath);
            }
            else if (Directory.Exists("C:\\"))
            {
                Dlg.InitialDirectory = "C:\\";
            }
            if (Dlg.ShowDialog() != DialogResult.OK)
            {
                Cursor = Cursors.Default;
                return;
            }
            if (!File.Exists(Dlg.FileName))
            {
                Cursor = Cursors.Default;
                MsgBox.Show(this, "File not found");
                return;
            }
            string[] fields;
            double   feeAmt;

            using (StreamReader sr = new StreamReader(Dlg.FileName)){
                string line = sr.ReadLine();
                while (line != null)
                {
                    Cursor = Cursors.WaitCursor;
                    fields = line.Split(new string[1] {
                        "\t"
                    }, StringSplitOptions.None);
                    if (fields.Length > 1)                  // && fields[1]!=""){//we no longer skip blank fees
                    {
                        if (fields[1] == "")
                        {
                            feeAmt = -1;                          //triggers deletion of existing fee, but no insert.
                        }
                        else
                        {
                            feeAmt = PIn.Double(fields[1]);
                        }
                        Fees.Import(fields[0], feeAmt, SchedNum);
                    }
                    line = sr.ReadLine();
                }
            }
            DataValid.SetInvalid(InvalidType.Fees);
            Cursor       = Cursors.Default;
            DialogResult = DialogResult.OK;
        }
Ejemplo n.º 2
0
        private void butImport_Click(object sender, EventArgs e)
        {
            if (!MsgBox.Show(this, true, "If you want a clean slate, the current fee schedule should be cleared first.  When imported, any fees that are found in the text file will overwrite values of the current fee schedule showing in the main window.  Are you sure you want to continue?"))
            {
                return;
            }
            Cursor = Cursors.WaitCursor;
            OpenFileDialog Dlg = new OpenFileDialog();

            if (Directory.Exists(PrefB.GetString("ExportPath")))
            {
                Dlg.InitialDirectory = PrefB.GetString("ExportPath");
            }
            else if (Directory.Exists("C:\\"))
            {
                Dlg.InitialDirectory = "C:\\";
            }
            if (Dlg.ShowDialog() != DialogResult.OK)
            {
                Cursor = Cursors.Default;
                return;
            }
            if (!File.Exists(Dlg.FileName))
            {
                Cursor = Cursors.Default;
                MsgBox.Show(this, "File not found");
                return;
            }
            string[] fields;
            double   fee;
            int      schedI = DefB.GetOrder(DefCat.FeeSchedNames, SchedNum);

            using (StreamReader sr = new StreamReader(Dlg.FileName)){
                string line = sr.ReadLine();
                while (line != null)
                {
                    fields = line.Split(new string[1] {
                        "\t"
                    }, StringSplitOptions.None);
                    if (fields.Length > 1 && fields[1] != "")                //skips blank fees
                    {
                        fee = PIn.PDouble(fields[1]);
                        Fees.Import(fields[0], fee, schedI);
                    }
                    line = sr.ReadLine();
                }
            }
            Cursor       = Cursors.Default;
            DialogResult = DialogResult.OK;
        }
Ejemplo n.º 3
0
        ///<summary>Imports fees into the database from the provided file.</summary>
        ///<param name="fileName">Must be a tab-delimited .xls or .csv file. Each row must have two columns. The first column must be the proc code
        ///and the second column must be the fee amount.</param>
        public static void ImportFees(long feeSchedNum, long clinicNum, long provNum, string fileName, Form currentForm)
        {
            FeeCache   _feeCache   = new FeeCache();
            List <Fee> listNewFees = _feeCache.GetListFees(feeSchedNum, clinicNum, provNum);
            Action     actionCloseFeeSchedImportProgress = ODProgressOld.ShowProgressStatus("FeeSchedImport", currentForm,
                                                                                            Lan.g(currentForm, "Importing fees, please wait") + "...");

            string[] fields;
            double   feeAmt;

            using (StreamReader sr = new StreamReader(fileName)){
                string line = sr.ReadLine();
                while (line != null)
                {
                    currentForm.Cursor = Cursors.WaitCursor;
                    fields             = line.Split(new string[1] {
                        "\t"
                    }, StringSplitOptions.None);
                    if (fields.Length > 1)                  // && fields[1]!=""){//we no longer skip blank fees
                    {
                        if (fields[1] == "")
                        {
                            feeAmt = -1;                          //triggers deletion of existing fee, but no insert.
                        }
                        else
                        {
                            feeAmt = PIn.Double(fields[1]);
                        }
                        listNewFees = Fees.Import(fields[0], feeAmt, feeSchedNum, clinicNum, provNum, listNewFees);
                    }
                    line = sr.ReadLine();
                }
            }
            currentForm.Cursor = Cursors.Default;
            actionCloseFeeSchedImportProgress();
            MsgBox.Show(currentForm, "Fee schedule imported.");
            _feeCache.BeginTransaction();
            _feeCache.RemoveFees(feeSchedNum, clinicNum, provNum);
            foreach (Fee fee in listNewFees)
            {
                _feeCache.Add(fee);
            }
            currentForm.Cursor = Cursors.WaitCursor;
            _feeCache.SaveToDb();
            currentForm.Cursor = Cursors.Default;
        }
Ejemplo n.º 4
0
        private void butImportCanada_Click(object sender, EventArgs e)
        {
            if (!MsgBox.Show(this, true, "If you want a clean slate, the current fee schedule should be cleared first.  When imported, any fees that are found in the text file will overwrite values of the current fee schedule showing in the main window.  Are you sure you want to continue?"))
            {
                return;
            }
            Cursor = Cursors.WaitCursor;
            FormFeeSchedPickRemote formPick = new FormFeeSchedPickRemote();

            formPick.Url = @"http://www.opendental.com/feescanada/";          //points to index.php file
            if (formPick.ShowDialog() != DialogResult.OK)
            {
                Cursor = Cursors.Default;
                return;
            }
            Cursor = Cursors.WaitCursor;          //original wait cursor seems to go away for some reason.
            Application.DoEvents();
            string feeData = "";

            if (formPick.IsFileChosenProtected)
            {
                string memberNumberODA   = "";
                string memberPasswordODA = "";
                if (formPick.FileChosenName.StartsWith("ON_"))                 //Any and all Ontario fee schedules
                {
                    FormFeeSchedPickAuthOntario formAuth = new FormFeeSchedPickAuthOntario();
                    if (formAuth.ShowDialog() != DialogResult.OK)
                    {
                        Cursor = Cursors.Default;
                        return;
                    }
                    memberNumberODA   = formAuth.ODAMemberNumber;
                    memberPasswordODA = formAuth.ODAMemberPassword;
                }
                //prepare the xml document to send--------------------------------------------------------------------------------------
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent      = true;
                settings.IndentChars = ("    ");
                StringBuilder strbuild = new StringBuilder();
                using (XmlWriter writer = XmlWriter.Create(strbuild, settings)) {
                    writer.WriteStartElement("RequestFeeSched");
                    writer.WriteStartElement("RegistrationKey");
                    writer.WriteString(PrefC.GetString(PrefName.RegistrationKey));
                    writer.WriteEndElement();                    //RegistrationKey
                    writer.WriteStartElement("FeeSchedFileName");
                    writer.WriteString(formPick.FileChosenName);
                    writer.WriteEndElement();                    //FeeSchedFileName
                    if (memberNumberODA != "")
                    {
                        writer.WriteStartElement("ODAMemberNumber");
                        writer.WriteString(memberNumberODA);
                        writer.WriteEndElement();                        //ODAMemberNumber
                        writer.WriteStartElement("ODAMemberPassword");
                        writer.WriteString(memberPasswordODA);
                        writer.WriteEndElement();                //ODAMemberPassword
                    }
                    writer.WriteEndElement();                    //RequestFeeSched
                }
#if DEBUG
                OpenDental.localhost.Service1 updateService = new OpenDental.localhost.Service1();
#else
                OpenDental.customerUpdates.Service1 updateService = new OpenDental.customerUpdates.Service1();
                updateService.Url = PrefC.GetString(PrefName.UpdateServerAddress);
#endif
                //Send the message and get the result-------------------------------------------------------------------------------------
                string result = "";
                try {
                    result = updateService.RequestFeeSched(strbuild.ToString());
                }
                catch (Exception ex) {
                    Cursor = Cursors.Default;
                    MessageBox.Show("Error: " + ex.Message);
                    return;
                }
                Cursor = Cursors.Default;
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(result);
                //Process errors------------------------------------------------------------------------------------------------------------
                XmlNode node = doc.SelectSingleNode("//Error");
                if (node != null)
                {
                    MessageBox.Show(node.InnerText, "Error");
                    return;
                }
                node = doc.SelectSingleNode("//KeyDisabled");
                if (node == null)
                {
                    //no error, and no disabled message
                    if (Prefs.UpdateBool(PrefName.RegistrationKeyIsDisabled, false))                    //this is one of three places in the program where this happens.
                    {
                        DataValid.SetInvalid(InvalidType.Prefs);
                    }
                }
                else
                {
                    MessageBox.Show(node.InnerText);
                    if (Prefs.UpdateBool(PrefName.RegistrationKeyIsDisabled, true))                    //this is one of three places in the program where this happens.
                    {
                        DataValid.SetInvalid(InvalidType.Prefs);
                    }
                    return;
                }
                //Process a valid return value------------------------------------------------------------------------------------------------
                node = doc.SelectSingleNode("//ResultCSV64");
                string feeData64    = node.InnerXml;
                byte[] feeDataBytes = Convert.FromBase64String(feeData64);
                feeData = Encoding.UTF8.GetString(feeDataBytes);
            }
            else
            {
                string    tempFile    = Path.GetTempFileName();
                WebClient myWebClient = new WebClient();
                try {
                    myWebClient.DownloadFile(formPick.FileChosenUrl, tempFile);
                }
                catch (Exception ex) {
                    MessageBox.Show(Lan.g(this, "Failed to download fee schedule file") + ": " + ex.Message);
                    Cursor = Cursors.Default;
                    return;
                }
                feeData = File.ReadAllText(tempFile);
                File.Delete(tempFile);
            }
            string[] feeLines = feeData.Split('\n');
            double   feeAmt;
            long     numImported = 0;
            long     numSkipped  = 0;
            for (int i = 0; i < feeLines.Length; i++)
            {
                string[] fields = feeLines[i].Split('\t');
                if (fields.Length > 1)               // && fields[1]!=""){//we no longer skip blank fees
                {
                    string procCode = fields[0];
                    if (ProcedureCodes.IsValidCode(procCode))                      //The Fees.Import() function will not import fees for codes that do not exist.
                    {
                        if (fields[1] == "")
                        {
                            feeAmt = -1;                          //triggers deletion of existing fee, but no insert.
                        }
                        else
                        {
                            feeAmt = PIn.Double(fields[1]);
                        }
                        Fees.Import(procCode, feeAmt, SchedNum);
                        numImported++;
                    }
                    else
                    {
                        numSkipped++;
                    }
                }
            }
            DataValid.SetInvalid(InvalidType.Fees);
            Cursor       = Cursors.Default;
            DialogResult = DialogResult.OK;
            string outputMessage = Lan.g(this, "Done. Number imported") + ": " + numImported;
            if (numSkipped > 0)
            {
                outputMessage += " " + Lan.g(this, "Number skipped") + ": " + numSkipped;
            }
            MessageBox.Show(outputMessage);
        }
Ejemplo n.º 5
0
        private void butImportEcw_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            OpenFileDialog Dlg = new OpenFileDialog();

                        #if DEBUG
            Dlg.InitialDirectory = @"E:\My Documents\Bridge Info\eClinicalWorks\FeeSchedules";
                        #endif
            if (Dlg.ShowDialog() != DialogResult.OK)
            {
                Cursor = Cursors.Default;
                return;
            }
            if (!File.Exists(Dlg.FileName))
            {
                Cursor = Cursors.Default;
                MsgBox.Show(this, "File not found");
                return;
            }
            string extension = Path.GetExtension(Dlg.FileName);
            if (extension != ".csv")
            {
                Cursor = Cursors.Default;
                MsgBox.Show(this, "Only .csv files may be imported.");
                return;
            }
            string[] lines = File.ReadAllLines(Dlg.FileName);
            if (lines.Length == 0 || (lines[0] != "Code,Description,Unit Fee,Allowed Fee,POS,TOS,Modifier,RequiresCliaID,GlobalBillingDays,ChargeCode" &&
                                      lines[0] != "\"Code\",\"Description\",\"UnitFee\",\"AllowedFee\",\"POS\",\"TOS\",\"Modifier\",\"RequiresCliaID\",\"GlobalBillingDays\",\"ChargeCode\""))
            {
                Cursor = Cursors.Default;
                MessageBox.Show("Unexpected file format. First line in file should be:\r\nCode,Description,Unit Fee,Allowed Fee,POS,TOS,Modifier,RequiresCliaID,GlobalBillingDays,ChargeCode\r\nor\r\n\"Code\",\"Description\",\"UnitFee\",\"AllowedFee\",\"POS\",\"TOS\",\"Modifier\",\"RequiresCliaID\",\"GlobalBillingDays\",\"ChargeCode\"");
                return;
            }
            string   feeSchedName = Path.GetFileNameWithoutExtension(Dlg.FileName);
            FeeSched feesched     = FeeScheds.GetByExactName(feeSchedName, FeeScheduleType.Normal);
            if (feesched == null)
            {
                feesched              = new FeeSched();
                feesched.Description  = feeSchedName;
                feesched.FeeSchedType = FeeScheduleType.Normal;
                feesched.ItemOrder    = FeeSchedC.ListLong[FeeSchedC.ListLong.Count - 1].ItemOrder + 1;
                feesched.IsHidden     = false;
                //feesched.IsNew=true;
                FeeScheds.Insert(feesched);
                DataValid.SetInvalid(InvalidType.FeeScheds);
            }
            else
            {
                if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "Fee schedule already exists and all the fees will be overwritten.  Continue?"))
                {
                    Cursor = Cursors.Default;
                    return;
                }
                Fees.ClearFeeSched(feesched.FeeSchedNum);
            }
            bool importAllowed = false;
            if (MsgBox.Show(this, MsgBoxButtons.YesNo, "Import Allowed Fee column instead of Unit Fee column?"))
            {
                importAllowed = true;
            }
            int           imported         = 0;
            int           skippedCode      = 0;
            int           skippedMalformed = 0;
            string[]      fieldArray;
            List <string> fields;
            double        feeAmt       = 0;
            string        codeText     = "";
            bool          formatQuotes = false;
            if (lines.Length > 1)
            {
                if (lines[1].Substring(0, 1) == "\"")
                {
                    formatQuotes = true;
                }
            }
            if (formatQuotes)             //Original format - fields are surrounded by quotes (except first row, above)
            {
                for (int i = 1; i < lines.Length; i++)
                {
                    //fieldArray=lines[i].Split(new string[1] { "\"" },StringSplitOptions.RemoveEmptyEntries);//Removing emtpy entries will misalign the columns
                    fieldArray = lines[i].Split(new string[1] {
                        "\""
                    }, StringSplitOptions.None);                                //half the 'fields' will be commas.
                    fields = new List <string>();
                    for (int f = 1; f < fieldArray.Length - 1; f++)             //this loop skips the first and last elements because they are artifacts of the string splitting.
                    {
                        if (fieldArray[f] == ",")
                        {
                            continue;
                        }
                        fields.Add(fieldArray[f]);
                    }
                    if (fields.Count < 4)
                    {
                        skippedMalformed++;
                        continue;
                    }
                    if (importAllowed)
                    {
                        feeAmt = PIn.Double(fields[3]);
                    }
                    else
                    {
                        feeAmt = PIn.Double(fields[2]);
                    }
                    codeText = fields[0];
                    if (!ProcedureCodes.IsValidCode(codeText))
                    {
                        skippedCode++;
                        continue;
                    }
                    Fees.Import(fields[0], feeAmt, feesched.FeeSchedNum);
                    imported++;
                }
            }
            else              //New format - fields are delimited by commas only (no quotes)
            {
                for (int i = 1; i < lines.Length; i++)
                {
                    fieldArray = lines[i].Split(new string[1] {
                        ","
                    }, StringSplitOptions.None);
                    fields = new List <string>();
                    for (int f = 0; f < fieldArray.Length; f++)
                    {
                        fields.Add(fieldArray[f]);
                    }
                    if (fields.Count < 4)
                    {
                        skippedMalformed++;
                        continue;
                    }
                    if (fields.Count > 10)
                    {
                        MsgBox.Show(this, "Import aborted. Commas are not allowed in text fields. Check your descriptions for commas and try again.");
                        Cursor = Cursors.Default;
                        return;
                    }
                    if (importAllowed)
                    {
                        feeAmt = PIn.Double(fields[3]);
                    }
                    else
                    {
                        feeAmt = PIn.Double(fields[2]);
                    }
                    codeText = fields[0];
                    if (!ProcedureCodes.IsValidCode(codeText))
                    {
                        skippedCode++;
                        continue;
                    }
                    Fees.Import(fields[0], feeAmt, feesched.FeeSchedNum);
                    imported++;
                }
            }
            DataValid.SetInvalid(InvalidType.Fees);
            Cursor = Cursors.Default;
            string displayMsg = "Import complete.\r\nCodes imported: " + imported.ToString();
            if (skippedCode > 0)
            {
                displayMsg += "\r\nCodes skipped because not valid codes in Open Dental: " + skippedCode.ToString();
            }
            if (skippedMalformed > 0)
            {
                displayMsg += "\r\nCodes skipped because malformed line in text file: " + skippedMalformed.ToString();
            }
            MessageBox.Show(displayMsg);
            DialogResult = DialogResult.OK;
        }