private Document SaveToImageFolder(string fileSourcePath, LetterMerge letterCur)
        {
            if (letterCur.ImageFolder == 0)           //This shouldn't happen
            {
                return(new Document());
            }
            string rawBase64 = "";

            if (PrefC.AtoZfolderUsed == DataStorageType.InDatabase)
            {
                rawBase64 = Convert.ToBase64String(File.ReadAllBytes(fileSourcePath));
            }
            Document docSave = new Document();

            docSave.DocNum      = Documents.Insert(docSave);
            docSave.ImgType     = ImageType.Document;
            docSave.DateCreated = DateTime.Now;
            docSave.PatNum      = PatCur.PatNum;
            docSave.DocCategory = letterCur.ImageFolder;
            docSave.Description = letterCur.Description + docSave.DocNum; //no extension.
            docSave.RawBase64   = rawBase64;                              //blank if using AtoZfolder
            docSave.FileName    = ODFileUtils.CleanFileName(letterCur.Description) + GetFileExtensionForWordDoc(fileSourcePath);
            string fileDestPath = ImageStore.GetFilePath(docSave, ImageStore.GetPatientFolder(PatCur, ImageStore.GetPreferredAtoZpath()));

            FileAtoZ.Copy(fileSourcePath, fileDestPath, FileAtoZSourceDestination.LocalToAtoZ);
            Documents.Update(docSave);
            return(docSave);
        }
Exemple #2
0
        private void SaveToImageFolder(string fileSourcePath, LetterMerge letterCur)
        {
            if (letterCur.ImageFolder == 0)           //This shouldn't happen
            {
                return;
            }
            string rawBase64 = "";

            if (PrefC.AtoZfolderUsed == DataStorageType.InDatabase)
            {
                rawBase64 = Convert.ToBase64String(File.ReadAllBytes(fileSourcePath));
            }
            Document docSave = new Document();

            docSave.DocNum = Documents.Insert(docSave);
            string fileName     = Lans.g(this, "LetterMerge") + "_" + letterCur.Description + docSave.DocNum;
            string fileDestPath = FileAtoZ.CombinePaths(ImageStore.GetPatientFolder(PatCur, ImageStore.GetPreferredAtoZpath()), fileName + ".doc");

            docSave.ImgType     = ImageType.Document;
            docSave.DateCreated = DateTime.Now;
            docSave.PatNum      = PatCur.PatNum;
            docSave.DocCategory = letterCur.ImageFolder;
            docSave.Description = fileName;          //no extension.
            docSave.RawBase64   = rawBase64;         //blank if using AtoZfolder
            docSave.FileName    = fileName + ".doc"; //file extension used for both DB images and AtoZ images
            FileAtoZ.Copy(fileSourcePath, fileDestPath, FileAtoZSourceDestination.LocalToAtoZ);
            Documents.Update(docSave);
        }
        private void butSavePDFToImages_Click(object sender, EventArgs e)
        {
            if (gridMain.ListGridRows.Count == 0)
            {
                MsgBox.Show(this, "Grid is empty.");
                return;
            }
            //Get image category to save to. First image "Statement(S)" category.
            List <Def> listImageCatDefs = Defs.GetDefsForCategory(DefCat.ImageCats, true).Where(x => x.ItemValue.Contains("S")).ToList();

            if (listImageCatDefs.IsNullOrEmpty())
            {
                MsgBox.Show(this, "No image category set for Statements.");
                return;
            }
            string tempFile = PrefC.GetRandomTempFile(".pdf");

            CreatePDF(tempFile);
            Patient patCur    = _fam.GetPatient(PatNum);
            string  rawBase64 = "";

            if (PrefC.AtoZfolderUsed == DataStorageType.InDatabase)
            {
                rawBase64 = Convert.ToBase64String(File.ReadAllBytes(tempFile));
            }
            Document docSave = new Document();

            docSave.DocNum      = Documents.Insert(docSave);
            docSave.ImgType     = ImageType.Document;
            docSave.DateCreated = DateTime.Now;
            docSave.PatNum      = PatNum;
            docSave.DocCategory = listImageCatDefs.FirstOrDefault().DefNum;
            docSave.Description = $"ServiceDateView" + docSave.DocNum + $"{docSave.DateCreated.Year}_{docSave.DateCreated.Month}_{docSave.DateCreated.Day}";
            docSave.RawBase64   = rawBase64;        //blank if using AtoZfolder
            string fileName = ODFileUtils.CleanFileName(docSave.Description);
            string filePath = ImageStore.GetPatientFolder(patCur, ImageStore.GetPreferredAtoZpath());

            while (FileAtoZ.Exists(FileAtoZ.CombinePaths(filePath, fileName + ".pdf")))
            {
                fileName += "x";
            }
            FileAtoZ.Copy(tempFile, ODFileUtils.CombinePaths(filePath, fileName + ".pdf"), FileAtoZSourceDestination.LocalToAtoZ);
            docSave.FileName = fileName + ".pdf";        //file extension used for both DB images and AtoZ images
            Documents.Update(docSave);
            try {
                File.Delete(tempFile);                 //cleanup the temp file.
            }
            catch (Exception ex) {
                ex.DoNothing();
            }
            MsgBox.Show(this, "PDF saved successfully.");
        }