public Document Import(string path, int docCategory)
        {
            Document doc = new Document();

            //Document.Insert will use this extension when naming:
            doc.FileName    = Path.GetExtension(path);
            doc.DateCreated = DateTime.Today;
            doc.PatNum      = Patient.PatNum;
            doc.ImgType     = (HasImageExtension(path) || Path.GetExtension(path) == "") ? ImageType.Photo : ImageType.Document;
            doc.DocCategory = docCategory;
            Documents.Insert(doc, Patient);            //this assigns a filename and saves to db
            try {
                // If the file has no extension, try to open it as a image. If it is an image,
                // save it as a JPEG file.
                if (Path.GetExtension(path) == string.Empty && IsImageFile(path))
                {
                    Bitmap testImage = new Bitmap(path);
                    doc.FileName += ".jpg";
                    Documents.Update(doc);
                    SaveDocument(doc, testImage, ImageFormat.Jpeg);
                }
                else
                {
                    // Just copy the file.
                    SaveDocument(doc, path);
                }
            }
            catch {
                Documents.Delete(doc);
                throw;
            }
            return(doc);
        }
        public Document ImportForm(string form, int docCategory)
        {
            string fileName = ODFileUtils.CombinePaths(new string[] { FileStoreSettings.GetPreferredImagePath,
                                                                      "Forms", form });

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

            doc.FileName    = Path.GetExtension(fileName);
            doc.DateCreated = DateTime.Today;
            doc.DocCategory = docCategory;
            doc.PatNum      = Patient.PatNum;
            doc.ImgType     = ImageType.Document;
            Documents.Insert(doc, Patient);            //this assigns a filename and saves to db
            try {
                SaveDocument(doc, fileName);
            }
            catch {
                Documents.Delete(doc);
                throw;
            }
            return(doc);
        }
        public void DeleteTest()
        {
            VerifyExists();
            bool value = false;

            try
            {
                long id = Documents.GetId(_databasePath, Doc_Title, out _errOut);
                if (_errOut.Length > 0)
                {
                    throw new Exception(_errOut);
                }
                if (!Documents.Delete(_databasePath, id, out _errOut))
                {
                    throw new Exception(_errOut);
                }
                value = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            General.HasTrueValue(value, _errOut);
        }
        protected void btnDeleteLink_Click(Object Sender, EventArgs e)
        {
            LinkButton oDelete     = (LinkButton)Sender;
            int        intDocument = Int32.Parse(oDelete.CommandArgument);

            oDocument.Delete(intDocument, true, oVariables.DocumentsFolder());
            Response.Redirect(Request.Path + URL() + "&delete=true");
        }
        public void Documents__Delete__ShouldRemoveADocument()
        {
            SetSandboxUrl();
            Document doc = new Document();

            doc.OriginalHash = MifielAPI.Utils.MifielUtils.GetDocumentHash(_pdfFilePath);
            doc.FileName     = "PdfFileName";
            doc = _docs.Save(doc);

            _docs.Delete(doc.Id);
        }
        public Document Import(Bitmap image, int docCategory, ImageType imageType)
        {
            Document doc = new Document();

            doc.ImgType     = imageType;
            doc.FileName    = ".jpg";
            doc.DateCreated = DateTime.Today;
            doc.PatNum      = Patient.PatNum;
            doc.DocCategory = docCategory;
            Documents.Insert(doc, Patient);            //creates filename and saves to db

            long qualityL = 0;

            if (imageType == ImageType.Radiograph)
            {
                qualityL = Convert.ToInt64(((Pref)PrefB.HList["ScannerCompressionRadiographs"]).ValueString);
            }
            else if (imageType == ImageType.Photo)
            {
                qualityL = Convert.ToInt64(((Pref)PrefB.HList["ScannerCompressionPhotos"]).ValueString);
            }
            else              //Assume document
                              //Possible values 0-100?
            {
                qualityL = (long)Convert.ToInt32(((Pref)PrefB.HList["ScannerCompression"]).ValueString);
            }

            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];
                }
            }
            System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
            EncoderParameters myEncoderParameters    = new EncoderParameters(1);
            EncoderParameter  myEncoderParameter     = new EncoderParameter(myEncoder, qualityL);

            myEncoderParameters.Param[0] = myEncoderParameter;
            //AutoCrop()?
            try {
                SaveDocument(doc, image, myImageCodecInfo, myEncoderParameters);
            }
            catch {
                Documents.Delete(doc);
                throw;
            }
            return(doc);
        }
        public void ImportPdf(string sPDF)
        {
            Document DocCur = new Document();

            DocCur.FileName    = ".pdf";
            DocCur.DateCreated = DateTime.Today;

            //Find the category, hopefully 'Patient Information'
            //otherwise, just default to first one
            int iCategory = iCategory = DefB.Short[(int)DefCat.ImageCats][0].DefNum;;

            for (int i = 0; i < DefB.Short[(int)DefCat.ImageCats].Length; i++)
            {
                if (DefB.Short[(int)DefCat.ImageCats][i].ItemName == "Patient Information")
                {
                    iCategory = DefB.Short[(int)DefCat.ImageCats][i].DefNum;
                }
            }

            DocCur.DocCategory = iCategory;
            DocCur.ImgType     = ImageType.Document;
            DocCur.Description = "New Patient Form";
            DocCur.PatNum      = Patient.PatNum;
            Documents.Insert(DocCur, Patient);            //this assigns a filename and saves to db

            // Save the PDF to a temporary file, then import that file.
            string tempFileName = Path.GetTempFileName();

            try {
                // Convert the Base64 UUEncoded input into binary output.
                byte[] binaryData = Convert.FromBase64String(sPDF);

                // Write out the decoded data.
                FileStream outFile = new FileStream(tempFileName, FileMode.Create, FileAccess.Write);
                outFile.Write(binaryData, 0, binaryData.Length);
                outFile.Close();
                //Above is the code to save the file to a particular directory from NewPatientForm.com

                // Import this file
                SaveDocument(DocCur, tempFileName);
            }
            catch {
                Documents.Delete(DocCur);
                throw;
            }
            finally {
                if (File.Exists(tempFileName))
                {
                    File.Delete(tempFileName);
                }
            }
        }
Exemple #8
0
        protected void btnDelete_Click(Object Sender, EventArgs e)
        {
            bool boolDelete = oDocument.Delete(intDocument, true, oVariables.DocumentsFolder());

            if (boolDelete == true)
            {
                Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "delete", "<script type=\"text/javascript\">window.opener.location.reload();window.close();<" + "/" + "script>");
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "delete", "<script type=\"text/javascript\">alert('There was a problem deleting the file');<" + "/" + "script>");
            }
        }
        public Document Import(Bitmap image, int docCategory)
        {
            Document doc = new Document();

            doc.FileName    = ".jpg";
            doc.DateCreated = DateTime.Today;
            doc.DocCategory = docCategory;
            doc.PatNum      = Patient.PatNum;
            doc.ImgType     = ImageType.Photo;
            Documents.Insert(doc, Patient);            //this assigns a filename and saves to db
            try {
                SaveDocument(doc, image);
            }
            catch {
                Documents.Delete(doc);
                throw;
            }
            return(doc);
        }
 public void DeleteImage(IList <Document> documents)
 {
     for (int i = 0; i < documents.Count; i++)
     {
         if (documents[i] == null)
         {
             continue;
         }
         try {
             DeleteDocument(documents[i]);
         }
         catch {
             if (verbose)
             {
                 Debug.WriteLine(Lan.g("ContrDocs", "Could not delete file. It may be in use elsewhere, or may have already been deleted."));
             }
         }
         Documents.Delete(documents[i]);
     }
 }
 /// <summary>
 /// Verifies the doesnt exists.
 /// </summary>
 /// <exception cref="System.Exception"></exception>
 /// <exception cref="System.Exception"></exception>
 public void VerifyDoesntExists()
 {
     try
     {
         if (Documents.Exists(_databasePath, Doc_Title, out _errOut))
         {
             long id = Documents.GetId(_databasePath, Doc_Title, out _errOut);
             if (_errOut.Length > 0)
             {
                 throw new Exception(_errOut);
             }
             if (!Documents.Delete(_databasePath, id, out _errOut))
             {
                 throw new Exception(_errOut);
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine($"ERROR: {e}");
     }
 }
        public Document ImportCapturedImage(Bitmap image, short rotationAngle, int mountItemNum, int docCategory)
        {
            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         = Patient.PatNum;
            doc.DocCategory    = docCategory;
            doc.WindowingMin   = PrefB.GetInt("ImageWindowingMin");
            doc.WindowingMax   = PrefB.GetInt("ImageWindowingMax");
            Documents.Insert(doc, Patient);            //creates filename and saves to db
            try {
                SaveDocument(doc, image, ImageFormat.Bmp);
            }
            catch {
                Documents.Delete(doc);
                throw;
            }
            return(doc);
        }
        private void btnImportForms_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            XmlDocument x = new XmlDocument();

            AddResults("Downloading new patient list...");
            try
            {
                x.Load(sURL);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cannot access account.\r\n\r\nPlease make sure URL, username and password are correct.\r\n\r\nContact www.NewPatientForm.com for help.\r\n\r\n" + ex.Message);
                this.Close();
                return;
            }

            if (x.DocumentElement.ChildNodes.Count == 0)
            {
                MessageBox.Show("No new patients.");
                this.Close();
                return;
            }

            //Now that we have loaded all the new patient forms, loop through
            //each patient, import the xml and store the pdf file
            foreach (XmlNode ndeMessage in x.DocumentElement.ChildNodes)
            {
                string sPatientName = "";

                try
                {
                    sPatientName += ndeMessage.SelectSingleNode("PatientIdentification/NameLast").InnerText;
                }
                catch
                {
                    AddResults("No lastname found.");
                }

                try
                {
                    sPatientName += ", " + ndeMessage.SelectSingleNode("PatientIdentification/NameFirst").InnerText;
                }
                catch
                {
                    AddResults("No firstname found.");
                }

                if (MessageBox.Show("Do you want to import information for " + sPatientName + " ?", "", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    AddResults("Adding patient " + sPatientName);

                    string sPDF = "";

                    try
                    {
                        sPDF = ndeMessage.SelectSingleNode("PatientIdentification/NewPatientForm").InnerText;
                    }
                    catch
                    {
                        AddResults("No pdf form found.");
                    }

                    //We have the encoded pdf in sPDF string so lets
                    //delete that node and try to import the patient
                    ndeMessage.SelectSingleNode("PatientIdentification").RemoveChild(ndeMessage.SelectSingleNode("PatientIdentification/NewPatientForm"));

                    FormImportXML frmX = new FormImportXML();
                    frmX.textMain.Text = ndeMessage.OuterXml;
                    frmX.butOK_Click(null, null);


                    //The patient info is entered, let's save the pdf document to the images folder

                    try
                    {
                        //We'll be working with a document

                        //First make sure we have a directory and
                        //everything is up to date
                        ContrDocs cd = new ContrDocs();

                        cd.RefreshModuleData(frmX.existingPatOld.PatNum);


                        Document DocCur = new Document();

                        OpenFileDialog openFileDialog = new OpenFileDialog();
                        DocCur.FileName    = ".pdf";
                        DocCur.DateCreated = DateTime.Today;

                        //Find the category, hopefully 'Patient Information'
                        //otherwise, just default to first one
                        int iCategory = iCategory = DefB.Short[(int)DefCat.ImageCats][0].DefNum;;
                        for (int i = 0; i < DefB.Short[(int)DefCat.ImageCats].Length; i++)
                        {
                            if (DefB.Short[(int)DefCat.ImageCats][i].ItemName == "Patient Information")
                            {
                                iCategory = DefB.Short[(int)DefCat.ImageCats][i].DefNum;
                            }
                        }
                        DocCur.DocCategory = iCategory;
                        DocCur.ImgType     = ImageType.Document;
                        DocCur.Description = "New Patient Form";
                        DocCur.WithPat     = cd.PatCur.PatNum;
                        Documents.Insert(DocCur, cd.PatCur);//this assigns a filename and saves to db


                        try
                        {
                            // Convert the Base64 UUEncoded input into binary output.
                            byte[] binaryData = System.Convert.FromBase64String(sPDF);

                            // Write out the decoded data.
                            System.IO.FileStream outFile = new System.IO.FileStream(cd.patFolder + DocCur.FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                            outFile.Write(binaryData, 0, binaryData.Length);
                            outFile.Close();
                            //Above is the code to save the file to a particular directory from NewPatientForm.com
                        }
                        catch
                        {
                            MessageBox.Show(Lan.g(this, "Unable to write pdf file to disk."));
                            Documents.Delete(DocCur);
                        }
                    }
                    catch
                    {
                        AddResults("Could not save pdf file to patient's file.");
                    }

                    AddResults("Done writing pdf file to disk");
                }
                else
                {
                    AddResults("Cacelled import for " + sPatientName + ".");
                }
            }
            this.Cursor = Cursors.Default;
            MessageBox.Show("Import complete.\r\n\r\nIf any form imports were cancelled or unsuccessful\r\nthey will need to be imported manually.");

            btnImportForms.Enabled = false;
            //clear form instanciations
        }