static void Main(string[] args)
        {
            string careProviderIDs = string.Empty;

            ConfigurationValues.GreenwayConnection = System.Configuration.ConfigurationManager.AppSettings["greenwayConnection"];
            ConfigurationValues.WaldenFaxConnection = System.Configuration.ConfigurationManager.AppSettings["fax"];
            ConfigurationValues.ProcessFaxPath = System.Configuration.ConfigurationManager.AppSettings["processFaxPath"];
            ConfigurationValues.CreatePdfPath = System.Configuration.ConfigurationManager.AppSettings["createPdfPath"];
            ConfigurationValues.CorrespondensePath = System.Configuration.ConfigurationManager.AppSettings["correspondensePath"];
            ConfigurationValues.ArchieveFolder = System.Configuration.ConfigurationManager.AppSettings["archieveFolder"];
            ConfigurationValues.FaxAutomationUserName = System.Configuration.ConfigurationManager.AppSettings["faxAutomationUserName"];

            Aspose.Pdf.License pdflicense = new Aspose.Pdf.License();
            pdflicense.SetLicense(System.Configuration.ConfigurationManager.AppSettings["aposePDFLicense"]);
            pdflicense.Embedded = true;

            List<SignedDocument> documentsList = GetListOfDocumentssToSendViaFax(GetListOfCarProviderIDs());
            List<FaxTelephoneNumber> faxTelephoneNumberList = new List<FaxTelephoneNumber>();

            for (int i = 0; i < documentsList.Count; i++)
            {
                InsertAllSignedNotes(documentsList[i]);

                if (documentsList[i].PrimaryCareProviderID > 0 && documentsList[i].ReferringCareProviderID > 0)
                {
                    if (documentsList[i].CareProviderID == documentsList[i].PrimaryCareProviderID )
                    {
                        careProviderIDs = " (" + documentsList[i].ReferringCareProviderID.ToString() + ")";
                    }
                    else if (documentsList[i].CareProviderID != documentsList[i].ReferringCareProviderID)
                    {
                        careProviderIDs = " (" + documentsList[i].PrimaryCareProviderID.ToString() + ")";
                    }
                    else
                    {
                        careProviderIDs = " (" + documentsList[i].PrimaryCareProviderID.ToString()
                            + "," + documentsList[i].ReferringCareProviderID.ToString()
                            + ")";
                    }
                }
                else if (documentsList[i].PrimaryCareProviderID > 0 && documentsList[i].ReferringCareProviderID == 0)
                {
                    if (documentsList[i].CareProviderID != documentsList[i].PrimaryCareProviderID)
                    {
                        careProviderIDs = " (" + documentsList[i].PrimaryCareProviderID.ToString() + ")";
                    }
                }
                else if (documentsList[i].PrimaryCareProviderID == 0 && documentsList[i].ReferringCareProviderID > 0)
                {
                    if (documentsList[i].CareProviderID != documentsList[i].ReferringCareProviderID)
                    {
                        careProviderIDs = " (" + documentsList[i].ReferringCareProviderID.ToString() + ")";
                    }
                }
                else if (documentsList[i].PrimaryCareProviderID == 0 && documentsList[i].ReferringCareProviderID == 0)
                {


                }

                faxTelephoneNumberList = GetFaxNumbers(careProviderIDs);

                for (int j = 0; j < faxTelephoneNumberList.Count; j++)
                {
                    if (faxTelephoneNumberList[j].FaxNumber.Length > 0)
                    {
                        GetDocumentFromGreenway(documentsList[i].DocumentID);

                        CreateLetterToPutInFrontOfNote(faxTelephoneNumberList[j], documentsList[i]);

                        SentNotesFax sentNotesFax = new SentNotesFax();
                        sentNotesFax.DocumentID = documentsList[i].DocumentID;
                        sentNotesFax.FromProviderID = documentsList[i].CareProviderID;
                        sentNotesFax.FromProviderName = documentsList[i].CareProviderName;
                        sentNotesFax.PatientID = documentsList[i].PatientID.ToString(); ;
                        sentNotesFax.PatientName = documentsList[i].PatientName;
                        sentNotesFax.ToProviderID = faxTelephoneNumberList[j].ProviderID;
                        sentNotesFax.ToProviderName = faxTelephoneNumberList[j].FullName;
                        ////faxTelephoneNumberList[j].FullName
                        ////string[] credential = faxTelephoneNumberList[j].FullName.Split(' ');
                        ////faxTelephoneNumberList[j].Name = faxTelephoneNumberList[j].Name = " ," + credential[credential.Length - 1];

                        //PdfFileEditor pdfEditor = new PdfFileEditor();
                        SendFax sendAFax = new Models.SendFax();
                        sendAFax.AccountID = "1001";
                        sendAFax.UserID = ConfigurationValues.FaxAutomationUserName;
                        sendAFax.FaxName = documentsList[i].CareProviderName;
                        sendAFax.FaxPath = ConfigurationValues.FinalFaxPath;
                        sendAFax.FaxNumber = faxTelephoneNumberList[j].FaxNumber;
                        //sendAFax.FaxNumber = "9,2034668585";
                        sendAFax.RecipientName = faxTelephoneNumberList[j].Name;
                        sendAFax.Notes = string.Empty;
                        sendAFax.PageCount = GetPageCount(ConfigurationValues.FinalFaxPath);
                        sendAFax.FaxSent = "Y";
                        sendAFax.InUse = "N";
                        sendAFax.ToTif = "Y";
                        sendAFax.CallWait = 0;
                        sendAFax.TimesCalled = 0;
                        sendAFax.Status = "New Fax Entry";
                        sendAFax.ShowFax = "Y";
                        sendAFax.CreateTime = DateTime.Now.ToShortDateString()
                            + " " + DateTime.Now.ToShortTimeString();
                        sendAFax.CompletionTime = string.Empty;
                        sendAFax.DateStamp = DateTime.Now.ToShortDateString()
                            + " " + DateTime.Now.ToShortTimeString();

                        OperationResult operationResult = SendFax(sendAFax);
                        sentNotesFax.SendID = int.Parse(operationResult.MessageList[0]);
                        AddReportingRecord(sentNotesFax);

                        if (operationResult.Success)
                        {
                            SendFaxMultitech sendFax = new SendFaxMultitech();

                            faxTelephoneNumberList[j].FaxNumber = faxTelephoneNumberList[j].FaxNumber.Replace("(", "")
                                .Replace(")", "")
                                .Replace("-", "")
                                .Replace(" ", "");

                            //sendFax.SendTheFax(documentsList[i].PatientName, ConfigurationValues.FinalFaxPath, faxTelephoneNumberList[j].Name, faxTelephoneNumberList[j].FaxNumber, operationResult.MessageList[0], "");
                        }
                    }
                }
            }

            //Scott here are the API calls you would need to make to get the data from the Greenway API for the faxing solution.  We are working to get you access to the PrimeSuite server that the test API uses.   No one was in the office Friday at Greenway to get it done.  We will also look at the API calls for the other project today. 
            //Goal: Provide a list of signed documents for the day
            //API transactions needed:
            //Visit Search
            //Care Provider Search
            //DocumentType Get
            //Document List Search 2
            //Document Get


            //Instructions:
            //1.       Call Visit Search with desired From/Through date
            //a.       This will give you a list of all patients seen during the specified date range. If you know which provider you want to filter by that would be ideal. You will get all patients from all providers if you don’t populate the CareProviderID field. 
            //b.      Call Care Provider Search if you need the Care Provider ID’s for a Provider.
            //2.       Call Document Type get
            //a.       This will give you a list of document types and their respective IDs for the practice –parts of this list can be unique for each practice.
            //3.       Call Document List Search 2 using Patient IDs from the response of Visit search. Use Doc Type ID if you want to filter the documents by a specific type. Use DocumentStatus=2 if you only want authenticated notes
            //a.       This will give you a DocumentID in the response
            //4.       Call Document Get to retrieve a PDF of the document-you will need to populate the DocumentID and the ExportType (PDF) in the request of this transaction.

            //This is the call for the visit search
            //            ContractBuilderVisitSearch oBuilder = new ContractBuilderVisitSearch();
            //            Greenway.PrimeSuite.DataContracts.SystemAdmin.VisitSearchRequest visitSearchRequest = new Greenway.PrimeSuite.DataContracts.SystemAdmin.VisitSearchRequest();
            //            Greenway.PrimeSuite.DataContracts.SystemAdmin.VisitSearchCriteria visitSearchCriteria = new Greenway.PrimeSuite.DataContracts.SystemAdmin.VisitSearchCriteria();
            //            Greenway.PrimeSuite.DataContracts.SystemAdmin.VisitSearchResponse visitSearchResponse = new Greenway.PrimeSuite.DataContracts.SystemAdmin.VisitSearchResponse();

            //            visitSearchRequest = oBuilder.BuildVisitSearchRequest();
            //            visitSearchCriteria.PatientID = 1121;
            //            visitSearchRequest.VisitSearchCriteria = visitSearchCriteria;

            //            AutomatedFax.SearchVisits ocall = new SearchVisits();
            //            visitSearchResponse = ocall.GetVisitsFromSearch(visitSearchRequest, "192.168.192.11");

            //This is the call for the Care Provider Search
            ContractBuilderProviderSearch oBuilderProviderSearch = new ContractBuilderProviderSearch();
            //            Greenway.PrimeSuite.DataContracts.Person.CareProvider.CareProviderSearchRequest careProviderSearchRequest = new Greenway.PrimeSuite.DataContracts.Person.CareProvider.CareProviderSearchRequest();
            //            Greenway.PrimeSuite.DataContracts.Person.CareProvider.CareProviderSearchResponse careProviderSearchResponse = new Greenway.PrimeSuite.DataContracts.Person.CareProvider.CareProviderSearchResponse();
            //            careProviderSearchRequest = oBuilderProviderSearch.BuildProviderSearchRequest();
            //            //oBuilderProviderSearch.BuildProviderSearchRequest
            //            careProviderSearchRequest.CareProviderID = 1671;
            //            AutomatedFax.SearchProviders ocallSearchProviders = new SearchProviders();
            //            careProviderSearchResponse = ocallSearchProviders.GetProvidersFromSearch(careProviderSearchRequest, "192.168.192.11");

            //This is the call for Call Document Type
            //            ContractBuilderDocumentTypeSearch oBuilderDocumentTypeSearch = new ContractBuilderDocumentTypeSearch();
            //            Greenway.PrimeSuite.DataContracts.SystemAdmin.DocumentTypeSearchRequest documentTypeSearchRequest = new Greenway.PrimeSuite.DataContracts.SystemAdmin.DocumentTypeSearchRequest();
            //            Greenway.PrimeSuite.DataContracts.SystemAdmin.DocumentTypeSearchResponse documentTypeSearchResponse = new Greenway.PrimeSuite.DataContracts.SystemAdmin.DocumentTypeSearchResponse();
            //            documentTypeSearchRequest = oBuilderDocumentTypeSearch.BuildDocumentTypeSearchRequest();
            //            AutomatedFax.SearchDocumentType ocallSearchDocumentType = new SearchDocumentType();
            //            documentTypeSearchResponse = ocallSearchDocumentType.GetDocumentTypeFromSearch(documentTypeSearchRequest, "192.168.192.11");

            //This is the call for Document List Search 2
            //            ContractBuilderDocumentSearch oBuilderDocumentSearch = new ContractBuilderDocumentSearch();
            //            Greenway.PrimeSuite.DataContracts.Document.DocumentListSearchRequest2 documentListSearchRequest = new Greenway.PrimeSuite.DataContracts.Document.DocumentListSearchRequest2();
            //            Greenway.PrimeSuite.DataContracts.Document.DocumentListSearchResponse documentListSearchResponse = new Greenway.PrimeSuite.DataContracts.Document.DocumentListSearchResponse();
            //            documentListSearchRequest = oBuilderDocumentSearch.BuildDocumentSearchRequest();
            //            AutomatedFax.SearchDocumentSearch ocallSearchDocument = new SearchDocumentSearch();
            //            documentListSearchResponse = ocallSearchDocument.GetDocumentFromSearch(documentListSearchRequest, "192.168.192.11");

            //This is the call for Document Get
            //ContractBuilderDocumentGet oBuilderDocumentGet = new ContractBuilderDocumentGet();
            //Greenway.PrimeSuite.DataContracts.Document.DocumentGetRequest documentGetRequest = new Greenway.PrimeSuite.DataContracts.Document.DocumentGetRequest();
            //Greenway.PrimeSuite.DataContracts.Document.DocumentGetResponse documentGetResponse = new Greenway.PrimeSuite.DataContracts.Document.DocumentGetResponse();
            //documentGetRequest = oBuilderDocumentGet.BuildDocumentGethRequest();
            //AutomatedFax.SearchDocumentGet ocallGetDocument = new SearchDocumentGet();
            //documentGetResponse = ocallGetDocument.GetDocumentListFromSearch(documentGetRequest, "192.168.192.11");

            string s1 = string.Empty;
        }
        private static OperationResult AddReportingRecord(SentNotesFax sentNotesFax)
        {

            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 [FaxesSent]"
                        + "("
                        + "[DocumentID]"
                        + " ,[PatientID]"
                        + " ,[PatientName]"
                        + " ,[ToProviderID]"
                        + " ,[ToProviderName]"
                        + " ,[FromProviderID]"
                        + " ,[FromProviderName]"
                        + " ,[DateTimeCreated]"
                        + " ,[DateTimeSent]"
                        + " ,[SendID]"
                        + ")"
                        + "VALUES"
                        + "("
                        + "@DocumentID,@PatientID,@PatientName,@ToProviderID,@ToProviderName,@FromProviderID"
                        + ",@FromProviderName,@DateTimeCreated,@DateTimeSent,@SendID)";

                    int rowsAffectd = db.Execute(query, new
                    {
                        @DocumentID = sentNotesFax.DocumentID,
                        @PatientID = sentNotesFax.PatientID,
                        @PatientName = sentNotesFax.PatientName,
                        @ToProviderID = sentNotesFax.ToProviderID,
                        @ToProviderName = sentNotesFax.ToProviderName,
                        @FromProviderID = sentNotesFax.FromProviderID,
                        @FromProviderName = sentNotesFax.FromProviderName,
                        @DateTimeCreated = now,
                        @DateTimeSent = now,
                        @SendID = sentNotesFax.SendID
                    });

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

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




            throw new NotImplementedException();
        }