private static void ProcessBarcodedDocuments(ImportDocument newDocumentToImport) { PostOfficev2.API.DataAccess.DocumentRepository documentData = new PostOfficev2.API.DataAccess.DocumentRepository(); CurrentDocuments currentDocument = documentData.GetCurrentDocumentPathPDF(Utility.GetUserName()); newDocumentToImport.FullPath = currentDocument.PathToCurrentPDFDocument; int pdfPageCount = 0; Document pdfDocument = new Document(newDocumentToImport.FullPath); pdfPageCount = pdfDocument.Pages.Count; try { System.IO.FileStream inFile; byte[] binaryData; try { inFile = new System.IO.FileStream(newDocumentToImport.FullPath, System.IO.FileMode.Open, System.IO.FileAccess.Read); binaryData = new Byte[inFile.Length]; long bytesRead = inFile.Read(binaryData, 0, (int)inFile.Length); inFile.Close(); } catch (Exception er) { Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString()); string[] fileNameArray = newDocumentToImport.FullPath.Split('\\'); string fileName = fileNameArray[fileNameArray.Length - 1]; File.Copy(newDocumentToImport.FullPath, pathToErrorFolder + fileName, true); return; } string base64String; try { base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length); } catch (System.ArgumentNullException) { //LogErrors("Binary data array is null."); string[] fileNameArray = newDocumentToImport.FullPath.Split('\\'); string fileName = fileNameArray[fileNameArray.Length - 1]; File.Copy(newDocumentToImport.FullPath, pathToErrorFolder + fileName, true); //AddErrorDocument(pathToErrorFolder + fileName, barCodeText.User); return; } ContractBuilder oBuilder = new ContractBuilder(); Greenway.PrimeSuite.DataContracts.Document.DocumentImportChartRequest oRequest = new Greenway.PrimeSuite.DataContracts.Document.DocumentImportChartRequest(); Greenway.PrimeSuite.DataContracts.Document.DocumentImportChartResponse oResponse = new Greenway.PrimeSuite.DataContracts.Document.DocumentImportChartResponse(); oRequest.Header = new Greenway.PrimeSuite.DataContracts.API.Header(); oRequest = oBuilder.BuildDocumentImportChartRequest(base64String); oRequest.PrimeSuitePatientId = newDocumentToImport.PatientID; oRequest.DocumentTypeID = newDocumentToImport.DocTypeId; oRequest.DocumentName = "Lab Result -"; oRequest.DocumentDescription = string.Empty; oRequest.Credentials.PrimeSuiteCredential.PrimeSuiteUserName = greenwayUserID; oRequest.Credentials.PrimeSuiteCredential.PrimeSuiteUserPassword = greenwayUserPassword; GreenwayDocuments.DocImporter.Document ocall = new GreenwayDocuments.DocImporter.Document(); oResponse = ocall.SendPDF(oRequest, greenwayServer); ArchiveDocument archiveDocument = new ArchiveDocument(); string[] listOfDocumentsToArchive = currentDocument.CurrentDocumentList.Split('~'); for (int i = 0; i < listOfDocumentsToArchive.Length - 1; i++) { string[] documentName = listOfDocumentsToArchive[i].Split('\\'); archiveDocument.ArchiveTheDocument(documentName[documentName.Length - 1], listOfDocumentsToArchive[i], Utility.GetUserName()); File.Delete(listOfDocumentsToArchive[i]); } return; } catch (Exception er) { Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString()); string[] fileNameArray = newDocumentToImport.FullPath.Split('\\'); string fileName = fileNameArray[fileNameArray.Length - 1]; File.Copy(newDocumentToImport.FullPath, pathToErrorFolder + fileName, true); return; } }
private static void ProcessBarcodedDocuments(ScannedDocument barCodeText) { int pdfPageCount = 0; int pdfPageCountCheck = 0; Document pdfDocument = new Document(barCodeText.FullPath); pdfPageCount = pdfDocument.Pages.Count; pdfPageCountCheck = pdfPageCountCheck + barCodeText.PageCount; if (pdfPageCount != pdfPageCountCheck) { string[] fileNameArray = barCodeText.FullPath.Split('\\'); string fileName = fileNameArray[fileNameArray.Length - 1]; UpdateDocumentArchive(barCodeText.ArchiveID, "F"); File.Copy(barCodeText.FullPath, pathToErrorFolder + fileName, true); AddErrorDocument(pathToErrorFolder + fileName, barCodeText.User); File.Delete(barCodeText.FullPath); return; } try { System.IO.FileStream inFile; byte[] binaryData; try { inFile = new System.IO.FileStream(barCodeText.FullPath, System.IO.FileMode.Open, System.IO.FileAccess.Read); binaryData = new Byte[inFile.Length]; long bytesRead = inFile.Read(binaryData, 0, (int)inFile.Length); inFile.Close(); } catch (Exception er) { LogErrors(er.ToString()); string[] fileNameArray = barCodeText.FullPath.Split('\\'); string fileName = fileNameArray[fileNameArray.Length - 1]; File.Copy(barCodeText.FullPath, pathToErrorFolder + fileName, true); AddErrorDocument(pathToErrorFolder + fileName, barCodeText.User); return; } string base64String; try { base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length); } catch (System.ArgumentNullException) { LogErrors("Binary data array is null."); string[] fileNameArray = barCodeText.FullPath.Split('\\'); string fileName = fileNameArray[fileNameArray.Length - 1]; File.Copy(barCodeText.FullPath, pathToErrorFolder + fileName, true); AddErrorDocument(pathToErrorFolder + fileName, barCodeText.User); return; } ContractBuilder oBuilder = new ContractBuilder(); Greenway.PrimeSuite.DataContracts.Document.DocumentImportChartRequest oRequest = new Greenway.PrimeSuite.DataContracts.Document.DocumentImportChartRequest(); Greenway.PrimeSuite.DataContracts.Document.DocumentImportChartResponse oResponse = new Greenway.PrimeSuite.DataContracts.Document.DocumentImportChartResponse(); oRequest = oBuilder.BuildDocumentImportChartRequest(base64String); oRequest.PrimeSuitePatientId = int.Parse(barCodeText.PatientID); oRequest.DocumentTypeID = int.Parse(barCodeText.TabID); oRequest.DocumentName = GetDocumentNameBasedOnDocumentType(barCodeText.TabID); oRequest.DocumentSignerID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["providerSignerID"]); oRequest.Credentials.PrimeSuiteCredential.PrimeSuiteUserName = greenwayUserID; oRequest.Credentials.PrimeSuiteCredential.PrimeSuiteUserPassword = greenwayUserPassword; GreenwayDocuments.DocImporter.Document ocall = new GreenwayDocuments.DocImporter.Document(); int countOfRecordsFromGreenway = GetDocumentCountGreenway(oRequest.PrimeSuitePatientId.ToString(), oRequest.DocumentSignerID.ToString(), oRequest.DocumentTypeID.ToString(), "Imported - " + oRequest.DocumentName); int countOfRecordsFromScannedDocuments = GetDocumentCountScannedDocuments(oRequest.PrimeSuitePatientId.ToString(), oRequest.DocumentSignerID.ToString(), oRequest.DocumentTypeID.ToString(), "Imported - " + oRequest.DocumentName); oResponse = ocall.SendPDF(oRequest, greenwayServer); Log("The document id is: " + oResponse.DocumentID.ToString()); UpdateScannedDocuments(barCodeText.ID, oResponse.DocumentID.ToString()); UpdateDocumentArchive(barCodeText.ArchiveID, "T"); File.Delete(barCodeText.FullPath); CheckToSeeIfProblemWithRecords(); } catch (Exception er) { LogErrors("Error is : " + er.ToString() + "PatienID: " + barCodeText.PatientID + " <br />" + "Document Name: " + GetDocumentNameBasedOnDocumentType(barCodeText.TabID) + " <br />" + "Document Type ID: " + barCodeText.TabID + " <br />" + "Page Count: " + barCodeText.PageCount.ToString() + " <br />"); string[] fileNameArray = barCodeText.FullPath.Split('\\'); string fileName = fileNameArray[fileNameArray.Length - 1]; UpdateDocumentArchive(barCodeText.ArchiveID, "F"); File.Copy(barCodeText.FullPath, pathToErrorFolder + fileName, true); AddErrorDocument(pathToErrorFolder + fileName, barCodeText.User); return; } }