public OperationResult AddFolder(Folder folder)
        {
            OperationResult operationResult = new Models.OperationResult();

            using (IDbConnection db = new SqlConnection(ConfigurationValues.PostOfficeDatabaseConnection))
            {
                try
                {

                    string query = "INSERT INTO [HoldFolders]"
                        + " ("
                        + " [ActiveDirectoryUser]"
                        + " ,[DocumentType]"
                        + " ,[FolderName]"
                        + " )"
                        + "VALUES"
                        + " ("
                        + " @ActiveDirectoryUser,@DocumentType,@FolderName"
                        + " )";

                    db.Execute(query, new
                    {
                        @ActiveDirectoryUser = Utility.GetUserName(),
                        @DocumentType = folder.DocumentType,
                        @FolderName = folder.FolderName
                    });

                    operationResult.Success = true;
                    return operationResult;
                }
                catch (Exception er)
                {
                    operationResult.Success = false;
                    operationResult.AddMessage(er.ToString());
                    return operationResult;
                }
            }
        }
        public OperationResult AddReportingRecord(SendFaxesReporting sentNotesFax)
        {
            if (string.IsNullOrEmpty(sentNotesFax.CareProviderName))
            {
                sentNotesFax.CareProviderName = string.Empty;
            }

            if (string.IsNullOrEmpty(sentNotesFax.PatientName))
            {
                sentNotesFax.PatientName = string.Empty;
            }

            if (string.IsNullOrEmpty(sentNotesFax.PrimaryCareFaxNumber))
            {
                sentNotesFax.PrimaryCareFaxNumber = string.Empty;
            }

            if (string.IsNullOrEmpty(sentNotesFax.PrimaryCareFaxSent))
            {
                sentNotesFax.PrimaryCareFaxSent = string.Empty;
            }

            if (string.IsNullOrEmpty(sentNotesFax.PrimaryCareProvider))
            {
                sentNotesFax.PrimaryCareProvider = string.Empty;
            }

            if (string.IsNullOrEmpty(sentNotesFax.PrimaryCareReason))
            {
                sentNotesFax.PrimaryCareReason = string.Empty;
            }

            if (string.IsNullOrEmpty(sentNotesFax.PrimaryCareResult))
            {
                sentNotesFax.PrimaryCareResult = string.Empty;
            }

            if (string.IsNullOrEmpty(sentNotesFax.ReferringCareFaxNumber))
            {
                sentNotesFax.ReferringCareFaxNumber = string.Empty;
            }

            if (string.IsNullOrEmpty(sentNotesFax.ReferringCareFaxSent))
            {
                sentNotesFax.ReferringCareFaxSent = string.Empty;
            }

            if (string.IsNullOrEmpty(sentNotesFax.ReferringCareProvider))
            {
                sentNotesFax.ReferringCareProvider = string.Empty;
            }

            if (string.IsNullOrEmpty(sentNotesFax.ReferringCareReason))
            {
                sentNotesFax.ReferringCareReason = string.Empty;
            }

            if (string.IsNullOrEmpty(sentNotesFax.ReferringCareResult))
            {
                sentNotesFax.ReferringCareResult = string.Empty;
            }

            OperationResult operationResult = new Models.OperationResult();

            string now = DateTime.Now.ToShortDateString()
                + " " + DateTime.Now.ToShortTimeString();

            using (IDbConnection db = new SqlConnection(ConfigurationValues.WaldenFaxConnection))
            {
                try
                {

                    const string query = "INSERT INTO [AutomatedFaxesSent]"
                        + "("
                        + "[DocumentID]"
                        + " ,[PatientID]"
                        + " ,[PatientName]"
                        + " ,[CareProviderID]"
                        + " ,[CareProviderName]"
                        + " ,[PrimaryCareProviderID]"
                        + " ,[PrimaryCareProvider]"
                        + " ,[PrimaryCareFaxNumber]"
                        + " ,[PrimaryCareFaxSent]"
                        + " ,[PrimaryCareReason]"
                        + " ,[PrimaryCareResult]"
                        + " ,[PrimaryCareSendID]"
                        + " ,[PrimaryCareCompletionTime]"
                        + " ,[ReferringCareProviderID]"
                        + " ,[ReferringCareProvider]"
                        + " ,[ReferringCareFaxNumber]"
                        + " ,[ReferringCareFaxSent]"
                        + " ,[ReferringCareReason]"
                        + " ,[ReferringCareResult]"
                        + " ,[ReferringCareSendID]"
                        + " ,[ReferringCareCompletionTime]"
                        + " ,[DateTimeCreated]"
                        + " ,[DateTimeSent]"
                        + ")"
                        + "VALUES"
                        + "("
                        + " @DocumentID,@PatientID,@PatientName,@CareProviderID,@CareProviderName,@PrimaryCareProviderID,"
                        + " @PrimaryCareProvider,@PrimaryCareFaxNumber,@PrimaryCareFaxSent,@PrimaryCareReason,@PrimaryCareResult,@PrimaryCareSendID,@PrimaryCareCompletionTime,"
                        + " @ReferringCareProviderID,@ReferringCareProvider,@ReferringCareFaxNumber,@ReferringCareFaxSent,@ReferringCareReason,@ReferringCareResult,"
                        + " @ReferringCareSendID,@ReferringCareCompletionTime,@DateTimeCreated,@DateTimeSent"
                        + " )";

                    int rowsAffectd = db.Execute(query, new
                    {

                        @DocumentID = sentNotesFax.DocumentID,
                        @PatientID = sentNotesFax.PatientID,
                        @PatientName = sentNotesFax.PatientName,
                        @CareProviderID = sentNotesFax.CareProviderID,
                        @CareProviderName = sentNotesFax.CareProviderName,
                        @PrimaryCareProviderID = sentNotesFax.PrimaryCareProviderID,
                        @PrimaryCareProvider = sentNotesFax.PrimaryCareProvider,
                        @PrimaryCareFaxNumber = sentNotesFax.PrimaryCareFaxNumber,
                        @PrimaryCareFaxSent = sentNotesFax.PrimaryCareFaxSent,
                        @PrimaryCareReason = sentNotesFax.PrimaryCareReason,
                        @PrimaryCareResult = sentNotesFax.PrimaryCareResult,
                        @PrimaryCareSendID = sentNotesFax.PrimaryCareSendID,
                        @PrimaryCareCompletionTime = string.Empty,
                        @ReferringCareProviderID = sentNotesFax.ReferringCareProviderID,
                        @ReferringCareProvider = sentNotesFax.ReferringCareProvider,
                        @ReferringCareFaxNumber = sentNotesFax.ReferringCareFaxNumber,
                        @ReferringCareFaxSent = sentNotesFax.ReferringCareFaxSent,
                        @ReferringCareReason = sentNotesFax.ReferringCareReason,
                        @ReferringCareResult = sentNotesFax.ReferringCareResult,
                        @ReferringCareSendID = sentNotesFax.ReferringCareSendID,
                        @ReferringCareCompletionTime = string.Empty,
                        @DateTimeCreated = now,
                        @DateTimeSent = now
                    });

                    sendFaxId = GetSendFaxID();
                    operationResult.Success = true;
                    operationResult.AddMessage(sendFaxId.ToString());

                    return operationResult;
                }
                catch (Exception er)
                {
                    Utility.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString());
                    operationResult.Success = false;
                    operationResult.AddMessage(er.ToString());
                    return operationResult;
                }
            }
        }
        public OperationResult SendFax(SendFax sendFax)
        {
            OperationResult operationResult = new Models.OperationResult();

            using (IDbConnection db = new SqlConnection(ConfigurationValues.WaldenFaxConnection))
            {
                try
                {
                    const string query = "INSERT INTO [FaxesSendServer]("
                        + "[AccountID]"
                        + ",[UserID]"
                        + ",[FaxName]"
                        + ",[FaxPath]"
                        + ",[FaxNumber]"
                        + ",[RecipientName]"
                        + ",[Notes]"
                        + ",[PageCount]"
                        + ",[FaxSent]"
                        + ",[InUse]"
                        + ",[ToTif]"
                        + ",[CallWait]"
                        + ",[TimesCalled]"
                        + ",[Status]"
                        + ",[ShowFax]"
                        + ",[CreateTime]"
                        + ",[CompletionTime]"
                        + ",[DateStamp])"
                        + " VALUES("
                        + "@AccountID"
                        + ",@UserID"
                        + ",@FaxName"
                        + ",@FaxPath"
                        + ",@FaxNumber"
                        + ",@RecipientName"
                        + ",@Notes"
                        + ",@PageCount"
                        + ",@FaxSent"
                        + ",@InUse"
                        + ",@ToTif"
                        + ",@CallWait"
                        + ",@TimesCalled"
                        + ",@Status"
                        + ",@ShowFax"
                        + ",@CreateTime"
                        + ",@CompletionTime"
                        + ",@DateStamp)";

                    int rowsAffectd = db.Execute(query, new
                    {
                        @AccountID = sendFax.AccountID,
                        @UserID = sendFax.UserID,
                        @FaxName = sendFax.FaxName,
                        @FaxPath = sendFax.FaxPath,
                        @FaxNumber = sendFax.FaxNumber,
                        @RecipientName = sendFax.RecipientName,
                        @Notes = sendFax.Notes,
                        @PageCount = sendFax.PageCount,
                        @FaxSent = sendFax.FaxSent,
                        @InUse = sendFax.InUse,
                        @ToTif = sendFax.ToTif,
                        @CallWait = sendFax.CallWait,
                        @TimesCalled = sendFax.TimesCalled,
                        @Status = sendFax.Status,
                        @ShowFax = sendFax.ShowFax,
                        @CreateTime = sendFax.CreateTime,
                        @CompletionTime = sendFax.CompletionTime,
                        @DateStamp = sendFax.DateStamp
                    });

                    sendFaxId = GetSendFaxID();
                    operationResult.Success = true;
                    operationResult.AddMessage(sendFaxId.ToString());

                    return operationResult;
                }
                catch (Exception er)
                {
                    Utility.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString());
                    operationResult.Success = false;
                    operationResult.AddMessage(er.ToString());
                    return operationResult;
                }
            }
        }
        public OperationResult InsertAllSignedNotes(SignedDocument document)
        {
            OperationResult operationResult = new Models.OperationResult();

            if (string.IsNullOrEmpty(document.DocumentID.ToString()))
            {
                document.DocumentID = 0;
            }

            if (string.IsNullOrEmpty(document.PatientID.ToString()))
            {
                document.PatientID = 0;
            }

            if (string.IsNullOrEmpty(document.PatientName))
            {
                document.PatientName = string.Empty;
            }

            if (string.IsNullOrEmpty(document.CareProviderID.ToString()))
            {
                document.CareProviderID = 0;
            }

            if (string.IsNullOrEmpty(document.CareProviderName))
            {
                document.CareProviderName = string.Empty;
            }

            if (string.IsNullOrEmpty(document.PrimaryCareProviderID.ToString()))
            {
                document.PrimaryCareProviderID = 0;
            }

            if (string.IsNullOrEmpty(document.PrimaryCareProvider))
            {
                document.PrimaryCareProvider = string.Empty;
            }

            if (string.IsNullOrEmpty(document.ReferringCareProviderID.ToString()))
            {
                document.ReferringCareProviderID = 0;
            }

            if (string.IsNullOrEmpty(document.ReferringCareProvider))
            {
                document.ReferringCareProvider = string.Empty;
            }

            if (string.IsNullOrEmpty(document.DocTypeName))
            {
                document.DocTypeName = string.Empty;
            }

            if (string.IsNullOrEmpty(document.SignerID.ToString()))
            {
                document.SignerID = 0;
            }

            using (IDbConnection db = new SqlConnection(ConfigurationValues.WaldenFaxConnection))
            {
                try
                {
                    const string query = "INSERT INTO [AllSignedNotes]"
                        + " ("
                        + " [DocumentID]"
                        + " ,[VisitID]"
                        + " ,[DateSigned]"
                        + " ,[PatientID]"
                        + " ,[PatientName]"
                        + " ,[CareProviderID]"
                        + " ,[CareProviderName]"
                        + " ,[PrimaryCareProviderID]"
                        + " ,[PrimaryCareProvider]"
                        + " ,[ReferringCareProviderID]"
                        + " ,[ReferringCareProvider]"
                        + " ,[DocTypeName]"
                        + " ,[SignerID]"
                        + ")"
                        + " VALUES"
                        + " ("
                        + " @DocumentID,@VisitID ,@DateSigned , @PatientID, @PatientName, @CareProviderID, @CareProviderName,"
                        + " @PrimaryCareProviderID, @PrimaryCareProvider, @ReferringCareProviderID, @ReferringCareProvider,"
                        + " @DocTypeName, @SignerID"
                        + " )";


                    int rowsAffectd = db.Execute(query, new
                    {
                        @DocumentID = document.DocumentID,
                        @VisitID = document.VisitID,
                        @DateSigned = document.DateSigned,
                        @PatientID = document.PatientID,
                        @PatientName = document.PatientName,
                        @CareProviderID = document.CareProviderID,
                        @CareProviderName = document.CareProviderName,
                        @PrimaryCareProviderID = document.PrimaryCareProviderID,
                        @PrimaryCareProvider = document.PrimaryCareProvider,
                        @ReferringCareProviderID = document.ReferringCareProviderID,
                        @ReferringCareProvider = document.ReferringCareProvider,
                        @DocTypeName = document.DocTypeName,
                        @SignerID = document.SignerID
                    });

                    operationResult.Success = true;
                    operationResult.AddMessage("Success");
                    return operationResult;
                }
                catch (Exception er)
                {
                    Utility.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString());
                    operationResult.Success = false;
                    operationResult.AddMessage(er.ToString());
                    return operationResult;
                }
            }
        }
        //public OperationResult SendFax(MiscFaxInformation miscFaxInformation, string permanentFaxPath, string from, string notes)
        public OperationResult SendFax( FaxingInformation miscFaxInformation, string permanentFaxPath, string from, string notes)
        {

            OperationResult operationResult = new Models.OperationResult();

            string now = DateTime.Now.ToShortDateString()
                + " "
                + DateTime.Now.ToShortTimeString();

            using (IDbConnection db = new SqlConnection(ConfigurationValues.WaldenFaxConnection))
            {
                try
                {
                    const string query = "INSERT INTO [FaxesSendServer]("
                        + "[AccountID]"
                        + ",[UserID]"
                        + ",[FaxName]"
                        + ",[FaxPath]"
                        + ",[FaxNumber]"
                        + ",[RecipientName]"
                        + ",[Notes]"
                        + ",[PageCount]"
                        + ",[FaxSent]"
                        + ",[InUse]"
                        + ",[ToTif]"
                        + ",[CallWait]"
                        + ",[TimesCalled]"
                        + ",[Status]"
                        + ",[ShowFax]"
                        + ",[CreateTime]"
                        + ",[CompletionTime]"
                        + ",[DateStamp])"
                        + " VALUES("
                        + "@AccountID"
                        + ",@UserID"
                        + ",@FaxName"
                        + ",@FaxPath"
                        + ",@FaxNumber"
                        + ",@RecipientName"
                        + ",@Notes"
                        + ",@PageCount"
                        + ",@FaxSent"
                        + ",@InUse"
                        + ",@ToTif"
                        + ",@CallWait"
                        + ",@TimesCalled"
                        + ",@Status"
                        + ",@ShowFax"
                        + ",@CreateTime"
                        + ",@CompletionTime"
                        + ",@DateStamp)";

                    int rowsAffectd = db.Execute(query, new
                    {
                        @AccountID = 1001,
                        @UserID = Utility.GetUserName(),
                        @FaxName = miscFaxInformation.Name,
                        @FaxPath = permanentFaxPath,
                        @FaxNumber = miscFaxInformation.FaxNumber,
                        @RecipientName = from,
                        @Notes = notes,
                        @PageCount = miscFaxInformation.PageCount,
                        @FaxSent = "Y",
                        @InUse = "N",
                        @ToTif = "Y",
                        @CallWait = 0,
                        @TimesCalled = 0,
                        @Status = "New Fax Entry",
                        @ShowFax = "Y",
                        @CreateTime = now,
                        @CompletionTime = string.Empty,
                        @DateStamp = now
                    });

                    int sendFaxId = GetSendFaxID();
                    operationResult.Success = true;
                    operationResult.AddMessage(sendFaxId.ToString());

                    return operationResult;
                }
                catch (Exception er)
                {
                    operationResult.Success = false;
                    operationResult.AddMessage(er.ToString());
                    return operationResult;
                }
            }
        }