private static void ProcessBarcodedDocuments(ImportDocument newDocumentToImport) { PostOffice.Api.DataAccess.DocumentRepository documentData = new PostOffice.Api.DataAccess.DocumentRepository(); CurrentDocuments currentDocument = documentData.GetCurrentDocumentPathPdf(Utility.GetUserName()); newDocumentToImport.FullPath = currentDocument.PathToCurrentPdfDocument; 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]; 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(); 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; PostOffice.Api.Document ocall = new PostOffice.Api.Document(); 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 OperationResult ProcessBarcodedDocuments(ImportDocument newDocumentToImport) { OperationResult operationResult = new OperationResult(); Logging.LogErrors(ConfigurationValues.ErrorLogPath, "Start Import"); PostOffice.Api.DataAccess.DocumentRepository documentData = new PostOffice.Api.DataAccess.DocumentRepository(); CurrentDocuments currentDocument = documentData.GetCurrentDocumentPathPdf(Utility.GetUserName()); newDocumentToImport.FullPath = currentDocument.PathToCurrentPdfDocument; Logging.LogErrors(ConfigurationValues.ErrorLogPath, "Start Creating Base 64"); 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]; 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); operationResult.Success = false; operationResult.AddMessage(er.ToString()); return operationResult; } string base64String; try { base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length); } catch (System.ArgumentNullException er) { //LogErrors("Binary data array is null."); string[] fileNameArray = newDocumentToImport.FullPath.Split('\\'); string fileName = fileNameArray[fileNameArray.Length - 1]; File.Copy(newDocumentToImport.FullPath, pathToErrorFolder + fileName, true); operationResult.Success = false; operationResult.AddMessage(er.ToString()); return operationResult; } Logging.LogErrors(ConfigurationValues.ErrorLogPath, "End Base 64"); ContractBuilder oBuilder = new ContractBuilder(); Logging.LogErrors(ConfigurationValues.ErrorLogPath, "1"); Greenway.PrimeSuite.DataContracts.Document.DocumentImportChartRequest oRequest = new Greenway.PrimeSuite.DataContracts.Document.DocumentImportChartRequest(); oRequest.Header = new Greenway.PrimeSuite.DataContracts.API.Header(); oRequest = oBuilder.BuildDocumentImportChartRequest(base64String); oRequest.PrimeSuitePatientId = newDocumentToImport.PatientID; oRequest.DocumentTypeID = newDocumentToImport.DocTypeId; oRequest.DocumentName = newDocumentToImport.DocumentName; oRequest.DocumentDescription = newDocumentToImport.DocumentName + " " + newDocumentToImport.Initials; oRequest.DocumentSignerID = int.Parse(ConfigurationValues.ProviderSignerID); Logging.LogErrors(ConfigurationValues.ErrorLogPath, "3"); if (newDocumentToImport.ProviderId.Length > 0) { oRequest.DocumentStatus = Greenway.PrimeSuite.DataContracts.Document.DocumentImportDocumentStatusDocumentImportDocumentStatusEnum.InProgress; oRequest.DocumentSignerID = int.Parse(newDocumentToImport.ProviderId); } oRequest.Credentials.PrimeSuiteCredential.PrimeSuiteUserName = greenwayUserID; oRequest.Credentials.PrimeSuiteCredential.PrimeSuiteUserPassword = greenwayUserPassword; PostOffice.Api.Document ocall = new PostOffice.Api.Document(); ocall.SendPdf(oRequest, greenwayServer); ArchiveDocument archiveDocument = new ArchiveDocument(); string[] listOfDocumentsToArchive = currentDocument.CurrentDocumentList.Split('~'); for (int i = 0; i < listOfDocumentsToArchive.Length - 1; i++) { try { string[] documentName = listOfDocumentsToArchive[i].Split('\\'); archiveDocument.ArchiveTheDocument(documentName[documentName.Length - 1], listOfDocumentsToArchive[i], Utility.GetUserName()); File.Delete(listOfDocumentsToArchive[i]); } catch (Exception er) { Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString()); operationResult.Success = true; operationResult.AddMessage("None"); return operationResult; } } operationResult.Success = true; operationResult.AddMessage("None"); return operationResult; } 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); operationResult.Success = false; operationResult.AddMessage(er.ToString()); return operationResult; } }