Beispiel #1
0
 ///<summary>Deletes the passed in list of statements. Checks for permission before deleting the stored image in ODI folder. Can force to delete the
 ///stored image without the permission check. Will always delete the statement object. Throws UE.</summary>
 public static void DeleteStatements(List <Statement> listStatements, bool forceImageDelete = false)
 {
     if (listStatements.IsNullOrEmpty())
     {
         return;
     }
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         Meth.GetVoid(MethodBase.GetCurrentMethod(), listStatements, forceImageDelete);
         return;
     }
     foreach (Statement stmt in listStatements)
     {
         //Per Nathan the image should not be deleted if the user does not have the Image Delete permission.  The statement can still be deleted.
         if (stmt.DocNum != 0 && (forceImageDelete || Security.IsAuthorized(Permissions.ImageDelete, stmt.DateSent, true)))
         {
             //deleted the pdf
             Patient         pat       = Patients.GetPat(stmt.PatNum);
             string          patFolder = ImageStore.GetPatientFolder(pat, ImageStore.GetPreferredAtoZpath());
             List <Document> listdocs  = new List <Document>();
             listdocs.Add(Documents.GetByNum(stmt.DocNum, true));
             ImageStore.DeleteDocuments(listdocs, patFolder);                   //May throw if document is in use.
         }
         Delete(stmt);
     }
 }
Beispiel #2
0
        /// <summary>Always saves as bmp.  So the 'paste to mount' logic needs to be changed to prevent conversion to bmp.</summary>
        public static Document ImportImageToMount(Bitmap image, short rotationAngle, long mountItemNum, long docCategory, Patient pat)
        {
            string   patFolder     = GetPatientFolder(pat, GetPreferredAtoZpath());
            string   fileExtention = ".bmp";          //The file extention to save the greyscale image as.
            Document doc           = new Document();

            doc.MountItemNum   = mountItemNum;
            doc.DegreesRotated = rotationAngle;
            doc.ImgType        = ImageType.Radiograph;
            doc.FileName       = fileExtention;
            doc.DateCreated    = DateTime.Today;
            doc.PatNum         = pat.PatNum;
            doc.DocCategory    = docCategory;
            doc.WindowingMin   = PrefC.GetInt(PrefName.ImageWindowingMin);
            doc.WindowingMax   = PrefC.GetInt(PrefName.ImageWindowingMax);
            Documents.Insert(doc, pat);           //creates filename and saves to db
            doc = Documents.GetByNum(doc.DocNum);
            try {
                SaveDocument(doc, image, ImageFormat.Bmp, patFolder);
            }
            catch {
                Documents.Delete(doc);
                throw;
            }
            return(doc);
        }
Beispiel #3
0
        /// <summary>Obviously no support for db storage</summary>
        public static Document ImportForm(string form, long docCategory, Patient pat)
        {
            string patFolder      = GetPatientFolder(pat, GetPreferredAtoZpath());
            string pathSourceFile = ODFileUtils.CombinePaths(GetPreferredAtoZpath(), "Forms", form);

            if (!File.Exists(pathSourceFile))
            {
                throw new Exception(Lans.g("ContrDocs", "Could not find file: ") + pathSourceFile);
            }
            Document doc = new Document();

            doc.FileName    = Path.GetExtension(pathSourceFile);
            doc.DateCreated = DateTime.Today;
            doc.DocCategory = docCategory;
            doc.PatNum      = pat.PatNum;
            doc.ImgType     = ImageType.Document;
            Documents.Insert(doc, pat);           //this assigns a filename and saves to db
            doc = Documents.GetByNum(doc.DocNum);
            try {
                SaveDocument(doc, pathSourceFile, patFolder);
            }
            catch {
                Documents.Delete(doc);
                throw;
            }
            return(doc);
        }
Beispiel #4
0
        ///<summary>Used along with GetChangedSinceDocumentNums</summary>
        public static List <Document> GetMultDocuments(List <long> documentNums, string AtoZpath)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <List <Document> >(MethodBase.GetCurrentMethod(), documentNums, AtoZpath));
            }
            string    strDocumentNums = "";
            DataTable table;

            if (documentNums.Count > 0)
            {
                for (int i = 0; i < documentNums.Count; i++)
                {
                    if (i > 0)
                    {
                        strDocumentNums += "OR ";
                    }
                    strDocumentNums += "DocNum='" + documentNums[i].ToString() + "' ";
                }
                string command = "SELECT * FROM document WHERE " + strDocumentNums;
                table = Db.GetTable(command);
            }
            else
            {
                table = new DataTable();
            }
            Document[]      multDocuments = Crud.DocumentCrud.TableToList(table).ToArray();
            List <Document> documentList  = new List <Document>(multDocuments);

            foreach (Document d in documentList)
            {
                if (string.IsNullOrEmpty(d.RawBase64))
                {
                    Patient pat             = Patients.GetPat(d.PatNum);
                    string  filePathAndName = ImageStore.GetFilePath(Documents.GetByNum(d.DocNum), AtoZpath);
                    if (File.Exists(filePathAndName))
                    {
                        FileStream fs      = new FileStream(filePathAndName, FileMode.Open, FileAccess.Read);
                        byte[]     rawData = new byte[fs.Length];
                        fs.Read(rawData, 0, (int)fs.Length);
                        fs.Close();
                        d.RawBase64 = Convert.ToBase64String(rawData);
                    }
                }
            }
            return(documentList);
        }
Beispiel #5
0
        /// <summary></summary>
        public static Document Import(string pathImportFrom, long docCategory, Patient pat)
        {
            string patFolder = "";

            if (PrefC.UsingAtoZfolder)
            {
                patFolder = GetPatientFolder(pat, GetPreferredAtoZpath());
            }
            Document doc = new Document();

            //Document.Insert will use this extension when naming:
            if (Path.GetExtension(pathImportFrom) == "")           //If the file has no extension
            {
                doc.FileName = ".jpg";
            }
            else
            {
                doc.FileName = Path.GetExtension(pathImportFrom);
            }
            doc.DateCreated = File.GetLastWriteTime(pathImportFrom);
            doc.PatNum      = pat.PatNum;
            if (HasImageExtension(doc.FileName))
            {
                doc.ImgType = ImageType.Photo;
            }
            else
            {
                doc.ImgType = ImageType.Document;
            }
            doc.DocCategory = docCategory;
            Documents.Insert(doc, pat);           //this assigns a filename and saves to db
            doc = Documents.GetByNum(doc.DocNum);
            try {
                SaveDocument(doc, pathImportFrom, patFolder);
                if (PrefC.UsingAtoZfolder)
                {
                    Documents.Update(doc);
                }
            }
            catch {
                Documents.Delete(doc);
                throw;
            }
            return(doc);
        }
Beispiel #6
0
        ///<summary>Attempts to open the document using the default program. If not using AtoZfolder saves a local temp file and opens it.</summary>
        public static void OpenDoc(long docNum)
        {
            Document docCur = Documents.GetByNum(docNum);

            if (docCur.DocNum == 0)
            {
                return;
            }
            Patient patCur = Patients.GetPat(docCur.PatNum);

            if (patCur == null)
            {
                return;
            }
            string docPath;

            if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ)
            {
                docPath = ImageStore.GetFilePath(docCur, ImageStore.GetPatientFolder(patCur, ImageStore.GetPreferredAtoZpath()));
            }
            else if (PrefC.AtoZfolderUsed == DataStorageType.InDatabase)
            {
                //Some programs require a file on disk and cannot open in memory files. Save to temp file from DB.
                docPath = PrefC.GetRandomTempFile(ImageStore.GetExtension(docCur));
                File.WriteAllBytes(docPath, Convert.FromBase64String(docCur.RawBase64));
            }
            else              //Cloud storage
                              //Download file to temp directory
            {
                OpenDentalCloud.Core.TaskStateDownload state = CloudStorage.Download(ImageStore.GetPatientFolder(patCur, ImageStore.GetPreferredAtoZpath())
                                                                                     , docCur.FileName);
                docPath = PrefC.GetRandomTempFile(ImageStore.GetExtension(docCur));
                if (ODBuild.IsWeb())
                {
                    ThinfinityUtils.HandleFile(docPath);
                    return;
                }
                File.WriteAllBytes(docPath, state.FileContent);
            }
            Process.Start(docPath);
        }
Beispiel #7
0
        //Checks to see if the document exists in the correct location, or checks DB for stored content.
        public static bool DocExists(long docNum)
        {
            Document docCur = Documents.GetByNum(docNum);

            if (docCur.DocNum == 0)
            {
                return(false);
            }
            Patient patCur = Patients.GetPat(docCur.PatNum);

            if (patCur == null)
            {
                return(false);
            }
            if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ)
            {
                return(File.Exists(ImageStore.GetFilePath(docCur, ImageStore.GetPatientFolder(patCur, ImageStore.GetPreferredAtoZpath()))));
            }
            else if (CloudStorage.IsCloudStorage)
            {
                return(CloudStorage.FileExists(ODFileUtils.CombinePaths(ImageStore.GetPatientFolder(patCur, ImageStore.GetPreferredAtoZpath()), docCur.FileName, '/')));
            }
            return(!string.IsNullOrEmpty(docCur.RawBase64));
        }
Beispiel #8
0
        /*
         * public static Document Import(Bitmap image,long docCategory,Patient pat) {
         *      string patFolder="";
         *      if(PrefC.UsingAtoZfolder) {
         *              patFolder=GetPatientFolder(pat,GetPreferredAtoZpath());
         *      }
         *      Document doc=new Document();
         *      doc.FileName=".jpg";
         *      doc.DateCreated=DateTime.Today;
         *      doc.DocCategory=docCategory;
         *      doc.PatNum=pat.PatNum;
         *      doc.ImgType=ImageType.Photo;
         *      //doc.RawBase64 handled further down.
         *      //doc.Thumbnail="";//no thumbnail yet
         *      Documents.Insert(doc,pat);//this assigns a filename and saves to db
         *      doc=Documents.GetByNum(doc.DocNum);
         *      try {
         *              SaveDocument(doc,image,ImageFormat.Jpeg,patFolder);
         *              if(PrefC.UsingAtoZfolder) {
         *                      Documents.Update(doc);
         *              }
         *      }
         *      catch {
         *              Documents.Delete(doc);
         *              throw;
         *      }
         *      return doc;
         * }*/

        /// <summary>Saves to either AtoZ folder or to db.  Saves image as a jpg.  Compression will differ depending on imageType.</summary>
        public static Document Import(Bitmap image, long docCategory, ImageType imageType, Patient pat)
        {
            string patFolder = "";

            if (PrefC.UsingAtoZfolder)
            {
                patFolder = GetPatientFolder(pat, GetPreferredAtoZpath());
            }
            Document doc = new Document();

            doc.ImgType     = imageType;
            doc.FileName    = ".jpg";
            doc.DateCreated = DateTime.Today;
            doc.PatNum      = pat.PatNum;
            doc.DocCategory = docCategory;
            Documents.Insert(doc, pat);           //creates filename and saves to db
            doc = Documents.GetByNum(doc.DocNum);
            long qualityL = 0;

            if (imageType == ImageType.Radiograph)
            {
                qualityL = 100;
            }
            else if (imageType == ImageType.Photo)
            {
                qualityL = 100;
            }
            else              //Assume document
                              //Possible values 0-100?
            {
                qualityL = PrefC.GetLong(PrefName.ScannerCompression);
            }
            ImageCodecInfo myImageCodecInfo;

            ImageCodecInfo[] encoders;
            encoders         = ImageCodecInfo.GetImageEncoders();
            myImageCodecInfo = null;
            for (int j = 0; j < encoders.Length; j++)
            {
                if (encoders[j].MimeType == "image/jpeg")
                {
                    myImageCodecInfo = encoders[j];
                }
            }
            EncoderParameters myEncoderParameters = new EncoderParameters(1);
            EncoderParameter  myEncoderParameter  = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityL);

            myEncoderParameters.Param[0] = myEncoderParameter;
            //AutoCrop()?
            try {
                SaveDocument(doc, image, myImageCodecInfo, myEncoderParameters, patFolder);
                if (!PrefC.UsingAtoZfolder)
                {
                    Documents.Update(doc);                    //because SaveDocument stuck the image in doc.RawBase64.
                    //no thumbnail yet
                }
            }
            catch {
                Documents.Delete(doc);
                throw;
            }
            return(doc);
        }