Example #1
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);
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
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);
        }