Exemple #1
0
 ///<summary>For each of the documents in the list, deletes row from db and image from AtoZ folder if needed.</summary>
 public static void DeleteDocuments(IList <Document> documents, string patFolder)
 {
     for (int i = 0; i < documents.Count; i++)
     {
         if (documents[i] == null)
         {
             continue;
         }
         if (PrefC.UsingAtoZfolder)
         {
             try{
                 string filePath = ODFileUtils.CombinePaths(patFolder, documents[i].FileName);
                 if (File.Exists(filePath))
                 {
                     File.Delete(filePath);
                 }
             }
             catch {
                 //if(verbose) {
                 //	Debug.WriteLine(Lans.g("ContrDocs", "Could not delete file. It may be in use elsewhere, or may have already been deleted."));
                 //}
             }
         }
         //Row from db.  This deletes the "image file" also if it's stored in db.
         Documents.Delete(documents[i]);
     }
 }
Exemple #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);
        }
Exemple #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);
        }
Exemple #4
0
 ///<summary>For each of the documents in the list, deletes row from db and image from AtoZ folder if needed.  Throws exception if the file cannot be deleted.  Surround in try/catch.</summary>
 public static void DeleteDocuments(IList <Document> documents, string patFolder)
 {
     for (int i = 0; i < documents.Count; i++)
     {
         if (documents[i] == null)
         {
             continue;
         }
         if (PrefC.AtoZfolderUsed)
         {
             try {
                 string filePath = ODFileUtils.CombinePaths(patFolder, documents[i].FileName);
                 if (File.Exists(filePath))
                 {
                     File.Delete(filePath);
                 }
             }
             catch {
                 throw new Exception(Lans.g("ContrImages", "Could not delete file, it may be in use."));
             }
         }
         //Row from db.  This deletes the "image file" also if it's stored in db.
         Documents.Delete(documents[i]);
     }
 }
Exemple #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);
        }
Exemple #6
0
        ///<summary>Cascading delete that deletes all MedLab, MedLabResult, MedLabSpecimen, and MedLabFacAttach.
        ///Also deletes any embedded PDFs that are linked to by the MedLabResults.
        ///The MedLabs and all associated results, specimens, and FacAttaches referenced by the MedLabNums in listExcludeMedLabNums will not be deleted.
        ///Used for deleting old entries and keeping new ones.  The list may be empty and then all will be deleted.</summary>
        public static int DeleteLabsAndResults(MedLab medLab, List <long> listExcludeMedLabNums = null)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetInt(MethodBase.GetCurrentMethod(), medLab, listExcludeMedLabNums));
            }
            List <MedLab> listLabsOld = MedLabs.GetForPatAndSpecimen(medLab.PatNum, medLab.SpecimenID, medLab.SpecimenIDFiller);       //patNum could be 0

            if (listExcludeMedLabNums != null)
            {
                listLabsOld = listLabsOld.FindAll(x => !listExcludeMedLabNums.Contains(x.MedLabNum));
            }
            if (listLabsOld.Count < 1)
            {
                return(0);
            }
            int                 failedCount    = 0;
            List <long>         listLabNumsOld = listLabsOld.Select(x => x.MedLabNum).ToList();
            List <MedLabResult> listResultsOld = listLabsOld.SelectMany(x => x.ListMedLabResults).ToList();         //sends one query to the db per MedLab

            MedLabFacAttaches.DeleteAllForLabsOrResults(listLabNumsOld, listResultsOld.Select(x => x.MedLabResultNum).ToList());
            MedLabSpecimens.DeleteAllForLabs(listLabNumsOld);            //MedLabSpecimens have a FK to MedLabNum
            MedLabResults.DeleteAllForMedLabs(listLabNumsOld);           //MedLabResults have a FK to MedLabNum
            MedLabs.DeleteAll(listLabNumsOld);
            foreach (Document doc in Documents.GetByNums(listResultsOld.Select(x => x.DocNum).ToList()))
            {
                Patient docPat = Patients.GetPat(doc.PatNum);
                if (docPat == null)
                {
                    Documents.Delete(doc);
                    continue;
                }
                try {
                    ImageStore.DeleteDocuments(new List <Document> {
                        doc
                    }, ImageStore.GetPatientFolder(docPat, ImageStore.GetPreferredAtoZpath()));
                }
                catch (Exception ex) {
                    ex.DoNothing();                    //To avoid a warning message.  The ex is needed to ensure all exceptions are caught.
                    failedCount++;
                }
            }
            return(failedCount);
        }
Exemple #7
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);
        }